1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package math.geom2d.spline;
25
26 import math.geom2d.AffineTransform2D;
27 import math.geom2d.Box2D;
28 import math.geom2d.Shape2D;
29 import math.geom2d.Vector2D;
30 import math.geom2d.curve.Curve2D;
31 import math.geom2d.curve.Curve2DUtils;
32 import math.geom2d.curve.CurveSet2D;
33 import math.geom2d.curve.SmoothCurve2D;
34
35
36
37
38
39
40
41
42 @Deprecated
43 public class BezierCurve2D extends CubicBezierCurve2D implements Cloneable {
44
45
46
47
48 private static final long serialVersionUID = 1L;
49
50
51
52
53
54 public BezierCurve2D() {
55 this(0, 0, 0, 0, 0, 0, 0, 0);
56 }
57
58
59
60
61
62
63
64 public BezierCurve2D(double[][] coefs) {
65 this(coefs[0][0], coefs[1][0],
66 coefs[0][0]+coefs[0][1]/3.0,
67 coefs[1][0]+coefs[1][1]/3.0,
68 coefs[0][0]+2*coefs[0][1]/3.0+coefs[0][2]/3.0,
69 coefs[1][0]+2*coefs[1][1]/3.0+coefs[1][2]/3.0,
70 coefs[0][0]+coefs[0][1]+coefs[0][2]+coefs[0][3],
71 coefs[1][0]+coefs[1][1]+coefs[1][2]+coefs[1][3]);
72 }
73
74
75
76
77
78
79
80
81
82
83
84 public BezierCurve2D(java.awt.geom.Point2D p1, java.awt.geom.Point2D ctrl1,
85 java.awt.geom.Point2D ctrl2, java.awt.geom.Point2D p2) {
86 this(p1.getX(), p1.getY(), ctrl1.getX(), ctrl1.getY(), ctrl2.getX(),
87 ctrl2.getY(), p2.getX(), p2.getY());
88 }
89
90
91
92
93
94
95
96
97
98
99 public BezierCurve2D(
100 java.awt.geom.Point2D p1, Vector2D v1,
101 java.awt.geom.Point2D p2, Vector2D v2) {
102 this(p1.getX(), p1.getY(), p1.getX()+v1.getX()/3,
103 p1.getY()+v1.getY()/3, p2.getX()-v2.getX()/3,
104 p2.getY()-v2.getY()/3, p2.getX(), p2.getY());
105 }
106
107
108
109
110
111
112 public BezierCurve2D(double x1, double y1, double xctrl1, double yctrl1,
113 double xctrl2, double yctrl2, double x2, double y2) {
114 super(x1, y1, xctrl1, yctrl1, xctrl2, yctrl2, x2, y2);
115 }
116
117
118
119
120
121
122
123
124 @Override
125 public BezierCurve2D getReverseCurve() {
126 return new BezierCurve2D(
127 this.getP2(), this.getCtrlP2(),
128 this.getCtrlP1(), this.getP1());
129 }
130
131
132
133
134 @Override
135 public BezierCurve2D getSubCurve(double t0, double t1) {
136 t0 = Math.max(t0, 0);
137 t1 = Math.min(t1, 1);
138 if (t0>t1)
139 return null;
140
141 double dt = t1-t0;
142 Vector2D v0 = getTangent(t0).times(dt);
143 Vector2D v1 = getTangent(t1).times(dt);
144 return new BezierCurve2D(getPoint(t0), v0, getPoint(t1), v1);
145 }
146
147
148
149
150 @Override
151 public CurveSet2D<? extends BezierCurve2D> clip(Box2D box) {
152
153 CurveSet2D<SmoothCurve2D> set =
154 Curve2DUtils.clipSmoothCurve(this, box);
155
156
157 CurveSet2D<BezierCurve2D> result = new CurveSet2D<BezierCurve2D>();
158
159
160 for (Curve2D curve : set.getCurves()) {
161 if (curve instanceof BezierCurve2D)
162 result.addCurve((BezierCurve2D) curve);
163 }
164 return result;
165 }
166
167
168
169
170
171 @Override
172 public BezierCurve2D transform(AffineTransform2D trans) {
173 return new BezierCurve2D(
174 trans.transform(this.getP1()),
175 trans.transform(this.getCtrlP1()),
176 trans.transform(this.getCtrlP2()),
177 trans.transform(this.getP2()));
178 }
179
180 @Override
181 public boolean equals(Object obj) {
182 if(!(obj instanceof java.awt.geom.CubicCurve2D.Double))
183 return false;
184
185 java.awt.geom.CubicCurve2D.Double bezier =
186 (java.awt.geom.CubicCurve2D.Double) obj;
187 if(Math.abs(this.x1-bezier.x1)>Shape2D.ACCURACY) return false;
188 if(Math.abs(this.y1-bezier.y1)>Shape2D.ACCURACY) return false;
189 if(Math.abs(this.ctrlx1-bezier.ctrlx1)>Shape2D.ACCURACY) return false;
190 if(Math.abs(this.ctrly1-bezier.ctrly1)>Shape2D.ACCURACY) return false;
191 if(Math.abs(this.ctrlx2-bezier.ctrlx2)>Shape2D.ACCURACY) return false;
192 if(Math.abs(this.ctrly2-bezier.ctrly2)>Shape2D.ACCURACY) return false;
193 if(Math.abs(this.x2-bezier.x2)>Shape2D.ACCURACY) return false;
194 if(Math.abs(this.y2-bezier.y2)>Shape2D.ACCURACY) return false;
195
196 return true;
197 }
198
199 @Override
200 public BezierCurve2D clone() {
201 return new BezierCurve2D(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
202 }
203 }