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 @ 42271
History | View | Annotate | Download (10.8 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.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.handler.Handler; |
31 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
32 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
33 |
import org.gvsig.fmap.geom.jts.primitive.surface.AbstractSurface; |
34 |
import org.gvsig.fmap.geom.jts.util.UtilFunctions; |
35 |
import org.gvsig.fmap.geom.primitive.Circle; |
36 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
37 |
import org.gvsig.fmap.geom.primitive.Point; |
38 |
|
39 |
|
40 |
/**
|
41 |
* @author fdiaz
|
42 |
*
|
43 |
*/
|
44 |
public abstract class AbstractCircle extends AbstractSurface implements Circle { |
45 |
|
46 |
/**
|
47 |
*
|
48 |
*/
|
49 |
private static final long serialVersionUID = -5509291843865895995L; |
50 |
|
51 |
protected Point center; |
52 |
protected double radious; |
53 |
|
54 |
|
55 |
/**
|
56 |
* @param type
|
57 |
* @param subtype
|
58 |
*/
|
59 |
protected AbstractCircle(int subtype) { |
60 |
super(Geometry.TYPES.CIRCLE, subtype);
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* @param type
|
65 |
* @param subtype
|
66 |
*/
|
67 |
protected AbstractCircle(int subtype, Point center, double radious) { |
68 |
this(subtype);
|
69 |
this.setCenter(center);
|
70 |
this.setRadious(radious);
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* @param initialPoint
|
75 |
* @return
|
76 |
*/
|
77 |
protected abstract Point fixPoint(Point point); |
78 |
|
79 |
/**
|
80 |
* @param center the center to set
|
81 |
*/
|
82 |
public void setCenter(Point center) { |
83 |
this.center = fixPoint(center);
|
84 |
} |
85 |
|
86 |
/* (non-Javadoc)
|
87 |
* @see org.gvsig.fmap.geom.primitive.Circle#getCenter()
|
88 |
*/
|
89 |
public Point getCenter() { |
90 |
return this.center; |
91 |
} |
92 |
|
93 |
/**
|
94 |
* @param radious the radious to set
|
95 |
*/
|
96 |
public void setRadious(double radious) { |
97 |
this.radious = radious;
|
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see org.gvsig.fmap.geom.primitive.Circle#getRadious()
|
102 |
*/
|
103 |
public double getRadious() { |
104 |
return this.radious; |
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
109 |
*/
|
110 |
public int getDimension() { |
111 |
return this.center.getDimension(); |
112 |
} |
113 |
|
114 |
/* (non-Javadoc)
|
115 |
* @see org.gvsig.fmap.geom.Geometry#isSimple()
|
116 |
*/
|
117 |
public boolean isSimple() { |
118 |
return true; |
119 |
} |
120 |
|
121 |
/* (non-Javadoc)
|
122 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
|
123 |
*/
|
124 |
public void setPoints(Point center, Point radious) { |
125 |
setCenter(center); |
126 |
this.radious = ((PointJTS)radious).getJTSCoordinate().distance(((PointJTS)this.center).getJTSCoordinate()); |
127 |
} |
128 |
|
129 |
/* (non-Javadoc)
|
130 |
* @see org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive.Point, double)
|
131 |
*/
|
132 |
public void setPoints(Point center, double radious) { |
133 |
setCenter(center); |
134 |
this.radious = radious;
|
135 |
} |
136 |
|
137 |
// /* (non-Javadoc)
|
138 |
// * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
139 |
// */
|
140 |
// public com.vividsolutions.jts.geom.Geometry getJTS() {
|
141 |
// return JTSUtils.createJTSCircle(this.center, this.radious);
|
142 |
// }
|
143 |
|
144 |
/* (non-Javadoc)
|
145 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
146 |
*/
|
147 |
public boolean is3D() { |
148 |
return ((PointJTS)center).is3D();
|
149 |
} |
150 |
|
151 |
/* (non-Javadoc)
|
152 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int)
|
153 |
*/
|
154 |
public double getCoordinateAt(int index, int dimension) { |
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#setCoordinateAt(int, int, double)
|
161 |
*/
|
162 |
public void setCoordinateAt(int index, int dimension, double value) { |
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#addVertex(org.gvsig.fmap.geom.primitive.Point)
|
169 |
*/
|
170 |
public void addVertex(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#addVertex(double, double)
|
177 |
*/
|
178 |
public void addVertex(double x, double y) { |
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#addVertex(double, double, double)
|
185 |
*/
|
186 |
public void addVertex(double x, double y, double z) { |
187 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
188 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
189 |
} |
190 |
|
191 |
/* (non-Javadoc)
|
192 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
|
193 |
*/
|
194 |
public void removeVertex(int index) { |
195 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
196 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
197 |
} |
198 |
|
199 |
/* (non-Javadoc)
|
200 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
201 |
*/
|
202 |
public Point getVertex(int index) { |
203 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
204 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
205 |
} |
206 |
|
207 |
/* (non-Javadoc)
|
208 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
|
209 |
*/
|
210 |
public int getNumVertices() { |
211 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
212 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
213 |
} |
214 |
|
215 |
/* (non-Javadoc)
|
216 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
217 |
*/
|
218 |
public void insertVertex(int index, Point p) { |
219 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
220 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
221 |
} |
222 |
|
223 |
/* (non-Javadoc)
|
224 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int, org.gvsig.fmap.geom.primitive.Point)
|
225 |
*/
|
226 |
public void setVertex(int index, Point p) { |
227 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
228 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
229 |
} |
230 |
|
231 |
/* (non-Javadoc)
|
232 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
|
233 |
*/
|
234 |
public void setGeneralPath(GeneralPathX generalPathX) { |
235 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
236 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
237 |
} |
238 |
|
239 |
/* (non-Javadoc)
|
240 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org.gvsig.fmap.geom.primitive.Point)
|
241 |
*/
|
242 |
public void addMoveToVertex(Point point) { |
243 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
244 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
245 |
} |
246 |
|
247 |
/* (non-Javadoc)
|
248 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
|
249 |
*/
|
250 |
public void closePrimitive() { |
251 |
notifyDeprecated("Calling deprecated method setPoints of a arc");
|
252 |
throw new UnsupportedOperationException("Calling deprecated method setPoints of a arc"); |
253 |
} |
254 |
|
255 |
/* (non-Javadoc)
|
256 |
* @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
257 |
*/
|
258 |
public Handler[] getHandlers(int type) { |
259 |
notifyDeprecated("Calling deprecated method getHandlers of a arc");
|
260 |
throw new UnsupportedOperationException("Calling deprecated method getHandlers of a arc"); |
261 |
} |
262 |
|
263 |
|
264 |
/* (non-Javadoc)
|
265 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
|
266 |
*/
|
267 |
public void ensureCapacity(int capacity) { |
268 |
// TODO Auto-generated method stub
|
269 |
|
270 |
} |
271 |
|
272 |
/* (non-Javadoc)
|
273 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
274 |
*/
|
275 |
public Geometry cloneGeometry() {
|
276 |
Circle2D clone = new Circle2D();
|
277 |
clone.setPoints(((PointJTS)((PointJTS)center).cloneGeometry()), radious); |
278 |
return clone;
|
279 |
} |
280 |
|
281 |
/* (non-Javadoc)
|
282 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
283 |
*/
|
284 |
public Shape getShape(AffineTransform affineTransform) { |
285 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
286 |
} |
287 |
|
288 |
/* (non-Javadoc)
|
289 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
290 |
*/
|
291 |
public Shape getShape() { |
292 |
return getShape(null); |
293 |
} |
294 |
|
295 |
/* (non-Javadoc)
|
296 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
297 |
*/
|
298 |
public PathIterator getPathIterator(AffineTransform at) { |
299 |
return this.getPathIterator(at, getManager().getFlatness()); |
300 |
} |
301 |
|
302 |
/* (non-Javadoc)
|
303 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
304 |
*/
|
305 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
306 |
|
307 |
java.awt.geom.Point2D.Double center = new java.awt.geom.Point2D.Double(this.center.getX(), this.center.getY()); |
308 |
java.awt.geom.Arc2D arco = UtilFunctions.createCircle(center, radious); |
309 |
|
310 |
return arco.getPathIterator(at, flatness);
|
311 |
} |
312 |
|
313 |
/* (non-Javadoc)
|
314 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
315 |
*/
|
316 |
public GeneralPathX getGeneralPath() {
|
317 |
GeneralPathX gp = new DefaultGeneralPathX(getPathIterator(null, getManager().getFlatness()), is3D(), 0.0); |
318 |
return gp;
|
319 |
} |
320 |
|
321 |
} |