42 |
import java.awt.Shape; |
import java.awt.Shape; |
43 |
import java.util.NoSuchElementException; |
import java.util.NoSuchElementException; |
44 |
|
|
45 |
|
|
46 |
/** |
/** |
47 |
* STUBS ONLY |
* A two-dimensional curve that is parameterized with a cubic |
48 |
* XXX Implement and document. |
* function. |
49 |
|
* |
50 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
51 |
|
* alt="A drawing of a CubicCurve2D" /> |
52 |
|
* |
53 |
|
* @author Eric Blake (ebb9@email.byu.edu) |
54 |
|
* @author Graydon Hoare (graydon@redhat.com) |
55 |
|
* @author Sascha Brawer (brawer@dandelis.ch) |
56 |
|
* |
57 |
|
* @since 1.2 |
58 |
*/ |
*/ |
59 |
public abstract class CubicCurve2D implements Shape, Cloneable |
public abstract class CubicCurve2D |
60 |
|
implements Shape, Cloneable |
61 |
{ |
{ |
62 |
|
/** |
63 |
|
* Constructs a new CubicCurve2D. Typical users will want to |
64 |
|
* construct instances of a subclass, such as {@link |
65 |
|
* CubicCurve2D.Float} or {@link CubicCurve2D.Double}. |
66 |
|
*/ |
67 |
protected CubicCurve2D() |
protected CubicCurve2D() |
68 |
{ |
{ |
69 |
} |
} |
70 |
|
|
71 |
|
|
72 |
|
/** |
73 |
|
* Returns the <i>x</i> coordinate of the curve’s start |
74 |
|
* point. |
75 |
|
*/ |
76 |
public abstract double getX1(); |
public abstract double getX1(); |
77 |
|
|
78 |
|
|
79 |
|
/** |
80 |
|
* Returns the <i>y</i> coordinate of the curve’s start |
81 |
|
* point. |
82 |
|
*/ |
83 |
public abstract double getY1(); |
public abstract double getY1(); |
84 |
|
|
85 |
|
|
86 |
|
/** |
87 |
|
* Returns the curve’s start point. |
88 |
|
*/ |
89 |
public abstract Point2D getP1(); |
public abstract Point2D getP1(); |
90 |
|
|
91 |
|
|
92 |
|
/** |
93 |
|
* Returns the <i>x</i> coordinate of the curve’s first |
94 |
|
* control point. |
95 |
|
*/ |
96 |
public abstract double getCtrlX1(); |
public abstract double getCtrlX1(); |
97 |
|
|
98 |
|
|
99 |
|
/** |
100 |
|
* Returns the <i>y</i> coordinate of the curve’s first |
101 |
|
* control point. |
102 |
|
*/ |
103 |
public abstract double getCtrlY1(); |
public abstract double getCtrlY1(); |
104 |
|
|
105 |
|
|
106 |
|
/** |
107 |
|
* Returns the curve’s first control point. |
108 |
|
*/ |
109 |
public abstract Point2D getCtrlP1(); |
public abstract Point2D getCtrlP1(); |
110 |
|
|
111 |
|
|
112 |
|
/** |
113 |
|
* Returns the <i>x</i> coordinate of the curve’s second |
114 |
|
* control point. |
115 |
|
*/ |
116 |
public abstract double getCtrlX2(); |
public abstract double getCtrlX2(); |
117 |
|
|
118 |
|
|
119 |
|
/** |
120 |
|
* Returns the <i>y</i> coordinate of the curve’s second |
121 |
|
* control point. |
122 |
|
*/ |
123 |
public abstract double getCtrlY2(); |
public abstract double getCtrlY2(); |
124 |
|
|
125 |
|
|
126 |
|
/** |
127 |
|
* Returns the curve’s second control point. |
128 |
|
*/ |
129 |
public abstract Point2D getCtrlP2(); |
public abstract Point2D getCtrlP2(); |
130 |
|
|
131 |
|
|
132 |
|
/** |
133 |
|
* Returns the <i>x</i> coordinate of the curve’s end |
134 |
|
* point. |
135 |
|
*/ |
136 |
public abstract double getX2(); |
public abstract double getX2(); |
137 |
|
|
138 |
|
|
139 |
|
/** |
140 |
|
* Returns the <i>y</i> coordinate of the curve’s end |
141 |
|
* point. |
142 |
|
*/ |
143 |
public abstract double getY2(); |
public abstract double getY2(); |
144 |
|
|
145 |
|
|
146 |
|
/** |
147 |
|
* Returns the curve’s end point. |
148 |
|
*/ |
149 |
public abstract Point2D getP2(); |
public abstract Point2D getP2(); |
150 |
|
|
151 |
|
|
152 |
|
/** |
153 |
|
* Changes the curve geometry, separately specifying each coordinate |
154 |
|
* value. |
155 |
|
* |
156 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
157 |
|
* alt="A drawing of a CubicCurve2D" /> |
158 |
|
* |
159 |
|
* @param x1 the <i>x</i> coordinate of the curve’s new start |
160 |
|
* point. |
161 |
|
* |
162 |
|
* @param y1 the <i>y</i> coordinate of the curve’s new start |
163 |
|
* point. |
164 |
|
* |
165 |
|
* @param cx1 the <i>x</i> coordinate of the curve’s new |
166 |
|
* first control point. |
167 |
|
* |
168 |
|
* @param cy1 the <i>y</i> coordinate of the curve’s new |
169 |
|
* first control point. |
170 |
|
* |
171 |
|
* @param cx2 the <i>x</i> coordinate of the curve’s new |
172 |
|
* second control point. |
173 |
|
* |
174 |
|
* @param cy2 the <i>y</i> coordinate of the curve’s new |
175 |
|
* second control point. |
176 |
|
* |
177 |
|
* @param x2 the <i>x</i> coordinate of the curve’s new end |
178 |
|
* point. |
179 |
|
* |
180 |
|
* @param y2 the <i>y</i> coordinate of the curve’s new end |
181 |
|
* point. |
182 |
|
*/ |
183 |
public abstract void setCurve(double x1, double y1, double cx1, double cy1, |
public abstract void setCurve(double x1, double y1, double cx1, double cy1, |
184 |
double cx2, double cy2, double x2, double y2); |
double cx2, double cy2, double x2, double y2); |
185 |
|
|
186 |
|
|
187 |
|
/** |
188 |
|
* Changes the curve geometry, specifying coordinate values in an |
189 |
|
* array. |
190 |
|
* |
191 |
|
* @param coords an array containing the new coordinate values. The |
192 |
|
* <i>x</i> coordinate of the new start point is located at |
193 |
|
* <code>coords[offset]</code>, its <i>y</i> coordinate at |
194 |
|
* <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the |
195 |
|
* new first control point is located at <code>coords[offset + |
196 |
|
* 2]</code>, its <i>y</i> coordinate at <code>coords[offset + |
197 |
|
* 3]</code>. The <i>x</i> coordinate of the new second control |
198 |
|
* point is located at <code>coords[offset + 4]</code>, its <i>y</i> |
199 |
|
* coordinate at <code>coords[offset + 5]</code>. The <i>x</i> |
200 |
|
* coordinate of the new end point is located at <code>coords[offset |
201 |
|
* + 6]</code>, its <i>y</i> coordinate at <code>coords[offset + |
202 |
|
* 7]</code>. |
203 |
|
* |
204 |
|
* @param offset the offset of the first coordinate value in |
205 |
|
* <code>coords</code>. |
206 |
|
*/ |
207 |
public void setCurve(double[] coords, int offset) |
public void setCurve(double[] coords, int offset) |
208 |
{ |
{ |
209 |
setCurve(coords[offset++], coords[offset++], |
setCurve(coords[offset++], coords[offset++], |
211 |
coords[offset++], coords[offset++], |
coords[offset++], coords[offset++], |
212 |
coords[offset++], coords[offset++]); |
coords[offset++], coords[offset++]); |
213 |
} |
} |
214 |
|
|
215 |
|
|
216 |
|
/** |
217 |
|
* Changes the curve geometry, specifying coordinate values in |
218 |
|
* separate Point objects. |
219 |
|
* |
220 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
221 |
|
* alt="A drawing of a CubicCurve2D" /> |
222 |
|
* |
223 |
|
* <p>The curve does not keep any reference to the passed point |
224 |
|
* objects. Therefore, a later change to <code>p1</code>, |
225 |
|
* <code>c1</code>, <code>c2</code> or <code>p2</code> will not |
226 |
|
* affect the curve geometry. |
227 |
|
* |
228 |
|
* @param p1 the new start point. |
229 |
|
* @param c1 the new first control point. |
230 |
|
* @param c2 the new second control point. |
231 |
|
* @param p2 the new end point. |
232 |
|
*/ |
233 |
public void setCurve(Point2D p1, Point2D c1, Point2D c2, Point2D p2) |
public void setCurve(Point2D p1, Point2D c1, Point2D c2, Point2D p2) |
234 |
{ |
{ |
235 |
setCurve(p1.getX(), p1.getY(), c1.getX(), c1.getY(), |
setCurve(p1.getX(), p1.getY(), c1.getX(), c1.getY(), |
236 |
c2.getX(), c2.getY(), p2.getX(), p2.getY()); |
c2.getX(), c2.getY(), p2.getX(), p2.getY()); |
237 |
} |
} |
238 |
|
|
239 |
|
|
240 |
|
/** |
241 |
|
* Changes the curve geometry, specifying coordinate values in an |
242 |
|
* array of Point objects. |
243 |
|
* |
244 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
245 |
|
* alt="A drawing of a CubicCurve2D" /> |
246 |
|
* |
247 |
|
* <p>The curve does not keep references to the passed point |
248 |
|
* objects. Therefore, a later change to the <code>pts</code> array |
249 |
|
* or any of its elements will not affect the curve geometry. |
250 |
|
* |
251 |
|
* @param pts an array containing the points. The new start point |
252 |
|
* is located at <code>pts[offset]</code>, the new first control |
253 |
|
* point at <code>pts[offset + 1]</code>, the new second control |
254 |
|
* point at <code>pts[offset + 2]</code>, and the new end point |
255 |
|
* at <code>pts[offset + 3]</code>. |
256 |
|
* |
257 |
|
* @param offset the offset of the start point in <code>pts</code>. |
258 |
|
*/ |
259 |
public void setCurve(Point2D[] pts, int offset) |
public void setCurve(Point2D[] pts, int offset) |
260 |
{ |
{ |
261 |
setCurve(pts[offset].getX(), pts[offset++].getY(), |
setCurve(pts[offset].getX(), pts[offset++].getY(), |
263 |
pts[offset].getX(), pts[offset++].getY(), |
pts[offset].getX(), pts[offset++].getY(), |
264 |
pts[offset].getX(), pts[offset++].getY()); |
pts[offset].getX(), pts[offset++].getY()); |
265 |
} |
} |
266 |
|
|
267 |
|
|
268 |
|
/** |
269 |
|
* Changes the curve geometry to that of another curve. |
270 |
|
* |
271 |
|
* @param c the curve whose coordinates will be copied. |
272 |
|
*/ |
273 |
public void setCurve(CubicCurve2D c) |
public void setCurve(CubicCurve2D c) |
274 |
{ |
{ |
275 |
setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(), |
setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(), |
276 |
c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2()); |
c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2()); |
277 |
} |
} |
278 |
|
|
279 |
|
|
280 |
|
/** |
281 |
|
* Calculates the squared flatness of a cubic curve, directly |
282 |
|
* specifying each coordinate value. The flatness is the maximal |
283 |
|
* distance of a control point to the line between start and end |
284 |
|
* point. |
285 |
|
* |
286 |
|
* <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" |
287 |
|
* alt="A drawing that illustrates the flatness" /> |
288 |
|
* |
289 |
|
* <p>In the above drawing, the straight line connecting start point |
290 |
|
* P1 and end point P2 is depicted in gray. In comparison to C1, |
291 |
|
* control point C2 is father away from the gray line. Therefore, |
292 |
|
* the result will be the square of the distance between C2 and the |
293 |
|
* gray line, i.e. the squared length of the red line. |
294 |
|
* |
295 |
|
* @param x1 the <i>x</i> coordinate of the start point P1. |
296 |
|
* @param y1 the <i>y</i> coordinate of the start point P1. |
297 |
|
* @param cx1 the <i>x</i> coordinate of the first control point C1. |
298 |
|
* @param cy1 the <i>y</i> coordinate of the first control point C1. |
299 |
|
* @param cx2 the <i>x</i> coordinate of the second control point C2. |
300 |
|
* @param cy2 the <i>y</i> coordinate of the second control point C2. |
301 |
|
* @param x2 the <i>x</i> coordinate of the end point P2. |
302 |
|
* @param y2 the <i>y</i> coordinate of the end point P2. |
303 |
|
*/ |
304 |
public static double getFlatnessSq(double x1, double y1, double cx1, |
public static double getFlatnessSq(double x1, double y1, double cx1, |
305 |
double cy1, double cx2, double cy2, |
double cy1, double cx2, double cy2, |
306 |
double x2, double y2) |
double x2, double y2) |
308 |
return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, cx1, cy1), |
return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, cx1, cy1), |
309 |
Line2D.ptSegDistSq(x1, y1, x2, y2, cx2, cy2)); |
Line2D.ptSegDistSq(x1, y1, x2, y2, cx2, cy2)); |
310 |
} |
} |
311 |
|
|
312 |
|
|
313 |
|
/** |
314 |
|
* Calculates the flatness of a cubic curve, directly specifying |
315 |
|
* each coordinate value. The flatness is the maximal distance of a |
316 |
|
* control point to the line between start and end point. |
317 |
|
* |
318 |
|
* <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" |
319 |
|
* alt="A drawing that illustrates the flatness" /> |
320 |
|
* |
321 |
|
* <p>In the above drawing, the straight line connecting start point |
322 |
|
* P1 and end point P2 is depicted in gray. In comparison to C1, |
323 |
|
* control point C2 is father away from the gray line. Therefore, |
324 |
|
* the result will be the distance between C2 and the gray line, |
325 |
|
* i.e. the length of the red line. |
326 |
|
* |
327 |
|
* @param x1 the <i>x</i> coordinate of the start point P1. |
328 |
|
* @param y1 the <i>y</i> coordinate of the start point P1. |
329 |
|
* @param cx1 the <i>x</i> coordinate of the first control point C1. |
330 |
|
* @param cy1 the <i>y</i> coordinate of the first control point C1. |
331 |
|
* @param cx2 the <i>x</i> coordinate of the second control point C2. |
332 |
|
* @param cy2 the <i>y</i> coordinate of the second control point C2. |
333 |
|
* @param x2 the <i>x</i> coordinate of the end point P2. |
334 |
|
* @param y2 the <i>y</i> coordinate of the end point P2. |
335 |
|
*/ |
336 |
public static double getFlatness(double x1, double y1, double cx1, |
public static double getFlatness(double x1, double y1, double cx1, |
337 |
double cy1, double cx2, double cy2, |
double cy1, double cx2, double cy2, |
338 |
double x2, double y2) |
double x2, double y2) |
339 |
{ |
{ |
340 |
return Math.sqrt(getFlatnessSq(x1, y1, cx1, cy1, cx2, cy2, x2, y2)); |
return Math.sqrt(getFlatnessSq(x1, y1, cx1, cy1, cx2, cy2, x2, y2)); |
341 |
} |
} |
342 |
|
|
343 |
|
|
344 |
|
/** |
345 |
|
* Calculates the squared flatness of a cubic curve, specifying the |
346 |
|
* coordinate values in an array. The flatness is the maximal |
347 |
|
* distance of a control point to the line between start and end |
348 |
|
* point. |
349 |
|
* |
350 |
|
* <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" |
351 |
|
* alt="A drawing that illustrates the flatness" /> |
352 |
|
* |
353 |
|
* <p>In the above drawing, the straight line connecting start point |
354 |
|
* P1 and end point P2 is depicted in gray. In comparison to C1, |
355 |
|
* control point C2 is father away from the gray line. Therefore, |
356 |
|
* the result will be the square of the distance between C2 and the |
357 |
|
* gray line, i.e. the squared length of the red line. |
358 |
|
* |
359 |
|
* @param coords an array containing the coordinate values. The |
360 |
|
* <i>x</i> coordinate of the start point P1 is located at |
361 |
|
* <code>coords[offset]</code>, its <i>y</i> coordinate at |
362 |
|
* <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the |
363 |
|
* first control point C1 is located at <code>coords[offset + |
364 |
|
* 2]</code>, its <i>y</i> coordinate at <code>coords[offset + |
365 |
|
* 3]</code>. The <i>x</i> coordinate of the second control point C2 |
366 |
|
* is located at <code>coords[offset + 4]</code>, its <i>y</i> |
367 |
|
* coordinate at <code>coords[offset + 5]</code>. The <i>x</i> |
368 |
|
* coordinate of the end point P2 is located at <code>coords[offset |
369 |
|
* + 6]</code>, its <i>y</i> coordinate at <code>coords[offset + |
370 |
|
* 7]</code>. |
371 |
|
* |
372 |
|
* @param offset the offset of the first coordinate value in |
373 |
|
* <code>coords</code>. |
374 |
|
*/ |
375 |
public static double getFlatnessSq(double[] coords, int offset) |
public static double getFlatnessSq(double[] coords, int offset) |
376 |
{ |
{ |
377 |
return getFlatnessSq(coords[offset++], coords[offset++], |
return getFlatnessSq(coords[offset++], coords[offset++], |
379 |
coords[offset++], coords[offset++], |
coords[offset++], coords[offset++], |
380 |
coords[offset++], coords[offset++]); |
coords[offset++], coords[offset++]); |
381 |
} |
} |
382 |
|
|
383 |
|
|
384 |
|
/** |
385 |
|
* Calculates the flatness of a cubic curve, specifying the |
386 |
|
* coordinate values in an array. The flatness is the maximal |
387 |
|
* distance of a control point to the line between start and end |
388 |
|
* point. |
389 |
|
* |
390 |
|
* <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" |
391 |
|
* alt="A drawing that illustrates the flatness" /> |
392 |
|
* |
393 |
|
* <p>In the above drawing, the straight line connecting start point |
394 |
|
* P1 and end point P2 is depicted in gray. In comparison to C1, |
395 |
|
* control point C2 is father away from the gray line. Therefore, |
396 |
|
* the result will be the distance between C2 and the gray line, |
397 |
|
* i.e. the length of the red line. |
398 |
|
* |
399 |
|
* @param coords an array containing the coordinate values. The |
400 |
|
* <i>x</i> coordinate of the start point P1 is located at |
401 |
|
* <code>coords[offset]</code>, its <i>y</i> coordinate at |
402 |
|
* <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the |
403 |
|
* first control point C1 is located at <code>coords[offset + |
404 |
|
* 2]</code>, its <i>y</i> coordinate at <code>coords[offset + |
405 |
|
* 3]</code>. The <i>x</i> coordinate of the second control point C2 |
406 |
|
* is located at <code>coords[offset + 4]</code>, its <i>y</i> |
407 |
|
* coordinate at <code>coords[offset + 5]</code>. The <i>x</i> |
408 |
|
* coordinate of the end point P2 is located at <code>coords[offset |
409 |
|
* + 6]</code>, its <i>y</i> coordinate at <code>coords[offset + |
410 |
|
* 7]</code>. |
411 |
|
* |
412 |
|
* @param offset the offset of the first coordinate value in |
413 |
|
* <code>coords</code>. |
414 |
|
*/ |
415 |
public static double getFlatness(double[] coords, int offset) |
public static double getFlatness(double[] coords, int offset) |
416 |
{ |
{ |
417 |
return Math.sqrt(getFlatnessSq(coords[offset++], coords[offset++], |
return Math.sqrt(getFlatnessSq(coords[offset++], coords[offset++], |
419 |
coords[offset++], coords[offset++], |
coords[offset++], coords[offset++], |
420 |
coords[offset++], coords[offset++])); |
coords[offset++], coords[offset++])); |
421 |
} |
} |
422 |
|
|
423 |
|
|
424 |
|
/** |
425 |
|
* Calculates the squared flatness of this curve. The flatness is |
426 |
|
* the maximal distance of a control point to the line between start |
427 |
|
* and end point. |
428 |
|
* |
429 |
|
* <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" |
430 |
|
* alt="A drawing that illustrates the flatness" /> |
431 |
|
* |
432 |
|
* <p>In the above drawing, the straight line connecting start point |
433 |
|
* P1 and end point P2 is depicted in gray. In comparison to C1, |
434 |
|
* control point C2 is father away from the gray line. Therefore, |
435 |
|
* the result will be the square of the distance between C2 and the |
436 |
|
* gray line, i.e. the squared length of the red line. |
437 |
|
*/ |
438 |
public double getFlatnessSq() |
public double getFlatnessSq() |
439 |
{ |
{ |
440 |
return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(), |
return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(), |
441 |
getCtrlX2(), getCtrlY2(), getX2(), getY2()); |
getCtrlX2(), getCtrlY2(), getX2(), getY2()); |
442 |
} |
} |
443 |
|
|
444 |
|
|
445 |
|
/** |
446 |
|
* Calculates the flatness of this curve. The flatness is the |
447 |
|
* maximal distance of a control point to the line between start and |
448 |
|
* end point. |
449 |
|
* |
450 |
|
* <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" |
451 |
|
* alt="A drawing that illustrates the flatness" /> |
452 |
|
* |
453 |
|
* <p>In the above drawing, the straight line connecting start point |
454 |
|
* P1 and end point P2 is depicted in gray. In comparison to C1, |
455 |
|
* control point C2 is father away from the gray line. Therefore, |
456 |
|
* the result will be the distance between C2 and the gray line, |
457 |
|
* i.e. the length of the red line. |
458 |
|
*/ |
459 |
public double getFlatness() |
public double getFlatness() |
460 |
{ |
{ |
461 |
return Math.sqrt(getFlatnessSq(getX1(), getY1(), getCtrlX1(), |
return Math.sqrt(getFlatnessSq(getX1(), getY1(), getCtrlX1(), |
463 |
getX2(), getY2())); |
getX2(), getY2())); |
464 |
} |
} |
465 |
|
|
466 |
|
|
467 |
|
/** |
468 |
|
* Subdivides this curve into two halves. |
469 |
|
* |
470 |
|
* <p><img src="doc-files/CubicCurve2D-3.png" width="700" |
471 |
|
* height="180" alt="A drawing that illustrates the effects of |
472 |
|
* subdividing a CubicCurve2D" /> |
473 |
|
* |
474 |
|
* @param left a curve whose geometry will be set to the left half |
475 |
|
* of this curve, or <code>null</code> if the caller is not |
476 |
|
* interested in the left half. |
477 |
|
* |
478 |
|
* @param right a curve whose geometry will be set to the right half |
479 |
|
* of this curve, or <code>null</code> if the caller is not |
480 |
|
* interested in the right half. |
481 |
|
*/ |
482 |
public void subdivide(CubicCurve2D left, CubicCurve2D right) |
public void subdivide(CubicCurve2D left, CubicCurve2D right) |
483 |
{ |
{ |
484 |
// Use empty slots at end to share single array. |
// Use empty slots at end to share single array. |
491 |
if (right != null) |
if (right != null) |
492 |
right.setCurve(d, 6); |
right.setCurve(d, 6); |
493 |
} |
} |
494 |
|
|
495 |
|
|
496 |
|
/** |
497 |
|
* Subdivides a cubic curve into two halves. |
498 |
|
* |
499 |
|
* <p><img src="doc-files/CubicCurve2D-3.png" width="700" |
500 |
|
* height="180" alt="A drawing that illustrates the effects of |
501 |
|
* subdividing a CubicCurve2D" /> |
502 |
|
* |
503 |
|
* @param src the curve to be subdivided. |
504 |
|
* |
505 |
|
* @param left a curve whose geometry will be set to the left half |
506 |
|
* of <code>src</code>, or <code>null</code> if the caller is not |
507 |
|
* interested in the left half. |
508 |
|
* |
509 |
|
* @param right a curve whose geometry will be set to the right half |
510 |
|
* of <code>src</code>, or <code>null</code> if the caller is not |
511 |
|
* interested in the right half. |
512 |
|
*/ |
513 |
public static void subdivide(CubicCurve2D src, |
public static void subdivide(CubicCurve2D src, |
514 |
CubicCurve2D l, CubicCurve2D r) |
CubicCurve2D left, CubicCurve2D right) |
515 |
{ |
{ |
516 |
src.subdivide(l, r); |
src.subdivide(left, right); |
517 |
} |
} |
518 |
|
|
519 |
|
|
520 |
|
/** |
521 |
|
* Subdivides a cubic curve into two halves, passing all coordinates |
522 |
|
* in an array. |
523 |
|
* |
524 |
|
* <p><img src="doc-files/CubicCurve2D-3.png" width="700" |
525 |
|
* height="180" alt="A drawing that illustrates the effects of |
526 |
|
* subdividing a CubicCurve2D" /> |
527 |
|
* |
528 |
|
* <p>The left end point and the right start point will always be |
529 |
|
* identical. Memory-concious programmers thus may want to pass the |
530 |
|
* same array for both <code>left</code> and <code>right</code>, and |
531 |
|
* set <code>rightOff</code> to <code>leftOff + 6</code>. |
532 |
|
* |
533 |
|
* @param src an array containing the coordinates of the curve to be |
534 |
|
* subdivided. The <i>x</i> coordinate of the start point P1 is |
535 |
|
* located at <code>src[srcOff]</code>, its <i>y</i> at |
536 |
|
* <code>src[srcOff + 1]</code>. The <i>x</i> coordinate of the |
537 |
|
* first control point C1 is located at <code>src[srcOff + |
538 |
|
* 2]</code>, its <i>y</i> at <code>src[srcOff + 3]</code>. The |
539 |
|
* <i>x</i> coordinate of the second control point C2 is located at |
540 |
|
* <code>src[srcOff + 4]</code>, its <i>y</i> at <code>src[srcOff + |
541 |
|
* 5]</code>. The <i>x</i> coordinate of the end point is located at |
542 |
|
* <code>src[srcOff + 6]</code>, its <i>y</i> at <code>src[srcOff + |
543 |
|
* 7]</code>. |
544 |
|
* |
545 |
|
* @param srcOff an offset into <code>src</code>, specifying |
546 |
|
* the index of the start point’s <i>x</i> coordinate. |
547 |
|
* |
548 |
|
* @param left an array that will receive the coordinates of the |
549 |
|
* left half of <code>src</code>. It is acceptable to pass |
550 |
|
* <code>src</code>. A caller who is not interested in the left half |
551 |
|
* can pass <code>null</code>. |
552 |
|
* |
553 |
|
* @param leftOff an offset into <code>left</code>, specifying the |
554 |
|
* index where the start point’s <i>x</i> coordinate will be |
555 |
|
* stored. |
556 |
|
* |
557 |
|
* @param right an array that will receive the coordinates of the |
558 |
|
* right half of <code>src</code>. It is acceptable to pass |
559 |
|
* <code>src</code> or <code>left</code>. A caller who is not |
560 |
|
* interested in the right half can pass <code>null</code>. |
561 |
|
* |
562 |
|
* @param rightOff an offset into <code>right</code>, specifying the |
563 |
|
* index where the start point’s <i>x</i> coordinate will be |
564 |
|
* stored. |
565 |
|
*/ |
566 |
public static void subdivide(double[] src, int srcOff, |
public static void subdivide(double[] src, int srcOff, |
567 |
double[] left, int leftOff, |
double[] left, int leftOff, |
568 |
double[] right, int rightOff) |
double[] right, int rightOff) |
622 |
right[rightOff + 7] = right_P2_y; |
right[rightOff + 7] = right_P2_y; |
623 |
} |
} |
624 |
} |
} |
625 |
|
|
626 |
|
|
627 |
public static int solveCubic(double[] eqn) |
public static int solveCubic(double[] eqn) |
628 |
{ |
{ |
629 |
return solveCubic(eqn, eqn); |
return solveCubic(eqn, eqn); |
630 |
} |
} |
631 |
|
|
632 |
|
|
633 |
public static int solveCubic(double[] eqn, double[] res) |
public static int solveCubic(double[] eqn, double[] res) |
634 |
{ |
{ |
635 |
double a, b, c, q, r, Q, R; |
double a, b, c, q, r, Q, R; |
647 |
throw new Error("not implemented"); // FIXME |
throw new Error("not implemented"); // FIXME |
648 |
} |
} |
649 |
|
|
650 |
|
|
651 |
|
/** |
652 |
|
* Determines whether a position lies inside the area that is bounded |
653 |
|
* by the curve and the straight line connecting its end points. |
654 |
|
* |
655 |
|
* <p><img src="CubicCurve2D-5.png" width="350" height="180" |
656 |
|
* alt="A drawing of the area spanned by the curve" /> |
657 |
|
* |
658 |
|
* <p>The above drawing illustrates in which area points are |
659 |
|
* considered –contained— in a CubicCurve2D. |
660 |
|
*/ |
661 |
public boolean contains(double x, double y) |
public boolean contains(double x, double y) |
662 |
{ |
{ |
663 |
// XXX Implement. |
// XXX Implement. |
664 |
throw new Error("not implemented"); |
throw new Error("not implemented"); |
665 |
} |
} |
666 |
|
|
667 |
|
|
668 |
|
/** |
669 |
|
* Determines whether a point lies inside the area that is bounded |
670 |
|
* by the curve and the straight line connecting its end points. |
671 |
|
* |
672 |
|
* <p><img src="CubicCurve2D-5.png" width="350" height="180" |
673 |
|
* alt="A drawing of the area spanned by the curve" /> |
674 |
|
* |
675 |
|
* <p>The above drawing illustrates in which area points are |
676 |
|
* considered –contained— in a CubicCurve2D. |
677 |
|
*/ |
678 |
public boolean contains(Point2D p) |
public boolean contains(Point2D p) |
679 |
{ |
{ |
680 |
return contains(p.getX(), p.getY()); |
return contains(p.getX(), p.getY()); |
681 |
} |
} |
682 |
|
|
683 |
|
|
684 |
public boolean intersects(double x, double y, double w, double h) |
public boolean intersects(double x, double y, double w, double h) |
685 |
{ |
{ |
686 |
// XXX Implement. |
// XXX Implement. |
687 |
throw new Error("not implemented"); |
throw new Error("not implemented"); |
688 |
} |
} |
689 |
|
|
690 |
|
|
691 |
public boolean intersects(Rectangle2D r) |
public boolean intersects(Rectangle2D r) |
692 |
{ |
{ |
693 |
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
694 |
} |
} |
695 |
|
|
696 |
|
|
697 |
public boolean contains(double x, double y, double w, double h) |
public boolean contains(double x, double y, double w, double h) |
698 |
{ |
{ |
699 |
// XXX Implement. |
// XXX Implement. |
700 |
throw new Error("not implemented"); |
throw new Error("not implemented"); |
701 |
} |
} |
702 |
|
|
703 |
|
|
704 |
public boolean contains(Rectangle2D r) |
public boolean contains(Rectangle2D r) |
705 |
{ |
{ |
706 |
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
707 |
} |
} |
708 |
|
|
709 |
|
|
710 |
|
/** |
711 |
|
* Determines the smallest rectangle that encloses the |
712 |
|
* curve’s start, end and control points. As the illustration |
713 |
|
* below shows, the invisible control points may cause the bounds to |
714 |
|
* be much larger than the area that is actually covered by the |
715 |
|
* curve. |
716 |
|
* |
717 |
|
* <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180" |
718 |
|
* alt="An illustration of the bounds of a CubicCurve2D" /> |
719 |
|
*/ |
720 |
public Rectangle getBounds() |
public Rectangle getBounds() |
721 |
{ |
{ |
722 |
return getBounds2D().getBounds(); |
return getBounds2D().getBounds(); |
723 |
} |
} |
724 |
|
|
725 |
|
|
726 |
public PathIterator getPathIterator(final AffineTransform at) |
public PathIterator getPathIterator(final AffineTransform at) |
727 |
{ |
{ |
728 |
return new PathIterator() |
return new PathIterator() |
800 |
} |
} |
801 |
}; |
}; |
802 |
} |
} |
803 |
|
|
804 |
|
|
805 |
public PathIterator getPathIterator(AffineTransform at, double flatness) |
public PathIterator getPathIterator(AffineTransform at, double flatness) |
806 |
{ |
{ |
807 |
return new FlatteningPathIterator(getPathIterator(at), flatness); |
return new FlatteningPathIterator(getPathIterator(at), flatness); |
808 |
} |
} |
809 |
|
|
810 |
|
|
811 |
/** |
/** |
812 |
* Create a new curve of the same run-time type with the same contents as |
* Create a new curve with the same contents as this one. |
|
* this one. |
|
813 |
* |
* |
814 |
* @return the clone |
* @return the clone. |
815 |
*/ |
*/ |
816 |
public Object clone() |
public Object clone() |
817 |
{ |
{ |
818 |
try |
try |
819 |
{ |
{ |
820 |
return super.clone(); |
return super.clone(); |
821 |
} |
} |
822 |
catch (CloneNotSupportedException e) |
catch (CloneNotSupportedException e) |
823 |
{ |
{ |
824 |
throw (Error) new InternalError().initCause(e); // Impossible |
throw (Error) new InternalError().initCause(e); // Impossible |
825 |
} |
} |
826 |
} |
} |
827 |
|
|
828 |
|
|
829 |
/** |
/** |
830 |
* STUBS ONLY |
* A two-dimensional curve that is parameterized with a cubic |
831 |
|
* function and stores coordinate values in double-precision |
832 |
|
* floating-point format. |
833 |
|
* |
834 |
|
* @see CubicCurve2D.Float |
835 |
|
* |
836 |
|
* @author Eric Blake (ebb9@email.byu.edu) |
837 |
|
* @author Sascha Brawer (brawer@dandelis.ch) |
838 |
*/ |
*/ |
839 |
public static class Double extends CubicCurve2D |
public static class Double |
840 |
|
extends CubicCurve2D |
841 |
{ |
{ |
842 |
|
/** |
843 |
|
* The <i>x</i> coordinate of the curve’s start point. |
844 |
|
*/ |
845 |
public double x1; |
public double x1; |
846 |
|
|
847 |
|
|
848 |
|
/** |
849 |
|
* The <i>y</i> coordinate of the curve’s start point. |
850 |
|
*/ |
851 |
public double y1; |
public double y1; |
852 |
|
|
853 |
|
|
854 |
|
/** |
855 |
|
* The <i>x</i> coordinate of the curve’s first control point. |
856 |
|
*/ |
857 |
public double ctrlx1; |
public double ctrlx1; |
858 |
|
|
859 |
|
|
860 |
|
/** |
861 |
|
* The <i>y</i> coordinate of the curve’s first control point. |
862 |
|
*/ |
863 |
public double ctrly1; |
public double ctrly1; |
864 |
|
|
865 |
|
|
866 |
|
/** |
867 |
|
* The <i>x</i> coordinate of the curve’s second control point. |
868 |
|
*/ |
869 |
public double ctrlx2; |
public double ctrlx2; |
870 |
|
|
871 |
|
|
872 |
|
/** |
873 |
|
* The <i>y</i> coordinate of the curve’s second control point. |
874 |
|
*/ |
875 |
public double ctrly2; |
public double ctrly2; |
876 |
|
|
877 |
|
|
878 |
|
/** |
879 |
|
* The <i>x</i> coordinate of the curve’s end point. |
880 |
|
*/ |
881 |
public double x2; |
public double x2; |
882 |
|
|
883 |
|
|
884 |
|
/** |
885 |
|
* The <i>y</i> coordinate of the curve’s end point. |
886 |
|
*/ |
887 |
public double y2; |
public double y2; |
888 |
|
|
889 |
|
|
890 |
|
/** |
891 |
|
* Constructs a new CubicCurve2D that stores its coordinate values |
892 |
|
* in double-precision floating-point format. All points are |
893 |
|
* initially at position (0, 0). |
894 |
|
*/ |
895 |
public Double() |
public Double() |
896 |
{ |
{ |
897 |
} |
} |
898 |
|
|
899 |
|
|
900 |
|
/** |
901 |
|
* Constructs a new CubicCurve2D that stores its coordinate values |
902 |
|
* in double-precision floating-point format, specifying the |
903 |
|
* initial position of each point. |
904 |
|
* |
905 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
906 |
|
* alt="A drawing of a CubicCurve2D" /> |
907 |
|
* |
908 |
|
* @param x1 the <i>x</i> coordinate of the curve’s start |
909 |
|
* point. |
910 |
|
* |
911 |
|
* @param y1 the <i>y</i> coordinate of the curve’s start |
912 |
|
* point. |
913 |
|
* |
914 |
|
* @param cx1 the <i>x</i> coordinate of the curve’s first |
915 |
|
* control point. |
916 |
|
* |
917 |
|
* @param cy1 the <i>y</i> coordinate of the curve’s first |
918 |
|
* control point. |
919 |
|
* |
920 |
|
* @param cx2 the <i>x</i> coordinate of the curve’s second |
921 |
|
* control point. |
922 |
|
* |
923 |
|
* @param cy2 the <i>y</i> coordinate of the curve’s second |
924 |
|
* control point. |
925 |
|
* |
926 |
|
* @param x2 the <i>x</i> coordinate of the curve’s end |
927 |
|
* point. |
928 |
|
* |
929 |
|
* @param y2 the <i>y</i> coordinate of the curve’s end |
930 |
|
* point. |
931 |
|
*/ |
932 |
public Double(double x1, double y1, double cx1, double cy1, |
public Double(double x1, double y1, double cx1, double cy1, |
933 |
double cx2, double cy2, double x2, double y2) |
double cx2, double cy2, double x2, double y2) |
934 |
{ |
{ |
942 |
this.y2 = y2; |
this.y2 = y2; |
943 |
} |
} |
944 |
|
|
945 |
|
|
946 |
|
/** |
947 |
|
* Returns the <i>x</i> coordinate of the curve’s start |
948 |
|
* point. |
949 |
|
*/ |
950 |
public double getX1() |
public double getX1() |
951 |
{ |
{ |
952 |
return x1; |
return x1; |
953 |
} |
} |
954 |
|
|
955 |
|
|
956 |
|
/** |
957 |
|
* Returns the <i>y</i> coordinate of the curve’s start |
958 |
|
* point. |
959 |
|
*/ |
960 |
public double getY1() |
public double getY1() |
961 |
{ |
{ |
962 |
return y1; |
return y1; |
963 |
} |
} |
964 |
|
|
965 |
|
|
966 |
|
/** |
967 |
|
* Returns the curve’s start point. |
968 |
|
*/ |
969 |
public Point2D getP1() |
public Point2D getP1() |
970 |
{ |
{ |
971 |
return new Point2D.Double(x1, y1); |
return new Point2D.Double(x1, y1); |
972 |
} |
} |
973 |
|
|
974 |
|
|
975 |
|
/** |
976 |
|
* Returns the <i>x</i> coordinate of the curve’s first |
977 |
|
* control point. |
978 |
|
*/ |
979 |
public double getCtrlX1() |
public double getCtrlX1() |
980 |
{ |
{ |
981 |
return ctrlx1; |
return ctrlx1; |
982 |
} |
} |
983 |
|
|
984 |
|
|
985 |
|
/** |
986 |
|
* Returns the <i>y</i> coordinate of the curve’s first |
987 |
|
* control point. |
988 |
|
*/ |
989 |
public double getCtrlY1() |
public double getCtrlY1() |
990 |
{ |
{ |
991 |
return ctrly1; |
return ctrly1; |
992 |
} |
} |
993 |
|
|
994 |
|
|
995 |
|
/** |
996 |
|
* Returns the curve’s first control point. |
997 |
|
*/ |
998 |
public Point2D getCtrlP1() |
public Point2D getCtrlP1() |
999 |
{ |
{ |
1000 |
return new Point2D.Double(ctrlx1, ctrly1); |
return new Point2D.Double(ctrlx1, ctrly1); |
1001 |
} |
} |
1002 |
|
|
1003 |
|
|
1004 |
|
/** |
1005 |
|
* Returns the <i>x</i> coordinate of the curve’s second |
1006 |
|
* control point. |
1007 |
|
*/ |
1008 |
public double getCtrlX2() |
public double getCtrlX2() |
1009 |
{ |
{ |
1010 |
return ctrlx2; |
return ctrlx2; |
1011 |
} |
} |
1012 |
|
|
1013 |
|
|
1014 |
|
/** |
1015 |
|
* Returns the <i>y</i> coordinate of the curve’s second |
1016 |
|
* control point. |
1017 |
|
*/ |
1018 |
public double getCtrlY2() |
public double getCtrlY2() |
1019 |
{ |
{ |
1020 |
return ctrly2; |
return ctrly2; |
1021 |
} |
} |
1022 |
|
|
1023 |
|
|
1024 |
|
/** |
1025 |
|
* Returns the curve’s second control point. |
1026 |
|
*/ |
1027 |
public Point2D getCtrlP2() |
public Point2D getCtrlP2() |
1028 |
{ |
{ |
1029 |
return new Point2D.Double(ctrlx2, ctrly2); |
return new Point2D.Double(ctrlx2, ctrly2); |
1030 |
} |
} |
1031 |
|
|
1032 |
|
|
1033 |
|
/** |
1034 |
|
* Returns the <i>x</i> coordinate of the curve’s end |
1035 |
|
* point. |
1036 |
|
*/ |
1037 |
public double getX2() |
public double getX2() |
1038 |
{ |
{ |
1039 |
return x2; |
return x2; |
1040 |
} |
} |
1041 |
|
|
1042 |
|
|
1043 |
|
/** |
1044 |
|
* Returns the <i>y</i> coordinate of the curve’s end |
1045 |
|
* point. |
1046 |
|
*/ |
1047 |
public double getY2() |
public double getY2() |
1048 |
{ |
{ |
1049 |
return y2; |
return y2; |
1050 |
} |
} |
1051 |
|
|
1052 |
|
|
1053 |
|
/** |
1054 |
|
* Returns the curve’s end point. |
1055 |
|
*/ |
1056 |
public Point2D getP2() |
public Point2D getP2() |
1057 |
{ |
{ |
1058 |
return new Point2D.Double(x2, y2); |
return new Point2D.Double(x2, y2); |
1059 |
} |
} |
1060 |
|
|
1061 |
|
|
1062 |
|
/** |
1063 |
|
* Changes the curve geometry, separately specifying each coordinate |
1064 |
|
* value. |
1065 |
|
* |
1066 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
1067 |
|
* alt="A drawing of a CubicCurve2D" /> |
1068 |
|
* |
1069 |
|
* @param x1 the <i>x</i> coordinate of the curve’s new start |
1070 |
|
* point. |
1071 |
|
* |
1072 |
|
* @param y1 the <i>y</i> coordinate of the curve’s new start |
1073 |
|
* point. |
1074 |
|
* |
1075 |
|
* @param cx1 the <i>x</i> coordinate of the curve’s new |
1076 |
|
* first control point. |
1077 |
|
* |
1078 |
|
* @param cy1 the <i>y</i> coordinate of the curve’s new |
1079 |
|
* first control point. |
1080 |
|
* |
1081 |
|
* @param cx2 the <i>x</i> coordinate of the curve’s new |
1082 |
|
* second control point. |
1083 |
|
* |
1084 |
|
* @param cy2 the <i>y</i> coordinate of the curve’s new |
1085 |
|
* second control point. |
1086 |
|
* |
1087 |
|
* @param x2 the <i>x</i> coordinate of the curve’s new end |
1088 |
|
* point. |
1089 |
|
* |
1090 |
|
* @param y2 the <i>y</i> coordinate of the curve’s new end |
1091 |
|
* point. |
1092 |
|
*/ |
1093 |
public void setCurve(double x1, double y1, double cx1, double cy1, |
public void setCurve(double x1, double y1, double cx1, double cy1, |
1094 |
double cx2, double cy2, double x2, double y2) |
double cx2, double cy2, double x2, double y2) |
1095 |
{ |
{ |
1102 |
this.x2 = x2; |
this.x2 = x2; |
1103 |
this.y2 = y2; |
this.y2 = y2; |
1104 |
} |
} |
1105 |
|
|
1106 |
|
|
1107 |
|
/** |
1108 |
|
* Determines the smallest rectangle that encloses the |
1109 |
|
* curve’s start, end and control points. As the |
1110 |
|
* illustration below shows, the invisible control points may cause |
1111 |
|
* the bounds to be much larger than the area that is actually |
1112 |
|
* covered by the curve. |
1113 |
|
* |
1114 |
|
* <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180" |
1115 |
|
* alt="An illustration of the bounds of a CubicCurve2D" /> |
1116 |
|
*/ |
1117 |
public Rectangle2D getBounds2D() |
public Rectangle2D getBounds2D() |
1118 |
{ |
{ |
1119 |
double nx1 = Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); |
double nx1 = Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); |
1122 |
double ny2 = Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); |
double ny2 = Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); |
1123 |
return new Rectangle2D.Double(nx1, ny1, nx2 - nx1, ny2 - ny1); |
return new Rectangle2D.Double(nx1, ny1, nx2 - nx1, ny2 - ny1); |
1124 |
} |
} |
1125 |
} // class Double |
} |
1126 |
|
|
1127 |
|
|
1128 |
/** |
/** |
1129 |
* STUBS ONLY |
* A two-dimensional curve that is parameterized with a cubic |
1130 |
|
* function and stores coordinate values in single-precision |
1131 |
|
* floating-point format. |
1132 |
|
* |
1133 |
|
* @see CubicCurve2D.Float |
1134 |
|
* |
1135 |
|
* @author Eric Blake (ebb9@email.byu.edu) |
1136 |
|
* @author Sascha Brawer (brawer@dandelis.ch) |
1137 |
*/ |
*/ |
1138 |
public static class Float extends CubicCurve2D |
public static class Float |
1139 |
|
extends CubicCurve2D |
1140 |
{ |
{ |
1141 |
|
/** |
1142 |
|
* The <i>x</i> coordinate of the curve’s start point. |
1143 |
|
*/ |
1144 |
public float x1; |
public float x1; |
1145 |
|
|
1146 |
|
|
1147 |
|
/** |
1148 |
|
* The <i>y</i> coordinate of the curve’s start point. |
1149 |
|
*/ |
1150 |
public float y1; |
public float y1; |
1151 |
|
|
1152 |
|
|
1153 |
|
/** |
1154 |
|
* The <i>x</i> coordinate of the curve’s first control point. |
1155 |
|
*/ |
1156 |
public float ctrlx1; |
public float ctrlx1; |
1157 |
|
|
1158 |
|
|
1159 |
|
/** |
1160 |
|
* The <i>y</i> coordinate of the curve’s first control point. |
1161 |
|
*/ |
1162 |
public float ctrly1; |
public float ctrly1; |
1163 |
|
|
1164 |
|
|
1165 |
|
/** |
1166 |
|
* The <i>x</i> coordinate of the curve’s second control point. |
1167 |
|
*/ |
1168 |
public float ctrlx2; |
public float ctrlx2; |
1169 |
|
|
1170 |
|
|
1171 |
|
/** |
1172 |
|
* The <i>y</i> coordinate of the curve’s second control point. |
1173 |
|
*/ |
1174 |
public float ctrly2; |
public float ctrly2; |
1175 |
|
|
1176 |
|
|
1177 |
|
/** |
1178 |
|
* The <i>x</i> coordinate of the curve’s end point. |
1179 |
|
*/ |
1180 |
public float x2; |
public float x2; |
1181 |
|
|
1182 |
|
|
1183 |
|
/** |
1184 |
|
* The <i>y</i> coordinate of the curve’s end point. |
1185 |
|
*/ |
1186 |
public float y2; |
public float y2; |
1187 |
|
|
1188 |
|
|
1189 |
|
/** |
1190 |
|
* Constructs a new CubicCurve2D that stores its coordinate values |
1191 |
|
* in single-precision floating-point format. All points are |
1192 |
|
* initially at position (0, 0). |
1193 |
|
*/ |
1194 |
public Float() |
public Float() |
1195 |
{ |
{ |
1196 |
} |
} |
1197 |
|
|
1198 |
|
|
1199 |
|
/** |
1200 |
|
* Constructs a new CubicCurve2D that stores its coordinate values |
1201 |
|
* in single-precision floating-point format, specifying the |
1202 |
|
* initial position of each point. |
1203 |
|
* |
1204 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
1205 |
|
* alt="A drawing of a CubicCurve2D" /> |
1206 |
|
* |
1207 |
|
* @param x1 the <i>x</i> coordinate of the curve’s start |
1208 |
|
* point. |
1209 |
|
* |
1210 |
|
* @param y1 the <i>y</i> coordinate of the curve’s start |
1211 |
|
* point. |
1212 |
|
* |
1213 |
|
* @param cx1 the <i>x</i> coordinate of the curve’s first |
1214 |
|
* control point. |
1215 |
|
* |
1216 |
|
* @param cy1 the <i>y</i> coordinate of the curve’s first |
1217 |
|
* control point. |
1218 |
|
* |
1219 |
|
* @param cx2 the <i>x</i> coordinate of the curve’s second |
1220 |
|
* control point. |
1221 |
|
* |
1222 |
|
* @param cy2 the <i>y</i> coordinate of the curve’s second |
1223 |
|
* control point. |
1224 |
|
* |
1225 |
|
* @param x2 the <i>x</i> coordinate of the curve’s end |
1226 |
|
* point. |
1227 |
|
* |
1228 |
|
* @param y2 the <i>y</i> coordinate of the curve’s end |
1229 |
|
* point. |
1230 |
|
*/ |
1231 |
public Float(float x1, float y1, float cx1, float cy1, |
public Float(float x1, float y1, float cx1, float cy1, |
1232 |
float cx2, float cy2, float x2, float y2) |
float cx2, float cy2, float x2, float y2) |
1233 |
{ |
{ |
1241 |
this.y2 = y2; |
this.y2 = y2; |
1242 |
} |
} |
1243 |
|
|
1244 |
|
|
1245 |
|
/** |
1246 |
|
* Returns the <i>x</i> coordinate of the curve’s start |
1247 |
|
* point. |
1248 |
|
*/ |
1249 |
public double getX1() |
public double getX1() |
1250 |
{ |
{ |
1251 |
return x1; |
return x1; |
1252 |
} |
} |
1253 |
|
|
1254 |
|
|
1255 |
|
/** |
1256 |
|
* Returns the <i>y</i> coordinate of the curve’s start |
1257 |
|
* point. |
1258 |
|
*/ |
1259 |
public double getY1() |
public double getY1() |
1260 |
{ |
{ |
1261 |
return y1; |
return y1; |
1262 |
} |
} |
1263 |
|
|
1264 |
|
|
1265 |
|
/** |
1266 |
|
* Returns the curve’s start point. |
1267 |
|
*/ |
1268 |
public Point2D getP1() |
public Point2D getP1() |
1269 |
{ |
{ |
1270 |
return new Point2D.Float(x1, y1); |
return new Point2D.Float(x1, y1); |
1271 |
} |
} |
1272 |
|
|
1273 |
|
|
1274 |
|
/** |
1275 |
|
* Returns the <i>x</i> coordinate of the curve’s first |
1276 |
|
* control point. |
1277 |
|
*/ |
1278 |
public double getCtrlX1() |
public double getCtrlX1() |
1279 |
{ |
{ |
1280 |
return ctrlx1; |
return ctrlx1; |
1281 |
} |
} |
1282 |
|
|
1283 |
|
|
1284 |
|
/** |
1285 |
|
* Returns the <i>y</i> coordinate of the curve’s first |
1286 |
|
* control point. |
1287 |
|
*/ |
1288 |
public double getCtrlY1() |
public double getCtrlY1() |
1289 |
{ |
{ |
1290 |
return ctrly1; |
return ctrly1; |
1291 |
} |
} |
1292 |
|
|
1293 |
|
|
1294 |
|
/** |
1295 |
|
* Returns the curve’s first control point. |
1296 |
|
*/ |
1297 |
public Point2D getCtrlP1() |
public Point2D getCtrlP1() |
1298 |
{ |
{ |
1299 |
return new Point2D.Float(ctrlx1, ctrly1); |
return new Point2D.Float(ctrlx1, ctrly1); |
1300 |
} |
} |
1301 |
|
|
1302 |
|
|
1303 |
|
/** |
1304 |
|
* Returns the <i>s</i> coordinate of the curve’s second |
1305 |
|
* control point. |
1306 |
|
*/ |
1307 |
public double getCtrlX2() |
public double getCtrlX2() |
1308 |
{ |
{ |
1309 |
return ctrlx2; |
return ctrlx2; |
1310 |
} |
} |
1311 |
|
|
1312 |
|
|
1313 |
|
/** |
1314 |
|
* Returns the <i>y</i> coordinate of the curve’s second |
1315 |
|
* control point. |
1316 |
|
*/ |
1317 |
public double getCtrlY2() |
public double getCtrlY2() |
1318 |
{ |
{ |
1319 |
return ctrly2; |
return ctrly2; |
1320 |
} |
} |
1321 |
|
|
1322 |
|
|
1323 |
|
/** |
1324 |
|
* Returns the curve’s second control point. |
1325 |
|
*/ |
1326 |
public Point2D getCtrlP2() |
public Point2D getCtrlP2() |
1327 |
{ |
{ |
1328 |
return new Point2D.Float(ctrlx2, ctrly2); |
return new Point2D.Float(ctrlx2, ctrly2); |
1329 |
} |
} |
1330 |
|
|
1331 |
|
|
1332 |
|
/** |
1333 |
|
* Returns the <i>x</i> coordinate of the curve’s end |
1334 |
|
* point. |
1335 |
|
*/ |
1336 |
public double getX2() |
public double getX2() |
1337 |
{ |
{ |
1338 |
return x2; |
return x2; |
1339 |
} |
} |
1340 |
|
|
1341 |
|
|
1342 |
|
/** |
1343 |
|
* Returns the <i>y</i> coordinate of the curve’s end |
1344 |
|
* point. |
1345 |
|
*/ |
1346 |
public double getY2() |
public double getY2() |
1347 |
{ |
{ |
1348 |
return y2; |
return y2; |
1349 |
} |
} |
1350 |
|
|
1351 |
|
|
1352 |
|
/** |
1353 |
|
* Returns the curve’s end point. |
1354 |
|
*/ |
1355 |
public Point2D getP2() |
public Point2D getP2() |
1356 |
{ |
{ |
1357 |
return new Point2D.Float(x2, y2); |
return new Point2D.Float(x2, y2); |
1358 |
} |
} |
1359 |
|
|
1360 |
|
|
1361 |
|
/** |
1362 |
|
* Changes the curve geometry, separately specifying each coordinate |
1363 |
|
* value as a double-precision floating-point number. |
1364 |
|
* |
1365 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
1366 |
|
* alt="A drawing of a CubicCurve2D" /> |
1367 |
|
* |
1368 |
|
* @param x1 the <i>x</i> coordinate of the curve’s new start |
1369 |
|
* point. |
1370 |
|
* |
1371 |
|
* @param y1 the <i>y</i> coordinate of the curve’s new start |
1372 |
|
* point. |
1373 |
|
* |
1374 |
|
* @param cx1 the <i>x</i> coordinate of the curve’s new |
1375 |
|
* first control point. |
1376 |
|
* |
1377 |
|
* @param cy1 the <i>y</i> coordinate of the curve’s new |
1378 |
|
* first control point. |
1379 |
|
* |
1380 |
|
* @param cx2 the <i>x</i> coordinate of the curve’s new |
1381 |
|
* second control point. |
1382 |
|
* |
1383 |
|
* @param cy2 the <i>y</i> coordinate of the curve’s new |
1384 |
|
* second control point. |
1385 |
|
* |
1386 |
|
* @param x2 the <i>x</i> coordinate of the curve’s new end |
1387 |
|
* point. |
1388 |
|
* |
1389 |
|
* @param y2 the <i>y</i> coordinate of the curve’s new end |
1390 |
|
* point. |
1391 |
|
*/ |
1392 |
public void setCurve(double x1, double y1, double cx1, double cy1, |
public void setCurve(double x1, double y1, double cx1, double cy1, |
1393 |
double cx2, double cy2, double x2, double y2) |
double cx2, double cy2, double x2, double y2) |
1394 |
{ |
{ |
1401 |
this.x2 = (float) x2; |
this.x2 = (float) x2; |
1402 |
this.y2 = (float) y2; |
this.y2 = (float) y2; |
1403 |
} |
} |
1404 |
|
|
1405 |
|
|
1406 |
|
/** |
1407 |
|
* Changes the curve geometry, separately specifying each coordinate |
1408 |
|
* value as a single-precision floating-point number. |
1409 |
|
* |
1410 |
|
* <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" |
1411 |
|
* alt="A drawing of a CubicCurve2D" /> |
1412 |
|
* |
1413 |
|
* @param x1 the <i>x</i> coordinate of the curve’s new start |
1414 |
|
* point. |
1415 |
|
* |
1416 |
|
* @param y1 the <i>y</i> coordinate of the curve’s new start |
1417 |
|
* point. |
1418 |
|
* |
1419 |
|
* @param cx1 the <i>x</i> coordinate of the curve’s new |
1420 |
|
* first control point. |
1421 |
|
* |
1422 |
|
* @param cy1 the <i>y</i> coordinate of the curve’s new |
1423 |
|
* first control point. |
1424 |
|
* |
1425 |
|
* @param cx2 the <i>x</i> coordinate of the curve’s new |
1426 |
|
* second control point. |
1427 |
|
* |
1428 |
|
* @param cy2 the <i>y</i> coordinate of the curve’s new |
1429 |
|
* second control point. |
1430 |
|
* |
1431 |
|
* @param x2 the <i>x</i> coordinate of the curve’s new end |
1432 |
|
* point. |
1433 |
|
* |
1434 |
|
* @param y2 the <i>y</i> coordinate of the curve’s new end |
1435 |
|
* point. |
1436 |
|
*/ |
1437 |
public void setCurve(float x1, float y1, float cx1, float cy1, |
public void setCurve(float x1, float y1, float cx1, float cy1, |
1438 |
float cx2, float cy2, float x2, float y2) |
float cx2, float cy2, float x2, float y2) |
1439 |
{ |
{ |
1446 |
this.x2 = x2; |
this.x2 = x2; |
1447 |
this.y2 = y2; |
this.y2 = y2; |
1448 |
} |
} |
1449 |
|
|
1450 |
|
|
1451 |
|
/** |
1452 |
|
* Determines the smallest rectangle that encloses the |
1453 |
|
* curve’s start, end and control points. As the |
1454 |
|
* illustration below shows, the invisible control points may cause |
1455 |
|
* the bounds to be much larger than the area that is actually |
1456 |
|
* covered by the curve. |
1457 |
|
* |
1458 |
|
* <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180" |
1459 |
|
* alt="An illustration of the bounds of a CubicCurve2D" /> |
1460 |
|
*/ |
1461 |
public Rectangle2D getBounds2D() |
public Rectangle2D getBounds2D() |
1462 |
{ |
{ |
1463 |
float nx1 = (float) Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); |
float nx1 = (float) Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); |
1466 |
float ny2 = (float) Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); |
float ny2 = (float) Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); |
1467 |
return new Rectangle2D.Float(nx1, ny1, nx2 - nx1, ny2 - ny1); |
return new Rectangle2D.Float(nx1, ny1, nx2 - nx1, ny2 - ny1); |
1468 |
} |
} |
1469 |
} // class Float |
} |
1470 |
} // class CubicCurve2D |
} |