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 @ 42281
History | View | Annotate | Download (13.6 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.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.point.PointJTS; |
35 |
import org.gvsig.fmap.geom.jts.primitive.surface.AbstractSurface; |
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.Circle; |
40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.primitive.Line; |
42 |
import org.gvsig.fmap.geom.primitive.Point; |
43 |
import org.gvsig.fmap.geom.primitive.Ring; |
44 |
|
45 |
|
46 |
/**
|
47 |
* @author fdiaz
|
48 |
*
|
49 |
*/
|
50 |
public abstract class AbstractCircle extends AbstractSurface implements Circle { |
51 |
|
52 |
/**
|
53 |
*
|
54 |
*/
|
55 |
private static final long serialVersionUID = -5509291843865895995L; |
56 |
|
57 |
protected Point center; |
58 |
protected double radious; |
59 |
|
60 |
|
61 |
/**
|
62 |
* @param type
|
63 |
* @param subtype
|
64 |
*/
|
65 |
protected AbstractCircle(int subtype) { |
66 |
super(Geometry.TYPES.CIRCLE, subtype);
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* @param type
|
71 |
* @param subtype
|
72 |
*/
|
73 |
protected AbstractCircle(int subtype, Point center, double radious) { |
74 |
this(subtype);
|
75 |
this.setCenter(center);
|
76 |
this.setRadious(radious);
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* @param initialPoint
|
81 |
* @return
|
82 |
*/
|
83 |
protected abstract Point fixPoint(Point point); |
84 |
|
85 |
/**
|
86 |
* @param center the center to set
|
87 |
*/
|
88 |
public void setCenter(Point center) { |
89 |
this.center = fixPoint(center);
|
90 |
} |
91 |
|
92 |
/* (non-Javadoc)
|
93 |
* @see org.gvsig.fmap.geom.primitive.Circle#getCenter()
|
94 |
*/
|
95 |
public Point getCenter() { |
96 |
return this.center; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* @param radious the radious to set
|
101 |
*/
|
102 |
public void setRadious(double radious) { |
103 |
this.radious = radious;
|
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see org.gvsig.fmap.geom.primitive.Circle#getRadious()
|
108 |
*/
|
109 |
public double getRadious() { |
110 |
return this.radious; |
111 |
} |
112 |
|
113 |
/* (non-Javadoc)
|
114 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
115 |
*/
|
116 |
public int getDimension() { |
117 |
return this.center.getDimension(); |
118 |
} |
119 |
|
120 |
/* (non-Javadoc)
|
121 |
* @see org.gvsig.fmap.geom.Geometry#isSimple()
|
122 |
*/
|
123 |
public boolean isSimple() { |
124 |
return true; |
125 |
} |
126 |
|
127 |
/* (non-Javadoc)
|
128 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
|
129 |
*/
|
130 |
public void setPoints(Point center, Point radious) { |
131 |
setCenter(center); |
132 |
this.radious = ((PointJTS)radious).getJTSCoordinate().distance(((PointJTS)this.center).getJTSCoordinate()); |
133 |
} |
134 |
|
135 |
/* (non-Javadoc)
|
136 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, double)
|
137 |
*/
|
138 |
public void setPoints(Point center, double radious) { |
139 |
setCenter(center); |
140 |
this.radious = radious;
|
141 |
} |
142 |
|
143 |
/* (non-Javadoc)
|
144 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
145 |
*/
|
146 |
public boolean is3D() { |
147 |
return ((PointJTS)center).is3D();
|
148 |
} |
149 |
|
150 |
/* (non-Javadoc)
|
151 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int)
|
152 |
*/
|
153 |
public double getCoordinateAt(int index, int dimension) { |
154 |
String message = "Calling deprecated method setPoints of a circle"; |
155 |
notifyDeprecated(message); |
156 |
throw new UnsupportedOperationException(message); |
157 |
} |
158 |
|
159 |
/* (non-Javadoc)
|
160 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setCoordinateAt(int, int, double)
|
161 |
*/
|
162 |
public void setCoordinateAt(int index, int dimension, double value) { |
163 |
String message = "Calling deprecated method setPoints of a circle"; |
164 |
notifyDeprecated(message); |
165 |
throw new UnsupportedOperationException(message); |
166 |
} |
167 |
|
168 |
/* (non-Javadoc)
|
169 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(org.gvsig.fmap.geom.primitive.Point)
|
170 |
*/
|
171 |
public void addVertex(Point point) { |
172 |
String message = "Calling deprecated method setPoints of a circle"; |
173 |
notifyDeprecated(message); |
174 |
throw new UnsupportedOperationException(message); |
175 |
} |
176 |
|
177 |
/* (non-Javadoc)
|
178 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
179 |
*/
|
180 |
public void addVertex(double x, double y) { |
181 |
String message = "Calling deprecated method setPoints of a circle"; |
182 |
notifyDeprecated(message); |
183 |
throw new UnsupportedOperationException(message); |
184 |
} |
185 |
|
186 |
/* (non-Javadoc)
|
187 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
188 |
*/
|
189 |
public void addVertex(double x, double y, double z) { |
190 |
String message = "Calling deprecated method setPoints of a circle"; |
191 |
notifyDeprecated(message); |
192 |
throw new UnsupportedOperationException(message); |
193 |
} |
194 |
|
195 |
/* (non-Javadoc)
|
196 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
|
197 |
*/
|
198 |
public void removeVertex(int index) { |
199 |
String message = "Calling deprecated method setPoints of a circle"; |
200 |
notifyDeprecated(message); |
201 |
throw new UnsupportedOperationException(message); |
202 |
} |
203 |
|
204 |
/* (non-Javadoc)
|
205 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
206 |
*/
|
207 |
public Point getVertex(int index) { |
208 |
String message = "Calling deprecated method setPoints of a circle"; |
209 |
notifyDeprecated(message); |
210 |
throw new UnsupportedOperationException(message); |
211 |
} |
212 |
|
213 |
/* (non-Javadoc)
|
214 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
|
215 |
*/
|
216 |
public int getNumVertices() { |
217 |
String message = "Calling deprecated method setPoints of a circle"; |
218 |
notifyDeprecated(message); |
219 |
throw new UnsupportedOperationException(message); |
220 |
} |
221 |
|
222 |
/* (non-Javadoc)
|
223 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
224 |
*/
|
225 |
public void insertVertex(int index, Point p) { |
226 |
String message = "Calling deprecated method setPoints of a circle"; |
227 |
notifyDeprecated(message); |
228 |
throw new UnsupportedOperationException(message); |
229 |
} |
230 |
|
231 |
/* (non-Javadoc)
|
232 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
233 |
*/
|
234 |
public void setVertex(int index, Point p) { |
235 |
String message = "Calling deprecated method setPoints of a circle"; |
236 |
notifyDeprecated(message); |
237 |
throw new UnsupportedOperationException(message); |
238 |
} |
239 |
|
240 |
/* (non-Javadoc)
|
241 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
242 |
*/
|
243 |
public void setGeneralPath(GeneralPathX generalPathX) { |
244 |
String message = "Calling deprecated method setPoints of a circle"; |
245 |
notifyDeprecated(message); |
246 |
throw new UnsupportedOperationException(message); |
247 |
} |
248 |
|
249 |
/* (non-Javadoc)
|
250 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org.gvsig.fmap.geom.primitive.Point)
|
251 |
*/
|
252 |
public void addMoveToVertex(Point point) { |
253 |
String message = "Calling deprecated method setPoints of a circle"; |
254 |
notifyDeprecated(message); |
255 |
throw new UnsupportedOperationException(message); |
256 |
} |
257 |
|
258 |
/* (non-Javadoc)
|
259 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
|
260 |
*/
|
261 |
public void closePrimitive() { |
262 |
String message = "Calling deprecated method setPoints of a circle"; |
263 |
notifyDeprecated(message); |
264 |
throw new UnsupportedOperationException(message); |
265 |
} |
266 |
|
267 |
/* (non-Javadoc)
|
268 |
* @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
269 |
*/
|
270 |
public Handler[] getHandlers(int type) { |
271 |
String message = "Calling deprecated method getHandlers of a circle"; |
272 |
notifyDeprecated(message); |
273 |
throw new UnsupportedOperationException(message); |
274 |
} |
275 |
|
276 |
|
277 |
/* (non-Javadoc)
|
278 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
|
279 |
*/
|
280 |
public void ensureCapacity(int capacity) { |
281 |
String message = "Calling deprecated method ensureCapacity of a circle"; |
282 |
notifyDeprecated(message); |
283 |
throw new UnsupportedOperationException(message); |
284 |
} |
285 |
|
286 |
/* (non-Javadoc)
|
287 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
288 |
*/
|
289 |
public Geometry cloneGeometry() {
|
290 |
Circle2D clone = new Circle2D();
|
291 |
clone.setPoints(((PointJTS)((PointJTS)center).cloneGeometry()), radious); |
292 |
return clone;
|
293 |
} |
294 |
|
295 |
/* (non-Javadoc)
|
296 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
297 |
*/
|
298 |
public Shape getShape(AffineTransform affineTransform) { |
299 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
300 |
} |
301 |
|
302 |
/* (non-Javadoc)
|
303 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
304 |
*/
|
305 |
public Shape getShape() { |
306 |
return getShape(null); |
307 |
} |
308 |
|
309 |
/* (non-Javadoc)
|
310 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
311 |
*/
|
312 |
public PathIterator getPathIterator(AffineTransform at) { |
313 |
return this.getPathIterator(at, getManager().getFlatness()); |
314 |
} |
315 |
|
316 |
/* (non-Javadoc)
|
317 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
318 |
*/
|
319 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
320 |
|
321 |
java.awt.geom.Point2D.Double center = new java.awt.geom.Point2D.Double(this.center.getX(), this.center.getY()); |
322 |
java.awt.geom.Arc2D arco = UtilFunctions.createCircle(center, radious); |
323 |
|
324 |
return arco.getPathIterator(at, flatness);
|
325 |
} |
326 |
|
327 |
/* (non-Javadoc)
|
328 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
329 |
*/
|
330 |
public GeneralPathX getGeneralPath() {
|
331 |
GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
332 |
return gp;
|
333 |
} |
334 |
|
335 |
/* (non-Javadoc)
|
336 |
* @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
|
337 |
*/
|
338 |
public int getNumInteriorRings() { |
339 |
String message = "Calling deprecated method getNumInteriorRings of a circle"; |
340 |
notifyDeprecated(message); |
341 |
throw new UnsupportedOperationException(message); |
342 |
} |
343 |
|
344 |
/* (non-Javadoc)
|
345 |
* @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
|
346 |
*/
|
347 |
public Ring getInteriorRing(int index) { |
348 |
String message = "Calling deprecated method getInteriorRing of a circle"; |
349 |
notifyDeprecated(message); |
350 |
throw new UnsupportedOperationException(message); |
351 |
} |
352 |
|
353 |
/* (non-Javadoc)
|
354 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
|
355 |
*/
|
356 |
public void addInteriorRing(Ring ring) { |
357 |
String message = "Calling deprecated method addInteriorRing of a circle"; |
358 |
notifyDeprecated(message); |
359 |
throw new UnsupportedOperationException(message); |
360 |
} |
361 |
|
362 |
/* (non-Javadoc)
|
363 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
|
364 |
*/
|
365 |
public void addInteriorRing(Line ring) { |
366 |
String message = "Calling deprecated method addInteriorRing of a circle"; |
367 |
notifyDeprecated(message); |
368 |
throw new UnsupportedOperationException(message); |
369 |
} |
370 |
|
371 |
/* (non-Javadoc)
|
372 |
* @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
|
373 |
*/
|
374 |
public void removeInteriorRing(int index) { |
375 |
String message = "Calling deprecated method removeInteriorRing of a circle"; |
376 |
notifyDeprecated(message); |
377 |
throw new UnsupportedOperationException(message); |
378 |
} |
379 |
|
380 |
/* (non-Javadoc)
|
381 |
* @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
|
382 |
*/
|
383 |
public void reProject(ICoordTrans ct) { |
384 |
String message = "Calling deprecated method reProject of a circle"; |
385 |
notifyDeprecated(message); |
386 |
throw new UnsupportedOperationException(message); |
387 |
} |
388 |
|
389 |
/* (non-Javadoc)
|
390 |
* @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
|
391 |
*/
|
392 |
public void transform(AffineTransform at) { |
393 |
String message = "Calling deprecated method transform of a circle"; |
394 |
notifyDeprecated(message); |
395 |
throw new UnsupportedOperationException(message); |
396 |
} |
397 |
|
398 |
/* (non-Javadoc)
|
399 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
|
400 |
*/
|
401 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
402 |
//FIXME: throw UnssupportedOperationException or do nothing?
|
403 |
// String message = "Can't flip a circle";
|
404 |
// notifyDeprecated(message);
|
405 |
// throw new UnsupportedOperationException(message);
|
406 |
} |
407 |
|
408 |
} |