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.Point2D;
29 import math.geom2d.Shape2D;
30 import math.geom2d.Vector2D;
31 import math.geom2d.curve.Curve2D;
32 import math.geom2d.curve.Curve2DUtils;
33 import math.geom2d.curve.CurveSet2D;
34 import math.geom2d.curve.SmoothCurve2D;
35 import math.geom2d.domain.ContinuousOrientedCurve2D;
36 import math.geom2d.line.StraightLine2D;
37
38
39
40
41
42
43
44
45 @Deprecated
46 public class QuadBezier2D extends QuadBezierCurve2D
47 implements SmoothCurve2D, ContinuousOrientedCurve2D, Cloneable {
48
49 private static final long serialVersionUID = 1L;
50
51
52
53
54 public QuadBezier2D() {
55 this(0, 0, 0, 0, 0, 0);
56 }
57
58
59
60
61
62
63
64 public QuadBezier2D(double[][] coefs) {
65 this(coefs[0][0], coefs[1][0], coefs[0][0]+coefs[0][1]/2.0, coefs[1][0]
66 +coefs[1][1]/2.0, coefs[0][0]+coefs[0][1]+coefs[0][2],
67 coefs[1][0]+coefs[1][1]+coefs[1][2]);
68 }
69
70
71
72
73
74
75
76
77
78
79 public QuadBezier2D(java.awt.geom.Point2D p1, java.awt.geom.Point2D ctrl,
80 java.awt.geom.Point2D p2) {
81 this(p1.getX(), p1.getY(), ctrl.getX(), ctrl.getY(), p2.getX(), p2
82 .getY());
83 }
84
85 public QuadBezier2D(java.awt.geom.Point2D[] pts) {
86 this(pts[0].getX(), pts[0].getY(), pts[1].getX(), pts[1].getY(), pts[2]
87 .getX(), pts[2].getY());
88 }
89
90
91
92
93
94
95 public QuadBezier2D(double x1, double y1, double xctrl, double yctrl,
96 double x2, double y2) {
97 super(x1, y1, xctrl, yctrl, x2, y2);
98 }
99
100
101
102
103
104 @Override
105 public QuadBezier2D getReverseCurve() {
106 return new QuadBezier2D(this.getP2(), this.getControl(), this.getP1());
107 }
108
109
110
111
112 @Override
113 public QuadBezier2D getSubCurve(double t0, double t1) {
114 t0 = Math.max(t0, 0);
115 t1 = Math.min(t1, 1);
116 if (t0>t1)
117 return null;
118
119
120 Point2D p0 = getPoint(t0);
121 Point2D p1 = getPoint(t1);
122
123
124 Vector2D v0 = getTangent(t0);
125 Vector2D v1 = getTangent(t1);
126
127
128 StraightLine2D tan0 = new StraightLine2D(p0, v0);
129 StraightLine2D tan1 = new StraightLine2D(p1, v1);
130 Point2D control = tan0.getIntersection(tan1);
131
132
133 return new QuadBezier2D(p0, control, p1);
134 }
135
136
137
138
139
140
141
142
143 @Override
144 public CurveSet2D<? extends QuadBezier2D> clip(Box2D box) {
145
146 CurveSet2D<SmoothCurve2D> set = Curve2DUtils.clipSmoothCurve(this, box);
147
148
149 CurveSet2D<QuadBezier2D> result = new CurveSet2D<QuadBezier2D>();
150
151
152 for (Curve2D curve : set.getCurves()) {
153 if (curve instanceof QuadBezier2D)
154 result.addCurve((QuadBezier2D) curve);
155 }
156 return result;
157 }
158
159
160
161
162
163 @Override
164 public QuadBezier2D transform(AffineTransform2D trans) {
165 return new QuadBezier2D(
166 trans.transform(this.getP1()),
167 trans.transform(this.getControl()),
168 trans.transform(this.getP2()));
169 }
170
171 @Override
172 public boolean equals(Object obj) {
173 if(!(obj instanceof java.awt.geom.QuadCurve2D.Double))
174 return false;
175
176 java.awt.geom.QuadCurve2D.Double bezier =
177 (java.awt.geom.QuadCurve2D.Double) obj;
178 if(Math.abs(this.x1-bezier.x1)>Shape2D.ACCURACY) return false;
179 if(Math.abs(this.y1-bezier.y1)>Shape2D.ACCURACY) return false;
180 if(Math.abs(this.ctrlx-bezier.ctrlx)>Shape2D.ACCURACY) return false;
181 if(Math.abs(this.ctrly-bezier.ctrly)>Shape2D.ACCURACY) return false;
182 if(Math.abs(this.x2-bezier.x2)>Shape2D.ACCURACY) return false;
183 if(Math.abs(this.y2-bezier.y2)>Shape2D.ACCURACY) return false;
184
185 return true;
186 }
187
188 @Override
189 public QuadBezier2D clone() {
190 return new QuadBezier2D(x1, y1, ctrlx, ctrly, x2, y2);
191 }
192 }