Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / primitive / PointIterator.java @ 40596

History | View | Annotate | Download (2.74 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.geom.primitive;
25

    
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.PathIterator;
28
import java.awt.geom.Point2D;
29

    
30
import org.gvsig.fmap.geom.Geometry;
31

    
32
/**
33
 * A iterator to retrieve all the points of a 
34
 * {@link Geometry}
35
 *
36
 * @author FJP
37
 */
38
public class PointIterator extends GeneralPathXIterator {
39
        /** Transform applied on the coordinates during iteration */
40
        private AffineTransform at;
41

    
42
        /** The point we are going to provide when asked for coordinates */
43
        private Point2D p;
44

    
45
        /** True when the point has been read once */
46
        private boolean done;
47

    
48
        /**
49
         * Creates a new PointIterator object.
50
         *
51
         * @param p The polygon
52
         * @param at The affine transform applied to coordinates during iteration
53
         */
54
        public PointIterator(Point2D p, AffineTransform at) {
55
                super(new GeneralPathX());
56
                if (at == null) {
57
                        at = new AffineTransform();
58
                }
59

    
60
                this.at = at;
61
                this.p = p;
62
                done = false;
63
        }
64

    
65
        /**
66
         * Return the winding rule for determining the interior of the path.
67
         *
68
         * @return <code>WIND_EVEN_ODD</code> by default.
69
         */
70
        public int getWindingRule() {
71
                return PathIterator.WIND_EVEN_ODD;
72
        }
73

    
74
        /**
75
         * @see java.awt.geom.PathIterator#next()
76
         */
77
        public void next() {
78
                done = true;
79
        }
80

    
81
        /**
82
         * @see java.awt.geom.PathIterator#isDone()
83
         */
84
        public boolean isDone() {
85
                return done;
86
        }
87

    
88
        /**
89
         * @see java.awt.geom.PathIterator#currentSegment(double[])
90
         */
91
        public int currentSegment(double[] coords) {
92
                coords[0] = p.getX();
93
                coords[1] = p.getY();
94
                at.transform(coords, 0, coords, 0, 1);
95

    
96
                return PathIterator.SEG_MOVETO;
97
        }
98

    
99
        /* (non-Javadoc)
100
         * @see java.awt.geom.PathIterator#currentSegment(float[])
101
         */
102
        public int currentSegment(float[] coords) {
103
                coords[0] = (float) p.getX();
104
                coords[1] = (float) p.getY();
105
                at.transform(coords, 0, coords, 0, 1);
106

    
107
                return PathIterator.SEG_MOVETO;
108
        }
109
}