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 / BaseEllipticArc2DM.java @ 47432

History | View | Annotate | Download (5.61 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 com.vividsolutions.jts.geom.Coordinate;
26
import java.awt.geom.PathIterator;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryException;
29
import org.gvsig.fmap.geom.aggregate.MultiLine;
30
import org.gvsig.fmap.geom.aggregate.MultiPoint;
31
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
32
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D;
33
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D;
34
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D;
35
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate;
36
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
37
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM;
38
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
39
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D;
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 BaseEllipticArc2DM extends AbstractEllipticArc {
51

    
52
    private double mValue = Double.NaN;
53

    
54
    /**
55
     * @param subtype
56
     */
57
    public BaseEllipticArc2DM(int type) {
58
        super(type, Geometry.SUBTYPES.GEOM2DM);
59
    }
60

    
61
    /*
62
     * (non-Javadoc)
63
     *
64
     * @see
65
     * org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
66
     * .gvsig.fmap.geom.primitive.Point)
67
     */
68
    @Override
69
    protected Point fixPoint(Point point) {
70
        if (point instanceof Point2DM) {
71
            Point2DM point2DM = (Point2DM) point;
72
            if (Double.isNaN(mValue) && !(Double.isNaN(point2DM.getM()))) {
73
                mValue = point2DM.getM();
74
                if (axis1Start!=null) {
75
                    ((Point2DM) axis1Start).setM(mValue);
76
                }
77
                if (axis1End!=null) {
78
                    ((Point2DM) axis1End).setM(mValue);
79
                }
80
                return point2DM;
81
            }
82
        }
83
        return new Point3D(point.getX(), point.getY(), Double.isNaN(mValue)?0:mValue);
84
    }
85

    
86
    /**
87
     * @return
88
     */
89
    protected ArrayListCoordinateSequence getJTSCoordinates() {
90
        PathIterator pi = getPathIterator(null);
91
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
92

    
93
        double coords[] = new double[6];
94
        while (!pi.isDone()) {
95
            switch (pi.currentSegment(coords)) {
96
            case PathIterator.SEG_MOVETO:
97
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
98
                break;
99
            case PathIterator.SEG_LINETO:
100
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
101
                break;
102
            case PathIterator.SEG_QUADTO:
103
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
104
                coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue));
105
                break;
106
            case PathIterator.SEG_CUBICTO:
107
                coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue));
108
                coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue));
109
                coordinates.add(new MCoordinate(coords[4], coords[5], Double.NaN, mValue));
110
                break;
111
            case PathIterator.SEG_CLOSE:
112
                coordinates.add((Coordinate)coordinates.get(0).clone());
113
                break;
114
            }
115
            pi.next();
116
        }
117
        return coordinates;
118
    }
119

    
120

    
121
    /* (non-Javadoc)
122
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
123
     */
124
    public MultiPoint toPoints() throws GeometryException {
125
        MultiPoint multiPoint = new MultiPoint3D();
126
        Coordinate[] coordinates = getJTS().getCoordinates();
127
        multiPoint.ensureCapacity(coordinates.length);
128
        for (int i = 0; i < coordinates.length; i++) {
129
            multiPoint.addPoint(new Point3D(this.getProjection(), coordinates[i]));
130
        }
131
        return multiPoint;
132
    }
133

    
134
    /* (non-Javadoc)
135
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
136
     */
137
    public MultiLine toLines() throws GeometryException {
138
        MultiLine multiLine = new MultiLine3D();
139
        Line line = new Line3D(getJTS().getCoordinates());
140
        multiLine.addPrimitive(line);
141
        return multiLine;
142
    }
143

    
144
    /* (non-Javadoc)
145
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
146
     */
147
    public MultiPolygon toPolygons() throws GeometryException {
148
        MultiPolygon multiPolygon = new MultiPolygon3D();
149
        Polygon polygon = new Polygon3D(getJTS().getCoordinates());
150
        multiPolygon.addPrimitive(polygon);
151
        return multiPolygon;
152
    }
153

    
154

    
155

    
156
}