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 @ 45762
History | View | Annotate | Download (11.7 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.surface.circle; |
24 |
|
25 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
|
29 |
import org.cresques.cts.CoordTransRuntimeException; |
30 |
import org.cresques.cts.ICoordTrans; |
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
|
33 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
34 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
35 |
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 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.primitive.Line; |
42 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
43 |
import org.gvsig.fmap.geom.primitive.Point; |
44 |
import org.gvsig.fmap.geom.primitive.Polygon; |
45 |
import org.gvsig.fmap.geom.primitive.Ring; |
46 |
import org.gvsig.tools.exception.BaseException; |
47 |
|
48 |
|
49 |
/**
|
50 |
* @author fdiaz
|
51 |
*
|
52 |
*/
|
53 |
public abstract class AbstractCircle extends AbstractSurface { |
54 |
|
55 |
/**
|
56 |
*
|
57 |
*/
|
58 |
private static final long serialVersionUID = -5509291843865895995L; |
59 |
|
60 |
protected Point center; |
61 |
protected double radius; |
62 |
|
63 |
/**
|
64 |
* @param type
|
65 |
* @param subtype
|
66 |
*/
|
67 |
public AbstractCircle(int type, int subtype) { |
68 |
super(type, subtype);
|
69 |
} |
70 |
|
71 |
/**
|
72 |
* @param type
|
73 |
* @param subtype
|
74 |
*/
|
75 |
protected AbstractCircle(int type, int subtype, Point center, double radius) { |
76 |
this(type, subtype);
|
77 |
this.setCenter(center);
|
78 |
this.setRadius(radius);
|
79 |
} |
80 |
|
81 |
@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 |
|
88 |
/**
|
89 |
* @param point
|
90 |
* @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 |
* @param radius the radius to set
|
107 |
*/
|
108 |
public void setRadius(double radius) { |
109 |
this.radius = radius;
|
110 |
} |
111 |
|
112 |
public double getRadious() { |
113 |
return this.radius; |
114 |
} |
115 |
|
116 |
@Override
|
117 |
public int getDimension() { |
118 |
return this.center.getDimension(); |
119 |
} |
120 |
|
121 |
@Override
|
122 |
public boolean isSimple() { |
123 |
return true; |
124 |
} |
125 |
|
126 |
public void setPoints(Point center, Point radius) { |
127 |
setCenter(center); |
128 |
this.radius = ((PointJTS)radius).getJTSCoordinate().distance(((PointJTS)this.center).getJTSCoordinate()); |
129 |
} |
130 |
|
131 |
public void setPoints(Point center, double radius) { |
132 |
setCenter(center); |
133 |
this.radius = radius;
|
134 |
} |
135 |
|
136 |
@Override
|
137 |
public boolean is3D() { |
138 |
return ((PointJTS)center).is3D();
|
139 |
} |
140 |
|
141 |
@Override
|
142 |
public double getCoordinateAt(int index, int dimension) { |
143 |
String message = "Calling deprecated method setPoints of a circle"; |
144 |
notifyDeprecated(message); |
145 |
throw new UnsupportedOperationException(message); |
146 |
} |
147 |
|
148 |
@Override
|
149 |
public OrientablePrimitive setCoordinateAt(int index, int dimension, double value) { |
150 |
String message = "Calling deprecated method setPoints of a circle"; |
151 |
notifyDeprecated(message); |
152 |
throw new UnsupportedOperationException(message); |
153 |
} |
154 |
|
155 |
@Override
|
156 |
public OrientablePrimitive addVertex(Point point) { |
157 |
String message = "Calling deprecated method setPoints of a circle"; |
158 |
notifyDeprecated(message); |
159 |
throw new UnsupportedOperationException(message); |
160 |
} |
161 |
|
162 |
@Override
|
163 |
public OrientablePrimitive addVertex(double x, double y) { |
164 |
String message = "Calling deprecated method setPoints of a circle"; |
165 |
notifyDeprecated(message); |
166 |
throw new UnsupportedOperationException(message); |
167 |
} |
168 |
|
169 |
@Override
|
170 |
public OrientablePrimitive addVertex(double x, double y, double z) { |
171 |
String message = "Calling deprecated method setPoints of a circle"; |
172 |
notifyDeprecated(message); |
173 |
throw new UnsupportedOperationException(message); |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public void removeVertex(int index) { |
178 |
String message = "Calling deprecated method setPoints of a circle"; |
179 |
notifyDeprecated(message); |
180 |
throw new UnsupportedOperationException(message); |
181 |
} |
182 |
|
183 |
@Override
|
184 |
public Point getVertex(int index) { |
185 |
String message = "Calling deprecated method setPoints of a circle"; |
186 |
notifyDeprecated(message); |
187 |
throw new UnsupportedOperationException(message); |
188 |
} |
189 |
|
190 |
@Override
|
191 |
public int getNumVertices() { |
192 |
String message = "Calling deprecated method getNumVertices of a circle"; |
193 |
notifyDeprecated(message); |
194 |
throw new UnsupportedOperationException(message); |
195 |
} |
196 |
|
197 |
@Override
|
198 |
public OrientablePrimitive insertVertex(int index, Point p) { |
199 |
String message = "Calling deprecated method setPoints of a circle"; |
200 |
notifyDeprecated(message); |
201 |
throw new UnsupportedOperationException(message); |
202 |
} |
203 |
|
204 |
@Override
|
205 |
public OrientablePrimitive setVertex(int index, Point p) { |
206 |
String message = "Calling deprecated method setPoints of a circle"; |
207 |
notifyDeprecated(message); |
208 |
throw new UnsupportedOperationException(message); |
209 |
} |
210 |
|
211 |
@Override
|
212 |
public void setGeneralPath(GeneralPathX generalPathX) { |
213 |
String message = "Calling deprecated method setPoints of a circle"; |
214 |
notifyDeprecated(message); |
215 |
throw new UnsupportedOperationException(message); |
216 |
} |
217 |
|
218 |
@Override
|
219 |
public void addMoveToVertex(Point point) { |
220 |
String message = "Calling deprecated method setPoints of a circle"; |
221 |
notifyDeprecated(message); |
222 |
throw new UnsupportedOperationException(message); |
223 |
} |
224 |
|
225 |
@Override
|
226 |
public void closePrimitive() { |
227 |
String message = "Calling deprecated method setPoints of a circle"; |
228 |
notifyDeprecated(message); |
229 |
throw new UnsupportedOperationException(message); |
230 |
} |
231 |
|
232 |
@Override
|
233 |
public OrientablePrimitive ensureCapacity(int capacity) { |
234 |
String message = "Calling deprecated method ensureCapacity of a circle"; |
235 |
notifyDeprecated(message); |
236 |
throw new UnsupportedOperationException(message); |
237 |
} |
238 |
|
239 |
@Override
|
240 |
public Shape getShape(AffineTransform affineTransform) { |
241 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
242 |
} |
243 |
|
244 |
@Override
|
245 |
public Shape getShape() { |
246 |
return getShape(null); |
247 |
} |
248 |
|
249 |
@Override
|
250 |
public PathIterator getPathIterator(AffineTransform at) { |
251 |
return this.getPathIterator(at, getManager().getFlatness()); |
252 |
} |
253 |
|
254 |
@Override
|
255 |
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 |
java.awt.geom.Arc2D arco = UtilFunctions.createCircle(center, radius); |
259 |
|
260 |
return arco.getPathIterator(at, flatness);
|
261 |
} |
262 |
|
263 |
@Override
|
264 |
public GeneralPathX getGeneralPath() {
|
265 |
GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
266 |
return gp;
|
267 |
} |
268 |
|
269 |
@Override
|
270 |
public int getNumInteriorRings() { |
271 |
String message = "Calling deprecated method getNumInteriorRings of a circle"; |
272 |
notifyDeprecated(message); |
273 |
throw new UnsupportedOperationException(message); |
274 |
} |
275 |
|
276 |
@Override
|
277 |
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 |
@Override
|
284 |
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 |
@Override
|
291 |
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 |
@Override
|
298 |
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 |
|
304 |
@Override
|
305 |
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 |
@Override
|
312 |
public void reProject(ICoordTrans ct) { |
313 |
//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 |
Point2D aux = new Point2D(center.getX(), center.getY()-radius); |
317 |
try {
|
318 |
center.reProject(ct); |
319 |
aux.reProject(ct); |
320 |
this.setProjection(ct.getPDest());
|
321 |
} catch (CoordTransRuntimeException e){
|
322 |
center.setX(0);
|
323 |
center.setY(0);
|
324 |
radius = 0;
|
325 |
return;
|
326 |
} |
327 |
try {
|
328 |
radius = center.distance(aux); |
329 |
} catch (BaseException e) {
|
330 |
throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
331 |
} |
332 |
} |
333 |
|
334 |
@Override
|
335 |
public void transform(AffineTransform at) { |
336 |
//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 |
Point2D aux = new Point2D(center.getX(), center.getY()-radius); |
340 |
center.transform(at); |
341 |
aux.transform(at); |
342 |
try {
|
343 |
radius = center.distance(aux); |
344 |
} catch (BaseException e) {
|
345 |
throw new UnsupportedOperationException("Error calculating the radius of the transformed circle.", e); |
346 |
} |
347 |
|
348 |
} |
349 |
|
350 |
@Override
|
351 |
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 |
|
358 |
|
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 |
|
369 |
@Override
|
370 |
public Geometry offset(int joinStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
371 |
return offset(distance);
|
372 |
} |
373 |
|
374 |
} |