svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / impl / Ellipse2D.java @ 40416
History | View | Annotate | Download (18.4 KB)
1 | 21308 | jiyarza | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 20964 | jiyarza | *
|
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 | 21308 | jiyarza | * Av. Blasco Ib??ez, 50
|
24 | 20964 | jiyarza | * 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 | 27029 | jpiera | package org.gvsig.fmap.geom.primitive.impl; |
42 | 20761 | jmvivo | |
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 | 21870 | vcaballero | import org.cresques.cts.IProjection; |
50 | 29097 | jpiera | import org.gvsig.fmap.geom.Geometry; |
51 | 20761 | jmvivo | import org.gvsig.fmap.geom.handler.AbstractHandler; |
52 | import org.gvsig.fmap.geom.handler.CuadrantHandler; |
||
53 | import org.gvsig.fmap.geom.handler.Handler; |
||
54 | 27029 | jpiera | import org.gvsig.fmap.geom.primitive.Ellipse; |
55 | import org.gvsig.fmap.geom.primitive.FShape; |
||
56 | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
||
57 | import org.gvsig.fmap.geom.primitive.Point; |
||
58 | 20964 | jiyarza | import org.gvsig.fmap.geom.type.GeometryType; |
59 | 20761 | jmvivo | import org.gvsig.fmap.geom.util.UtilFunctions; |
60 | |||
61 | /**
|
||
62 | 20964 | jiyarza | * DOCUMENT ME!
|
63 | 21731 | vcaballero | *
|
64 | 20964 | jiyarza | * @author Vicente Caballero Navarro
|
65 | */
|
||
66 | 26788 | jpiera | public class Ellipse2D extends Surface2D implements Ellipse { |
67 | 35475 | jpiera | private static final long serialVersionUID = 7624230115118134004L; |
68 | 20761 | jmvivo | |
69 | 35475 | jpiera | private Point2D init; |
70 | private Point2D end; |
||
71 | private double ydist; |
||
72 | 20964 | jiyarza | |
73 | 35475 | jpiera | /**
|
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 Ellipse2D(GeometryType geometryType) { |
||
81 | super(geometryType);
|
||
82 | } |
||
83 | 20761 | jmvivo | |
84 | 35475 | jpiera | /**
|
85 | * Constructor used in the {@link Geometry#cloneGeometry()} method
|
||
86 | * @param id
|
||
87 | * @param projection
|
||
88 | * @param gpx
|
||
89 | * @param i
|
||
90 | * @param e
|
||
91 | * @param d
|
||
92 | */
|
||
93 | Ellipse2D(GeometryType geometryType,String id, IProjection projection, GeneralPathX gpx, |
||
94 | Point2D i, Point2D e, double d) { |
||
95 | super(geometryType, id, projection, gpx);
|
||
96 | init = i; |
||
97 | end = e; |
||
98 | ydist = d; |
||
99 | } |
||
100 | 20964 | jiyarza | |
101 | 27049 | jpiera | /*
|
102 | * (non-Javadoc)
|
||
103 | 35475 | jpiera | * @see org.gvsig.fmap.geom.primitive.impl.Surface2D#cloneFShape()
|
104 | */
|
||
105 | public FShape cloneFShape() {
|
||
106 | return new Ellipse2D(getGeometryType(), id, projection, (GeneralPathX) gp.clone(), init, |
||
107 | end, ydist); |
||
108 | } |
||
109 | |||
110 | /*
|
||
111 | * (non-Javadoc)
|
||
112 | 27049 | jpiera | * @see org.gvsig.fmap.geom.primitive.impl.Surface2D#getShapeType()
|
113 | */
|
||
114 | 35475 | jpiera | public int getShapeType() { |
115 | return TYPES.ELLIPSE;
|
||
116 | } |
||
117 | 20964 | jiyarza | |
118 | 35475 | jpiera | /*
|
119 | * (non-Javadoc)
|
||
120 | * @see org.gvsig.fmap.geom.primitive.impl.OrientablePrimitive2D#transform(java.awt.geom.AffineTransform)
|
||
121 | */
|
||
122 | public void transform(AffineTransform at) { |
||
123 | 39122 | jldominguez | |
124 | if (at == null) { |
||
125 | return;
|
||
126 | } |
||
127 | |||
128 | 35475 | jpiera | Point2D center = new Point2D.Double((init.getX() + end.getX()) / 2, |
129 | (init.getY() + end.getY()) / 2);
|
||
130 | Point2D pdist = UtilFunctions.getPerpendicularPoint(init, end, center,
|
||
131 | ydist); |
||
132 | Point2D aux1 = new Point2D.Double(); |
||
133 | at.transform(init, aux1); |
||
134 | init = aux1; |
||
135 | Point2D aux2 = new Point2D.Double(); |
||
136 | at.transform(end, aux2); |
||
137 | end = aux2; |
||
138 | 20761 | jmvivo | |
139 | 35475 | jpiera | center = new Point2D.Double((init.getX() + end.getX()) / 2, (init |
140 | .getY() + end.getY()) / 2);
|
||
141 | 20761 | jmvivo | |
142 | 35475 | jpiera | Point2D aux3 = new Point2D.Double(); |
143 | at.transform(pdist, aux3); |
||
144 | ydist = center.distance(aux3); |
||
145 | gp.transform(at); |
||
146 | } |
||
147 | 20964 | jiyarza | |
148 | 35475 | jpiera | /*
|
149 | * (non-Javadoc)
|
||
150 | * @see org.gvsig.fmap.geom.primitive.impl.OrientablePrimitive2D#getStretchingHandlers()
|
||
151 | */
|
||
152 | public Handler[] getStretchingHandlers() { |
||
153 | ArrayList handlers = new ArrayList(); |
||
154 | Rectangle2D rect = this.getBounds2D(); |
||
155 | handlers |
||
156 | .add(new CenterHandler(0, rect.getCenterX(), rect.getCenterY())); |
||
157 | return (Handler[]) handlers.toArray(new Handler[0]); |
||
158 | } |
||
159 | 20964 | jiyarza | |
160 | 35475 | jpiera | /*
|
161 | * (non-Javadoc)
|
||
162 | * @see org.gvsig.fmap.geom.primitive.impl.OrientablePrimitive2D#getSelectHandlers()
|
||
163 | */
|
||
164 | public Handler[] getSelectHandlers() { |
||
165 | ArrayList handlers = new ArrayList(); |
||
166 | Rectangle2D rect = this.getBounds2D(); |
||
167 | handlers.add(new CenterSelHandler(0, rect.getCenterX(), rect |
||
168 | .getCenterY())); |
||
169 | handlers.add(new InitSelHandler(1, init.getX(), init.getY())); |
||
170 | handlers.add(new EndSelHandler(2, end.getX(), end.getY())); |
||
171 | Point2D mediop = new Point2D.Double((end.getX() + init.getX()) / 2, |
||
172 | (end.getY() + init.getY()) / 2);
|
||
173 | Point2D[] p = UtilFunctions.getPerpendicular(init, end, mediop); |
||
174 | Point2D u = UtilFunctions.getPoint(mediop, p[1], ydist); |
||
175 | Point2D d = UtilFunctions.getPoint(mediop, p[1], -ydist); |
||
176 | 20761 | jmvivo | |
177 | 35475 | jpiera | handlers.add(new RadioSelYHandler(3, u.getX(), u.getY())); |
178 | handlers.add(new RadioSelYHandler(4, d.getX(), d.getY())); |
||
179 | 20761 | jmvivo | |
180 | 35475 | jpiera | return (Handler[]) handlers.toArray(new Handler[0]); |
181 | } |
||
182 | 20761 | jmvivo | |
183 | 35475 | jpiera | /**
|
184 | * DOCUMENT ME!
|
||
185 | *
|
||
186 | * @author Vicente Caballero Navarro
|
||
187 | */
|
||
188 | class CenterHandler extends AbstractHandler implements Handler { |
||
189 | /**
|
||
190 | * Crea un nuevo PointHandler.
|
||
191 | *
|
||
192 | * @param i
|
||
193 | * DOCUMENT ME!
|
||
194 | * @param x
|
||
195 | * DOCUMENT ME!
|
||
196 | * @param y
|
||
197 | * DOCUMENT ME!
|
||
198 | */
|
||
199 | public CenterHandler(int i, double x, double y) { |
||
200 | point = new Point2D.Double(x, y); |
||
201 | index = i; |
||
202 | } |
||
203 | 20761 | jmvivo | |
204 | 35475 | jpiera | /**
|
205 | * DOCUMENT ME!
|
||
206 | *
|
||
207 | * @param x
|
||
208 | * DOCUMENT ME!
|
||
209 | * @param y
|
||
210 | * DOCUMENT ME!
|
||
211 | *
|
||
212 | * @return DOCUMENT ME!
|
||
213 | */
|
||
214 | public void move(double x, double y) { |
||
215 | Point point;
|
||
216 | for (int i = 0; i < gp.getNumCoords() ; i++) { |
||
217 | point = gp.getPointAt(i); |
||
218 | point.setX(point.getX() + x); |
||
219 | point.setY(point.getY() + y); |
||
220 | } |
||
221 | init = new Point2D.Double(init.getX() + x, init.getY() + y); |
||
222 | end = new Point2D.Double(end.getX() + x, end.getY() + y); |
||
223 | } |
||
224 | 20761 | jmvivo | |
225 | 35475 | jpiera | /**
|
226 | * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
||
227 | */
|
||
228 | public void set(double x, double y) { |
||
229 | } |
||
230 | } |
||
231 | 20964 | jiyarza | |
232 | 35475 | jpiera | /**
|
233 | * DOCUMENT ME!
|
||
234 | *
|
||
235 | * @author Vicente Caballero Navarro
|
||
236 | */
|
||
237 | class CenterSelHandler extends AbstractHandler implements Handler { |
||
238 | /**
|
||
239 | * Crea un nuevo PointHandler.
|
||
240 | *
|
||
241 | * @param i
|
||
242 | * DOCUMENT ME!
|
||
243 | * @param x
|
||
244 | * DOCUMENT ME!
|
||
245 | * @param y
|
||
246 | * DOCUMENT ME!
|
||
247 | */
|
||
248 | public CenterSelHandler(int i, double x, double y) { |
||
249 | point = new Point2D.Double(x, y); |
||
250 | index = i; |
||
251 | } |
||
252 | 20761 | jmvivo | |
253 | 35475 | jpiera | /**
|
254 | * DOCUMENT ME!
|
||
255 | *
|
||
256 | * @param x
|
||
257 | * DOCUMENT ME!
|
||
258 | * @param y
|
||
259 | * DOCUMENT ME!
|
||
260 | *
|
||
261 | * @return DOCUMENT ME!
|
||
262 | */
|
||
263 | public void move(double x, double y) { |
||
264 | Point point;
|
||
265 | for (int i = 0; i < gp.getNumCoords() ; i++) { |
||
266 | point = gp.getPointAt(i); |
||
267 | point.setX(point.getX() + x); |
||
268 | point.setY(point.getY() + y); |
||
269 | } |
||
270 | } |
||
271 | 20761 | jmvivo | |
272 | 35475 | jpiera | /**
|
273 | * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
||
274 | */
|
||
275 | public void set(double x, double y) { |
||
276 | Point2D center = new Point2D.Double((init.getX() + end.getX()) / 2, |
||
277 | (init.getY() + end.getY()) / 2);
|
||
278 | double dx = x - center.getX();
|
||
279 | double dy = y - center.getY();
|
||
280 | Point point;
|
||
281 | for (int i = 0; i < gp.getNumCoords() ; i++) { |
||
282 | point = gp.getPointAt(i); |
||
283 | point.setX(point.getX() + dx); |
||
284 | point.setY(point.getY() + dy); |
||
285 | } |
||
286 | init = new Point2D.Double(init.getX() + dx, init.getY() + dy); |
||
287 | end = new Point2D.Double(end.getX() + dx, end.getY() + dy); |
||
288 | } |
||
289 | } |
||
290 | 20761 | jmvivo | |
291 | 35475 | jpiera | /**
|
292 | * DOCUMENT ME!
|
||
293 | *
|
||
294 | * @author Vicente Caballero Navarro
|
||
295 | */
|
||
296 | class InitSelHandler extends AbstractHandler implements CuadrantHandler { |
||
297 | /**
|
||
298 | * Crea un nuevo PointHandler.
|
||
299 | *
|
||
300 | * @param i
|
||
301 | * DOCUMENT ME!
|
||
302 | * @param x
|
||
303 | * DOCUMENT ME!
|
||
304 | * @param y
|
||
305 | * DOCUMENT ME!
|
||
306 | */
|
||
307 | public InitSelHandler(int i, double x, double y) { |
||
308 | point = new Point2D.Double(x, y); |
||
309 | index = i; |
||
310 | } |
||
311 | 20761 | jmvivo | |
312 | 35475 | jpiera | /**
|
313 | * DOCUMENT ME!
|
||
314 | *
|
||
315 | * @param x
|
||
316 | * DOCUMENT ME!
|
||
317 | * @param y
|
||
318 | * DOCUMENT ME!
|
||
319 | *
|
||
320 | * @return DOCUMENT ME!
|
||
321 | */
|
||
322 | public void move(double x, double y) { |
||
323 | 20761 | jmvivo | |
324 | 35475 | jpiera | } |
325 | 20761 | jmvivo | |
326 | 35475 | jpiera | /**
|
327 | * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
||
328 | */
|
||
329 | public void set(double x, double y) { |
||
330 | // TODO comentado para quitar warning: double dx=x-init.getX();
|
||
331 | // TODO comentado para quitar warning: double dy=y-init.getY();
|
||
332 | Point2D center = new Point2D.Double((init.getX() + end.getX()) / 2, |
||
333 | (init.getY() + end.getY()) / 2);
|
||
334 | // Point2D[]
|
||
335 | // p1=TrigonometricalFunctions.getPerpendicular(init,end,center);
|
||
336 | // Point2D[]
|
||
337 | // p2=TrigonometricalFunctions.getPerpendicular(p1[0],p1[1],new
|
||
338 | // Point2D.Double(x,y));
|
||
339 | 20761 | jmvivo | |
340 | 35475 | jpiera | // Point2D
|
341 | // pl=TrigonometricalFunctions.getIntersection(p2[0],p2[1],p1[0],p1[1]);
|
||
342 | // double xdist=2*pl.distance(x,y);
|
||
343 | double xdist = 2 * center.distance(x, y); |
||
344 | // init=new Point2D.Double(init.getX()+dx,init.getY()+dy);
|
||
345 | init = UtilFunctions.getPoint(center, init, center.distance(x, y)); |
||
346 | end = UtilFunctions.getPoint(init, center, xdist); |
||
347 | Arc2D.Double arc = new Arc2D.Double(init.getX(), init.getY() |
||
348 | - ydist, xdist, 2 * ydist, 0, 360, Arc2D.OPEN); |
||
349 | // TODO comentado para quitar warning: Point2D rotationPoint = new
|
||
350 | // Point2D.Double(init.getX() + xdist /2, init.getY());
|
||
351 | 20761 | jmvivo | |
352 | 35475 | jpiera | double angle = UtilFunctions.getAngle(init, end);
|
353 | AffineTransform mT = AffineTransform.getRotateInstance(angle, init |
||
354 | .getX(), init.getY()); |
||
355 | gp = new GeneralPathX(arc.getPathIterator(null)); |
||
356 | gp.transform(mT); |
||
357 | 20761 | jmvivo | |
358 | 35475 | jpiera | } |
359 | } |
||
360 | 20964 | jiyarza | |
361 | 35475 | jpiera | /**
|
362 | * DOCUMENT ME!
|
||
363 | *
|
||
364 | * @author Vicente Caballero Navarro
|
||
365 | */
|
||
366 | class EndSelHandler extends AbstractHandler implements CuadrantHandler { |
||
367 | /**
|
||
368 | * Crea un nuevo PointHandler.
|
||
369 | *
|
||
370 | * @param i
|
||
371 | * DOCUMENT ME!
|
||
372 | * @param x
|
||
373 | * DOCUMENT ME!
|
||
374 | * @param y
|
||
375 | * DOCUMENT ME!
|
||
376 | */
|
||
377 | public EndSelHandler(int i, double x, double y) { |
||
378 | point = new Point2D.Double(x, y); |
||
379 | index = i; |
||
380 | } |
||
381 | 20761 | jmvivo | |
382 | 35475 | jpiera | /**
|
383 | * DOCUMENT ME!
|
||
384 | *
|
||
385 | * @param x
|
||
386 | * DOCUMENT ME!
|
||
387 | * @param y
|
||
388 | * DOCUMENT ME!
|
||
389 | *
|
||
390 | * @return DOCUMENT ME!
|
||
391 | */
|
||
392 | public void move(double x, double y) { |
||
393 | 20761 | jmvivo | |
394 | 35475 | jpiera | } |
395 | 20761 | jmvivo | |
396 | 35475 | jpiera | /**
|
397 | * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
||
398 | */
|
||
399 | public void set(double x, double y) { |
||
400 | // double dx=x-getPoint().getX();
|
||
401 | // double dy=y-getPoint().getY();
|
||
402 | Point2D center = new Point2D.Double((init.getX() + end.getX()) / 2, |
||
403 | (init.getY() + end.getY()) / 2);
|
||
404 | // Point2D[]
|
||
405 | // p1=TrigonometricalFunctions.getPerpendicular(init,end,center);
|
||
406 | // Point2D[]
|
||
407 | // p2=TrigonometricalFunctions.getPerpendicular(p1[0],p1[1],new
|
||
408 | // Point2D.Double(x,y));
|
||
409 | 20761 | jmvivo | |
410 | 35475 | jpiera | // Point2D
|
411 | // pl=TrigonometricalFunctions.getIntersection(p2[0],p2[1],p1[0],p1[1]);
|
||
412 | // double xdist=2*pl.distance(x,y);
|
||
413 | double xdist = 2 * center.distance(x, y); |
||
414 | end = UtilFunctions.getPoint(center, end, center.distance(x, y)); |
||
415 | // end=new Point2D.Double(end.getX()+dx,end.getY()+dy);
|
||
416 | init = UtilFunctions.getPoint(end, center, xdist); |
||
417 | Arc2D.Double arc = new Arc2D.Double(init.getX(), init.getY() |
||
418 | - ydist, xdist, 2 * ydist, 0, 360, Arc2D.OPEN); |
||
419 | // Point2D rotationPoint = new Point2D.Double(init.getX() + xdist
|
||
420 | // /2, init.getY());
|
||
421 | 20761 | jmvivo | |
422 | 35475 | jpiera | double angle = UtilFunctions.getAngle(init, end);
|
423 | AffineTransform mT = AffineTransform.getRotateInstance(angle, init |
||
424 | .getX(), init.getY()); |
||
425 | gp = new GeneralPathX(arc.getPathIterator(null)); |
||
426 | gp.transform(mT); |
||
427 | 20761 | jmvivo | |
428 | 35475 | jpiera | } |
429 | } |
||
430 | 20964 | jiyarza | |
431 | 35475 | jpiera | /**
|
432 | * DOCUMENT ME!
|
||
433 | *
|
||
434 | * @author Vicente Caballero Navarro
|
||
435 | */
|
||
436 | class RadioSelYHandler extends AbstractHandler implements CuadrantHandler { |
||
437 | /**
|
||
438 | * Crea un nuevo PointHandler.
|
||
439 | *
|
||
440 | * @param i
|
||
441 | * DOCUMENT ME!
|
||
442 | * @param x
|
||
443 | * DOCUMENT ME!
|
||
444 | * @param y
|
||
445 | * DOCUMENT ME!
|
||
446 | */
|
||
447 | public RadioSelYHandler(int i, double x, double y) { |
||
448 | point = new Point2D.Double(x, y); |
||
449 | index = i; |
||
450 | } |
||
451 | 20761 | jmvivo | |
452 | 35475 | jpiera | /**
|
453 | * DOCUMENT ME!
|
||
454 | *
|
||
455 | * @param x
|
||
456 | * DOCUMENT ME!
|
||
457 | * @param y
|
||
458 | * DOCUMENT ME!
|
||
459 | *
|
||
460 | * @return DOCUMENT ME!
|
||
461 | */
|
||
462 | public void move(double x, double y) { |
||
463 | 20761 | jmvivo | |
464 | 35475 | jpiera | } |
465 | 20761 | jmvivo | |
466 | 35475 | jpiera | /**
|
467 | * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
||
468 | */
|
||
469 | public void set(double x, double y) { |
||
470 | ydist = new Point2D.Double((init.getX() + end.getX()) / 2, (init |
||
471 | .getY() + end.getY()) / 2).distance(x, y);
|
||
472 | // ydist=getSelectHandlers()[1].getPoint().distance(x,y);
|
||
473 | // Point2D center=new Point2D.Double((init.getX() + end.getX()) / 2,
|
||
474 | // (init.getY() + end.getY()) / 2);
|
||
475 | // Point2D[]
|
||
476 | // p=TrigonometricalFunctions.getPerpendicular(init,end,new
|
||
477 | // Point2D.Double(x,y));
|
||
478 | // Point2D
|
||
479 | // pl=TrigonometricalFunctions.getIntersection(p[0],p[1],init,end);
|
||
480 | // double xdist=2*pl.distance(x,y);
|
||
481 | double xdist = init.distance(end);
|
||
482 | Arc2D.Double arc = new Arc2D.Double(init.getX(), init.getY() |
||
483 | - ydist, xdist, 2 * ydist, 0, 360, Arc2D.OPEN); |
||
484 | // Point2D rotationPoint = new Point2D.Double(init.getX() + xdist
|
||
485 | // /2, init.getY());
|
||
486 | 20761 | jmvivo | |
487 | 35475 | jpiera | double angle = UtilFunctions.getAngle(init, end);
|
488 | AffineTransform mT = AffineTransform.getRotateInstance(angle, init |
||
489 | .getX(), init.getY()); |
||
490 | gp = new GeneralPathX(arc.getPathIterator(null)); |
||
491 | gp.transform(mT); |
||
492 | } |
||
493 | } |
||
494 | 20761 | jmvivo | |
495 | 35475 | jpiera | /*
|
496 | * (non-Javadoc)
|
||
497 | *
|
||
498 | * @see com.iver.cit.gvsig.fmap.core.FPolyline2D#intersects(java.awt.geom.Rectangle2D)
|
||
499 | */
|
||
500 | public boolean intersects(Rectangle2D r) { |
||
501 | return gp.intersects(r);
|
||
502 | } |
||
503 | 20761 | jmvivo | |
504 | 35475 | jpiera | /* (non-Javadoc)
|
505 | * @see org.gvsig.fmap.geom.primitive.Ellipse#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point, double)
|
||
506 | */
|
||
507 | public void setPoints(Point axis1Start, Point axis1End, double axis2Length) { |
||
508 | Point2D _axis1Start = new java.awt.geom.Point2D.Double(axis1Start.getCoordinateAt(0), axis1Start.getCoordinateAt(1)); |
||
509 | Point2D _axis1End = new java.awt.geom.Point2D.Double(axis1End.getCoordinateAt(0), axis1End.getCoordinateAt(1)); |
||
510 | setPoints(_axis1Start, _axis1End, axis2Length); |
||
511 | } |
||
512 | 26788 | jpiera | |
513 | 35475 | jpiera | /* (non-Javadoc)
|
514 | * @see org.gvsig.fmap.geom.primitive.Surface2D#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
||
515 | */
|
||
516 | public void setGeneralPath(GeneralPathX generalPathX) { |
||
517 | throw new UnsupportedOperationException("Use setPoints(Point axis1Start, Point axis1End, double axis2Length)"); |
||
518 | } |
||
519 | 26788 | jpiera | |
520 | 35475 | jpiera | /* (non-Javadoc)
|
521 | * @see org.gvsig.fmap.geom.primitive.Ellipse#setPoints(java.awt.geom.Point2D, java.awt.geom.Point2D, double)
|
||
522 | */
|
||
523 | private void setPoints(Point2D axis1Start, Point2D axis1End, |
||
524 | double axis2Length) {
|
||
525 | double xAxis = axis1Start.distance(axis1End);
|
||
526 | Arc2D.Double arc = new Arc2D.Double(axis1Start.getX(), axis1Start |
||
527 | .getY() |
||
528 | - axis2Length, xAxis, 2 * axis2Length, 0, 360, Arc2D.OPEN); |
||
529 | // TODO L?nea comentada para quitar warning: Point2D rotationPoint = new
|
||
530 | // Point2D.Double(axis1Start.getX() + xAxis /2, axis1Start.getY());
|
||
531 | double angle = UtilFunctions.getAngle(axis1Start, axis1End);
|
||
532 | AffineTransform mT = AffineTransform.getRotateInstance(angle, |
||
533 | axis1Start.getX(), axis1Start.getY()); |
||
534 | GeneralPathX gp = new GeneralPathX(arc.getPathIterator(null)); |
||
535 | gp.transform(mT); |
||
536 | this.gp = new GeneralPathX(gp.getPathIterator(null)); |
||
537 | this.init = axis1Start;
|
||
538 | this.end = axis1End;
|
||
539 | this.ydist = axis2Length;
|
||
540 | } |
||
541 | 26810 | jpiera | |
542 | 35475 | jpiera | /* (non-Javadoc)
|
543 | * @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1End()
|
||
544 | */
|
||
545 | public Point getAxis1End() { |
||
546 | try {
|
||
547 | return new org.gvsig.fmap.geom.primitive.impl.Point2D(end); |
||
548 | } catch (Exception e){ |
||
549 | return null; |
||
550 | } |
||
551 | } |
||
552 | 26810 | jpiera | |
553 | 35475 | jpiera | /* (non-Javadoc)
|
554 | * @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis1Start()
|
||
555 | */
|
||
556 | public Point getAxis1Start() { |
||
557 | try {
|
||
558 | return new org.gvsig.fmap.geom.primitive.impl.Point2D(init); |
||
559 | } catch (Exception e){ |
||
560 | return null; |
||
561 | } |
||
562 | } |
||
563 | 26810 | jpiera | |
564 | 35475 | jpiera | /* (non-Javadoc)
|
565 | * @see org.gvsig.fmap.geom.primitive.Ellipse#getAxis2Dist()
|
||
566 | */
|
||
567 | public double getAxis2Dist() { |
||
568 | return ydist;
|
||
569 | } |
||
570 | 26788 | jpiera | |
571 | 20761 | jmvivo | } |