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 @ 40435
History | View | Annotate | Download (3.16 KB)
1 | 40435 | jjdelcerro | /*
|
---|---|---|---|
2 | * Created on 25-nov-2004
|
||
3 | *
|
||
4 | * TODO To change the template for this generated file go to
|
||
5 | * Window - Preferences - Java - Code Generation - Code and Comments
|
||
6 | */
|
||
7 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | package org.gvsig.fmap.geom.primitive; |
||
48 | |||
49 | import java.awt.geom.AffineTransform; |
||
50 | import java.awt.geom.PathIterator; |
||
51 | import java.awt.geom.Point2D; |
||
52 | |||
53 | import org.gvsig.fmap.geom.Geometry; |
||
54 | |||
55 | /**
|
||
56 | * A iterator to retrieve all the points of a
|
||
57 | * {@link Geometry}
|
||
58 | *
|
||
59 | * @author FJP
|
||
60 | */
|
||
61 | public class PointIterator extends GeneralPathXIterator { |
||
62 | /** Transform applied on the coordinates during iteration */
|
||
63 | private AffineTransform at; |
||
64 | |||
65 | /** The point we are going to provide when asked for coordinates */
|
||
66 | private Point2D p; |
||
67 | |||
68 | /** True when the point has been read once */
|
||
69 | private boolean done; |
||
70 | |||
71 | /**
|
||
72 | * Creates a new PointIterator object.
|
||
73 | *
|
||
74 | * @param p The polygon
|
||
75 | * @param at The affine transform applied to coordinates during iteration
|
||
76 | */
|
||
77 | public PointIterator(Point2D p, AffineTransform at) { |
||
78 | super(new GeneralPathX()); |
||
79 | if (at == null) { |
||
80 | at = new AffineTransform(); |
||
81 | } |
||
82 | |||
83 | this.at = at;
|
||
84 | this.p = p;
|
||
85 | done = false;
|
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * Return the winding rule for determining the interior of the path.
|
||
90 | *
|
||
91 | * @return <code>WIND_EVEN_ODD</code> by default.
|
||
92 | */
|
||
93 | public int getWindingRule() { |
||
94 | return PathIterator.WIND_EVEN_ODD; |
||
95 | } |
||
96 | |||
97 | /**
|
||
98 | * @see java.awt.geom.PathIterator#next()
|
||
99 | */
|
||
100 | public void next() { |
||
101 | done = true;
|
||
102 | } |
||
103 | |||
104 | /**
|
||
105 | * @see java.awt.geom.PathIterator#isDone()
|
||
106 | */
|
||
107 | public boolean isDone() { |
||
108 | return done;
|
||
109 | } |
||
110 | |||
111 | /**
|
||
112 | * @see java.awt.geom.PathIterator#currentSegment(double[])
|
||
113 | */
|
||
114 | public int currentSegment(double[] coords) { |
||
115 | coords[0] = p.getX();
|
||
116 | coords[1] = p.getY();
|
||
117 | at.transform(coords, 0, coords, 0, 1); |
||
118 | |||
119 | return PathIterator.SEG_MOVETO; |
||
120 | } |
||
121 | |||
122 | /* (non-Javadoc)
|
||
123 | * @see java.awt.geom.PathIterator#currentSegment(float[])
|
||
124 | */
|
||
125 | public int currentSegment(float[] coords) { |
||
126 | coords[0] = (float) p.getX(); |
||
127 | coords[1] = (float) p.getY(); |
||
128 | at.transform(coords, 0, coords, 0, 1); |
||
129 | |||
130 | return PathIterator.SEG_MOVETO; |
||
131 | } |
||
132 | } |