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

History | View | Annotate | Download (5.91 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.BaseEllipse2DZ;
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.PeriEllipse;
36
import org.gvsig.fmap.geom.primitive.Point;
37

    
38

    
39
/**
40
 * @author fdiaz
41
 *
42
 */
43
public class PeriEllipse2DZ extends BaseEllipse2DZ implements PeriEllipse{
44

    
45
    /**
46
     *
47
     */
48
    private static final long serialVersionUID = -3947765110197450655L;
49

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

    
57

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

    
69

    
70
    /* (non-Javadoc)
71
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
72
     */
73
    public com.vividsolutions.jts.geom.Geometry getJTS() {
74
        ArrayListCoordinateSequence coordinates = getJTSCoordinates();
75
        //Ellipse's getJTSCoordinates return the coordinates in reverse order
76
        LineString g = JTSUtils.createJTSLineString(coordinates);
77
        return g.reverse();
78
    }
79

    
80

    
81
    /* (non-Javadoc)
82
     * @see org.gvsig.fmap.geom.primitive.Curve#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
83
     */
84
    public void setPoints(Point initialPoint, Point endPoint) {
85
        String message = "Calling deprecated method setPoints of a perimeter of ellipse";
86
        notifyDeprecated(message);
87
        throw new UnsupportedOperationException(message);
88
    }
89

    
90
    /* (non-Javadoc)
91
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
92
     */
93
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
94
        PeriEllipse clonedEllipse = (PeriEllipse) this.cloneGeometry();
95

    
96
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
97
        Point center = new Point2D((getAxis1Start().getX()+getAxis1End().getX())/2,
98
            (getAxis1Start().getY()+getAxis1End().getY())/2);
99
        double axis1Lenght = getAxis1Start().distance(getAxis1End());
100

    
101
        Point clonedAxis1Start = (Point) getAxis1Start().cloneGeometry();
102
        Point clonedAxis1End = (Point) getAxis1End().cloneGeometry();
103
        double clonedYDist = this.ydist+distance;
104

    
105
        clonedAxis1Start.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1Start().getX(), axis1Lenght/2+distance));
106
        clonedAxis1Start.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1Start().getY(), axis1Lenght/2+distance));
107

    
108
        clonedAxis1End.setX(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getX(), getAxis1End().getX(), axis1Lenght/2+distance));
109
        clonedAxis1End.setY(JTSUtils.straightLineThroughTwoPointsEquation(0, axis1Lenght/2, center.getY(), getAxis1End().getY(), axis1Lenght/2+distance));
110

    
111
        clonedEllipse.setPoints(clonedAxis1Start, clonedAxis1End, clonedYDist);
112
        return clonedEllipse;
113
    }
114
 
115
    @Override
116
    public Geometry offset(int joinStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
117
        return offset(distance);
118
    }
119

    
120
    @Override
121
    public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException {
122
        PeriEllipse2D other = new PeriEllipse2D();
123
        other.setProjection(this.getProjection());
124
        other.setPoints((Point)init.force2D(), (Point)end.force2D(), ydist);
125
        return other;
126
    }
127

    
128
    @Override
129
    public Geometry force2DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
130
        PeriEllipse2DM other = new PeriEllipse2DM();
131
        other.setProjection(this.getProjection());
132
        other.setPoints((Point)init.force2DM(), (Point)end.force2DM(), ydist);
133
        return other;
134
    }
135
    
136
    @Override
137
    public Geometry force3D() throws GeometryOperationNotSupportedException, GeometryOperationException {
138
        Geometry c = this.cloneGeometry();
139
        return c;
140
    }
141

    
142
    @Override
143
    public Geometry force3DM() throws GeometryOperationNotSupportedException, GeometryOperationException {
144
        PeriEllipse2DZM other = new PeriEllipse2DZM();
145
        other.setProjection(this.getProjection());
146
        other.setPoints((Point)init.force3DM(), (Point)end.force3DM(), ydist);
147
        return other;
148
    }
149
    
150

    
151
}