Statistics
| Revision:

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 @ 42464

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