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 / surface / circle / AbstractCircle.java @ 44617
History | View | Annotate | Download (11.5 KB)
1 | 42268 | fdiaz | /* 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.surface.circle; |
||
24 | |||
25 | import java.awt.Shape; |
||
26 | import java.awt.geom.AffineTransform; |
||
27 | import java.awt.geom.PathIterator; |
||
28 | |||
29 | 42464 | fdiaz | import org.cresques.cts.CoordTransRuntimeException; |
30 | 42272 | fdiaz | import org.cresques.cts.ICoordTrans; |
31 | 44612 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
32 | 42272 | fdiaz | |
33 | 42268 | fdiaz | import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
34 | 42283 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
35 | 42268 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
36 | import org.gvsig.fmap.geom.jts.primitive.surface.AbstractSurface; |
||
37 | import org.gvsig.fmap.geom.jts.util.UtilFunctions; |
||
38 | 42281 | fdiaz | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
39 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
40 | 42268 | fdiaz | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 | 42272 | fdiaz | import org.gvsig.fmap.geom.primitive.Line; |
42 | 44617 | jjdelcerro | import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
43 | 42268 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
44 | 42283 | fdiaz | import org.gvsig.fmap.geom.primitive.Polygon; |
45 | 42272 | fdiaz | import org.gvsig.fmap.geom.primitive.Ring; |
46 | 42283 | fdiaz | import org.gvsig.tools.exception.BaseException; |
47 | 42268 | fdiaz | |
48 | |||
49 | /**
|
||
50 | * @author fdiaz
|
||
51 | *
|
||
52 | */
|
||
53 | 42304 | fdiaz | public abstract class AbstractCircle extends AbstractSurface { |
54 | 42268 | fdiaz | |
55 | /**
|
||
56 | *
|
||
57 | */
|
||
58 | private static final long serialVersionUID = -5509291843865895995L; |
||
59 | |||
60 | protected Point center; |
||
61 | 42304 | fdiaz | protected double radius; |
62 | 42268 | fdiaz | |
63 | /**
|
||
64 | * @param type
|
||
65 | * @param subtype
|
||
66 | */
|
||
67 | 42304 | fdiaz | public AbstractCircle(int type, int subtype) { |
68 | super(type, subtype);
|
||
69 | 42268 | fdiaz | } |
70 | |||
71 | /**
|
||
72 | * @param type
|
||
73 | * @param subtype
|
||
74 | */
|
||
75 | 42304 | fdiaz | protected AbstractCircle(int type, int subtype, Point center, double radius) { |
76 | this(type, subtype);
|
||
77 | 42268 | fdiaz | this.setCenter(center);
|
78 | 42304 | fdiaz | this.setRadius(radius);
|
79 | 42268 | fdiaz | } |
80 | |||
81 | 44612 | jjdelcerro | @Override
|
82 | public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
83 | Circle2D other = new Circle2D((Point) center.force2D(), radius); |
||
84 | other.setProjection(this.getProjection());
|
||
85 | return other;
|
||
86 | } |
||
87 | 42304 | fdiaz | |
88 | 42268 | fdiaz | /**
|
89 | 44617 | jjdelcerro | * @param point
|
90 | 42268 | fdiaz | * @return
|
91 | */
|
||
92 | protected abstract Point fixPoint(Point point); |
||
93 | |||
94 | /**
|
||
95 | * @param center the center to set
|
||
96 | */
|
||
97 | public void setCenter(Point center) { |
||
98 | this.center = fixPoint(center);
|
||
99 | } |
||
100 | |||
101 | public Point getCenter() { |
||
102 | return this.center; |
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | 42304 | fdiaz | * @param radius the radius to set
|
107 | 42268 | fdiaz | */
|
108 | 42304 | fdiaz | public void setRadius(double radius) { |
109 | this.radius = radius;
|
||
110 | 42268 | fdiaz | } |
111 | |||
112 | public double getRadious() { |
||
113 | 42304 | fdiaz | return this.radius; |
114 | 42268 | fdiaz | } |
115 | |||
116 | 44617 | jjdelcerro | @Override
|
117 | 42268 | fdiaz | public int getDimension() { |
118 | return this.center.getDimension(); |
||
119 | } |
||
120 | |||
121 | 44617 | jjdelcerro | @Override
|
122 | 42268 | fdiaz | public boolean isSimple() { |
123 | return true; |
||
124 | } |
||
125 | |||
126 | 42304 | fdiaz | public void setPoints(Point center, Point radius) { |
127 | 42268 | fdiaz | setCenter(center); |
128 | 42304 | fdiaz | this.radius = ((PointJTS)radius).getJTSCoordinate().distance(((PointJTS)this.center).getJTSCoordinate()); |
129 | 42268 | fdiaz | } |
130 | |||
131 | 42304 | fdiaz | public void setPoints(Point center, double radius) { |
132 | 42268 | fdiaz | setCenter(center); |
133 | 42304 | fdiaz | this.radius = radius;
|
134 | 42268 | fdiaz | } |
135 | |||
136 | 44617 | jjdelcerro | @Override
|
137 | 42268 | fdiaz | public boolean is3D() { |
138 | return ((PointJTS)center).is3D();
|
||
139 | } |
||
140 | |||
141 | 44617 | jjdelcerro | @Override
|
142 | 42268 | fdiaz | public double getCoordinateAt(int index, int dimension) { |
143 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
144 | notifyDeprecated(message); |
||
145 | throw new UnsupportedOperationException(message); |
||
146 | 42268 | fdiaz | } |
147 | |||
148 | 44617 | jjdelcerro | @Override
|
149 | public OrientablePrimitive setCoordinateAt(int index, int dimension, double value) { |
||
150 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
151 | notifyDeprecated(message); |
||
152 | throw new UnsupportedOperationException(message); |
||
153 | 42268 | fdiaz | } |
154 | |||
155 | 44617 | jjdelcerro | @Override
|
156 | public OrientablePrimitive addVertex(Point point) { |
||
157 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
158 | notifyDeprecated(message); |
||
159 | throw new UnsupportedOperationException(message); |
||
160 | 42268 | fdiaz | } |
161 | |||
162 | 44617 | jjdelcerro | @Override
|
163 | public OrientablePrimitive addVertex(double x, double y) { |
||
164 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
165 | notifyDeprecated(message); |
||
166 | throw new UnsupportedOperationException(message); |
||
167 | 42268 | fdiaz | } |
168 | |||
169 | 44617 | jjdelcerro | @Override
|
170 | public OrientablePrimitive addVertex(double x, double y, double z) { |
||
171 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
172 | notifyDeprecated(message); |
||
173 | throw new UnsupportedOperationException(message); |
||
174 | 42268 | fdiaz | } |
175 | |||
176 | 44617 | jjdelcerro | @Override
|
177 | 42268 | fdiaz | public void removeVertex(int index) { |
178 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
179 | notifyDeprecated(message); |
||
180 | throw new UnsupportedOperationException(message); |
||
181 | 42268 | fdiaz | } |
182 | |||
183 | 44617 | jjdelcerro | @Override
|
184 | 42268 | fdiaz | public Point getVertex(int index) { |
185 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
186 | notifyDeprecated(message); |
||
187 | throw new UnsupportedOperationException(message); |
||
188 | 42268 | fdiaz | } |
189 | |||
190 | 44617 | jjdelcerro | @Override
|
191 | 42268 | fdiaz | public int getNumVertices() { |
192 | 42304 | fdiaz | String message = "Calling deprecated method getNumVertices of a circle"; |
193 | 42272 | fdiaz | notifyDeprecated(message); |
194 | throw new UnsupportedOperationException(message); |
||
195 | 42268 | fdiaz | } |
196 | |||
197 | 44617 | jjdelcerro | @Override
|
198 | public OrientablePrimitive insertVertex(int index, Point p) { |
||
199 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
200 | notifyDeprecated(message); |
||
201 | throw new UnsupportedOperationException(message); |
||
202 | 42268 | fdiaz | } |
203 | |||
204 | 44617 | jjdelcerro | @Override
|
205 | public OrientablePrimitive setVertex(int index, Point p) { |
||
206 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
207 | notifyDeprecated(message); |
||
208 | throw new UnsupportedOperationException(message); |
||
209 | 42268 | fdiaz | } |
210 | |||
211 | 44617 | jjdelcerro | @Override
|
212 | 42268 | fdiaz | public void setGeneralPath(GeneralPathX generalPathX) { |
213 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
214 | notifyDeprecated(message); |
||
215 | throw new UnsupportedOperationException(message); |
||
216 | 42268 | fdiaz | } |
217 | |||
218 | 44617 | jjdelcerro | @Override
|
219 | 42268 | fdiaz | public void addMoveToVertex(Point point) { |
220 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
221 | notifyDeprecated(message); |
||
222 | throw new UnsupportedOperationException(message); |
||
223 | 42268 | fdiaz | } |
224 | |||
225 | 44617 | jjdelcerro | @Override
|
226 | 42268 | fdiaz | public void closePrimitive() { |
227 | 42272 | fdiaz | String message = "Calling deprecated method setPoints of a circle"; |
228 | notifyDeprecated(message); |
||
229 | throw new UnsupportedOperationException(message); |
||
230 | 42268 | fdiaz | } |
231 | |||
232 | 44617 | jjdelcerro | @Override
|
233 | public OrientablePrimitive ensureCapacity(int capacity) { |
||
234 | 42272 | fdiaz | String message = "Calling deprecated method ensureCapacity of a circle"; |
235 | notifyDeprecated(message); |
||
236 | throw new UnsupportedOperationException(message); |
||
237 | 42268 | fdiaz | } |
238 | |||
239 | 44617 | jjdelcerro | @Override
|
240 | 42268 | fdiaz | public Shape getShape(AffineTransform affineTransform) { |
241 | return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
||
242 | } |
||
243 | |||
244 | 44617 | jjdelcerro | @Override
|
245 | 42268 | fdiaz | public Shape getShape() { |
246 | return getShape(null); |
||
247 | } |
||
248 | |||
249 | 44617 | jjdelcerro | @Override
|
250 | 42268 | fdiaz | public PathIterator getPathIterator(AffineTransform at) { |
251 | return this.getPathIterator(at, getManager().getFlatness()); |
||
252 | } |
||
253 | |||
254 | 44617 | jjdelcerro | @Override
|
255 | 42268 | fdiaz | public PathIterator getPathIterator(AffineTransform at, double flatness) { |
256 | |||
257 | java.awt.geom.Point2D.Double center = new java.awt.geom.Point2D.Double(this.center.getX(), this.center.getY()); |
||
258 | 42304 | fdiaz | java.awt.geom.Arc2D arco = UtilFunctions.createCircle(center, radius); |
259 | 42268 | fdiaz | |
260 | return arco.getPathIterator(at, flatness);
|
||
261 | } |
||
262 | |||
263 | 44617 | jjdelcerro | @Override
|
264 | 42268 | fdiaz | public GeneralPathX getGeneralPath() {
|
265 | GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
||
266 | return gp;
|
||
267 | } |
||
268 | |||
269 | 44617 | jjdelcerro | @Override
|
270 | 42272 | fdiaz | public int getNumInteriorRings() { |
271 | String message = "Calling deprecated method getNumInteriorRings of a circle"; |
||
272 | notifyDeprecated(message); |
||
273 | throw new UnsupportedOperationException(message); |
||
274 | } |
||
275 | |||
276 | 44617 | jjdelcerro | @Override
|
277 | 42272 | fdiaz | public Ring getInteriorRing(int index) { |
278 | String message = "Calling deprecated method getInteriorRing of a circle"; |
||
279 | notifyDeprecated(message); |
||
280 | throw new UnsupportedOperationException(message); |
||
281 | } |
||
282 | |||
283 | 44617 | jjdelcerro | @Override
|
284 | 42272 | fdiaz | public void addInteriorRing(Ring ring) { |
285 | String message = "Calling deprecated method addInteriorRing of a circle"; |
||
286 | notifyDeprecated(message); |
||
287 | throw new UnsupportedOperationException(message); |
||
288 | } |
||
289 | |||
290 | 44617 | jjdelcerro | @Override
|
291 | 42272 | fdiaz | public void addInteriorRing(Line ring) { |
292 | String message = "Calling deprecated method addInteriorRing of a circle"; |
||
293 | notifyDeprecated(message); |
||
294 | throw new UnsupportedOperationException(message); |
||
295 | } |
||
296 | |||
297 | 44617 | jjdelcerro | @Override
|
298 | 42283 | fdiaz | public void addInteriorRing(Polygon polygon) { |
299 | String message = "Calling unsupported method addInteriorRing of a circle"; |
||
300 | notifyDeprecated(message); |
||
301 | throw new UnsupportedOperationException(message); |
||
302 | } |
||
303 | 44617 | jjdelcerro | |
304 | @Override
|
||
305 | 42272 | fdiaz | public void removeInteriorRing(int index) { |
306 | String message = "Calling deprecated method removeInteriorRing of a circle"; |
||
307 | notifyDeprecated(message); |
||
308 | throw new UnsupportedOperationException(message); |
||
309 | } |
||
310 | |||
311 | 44617 | jjdelcerro | @Override
|
312 | 42272 | fdiaz | public void reProject(ICoordTrans ct) { |
313 | 42283 | fdiaz | //FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
314 | // Ser?a incorrecto para las de deformaci?n en cizallamiento
|
||
315 | |||
316 | 42304 | fdiaz | Point2D aux = new Point2D(center.getX(), center.getY()-radius); |
317 | 42283 | fdiaz | try {
|
318 | 42464 | fdiaz | center.reProject(ct); |
319 | aux.reProject(ct); |
||
320 | 43785 | jjdelcerro | this.setProjection(ct.getPDest());
|
321 | 42464 | fdiaz | } catch (CoordTransRuntimeException e){
|
322 | center.setX(0);
|
||
323 | center.setY(0);
|
||
324 | radius = 0;
|
||
325 | return;
|
||
326 | } |
||
327 | try {
|
||
328 | 42304 | fdiaz | radius = center.distance(aux); |
329 | 42283 | fdiaz | } catch (BaseException e) {
|
330 | throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
||
331 | } |
||
332 | 42272 | fdiaz | } |
333 | |||
334 | 44617 | jjdelcerro | @Override
|
335 | 42272 | fdiaz | public void transform(AffineTransform at) { |
336 | 42283 | fdiaz | //FIXME: Esto solo ser?a correcto para transformaciones de traslaci?n, rotaci?n y escala
|
337 | // Ser?a incorrecto para las de deformaci?n en cizallamiento
|
||
338 | |||
339 | 42304 | fdiaz | Point2D aux = new Point2D(center.getX(), center.getY()-radius); |
340 | 42283 | fdiaz | center.transform(at); |
341 | aux.transform(at); |
||
342 | try {
|
||
343 | 42304 | fdiaz | radius = center.distance(aux); |
344 | 42283 | fdiaz | } catch (BaseException e) {
|
345 | throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
||
346 | } |
||
347 | |||
348 | 42272 | fdiaz | } |
349 | |||
350 | 44617 | jjdelcerro | @Override
|
351 | 42281 | fdiaz | public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
352 | //FIXME: throw UnssupportedOperationException or do nothing?
|
||
353 | // String message = "Can't flip a circle";
|
||
354 | // notifyDeprecated(message);
|
||
355 | // throw new UnsupportedOperationException(message);
|
||
356 | } |
||
357 | 42272 | fdiaz | |
358 | 43002 | fdiaz | |
359 | @Override
|
||
360 | public boolean canBeTransformed(AffineTransform at) { |
||
361 | return false; |
||
362 | } |
||
363 | |||
364 | @Override
|
||
365 | public boolean canBeReprojected(ICoordTrans ct) { |
||
366 | return false; |
||
367 | } |
||
368 | 43092 | jjdelcerro | |
369 | 42268 | fdiaz | } |