svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / aggregate / AbstractMultiCurve.java @ 42283
History | View | Annotate | Download (5.41 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.jts.aggregate; |
24 |
|
25 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.PathIterator; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
29 |
import java.util.List; |
30 |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
33 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
34 |
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
35 |
import org.gvsig.fmap.geom.primitive.Curve; |
36 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
37 |
import org.gvsig.fmap.geom.primitive.Primitive; |
38 |
|
39 |
|
40 |
/**
|
41 |
* @author fdiaz
|
42 |
*
|
43 |
*/
|
44 |
public abstract class AbstractMultiCurve extends AbstractMultiPrimitive implements MultiCurve { |
45 |
|
46 |
/**
|
47 |
*
|
48 |
*/
|
49 |
private static final long serialVersionUID = 5498201227873886542L; |
50 |
|
51 |
|
52 |
/**
|
53 |
* @param multiline
|
54 |
* @param subtype
|
55 |
*/
|
56 |
public AbstractMultiCurve(int type, int subtype) { |
57 |
super(type, subtype);
|
58 |
} |
59 |
|
60 |
/**
|
61 |
* @param type
|
62 |
*/
|
63 |
public AbstractMultiCurve(int subtype) { |
64 |
super(Geometry.TYPES.MULTICURVE, subtype);
|
65 |
} |
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see org.gvsig.fmap.geom.aggregate.MultiCurve#getCurveAt(int)
|
69 |
*/
|
70 |
public Curve getCurveAt(int index) { |
71 |
return (Curve)primitives.get(index);
|
72 |
} |
73 |
|
74 |
|
75 |
/* (non-Javadoc)
|
76 |
* @see org.gvsig.fmap.geom.aggregate.MultiCurve#addCurve(org.gvsig.fmap.geom.primitive.Curve)
|
77 |
*/
|
78 |
public void addCurve(Curve curve) { |
79 |
primitives.add((Primitive) fixPrimitive(curve)); |
80 |
} |
81 |
|
82 |
|
83 |
/* (non-Javadoc)
|
84 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
85 |
*/
|
86 |
public PathIterator getPathIterator(AffineTransform at) { |
87 |
MultiCurveIterator pi = new MultiCurveIterator(at);
|
88 |
return pi;
|
89 |
} |
90 |
|
91 |
/* (non-Javadoc)
|
92 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
93 |
*/
|
94 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
95 |
return getPathIterator(at);
|
96 |
} |
97 |
|
98 |
/* (non-Javadoc)
|
99 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
100 |
*/
|
101 |
public GeneralPathX getGeneralPath() {
|
102 |
return new DefaultGeneralPathX(getPathIterator(null), false, 0); |
103 |
} |
104 |
|
105 |
protected class MultiCurveIterator extends GeneralPathXIterator { |
106 |
|
107 |
/** Transform applied on the coordinates during iteration */
|
108 |
private AffineTransform at; |
109 |
|
110 |
/** True when the point has been read once */
|
111 |
private boolean done; |
112 |
private int index = 0; |
113 |
private List<PathIterator>iterators = new ArrayList<PathIterator>(primitives.size()); |
114 |
|
115 |
/**
|
116 |
* Creates a new PointIterator object.
|
117 |
*
|
118 |
* @param p
|
119 |
* The polygon
|
120 |
* @param at
|
121 |
* The affine transform applied to coordinates during
|
122 |
* iteration
|
123 |
*/
|
124 |
public MultiCurveIterator(AffineTransform at) { |
125 |
super(new GeneralPathX()); |
126 |
if (at == null) { |
127 |
at = new AffineTransform(); |
128 |
} |
129 |
|
130 |
this.at = at;
|
131 |
for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
132 |
Primitive primitive = (Primitive) iterator.next(); |
133 |
iterators.add(primitive.getPathIterator(at)); |
134 |
} |
135 |
done = false;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* Return the winding rule for determining the interior of the path.
|
140 |
*
|
141 |
* @return <code>WIND_EVEN_ODD</code> by default.
|
142 |
*/
|
143 |
public int getWindingRule() { |
144 |
return PathIterator.WIND_EVEN_ODD; |
145 |
} |
146 |
|
147 |
/**
|
148 |
* @see java.awt.geom.PathIterator#next()
|
149 |
*/
|
150 |
public void next() { |
151 |
PathIterator pathIteratorPrimitive = iterators.get(index);
|
152 |
pathIteratorPrimitive.next(); |
153 |
if(pathIteratorPrimitive.isDone()){
|
154 |
index++; |
155 |
done = (index==primitives.size()); |
156 |
} |
157 |
} |
158 |
|
159 |
/**
|
160 |
* @see java.awt.geom.PathIterator#isDone()
|
161 |
*/
|
162 |
public boolean isDone() { |
163 |
return done;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* @see java.awt.geom.PathIterator#currentSegment(double[])
|
168 |
*/
|
169 |
public int currentSegment(double[] coords) { |
170 |
return iterators.get(index).currentSegment(coords);
|
171 |
} |
172 |
|
173 |
/*
|
174 |
* (non-Javadoc)
|
175 |
*
|
176 |
* @see java.awt.geom.PathIterator#currentSegment(float[])
|
177 |
*/
|
178 |
public int currentSegment(float[] coords) { |
179 |
return iterators.get(index).currentSegment(coords);
|
180 |
} |
181 |
} |
182 |
|
183 |
} |