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