Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / primitive / impl / Envelope2D.java @ 40767

History | View | Annotate | Download (3.18 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.fmap.geom.primitive.impl;
26

    
27
import java.awt.geom.Rectangle2D;
28

    
29
import org.cresques.cts.ICoordTrans;
30
import org.gvsig.fmap.geom.primitive.Envelope;
31
import org.gvsig.fmap.geom.primitive.EnvelopeNotInitializedException;
32
import org.gvsig.fmap.geom.primitive.Point;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynStruct;
35
import org.gvsig.tools.lang.Cloneable;
36
import org.gvsig.tools.persistence.PersistenceManager;
37

    
38
/**
39
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
40
 */
41
public class Envelope2D extends DefaultEnvelope implements Cloneable{
42
        public static final String PERSISTENCE_DEFINITION_NAME = "Envelope2Dimensions";
43
        
44
        public Envelope2D() {
45
                super();        
46
        }
47

    
48
        public Envelope2D(Point min, Point max) {
49
                super(min, max);
50
        }
51

    
52
        public Envelope2D(double minX,double minY,double maxX, double maxY){
53
                this(new Point2D(minX, minY), new Point2D(maxX, maxY));
54
        }
55

    
56
        /* (non-Javadoc)
57
         * @see org.gvsig.fmap.geom.primitive.Envelope#getDimension()
58
         */
59
        public int getDimension() {
60
                return 2;
61
        }
62

    
63
        /*
64
         * (non-Javadoc)
65
         * @see org.gvsig.fmap.geom.primitive.Envelope#convert(org.cresques.cts.ICoordTrans)
66
         */
67
        public Envelope convert(ICoordTrans trans) {
68
            if (isEmpty){
69
            throw new EnvelopeNotInitializedException();
70
        }
71
            if (this.getDimension() > 2) {
72
                        return null;
73
                }
74
                Rectangle2D rect = new Rectangle2D.Double(this.getMinimum(0), this
75
                                .getMinimum(1), this.getLength(0), this.getLength(1));
76
                Rectangle2D rectDest = trans.convert(rect);
77
                if (rectDest == null){
78
                        return null;
79
                }
80
                Point2D p1 = new Point2D(rectDest.getMinX(), rectDest.getMinY());
81
                Point2D p2 = new Point2D(rectDest.getMaxX(), rectDest.getMaxY());
82

    
83
                return new Envelope2D(p1, p2);
84
        }
85

    
86
        public static void registerPersistent() {
87
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
88
                if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) {
89
                        DynStruct definition = manager.addDefinition(
90
                                        Envelope2D.class,
91
                                        PERSISTENCE_DEFINITION_NAME,
92
                                        "Envelope2D persistence definition",
93
                                        null, 
94
                                        null
95
                        ); 
96
                        
97
                        definition.extend(manager.getDefinition(DefaultEnvelope.PERSISTENCE_DEFINITION_NAME));        
98
                }
99
        }
100
        
101
    public Object clone() throws CloneNotSupportedException {
102
        return super.clone();
103
    }
104
}
105