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 / Ellipse2D.java @ 42441

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.AffineTransform;
26

    
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryLocator;
29
import org.gvsig.fmap.geom.GeometryManager;
30
import org.gvsig.fmap.geom.jts.primitive.point.Point2D;
31
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
32
import org.gvsig.fmap.geom.jts.util.JTSUtils;
33
import org.gvsig.fmap.geom.jts.util.UtilFunctions;
34
import org.gvsig.fmap.geom.operation.GeometryOperationException;
35
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
36
import org.gvsig.fmap.geom.primitive.Ellipse;
37
import org.gvsig.fmap.geom.primitive.Point;
38

    
39

    
40
/**
41
 * @author fdiaz
42
 *
43
 */
44
public class Ellipse2D extends BaseEllipse2D implements Ellipse {
45

    
46
    /**
47
     *
48
     */
49
    private static final long serialVersionUID = 3414562338763885954L;
50

    
51
    /**
52
     * @param subtype
53
     */
54
    public Ellipse2D() {
55
        super(Geometry.TYPES.ELLIPSE);
56
    }
57

    
58

    
59
    /* (non-Javadoc)
60
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
61
     */
62
    public Geometry cloneGeometry() {
63
        Ellipse2D clone = new Ellipse2D();
64
        clone.setPoints((Point)init.cloneGeometry(), (Point)end.cloneGeometry(), ydist);
65
        return clone;
66
    }
67

    
68
    /* (non-Javadoc)
69
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
70
     */
71
    public com.vividsolutions.jts.geom.Geometry getJTS() {
72
        ArrayListCoordinateSequence coordinates = getJTSCoordinates();
73
        return JTSUtils.createJTSPolygon(coordinates);
74
    }
75

    
76

    
77
    /* (non-Javadoc)
78
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getRectangleCorner()
79
     */
80
    public Point getRectangleCorner() {
81
        return new Point2D(
82
            this.getAxis1Start().getX(),
83
            this.getAxis1Start().getY()-this.getAxis2Dist());
84
    }
85

    
86

    
87
    /* (non-Javadoc)
88
     * @see org.gvsig.fmap.geom.primitive.Ellipse#getRectangleHeight()
89
     */
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
    public double getRectangleWidth() throws GeometryOperationNotSupportedException, GeometryOperationException {
99
        return this.getAxis1Start().distance(this.getAxis1End());
100
    }
101

    
102

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

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

    
116
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
117
        Point center = new Point2D((getAxis1Start().getX()+getAxis1End().getX())/2,
118
            (getAxis1Start().getY()+getAxis1End().getY())/2);
119
        double axis1Lenght = getAxis1Start().distance(getAxis1End());
120

    
121
        Point clonedAxis1Start = (Point) getAxis1Start().cloneGeometry();
122
        Point clonedAxis1End = (Point) getAxis1End().cloneGeometry();
123
        double clonedYDist = this.ydist+distance;
124

    
125
        clonedAxis1Start.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1Start().getX(), axis1Lenght/2+distance));
126
        clonedAxis1Start.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1Start().getY(), axis1Lenght/2+distance));
127

    
128
        clonedAxis1End.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1End().getX(), axis1Lenght/2+distance));
129
        clonedAxis1End.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1End().getY(), axis1Lenght/2+distance));
130

    
131
        clonedEllipse.setPoints(clonedAxis1Start, clonedAxis1End, clonedYDist);
132
        return clonedEllipse;
133
    }
134
}