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 / ellipse / BaseEllipse2D.java @ 42385
History | View | Annotate | Download (4.99 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.ellipse; |
24 |
|
25 |
import java.awt.geom.PathIterator; |
26 |
|
27 |
import com.vividsolutions.jts.geom.Coordinate; |
28 |
|
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.GeometryException; |
31 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
33 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
34 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine2D; |
35 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2D; |
36 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2D; |
37 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D; |
38 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
39 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D; |
40 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
41 |
import org.gvsig.fmap.geom.primitive.Line; |
42 |
import org.gvsig.fmap.geom.primitive.Point; |
43 |
import org.gvsig.fmap.geom.primitive.Polygon; |
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public abstract class BaseEllipse2D extends AbstractEllipse { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = 183488293452726475L; |
55 |
|
56 |
/**
|
57 |
* @param subtype
|
58 |
*/
|
59 |
public BaseEllipse2D(int type) { |
60 |
super(type, Geometry.SUBTYPES.GEOM2D);
|
61 |
} |
62 |
|
63 |
/*
|
64 |
* (non-Javadoc)
|
65 |
*
|
66 |
* @see
|
67 |
* org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
|
68 |
* .gvsig.fmap.geom.primitive.Point)
|
69 |
*/
|
70 |
@Override
|
71 |
protected Point fixPoint(Point point) { |
72 |
if (point instanceof Point2D) { |
73 |
return point;
|
74 |
} else {
|
75 |
return new Point2D(point.getX(), point.getY()); |
76 |
} |
77 |
} |
78 |
|
79 |
/**
|
80 |
* @return
|
81 |
*/
|
82 |
protected ArrayListCoordinateSequence getJTSCoordinates() {
|
83 |
PathIterator pi = getPathIterator(null); |
84 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
85 |
|
86 |
double coords[] = new double[6]; |
87 |
while (!pi.isDone()) {
|
88 |
switch (pi.currentSegment(coords)) {
|
89 |
case PathIterator.SEG_MOVETO: |
90 |
coordinates.add(new Coordinate(coords[0], coords[1])); |
91 |
break;
|
92 |
case PathIterator.SEG_LINETO: |
93 |
coordinates.add(new Coordinate(coords[0], coords[1])); |
94 |
break;
|
95 |
case PathIterator.SEG_QUADTO: |
96 |
coordinates.add(new Coordinate(coords[0], coords[1])); |
97 |
coordinates.add(new Coordinate(coords[2], coords[3])); |
98 |
break;
|
99 |
case PathIterator.SEG_CUBICTO: |
100 |
coordinates.add(new Coordinate(coords[0], coords[1])); |
101 |
coordinates.add(new Coordinate(coords[2], coords[3])); |
102 |
coordinates.add(new Coordinate(coords[4], coords[5])); |
103 |
break;
|
104 |
case PathIterator.SEG_CLOSE: |
105 |
coordinates.add((Coordinate) coordinates.get(0).clone());
|
106 |
break;
|
107 |
} |
108 |
pi.next(); |
109 |
} |
110 |
return coordinates;
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
*
|
116 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
117 |
*/
|
118 |
public MultiPoint toPoints() throws GeometryException { |
119 |
MultiPoint multiPoint = new MultiPoint2D();
|
120 |
Coordinate[] coordinates = getJTS().getCoordinates();
|
121 |
multiPoint.ensureCapacity(coordinates.length); |
122 |
for (int i = 0; i < coordinates.length; i++) { |
123 |
multiPoint.addPoint(new Point2D(coordinates[i])); |
124 |
} |
125 |
return multiPoint;
|
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
*
|
131 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
132 |
*/
|
133 |
public MultiLine toLines() throws GeometryException { |
134 |
MultiLine multiLine = new MultiLine2D();
|
135 |
Line line = new Line2D(getJTS().getCoordinates()); |
136 |
multiLine.addPrimitive(line); |
137 |
return multiLine;
|
138 |
} |
139 |
|
140 |
/*
|
141 |
* (non-Javadoc)
|
142 |
*
|
143 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
144 |
*/
|
145 |
public MultiPolygon toPolygons() throws GeometryException { |
146 |
MultiPolygon multiPolygon = new MultiPolygon2D();
|
147 |
Polygon polygon = new Polygon2D(getJTS().getCoordinates()); |
148 |
multiPolygon.addPrimitive(polygon); |
149 |
return multiPolygon;
|
150 |
} |
151 |
} |