root / tags / v2_0_0_Build_2060 / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / impl / Circle2D.java @ 39365
History | View | Annotate | Download (13 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 org.gvsig.fmap.geom.primitive.impl; |
42 |
|
43 |
import java.awt.geom.AffineTransform; |
44 |
import java.awt.geom.Arc2D; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.util.ArrayList; |
48 |
|
49 |
import org.cresques.cts.IProjection; |
50 |
|
51 |
import org.gvsig.fmap.geom.Geometry; |
52 |
import org.gvsig.fmap.geom.handler.AbstractHandler; |
53 |
import org.gvsig.fmap.geom.handler.CuadrantHandler; |
54 |
import org.gvsig.fmap.geom.handler.Handler; |
55 |
import org.gvsig.fmap.geom.primitive.Circle; |
56 |
import org.gvsig.fmap.geom.primitive.FShape; |
57 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
58 |
import org.gvsig.fmap.geom.primitive.Point; |
59 |
import org.gvsig.fmap.geom.type.GeometryType; |
60 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
61 |
|
62 |
/**
|
63 |
* DOCUMENT ME!
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
*/
|
67 |
public class Circle2D extends Surface2D implements Circle { |
68 |
private static final long serialVersionUID = -2709867465161215668L; |
69 |
|
70 |
private Point2D center; |
71 |
private double radio; |
72 |
|
73 |
/**
|
74 |
* The constructor with the GeometryType like and argument
|
75 |
* is used by the {@link GeometryType}{@link #create()}
|
76 |
* to create the geometry
|
77 |
* @param type
|
78 |
* The geometry type
|
79 |
*/
|
80 |
public Circle2D(GeometryType geometryType) {
|
81 |
super(geometryType);
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Constructor used in the {@link Geometry#cloneGeometry()} method
|
86 |
*/
|
87 |
Circle2D(GeometryType geometryType, String id, IProjection projection, GeneralPathX gpx,
|
88 |
Point2D c, double r) { |
89 |
super(geometryType, id, projection, gpx);
|
90 |
center = c; |
91 |
radio = r; |
92 |
} |
93 |
|
94 |
/*
|
95 |
* (non-Javadoc)
|
96 |
* @see org.gvsig.fmap.geom.primitive.Circle#getCenter()
|
97 |
*/
|
98 |
public Point getCenter() { |
99 |
return new org.gvsig.fmap.geom.primitive.impl.Point2D(center.getX(), center.getY()); |
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
* @see org.gvsig.fmap.geom.primitive.impl.Surface2D#cloneFShape()
|
105 |
*/
|
106 |
public FShape cloneFShape() {
|
107 |
return new Circle2D(getGeometryType(), id, projection, (GeneralPathX) gp.clone(), center, |
108 |
radio); |
109 |
} |
110 |
|
111 |
/*
|
112 |
* (non-Javadoc)
|
113 |
* @see org.gvsig.fmap.geom.primitive.impl.Surface2D#getShapeType()
|
114 |
*/
|
115 |
public int getShapeType() { |
116 |
return TYPES.CIRCLE;
|
117 |
} |
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
* @see org.gvsig.fmap.geom.primitive.impl.OrientablePrimitive2D#transform(java.awt.geom.AffineTransform)
|
122 |
*/
|
123 |
public void transform(AffineTransform at) { |
124 |
|
125 |
if (at == null) { |
126 |
return;
|
127 |
} |
128 |
|
129 |
Point2D pdist = UtilFunctions.getPerpendicularPoint(new Point2D.Double( |
130 |
center.getX() + 10, center.getY()), new Point2D.Double(center |
131 |
.getX() - 10, center.getY()), center, radio);
|
132 |
Point2D aux = new Point2D.Double(); |
133 |
at.transform(center, aux); |
134 |
center = aux; |
135 |
Point2D aux3 = new Point2D.Double(); |
136 |
at.transform(pdist, aux3); |
137 |
radio = center.distance(aux3); |
138 |
gp.transform(at); |
139 |
} |
140 |
|
141 |
/*
|
142 |
* (non-Javadoc)
|
143 |
* @see org.gvsig.fmap.geom.primitive.impl.OrientablePrimitive2D#getStretchingHandlers()
|
144 |
*/
|
145 |
public Handler[] getStretchingHandlers() { |
146 |
ArrayList handlers = new ArrayList(); |
147 |
Rectangle2D rect = this.getBounds2D(); |
148 |
handlers |
149 |
.add(new CenterHandler(0, rect.getCenterX(), rect.getCenterY())); |
150 |
// handlers.add(new RadioHandler(1, rect.getX(), rect.getCenterY()));
|
151 |
// handlers.add(new RadioHandler(2, rect.getMaxX(), rect.getCenterY()));
|
152 |
// handlers.add(new RadioHandler(3, rect.getCenterX(), rect.getY()));
|
153 |
// handlers.add(new RadioHandler(3, rect.getCenterX(), rect.getMaxY()));
|
154 |
|
155 |
return (Handler[]) handlers.toArray(new Handler[0]); |
156 |
} |
157 |
|
158 |
/*
|
159 |
* (non-Javadoc)
|
160 |
* @see org.gvsig.fmap.geom.primitive.impl.OrientablePrimitive2D#getSelectHandlers()
|
161 |
*/
|
162 |
public Handler[] getSelectHandlers() { |
163 |
ArrayList handlers = new ArrayList(); |
164 |
handlers.add(new CenterSelHandler(0, center.getX(), center.getY())); |
165 |
handlers.add(new RadioSelHandler(1, center.getX() - radio, center |
166 |
.getY())); |
167 |
handlers.add(new RadioSelHandler(2, center.getX() + radio, center |
168 |
.getY())); |
169 |
handlers.add(new RadioSelHandler(3, center.getX(), center.getY() |
170 |
- radio)); |
171 |
handlers.add(new RadioSelHandler(3, center.getX(), center.getY() |
172 |
+ radio)); |
173 |
|
174 |
return (Handler[]) handlers.toArray(new Handler[0]); |
175 |
} |
176 |
|
177 |
/**
|
178 |
* DOCUMENT ME!
|
179 |
*
|
180 |
* @author Vicente Caballero Navarro
|
181 |
*/
|
182 |
class CenterHandler extends AbstractHandler implements Handler, org.gvsig.fmap.geom.handler.CenterHandler{ |
183 |
/**
|
184 |
* Crea un nuevo PointHandler.
|
185 |
*
|
186 |
* @param i
|
187 |
* DOCUMENT ME!
|
188 |
* @param x
|
189 |
* DOCUMENT ME!
|
190 |
* @param y
|
191 |
* DOCUMENT ME!
|
192 |
*/
|
193 |
public CenterHandler(int i, double x, double y) { |
194 |
point = new Point2D.Double(x, y); |
195 |
index = i; |
196 |
} |
197 |
|
198 |
/**
|
199 |
* DOCUMENT ME!
|
200 |
*
|
201 |
* @param x
|
202 |
* DOCUMENT ME!
|
203 |
* @param y
|
204 |
* DOCUMENT ME!
|
205 |
*
|
206 |
* @return DOCUMENT ME!
|
207 |
*/
|
208 |
public void move(double x, double y) { |
209 |
center = new Point2D.Double(center.getX() + x, center.getY() + y); |
210 |
Point point;
|
211 |
for (int i = 0; i < gp.getNumCoords(); i++) { |
212 |
point = gp.getPointAt(i); |
213 |
point.setX(point.getX() + x); |
214 |
point.setY(point.getY() + y); |
215 |
} |
216 |
} |
217 |
|
218 |
/**
|
219 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
220 |
*/
|
221 |
public void set(double x, double y) { |
222 |
} |
223 |
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* DOCUMENT ME!
|
228 |
*
|
229 |
* @author Vicente Caballero Navarro
|
230 |
*/
|
231 |
class CenterSelHandler extends AbstractHandler implements Handler, org.gvsig.fmap.geom.handler.CenterHandler { |
232 |
/**
|
233 |
* Crea un nuevo PointHandler.
|
234 |
*
|
235 |
* @param i
|
236 |
* DOCUMENT ME!
|
237 |
* @param x
|
238 |
* DOCUMENT ME!
|
239 |
* @param y
|
240 |
* DOCUMENT ME!
|
241 |
*/
|
242 |
public CenterSelHandler(int i, double x, double y) { |
243 |
point = new Point2D.Double(x, y); |
244 |
index = i; |
245 |
} |
246 |
|
247 |
/**
|
248 |
* DOCUMENT ME!
|
249 |
*
|
250 |
* @param x
|
251 |
* DOCUMENT ME!
|
252 |
* @param y
|
253 |
* DOCUMENT ME!
|
254 |
*
|
255 |
* @return DOCUMENT ME!
|
256 |
*/
|
257 |
public void move(double x, double y) { |
258 |
Point point;
|
259 |
for (int i = 0; i < gp.getNumCoords() ; i++) { |
260 |
point = gp.getPointAt(i); |
261 |
point.setX(point.getX() + x); |
262 |
point.setY(point.getY() + y); |
263 |
} |
264 |
} |
265 |
|
266 |
/**
|
267 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
268 |
*/
|
269 |
public void set(double x, double y) { |
270 |
center = new Point2D.Double(x, y); |
271 |
Arc2D.Double arc = new Arc2D.Double(center.getX() - radio, center |
272 |
.getY() |
273 |
- radio, 2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
274 |
gp = new GeneralPathX(arc.getPathIterator(null)); |
275 |
gp.closePath(); |
276 |
} |
277 |
} |
278 |
|
279 |
/**
|
280 |
* DOCUMENT ME!
|
281 |
*
|
282 |
* @author Vicente Caballero Navarro
|
283 |
*/
|
284 |
class RadioSelHandler extends AbstractHandler implements CuadrantHandler { |
285 |
|
286 |
/**
|
287 |
* Crea un nuevo PointHandler.
|
288 |
*
|
289 |
* @param i
|
290 |
* DOCUMENT ME!
|
291 |
* @param x
|
292 |
* DOCUMENT ME!
|
293 |
* @param y
|
294 |
* DOCUMENT ME!
|
295 |
*/
|
296 |
public RadioSelHandler(int i, double x, double y) { |
297 |
point = new Point2D.Double(x, y); |
298 |
index = i; |
299 |
} |
300 |
|
301 |
/**
|
302 |
* DOCUMENT ME!
|
303 |
*
|
304 |
* @param x
|
305 |
* DOCUMENT ME!
|
306 |
* @param y
|
307 |
* DOCUMENT ME!
|
308 |
*
|
309 |
* @return DOCUMENT ME!
|
310 |
*/
|
311 |
public void move(double x, double y) { |
312 |
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
317 |
*/
|
318 |
public void set(double x, double y) { |
319 |
radio = center.distance(x, y); |
320 |
Arc2D.Double arc = new Arc2D.Double(center.getX() - radio, center |
321 |
.getY() |
322 |
- radio, 2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
323 |
gp = new GeneralPathX(arc.getPathIterator(null)); |
324 |
} |
325 |
} |
326 |
|
327 |
/*
|
328 |
* (non-Javadoc)
|
329 |
*
|
330 |
* @see com.iver.cit.gvsig.fmap.core.FPolyline2D#intersects(java.awt.geom.Rectangle2D)
|
331 |
*/
|
332 |
public boolean intersects(Rectangle2D r) { |
333 |
return gp.intersects(r);
|
334 |
} |
335 |
|
336 |
/* (non-Javadoc)
|
337 |
* @see org.gvsig.fmap.geom.primitive.Surface2D#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
338 |
*/
|
339 |
public void setGeneralPath(GeneralPathX generalPathX) { |
340 |
throw new UnsupportedOperationException("Use setPoints(Point center, Point radious)"); |
341 |
} |
342 |
|
343 |
/* (non-Javadoc)
|
344 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
|
345 |
*/
|
346 |
public void setPoints(Point center, Point radious) { |
347 |
Point2D _center = new java.awt.geom.Point2D.Double(center.getCoordinateAt(0), center.getCoordinateAt(1)); |
348 |
Point2D _radious = new java.awt.geom.Point2D.Double(radious.getCoordinateAt(0), radious.getCoordinateAt(1)); |
349 |
double dRadious = _center.distance(_radious);
|
350 |
setPoints(center, dRadious); |
351 |
} |
352 |
|
353 |
/*
|
354 |
* (non-Javadoc)
|
355 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, double)
|
356 |
*/
|
357 |
public void setPoints(Point center, double radious){ |
358 |
Point2D _center = new java.awt.geom.Point2D.Double(center.getCoordinateAt(0), center.getCoordinateAt(1)); |
359 |
java.awt.geom.Arc2D.Double arc = |
360 |
new java.awt.geom.Arc2D.Double(center.getX() - radious, _center
|
361 |
.getY() |
362 |
- radious, 2 * radious, 2 * radious, 0, 360, Arc2D.OPEN); |
363 |
this.gp = new GeneralPathX(arc.getPathIterator(null)); |
364 |
gp.closePath(); |
365 |
this.center = _center;
|
366 |
this.radio = radious;
|
367 |
} |
368 |
|
369 |
/* (non-Javadoc)
|
370 |
* @see org.gvsig.fmap.geom.primitive.Arc#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
|
371 |
*/
|
372 |
public void setPoints(Point p1, Point p2, Point p3) { |
373 |
Point2D _p1 = new java.awt.geom.Point2D.Double(p1.getCoordinateAt(0), p1.getCoordinateAt(1)); |
374 |
Point2D _p2 = new java.awt.geom.Point2D.Double(p2.getCoordinateAt(0), p2.getCoordinateAt(1)); |
375 |
Point2D _p3 = new java.awt.geom.Point2D.Double(p3.getCoordinateAt(0), p3.getCoordinateAt(1)); |
376 |
setPoints(_p1, _p2, _p3); |
377 |
} |
378 |
|
379 |
/* (non-Javadoc)
|
380 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point2D, org.gvsig.fmap.geom.primitive.Point2D)
|
381 |
*/
|
382 |
public void setPoints(org.gvsig.fmap.geom.primitive.impl.Point2D center, |
383 |
org.gvsig.fmap.geom.primitive.impl.Point2D radious) { |
384 |
Point2D _center = new java.awt.geom.Point2D.Double(center.getCoordinateAt(0), center.getCoordinateAt(1)); |
385 |
Point2D _radious = new java.awt.geom.Point2D.Double(radious.getCoordinateAt(0), radious.getCoordinateAt(1)); |
386 |
setPoints(_center, _radious); |
387 |
} |
388 |
|
389 |
/* (non-Javadoc)
|
390 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point2D, double)
|
391 |
*/
|
392 |
public void setPoints(Point2D center, |
393 |
double radious) {
|
394 |
java.awt.geom.Arc2D.Double arc = |
395 |
new java.awt.geom.Arc2D.Double(center.getX() - radious, center
|
396 |
.getY() |
397 |
- radious, 2 * radious, 2 * radious, 0, 360, Arc2D.OPEN); |
398 |
this.gp = new GeneralPathX(arc.getPathIterator(null)); |
399 |
gp.closePath(); |
400 |
this.center = center;
|
401 |
this.radio = radious;
|
402 |
|
403 |
} |
404 |
|
405 |
/* (non-Javadoc)
|
406 |
* @see org.gvsig.fmap.geom.primitive.Arc#setPoints(java.awt.geom.Point2D, java.awt.geom.Point2D, java.awt.geom.Point2D)
|
407 |
*/
|
408 |
public void setPoints(Point2D p1, Point2D p2, Point2D p3) { |
409 |
Point2D center = UtilFunctions.getCenter(p1, p2, p3);
|
410 |
if (center != null) { |
411 |
setPoints(center, p1); |
412 |
} |
413 |
} |
414 |
|
415 |
/* (non-Javadoc)
|
416 |
* @see org.gvsig.fmap.geom.primitive.Curve#setCoordinateAt(int, int, double)
|
417 |
*/
|
418 |
public void setCoordinateAt(int index, int dimension, double value) { |
419 |
throw new UnsupportedOperationException("Use setGeneralPathX"); |
420 |
} |
421 |
|
422 |
/* (non-Javadoc)
|
423 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(java.awt.geom.Point2D, java.awt.geom.Point2D)
|
424 |
*/
|
425 |
private void setPoints(Point2D center, Point2D radious) { |
426 |
double radio = center.distance(radious);
|
427 |
setPoints(center, radio); |
428 |
} |
429 |
|
430 |
/* (non-Javadoc)
|
431 |
* @see org.gvsig.fmap.geom.primitive.Arc#setPoints(org.gvsig.fmap.geom.primitive.Point, double, double, double)
|
432 |
*/
|
433 |
public void setPoints(Point center, double radius, double initAngle, |
434 |
double angleExt) {
|
435 |
throw new UnsupportedOperationException("Use setGeneralPathX"); |
436 |
} |
437 |
|
438 |
/* (non-Javadoc)
|
439 |
* @see org.gvsig.fmap.geom.primitive.Arc#setPoints(java.awt.geom.Point2D, double, double, double)
|
440 |
*/
|
441 |
private void setPoints(Point2D center, double radius, double initAngle, |
442 |
double angleExt) {
|
443 |
throw new UnsupportedOperationException("Use setGeneralPathX"); |
444 |
} |
445 |
|
446 |
/* (non-Javadoc)
|
447 |
* @see org.gvsig.fmap.geom.primitive.Circle#getRadious()
|
448 |
*/
|
449 |
public double getRadious() { |
450 |
return radio;
|
451 |
} |
452 |
|
453 |
|
454 |
} |