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 / GeneralPathXIteratorSimple.java @ 40435
History | View | Annotate | Download (6.23 KB)
1 | 40435 | jjdelcerro | /*
|
---|---|---|---|
2 | * Created on 10-jun-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 | |||
52 | /*
|
||
53 | * @(#)GeneralPathXIterator.java 1.21 03/01/23
|
||
54 | *
|
||
55 | * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
|
||
56 | * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||
57 | */
|
||
58 | |||
59 | /**
|
||
60 | * This class represents the iterator for General Paths X.
|
||
61 | * It can be used to retrieve all of the elements in a GeneralPathX.
|
||
62 | * The {@link GeneralPathX#getPathIterator}
|
||
63 | * method is used to create a
|
||
64 | * GeneralPathXIterator for a particular GeneralPathX.
|
||
65 | * The iterator can be used to iterator the path only once.
|
||
66 | * Subsequent iterations require a new iterator.
|
||
67 | *
|
||
68 | * @see GeneralPathX
|
||
69 | *
|
||
70 | * @version 10 Feb 1997
|
||
71 | * @author Jim Graham
|
||
72 | * @deprecated
|
||
73 | * this class will be removed to the API. Use the
|
||
74 | * geometry methods to get the internal points.
|
||
75 | */
|
||
76 | public class GeneralPathXIteratorSimple implements PathIterator { |
||
77 | protected int typeIdx = 0; |
||
78 | protected int pointIdx = 0; |
||
79 | protected GeneralPathX path;
|
||
80 | protected AffineTransform affine; |
||
81 | |||
82 | private static final int curvesize[] = {1, 1, 2, 3, 0}; |
||
83 | |||
84 | /**
|
||
85 | * Constructs an iterator given a GeneralPathX.
|
||
86 | * @see GeneralPathX#getPathIterator
|
||
87 | */
|
||
88 | public GeneralPathXIteratorSimple(GeneralPathX path) {
|
||
89 | this(path, null); |
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * Constructs an iterator given a GeneralPathX and an optional
|
||
94 | * AffineTransform.
|
||
95 | * @see GeneralPathX#getPathIterator
|
||
96 | */
|
||
97 | public GeneralPathXIteratorSimple(GeneralPathX path, AffineTransform at) { |
||
98 | this.path = path;
|
||
99 | this.affine = at;
|
||
100 | } |
||
101 | |||
102 | /**
|
||
103 | * Return the winding rule for determining the interior of the
|
||
104 | * path.
|
||
105 | * @see PathIterator#WIND_EVEN_ODD
|
||
106 | * @see PathIterator#WIND_NON_ZERO
|
||
107 | */
|
||
108 | public int getWindingRule() { |
||
109 | return path.getWindingRule();
|
||
110 | } |
||
111 | |||
112 | /**
|
||
113 | * Tests if there are more points to read.
|
||
114 | * @return true if there are more points to read
|
||
115 | */
|
||
116 | public boolean isDone() { |
||
117 | return (typeIdx >= path.getNumTypes());
|
||
118 | } |
||
119 | |||
120 | /**
|
||
121 | * Moves the iterator to the next segment of the path forwards
|
||
122 | * along the primary direction of traversal as long as there are
|
||
123 | * more points in that direction.
|
||
124 | */
|
||
125 | public void next() { |
||
126 | int type = path.getTypeAt(typeIdx++);
|
||
127 | pointIdx += curvesize[type]; |
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * Returns the coordinates and type of the current path segment in
|
||
132 | * the iteration.
|
||
133 | * The return value is the path segment type:
|
||
134 | * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
|
||
135 | * A float array of length 6 must be passed in and may be used to
|
||
136 | * store the coordinates of the point(s).
|
||
137 | * Each point is stored as a pair of float x,y coordinates.
|
||
138 | * SEG_MOVETO and SEG_LINETO types will return one point,
|
||
139 | * SEG_QUADTO will return two points,
|
||
140 | * SEG_CUBICTO will return 3 points
|
||
141 | * and SEG_CLOSE will not return any points.
|
||
142 | * @see PathIterator#SEG_MOVETO
|
||
143 | * @see PathIterator#SEG_LINETO
|
||
144 | * @see PathIterator#SEG_QUADTO
|
||
145 | * @see PathIterator#SEG_CUBICTO
|
||
146 | * @see PathIterator#SEG_CLOSE
|
||
147 | */
|
||
148 | public int currentSegment(float[] coords) { |
||
149 | int type = path.getTypeAt(typeIdx);
|
||
150 | if (type != PathIterator.SEG_CLOSE){ |
||
151 | double[] coordinates = path.getCoordinatesAt(pointIdx); |
||
152 | if (affine != null) { |
||
153 | affine.transform(coordinates, 0,
|
||
154 | coords, 0,
|
||
155 | 1);
|
||
156 | } else {
|
||
157 | coords[0] = (float) coordinates[0]; |
||
158 | coords[1] = (float) coordinates[1]; |
||
159 | } |
||
160 | } |
||
161 | return type;
|
||
162 | } |
||
163 | |||
164 | /**
|
||
165 | * Returns the coordinates and type of the current path segment in
|
||
166 | * the iteration.
|
||
167 | * The return value is the path segment type:
|
||
168 | * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
|
||
169 | * A double array of length 6 must be passed in and may be used to
|
||
170 | * store the coordinates of the point(s).
|
||
171 | * Each point is stored as a pair of double x,y coordinates.
|
||
172 | * SEG_MOVETO and SEG_LINETO types will return one point,
|
||
173 | * SEG_QUADTO will return two points,
|
||
174 | * SEG_CUBICTO will return 3 points
|
||
175 | * and SEG_CLOSE will not return any points.
|
||
176 | * @see PathIterator#SEG_MOVETO
|
||
177 | * @see PathIterator#SEG_LINETO
|
||
178 | * @see PathIterator#SEG_QUADTO
|
||
179 | * @see PathIterator#SEG_CUBICTO
|
||
180 | * @see PathIterator#SEG_CLOSE
|
||
181 | */
|
||
182 | public int currentSegment(double[] coords) { |
||
183 | int type = path.getTypeAt(typeIdx);
|
||
184 | if (type != PathIterator.SEG_CLOSE){ |
||
185 | double[] coordinates = path.getCoordinatesAt(pointIdx); |
||
186 | if (affine != null) { |
||
187 | affine.transform(coordinates, 0, coords, 0, 1); |
||
188 | } else {
|
||
189 | coords[0] = coordinates[0]; |
||
190 | coords[1] = coordinates[1]; |
||
191 | } |
||
192 | } |
||
193 | return type;
|
||
194 | } |
||
195 | } |