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