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