Statistics
| Revision:

svn-gvsig-desktop / branches / Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPoint2D.java @ 1848

History | View | Annotate | Download (4.62 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.core;
42

    
43
import org.cresques.cts.ICoordTrans;
44

    
45
import java.awt.Rectangle;
46
import java.awt.geom.AffineTransform;
47
import java.awt.geom.PathIterator;
48
import java.awt.geom.Point2D;
49
import java.awt.geom.Rectangle2D;
50
import java.io.Serializable;
51

    
52

    
53
/**
54
 * Punto 2D.
55
 *
56
 * @author Vicente Caballero Navarro
57
 */
58
public class FPoint2D implements FShape {
59
        protected double x;
60
        protected double y;
61

    
62
        /**
63
         * Crea un nuevo Point2D.
64
         *
65
         * @param x Coordenada x del punto.
66
         * @param y Coordenada y del punto.
67
         */
68
        public FPoint2D(double x, double y) {
69
                this.x = x;
70
                this.y = y;
71
        }
72

    
73
        /**
74
         * Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
75
         * par?metro.
76
         *
77
         * @param at Matriz de transformaci?n.
78
         */
79
        public void transform(AffineTransform at) {
80
                double[] p  = new double[]{x, y};
81
                at.transform(p, 0, p, 0, 1);
82
        }
83

    
84
        /* (non-Javadoc)
85
         * @see java.awt.Shape#contains(double, double)
86
         */
87
        public boolean contains(double x, double y) {
88
                if ((x == this.x) || (y == this.y)) {
89
                        return true;
90
                } else {
91
                        return false;
92
                }
93
        }
94

    
95
        /* (non-Javadoc)
96
         * @see java.awt.Shape#contains(double, double, double, double)
97
         */
98
        public boolean contains(double x, double y, double w, double h) {
99
                return false;
100
        }
101

    
102
        /* (non-Javadoc)
103
         * @see java.awt.Shape#intersects(double, double, double, double)
104
         */
105
        public boolean intersects(double x, double y, double w, double h) {
106
                Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
107

    
108
                return rAux.contains(this.x, this.y);
109
        }
110

    
111
        /* (non-Javadoc)
112
         * @see java.awt.Shape#getBounds()
113
         */
114
        public Rectangle getBounds() {
115
                return new Rectangle((int) this.x, (int) this.y, 0, 0);
116
        }
117

    
118
        /**
119
         * Devuelve la coordenada x del punto.
120
         *
121
         * @return Coordenada x.
122
         */
123
        public double getX() {
124
                return this.x;
125
        }
126

    
127
        /**
128
         * Devuelve la coordenada y del punto.
129
         *
130
         * @return Coordenada y.
131
         */
132
        public double getY() {
133
                return this.y;
134
        }
135

    
136
        /* (non-Javadoc)
137
         * @see java.awt.Shape#contains(java.awt.geom.Point2D)
138
         */
139
        public boolean contains(Point2D p) {
140
                return false;
141
        }
142

    
143
        /* (non-Javadoc)
144
         * @see java.awt.Shape#getBounds2D()
145
         */
146
        public Rectangle2D getBounds2D() {
147
                return new Rectangle2D.Double(x, y, 0, 0);
148
        }
149

    
150
        /* (non-Javadoc)
151
         * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
152
         */
153
        public boolean contains(Rectangle2D r) {
154
                return false;
155
        }
156

    
157
        /* (non-Javadoc)
158
         * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
159
         */
160
        public boolean intersects(Rectangle2D r) {
161
                return r.contains(new Point2D.Double(x, y));
162
        }
163

    
164
        /* (non-Javadoc)
165
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
166
         */
167
        public PathIterator getPathIterator(AffineTransform at) {
168
                return new FPointIterator(new Point2D.Double(x, y), at);
169
        }
170

    
171
        /* (non-Javadoc)
172
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
173
         */
174
        public PathIterator getPathIterator(AffineTransform at, double flatness) {
175
                return new FPointIterator(new Point2D.Double(x, y), at);
176
        }
177

    
178
        /**
179
         * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
180
         */
181
        public int getShapeType() {
182
                return FShape.POINT;
183
        }
184

    
185
        /* (non-Javadoc)
186
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
187
         */
188
        public FShape cloneFShape() {
189
                return new FPoint2D(x, y);
190
        }
191

    
192
        /* (non-Javadoc)
193
         * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
194
         */
195
        public void reProject(ICoordTrans ct) {
196
                Point2D p = new Point2D.Double(x, y);
197
                p = ct.convert(p, p);
198
                x = p.getX();
199
                y = p.getY();
200
        }
201
}