1 |
/* CubicCurve2D.java -- represents a parameterized cubic curve in 2-D space |
/* CubicCurve2D.java -- represents a parameterized cubic curve in 2-D space |
2 |
Copyright (C) 2002 Free Software Foundation |
Copyright (C) 2002, 2003 Free Software Foundation |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
95 |
double cy1, double cx2, double cy2, |
double cy1, double cx2, double cy2, |
96 |
double x2, double y2) |
double x2, double y2) |
97 |
{ |
{ |
98 |
// XXX Implement. |
return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, cx1, cy1), |
99 |
throw new Error("not implemented"); |
Line2D.ptSegDistSq(x1, y1, x2, y2, cx2, cy2)); |
100 |
} |
} |
101 |
public static double getFlatness(double x1, double y1, double cx1, |
public static double getFlatness(double x1, double y1, double cx1, |
102 |
double cy1, double cx2, double cy2, |
double cy1, double cx2, double cy2, |
130 |
getX2(), getY2())); |
getX2(), getY2())); |
131 |
} |
} |
132 |
|
|
133 |
public void subdivide(CubicCurve2D l, CubicCurve2D r) |
public void subdivide(CubicCurve2D left, CubicCurve2D right) |
134 |
{ |
{ |
|
if (l == null) |
|
|
l = new CubicCurve2D.Double(); |
|
|
if (r == null) |
|
|
r = new CubicCurve2D.Double(); |
|
135 |
// Use empty slots at end to share single array. |
// Use empty slots at end to share single array. |
136 |
double[] d = new double[] { getX1(), getY1(), getCtrlX1(), getCtrlY1(), |
double[] d = new double[] { getX1(), getY1(), getCtrlX1(), getCtrlY1(), |
137 |
getCtrlX2(), getCtrlY2(), getX2(), getY2(), |
getCtrlX2(), getCtrlY2(), getX2(), getY2(), |
138 |
0, 0, 0, 0, 0, 0 }; |
0, 0, 0, 0, 0, 0 }; |
139 |
subdivide(d, 0, d, 0, d, 6); |
subdivide(d, 0, d, 0, d, 6); |
140 |
l.setCurve(d, 0); |
if (left != null) |
141 |
r.setCurve(d, 6); |
left.setCurve(d, 0); |
142 |
|
if (right != null) |
143 |
|
right.setCurve(d, 6); |
144 |
} |
} |
145 |
public static void subdivide(CubicCurve2D src, |
public static void subdivide(CubicCurve2D src, |
146 |
CubicCurve2D l, CubicCurve2D r) |
CubicCurve2D l, CubicCurve2D r) |
151 |
double[] left, int leftOff, |
double[] left, int leftOff, |
152 |
double[] right, int rightOff) |
double[] right, int rightOff) |
153 |
{ |
{ |
154 |
// XXX Implement. |
// To understand this code, please have a look at the image |
155 |
throw new Error("not implemented"); |
// "CubicCurve2D-3.png" in the sub-directory "doc-files". |
156 |
|
double src_C1_x, src_C1_y, src_C2_x, src_C2_y; |
157 |
|
double left_P1_x, left_P1_y; |
158 |
|
double left_C1_x, left_C1_y, left_C2_x, left_C2_y; |
159 |
|
double right_C1_x, right_C1_y, right_C2_x, right_C2_y; |
160 |
|
double right_P2_x, right_P2_y; |
161 |
|
double Mid_x, Mid_y; // Mid = left.P2 = right.P1 |
162 |
|
|
163 |
|
left_P1_x = src[srcOff]; |
164 |
|
left_P1_y = src[srcOff + 1]; |
165 |
|
src_C1_x = src[srcOff + 2]; |
166 |
|
src_C1_y = src[srcOff + 3]; |
167 |
|
src_C2_x = src[srcOff + 4]; |
168 |
|
src_C2_y = src[srcOff + 5]; |
169 |
|
right_P2_x = src[srcOff + 6]; |
170 |
|
right_P2_y = src[srcOff + 7]; |
171 |
|
|
172 |
|
left_C1_x = (left_P1_x + src_C1_x) / 2; |
173 |
|
left_C1_y = (left_P1_y + src_C1_y) / 2; |
174 |
|
right_C2_x = (right_P2_x + src_C2_x) / 2; |
175 |
|
right_C2_y = (right_P2_y + src_C2_y) / 2; |
176 |
|
Mid_x = (src_C1_x + src_C2_x) / 2; |
177 |
|
Mid_y = (src_C1_y + src_C2_y) / 2; |
178 |
|
left_C2_x = (left_C1_x + Mid_x) / 2; |
179 |
|
left_C2_y = (left_C1_y + Mid_y) / 2; |
180 |
|
right_C1_x = (Mid_x + right_C2_x) / 2; |
181 |
|
right_C1_y = (Mid_y + right_C2_y) / 2; |
182 |
|
Mid_x = (left_C2_x + right_C1_x) / 2; |
183 |
|
Mid_y = (left_C2_y + right_C1_y) / 2; |
184 |
|
|
185 |
|
if (left != null) |
186 |
|
{ |
187 |
|
left[leftOff] = left_P1_x; |
188 |
|
left[leftOff + 1] = left_P1_y; |
189 |
|
left[leftOff + 2] = left_C1_x; |
190 |
|
left[leftOff + 3] = left_C1_y; |
191 |
|
left[leftOff + 4] = left_C2_x; |
192 |
|
left[leftOff + 5] = left_C2_y; |
193 |
|
left[leftOff + 6] = Mid_x; |
194 |
|
left[leftOff + 7] = Mid_y; |
195 |
|
} |
196 |
|
|
197 |
|
if (right != null) |
198 |
|
{ |
199 |
|
right[rightOff] = Mid_x; |
200 |
|
right[rightOff + 1] = Mid_y; |
201 |
|
right[rightOff + 2] = right_C1_x; |
202 |
|
right[rightOff + 3] = right_C1_y; |
203 |
|
right[rightOff + 4] = right_C2_x; |
204 |
|
right[rightOff + 5] = right_C2_y; |
205 |
|
right[rightOff + 6] = right_P2_x; |
206 |
|
right[rightOff + 7] = right_P2_y; |
207 |
|
} |
208 |
} |
} |
209 |
public static int solveCubic(double[] eqn) |
public static int solveCubic(double[] eqn) |
210 |
{ |
{ |
212 |
} |
} |
213 |
public static int solveCubic(double[] eqn, double[] res) |
public static int solveCubic(double[] eqn, double[] res) |
214 |
{ |
{ |
215 |
if (eqn[3] == 0) |
double a, b, c, q, r, Q, R; |
216 |
|
|
217 |
|
double c3 = eqn[3]; |
218 |
|
if (c3 == 0) |
219 |
return QuadCurve2D.solveQuadratic(eqn, res); |
return QuadCurve2D.solveQuadratic(eqn, res); |
220 |
// XXX Implement. |
|
221 |
throw new Error("not implemented"); |
// Divide the equation by the cubic coefficient. |
222 |
|
c = eqn[0] / c3; |
223 |
|
b = eqn[1] / c3; |
224 |
|
a = eqn[2] / c3; |
225 |
|
|
226 |
|
// We now need to solve x^3 + ax^2 + bx + c = 0. |
227 |
|
throw new Error("not implemented"); // FIXME |
228 |
} |
} |
229 |
|
|
230 |
public boolean contains(double x, double y) |
public boolean contains(double x, double y) |