1
2
3
4
5
6
7
8
9 package math.geom2d.circulinear;
10
11 import java.awt.Graphics2D;
12 import java.util.ArrayList;
13 import java.util.Collection;
14
15 import math.geom2d.AffineTransform2D;
16 import math.geom2d.Box2D;
17 import math.geom2d.curve.Curve2D;
18 import math.geom2d.curve.Curve2DUtils;
19 import math.geom2d.curve.CurveSet2D;
20 import math.geom2d.domain.BoundaryPolyCurve2D;
21 import math.geom2d.domain.ContinuousOrientedCurve2D;
22 import math.geom2d.domain.PolyOrientedCurve2D;
23 import math.geom2d.transform.CircleInversion2D;
24
25
26
27
28
29
30
31
32
33
34 public class BoundaryPolyCirculinearCurve2D<T extends CirculinearContinuousCurve2D>
35 extends PolyCirculinearCurve2D<T>
36 implements CirculinearContinuousCurve2D, CirculinearContour2D {
37
38
39
40
41 public BoundaryPolyCirculinearCurve2D() {
42 super();
43 }
44
45 public BoundaryPolyCirculinearCurve2D(int size) {
46 super(size);
47 }
48
49 public BoundaryPolyCirculinearCurve2D(T[] curves) {
50 super(curves);
51 }
52
53 public BoundaryPolyCirculinearCurve2D(T[] curves, boolean closed) {
54 super(curves, closed);
55 }
56
57 public BoundaryPolyCirculinearCurve2D(Collection<? extends T> curves) {
58 super(curves);
59 }
60
61 public BoundaryPolyCirculinearCurve2D(Collection<? extends T> curves, boolean closed) {
62 super(curves, closed);
63 }
64
65
66
67
68
69
70
71
72
73
74 public static <T extends CirculinearContinuousCurve2D>
75 BoundaryPolyCirculinearCurve2D<T>
76 create(Collection<T> curves) {
77 return new BoundaryPolyCirculinearCurve2D<T>(curves);
78 }
79
80
81
82
83
84
85 public static <T extends CirculinearContinuousCurve2D>
86 BoundaryPolyCirculinearCurve2D<T>
87 create(Collection<T> curves, boolean closed) {
88 return new BoundaryPolyCirculinearCurve2D<T>(curves, closed);
89 }
90
91
92
93
94
95
96 public static <T extends CirculinearContour2D>
97 BoundaryPolyCirculinearCurve2D<T> create(T[] curves) {
98 return new BoundaryPolyCirculinearCurve2D<T>(curves);
99 }
100
101
102
103
104
105
106 public static <T extends CirculinearContour2D>
107 BoundaryPolyCirculinearCurve2D<T> create(T[] curves, boolean closed) {
108 return new BoundaryPolyCirculinearCurve2D<T>(curves, closed);
109 }
110
111
112
113
114
115
116
117
118 @Override
119 public double getLength() {
120 double sum = 0;
121 for(CirculinearCurve2D curve : this.getCurves())
122 sum += curve.getLength();
123 return sum;
124 }
125
126
127
128
129 @Override
130 public double getLength(double pos) {
131 return CirculinearCurve2DUtils.getLength(this, pos);
132 }
133
134
135
136
137 @Override
138 public double getPosition(double length) {
139 return CirculinearCurve2DUtils.getPosition(this, length);
140 }
141
142
143
144
145 @Override
146 public CirculinearRing2D getParallel(double dist) {
147 return GenericCirculinearRing2D.create(
148 CirculinearCurve2DUtils.createContinuousParallel(this, dist)
149 .getSmoothPieces());
150 }
151
152
153
154
155
156 @Override
157 public BoundaryPolyCirculinearCurve2D<? extends CirculinearContinuousCurve2D>
158 transform(CircleInversion2D inv) {
159
160 int n = curves.size();
161 BoundaryPolyCirculinearCurve2D<CirculinearContinuousCurve2D> result =
162 new BoundaryPolyCirculinearCurve2D<CirculinearContinuousCurve2D>(n);
163
164
165 for (CirculinearContinuousCurve2D curve : curves)
166 result.addCurve((CirculinearContinuousCurve2D)curve.transform(inv));
167 return result;
168 }
169
170
171
172
173
174
175
176 public void fill(Graphics2D g2) {
177 g2.fill(this.getGeneralPath());
178 }
179
180
181
182
183 public Collection<BoundaryPolyCirculinearCurve2D<T>> getBoundaryCurves() {
184 ArrayList<BoundaryPolyCirculinearCurve2D<T>> list =
185 new ArrayList<BoundaryPolyCirculinearCurve2D<T>>(1);
186 list.add(this);
187 return list;
188 }
189
190
191
192
193 public CirculinearDomain2D getDomain() {
194 return new GenericCirculinearDomain2D(this);
195 }
196
197
198
199
200
201
202
203
204
205 @Override
206 public Collection<? extends CirculinearElement2D> getSmoothPieces() {
207
208 ArrayList<CirculinearElement2D> result =
209 new ArrayList<CirculinearElement2D>();
210
211
212 for(CirculinearContinuousCurve2D curve : curves)
213 result.addAll(curve.getSmoothPieces());
214
215
216 return result;
217 }
218
219
220
221
222 @Override
223 public Collection<? extends BoundaryPolyCirculinearCurve2D<?>>
224 getContinuousCurves() {
225 return wrapCurve(this);
226 }
227
228 @Override
229 public BoundaryPolyCirculinearCurve2D<? extends CirculinearContinuousCurve2D>
230 getReverseCurve() {
231 int n = curves.size();
232
233 CirculinearContinuousCurve2D[] curves2 =
234 new CirculinearContinuousCurve2D[n];
235
236
237 for (int i = 0; i<n; i++)
238 curves2[i] = (CirculinearContinuousCurve2D)curves.get(n-1-i).getReverseCurve();
239
240
241 return new BoundaryPolyCirculinearCurve2D<CirculinearContinuousCurve2D>(curves2);
242 }
243
244 @Override
245 public PolyCirculinearCurve2D<? extends CirculinearContinuousCurve2D>
246 getSubCurve(double t0, double t1) {
247
248 PolyOrientedCurve2D<? extends ContinuousOrientedCurve2D> subcurve =
249 super.getSubCurve(t0, t1);
250
251
252 int n = subcurve.getCurveNumber();
253 PolyCirculinearCurve2D<CirculinearContinuousCurve2D> result =
254 new PolyCirculinearCurve2D<CirculinearContinuousCurve2D>(n);
255
256
257 for(Curve2D curve : subcurve) {
258 if(curve instanceof CirculinearContinuousCurve2D)
259 result.addCurve((CirculinearContinuousCurve2D) curve);
260 }
261
262
263 return result;
264 }
265
266
267
268
269 @Override
270 public CirculinearCurveSet2D<? extends CirculinearContinuousCurve2D>
271 clip(Box2D box) {
272
273 CurveSet2D<? extends Curve2D> set = Curve2DUtils.clipCurve(this, box);
274
275
276 int n = set.getCurveNumber();
277 CirculinearCurveSet2D<CirculinearContinuousCurve2D> result =
278 new CirculinearCurveSet2D<CirculinearContinuousCurve2D>(n);
279
280
281 for (Curve2D curve : set.getCurves()) {
282 if (curve instanceof CirculinearContinuousCurve2D)
283 result.addCurve((CirculinearContinuousCurve2D) curve);
284 }
285
286
287 return result;
288 }
289
290 @Override
291 public BoundaryPolyCurve2D<? extends ContinuousOrientedCurve2D>
292 transform(AffineTransform2D trans) {
293
294 int n = this.getCurveNumber();
295
296
297 BoundaryPolyCurve2D<ContinuousOrientedCurve2D> result =
298 new BoundaryPolyCurve2D<ContinuousOrientedCurve2D>(n);
299
300
301 for (ContinuousOrientedCurve2D curve : curves)
302 result.addCurve((ContinuousOrientedCurve2D)curve.transform(trans));
303
304 result.setClosed(this.isClosed());
305 return result;
306 }
307
308 }