svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / Arc2D.java @ 20964
History | View | Annotate | Download (12 KB)
1 |
/*
|
---|---|
2 |
* Created on 09-feb-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
21 |
USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib��ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package org.gvsig.fmap.geom.primitive; |
46 |
|
47 |
import java.awt.geom.AffineTransform; |
48 |
import java.awt.geom.Rectangle2D; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.util.ArrayList; |
51 |
|
52 |
import org.cresques.cts.IProjection; |
53 |
import org.gvsig.fmap.geom.GeometryManager; |
54 |
import org.gvsig.fmap.geom.aggregate.MultiPoint3D; |
55 |
import org.gvsig.fmap.geom.handler.AbstractHandler; |
56 |
import org.gvsig.fmap.geom.handler.CenterHandler; |
57 |
import org.gvsig.fmap.geom.handler.FinalHandler; |
58 |
import org.gvsig.fmap.geom.handler.Handler; |
59 |
import org.gvsig.fmap.geom.type.GeometryType; |
60 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
61 |
|
62 |
|
63 |
|
64 |
/**
|
65 |
* DOCUMENT ME!
|
66 |
*
|
67 |
* @author Vicente Caballero Navarro
|
68 |
*/
|
69 |
public class Arc2D extends Curve2D implements Arc { |
70 |
|
71 |
private static final long serialVersionUID = 1L; |
72 |
|
73 |
private static GeometryType geomType = GeometryManager.getInstance() |
74 |
.registerGeometryType(Arc2D.class);
|
75 |
|
76 |
public static int GEOM_TYPE = geomType.getType(); |
77 |
|
78 |
private Point2D init; |
79 |
private Point2D center; |
80 |
private Point2D end; |
81 |
/**
|
82 |
* DOCUMENT ME!
|
83 |
*
|
84 |
* @param gpx
|
85 |
*/
|
86 |
public Arc2D(String id, IProjection projection, GeneralPathX gpx, Point2D i,Point2D c, Point2D e) { |
87 |
super(id, projection, gpx);
|
88 |
init=i; |
89 |
center=c; |
90 |
end=e; |
91 |
} |
92 |
public Point2D getInit(){ |
93 |
return init;
|
94 |
} |
95 |
public Point2D getEnd(){ |
96 |
return end;
|
97 |
} |
98 |
public Point2D getCenter(){ |
99 |
return UtilFunctions.getCenter(init, center,end);
|
100 |
} |
101 |
public Point2D getMid(){ |
102 |
return center;
|
103 |
} |
104 |
/* (non-Javadoc)
|
105 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
106 |
*/
|
107 |
public FShape cloneFShape() {
|
108 |
Arc2D arc=new Arc2D(id, projection, (GeneralPathX) gp.clone(),init,center,end); |
109 |
return arc;
|
110 |
} |
111 |
public void transform(AffineTransform at) { |
112 |
gp.transform(at); |
113 |
InitHandler inithandler=(InitHandler)getStretchingHandlers()[0];
|
114 |
//CenterHandler centerhandler=(CenterHandler)getHandlers()[1];
|
115 |
EndHandler endhandler=(EndHandler)getStretchingHandlers()[1];
|
116 |
Point2D aux1=new Point2D.Double(); |
117 |
Point2D aux2=new Point2D.Double(); |
118 |
Point2D aux3=new Point2D.Double(); |
119 |
at.transform(inithandler.getPoint(),aux1); |
120 |
inithandler.setPoint(aux1); |
121 |
//at.transform(centerhandler.getPoint(),aux2);
|
122 |
//centerhandler.setPoint(aux2);
|
123 |
at.transform(endhandler.getPoint(),aux3); |
124 |
endhandler.setPoint(aux3); |
125 |
CenterSelHandler centerhandler=(CenterSelHandler)getSelectHandlers()[1];
|
126 |
at.transform(centerhandler.getPoint(),aux2); |
127 |
centerhandler.setPoint(aux2); |
128 |
|
129 |
} |
130 |
/**
|
131 |
* @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
|
132 |
*/
|
133 |
public int getShapeType() { |
134 |
return FShape.ARC;
|
135 |
} |
136 |
/**
|
137 |
* DOCUMENT ME!
|
138 |
*
|
139 |
* @return DOCUMENT ME!
|
140 |
*/
|
141 |
public Handler[] getStretchingHandlers() { |
142 |
ArrayList handlers = new ArrayList(); |
143 |
|
144 |
handlers.add(new InitHandler(0, init.getX(), init.getY())); |
145 |
//handlers.add(new CenterHandler(1, center.getX(), center.getY()));
|
146 |
handlers.add(new EndHandler(1, end.getX(), end.getY())); |
147 |
|
148 |
return (Handler[]) handlers.toArray(new Handler[0]); |
149 |
} |
150 |
|
151 |
public Handler[] getSelectHandlers() { |
152 |
ArrayList handlers = new ArrayList(); |
153 |
|
154 |
handlers.add(new InitSelHandler(0, init.getX(), init.getY())); |
155 |
handlers.add(new CenterSelHandler(1, center.getX(), center.getY())); |
156 |
handlers.add(new EndSelHandler(2, end.getX(), end.getY())); |
157 |
|
158 |
return (Handler[]) handlers.toArray(new Handler[0]); |
159 |
} |
160 |
/**
|
161 |
* DOCUMENT ME!
|
162 |
*
|
163 |
* @author Vicente Caballero Navarro
|
164 |
*/
|
165 |
class CenterSelHandler extends AbstractHandler implements CenterHandler{ |
166 |
/**
|
167 |
* Crea un nuevo PointHandler.
|
168 |
*
|
169 |
* @param i DOCUMENT ME!
|
170 |
* @param x DOCUMENT ME!
|
171 |
* @param y DOCUMENT ME!
|
172 |
*/
|
173 |
public CenterSelHandler(int i, double x, double y) { |
174 |
center = new Point2D.Double(x, y); |
175 |
index = i; |
176 |
} |
177 |
|
178 |
/**
|
179 |
* DOCUMENT ME!
|
180 |
*
|
181 |
* @param x DOCUMENT ME!
|
182 |
* @param y DOCUMENT ME!
|
183 |
*
|
184 |
* @return DOCUMENT ME!
|
185 |
*/
|
186 |
public void move(double x, double y) { |
187 |
} |
188 |
public void setPoint(Point2D p){ |
189 |
center=p; |
190 |
} |
191 |
public Point2D getPoint(){ |
192 |
return center;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
197 |
*/
|
198 |
public void set(double x, double y) { |
199 |
center=new Point2D.Double(x,y); |
200 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init, center, end); |
201 |
gp = new GeneralPathX(arco);
|
202 |
} |
203 |
} |
204 |
|
205 |
/**
|
206 |
* DOCUMENT ME!
|
207 |
*
|
208 |
* @author Vicente Caballero Navarro
|
209 |
*/
|
210 |
class InitHandler extends AbstractHandler implements FinalHandler{ |
211 |
/**
|
212 |
* Crea un nuevo PointHandler.
|
213 |
*
|
214 |
* @param i DOCUMENT ME!
|
215 |
* @param x DOCUMENT ME!
|
216 |
* @param y DOCUMENT ME!
|
217 |
*/
|
218 |
public InitHandler(int i, double x, double y) { |
219 |
init = new Point2D.Double(x, y); |
220 |
index = i; |
221 |
} |
222 |
|
223 |
/**
|
224 |
* DOCUMENT ME!
|
225 |
*
|
226 |
* @param x DOCUMENT ME!
|
227 |
* @param y DOCUMENT ME!
|
228 |
*
|
229 |
* @return DOCUMENT ME!
|
230 |
*/
|
231 |
public void move(double x, double y) { |
232 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
233 |
double dist=mediop.distance(center);
|
234 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
235 |
|
236 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
237 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
238 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
239 |
dist=-dist; |
240 |
} |
241 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
242 |
|
243 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
244 |
gp=new GeneralPathX(arco);
|
245 |
} |
246 |
public void setPoint(Point2D p){ |
247 |
init=p; |
248 |
} |
249 |
public Point2D getPoint(){ |
250 |
return init;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
255 |
*/
|
256 |
public void set(double x, double y) { |
257 |
} |
258 |
} |
259 |
|
260 |
/**
|
261 |
* DOCUMENT ME!
|
262 |
*
|
263 |
* @author Vicente Caballero Navarro
|
264 |
*/
|
265 |
class EndHandler extends AbstractHandler implements FinalHandler{ |
266 |
/**
|
267 |
* Crea un nuevo PointHandler.
|
268 |
*
|
269 |
* @param i DOCUMENT ME!
|
270 |
* @param x DOCUMENT ME!
|
271 |
* @param y DOCUMENT ME!
|
272 |
*/
|
273 |
public EndHandler(int i, double x, double y) { |
274 |
end = new Point2D.Double(x, y); |
275 |
index = i; |
276 |
} |
277 |
|
278 |
/**
|
279 |
* DOCUMENT ME!
|
280 |
*
|
281 |
* @param x DOCUMENT ME!
|
282 |
* @param y DOCUMENT ME!
|
283 |
*
|
284 |
* @return DOCUMENT ME!
|
285 |
*/
|
286 |
public void move(double x, double y) { |
287 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
288 |
double dist=mediop.distance(center);
|
289 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
290 |
|
291 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
292 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
293 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
294 |
dist=-dist; |
295 |
} |
296 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
297 |
|
298 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
299 |
gp=new GeneralPathX(arco);
|
300 |
} |
301 |
public void setPoint(Point2D p){ |
302 |
end=p; |
303 |
} |
304 |
public Point2D getPoint(){ |
305 |
return end;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
310 |
*/
|
311 |
public void set(double x, double y) { |
312 |
|
313 |
} |
314 |
} |
315 |
|
316 |
/**
|
317 |
* DOCUMENT ME!
|
318 |
*
|
319 |
* @author Vicente Caballero Navarro
|
320 |
*/
|
321 |
class InitSelHandler extends AbstractHandler implements FinalHandler{ |
322 |
/**
|
323 |
* Crea un nuevo PointHandler.
|
324 |
*
|
325 |
* @param i DOCUMENT ME!
|
326 |
* @param x DOCUMENT ME!
|
327 |
* @param y DOCUMENT ME!
|
328 |
*/
|
329 |
public InitSelHandler(int i, double x, double y) { |
330 |
init = new Point2D.Double(x, y); |
331 |
index = i; |
332 |
} |
333 |
|
334 |
/**
|
335 |
* DOCUMENT ME!
|
336 |
*
|
337 |
* @param x DOCUMENT ME!
|
338 |
* @param y DOCUMENT ME!
|
339 |
*
|
340 |
* @return DOCUMENT ME!
|
341 |
*/
|
342 |
public void move(double x, double y) { |
343 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
344 |
double dist=mediop.distance(center);
|
345 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
346 |
|
347 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
348 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
349 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
350 |
dist=-dist; |
351 |
} |
352 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
353 |
|
354 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
355 |
gp=new GeneralPathX(arco);
|
356 |
} |
357 |
public void setPoint(Point2D p){ |
358 |
init=p; |
359 |
} |
360 |
public Point2D getPoint(){ |
361 |
return init;
|
362 |
} |
363 |
|
364 |
/**
|
365 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
366 |
*/
|
367 |
public void set(double x, double y) { |
368 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
369 |
double dist=mediop.distance(center);
|
370 |
init=new Point2D.Double(x,y); |
371 |
|
372 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
373 |
// TODO comentado para quitar warning: Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop);
|
374 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
375 |
dist=-dist; |
376 |
} |
377 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
378 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
379 |
gp=new GeneralPathX(arco);
|
380 |
} |
381 |
} |
382 |
|
383 |
/**
|
384 |
* DOCUMENT ME!
|
385 |
*
|
386 |
* @author Vicente Caballero Navarro
|
387 |
*/
|
388 |
class EndSelHandler extends AbstractHandler implements FinalHandler{ |
389 |
/**
|
390 |
* Crea un nuevo PointHandler.
|
391 |
*
|
392 |
* @param i DOCUMENT ME!
|
393 |
* @param x DOCUMENT ME!
|
394 |
* @param y DOCUMENT ME!
|
395 |
*/
|
396 |
public EndSelHandler(int i, double x, double y) { |
397 |
end = new Point2D.Double(x, y); |
398 |
index = i; |
399 |
} |
400 |
|
401 |
/**
|
402 |
* DOCUMENT ME!
|
403 |
*
|
404 |
* @param x DOCUMENT ME!
|
405 |
* @param y DOCUMENT ME!
|
406 |
*
|
407 |
* @return DOCUMENT ME!
|
408 |
*/
|
409 |
public void move(double x, double y) { |
410 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
411 |
double dist=mediop.distance(center);
|
412 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
413 |
|
414 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
415 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
416 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
417 |
dist=-dist; |
418 |
} |
419 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
420 |
|
421 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
422 |
gp=new GeneralPathX(arco);
|
423 |
} |
424 |
public void setPoint(Point2D p){ |
425 |
end=p; |
426 |
} |
427 |
public Point2D getPoint(){ |
428 |
return end;
|
429 |
} |
430 |
|
431 |
/**
|
432 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
433 |
*/
|
434 |
public void set(double x, double y) { |
435 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
436 |
double dist=mediop.distance(center);
|
437 |
end=new Point2D.Double(x,y); |
438 |
|
439 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
440 |
// TODO comentado para quitar warning: Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop);
|
441 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
442 |
dist=-dist; |
443 |
} |
444 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
445 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
446 |
gp=new GeneralPathX(arco);
|
447 |
} |
448 |
} |
449 |
|
450 |
/* (non-Javadoc)
|
451 |
* @see com.iver.cit.gvsig.fmap.core.FPolyline2D#intersects(java.awt.geom.Rectangle2D)
|
452 |
*/
|
453 |
public boolean intersects(Rectangle2D r) { |
454 |
return gp.intersects(r);
|
455 |
} |
456 |
|
457 |
public GeometryType getGeometryType() {
|
458 |
return geomType;
|
459 |
} |
460 |
|
461 |
} |