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

History | View | Annotate | Download (5.04 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.AffineTransform;
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.fmap.geom.jts.primitive.point.Point2D;
28
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM;
29
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
30
import org.gvsig.fmap.geom.jts.util.JTSUtils;
31
import org.gvsig.fmap.geom.operation.GeometryOperationException;
32
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
33
import org.gvsig.fmap.geom.primitive.Ellipse;
34
import org.gvsig.fmap.geom.primitive.Point;
35

    
36

    
37
/**
38
 * @author fdiaz
39
 *
40
 */
41
public class Ellipse2DZM extends BaseEllipse2DZ implements Ellipse {
42

    
43
    /**
44
     * @param subtype
45
     */
46
    public Ellipse2DZM() {
47
        super(Geometry.TYPES.ELLIPSE);
48
    }
49

    
50

    
51
    /* (non-Javadoc)
52
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
53
     */
54
    @Override
55
    public Geometry cloneGeometry() {
56
        Ellipse2DZM clone = new Ellipse2DZM();
57
        clone.setPoints((Point)init.cloneGeometry(), (Point)end.cloneGeometry(), ydist);
58
        clone.setProjection(this.getProjection());
59
        return clone;
60
    }
61

    
62
    /* (non-Javadoc)
63
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
64
     */
65
    @Override
66
    public com.vividsolutions.jts.geom.Geometry getJTS() {
67
        ArrayListCoordinateSequence coordinates = getJTSCoordinates();
68
        return JTSUtils.createJTSPolygon(coordinates);
69
    }
70

    
71

    
72
    /* (non-Javadoc)
73
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getRectangleCorner()
74
     */
75
    @Override
76
    public Point getRectangleCorner() {
77
        return new Point3DM(
78
            this.getAxis1Start().getX(),
79
            this.getAxis1Start().getY()-this.getAxis2Dist(),
80
            ((Point3DM)this.getAxis1Start()).getZ(),
81
            ((Point3DM)this.getAxis1Start()).getM()
82
        );
83
    }
84

    
85

    
86
    /* (non-Javadoc)
87
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getRectangleHeight()
88
     */
89
    @Override
90
    public double getRectangleHeight() {
91
        return this.getAxis2Dist()*2;
92
    }
93

    
94

    
95
    /* (non-Javadoc)
96
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getRectangleWidth()
97
     */
98
    @Override
99
    public double getRectangleWidth() throws GeometryOperationNotSupportedException, GeometryOperationException {
100
        return this.getAxis1Start().distance(this.getAxis1End());
101
    }
102

    
103

    
104
    /* (non-Javadoc)
105
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getRectangleRotation()
106
     */
107
    @Override
108
    public AffineTransform getRectangleRotation() throws GeometryOperationNotSupportedException, GeometryOperationException {
109
        return AffineTransform.getRotateInstance(getAxis1Angle(), this.getAxis1Start().getX(), this.getAxis1Start().getY());
110
    }
111

    
112

    
113
    /* (non-Javadoc)
114
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
115
     */
116
    @Override
117
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
118
        Ellipse clonedEllipse = (Ellipse) this.cloneGeometry();
119

    
120
        Point axis1Start = getAxis1Start();
121
        Point center = new Point2D((axis1Start.getX()+getAxis1End().getX())/2,
122
            (axis1Start.getY()+getAxis1End().getY())/2);
123
        double axis1Lenght = getAxis1Start().distance(getAxis1End());
124

    
125
        Point clonedAxis1Start = (Point) axis1Start.cloneGeometry();
126
        Point clonedAxis1End = (Point) getAxis1End().cloneGeometry();
127
        double clonedYDist = this.ydist+distance;
128

    
129
        clonedAxis1Start.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1Start().getX(), axis1Lenght/2+distance));
130
        clonedAxis1Start.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1Start().getY(), axis1Lenght/2+distance));
131

    
132
        clonedAxis1End.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1End().getX(), axis1Lenght/2+distance));
133
        clonedAxis1End.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1End().getY(), axis1Lenght/2+distance));
134

    
135
        clonedEllipse.setPoints(clonedAxis1Start, clonedAxis1End, clonedYDist);
136
        return clonedEllipse;
137
    }
138
}