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.spline;
28
29 import java.util.Collection;
30
31 import math.geom2d.AffineTransform2D;
32 import math.geom2d.Box2D;
33 import math.geom2d.Point2D;
34 import math.geom2d.Vector2D;
35 import math.geom2d.curve.Curve2D;
36 import math.geom2d.curve.Curve2DUtils;
37 import math.geom2d.curve.CurveSet2D;
38 import math.geom2d.curve.PolyCurve2D;
39
40
41
42
43
44
45 public class PolyCubicBezierCurve2D extends PolyCurve2D<CubicBezierCurve2D> {
46
47
48
49
50 public PolyCubicBezierCurve2D() {
51 super();
52 }
53
54 public PolyCubicBezierCurve2D(int n) {
55 super(n);
56 }
57
58 public PolyCubicBezierCurve2D(CubicBezierCurve2D[] curves) {
59 super(curves);
60 }
61
62 public PolyCubicBezierCurve2D(Collection<CubicBezierCurve2D> curves) {
63 super(curves);
64 }
65
66
67
68
69
70
71
72
73
74 public final static PolyCubicBezierCurve2D create(Point2D[] points){
75
76 int np = points.length;
77
78
79 int nc = (np-1)/3;
80
81
82 PolyCubicBezierCurve2D polyBezier = new PolyCubicBezierCurve2D(nc);
83
84
85 for(int i=0; i<nc; i++)
86 polyBezier.addCurve(new CubicBezierCurve2D(
87 points[i*3], points[i*3+1], points[i*3+2], points[i*3+3]));
88
89
90 return polyBezier;
91 }
92
93
94
95
96
97
98
99 public final static PolyCubicBezierCurve2D create(
100 Point2D[] points, Vector2D[] vectors){
101
102 int np = Math.min(points.length, vectors.length);
103
104
105 int nc = (np-1)/2;
106
107
108 PolyCubicBezierCurve2D polyBezier = new PolyCubicBezierCurve2D(nc);
109
110
111 for(int i=0; i<nc; i++)
112 polyBezier.addCurve(new CubicBezierCurve2D(
113 points[i*2], vectors[i*2], points[i*2+1], vectors[i*2+1]));
114
115
116 return polyBezier;
117 }
118
119
120
121
122
123
124
125
126 @Override
127 public PolyCubicBezierCurve2D clip(Box2D box) {
128
129 CurveSet2D<? extends Curve2D> set = Curve2DUtils.clipCurve(this, box);
130
131
132 PolyCubicBezierCurve2D result = new PolyCubicBezierCurve2D(
133 set.getCurveNumber());
134
135
136 for (Curve2D curve : set.getCurves()) {
137 if (curve instanceof CubicBezierCurve2D)
138 result.addCurve((CubicBezierCurve2D) curve);
139 }
140 return result;
141 }
142
143 @Override
144 public PolyCubicBezierCurve2D transform(AffineTransform2D trans) {
145 PolyCubicBezierCurve2D result = new PolyCubicBezierCurve2D(this.curves.size());
146 for (CubicBezierCurve2D curve : curves)
147 result.addCurve(curve.transform(trans));
148 return result;
149 }
150
151 }