1 Clazz.declarePackage ("jssun.awt.geom");
\r
2 Clazz.load (["jssun.awt.geom.Curve"], "jssun.awt.geom.Order3", ["java.awt.geom.QuadCurve2D", "jssun.awt.geom.Order2"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
28 Clazz.instantialize (this, arguments);
\r
29 }, jssun.awt.geom, "Order3", jssun.awt.geom.Curve);
\r
30 c$.insert = Clazz.defineMethod (c$, "insert",
\r
31 function (curves, tmp, x0, y0, cx0, cy0, cx1, cy1, x1, y1, direction) {
\r
32 var numparams = jssun.awt.geom.Order3.getHorizontalParams (y0, cy0, cy1, y1, tmp);
\r
33 if (numparams == 0) {
\r
34 jssun.awt.geom.Order3.addInstance (curves, x0, y0, cx0, cy0, cx1, cy1, x1, y1, direction);
\r
45 if (numparams > 1 && t > tmp[1]) {
\r
49 }jssun.awt.geom.Order3.split (tmp, 3, t);
\r
50 if (numparams > 1) {
\r
51 t = (tmp[1] - t) / (1 - t);
\r
52 jssun.awt.geom.Order3.split (tmp, 9, t);
\r
54 if (direction == -1) {
\r
55 index += numparams * 6;
\r
56 }while (numparams >= 0) {
\r
57 jssun.awt.geom.Order3.addInstance (curves, tmp[index + 0], tmp[index + 1], tmp[index + 2], tmp[index + 3], tmp[index + 4], tmp[index + 5], tmp[index + 6], tmp[index + 7], direction);
\r
59 if (direction == 1) {
\r
64 }, "java.util.Vector,~A,~N,~N,~N,~N,~N,~N,~N,~N,~N");
\r
65 c$.addInstance = Clazz.defineMethod (c$, "addInstance",
\r
66 function (curves, x0, y0, cx0, cy0, cx1, cy1, x1, y1, direction) {
\r
68 curves.add ( new jssun.awt.geom.Order3 (x1, y1, cx1, cy1, cx0, cy0, x0, y0, -direction));
\r
69 } else if (y1 > y0) {
\r
70 curves.add ( new jssun.awt.geom.Order3 (x0, y0, cx0, cy0, cx1, cy1, x1, y1, direction));
\r
71 }}, "java.util.Vector,~N,~N,~N,~N,~N,~N,~N,~N,~N");
\r
72 c$.getHorizontalParams = Clazz.defineMethod (c$, "getHorizontalParams",
\r
73 function (c0, cp0, cp1, c1, ret) {
\r
74 if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
\r
80 ret[1] = (cp1 - cp0) * 2;
\r
81 ret[2] = (c1 - cp1 - cp1 + cp0);
\r
82 var numroots = java.awt.geom.QuadCurve2D.solveQuadratic (ret, ret);
\r
84 for (var i = 0; i < numroots; i++) {
\r
86 if (t > 0 && t < 1) {
\r
92 }, "~N,~N,~N,~N,~A");
\r
93 c$.split = Clazz.defineMethod (c$, "split",
\r
94 function (coords, pos, t) {
\r
103 coords[pos + 12] = x1 = coords[pos + 6];
\r
104 coords[pos + 13] = y1 = coords[pos + 7];
\r
105 cx1 = coords[pos + 4];
\r
106 cy1 = coords[pos + 5];
\r
107 x1 = cx1 + (x1 - cx1) * t;
\r
108 y1 = cy1 + (y1 - cy1) * t;
\r
109 x0 = coords[pos + 0];
\r
110 y0 = coords[pos + 1];
\r
111 cx0 = coords[pos + 2];
\r
112 cy0 = coords[pos + 3];
\r
113 x0 = x0 + (cx0 - x0) * t;
\r
114 y0 = y0 + (cy0 - y0) * t;
\r
115 cx0 = cx0 + (cx1 - cx0) * t;
\r
116 cy0 = cy0 + (cy1 - cy0) * t;
\r
117 cx1 = cx0 + (x1 - cx0) * t;
\r
118 cy1 = cy0 + (y1 - cy0) * t;
\r
119 cx0 = x0 + (cx0 - x0) * t;
\r
120 cy0 = y0 + (cy0 - y0) * t;
\r
121 coords[pos + 2] = x0;
\r
122 coords[pos + 3] = y0;
\r
123 coords[pos + 4] = cx0;
\r
124 coords[pos + 5] = cy0;
\r
125 coords[pos + 6] = cx0 + (cx1 - cx0) * t;
\r
126 coords[pos + 7] = cy0 + (cy1 - cy0) * t;
\r
127 coords[pos + 8] = cx1;
\r
128 coords[pos + 9] = cy1;
\r
129 coords[pos + 10] = x1;
\r
130 coords[pos + 11] = y1;
\r
132 Clazz.makeConstructor (c$,
\r
133 function (x0, y0, cx0, cy0, cx1, cy1, x1, y1, direction) {
\r
134 Clazz.superConstructor (this, jssun.awt.geom.Order3, [direction]);
\r
135 if (cy0 < y0) cy0 = y0;
\r
136 if (cy1 > y1) cy1 = y1;
\r
145 this.xmin = Math.min (Math.min (x0, x1), Math.min (cx0, cx1));
\r
146 this.xmax = Math.max (Math.max (x0, x1), Math.max (cx0, cx1));
\r
148 this.xcoeff1 = (cx0 - x0) * 3.0;
\r
149 this.xcoeff2 = (cx1 - cx0 - cx0 + x0) * 3.0;
\r
150 this.xcoeff3 = x1 - (cx1 - cx0) * 3.0 - x0;
\r
152 this.ycoeff1 = (cy0 - y0) * 3.0;
\r
153 this.ycoeff2 = (cy1 - cy0 - cy0 + y0) * 3.0;
\r
154 this.ycoeff3 = y1 - (cy1 - cy0) * 3.0 - y0;
\r
155 this.YforT1 = this.YforT2 = this.YforT3 = y0;
\r
156 }, "~N,~N,~N,~N,~N,~N,~N,~N,~N");
\r
157 Clazz.overrideMethod (c$, "getOrder",
\r
161 Clazz.overrideMethod (c$, "getXTop",
\r
165 Clazz.overrideMethod (c$, "getYTop",
\r
169 Clazz.overrideMethod (c$, "getXBot",
\r
173 Clazz.overrideMethod (c$, "getYBot",
\r
177 Clazz.overrideMethod (c$, "getXMin",
\r
181 Clazz.overrideMethod (c$, "getXMax",
\r
185 Clazz.overrideMethod (c$, "getX0",
\r
187 return (this.direction == 1) ? this.x0 : this.x1;
\r
189 Clazz.overrideMethod (c$, "getY0",
\r
191 return (this.direction == 1) ? this.y0 : this.y1;
\r
193 Clazz.defineMethod (c$, "getCX0",
\r
195 return (this.direction == 1) ? this.cx0 : this.cx1;
\r
197 Clazz.defineMethod (c$, "getCY0",
\r
199 return (this.direction == 1) ? this.cy0 : this.cy1;
\r
201 Clazz.defineMethod (c$, "getCX1",
\r
203 return (this.direction == -1) ? this.cx0 : this.cx1;
\r
205 Clazz.defineMethod (c$, "getCY1",
\r
207 return (this.direction == -1) ? this.cy0 : this.cy1;
\r
209 Clazz.overrideMethod (c$, "getX1",
\r
211 return (this.direction == -1) ? this.x0 : this.x1;
\r
213 Clazz.overrideMethod (c$, "getY1",
\r
215 return (this.direction == -1) ? this.y0 : this.y1;
\r
217 Clazz.overrideMethod (c$, "TforY",
\r
219 if (y <= this.y0) return 0;
\r
220 if (y >= this.y1) return 1;
\r
221 if (y == this.YforT1) return this.TforY1;
\r
222 if (y == this.YforT2) return this.TforY2;
\r
223 if (y == this.YforT3) return this.TforY3;
\r
224 if (this.ycoeff3 == 0.0) {
\r
225 return jssun.awt.geom.Order2.TforY (y, this.ycoeff0, this.ycoeff1, this.ycoeff2);
\r
226 }var a = this.ycoeff2 / this.ycoeff3;
\r
227 var b = this.ycoeff1 / this.ycoeff3;
\r
228 var c = (this.ycoeff0 - y) / this.ycoeff3;
\r
229 var Q = (a * a - 3.0 * b) / 9.0;
\r
230 var R = (2.0 * a * a * a - 9.0 * a * b + 27.0 * c) / 54.0;
\r
232 var Q3 = Q * Q * Q;
\r
236 var theta = Math.acos (R / Math.sqrt (Q3));
\r
237 Q = -2.0 * Math.sqrt (Q);
\r
238 t = this.refine (a, b, c, y, Q * Math.cos (theta / 3.0) - a_3);
\r
240 t = this.refine (a, b, c, y, Q * Math.cos ((theta + 6.283185307179586) / 3.0) - a_3);
\r
242 t = this.refine (a, b, c, y, Q * Math.cos ((theta - 6.283185307179586) / 3.0) - a_3);
\r
244 var neg = (R < 0.0);
\r
245 var S = Math.sqrt (R2 - Q3);
\r
248 }var A = Math.pow (R + S, 0.3333333333333333);
\r
251 }var B = (A == 0.0) ? 0.0 : (Q / A);
\r
252 t = this.refine (a, b, c, y, (A + B) - a_3);
\r
258 if (t == t0 || t == t1) {
\r
260 }var yt = this.YforT (t);
\r
263 } else if (yt > y) {
\r
269 this.TforY3 = this.TforY2;
\r
270 this.YforT3 = this.YforT2;
\r
271 this.TforY2 = this.TforY1;
\r
272 this.YforT2 = this.YforT1;
\r
277 Clazz.defineMethod (c$, "refine",
\r
278 function (a, b, c, target, t) {
\r
279 if (t < -0.1 || t > 1.1) {
\r
281 }var y = this.YforT (t);
\r
292 var useslope = true;
\r
293 while (y != target) {
\r
295 var t2 = (t0 + t1) / 2;
\r
296 if (t2 == t0 || t2 == t1) {
\r
300 var slope = this.dYforT (t, 1);
\r
304 }var t2 = t + ((target - y) / slope);
\r
305 if (t2 == t || t2 <= t0 || t2 >= t1) {
\r
309 }y = this.YforT (t);
\r
312 } else if (y > target) {
\r
317 var verbose = false;
\r
318 if (false && t >= 0 && t <= 1) {
\r
319 y = this.YforT (t);
\r
320 var tdiff = jssun.awt.geom.Curve.diffbits (t, origt);
\r
321 var ydiff = jssun.awt.geom.Curve.diffbits (y, origy);
\r
322 var yerr = jssun.awt.geom.Curve.diffbits (y, target);
\r
323 if (yerr > 0 || (verbose && tdiff > 0)) {
\r
324 System.out.println ("target was y = " + target);
\r
325 System.out.println ("original was y = " + origy + ", t = " + origt);
\r
326 System.out.println ("final was y = " + y + ", t = " + t);
\r
327 System.out.println ("t diff is " + tdiff);
\r
328 System.out.println ("y diff is " + ydiff);
\r
329 System.out.println ("y error is " + yerr);
\r
330 var tlow = jssun.awt.geom.Curve.prev (t);
\r
331 var ylow = this.YforT (tlow);
\r
332 var thi = jssun.awt.geom.Curve.next (t);
\r
333 var yhi = this.YforT (thi);
\r
334 if (Math.abs (target - ylow) < Math.abs (target - y) || Math.abs (target - yhi) < Math.abs (target - y)) {
\r
335 System.out.println ("adjacent y's = [" + ylow + ", " + yhi + "]");
\r
336 }}}return (t > 1) ? -1 : t;
\r
337 }, "~N,~N,~N,~N,~N");
\r
338 Clazz.overrideMethod (c$, "XforY",
\r
340 if (y <= this.y0) {
\r
342 }if (y >= this.y1) {
\r
344 }return this.XforT (this.TforY (y));
\r
346 Clazz.overrideMethod (c$, "XforT",
\r
348 return (((this.xcoeff3 * t) + this.xcoeff2) * t + this.xcoeff1) * t + this.xcoeff0;
\r
350 Clazz.overrideMethod (c$, "YforT",
\r
352 return (((this.ycoeff3 * t) + this.ycoeff2) * t + this.ycoeff1) * t + this.ycoeff0;
\r
354 Clazz.overrideMethod (c$, "dXforT",
\r
355 function (t, deriv) {
\r
358 return (((this.xcoeff3 * t) + this.xcoeff2) * t + this.xcoeff1) * t + this.xcoeff0;
\r
360 return ((3 * this.xcoeff3 * t) + 2 * this.xcoeff2) * t + this.xcoeff1;
\r
362 return (6 * this.xcoeff3 * t) + 2 * this.xcoeff2;
\r
364 return 6 * this.xcoeff3;
\r
369 Clazz.overrideMethod (c$, "dYforT",
\r
370 function (t, deriv) {
\r
373 return (((this.ycoeff3 * t) + this.ycoeff2) * t + this.ycoeff1) * t + this.ycoeff0;
\r
375 return ((3 * this.ycoeff3 * t) + 2 * this.ycoeff2) * t + this.ycoeff1;
\r
377 return (6 * this.ycoeff3 * t) + 2 * this.ycoeff2;
\r
379 return 6 * this.ycoeff3;
\r
384 Clazz.overrideMethod (c$, "nextVertical",
\r
385 function (t0, t1) {
\r
386 var eqn = Clazz.newDoubleArray (-1, [this.xcoeff1, 2 * this.xcoeff2, 3 * this.xcoeff3]);
\r
387 var numroots = java.awt.geom.QuadCurve2D.solveQuadratic (eqn, eqn);
\r
388 for (var i = 0; i < numroots; i++) {
\r
389 if (eqn[i] > t0 && eqn[i] < t1) {
\r
394 Clazz.overrideMethod (c$, "enlarge",
\r
396 r.add (this.x0, this.y0);
\r
397 var eqn = Clazz.newDoubleArray (-1, [this.xcoeff1, 2 * this.xcoeff2, 3 * this.xcoeff3]);
\r
398 var numroots = java.awt.geom.QuadCurve2D.solveQuadratic (eqn, eqn);
\r
399 for (var i = 0; i < numroots; i++) {
\r
401 if (t > 0 && t < 1) {
\r
402 r.add (this.XforT (t), this.YforT (t));
\r
404 r.add (this.x1, this.y1);
\r
405 }, "java.awt.geom.Rectangle2D");
\r
406 Clazz.defineMethod (c$, "getSubCurve",
\r
407 function (ystart, yend, dir) {
\r
408 if (ystart <= this.y0 && yend >= this.y1) {
\r
409 return this.getWithDirection (dir);
\r
410 }var eqn = Clazz.newDoubleArray (14, 0);
\r
413 t0 = this.TforY (ystart);
\r
414 t1 = this.TforY (yend);
\r
428 jssun.awt.geom.Order3.split (eqn, 0, t1);
\r
433 jssun.awt.geom.Order3.split (eqn, 0, t0 / t1);
\r
435 }return new jssun.awt.geom.Order3 (eqn[i + 0], ystart, eqn[i + 2], eqn[i + 3], eqn[i + 4], eqn[i + 5], eqn[i + 6], yend, dir);
\r
437 Clazz.overrideMethod (c$, "getReversedCurve",
\r
439 return new jssun.awt.geom.Order3 (this.x0, this.y0, this.cx0, this.cy0, this.cx1, this.cy1, this.x1, this.y1, -this.direction);
\r
441 Clazz.overrideMethod (c$, "getSegment",
\r
442 function (coords) {
\r
443 if (this.direction == 1) {
\r
444 coords[0] = this.cx0;
\r
445 coords[1] = this.cy0;
\r
446 coords[2] = this.cx1;
\r
447 coords[3] = this.cy1;
\r
448 coords[4] = this.x1;
\r
449 coords[5] = this.y1;
\r
451 coords[0] = this.cx1;
\r
452 coords[1] = this.cy1;
\r
453 coords[2] = this.cx0;
\r
454 coords[3] = this.cy0;
\r
455 coords[4] = this.x0;
\r
456 coords[5] = this.y0;
\r
459 Clazz.overrideMethod (c$, "controlPointString",
\r
461 return (("(" + jssun.awt.geom.Curve.round (this.getCX0 ()) + ", " + jssun.awt.geom.Curve.round (this.getCY0 ()) + "), ") + ("(" + jssun.awt.geom.Curve.round (this.getCX1 ()) + ", " + jssun.awt.geom.Curve.round (this.getCY1 ()) + "), "));
\r