svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / curve / arc / AbstractArc.java @ 42283
History | View | Annotate | Download (13.9 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.jts.primitive.curve.arc; |
24 |
|
25 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
|
29 |
import org.cresques.cts.ICoordTrans; |
30 |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.handler.Handler; |
33 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
34 |
import org.gvsig.fmap.geom.jts.primitive.curve.AbstractCurve; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
36 |
import org.gvsig.fmap.geom.jts.util.UtilFunctions; |
37 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
38 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
39 |
import org.gvsig.fmap.geom.primitive.Arc; |
40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.primitive.Point; |
42 |
|
43 |
|
44 |
/**
|
45 |
* @author fdiaz
|
46 |
*
|
47 |
*/
|
48 |
public abstract class AbstractArc extends AbstractCurve implements Arc { |
49 |
|
50 |
/**
|
51 |
*
|
52 |
*/
|
53 |
private static final long serialVersionUID = 454301669807892457L; |
54 |
|
55 |
/**
|
56 |
* @param type
|
57 |
* @param subtype
|
58 |
*/
|
59 |
protected AbstractArc(int subtype) { |
60 |
super(Geometry.TYPES.ARC, subtype);
|
61 |
} |
62 |
|
63 |
protected Point init; |
64 |
|
65 |
/**
|
66 |
* This is the middle point (belongs to the arc), not the center
|
67 |
* of the circle/ellipse
|
68 |
*/
|
69 |
protected Point middle; |
70 |
protected Point end; |
71 |
|
72 |
|
73 |
/* (non-Javadoc)
|
74 |
* @see org.gvsig.fmap.geom.primitive.Curve#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
|
75 |
*/
|
76 |
public void setPoints(Point initialPoint, Point endPoint) { |
77 |
String message = "Calling deprecated method setPoints of a arc"; |
78 |
notifyDeprecated(message); |
79 |
throw new UnsupportedOperationException(message); |
80 |
} |
81 |
|
82 |
/* (non-Javadoc)
|
83 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int)
|
84 |
*/
|
85 |
public double getCoordinateAt(int index, int dimension) { |
86 |
String message = "Calling deprecated method setPoints of a arc"; |
87 |
notifyDeprecated(message); |
88 |
throw new UnsupportedOperationException(message); |
89 |
} |
90 |
|
91 |
/* (non-Javadoc)
|
92 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setCoordinateAt(int, int, double)
|
93 |
*/
|
94 |
public void setCoordinateAt(int index, int dimension, double value) { |
95 |
String message = "Calling deprecated method setPoints of a arc"; |
96 |
notifyDeprecated(message); |
97 |
throw new UnsupportedOperationException(message); |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(org.gvsig.fmap.geom.primitive.Point)
|
102 |
*/
|
103 |
public void addVertex(Point point) { |
104 |
String message = "Calling deprecated method setPoints of a arc"; |
105 |
notifyDeprecated(message); |
106 |
throw new UnsupportedOperationException(message); |
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
111 |
*/
|
112 |
public void addVertex(double x, double y) { |
113 |
String message = "Calling deprecated method setPoints of a arc"; |
114 |
notifyDeprecated(message); |
115 |
throw new UnsupportedOperationException(message); |
116 |
} |
117 |
|
118 |
/* (non-Javadoc)
|
119 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
120 |
*/
|
121 |
public void addVertex(double x, double y, double z) { |
122 |
String message = "Calling deprecated method setPoints of a arc"; |
123 |
notifyDeprecated(message); |
124 |
throw new UnsupportedOperationException(message); |
125 |
} |
126 |
|
127 |
/* (non-Javadoc)
|
128 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
|
129 |
*/
|
130 |
public void removeVertex(int index) { |
131 |
String message = "Calling deprecated method setPoints of a arc"; |
132 |
notifyDeprecated(message); |
133 |
throw new UnsupportedOperationException(message); |
134 |
} |
135 |
|
136 |
/* (non-Javadoc)
|
137 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
138 |
*/
|
139 |
public Point getVertex(int index) { |
140 |
String message = "Calling deprecated method setPoints of a arc"; |
141 |
notifyDeprecated(message); |
142 |
throw new UnsupportedOperationException(message); |
143 |
} |
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
|
147 |
*/
|
148 |
public int getNumVertices() { |
149 |
String message = "Calling deprecated method setPoints of a arc"; |
150 |
notifyDeprecated(message); |
151 |
throw new UnsupportedOperationException(message); |
152 |
} |
153 |
|
154 |
/* (non-Javadoc)
|
155 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
156 |
*/
|
157 |
public void insertVertex(int index, Point p) { |
158 |
String message = "Calling deprecated method setPoints of a arc"; |
159 |
notifyDeprecated(message); |
160 |
throw new UnsupportedOperationException(message); |
161 |
} |
162 |
|
163 |
/* (non-Javadoc)
|
164 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
165 |
*/
|
166 |
public void setVertex(int index, Point p) { |
167 |
String message = "Calling deprecated method setPoints of a arc"; |
168 |
notifyDeprecated(message); |
169 |
throw new UnsupportedOperationException(message); |
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
174 |
*/
|
175 |
public void setGeneralPath(GeneralPathX generalPathX) { |
176 |
String message = "Calling deprecated method setPoints of a arc"; |
177 |
notifyDeprecated(message); |
178 |
throw new UnsupportedOperationException(message); |
179 |
} |
180 |
|
181 |
/* (non-Javadoc)
|
182 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org.gvsig.fmap.geom.primitive.Point)
|
183 |
*/
|
184 |
public void addMoveToVertex(Point point) { |
185 |
String message = "Calling deprecated method setPoints of a arc"; |
186 |
notifyDeprecated(message); |
187 |
throw new UnsupportedOperationException(message); |
188 |
} |
189 |
|
190 |
/* (non-Javadoc)
|
191 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
|
192 |
*/
|
193 |
public void closePrimitive() { |
194 |
String message = "Calling deprecated method setPoints of a arc"; |
195 |
notifyDeprecated(message); |
196 |
throw new UnsupportedOperationException(message); |
197 |
} |
198 |
|
199 |
/* (non-Javadoc)
|
200 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
|
201 |
*/
|
202 |
public void ensureCapacity(int capacity) { |
203 |
// TODO Auto-generated method stub
|
204 |
|
205 |
} |
206 |
|
207 |
/* (non-Javadoc)
|
208 |
* @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
|
209 |
*/
|
210 |
public void reProject(ICoordTrans ct) { |
211 |
//FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
212 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
213 |
|
214 |
init.reProject(ct); |
215 |
middle.reProject(ct); |
216 |
end.reProject(ct); |
217 |
} |
218 |
|
219 |
/* (non-Javadoc)
|
220 |
* @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
|
221 |
*/
|
222 |
public void transform(AffineTransform at) { |
223 |
//FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
224 |
// Ser?a incorrecto para las de deformaci?n en cizallamiento
|
225 |
|
226 |
init.transform(at); |
227 |
middle.transform(at); |
228 |
end.transform(at); |
229 |
} |
230 |
|
231 |
/* (non-Javadoc)
|
232 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
233 |
*/
|
234 |
public int getDimension() { |
235 |
return init.getDimension();
|
236 |
} |
237 |
|
238 |
/* (non-Javadoc)
|
239 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
240 |
*/
|
241 |
public Shape getShape(AffineTransform affineTransform) { |
242 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
243 |
} |
244 |
|
245 |
/* (non-Javadoc)
|
246 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
247 |
*/
|
248 |
public Shape getShape() { |
249 |
return getShape(null); |
250 |
} |
251 |
|
252 |
/* (non-Javadoc)
|
253 |
* @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
254 |
*/
|
255 |
public Handler[] getHandlers(int type) { |
256 |
notifyDeprecated("Calling deprecated method getHandlers of a arc");
|
257 |
throw new UnsupportedOperationException("Calling deprecated method getHandlers of a arc"); |
258 |
} |
259 |
|
260 |
/* (non-Javadoc)
|
261 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
262 |
*/
|
263 |
public boolean is3D() { |
264 |
return ((PointJTS)init).is3D();
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* @param initialPoint
|
269 |
* @return
|
270 |
*/
|
271 |
protected abstract Point fixPoint(Point point); |
272 |
|
273 |
/* (non-Javadoc)
|
274 |
* @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)
|
275 |
*/
|
276 |
public void setPoints(Point startPoint, Point midPoint, Point endPoint) { |
277 |
init = fixPoint(startPoint); |
278 |
middle = fixPoint(midPoint); |
279 |
end = fixPoint(endPoint); |
280 |
} |
281 |
|
282 |
/* (non-Javadoc)
|
283 |
* @see org.gvsig.fmap.geom.primitive.Arc#getInitPoint()
|
284 |
*/
|
285 |
public Point getInitPoint() { |
286 |
return init;
|
287 |
} |
288 |
|
289 |
/* (non-Javadoc)
|
290 |
* @see org.gvsig.fmap.geom.primitive.Arc#getEndPoint()
|
291 |
*/
|
292 |
public Point getEndPoint() { |
293 |
return end;
|
294 |
} |
295 |
|
296 |
/* (non-Javadoc)
|
297 |
* @see org.gvsig.fmap.geom.primitive.Arc#getMiddlePoint()
|
298 |
*/
|
299 |
public Point getMiddlePoint() { |
300 |
return middle;
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* Leaves the angle between PI and -PI
|
305 |
* @param angle (radians)
|
306 |
* @return
|
307 |
*/
|
308 |
protected double normalizeAngle(double angle) { |
309 |
if (angle > -Math.PI && angle <= Math.PI) { |
310 |
return angle;
|
311 |
} |
312 |
|
313 |
if (angle == Double.NEGATIVE_INFINITY || angle == Double.POSITIVE_INFINITY) { |
314 |
return 0; |
315 |
} |
316 |
|
317 |
double abs_ang = Math.abs(angle); |
318 |
double remove = Math.floor(abs_ang / (2 * Math.PI)); |
319 |
remove = remove * 2 * Math.PI; |
320 |
double resp = 0; |
321 |
|
322 |
if (angle > 0) { |
323 |
resp = angle - remove; |
324 |
if (resp > Math.PI) { |
325 |
// final adjustment
|
326 |
resp = resp - 2 * Math.PI; |
327 |
} |
328 |
} else {
|
329 |
resp = angle + remove; |
330 |
if (resp <= -Math.PI) { |
331 |
// final adjustment
|
332 |
resp = resp + 2 * Math.PI; |
333 |
} |
334 |
} |
335 |
|
336 |
return resp;
|
337 |
} |
338 |
|
339 |
|
340 |
/* (non-Javadoc)
|
341 |
* @see org.gvsig.fmap.geom.primitive.Arc#setPointsStartExt(org.gvsig.fmap.geom.primitive.Point, double, double, double)
|
342 |
*/
|
343 |
public void setPointsStartExt(Point center, double radius, double startAngle, double angleExt) { |
344 |
setPoints(center, radius, startAngle, angleExt); |
345 |
} |
346 |
|
347 |
/* (non-Javadoc)
|
348 |
* @see org.gvsig.fmap.geom.primitive.Arc#setPointsStartEnd(org.gvsig.fmap.geom.primitive.Point, double, double, double)
|
349 |
*/
|
350 |
public void setPointsStartEnd(Point center, double radius, double startAngle, double endAngle) { |
351 |
|
352 |
if (startAngle == endAngle) {
|
353 |
setPointsStartExt(center, radius, startAngle, 0);
|
354 |
} else {
|
355 |
|
356 |
/*
|
357 |
* Normalize then force clockwise:
|
358 |
*/
|
359 |
double norm_start = normalizeAngle(startAngle);
|
360 |
double norm_end = normalizeAngle(endAngle);
|
361 |
double ang_ext = 0; |
362 |
|
363 |
// clockwise
|
364 |
// ang_ext must be positive
|
365 |
if (norm_start >= norm_end) {
|
366 |
ang_ext = norm_start - norm_end; |
367 |
} else {
|
368 |
ang_ext = 2 * Math.PI - (norm_end - norm_start); |
369 |
} |
370 |
setPointsStartExt(center, radius, startAngle, ang_ext); |
371 |
|
372 |
// finally call other method with ang_ext
|
373 |
} |
374 |
} |
375 |
|
376 |
/* (non-Javadoc)
|
377 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
378 |
*/
|
379 |
public GeneralPathX getGeneralPath() {
|
380 |
|
381 |
GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
382 |
return gp;
|
383 |
} |
384 |
|
385 |
|
386 |
/* (non-Javadoc)
|
387 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
388 |
*/
|
389 |
public PathIterator getPathIterator(AffineTransform at) { |
390 |
return getPathIterator(at, getManager().getFlatness());
|
391 |
} |
392 |
|
393 |
|
394 |
/* (non-Javadoc)
|
395 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
396 |
*/
|
397 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
398 |
|
399 |
java.awt.geom.Point2D.Double p1 = new java.awt.geom.Point2D.Double(init.getX(), init.getY());
|
400 |
java.awt.geom.Point2D.Double p2 = new java.awt.geom.Point2D.Double(middle.getX(), middle.getY());
|
401 |
java.awt.geom.Point2D.Double p3 = new java.awt.geom.Point2D.Double(end.getX(), end.getY());
|
402 |
|
403 |
java.awt.geom.Arc2D arco = UtilFunctions.createArc(p1, p2, p3); |
404 |
if (arco == null) { |
405 |
logger.info("Did not set arc points (probably aligned points): " + p1.getX() + " " + p1.getY() + " :: " |
406 |
+ p2.getX() + " " + p2.getY() + " :: " + p3.getX() + " " + p3.getY()); |
407 |
throw new IllegalArgumentException("Did not set arc points (probably aligned points)."); |
408 |
} |
409 |
|
410 |
return arco.getPathIterator(at, flatness);
|
411 |
} |
412 |
|
413 |
/* (non-Javadoc)
|
414 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
|
415 |
*/
|
416 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
417 |
Point aux = init;
|
418 |
init = end; |
419 |
end = aux; |
420 |
} |
421 |
} |