1
2
3
4
5
6
7
8
9 package math.geom2d.circulinear;
10
11 import java.util.ArrayList;
12 import java.util.Collection;
13
14 import math.geom2d.Box2D;
15 import math.geom2d.curve.*;
16 import math.geom2d.domain.BoundarySet2D;
17 import math.geom2d.domain.ContinuousOrientedCurve2D;
18 import math.geom2d.transform.CircleInversion2D;
19
20
21
22
23
24
25
26 public class CirculinearBoundarySet2D<T extends CirculinearContour2D>
27 extends BoundarySet2D<T> implements CirculinearBoundary2D {
28
29
30
31
32
33
34
35
36
37
38
39
40 public CirculinearBoundarySet2D() {
41 this.curves = new ArrayList<T>();
42 }
43
44
45
46
47
48 public CirculinearBoundarySet2D(int n) {
49 this.curves = new ArrayList<T>(n);
50 }
51
52
53
54
55
56
57 public CirculinearBoundarySet2D(T[] curves) {
58 this.curves = new ArrayList<T>(curves.length);
59 for (T element : curves)
60 this.addCurve(element);
61 }
62
63
64
65
66
67
68
69 public CirculinearBoundarySet2D(T curve) {
70 this.curves = new ArrayList<T>();
71 this.curves.add(curve);
72 }
73
74
75
76
77
78
79
80 public CirculinearBoundarySet2D(Collection<? extends T> curves) {
81 this.curves = new ArrayList<T>(curves.size());
82 this.curves.addAll(curves);
83 }
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 public double getLength() {
118 double sum = 0;
119 for(CirculinearCurve2D curve : this.getCurves())
120 sum += curve.getLength();
121 return sum;
122 }
123
124
125
126
127 public double getLength(double pos) {
128 return CirculinearCurve2DUtils.getLength(this, pos);
129 }
130
131
132
133
134 public double getPosition(double length) {
135 return CirculinearCurve2DUtils.getPosition(this, length);
136 }
137
138
139
140
141 public CirculinearDomain2D getBuffer(double dist) {
142 return CirculinearCurve2DUtils.computeBuffer(this, dist);
143 }
144
145
146
147
148 public CirculinearCurve2D getParallel(double d) {
149 return CirculinearCurve2DUtils.createParallel(this, d);
150 }
151
152
153
154
155 public CirculinearBoundarySet2D<? extends CirculinearContour2D>
156 transform(CircleInversion2D inv) {
157
158 CirculinearBoundarySet2D<CirculinearContour2D> result =
159 new CirculinearBoundarySet2D<CirculinearContour2D>(
160 curves.size());
161
162
163 for (CirculinearContour2D curve : curves)
164 result.addCurve(curve.transform(inv));
165 return result;
166 }
167
168
169
170
171 @Override
172 public Collection<? extends CirculinearContour2D> getContinuousCurves() {
173
174 ArrayList<T> result = new ArrayList<T>();
175
176
177 result.addAll(curves);
178 return result;
179 }
180
181 @Override
182 public CirculinearCurveSet2D<? extends CirculinearContinuousCurve2D> clip(Box2D box) {
183
184 CurveSet2D<? extends Curve2D> set = Curve2DUtils.clipCurve(this, box);
185
186
187 int n = set.getCurveNumber();
188 CirculinearCurveSet2D<CirculinearContinuousCurve2D> result =
189 new CirculinearCurveSet2D<CirculinearContinuousCurve2D>(n);
190
191
192 for (Curve2D curve : set.getCurves()) {
193 if (curve instanceof CirculinearContinuousCurve2D)
194 result.addCurve((CirculinearContinuousCurve2D) curve);
195 }
196
197
198 return result;
199 }
200
201 @Override
202 public CirculinearBoundarySet2D<? extends CirculinearContour2D>
203 getReverseCurve(){
204 int n = curves.size();
205
206 CirculinearContour2D[] curves2 = new CirculinearContour2D[n];
207
208
209 for (int i = 0; i<n; i++)
210 curves2[i] = (CirculinearContour2D)curves.get(n-1-i).getReverseCurve();
211
212
213 return new CirculinearBoundarySet2D<CirculinearContour2D>(curves2);
214 }
215
216 @Override
217 public CirculinearCurveSet2D<? extends CirculinearContinuousCurve2D> getSubCurve(
218 double t0, double t1) {
219
220 CurveSet2D<? extends ContinuousOrientedCurve2D> curveSet =
221 super.getSubCurve(t0, t1);
222
223
224 ArrayList<CirculinearContinuousCurve2D> curves =
225 new ArrayList<CirculinearContinuousCurve2D>(
226 curveSet.getCurveNumber());
227
228
229 for (Curve2D curve : curveSet.getCurves())
230 curves.add((CirculinearContinuousCurve2D) curve);
231
232
233 return new CirculinearCurveSet2D<CirculinearContinuousCurve2D>(curves);
234 }
235 }