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