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 / point / Point2D.java @ 42267

History | View | Annotate | Download (5.34 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.point;
24

    
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.PathIterator;
27

    
28
import com.vividsolutions.jts.geom.Coordinate;
29

    
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.GeometryLocator;
32
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX;
33
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator;
34
import org.gvsig.fmap.geom.primitive.GeneralPathX;
35
import org.gvsig.fmap.geom.type.GeometryType;
36

    
37
/**
38
 * @author fdiaz
39
 *
40
 */
41
public class Point2D extends AbstractPoint {
42

    
43
    /**
44
     *
45
     */
46
    private static final long serialVersionUID = -5486980182751169991L;
47

    
48
    /**
49
     *
50
     */
51
    public Point2D(Coordinate coordinates) {
52
        super(Geometry.SUBTYPES.GEOM2D, coordinates);
53

    
54
    }
55

    
56
    /**
57
     *
58
     */
59
    public Point2D() {
60
        this(new Coordinate(0, 0));
61
    }
62

    
63
    /**
64
    *
65
    */
66
    public Point2D(double x, double y) {
67
        this(new Coordinate(x, y));
68
    }
69

    
70
    /*
71
     * (non-Javadoc)
72
     *
73
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
74
     */
75
    public Geometry cloneGeometry() {
76
        return new Point2D((Coordinate) this.coordinate.clone());
77
    }
78

    
79
    /*
80
     * (non-Javadoc)
81
     *
82
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
83
     */
84
    public int getDimension() {
85
        return 2;
86
    }
87

    
88
    /*
89
     * (non-Javadoc)
90
     *
91
     * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
92
     */
93
    public GeometryType getGeometryType() {
94
        try {
95
            return GeometryLocator.getGeometryManager().getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D);
96
        } catch (Exception e) {
97
            return null;
98
        }
99
    }
100

    
101
    /*
102
     * (non-Javadoc)
103
     *
104
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
105
     */
106
    public boolean is3D() {
107
        return false;
108
    }
109

    
110
    /* (non-Javadoc)
111
     * @see org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com.vividsolutions.jts.geom.Coordinate)
112
     */
113
    public void setJTSCoordinate(Coordinate coordinate) {
114
        this.coordinate = coordinate;
115
    }
116

    
117
    /*
118
     * (non-Javadoc)
119
     *
120
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
121
     */
122
    public GeneralPathX getGeneralPath() {
123
        return new DefaultGeneralPathX(new PointIterator(null),false,0);
124
    }
125

    
126
    /*
127
     * (non-Javadoc)
128
     *
129
     * @see
130
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
131
     * )
132
     */
133
    public PathIterator getPathIterator(AffineTransform at) {
134
        PointIterator pi = new PointIterator(at);
135
        return pi;
136
    }
137

    
138

    
139
    public class PointIterator extends GeneralPathXIterator {
140
        /** Transform applied on the coordinates during iteration */
141
        private AffineTransform at;
142

    
143
        /** True when the point has been read once */
144
        private boolean done;
145

    
146
        /**
147
         * Creates a new PointIterator object.
148
         *
149
         * @param p The polygon
150
         * @param at The affine transform applied to coordinates during iteration
151
         */
152
        public PointIterator(AffineTransform at) {
153
            super(new GeneralPathX());
154
            if (at == null) {
155
                at = new AffineTransform();
156
            }
157

    
158
            this.at = at;
159
            done = false;
160
        }
161

    
162
        /**
163
         * Return the winding rule for determining the interior of the path.
164
         *
165
         * @return <code>WIND_EVEN_ODD</code> by default.
166
         */
167
        public int getWindingRule() {
168
            return PathIterator.WIND_EVEN_ODD;
169
        }
170

    
171
        /**
172
         * @see java.awt.geom.PathIterator#next()
173
         */
174
        public void next() {
175
            done = true;
176
        }
177

    
178
        /**
179
         * @see java.awt.geom.PathIterator#isDone()
180
         */
181
        public boolean isDone() {
182
            return done;
183
        }
184

    
185
        /**
186
         * @see java.awt.geom.PathIterator#currentSegment(double[])
187
         */
188
        public int currentSegment(double[] coords) {
189
            coords[0] = getX();
190
            coords[1] = getY();
191
            at.transform(coords, 0, coords, 0, 1);
192

    
193
            return PathIterator.SEG_MOVETO;
194
        }
195

    
196
        /* (non-Javadoc)
197
         * @see java.awt.geom.PathIterator#currentSegment(float[])
198
         */
199
        public int currentSegment(float[] coords) {
200
            coords[0] = (float) getX();
201
            coords[1] = (float) getY();
202
            at.transform(coords, 0, coords, 0, 1);
203

    
204
            return PathIterator.SEG_MOVETO;
205
        }
206
    }
207

    
208
}