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

History | View | Annotate | Download (6.03 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.point.Point3DM;
40
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D;
41
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
42
import org.gvsig.fmap.geom.primitive.Line;
43
import org.gvsig.fmap.geom.primitive.Point;
44
import org.gvsig.fmap.geom.primitive.Polygon;
45

    
46

    
47
/**
48
 * @author fdiaz
49
 *
50
 */
51
public abstract class BaseEllipticArc2DZM extends AbstractEllipticArc {
52

    
53
    private double zValue = Double.NaN;
54
    private double mValue = Double.NaN;
55

    
56
    /**
57
     * @param subtype
58
     */
59
    public BaseEllipticArc2DZM(int type) {
60
        super(type, Geometry.SUBTYPES.GEOM3DM);
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 Point3DM) {
73
            Point3DM point3DM = (Point3DM) point;
74
            if (Double.isNaN(zValue) && !(Double.isNaN(point3DM.getZ()))) {
75
                zValue = point3DM.getZ();
76
                if (axis1Start!=null) {
77
                    ((Point3DM) axis1Start).setZ(zValue);
78
                }
79
                if (axis1End!=null) {
80
                    ((Point3DM) axis1End).setZ(zValue);
81
                }
82
            }
83
            if (Double.isNaN(mValue) && !(Double.isNaN(point3DM.getM()))) {
84
                mValue = point3DM.getM();
85
                if (axis1Start!=null) {
86
                    ((Point3DM) axis1Start).setM(mValue);
87
                }
88
                if (axis1End!=null) {
89
                    ((Point3DM) axis1End).setM(mValue);
90
                }
91
            }
92
        }
93
        return new Point3DM(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue, Double.isNaN(mValue)?0:mValue);
94
    }
95

    
96
    /**
97
     * @return
98
     */
99
    protected ArrayListCoordinateSequence getJTSCoordinates() {
100
        PathIterator pi = getPathIterator(null);
101
        ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
102

    
103
        double coords[] = new double[6];
104
        while (!pi.isDone()) {
105
            switch (pi.currentSegment(coords)) {
106
            case PathIterator.SEG_MOVETO:
107
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
108
                break;
109
            case PathIterator.SEG_LINETO:
110
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
111
                break;
112
            case PathIterator.SEG_QUADTO:
113
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
114
                coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue));
115
                break;
116
            case PathIterator.SEG_CUBICTO:
117
                coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue));
118
                coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue));
119
                coordinates.add(new MCoordinate(coords[4], coords[5], zValue, mValue));
120
                break;
121
            case PathIterator.SEG_CLOSE:
122
                coordinates.add((Coordinate)coordinates.get(0).clone());
123
                break;
124
            }
125
            pi.next();
126
        }
127
        return coordinates;
128
    }
129

    
130

    
131
    /* (non-Javadoc)
132
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
133
     */
134
    public MultiPoint toPoints() throws GeometryException {
135
        MultiPoint multiPoint = new MultiPoint3D();
136
        Coordinate[] coordinates = getJTS().getCoordinates();
137
        multiPoint.ensureCapacity(coordinates.length);
138
        for (int i = 0; i < coordinates.length; i++) {
139
            multiPoint.addPoint(new Point3D(this.getProjection(), coordinates[i]));
140
        }
141
        return multiPoint;
142
    }
143

    
144
    /* (non-Javadoc)
145
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
146
     */
147
    public MultiLine toLines() throws GeometryException {
148
        MultiLine multiLine = new MultiLine3D();
149
        Line line = new Line3D(getJTS().getCoordinates());
150
        multiLine.addPrimitive(line);
151
        return multiLine;
152
    }
153

    
154
    /* (non-Javadoc)
155
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
156
     */
157
    public MultiPolygon toPolygons() throws GeometryException {
158
        MultiPolygon multiPolygon = new MultiPolygon3D();
159
        Polygon polygon = new Polygon3D(getJTS().getCoordinates());
160
        multiPolygon.addPrimitive(polygon);
161
        return multiPolygon;
162
    }
163

    
164

    
165

    
166
}