1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package math.geom2d.line;
28
29 import java.util.Collection;
30
31 import math.geom2d.AffineTransform2D;
32 import math.geom2d.Point2D;
33 import math.geom2d.Shape2D;
34 import math.geom2d.polygon.Ring2D;
35
36
37
38
39
40
41
42
43 @Deprecated
44 public class ClosedPolyline2D extends Ring2D {
45
46 public ClosedPolyline2D() {
47 super();
48 }
49
50 public ClosedPolyline2D(Point2D initialPoint) {
51 super(initialPoint);
52 }
53
54 public ClosedPolyline2D(Point2D[] points) {
55 super(points);
56 }
57
58 public ClosedPolyline2D(double[] xcoords, double[] ycoords) {
59 super(xcoords, ycoords);
60 }
61
62 public ClosedPolyline2D(Collection<? extends Point2D> points) {
63 super(points);
64 }
65
66
67
68
69
70
71
72
73
74
75 @Override
76 public ClosedPolyline2D getReverseCurve() {
77 Point2D[] points2 = new Point2D[points.size()];
78 int n = points.size();
79 if (n>0) {
80 points2[0] = points.get(0);
81 for (int i = 1; i<n; i++)
82 points2[i] = points.get(n-i);
83 }
84 return new ClosedPolyline2D(points2);
85 }
86
87
88
89
90
91 @Override
92 public Polyline2D getSubCurve(double t0, double t1) {
93
94
95 Polyline2D res = new Polyline2D();
96
97
98 int indMax = (int) this.getT1();
99
100
101 t0 = Math.min(Math.max(t0, 0), indMax);
102 t1 = Math.min(Math.max(t1, 0), indMax);
103
104
105 int ind0 = (int) Math.floor(t0+Shape2D.ACCURACY);
106 int ind1 = (int) Math.floor(t1+Shape2D.ACCURACY);
107
108
109 if (ind0==ind1&&t0<t1) {
110
111 res.addPoint(this.getPoint(t0));
112 res.addPoint(this.getPoint(t1));
113
114 return res;
115 }
116
117
118 res.addPoint(this.getPoint(t0));
119
120 if (ind1>ind0) {
121
122 for (int n = ind0+1; n<=ind1; n++)
123 res.addPoint(points.get(n));
124 } else {
125
126 for (int n = ind0+1; n<indMax; n++)
127 res.addPoint(points.get(n));
128
129
130 for (int n = 0; n<=ind1; n++)
131 res.addPoint(points.get(n));
132 }
133
134
135 res.addPoint(this.getPoint(t1));
136
137
138 return res;
139 }
140
141
142
143
144
145
146
147 @Override
148 public ClosedPolyline2D transform(AffineTransform2D trans) {
149 Point2D[] pts = new Point2D[points.size()];
150 for (int i = 0; i<points.size(); i++)
151 pts[i] = trans.transform(points.get(i));
152 return new ClosedPolyline2D(pts);
153 }
154
155 }