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