root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / Arc2D.java @ 21308
History | View | Annotate | Download (11.9 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.Point2D; |
49 |
import java.awt.geom.Rectangle2D; |
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.handler.AbstractHandler; |
55 |
import org.gvsig.fmap.geom.handler.CenterHandler; |
56 |
import org.gvsig.fmap.geom.handler.FinalHandler; |
57 |
import org.gvsig.fmap.geom.handler.Handler; |
58 |
import org.gvsig.fmap.geom.type.GeometryType; |
59 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
60 |
|
61 |
|
62 |
|
63 |
/**
|
64 |
* DOCUMENT ME!
|
65 |
*
|
66 |
* @author Vicente Caballero Navarro
|
67 |
*/
|
68 |
public class Arc2D extends Curve2D implements Arc { |
69 |
|
70 |
private static final long serialVersionUID = 1L; |
71 |
|
72 |
private static GeometryType geomType = GeometryManager.getInstance() |
73 |
.registerGeometryType(Arc2D.class);
|
74 |
|
75 |
public static int CODE = geomType.getType(); |
76 |
|
77 |
private Point2D init; |
78 |
private Point2D center; |
79 |
private Point2D end; |
80 |
/**
|
81 |
* DOCUMENT ME!
|
82 |
*
|
83 |
* @param gpx
|
84 |
*/
|
85 |
public Arc2D(String id, IProjection projection, GeneralPathX gpx, Point2D i,Point2D c, Point2D e) { |
86 |
super(id, projection, gpx);
|
87 |
init=i; |
88 |
center=c; |
89 |
end=e; |
90 |
} |
91 |
public Point2D getInit(){ |
92 |
return init;
|
93 |
} |
94 |
public Point2D getEnd(){ |
95 |
return end;
|
96 |
} |
97 |
public Point2D getCenter(){ |
98 |
return UtilFunctions.getCenter(init, center,end);
|
99 |
} |
100 |
public Point2D getMid(){ |
101 |
return center;
|
102 |
} |
103 |
/* (non-Javadoc)
|
104 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
105 |
*/
|
106 |
public FShape cloneFShape() {
|
107 |
Arc2D arc=new Arc2D(id, projection, (GeneralPathX) gp.clone(),init,center,end); |
108 |
return arc;
|
109 |
} |
110 |
public void transform(AffineTransform at) { |
111 |
gp.transform(at); |
112 |
InitHandler inithandler=(InitHandler)getStretchingHandlers()[0];
|
113 |
//CenterHandler centerhandler=(CenterHandler)getHandlers()[1];
|
114 |
EndHandler endhandler=(EndHandler)getStretchingHandlers()[1];
|
115 |
Point2D aux1=new Point2D.Double(); |
116 |
Point2D aux2=new Point2D.Double(); |
117 |
Point2D aux3=new Point2D.Double(); |
118 |
at.transform(inithandler.getPoint(),aux1); |
119 |
inithandler.setPoint(aux1); |
120 |
//at.transform(centerhandler.getPoint(),aux2);
|
121 |
//centerhandler.setPoint(aux2);
|
122 |
at.transform(endhandler.getPoint(),aux3); |
123 |
endhandler.setPoint(aux3); |
124 |
CenterSelHandler centerhandler=(CenterSelHandler)getSelectHandlers()[1];
|
125 |
at.transform(centerhandler.getPoint(),aux2); |
126 |
centerhandler.setPoint(aux2); |
127 |
|
128 |
} |
129 |
/**
|
130 |
* @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
|
131 |
*/
|
132 |
public int getShapeType() { |
133 |
return FShape.ARC;
|
134 |
} |
135 |
/**
|
136 |
* DOCUMENT ME!
|
137 |
*
|
138 |
* @return DOCUMENT ME!
|
139 |
*/
|
140 |
public Handler[] getStretchingHandlers() { |
141 |
ArrayList handlers = new ArrayList(); |
142 |
|
143 |
handlers.add(new InitHandler(0, init.getX(), init.getY())); |
144 |
//handlers.add(new CenterHandler(1, center.getX(), center.getY()));
|
145 |
handlers.add(new EndHandler(1, end.getX(), end.getY())); |
146 |
|
147 |
return (Handler[]) handlers.toArray(new Handler[0]); |
148 |
} |
149 |
|
150 |
public Handler[] getSelectHandlers() { |
151 |
ArrayList handlers = new ArrayList(); |
152 |
|
153 |
handlers.add(new InitSelHandler(0, init.getX(), init.getY())); |
154 |
handlers.add(new CenterSelHandler(1, center.getX(), center.getY())); |
155 |
handlers.add(new EndSelHandler(2, end.getX(), end.getY())); |
156 |
|
157 |
return (Handler[]) handlers.toArray(new Handler[0]); |
158 |
} |
159 |
/**
|
160 |
* DOCUMENT ME!
|
161 |
*
|
162 |
* @author Vicente Caballero Navarro
|
163 |
*/
|
164 |
class CenterSelHandler extends AbstractHandler implements CenterHandler{ |
165 |
/**
|
166 |
* Crea un nuevo PointHandler.
|
167 |
*
|
168 |
* @param i DOCUMENT ME!
|
169 |
* @param x DOCUMENT ME!
|
170 |
* @param y DOCUMENT ME!
|
171 |
*/
|
172 |
public CenterSelHandler(int i, double x, double y) { |
173 |
center = new Point2D.Double(x, y); |
174 |
index = i; |
175 |
} |
176 |
|
177 |
/**
|
178 |
* DOCUMENT ME!
|
179 |
*
|
180 |
* @param x DOCUMENT ME!
|
181 |
* @param y DOCUMENT ME!
|
182 |
*
|
183 |
* @return DOCUMENT ME!
|
184 |
*/
|
185 |
public void move(double x, double y) { |
186 |
} |
187 |
public void setPoint(Point2D p){ |
188 |
center=p; |
189 |
} |
190 |
public Point2D getPoint(){ |
191 |
return center;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
196 |
*/
|
197 |
public void set(double x, double y) { |
198 |
center=new Point2D.Double(x,y); |
199 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init, center, end); |
200 |
gp = new GeneralPathX(arco);
|
201 |
} |
202 |
} |
203 |
|
204 |
/**
|
205 |
* DOCUMENT ME!
|
206 |
*
|
207 |
* @author Vicente Caballero Navarro
|
208 |
*/
|
209 |
class InitHandler extends AbstractHandler implements FinalHandler{ |
210 |
/**
|
211 |
* Crea un nuevo PointHandler.
|
212 |
*
|
213 |
* @param i DOCUMENT ME!
|
214 |
* @param x DOCUMENT ME!
|
215 |
* @param y DOCUMENT ME!
|
216 |
*/
|
217 |
public InitHandler(int i, double x, double y) { |
218 |
init = new Point2D.Double(x, y); |
219 |
index = i; |
220 |
} |
221 |
|
222 |
/**
|
223 |
* DOCUMENT ME!
|
224 |
*
|
225 |
* @param x DOCUMENT ME!
|
226 |
* @param y DOCUMENT ME!
|
227 |
*
|
228 |
* @return DOCUMENT ME!
|
229 |
*/
|
230 |
public void move(double x, double y) { |
231 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
232 |
double dist=mediop.distance(center);
|
233 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
234 |
|
235 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
236 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
237 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
238 |
dist=-dist; |
239 |
} |
240 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
241 |
|
242 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
243 |
gp=new GeneralPathX(arco);
|
244 |
} |
245 |
public void setPoint(Point2D p){ |
246 |
init=p; |
247 |
} |
248 |
public Point2D getPoint(){ |
249 |
return init;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
254 |
*/
|
255 |
public void set(double x, double y) { |
256 |
} |
257 |
} |
258 |
|
259 |
/**
|
260 |
* DOCUMENT ME!
|
261 |
*
|
262 |
* @author Vicente Caballero Navarro
|
263 |
*/
|
264 |
class EndHandler extends AbstractHandler implements FinalHandler{ |
265 |
/**
|
266 |
* Crea un nuevo PointHandler.
|
267 |
*
|
268 |
* @param i DOCUMENT ME!
|
269 |
* @param x DOCUMENT ME!
|
270 |
* @param y DOCUMENT ME!
|
271 |
*/
|
272 |
public EndHandler(int i, double x, double y) { |
273 |
end = new Point2D.Double(x, y); |
274 |
index = i; |
275 |
} |
276 |
|
277 |
/**
|
278 |
* DOCUMENT ME!
|
279 |
*
|
280 |
* @param x DOCUMENT ME!
|
281 |
* @param y DOCUMENT ME!
|
282 |
*
|
283 |
* @return DOCUMENT ME!
|
284 |
*/
|
285 |
public void move(double x, double y) { |
286 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
287 |
double dist=mediop.distance(center);
|
288 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
289 |
|
290 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
291 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
292 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
293 |
dist=-dist; |
294 |
} |
295 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
296 |
|
297 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
298 |
gp=new GeneralPathX(arco);
|
299 |
} |
300 |
public void setPoint(Point2D p){ |
301 |
end=p; |
302 |
} |
303 |
public Point2D getPoint(){ |
304 |
return end;
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
309 |
*/
|
310 |
public void set(double x, double y) { |
311 |
|
312 |
} |
313 |
} |
314 |
|
315 |
/**
|
316 |
* DOCUMENT ME!
|
317 |
*
|
318 |
* @author Vicente Caballero Navarro
|
319 |
*/
|
320 |
class InitSelHandler extends AbstractHandler implements FinalHandler{ |
321 |
/**
|
322 |
* Crea un nuevo PointHandler.
|
323 |
*
|
324 |
* @param i DOCUMENT ME!
|
325 |
* @param x DOCUMENT ME!
|
326 |
* @param y DOCUMENT ME!
|
327 |
*/
|
328 |
public InitSelHandler(int i, double x, double y) { |
329 |
init = new Point2D.Double(x, y); |
330 |
index = i; |
331 |
} |
332 |
|
333 |
/**
|
334 |
* DOCUMENT ME!
|
335 |
*
|
336 |
* @param x DOCUMENT ME!
|
337 |
* @param y DOCUMENT ME!
|
338 |
*
|
339 |
* @return DOCUMENT ME!
|
340 |
*/
|
341 |
public void move(double x, double y) { |
342 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
343 |
double dist=mediop.distance(center);
|
344 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
345 |
|
346 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
347 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
348 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
349 |
dist=-dist; |
350 |
} |
351 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
352 |
|
353 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
354 |
gp=new GeneralPathX(arco);
|
355 |
} |
356 |
public void setPoint(Point2D p){ |
357 |
init=p; |
358 |
} |
359 |
public Point2D getPoint(){ |
360 |
return init;
|
361 |
} |
362 |
|
363 |
/**
|
364 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
365 |
*/
|
366 |
public void set(double x, double y) { |
367 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
368 |
double dist=mediop.distance(center);
|
369 |
init=new Point2D.Double(x,y); |
370 |
|
371 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
372 |
// TODO comentado para quitar warning: Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop);
|
373 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
374 |
dist=-dist; |
375 |
} |
376 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
377 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
378 |
gp=new GeneralPathX(arco);
|
379 |
} |
380 |
} |
381 |
|
382 |
/**
|
383 |
* DOCUMENT ME!
|
384 |
*
|
385 |
* @author Vicente Caballero Navarro
|
386 |
*/
|
387 |
class EndSelHandler extends AbstractHandler implements FinalHandler{ |
388 |
/**
|
389 |
* Crea un nuevo PointHandler.
|
390 |
*
|
391 |
* @param i DOCUMENT ME!
|
392 |
* @param x DOCUMENT ME!
|
393 |
* @param y DOCUMENT ME!
|
394 |
*/
|
395 |
public EndSelHandler(int i, double x, double y) { |
396 |
end = new Point2D.Double(x, y); |
397 |
index = i; |
398 |
} |
399 |
|
400 |
/**
|
401 |
* DOCUMENT ME!
|
402 |
*
|
403 |
* @param x DOCUMENT ME!
|
404 |
* @param y DOCUMENT ME!
|
405 |
*
|
406 |
* @return DOCUMENT ME!
|
407 |
*/
|
408 |
public void move(double x, double y) { |
409 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
410 |
double dist=mediop.distance(center);
|
411 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
412 |
|
413 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
414 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
415 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
416 |
dist=-dist; |
417 |
} |
418 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
419 |
|
420 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
421 |
gp=new GeneralPathX(arco);
|
422 |
} |
423 |
public void setPoint(Point2D p){ |
424 |
end=p; |
425 |
} |
426 |
public Point2D getPoint(){ |
427 |
return end;
|
428 |
} |
429 |
|
430 |
/**
|
431 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
432 |
*/
|
433 |
public void set(double x, double y) { |
434 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
435 |
double dist=mediop.distance(center);
|
436 |
end=new Point2D.Double(x,y); |
437 |
|
438 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
439 |
// TODO comentado para quitar warning: Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop);
|
440 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
441 |
dist=-dist; |
442 |
} |
443 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
444 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end); |
445 |
gp=new GeneralPathX(arco);
|
446 |
} |
447 |
} |
448 |
|
449 |
/* (non-Javadoc)
|
450 |
* @see com.iver.cit.gvsig.fmap.core.FPolyline2D#intersects(java.awt.geom.Rectangle2D)
|
451 |
*/
|
452 |
public boolean intersects(Rectangle2D r) { |
453 |
return gp.intersects(r);
|
454 |
} |
455 |
|
456 |
public GeometryType getGeometryType() {
|
457 |
return geomType;
|
458 |
} |
459 |
|
460 |
} |