2df839a6b40230a0bfd7578ac31bc2cf93d0dcd1
[jalviewjs.git] / site / swingjs / j2s / jssun / awt / geom / Curve.js
1 Clazz.declarePackage ("jssun.awt.geom");
2 Clazz.load (null, "jssun.awt.geom.Curve", ["java.lang.Double", "$.InternalError", "java.awt.geom.IllegalPathStateException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.direction = 0;
5 Clazz.instantialize (this, arguments);
6 }, jssun.awt.geom, "Curve");
7 c$.insertMove = Clazz.defineMethod (c$, "insertMove", 
8 function (curves, x, y) {
9 curves.add ( new jssun.awt.geom.Order0 (x, y));
10 }, "java.util.Vector,~N,~N");
11 c$.insertLine = Clazz.defineMethod (c$, "insertLine", 
12 function (curves, x0, y0, x1, y1) {
13 if (y0 < y1) {
14 curves.add ( new jssun.awt.geom.Order1 (x0, y0, x1, y1, 1));
15 } else if (y0 > y1) {
16 curves.add ( new jssun.awt.geom.Order1 (x1, y1, x0, y0, -1));
17 } else {
18 }}, "java.util.Vector,~N,~N,~N,~N");
19 c$.insertQuad = Clazz.defineMethod (c$, "insertQuad", 
20 function (curves, x0, y0, coords) {
21 var y1 = coords[3];
22 if (y0 > y1) {
23 jssun.awt.geom.Order2.insert (curves, coords, coords[2], y1, coords[0], coords[1], x0, y0, -1);
24 } else if (y0 == y1 && y0 == coords[1]) {
25 return;
26 } else {
27 jssun.awt.geom.Order2.insert (curves, coords, x0, y0, coords[0], coords[1], coords[2], y1, 1);
28 }}, "java.util.Vector,~N,~N,~A");
29 c$.insertCubic = Clazz.defineMethod (c$, "insertCubic", 
30 function (curves, x0, y0, coords) {
31 var y1 = coords[5];
32 if (y0 > y1) {
33 jssun.awt.geom.Order3.insert (curves, coords, coords[4], y1, coords[2], coords[3], coords[0], coords[1], x0, y0, -1);
34 } else if (y0 == y1 && y0 == coords[1] && y0 == coords[3]) {
35 return;
36 } else {
37 jssun.awt.geom.Order3.insert (curves, coords, x0, y0, coords[0], coords[1], coords[2], coords[3], coords[4], y1, 1);
38 }}, "java.util.Vector,~N,~N,~A");
39 c$.pointCrossingsForPath = Clazz.defineMethod (c$, "pointCrossingsForPath", 
40 function (pi, px, py) {
41 if (pi.isDone ()) {
42 return 0;
43 }var coords =  Clazz.newDoubleArray (6, 0);
44 if (pi.currentSegment (coords) != 0) {
45 throw  new java.awt.geom.IllegalPathStateException ("missing initial moveto in path definition");
46 }pi.next ();
47 var movx = coords[0];
48 var movy = coords[1];
49 var curx = movx;
50 var cury = movy;
51 var endx;
52 var endy;
53 var crossings = 0;
54 while (!pi.isDone ()) {
55 switch (pi.currentSegment (coords)) {
56 case 0:
57 if (cury != movy) {
58 crossings += jssun.awt.geom.Curve.pointCrossingsForLine (px, py, curx, cury, movx, movy);
59 }movx = curx = coords[0];
60 movy = cury = coords[1];
61 break;
62 case 1:
63 endx = coords[0];
64 endy = coords[1];
65 crossings += jssun.awt.geom.Curve.pointCrossingsForLine (px, py, curx, cury, endx, endy);
66 curx = endx;
67 cury = endy;
68 break;
69 case 2:
70 endx = coords[2];
71 endy = coords[3];
72 crossings += jssun.awt.geom.Curve.pointCrossingsForQuad (px, py, curx, cury, coords[0], coords[1], endx, endy, 0);
73 curx = endx;
74 cury = endy;
75 break;
76 case 3:
77 endx = coords[4];
78 endy = coords[5];
79 crossings += jssun.awt.geom.Curve.pointCrossingsForCubic (px, py, curx, cury, coords[0], coords[1], coords[2], coords[3], endx, endy, 0);
80 curx = endx;
81 cury = endy;
82 break;
83 case 4:
84 if (cury != movy) {
85 crossings += jssun.awt.geom.Curve.pointCrossingsForLine (px, py, curx, cury, movx, movy);
86 }curx = movx;
87 cury = movy;
88 break;
89 }
90 pi.next ();
91 }
92 if (cury != movy) {
93 crossings += jssun.awt.geom.Curve.pointCrossingsForLine (px, py, curx, cury, movx, movy);
94 }return crossings;
95 }, "java.awt.geom.PathIterator,~N,~N");
96 c$.pointCrossingsForLine = Clazz.defineMethod (c$, "pointCrossingsForLine", 
97 function (px, py, x0, y0, x1, y1) {
98 if (py < y0 && py < y1) return 0;
99 if (py >= y0 && py >= y1) return 0;
100 if (px >= x0 && px >= x1) return 0;
101 if (px < x0 && px < x1) return (y0 < y1) ? 1 : -1;
102 var xintercept = x0 + (py - y0) * (x1 - x0) / (y1 - y0);
103 if (px >= xintercept) return 0;
104 return (y0 < y1) ? 1 : -1;
105 }, "~N,~N,~N,~N,~N,~N");
106 c$.pointCrossingsForQuad = Clazz.defineMethod (c$, "pointCrossingsForQuad", 
107 function (px, py, x0, y0, xc, yc, x1, y1, level) {
108 if (py < y0 && py < yc && py < y1) return 0;
109 if (py >= y0 && py >= yc && py >= y1) return 0;
110 if (px >= x0 && px >= xc && px >= x1) return 0;
111 if (px < x0 && px < xc && px < x1) {
112 if (py >= y0) {
113 if (py < y1) return 1;
114 } else {
115 if (py >= y1) return -1;
116 }return 0;
117 }if (level > 52) return jssun.awt.geom.Curve.pointCrossingsForLine (px, py, x0, y0, x1, y1);
118 var x0c = (x0 + xc) / 2;
119 var y0c = (y0 + yc) / 2;
120 var xc1 = (xc + x1) / 2;
121 var yc1 = (yc + y1) / 2;
122 xc = (x0c + xc1) / 2;
123 yc = (y0c + yc1) / 2;
124 if (Double.isNaN (xc) || Double.isNaN (yc)) {
125 return 0;
126 }return (jssun.awt.geom.Curve.pointCrossingsForQuad (px, py, x0, y0, x0c, y0c, xc, yc, level + 1) + jssun.awt.geom.Curve.pointCrossingsForQuad (px, py, xc, yc, xc1, yc1, x1, y1, level + 1));
127 }, "~N,~N,~N,~N,~N,~N,~N,~N,~N");
128 c$.pointCrossingsForCubic = Clazz.defineMethod (c$, "pointCrossingsForCubic", 
129 function (px, py, x0, y0, xc0, yc0, xc1, yc1, x1, y1, level) {
130 if (py < y0 && py < yc0 && py < yc1 && py < y1) return 0;
131 if (py >= y0 && py >= yc0 && py >= yc1 && py >= y1) return 0;
132 if (px >= x0 && px >= xc0 && px >= xc1 && px >= x1) return 0;
133 if (px < x0 && px < xc0 && px < xc1 && px < x1) {
134 if (py >= y0) {
135 if (py < y1) return 1;
136 } else {
137 if (py >= y1) return -1;
138 }return 0;
139 }if (level > 52) return jssun.awt.geom.Curve.pointCrossingsForLine (px, py, x0, y0, x1, y1);
140 var xmid = (xc0 + xc1) / 2;
141 var ymid = (yc0 + yc1) / 2;
142 xc0 = (x0 + xc0) / 2;
143 yc0 = (y0 + yc0) / 2;
144 xc1 = (xc1 + x1) / 2;
145 yc1 = (yc1 + y1) / 2;
146 var xc0m = (xc0 + xmid) / 2;
147 var yc0m = (yc0 + ymid) / 2;
148 var xmc1 = (xmid + xc1) / 2;
149 var ymc1 = (ymid + yc1) / 2;
150 xmid = (xc0m + xmc1) / 2;
151 ymid = (yc0m + ymc1) / 2;
152 if (Double.isNaN (xmid) || Double.isNaN (ymid)) {
153 return 0;
154 }return (jssun.awt.geom.Curve.pointCrossingsForCubic (px, py, x0, y0, xc0, yc0, xc0m, yc0m, xmid, ymid, level + 1) + jssun.awt.geom.Curve.pointCrossingsForCubic (px, py, xmid, ymid, xmc1, ymc1, xc1, yc1, x1, y1, level + 1));
155 }, "~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N");
156 c$.rectCrossingsForPath = Clazz.defineMethod (c$, "rectCrossingsForPath", 
157 function (pi, rxmin, rymin, rxmax, rymax) {
158 if (rxmax <= rxmin || rymax <= rymin) {
159 return 0;
160 }if (pi.isDone ()) {
161 return 0;
162 }var coords =  Clazz.newDoubleArray (6, 0);
163 if (pi.currentSegment (coords) != 0) {
164 throw  new java.awt.geom.IllegalPathStateException ("missing initial moveto in path definition");
165 }pi.next ();
166 var curx;
167 var cury;
168 var movx;
169 var movy;
170 var endx;
171 var endy;
172 curx = movx = coords[0];
173 cury = movy = coords[1];
174 var crossings = 0;
175 while (crossings != -2147483648 && !pi.isDone ()) {
176 switch (pi.currentSegment (coords)) {
177 case 0:
178 if (curx != movx || cury != movy) {
179 crossings = jssun.awt.geom.Curve.rectCrossingsForLine (crossings, rxmin, rymin, rxmax, rymax, curx, cury, movx, movy);
180 }movx = curx = coords[0];
181 movy = cury = coords[1];
182 break;
183 case 1:
184 endx = coords[0];
185 endy = coords[1];
186 crossings = jssun.awt.geom.Curve.rectCrossingsForLine (crossings, rxmin, rymin, rxmax, rymax, curx, cury, endx, endy);
187 curx = endx;
188 cury = endy;
189 break;
190 case 2:
191 endx = coords[2];
192 endy = coords[3];
193 crossings = jssun.awt.geom.Curve.rectCrossingsForQuad (crossings, rxmin, rymin, rxmax, rymax, curx, cury, coords[0], coords[1], endx, endy, 0);
194 curx = endx;
195 cury = endy;
196 break;
197 case 3:
198 endx = coords[4];
199 endy = coords[5];
200 crossings = jssun.awt.geom.Curve.rectCrossingsForCubic (crossings, rxmin, rymin, rxmax, rymax, curx, cury, coords[0], coords[1], coords[2], coords[3], endx, endy, 0);
201 curx = endx;
202 cury = endy;
203 break;
204 case 4:
205 if (curx != movx || cury != movy) {
206 crossings = jssun.awt.geom.Curve.rectCrossingsForLine (crossings, rxmin, rymin, rxmax, rymax, curx, cury, movx, movy);
207 }curx = movx;
208 cury = movy;
209 break;
210 }
211 pi.next ();
212 }
213 if (crossings != -2147483648 && (curx != movx || cury != movy)) {
214 crossings = jssun.awt.geom.Curve.rectCrossingsForLine (crossings, rxmin, rymin, rxmax, rymax, curx, cury, movx, movy);
215 }return crossings;
216 }, "java.awt.geom.PathIterator,~N,~N,~N,~N");
217 c$.rectCrossingsForLine = Clazz.defineMethod (c$, "rectCrossingsForLine", 
218 function (crossings, rxmin, rymin, rxmax, rymax, x0, y0, x1, y1) {
219 if (y0 >= rymax && y1 >= rymax) return crossings;
220 if (y0 <= rymin && y1 <= rymin) return crossings;
221 if (x0 <= rxmin && x1 <= rxmin) return crossings;
222 if (x0 >= rxmax && x1 >= rxmax) {
223 if (y0 < y1) {
224 if (y0 <= rymin) crossings++;
225 if (y1 >= rymax) crossings++;
226 } else if (y1 < y0) {
227 if (y1 <= rymin) crossings--;
228 if (y0 >= rymax) crossings--;
229 }return crossings;
230 }if ((x0 > rxmin && x0 < rxmax && y0 > rymin && y0 < rymax) || (x1 > rxmin && x1 < rxmax && y1 > rymin && y1 < rymax)) {
231 return -2147483648;
232 }var xi0 = x0;
233 if (y0 < rymin) {
234 xi0 += ((rymin - y0) * (x1 - x0) / (y1 - y0));
235 } else if (y0 > rymax) {
236 xi0 += ((rymax - y0) * (x1 - x0) / (y1 - y0));
237 }var xi1 = x1;
238 if (y1 < rymin) {
239 xi1 += ((rymin - y1) * (x0 - x1) / (y0 - y1));
240 } else if (y1 > rymax) {
241 xi1 += ((rymax - y1) * (x0 - x1) / (y0 - y1));
242 }if (xi0 <= rxmin && xi1 <= rxmin) return crossings;
243 if (xi0 >= rxmax && xi1 >= rxmax) {
244 if (y0 < y1) {
245 if (y0 <= rymin) crossings++;
246 if (y1 >= rymax) crossings++;
247 } else if (y1 < y0) {
248 if (y1 <= rymin) crossings--;
249 if (y0 >= rymax) crossings--;
250 }return crossings;
251 }return -2147483648;
252 }, "~N,~N,~N,~N,~N,~N,~N,~N,~N");
253 c$.rectCrossingsForQuad = Clazz.defineMethod (c$, "rectCrossingsForQuad", 
254 function (crossings, rxmin, rymin, rxmax, rymax, x0, y0, xc, yc, x1, y1, level) {
255 if (y0 >= rymax && yc >= rymax && y1 >= rymax) return crossings;
256 if (y0 <= rymin && yc <= rymin && y1 <= rymin) return crossings;
257 if (x0 <= rxmin && xc <= rxmin && x1 <= rxmin) return crossings;
258 if (x0 >= rxmax && xc >= rxmax && x1 >= rxmax) {
259 if (y0 < y1) {
260 if (y0 <= rymin && y1 > rymin) crossings++;
261 if (y0 < rymax && y1 >= rymax) crossings++;
262 } else if (y1 < y0) {
263 if (y1 <= rymin && y0 > rymin) crossings--;
264 if (y1 < rymax && y0 >= rymax) crossings--;
265 }return crossings;
266 }if ((x0 < rxmax && x0 > rxmin && y0 < rymax && y0 > rymin) || (x1 < rxmax && x1 > rxmin && y1 < rymax && y1 > rymin)) {
267 return -2147483648;
268 }if (level > 52) {
269 return jssun.awt.geom.Curve.rectCrossingsForLine (crossings, rxmin, rymin, rxmax, rymax, x0, y0, x1, y1);
270 }var x0c = (x0 + xc) / 2;
271 var y0c = (y0 + yc) / 2;
272 var xc1 = (xc + x1) / 2;
273 var yc1 = (yc + y1) / 2;
274 xc = (x0c + xc1) / 2;
275 yc = (y0c + yc1) / 2;
276 if (Double.isNaN (xc) || Double.isNaN (yc)) {
277 return 0;
278 }crossings = jssun.awt.geom.Curve.rectCrossingsForQuad (crossings, rxmin, rymin, rxmax, rymax, x0, y0, x0c, y0c, xc, yc, level + 1);
279 if (crossings != -2147483648) {
280 crossings = jssun.awt.geom.Curve.rectCrossingsForQuad (crossings, rxmin, rymin, rxmax, rymax, xc, yc, xc1, yc1, x1, y1, level + 1);
281 }return crossings;
282 }, "~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N");
283 c$.rectCrossingsForCubic = Clazz.defineMethod (c$, "rectCrossingsForCubic", 
284 function (crossings, rxmin, rymin, rxmax, rymax, x0, y0, xc0, yc0, xc1, yc1, x1, y1, level) {
285 if (y0 >= rymax && yc0 >= rymax && yc1 >= rymax && y1 >= rymax) {
286 return crossings;
287 }if (y0 <= rymin && yc0 <= rymin && yc1 <= rymin && y1 <= rymin) {
288 return crossings;
289 }if (x0 <= rxmin && xc0 <= rxmin && xc1 <= rxmin && x1 <= rxmin) {
290 return crossings;
291 }if (x0 >= rxmax && xc0 >= rxmax && xc1 >= rxmax && x1 >= rxmax) {
292 if (y0 < y1) {
293 if (y0 <= rymin && y1 > rymin) crossings++;
294 if (y0 < rymax && y1 >= rymax) crossings++;
295 } else if (y1 < y0) {
296 if (y1 <= rymin && y0 > rymin) crossings--;
297 if (y1 < rymax && y0 >= rymax) crossings--;
298 }return crossings;
299 }if ((x0 > rxmin && x0 < rxmax && y0 > rymin && y0 < rymax) || (x1 > rxmin && x1 < rxmax && y1 > rymin && y1 < rymax)) {
300 return -2147483648;
301 }if (level > 52) {
302 return jssun.awt.geom.Curve.rectCrossingsForLine (crossings, rxmin, rymin, rxmax, rymax, x0, y0, x1, y1);
303 }var xmid = (xc0 + xc1) / 2;
304 var ymid = (yc0 + yc1) / 2;
305 xc0 = (x0 + xc0) / 2;
306 yc0 = (y0 + yc0) / 2;
307 xc1 = (xc1 + x1) / 2;
308 yc1 = (yc1 + y1) / 2;
309 var xc0m = (xc0 + xmid) / 2;
310 var yc0m = (yc0 + ymid) / 2;
311 var xmc1 = (xmid + xc1) / 2;
312 var ymc1 = (ymid + yc1) / 2;
313 xmid = (xc0m + xmc1) / 2;
314 ymid = (yc0m + ymc1) / 2;
315 if (Double.isNaN (xmid) || Double.isNaN (ymid)) {
316 return 0;
317 }crossings = jssun.awt.geom.Curve.rectCrossingsForCubic (crossings, rxmin, rymin, rxmax, rymax, x0, y0, xc0, yc0, xc0m, yc0m, xmid, ymid, level + 1);
318 if (crossings != -2147483648) {
319 crossings = jssun.awt.geom.Curve.rectCrossingsForCubic (crossings, rxmin, rymin, rxmax, rymax, xmid, ymid, xmc1, ymc1, xc1, yc1, x1, y1, level + 1);
320 }return crossings;
321 }, "~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N");
322 Clazz.makeConstructor (c$, 
323 function (direction) {
324 this.direction = direction;
325 }, "~N");
326 Clazz.defineMethod (c$, "getDirection", 
327 function () {
328 return this.direction;
329 });
330 Clazz.defineMethod (c$, "getWithDirection", 
331 function (direction) {
332 return (this.direction == direction ? this : this.getReversedCurve ());
333 }, "~N");
334 c$.round = Clazz.defineMethod (c$, "round", 
335 function (v) {
336 return v;
337 }, "~N");
338 c$.orderof = Clazz.defineMethod (c$, "orderof", 
339 function (x1, x2) {
340 if (x1 < x2) {
341 return -1;
342 }if (x1 > x2) {
343 return 1;
344 }return 0;
345 }, "~N,~N");
346 c$.signeddiffbits = Clazz.defineMethod (c$, "signeddiffbits", 
347 function (y1, y2) {
348 return (Double.doubleToLongBits (y1) - Double.doubleToLongBits (y2));
349 }, "~N,~N");
350 c$.diffbits = Clazz.defineMethod (c$, "diffbits", 
351 function (y1, y2) {
352 return Math.abs (Double.doubleToLongBits (y1) - Double.doubleToLongBits (y2));
353 }, "~N,~N");
354 c$.prev = Clazz.defineMethod (c$, "prev", 
355 function (v) {
356 return Double.longBitsToDouble (Double.doubleToLongBits (v) - 1);
357 }, "~N");
358 c$.next = Clazz.defineMethod (c$, "next", 
359 function (v) {
360 return Double.longBitsToDouble (Double.doubleToLongBits (v) + 1);
361 }, "~N");
362 Clazz.overrideMethod (c$, "toString", 
363 function () {
364 return ("Curve[" + this.getOrder () + ", " + ("(" + jssun.awt.geom.Curve.round (this.getX0 ()) + ", " + jssun.awt.geom.Curve.round (this.getY0 ()) + "), ") + this.controlPointString () + ("(" + jssun.awt.geom.Curve.round (this.getX1 ()) + ", " + jssun.awt.geom.Curve.round (this.getY1 ()) + "), ") + (this.direction == 1 ? "D" : "U") + "]");
365 });
366 Clazz.defineMethod (c$, "controlPointString", 
367 function () {
368 return "";
369 });
370 Clazz.defineMethod (c$, "crossingsFor", 
371 function (x, y) {
372 if (y >= this.getYTop () && y < this.getYBot ()) {
373 if (x < this.getXMax () && (x < this.getXMin () || x < this.XforY (y))) {
374 return 1;
375 }}return 0;
376 }, "~N,~N");
377 Clazz.defineMethod (c$, "accumulateCrossings", 
378 function (c) {
379 var xhi = c.getXHi ();
380 if (this.getXMin () >= xhi) {
381 return false;
382 }var xlo = c.getXLo ();
383 var ylo = c.getYLo ();
384 var yhi = c.getYHi ();
385 var y0 = this.getYTop ();
386 var y1 = this.getYBot ();
387 var tstart;
388 var ystart;
389 var tend;
390 var yend;
391 if (y0 < ylo) {
392 if (y1 <= ylo) {
393 return false;
394 }ystart = ylo;
395 tstart = this.TforY (ylo);
396 } else {
397 if (y0 >= yhi) {
398 return false;
399 }ystart = y0;
400 tstart = 0;
401 }if (y1 > yhi) {
402 yend = yhi;
403 tend = this.TforY (yhi);
404 } else {
405 yend = y1;
406 tend = 1;
407 }var hitLo = false;
408 var hitHi = false;
409 while (true) {
410 var x = this.XforT (tstart);
411 if (x < xhi) {
412 if (hitHi || x > xlo) {
413 return true;
414 }hitLo = true;
415 } else {
416 if (hitLo) {
417 return true;
418 }hitHi = true;
419 }if (tstart >= tend) {
420 break;
421 }tstart = this.nextVertical (tstart, tend);
422 }
423 if (hitLo) {
424 c.record (ystart, yend, this.direction);
425 }return false;
426 }, "jssun.awt.geom.Crossings");
427 Clazz.defineMethod (c$, "getSubCurve", 
428 function (ystart, yend) {
429 return this.getSubCurve (ystart, yend, this.direction);
430 }, "~N,~N");
431 Clazz.defineMethod (c$, "compareTo", 
432 function (that, yrange) {
433 var y0 = yrange[0];
434 var y1 = yrange[1];
435 y1 = Math.min (Math.min (y1, this.getYBot ()), that.getYBot ());
436 if (y1 <= yrange[0]) {
437 System.err.println ("this == " + this);
438 System.err.println ("that == " + that);
439 System.out.println ("target range = " + yrange[0] + "=>" + yrange[1]);
440 throw  new InternalError ("backstepping from " + yrange[0] + " to " + y1);
441 }yrange[1] = y1;
442 if (this.getXMax () <= that.getXMin ()) {
443 if (this.getXMin () == that.getXMax ()) {
444 return 0;
445 }return -1;
446 }if (this.getXMin () >= that.getXMax ()) {
447 return 1;
448 }var s0 = this.TforY (y0);
449 var ys0 = this.YforT (s0);
450 if (ys0 < y0) {
451 s0 = this.refineTforY (s0, ys0, y0);
452 ys0 = this.YforT (s0);
453 }var s1 = this.TforY (y1);
454 if (this.YforT (s1) < y0) {
455 s1 = this.refineTforY (s1, this.YforT (s1), y0);
456 }var t0 = that.TforY (y0);
457 var yt0 = that.YforT (t0);
458 if (yt0 < y0) {
459 t0 = that.refineTforY (t0, yt0, y0);
460 yt0 = that.YforT (t0);
461 }var t1 = that.TforY (y1);
462 if (that.YforT (t1) < y0) {
463 t1 = that.refineTforY (t1, that.YforT (t1), y0);
464 }var xs0 = this.XforT (s0);
465 var xt0 = that.XforT (t0);
466 var scale = Math.max (Math.abs (y0), Math.abs (y1));
467 var ymin = Math.max (scale * 1E-14, 1E-300);
468 if (this.fairlyClose (xs0, xt0)) {
469 var bump = ymin;
470 var maxbump = Math.min (ymin * 1E13, (y1 - y0) * .1);
471 var y = y0 + bump;
472 while (y <= y1) {
473 if (this.fairlyClose (this.XforY (y), that.XforY (y))) {
474 if ((bump *= 2) > maxbump) {
475 bump = maxbump;
476 }} else {
477 y -= bump;
478 while (true) {
479 bump /= 2;
480 var newy = y + bump;
481 if (newy <= y) {
482 break;
483 }if (this.fairlyClose (this.XforY (newy), that.XforY (newy))) {
484 y = newy;
485 }}
486 break;
487 }y += bump;
488 }
489 if (y > y0) {
490 if (y < y1) {
491 yrange[1] = y;
492 }return 0;
493 }}if (ymin <= 0) {
494 System.out.println ("ymin = " + ymin);
495 }while (s0 < s1 && t0 < t1) {
496 var sh = this.nextVertical (s0, s1);
497 var xsh = this.XforT (sh);
498 var ysh = this.YforT (sh);
499 var th = that.nextVertical (t0, t1);
500 var xth = that.XforT (th);
501 var yth = that.YforT (th);
502 try {
503 if (this.findIntersect (that, yrange, ymin, 0, 0, s0, xs0, ys0, sh, xsh, ysh, t0, xt0, yt0, th, xth, yth)) {
504 break;
505 }} catch (t) {
506 System.err.println ("Error: " + t);
507 System.err.println ("y range was " + yrange[0] + "=>" + yrange[1]);
508 System.err.println ("s y range is " + ys0 + "=>" + ysh);
509 System.err.println ("t y range is " + yt0 + "=>" + yth);
510 System.err.println ("ymin is " + ymin);
511 return 0;
512 }
513 if (ysh < yth) {
514 if (ysh > yrange[0]) {
515 if (ysh < yrange[1]) {
516 yrange[1] = ysh;
517 }break;
518 }s0 = sh;
519 xs0 = xsh;
520 ys0 = ysh;
521 } else {
522 if (yth > yrange[0]) {
523 if (yth < yrange[1]) {
524 yrange[1] = yth;
525 }break;
526 }t0 = th;
527 xt0 = xth;
528 yt0 = yth;
529 }}
530 var ymid = (yrange[0] + yrange[1]) / 2;
531 return jssun.awt.geom.Curve.orderof (this.XforY (ymid), that.XforY (ymid));
532 }, "jssun.awt.geom.Curve,~A");
533 Clazz.defineMethod (c$, "findIntersect", 
534 function (that, yrange, ymin, slevel, tlevel, s0, xs0, ys0, s1, xs1, ys1, t0, xt0, yt0, t1, xt1, yt1) {
535 if (ys0 > yt1 || yt0 > ys1) {
536 return false;
537 }if (Math.min (xs0, xs1) > Math.max (xt0, xt1) || Math.max (xs0, xs1) < Math.min (xt0, xt1)) {
538 return false;
539 }if (s1 - s0 > 0.001) {
540 var s = (s0 + s1) / 2;
541 var xs = this.XforT (s);
542 var ys = this.YforT (s);
543 if (s == s0 || s == s1) {
544 System.out.println ("s0 = " + s0);
545 System.out.println ("s1 = " + s1);
546 throw  new InternalError ("no s progress!");
547 }if (t1 - t0 > 0.001) {
548 var t = (t0 + t1) / 2;
549 var xt = that.XforT (t);
550 var yt = that.YforT (t);
551 if (t == t0 || t == t1) {
552 System.out.println ("t0 = " + t0);
553 System.out.println ("t1 = " + t1);
554 throw  new InternalError ("no t progress!");
555 }if (ys >= yt0 && yt >= ys0) {
556 if (this.findIntersect (that, yrange, ymin, slevel + 1, tlevel + 1, s0, xs0, ys0, s, xs, ys, t0, xt0, yt0, t, xt, yt)) {
557 return true;
558 }}if (ys >= yt) {
559 if (this.findIntersect (that, yrange, ymin, slevel + 1, tlevel + 1, s0, xs0, ys0, s, xs, ys, t, xt, yt, t1, xt1, yt1)) {
560 return true;
561 }}if (yt >= ys) {
562 if (this.findIntersect (that, yrange, ymin, slevel + 1, tlevel + 1, s, xs, ys, s1, xs1, ys1, t0, xt0, yt0, t, xt, yt)) {
563 return true;
564 }}if (ys1 >= yt && yt1 >= ys) {
565 if (this.findIntersect (that, yrange, ymin, slevel + 1, tlevel + 1, s, xs, ys, s1, xs1, ys1, t, xt, yt, t1, xt1, yt1)) {
566 return true;
567 }}} else {
568 if (ys >= yt0) {
569 if (this.findIntersect (that, yrange, ymin, slevel + 1, tlevel, s0, xs0, ys0, s, xs, ys, t0, xt0, yt0, t1, xt1, yt1)) {
570 return true;
571 }}if (yt1 >= ys) {
572 if (this.findIntersect (that, yrange, ymin, slevel + 1, tlevel, s, xs, ys, s1, xs1, ys1, t0, xt0, yt0, t1, xt1, yt1)) {
573 return true;
574 }}}} else if (t1 - t0 > 0.001) {
575 var t = (t0 + t1) / 2;
576 var xt = that.XforT (t);
577 var yt = that.YforT (t);
578 if (t == t0 || t == t1) {
579 System.out.println ("t0 = " + t0);
580 System.out.println ("t1 = " + t1);
581 throw  new InternalError ("no t progress!");
582 }if (yt >= ys0) {
583 if (this.findIntersect (that, yrange, ymin, slevel, tlevel + 1, s0, xs0, ys0, s1, xs1, ys1, t0, xt0, yt0, t, xt, yt)) {
584 return true;
585 }}if (ys1 >= yt) {
586 if (this.findIntersect (that, yrange, ymin, slevel, tlevel + 1, s0, xs0, ys0, s1, xs1, ys1, t, xt, yt, t1, xt1, yt1)) {
587 return true;
588 }}} else {
589 var xlk = xs1 - xs0;
590 var ylk = ys1 - ys0;
591 var xnm = xt1 - xt0;
592 var ynm = yt1 - yt0;
593 var xmk = xt0 - xs0;
594 var ymk = yt0 - ys0;
595 var det = xnm * ylk - ynm * xlk;
596 if (det != 0) {
597 var detinv = 1 / det;
598 var s = (xnm * ymk - ynm * xmk) * detinv;
599 var t = (xlk * ymk - ylk * xmk) * detinv;
600 if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
601 s = s0 + s * (s1 - s0);
602 t = t0 + t * (t1 - t0);
603 if (s < 0 || s > 1 || t < 0 || t > 1) {
604 System.out.println ("Uh oh!");
605 }var y = (this.YforT (s) + that.YforT (t)) / 2;
606 if (y <= yrange[1] && y > yrange[0]) {
607 yrange[1] = y;
608 return true;
609 }}}}return false;
610 }, "jssun.awt.geom.Curve,~A,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N,~N");
611 Clazz.defineMethod (c$, "refineTforY", 
612 function (t0, yt0, y0) {
613 var t1 = 1;
614 while (true) {
615 var th = (t0 + t1) / 2;
616 if (th == t0 || th == t1) {
617 return t1;
618 }var y = this.YforT (th);
619 if (y < y0) {
620 t0 = th;
621 yt0 = y;
622 } else if (y > y0) {
623 t1 = th;
624 } else {
625 return t1;
626 }}
627 }, "~N,~N,~N");
628 Clazz.defineMethod (c$, "fairlyClose", 
629 function (v1, v2) {
630 return (Math.abs (v1 - v2) < Math.max (Math.abs (v1), Math.abs (v2)) * 1E-10);
631 }, "~N,~N");
632 Clazz.defineStatics (c$,
633 "INCREASING", 1,
634 "DECREASING", -1,
635 "RECT_INTERSECTS", 0x80000000,
636 "TMIN", 1E-3);
637 });