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 @ 40559

History | View | Annotate | Download (4.1 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
/*
25
 * Created on 25-nov-2004
26
 *
27
 * TODO To change the template for this generated file go to
28
 * Window - Preferences - Java - Code Generation - Code and Comments
29
 */
30
 /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.fmap.geom.primitive;
71

    
72
import java.awt.geom.AffineTransform;
73
import java.awt.geom.PathIterator;
74
import java.awt.geom.Point2D;
75

    
76
import org.gvsig.fmap.geom.Geometry;
77

    
78
/**
79
 * A iterator to retrieve all the points of a 
80
 * {@link Geometry}
81
 *
82
 * @author FJP
83
 */
84
public class PointIterator extends GeneralPathXIterator {
85
        /** Transform applied on the coordinates during iteration */
86
        private AffineTransform at;
87

    
88
        /** The point we are going to provide when asked for coordinates */
89
        private Point2D p;
90

    
91
        /** True when the point has been read once */
92
        private boolean done;
93

    
94
        /**
95
         * Creates a new PointIterator object.
96
         *
97
         * @param p The polygon
98
         * @param at The affine transform applied to coordinates during iteration
99
         */
100
        public PointIterator(Point2D p, AffineTransform at) {
101
                super(new GeneralPathX());
102
                if (at == null) {
103
                        at = new AffineTransform();
104
                }
105

    
106
                this.at = at;
107
                this.p = p;
108
                done = false;
109
        }
110

    
111
        /**
112
         * Return the winding rule for determining the interior of the path.
113
         *
114
         * @return <code>WIND_EVEN_ODD</code> by default.
115
         */
116
        public int getWindingRule() {
117
                return PathIterator.WIND_EVEN_ODD;
118
        }
119

    
120
        /**
121
         * @see java.awt.geom.PathIterator#next()
122
         */
123
        public void next() {
124
                done = true;
125
        }
126

    
127
        /**
128
         * @see java.awt.geom.PathIterator#isDone()
129
         */
130
        public boolean isDone() {
131
                return done;
132
        }
133

    
134
        /**
135
         * @see java.awt.geom.PathIterator#currentSegment(double[])
136
         */
137
        public int currentSegment(double[] coords) {
138
                coords[0] = p.getX();
139
                coords[1] = p.getY();
140
                at.transform(coords, 0, coords, 0, 1);
141

    
142
                return PathIterator.SEG_MOVETO;
143
        }
144

    
145
        /* (non-Javadoc)
146
         * @see java.awt.geom.PathIterator#currentSegment(float[])
147
         */
148
        public int currentSegment(float[] coords) {
149
                coords[0] = (float) p.getX();
150
                coords[1] = (float) p.getY();
151
                at.transform(coords, 0, coords, 0, 1);
152

    
153
                return PathIterator.SEG_MOVETO;
154
        }
155
}