svn-gvsig-desktop / tags / Root_FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / GeneralPathXIterator.java @ 1664
History | View | Annotate | Download (5.73 KB)
1 |
/*
|
---|---|
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 com.iver.cit.gvsig.fmap.core; |
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 |
*/
|
73 |
public class GeneralPathXIterator implements PathIterator { |
74 |
int typeIdx = 0; |
75 |
int pointIdx = 0; |
76 |
GeneralPathX path; |
77 |
AffineTransform affine;
|
78 |
|
79 |
private static final int curvesize[] = {2, 2, 4, 6, 0}; |
80 |
|
81 |
/**
|
82 |
* Constructs an iterator given a GeneralPathX.
|
83 |
* @see GeneralPathX#getPathIterator
|
84 |
*/
|
85 |
GeneralPathXIterator(GeneralPathX path) { |
86 |
this(path, null); |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Constructs an iterator given a GeneralPathX and an optional
|
91 |
* AffineTransform.
|
92 |
* @see GeneralPathX#getPathIterator
|
93 |
*/
|
94 |
GeneralPathXIterator(GeneralPathX path, AffineTransform at) {
|
95 |
this.path = path;
|
96 |
this.affine = at;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Return the winding rule for determining the interior of the
|
101 |
* path.
|
102 |
* @see PathIterator#WIND_EVEN_ODD
|
103 |
* @see PathIterator#WIND_NON_ZERO
|
104 |
*/
|
105 |
public int getWindingRule() { |
106 |
return path.getWindingRule();
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* Tests if there are more points to read.
|
111 |
* @return true if there are more points to read
|
112 |
*/
|
113 |
public boolean isDone() { |
114 |
return (typeIdx >= path.numTypes);
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Moves the iterator to the next segment of the path forwards
|
119 |
* along the primary direction of traversal as long as there are
|
120 |
* more points in that direction.
|
121 |
*/
|
122 |
public void next() { |
123 |
int type = path.pointTypes[typeIdx++];
|
124 |
pointIdx += curvesize[type]; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Returns the coordinates and type of the current path segment in
|
129 |
* the iteration.
|
130 |
* The return value is the path segment type:
|
131 |
* SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
|
132 |
* A float array of length 6 must be passed in and may be used to
|
133 |
* store the coordinates of the point(s).
|
134 |
* Each point is stored as a pair of float x,y coordinates.
|
135 |
* SEG_MOVETO and SEG_LINETO types will return one point,
|
136 |
* SEG_QUADTO will return two points,
|
137 |
* SEG_CUBICTO will return 3 points
|
138 |
* and SEG_CLOSE will not return any points.
|
139 |
* @see PathIterator#SEG_MOVETO
|
140 |
* @see PathIterator#SEG_LINETO
|
141 |
* @see PathIterator#SEG_QUADTO
|
142 |
* @see PathIterator#SEG_CUBICTO
|
143 |
* @see PathIterator#SEG_CLOSE
|
144 |
*/
|
145 |
public int currentSegment(float[] coords) { |
146 |
int type = path.pointTypes[typeIdx];
|
147 |
int numCoords = curvesize[type];
|
148 |
if (numCoords > 0 && affine != null) { |
149 |
affine.transform(path.pointCoords, pointIdx, |
150 |
coords, 0,
|
151 |
numCoords / 2);
|
152 |
} else {
|
153 |
for (int i=0; i < numCoords; i++) { |
154 |
coords[i] = (float) path.pointCoords[pointIdx + i];
|
155 |
} |
156 |
|
157 |
} |
158 |
return type;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Returns the coordinates and type of the current path segment in
|
163 |
* the iteration.
|
164 |
* The return value is the path segment type:
|
165 |
* SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
|
166 |
* A double array of length 6 must be passed in and may be used to
|
167 |
* store the coordinates of the point(s).
|
168 |
* Each point is stored as a pair of double x,y coordinates.
|
169 |
* SEG_MOVETO and SEG_LINETO types will return one point,
|
170 |
* SEG_QUADTO will return two points,
|
171 |
* SEG_CUBICTO will return 3 points
|
172 |
* and SEG_CLOSE will not return any points.
|
173 |
* @see PathIterator#SEG_MOVETO
|
174 |
* @see PathIterator#SEG_LINETO
|
175 |
* @see PathIterator#SEG_QUADTO
|
176 |
* @see PathIterator#SEG_CUBICTO
|
177 |
* @see PathIterator#SEG_CLOSE
|
178 |
*/
|
179 |
public int currentSegment(double[] coords) { |
180 |
int type = path.pointTypes[typeIdx];
|
181 |
int numCoords = curvesize[type];
|
182 |
if (numCoords > 0 && affine != null) { |
183 |
affine.transform(path.pointCoords, pointIdx, |
184 |
coords, 0,
|
185 |
numCoords / 2);
|
186 |
} else {
|
187 |
System.arraycopy(path.pointCoords, pointIdx, coords, 0, numCoords); |
188 |
} |
189 |
return type;
|
190 |
} |
191 |
} |