Revision 36221 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Point2D.java
Point2D.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
|
2 | 2 |
* |
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 | 8 |
* as published by the Free Software Foundation; either version 2 |
8 | 9 |
* of the License, or (at your option) any later version. |
9 |
* |
|
10 |
*
|
|
10 | 11 |
* This program is distributed in the hope that it will be useful, |
11 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 14 |
* GNU General Public License for more details. |
14 |
* |
|
15 |
*
|
|
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* 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 |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
40 | 21 |
*/ |
41 | 22 |
package org.gvsig.fmap.geom.primitive.impl; |
42 | 23 |
|
... | ... | |
63 | 44 |
|
64 | 45 |
/** |
65 | 46 |
* Punto 2D. |
66 |
* |
|
47 |
*
|
|
67 | 48 |
* @author Vicente Caballero Navarro |
68 | 49 |
*/ |
69 | 50 |
public class Point2D extends AbstractPrimitive implements Point, DirectPosition { |
70 |
|
|
71 |
protected static final String COORDINATES_FIELD = "coordinates"; |
|
72 |
|
|
73 |
private static final long serialVersionUID = 1836257305083881299L; |
|
74 |
protected double[] coordinates; |
|
75 |
|
|
76 |
/** |
|
77 |
* The constructor with the GeometryType like and argument |
|
78 |
* is used by the {@link GeometryType}{@link #create()} |
|
79 |
* to create the geometry |
|
80 |
* @param type |
|
81 |
* The geometry type |
|
82 |
*/ |
|
83 |
public Point2D(GeometryType geometryType) { |
|
84 |
this(geometryType, null, null, 0.0, 0.0); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Constructor used in the {@link Geometry#cloneGeometry()} method |
|
89 |
*/ |
|
90 |
Point2D(GeometryType geometryType, String id, IProjection projection, double x, double y) { |
|
91 |
super(geometryType, id, projection); |
|
92 |
coordinates = new double[getDimension()]; |
|
93 |
coordinates[0] = x; |
|
94 |
coordinates[1] = y; |
|
95 |
} |
|
96 |
|
|
97 |
public Point2D (double x, double y) { |
|
98 |
super(TYPES.POINT, SUBTYPES.GEOM2D); |
|
99 |
coordinates = new double[getDimension()]; |
|
100 |
coordinates[0] = x; |
|
101 |
coordinates[1] = y; |
|
102 |
} |
|
103 |
|
|
104 |
public Point2D (int type, int subtype) { |
|
105 |
super(type, subtype); |
|
51 |
|
|
52 |
protected static final String COORDINATES_FIELD = "coordinates"; |
|
53 |
|
|
54 |
private static final long serialVersionUID = 1836257305083881299L; |
|
55 |
protected double[] coordinates; |
|
56 |
|
|
57 |
/** |
|
58 |
* The constructor with the GeometryType like and argument |
|
59 |
* is used by the {@link GeometryType}{@link #create()} to create the |
|
60 |
* geometry |
|
61 |
* |
|
62 |
* @param type |
|
63 |
* The geometry type |
|
64 |
*/ |
|
65 |
public Point2D(GeometryType geometryType) { |
|
66 |
this(geometryType, null, null, 0.0, 0.0); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Constructor used in the {@link Geometry#cloneGeometry()} method |
|
71 |
*/ |
|
72 |
Point2D(GeometryType geometryType, String id, IProjection projection, |
|
73 |
double x, double y) { |
|
74 |
super(geometryType, id, projection); |
|
106 | 75 |
coordinates = new double[getDimension()]; |
76 |
coordinates[0] = x; |
|
77 |
coordinates[1] = y; |
|
107 | 78 |
} |
108 |
|
|
109 |
public Point2D (java.awt.geom.Point2D point) { |
|
110 |
super(TYPES.POINT, SUBTYPES.GEOM2D); |
|
111 |
coordinates = new double[getDimension()]; |
|
112 |
coordinates[0] = point.getX(); |
|
113 |
coordinates[1] = point.getY(); |
|
114 |
} |
|
115 | 79 |
|
116 |
/** |
|
117 |
* Aplica la transformaci?nn de la matriz de transformaci?n que se pasa como |
|
118 |
* par?metro. |
|
119 |
* |
|
120 |
* @param at |
|
121 |
* Matriz de transformaci?n. |
|
122 |
*/ |
|
123 |
public void transform(AffineTransform at) { |
|
124 |
at.transform(coordinates, 0, coordinates, 0, 1); |
|
125 |
} |
|
80 |
public Point2D(double x, double y) { |
|
81 |
super(TYPES.POINT, SUBTYPES.GEOM2D); |
|
82 |
coordinates = new double[getDimension()]; |
|
83 |
coordinates[0] = x; |
|
84 |
coordinates[1] = y; |
|
85 |
} |
|
126 | 86 |
|
127 |
/* |
|
128 |
* (non-Javadoc) |
|
129 |
* |
|
130 |
* @see java.awt.Shape#contains(double, double) |
|
131 |
*/ |
|
132 |
public boolean contains(double x, double y) { |
|
133 |
if ((x == coordinates[0]) || (y == coordinates[1])) { |
|
134 |
return true; |
|
135 |
} else { |
|
136 |
return false; |
|
137 |
} |
|
138 |
} |
|
87 |
public Point2D(int type, int subtype) { |
|
88 |
super(type, subtype); |
|
89 |
coordinates = new double[getDimension()]; |
|
90 |
} |
|
139 | 91 |
|
140 |
/* |
|
141 |
* (non-Javadoc) |
|
142 |
* |
|
143 |
* @see java.awt.Shape#contains(double, double, double, double) |
|
144 |
*/ |
|
145 |
public boolean contains(double x, double y, double w, double h) { |
|
146 |
return false; |
|
147 |
} |
|
92 |
public Point2D(java.awt.geom.Point2D point) { |
|
93 |
super(TYPES.POINT, SUBTYPES.GEOM2D); |
|
94 |
coordinates = new double[getDimension()]; |
|
95 |
coordinates[0] = point.getX(); |
|
96 |
coordinates[1] = point.getY(); |
|
97 |
} |
|
148 | 98 |
|
149 |
/* |
|
150 |
* (non-Javadoc) |
|
151 |
* |
|
152 |
* @see java.awt.Shape#intersects(double, double, double, double) |
|
153 |
*/ |
|
154 |
public boolean intersects(double x, double y, double w, double h) { |
|
155 |
Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h); |
|
99 |
/** |
|
100 |
* Aplica la transformaci?nn de la matriz de transformaci?n que se pasa como |
|
101 |
* par?metro. |
|
102 |
* |
|
103 |
* @param at |
|
104 |
* Matriz de transformaci?n. |
|
105 |
*/ |
|
106 |
public void transform(AffineTransform at) { |
|
107 |
at.transform(coordinates, 0, coordinates, 0, 1); |
|
108 |
} |
|
156 | 109 |
|
157 |
return rAux.contains(coordinates[0], coordinates[1]); |
|
158 |
} |
|
110 |
/* |
|
111 |
* (non-Javadoc) |
|
112 |
* |
|
113 |
* @see java.awt.Shape#contains(double, double) |
|
114 |
*/ |
|
115 |
public boolean contains(double x, double y) { |
|
116 |
if ((x == coordinates[0]) || (y == coordinates[1])) { |
|
117 |
return true; |
|
118 |
} else { |
|
119 |
return false; |
|
120 |
} |
|
121 |
} |
|
159 | 122 |
|
160 |
/*
|
|
161 |
* (non-Javadoc)
|
|
162 |
*
|
|
163 |
* @see java.awt.Shape#getBounds()
|
|
164 |
*/
|
|
165 |
public Rectangle getBounds() {
|
|
166 |
return new Rectangle((int) coordinates[0], (int) coordinates[1], 0, 0);
|
|
167 |
}
|
|
123 |
/*
|
|
124 |
* (non-Javadoc)
|
|
125 |
*
|
|
126 |
* @see java.awt.Shape#contains(double, double, double, double)
|
|
127 |
*/
|
|
128 |
public boolean contains(double x, double y, double w, double h) {
|
|
129 |
return false;
|
|
130 |
}
|
|
168 | 131 |
|
169 |
/** |
|
170 |
* Devuelve la coordenada x del punto. |
|
171 |
* |
|
172 |
* @return Coordenada x. |
|
173 |
*/ |
|
174 |
public double getX() { |
|
175 |
return coordinates[0]; |
|
176 |
} |
|
132 |
/* |
|
133 |
* (non-Javadoc) |
|
134 |
* |
|
135 |
* @see java.awt.Shape#intersects(double, double, double, double) |
|
136 |
*/ |
|
137 |
public boolean intersects(double x, double y, double w, double h) { |
|
138 |
Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h); |
|
177 | 139 |
|
178 |
/** |
|
179 |
* Devuelve la coordenada y del punto. |
|
180 |
* |
|
181 |
* @return Coordenada y. |
|
182 |
*/ |
|
183 |
public double getY() { |
|
184 |
return coordinates[1]; |
|
185 |
} |
|
140 |
return rAux.contains(coordinates[0], coordinates[1]); |
|
141 |
} |
|
186 | 142 |
|
187 |
/*
|
|
188 |
* (non-Javadoc)
|
|
189 |
*
|
|
190 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
|
191 |
*/
|
|
192 |
public boolean contains(java.awt.geom.Point2D p) {
|
|
193 |
return false;
|
|
194 |
}
|
|
143 |
/*
|
|
144 |
* (non-Javadoc)
|
|
145 |
*
|
|
146 |
* @see java.awt.Shape#getBounds()
|
|
147 |
*/
|
|
148 |
public Rectangle getBounds() {
|
|
149 |
return new Rectangle((int) coordinates[0], (int) coordinates[1], 0, 0);
|
|
150 |
}
|
|
195 | 151 |
|
196 |
/* |
|
197 |
* (non-Javadoc) |
|
198 |
* |
|
199 |
* @see java.awt.Shape#getBounds2D() |
|
200 |
*/ |
|
201 |
public Rectangle2D getBounds2D() { |
|
202 |
return new Rectangle2D.Double(coordinates[0] - 0.01, coordinates[1] - 0.01, 0.02, |
|
203 |
0.02); |
|
204 |
} |
|
152 |
/** |
|
153 |
* Devuelve la coordenada x del punto. |
|
154 |
* |
|
155 |
* @return Coordenada x. |
|
156 |
*/ |
|
157 |
public double getX() { |
|
158 |
return coordinates[0]; |
|
159 |
} |
|
205 | 160 |
|
206 |
/*
|
|
207 |
* (non-Javadoc)
|
|
208 |
*
|
|
209 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
|
|
210 |
*/
|
|
211 |
public boolean contains(Rectangle2D r) {
|
|
212 |
return false;
|
|
213 |
}
|
|
161 |
/**
|
|
162 |
* Devuelve la coordenada y del punto.
|
|
163 |
*
|
|
164 |
* @return Coordenada y.
|
|
165 |
*/
|
|
166 |
public double getY() {
|
|
167 |
return coordinates[1];
|
|
168 |
}
|
|
214 | 169 |
|
215 |
/*
|
|
216 |
* (non-Javadoc)
|
|
217 |
*
|
|
218 |
* @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
|
|
219 |
*/
|
|
220 |
public boolean intersects(Rectangle2D r) {
|
|
221 |
return r.contains(coordinates[0], coordinates[1]);
|
|
222 |
}
|
|
170 |
/*
|
|
171 |
* (non-Javadoc)
|
|
172 |
*
|
|
173 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
|
174 |
*/
|
|
175 |
public boolean contains(java.awt.geom.Point2D p) {
|
|
176 |
return false;
|
|
177 |
}
|
|
223 | 178 |
|
224 |
/* |
|
225 |
* (non-Javadoc) |
|
226 |
* |
|
227 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform) |
|
228 |
*/ |
|
229 |
public PathIterator getPathIterator(AffineTransform at) { |
|
230 |
return new PointIterator(getPoint2D(), at); |
|
231 |
} |
|
179 |
/* |
|
180 |
* (non-Javadoc) |
|
181 |
* |
|
182 |
* @see java.awt.Shape#getBounds2D() |
|
183 |
*/ |
|
184 |
public Rectangle2D getBounds2D() { |
|
185 |
return new Rectangle2D.Double(coordinates[0] - 0.01, |
|
186 |
coordinates[1] - 0.01, 0.02, 0.02); |
|
187 |
} |
|
232 | 188 |
|
233 |
/* |
|
234 |
* (non-Javadoc) |
|
235 |
* |
|
236 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, |
|
237 |
* double) |
|
238 |
*/ |
|
239 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
240 |
return new PointIterator(getPoint2D(), at); |
|
241 |
} |
|
189 |
/* |
|
190 |
* (non-Javadoc) |
|
191 |
* |
|
192 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D) |
|
193 |
*/ |
|
194 |
public boolean contains(Rectangle2D r) { |
|
195 |
return false; |
|
196 |
} |
|
242 | 197 |
|
243 |
private java.awt.geom.Point2D getPoint2D() { |
|
244 |
return new java.awt.geom.Point2D.Double(coordinates[0], coordinates[1]); |
|
245 |
} |
|
198 |
/* |
|
199 |
* (non-Javadoc) |
|
200 |
* |
|
201 |
* @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D) |
|
202 |
*/ |
|
203 |
public boolean intersects(Rectangle2D r) { |
|
204 |
return r.contains(coordinates[0], coordinates[1]); |
|
205 |
} |
|
246 | 206 |
|
247 |
/** |
|
248 |
* @see org.gvsig.fmap.geom.primitive.FShape#getShapeType() |
|
249 |
*/ |
|
250 |
public int getShapeType() { |
|
251 |
return TYPES.POINT; |
|
252 |
} |
|
207 |
/* |
|
208 |
* (non-Javadoc) |
|
209 |
* |
|
210 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform) |
|
211 |
*/ |
|
212 |
public PathIterator getPathIterator(AffineTransform at) { |
|
213 |
return new PointIterator(getPoint2D(), at); |
|
214 |
} |
|
253 | 215 |
|
254 |
/* |
|
255 |
* (non-Javadoc) |
|
256 |
* |
|
257 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape() |
|
258 |
*/ |
|
259 |
public FShape cloneFShape() { |
|
260 |
return new Point2D(getGeometryType(), id, projection, coordinates[0], coordinates[1]); |
|
261 |
} |
|
216 |
/* |
|
217 |
* (non-Javadoc) |
|
218 |
* |
|
219 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, |
|
220 |
* double) |
|
221 |
*/ |
|
222 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
223 |
return new PointIterator(getPoint2D(), at); |
|
224 |
} |
|
262 | 225 |
|
263 |
/* |
|
264 |
* (non-Javadoc) |
|
265 |
* |
|
266 |
* @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans) |
|
267 |
*/ |
|
268 |
public void reProject(ICoordTrans ct) { |
|
269 |
java.awt.geom.Point2D p = getPoint2D(); |
|
270 |
p = ct.convert(p, p); |
|
271 |
coordinates[0] = p.getX(); |
|
272 |
coordinates[1] = p.getY(); |
|
273 |
} |
|
226 |
private java.awt.geom.Point2D getPoint2D() { |
|
227 |
return new java.awt.geom.Point2D.Double(coordinates[0], coordinates[1]); |
|
228 |
} |
|
274 | 229 |
|
275 |
/* |
|
276 |
* (non-Javadoc) |
|
277 |
* |
|
278 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers() |
|
279 |
*/ |
|
280 |
public Handler[] getStretchingHandlers() { |
|
281 |
ArrayList handlers = new ArrayList(); |
|
282 |
handlers.add(new PointHandler(0, coordinates[0], coordinates[1])); |
|
283 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
284 |
} |
|
230 |
/** |
|
231 |
* @see org.gvsig.fmap.geom.primitive.FShape#getShapeType() |
|
232 |
*/ |
|
233 |
public int getShapeType() { |
|
234 |
return TYPES.POINT; |
|
235 |
} |
|
285 | 236 |
|
286 |
/* |
|
287 |
* (non-Javadoc) |
|
288 |
* |
|
289 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers() |
|
290 |
*/ |
|
291 |
public Handler[] getSelectHandlers() { |
|
292 |
ArrayList handlers = new ArrayList(); |
|
293 |
handlers.add(new PointHandler(0, coordinates[0], coordinates[1])); |
|
294 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
295 |
} |
|
237 |
/* |
|
238 |
* (non-Javadoc) |
|
239 |
* |
|
240 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape() |
|
241 |
*/ |
|
242 |
public FShape cloneFShape() { |
|
243 |
return new Point2D(getGeometryType(), id, projection, coordinates[0], |
|
244 |
coordinates[1]); |
|
245 |
} |
|
296 | 246 |
|
297 |
/** |
|
298 |
* DOCUMENT ME! |
|
299 |
* |
|
300 |
* @author Vicente Caballero Navarro |
|
301 |
*/ |
|
302 |
class PointHandler extends AbstractHandler implements FinalHandler { |
|
303 |
/** |
|
304 |
* Crea un nuevo PointHandler. |
|
305 |
* |
|
306 |
* @param x |
|
307 |
* DOCUMENT ME! |
|
308 |
* @param y |
|
309 |
* DOCUMENT ME! |
|
310 |
*/ |
|
311 |
public PointHandler(int i, double x, double y) { |
|
312 |
point = new java.awt.geom.Point2D.Double(x, y); |
|
313 |
index = i; |
|
314 |
} |
|
247 |
/* |
|
248 |
* (non-Javadoc) |
|
249 |
* |
|
250 |
* @see |
|
251 |
* com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans |
|
252 |
* ) |
|
253 |
*/ |
|
254 |
public void reProject(ICoordTrans ct) { |
|
255 |
java.awt.geom.Point2D p = getPoint2D(); |
|
256 |
p = ct.convert(p, p); |
|
257 |
coordinates[0] = p.getX(); |
|
258 |
coordinates[1] = p.getY(); |
|
259 |
} |
|
315 | 260 |
|
316 |
/** |
|
317 |
* DOCUMENT ME! |
|
318 |
* |
|
319 |
* @param x |
|
320 |
* DOCUMENT ME! |
|
321 |
* @param y |
|
322 |
* DOCUMENT ME! |
|
323 |
* |
|
324 |
* @return DOCUMENT ME! |
|
325 |
*/ |
|
326 |
public void move(double x, double y) { |
|
327 |
coordinates[0] = coordinates[0] + x; |
|
328 |
coordinates[1] = coordinates[1] + y; |
|
329 |
} |
|
261 |
/* |
|
262 |
* (non-Javadoc) |
|
263 |
* |
|
264 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers() |
|
265 |
*/ |
|
266 |
public Handler[] getStretchingHandlers() { |
|
267 |
ArrayList handlers = new ArrayList(); |
|
268 |
handlers.add(new PointHandler(0, coordinates[0], coordinates[1])); |
|
269 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
270 |
} |
|
330 | 271 |
|
331 |
/** |
|
332 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double) |
|
333 |
*/ |
|
334 |
public void set(double x, double y) { |
|
335 |
coordinates[0] = x; |
|
336 |
coordinates[1] = y; |
|
337 |
} |
|
338 |
} |
|
272 |
/* |
|
273 |
* (non-Javadoc) |
|
274 |
* |
|
275 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers() |
|
276 |
*/ |
|
277 |
public Handler[] getSelectHandlers() { |
|
278 |
ArrayList handlers = new ArrayList(); |
|
279 |
handlers.add(new PointHandler(0, coordinates[0], coordinates[1])); |
|
280 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
281 |
} |
|
339 | 282 |
|
340 |
/* |
|
341 |
* (non-Javadoc) |
|
342 |
* |
|
343 |
* @see org.gvsig.geometries.iso.GM_Object#coordinateDimension() |
|
344 |
*/ |
|
345 |
public int getDimension() { |
|
346 |
return 2; |
|
347 |
} |
|
283 |
/** |
|
284 |
* DOCUMENT ME! |
|
285 |
* |
|
286 |
* @author Vicente Caballero Navarro |
|
287 |
*/ |
|
288 |
class PointHandler extends AbstractHandler implements FinalHandler { |
|
348 | 289 |
|
349 |
public Envelope getEnvelope() { |
|
350 |
return new Envelope2D(coordinates[0] - 0.01, coordinates[1] - 0.01,coordinates[0]+0.02,coordinates[1]+ |
|
351 |
0.02); |
|
352 |
} |
|
290 |
/** |
|
291 |
* Crea un nuevo PointHandler. |
|
292 |
* |
|
293 |
* @param x |
|
294 |
* DOCUMENT ME! |
|
295 |
* @param y |
|
296 |
* DOCUMENT ME! |
|
297 |
*/ |
|
298 |
public PointHandler(int i, double x, double y) { |
|
299 |
point = new java.awt.geom.Point2D.Double(x, y); |
|
300 |
index = i; |
|
301 |
} |
|
353 | 302 |
|
354 |
public GeneralPathX getGeneralPath() { |
|
355 |
// TODO Auto-generated method stub |
|
356 |
return null; |
|
357 |
} |
|
303 |
/** |
|
304 |
* DOCUMENT ME! |
|
305 |
* |
|
306 |
* @param x |
|
307 |
* DOCUMENT ME! |
|
308 |
* @param y |
|
309 |
* DOCUMENT ME! |
|
310 |
* |
|
311 |
* @return DOCUMENT ME! |
|
312 |
*/ |
|
313 |
public void move(double x, double y) { |
|
314 |
coordinates[0] = coordinates[0] + x; |
|
315 |
coordinates[1] = coordinates[1] + y; |
|
316 |
} |
|
358 | 317 |
|
359 |
public DirectPosition getDirectPosition() { |
|
360 |
return this; |
|
361 |
} |
|
318 |
/** |
|
319 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double) |
|
320 |
*/ |
|
321 |
public void set(double x, double y) { |
|
322 |
coordinates[0] = x; |
|
323 |
coordinates[1] = y; |
|
324 |
} |
|
325 |
} |
|
362 | 326 |
|
363 |
public double getOrdinate(int dim) { |
|
364 |
if (dim == 0) { |
|
365 |
return getX(); |
|
366 |
} else if (dim == 1) { |
|
367 |
return getY(); |
|
368 |
} else { |
|
369 |
return 0; |
|
370 |
} |
|
371 |
} |
|
327 |
/* |
|
328 |
* (non-Javadoc) |
|
329 |
* |
|
330 |
* @see org.gvsig.geometries.iso.GM_Object#coordinateDimension() |
|
331 |
*/ |
|
332 |
public int getDimension() { |
|
333 |
return 2; |
|
334 |
} |
|
372 | 335 |
|
373 |
public boolean equals(Object other) { |
|
374 |
if (!super.equals(other)) { |
|
375 |
return false; |
|
376 |
} |
|
377 |
Point2D pother = (Point2D) other; |
|
378 |
if (Math.abs(this.getX() - pother.getX()) > 0.0000001) { |
|
379 |
return false; |
|
380 |
} |
|
381 |
if (Math.abs(this.getY() - pother.getY()) > 0.0000001) { |
|
382 |
return false; |
|
383 |
} |
|
384 |
return true; |
|
336 |
public Envelope getEnvelope() { |
|
337 |
return new Envelope2D(coordinates[0] - 0.01, coordinates[1] - 0.01, |
|
338 |
coordinates[0] + 0.02, coordinates[1] + 0.02); |
|
339 |
} |
|
385 | 340 |
|
386 |
} |
|
341 |
public GeneralPathX getGeneralPath() { |
|
342 |
// TODO Auto-generated method stub |
|
343 |
return null; |
|
344 |
} |
|
387 | 345 |
|
388 |
/* (non-Javadoc) |
|
389 |
* @see org.gvsig.fmap.geom.primitive.Point#getCoordinates() |
|
390 |
*/ |
|
391 |
public double[] getCoordinates() { |
|
392 |
return coordinates; |
|
393 |
} |
|
346 |
public DirectPosition getDirectPosition() { |
|
347 |
return this; |
|
348 |
} |
|
394 | 349 |
|
395 |
/* (non-Javadoc) |
|
396 |
* @see org.gvsig.fmap.geom.primitive.Point#getDoordinateAt(int) |
|
397 |
*/ |
|
398 |
public double getCoordinateAt(int dimension) { |
|
399 |
return coordinates[dimension]; |
|
400 |
} |
|
350 |
public double getOrdinate(int dim) { |
|
351 |
if (dim == 0) { |
|
352 |
return getX(); |
|
353 |
} else |
|
354 |
if (dim == 1) { |
|
355 |
return getY(); |
|
356 |
} else { |
|
357 |
return 0; |
|
358 |
} |
|
359 |
} |
|
401 | 360 |
|
402 |
/* (non-Javadoc) |
|
403 |
* @see org.gvsig.fmap.geom.primitive.Point#setCoordinateAt(int, double) |
|
404 |
*/ |
|
405 |
public void setCoordinateAt(int dimension, double value) { |
|
406 |
coordinates[dimension] = value; |
|
407 |
} |
|
361 |
public boolean equals(Object other) { |
|
362 |
if (!super.equals(other)) { |
|
363 |
return false; |
|
364 |
} |
|
365 |
Point2D pother = (Point2D) other; |
|
366 |
if (Math.abs(this.getX() - pother.getX()) > 0.0000001) { |
|
367 |
return false; |
|
368 |
} |
|
369 |
if (Math.abs(this.getY() - pother.getY()) > 0.0000001) { |
|
370 |
return false; |
|
371 |
} |
|
372 |
return true; |
|
408 | 373 |
|
409 |
/* (non-Javadoc) |
|
410 |
* @see org.gvsig.fmap.geom.primitive.Point#setCoordinates(double[]) |
|
411 |
*/ |
|
412 |
public void setCoordinates(double[] values) { |
|
413 |
coordinates = values; |
|
414 |
} |
|
374 |
} |
|
415 | 375 |
|
416 |
/* (non-Javadoc) |
|
417 |
* @see org.gvsig.fmap.geom.primitive.Point#setX(double) |
|
418 |
*/ |
|
419 |
public void setX(double x) { |
|
420 |
coordinates[0] = x; |
|
421 |
} |
|
376 |
/* |
|
377 |
* (non-Javadoc) |
|
378 |
* |
|
379 |
* @see org.gvsig.fmap.geom.primitive.Point#getCoordinates() |
|
380 |
*/ |
|
381 |
public double[] getCoordinates() { |
|
382 |
return coordinates; |
|
383 |
} |
|
422 | 384 |
|
423 |
/* (non-Javadoc) |
|
424 |
* @see org.gvsig.fmap.geom.primitive.Point#setY(double) |
|
425 |
*/ |
|
426 |
public void setY(double y) { |
|
427 |
coordinates[1] = y; |
|
428 |
} |
|
385 |
/* |
|
386 |
* (non-Javadoc) |
|
387 |
* |
|
388 |
* @see org.gvsig.fmap.geom.primitive.Point#getDoordinateAt(int) |
|
389 |
*/ |
|
390 |
public double getCoordinateAt(int dimension) { |
|
391 |
return coordinates[dimension]; |
|
392 |
} |
|
429 | 393 |
|
430 |
public String toString() { |
|
431 |
StringBuffer buffer = new StringBuffer(); |
|
432 |
buffer.append("Point2D("); |
|
433 |
toStringCoordinates(buffer); |
|
434 |
buffer.append(")"); |
|
435 |
return buffer.toString(); |
|
436 |
} |
|
437 |
|
|
438 |
protected void toStringCoordinates(StringBuffer buffer){ |
|
439 |
buffer.append(coordinates[0]); |
|
440 |
for(int i=1 ; i<coordinates.length; i++ ) { |
|
394 |
/* |
|
395 |
* (non-Javadoc) |
|
396 |
* |
|
397 |
* @see org.gvsig.fmap.geom.primitive.Point#setCoordinateAt(int, double) |
|
398 |
*/ |
|
399 |
public void setCoordinateAt(int dimension, double value) { |
|
400 |
coordinates[dimension] = value; |
|
401 |
} |
|
402 |
|
|
403 |
/* |
|
404 |
* (non-Javadoc) |
|
405 |
* |
|
406 |
* @see org.gvsig.fmap.geom.primitive.Point#setCoordinates(double[]) |
|
407 |
*/ |
|
408 |
public void setCoordinates(double[] values) { |
|
409 |
coordinates = values; |
|
410 |
} |
|
411 |
|
|
412 |
/* |
|
413 |
* (non-Javadoc) |
|
414 |
* |
|
415 |
* @see org.gvsig.fmap.geom.primitive.Point#setX(double) |
|
416 |
*/ |
|
417 |
public void setX(double x) { |
|
418 |
coordinates[0] = x; |
|
419 |
} |
|
420 |
|
|
421 |
/* |
|
422 |
* (non-Javadoc) |
|
423 |
* |
|
424 |
* @see org.gvsig.fmap.geom.primitive.Point#setY(double) |
|
425 |
*/ |
|
426 |
public void setY(double y) { |
|
427 |
coordinates[1] = y; |
|
428 |
} |
|
429 |
|
|
430 |
public String toString() { |
|
431 |
StringBuffer buffer = new StringBuffer(); |
|
432 |
buffer.append("Point2D("); |
|
433 |
toStringCoordinates(buffer); |
|
434 |
buffer.append(")"); |
|
435 |
return buffer.toString(); |
|
436 |
} |
|
437 |
|
|
438 |
protected void toStringCoordinates(StringBuffer buffer) { |
|
439 |
buffer.append(coordinates[0]); |
|
440 |
for (int i = 1; i < coordinates.length; i++) { |
|
441 | 441 |
buffer.append(",").append(coordinates[i]); |
442 | 442 |
} |
443 |
} |
|
444 |
} |
|
443 |
} |
|
444 |
} |
Also available in: Unified diff