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