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 @ 40435

History | View | Annotate | Download (3.2 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

    
28
package org.gvsig.fmap.geom.primitive.impl;
29

    
30
import java.awt.geom.Rectangle2D;
31

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

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

    
51
        public Envelope2D(Point min, Point max) {
52
                super(min, max);
53
        }
54

    
55
        public Envelope2D(double minX,double minY,double maxX, double maxY){
56
                this(new Point2D(minX, minY), new Point2D(maxX, maxY));
57
        }
58

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

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

    
86
                return new Envelope2D(p1, p2);
87
        }
88

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