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 / curve / periellipse / PeriEllipse2D.java @ 45762

History | View | Annotate | Download (5.09 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.curve.periellipse;
24

    
25
import com.vividsolutions.jts.geom.LineString;
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.fmap.geom.GeometryLocator;
28
import org.gvsig.fmap.geom.GeometryManager;
29
import org.gvsig.fmap.geom.jts.primitive.point.Point2D;
30
import org.gvsig.fmap.geom.jts.primitive.surface.ellipse.BaseEllipse2D;
31
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
32
import org.gvsig.fmap.geom.jts.util.JTSUtils;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
35
import org.gvsig.fmap.geom.primitive.Ellipse;
36
import org.gvsig.fmap.geom.primitive.PeriEllipse;
37
import org.gvsig.fmap.geom.primitive.Point;
38

    
39

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

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

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

    
58

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

    
69
    @Override
70
    public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException {
71
        PeriEllipse2D other = new PeriEllipse2D();
72
        other.setProjection(this.getProjection());
73
        other.setPoints((Point)init.force2D(), (Point)end.force2D(), ydist);
74
        return other;
75
    }
76

    
77
    /* (non-Javadoc)
78
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
79
     */
80
    public com.vividsolutions.jts.geom.Geometry getJTS() {
81
        ArrayListCoordinateSequence coordinates = getJTSCoordinates();
82
        //Ellipse's getJTSCoordinates return the coordinates in reverse order
83
        LineString g = JTSUtils.createJTSLineString(coordinates);
84
        return g.reverse();
85
    }
86

    
87
    /* (non-Javadoc)
88
     * @see org.gvsig.fmap.geom.primitive.Curve#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
89
     */
90
    public void setPoints(Point initialPoint, Point endPoint) {
91
        String message = "Calling deprecated method setPoints of a perimeter of ellipse";
92
        notifyDeprecated(message);
93
        throw new UnsupportedOperationException(message);
94
    }
95

    
96

    
97
    /* (non-Javadoc)
98
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
99
     */
100
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
101
        PeriEllipse clonedEllipse = (PeriEllipse) this.cloneGeometry();
102

    
103
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
104
        Point center = new Point2D((getAxis1Start().getX()+getAxis1End().getX())/2,
105
            (getAxis1Start().getY()+getAxis1End().getY())/2);
106
        double axis1Lenght = getAxis1Start().distance(getAxis1End());
107

    
108
        Point clonedAxis1Start = (Point) getAxis1Start().cloneGeometry();
109
        Point clonedAxis1End = (Point) getAxis1End().cloneGeometry();
110
        double clonedYDist = this.ydist+distance;
111

    
112
        clonedAxis1Start.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1Start().getX(), axis1Lenght/2+distance));
113
        clonedAxis1Start.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1Start().getY(), axis1Lenght/2+distance));
114

    
115
        clonedAxis1End.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1End().getX(), axis1Lenght/2+distance));
116
        clonedAxis1End.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1End().getY(), axis1Lenght/2+distance));
117

    
118
        clonedEllipse.setPoints(clonedAxis1Start, clonedAxis1End, clonedYDist);
119
        return clonedEllipse;
120
    }
121
    
122
    @Override
123
    public Geometry offset(int joinStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
124
        return offset(distance);
125
    }
126

    
127
}