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 / ellipticarc / BaseEllipticArc2D.java @ 44099

History | View | Annotate | Download (4.9 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.ellipticarc;
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
/**
47
 * @author fdiaz
48
 *
49
 */
50
public abstract class BaseEllipticArc2D extends AbstractEllipticArc {
51

    
52
    /**
53
     * @param subtype
54
     */
55
    public BaseEllipticArc2D(int type) {
56
        super(type, Geometry.SUBTYPES.GEOM2D);
57
    }
58

    
59

    
60
    /*
61
     * (non-Javadoc)
62
     *
63
     * @see
64
     * org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
65
     * .gvsig.fmap.geom.primitive.Point)
66
     */
67
    @Override
68
    protected Point fixPoint(Point point) {
69
        if (point instanceof Point2D) {
70
            return point;
71
        } else {
72
            return new Point2D(point.getX(), point.getY());
73
        }
74
    }
75

    
76

    
77
    /**
78
     * @return
79
     */
80
    protected ArrayListCoordinateSequence getJTSCoordinates() {
81
        PathIterator pi = getPathIterator(null);
82
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
83

    
84
        double coords[] = new double[6];
85
        while (!pi.isDone()) {
86
            switch (pi.currentSegment(coords)) {
87
            case PathIterator.SEG_MOVETO:
88
                coordinates.add(new Coordinate(coords[0], coords[1]));
89
                break;
90
            case PathIterator.SEG_LINETO:
91
                coordinates.add(new Coordinate(coords[0], coords[1]));
92
                break;
93
            case PathIterator.SEG_QUADTO:
94
                coordinates.add(new Coordinate(coords[0], coords[1]));
95
                coordinates.add(new Coordinate(coords[2], coords[3]));
96
                break;
97
            case PathIterator.SEG_CUBICTO:
98
                coordinates.add(new Coordinate(coords[0], coords[1]));
99
                coordinates.add(new Coordinate(coords[2], coords[3]));
100
                coordinates.add(new Coordinate(coords[4], coords[5]));
101
                break;
102
            case PathIterator.SEG_CLOSE:
103
                coordinates.add((Coordinate)coordinates.get(0).clone());
104
                break;
105
            }
106
            pi.next();
107
        }
108
        return coordinates;
109
    }
110

    
111
    /* (non-Javadoc)
112
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
113
     */
114
    public MultiPoint toPoints() throws GeometryException {
115
        MultiPoint multiPoint = new MultiPoint2D();
116
        Coordinate[] coordinates = getJTS().getCoordinates();
117
        multiPoint.ensureCapacity(coordinates.length);
118
        for (int i = 0; i < coordinates.length; i++) {
119
            multiPoint.addPoint(new Point2D(this.getProjection(), coordinates[i]));
120
        }
121
        return multiPoint;
122
    }
123

    
124
    /* (non-Javadoc)
125
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
126
     */
127
    public MultiLine toLines() throws GeometryException {
128
        MultiLine multiLine = new MultiLine2D();
129
        Line line = new Line2D(getJTS().getCoordinates());
130
        multiLine.addPrimitive(line);
131
        return multiLine;
132
    }
133

    
134
    /* (non-Javadoc)
135
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
136
     */
137
    public MultiPolygon toPolygons() throws GeometryException {
138
        MultiPolygon multiPolygon = new MultiPolygon2D();
139
        Polygon polygon = new Polygon2D(getJTS().getCoordinates());
140
        multiPolygon.addPrimitive(polygon);
141
        return multiPolygon;
142
    }
143

    
144

    
145
}