264 }
265 yrange[1] = y1;
266 if (this.getXMax() <= that.getXMin()) {
267 if (this.getXMin() == that.getXMax()) {
268 return 0;
269 }
270 return -1;
271 }
272 if (this.getXMin() >= that.getXMax()) {
273 return 1;
274 }
275 // Parameter s for thi(s) curve and t for tha(t) curve
276 // [st]0 = parameters for top of current section of interest
277 // [st]1 = parameters for bottom of valid range
278 // [st]h = parameters for hypothesis point
279 // [d][xy]s = valuations of thi(s) curve at sh
280 // [d][xy]t = valuations of tha(t) curve at th
281 double s0 = this.TforY(y0);
282 double ys0 = this.YforT(s0);
283 if (ys0 < y0) {
284 s0 = refineTforY(s0, ys0, y0);
285 ys0 = this.YforT(s0);
286 }
287 double s1 = this.TforY(y1);
288 if (this.YforT(s1) < y0) {
289 s1 = refineTforY(s1, this.YforT(s1), y0);
290 //System.out.println("s1 problem!");
291 }
292 double t0 = that.TforY(y0);
293 double yt0 = that.YforT(t0);
294 if (yt0 < y0) {
295 t0 = that.refineTforY(t0, yt0, y0);
296 yt0 = that.YforT(t0);
297 }
298 double t1 = that.TforY(y1);
299 if (that.YforT(t1) < y0) {
300 t1 = that.refineTforY(t1, that.YforT(t1), y0);
301 //System.out.println("t1 problem!");
302 }
303 double xs0 = this.XforT(s0);
304 double xt0 = that.XforT(t0);
305 double scale = Math.max(Math.abs(y0), Math.abs(y1));
306 double ymin = Math.max(scale * 1E-14, 1E-300);
307 if (fairlyClose(xs0, xt0)) {
308 double bump = ymin;
309 double maxbump = Math.min(ymin * 1E13, (y1 - y0) * .1);
310 double y = y0 + bump;
311 while (y <= y1) {
312 if (fairlyClose(this.XforY(y), that.XforY(y))) {
313 if ((bump *= 2) > maxbump) {
314 bump = maxbump;
315 }
316 } else {
317 y -= bump;
318 while (true) {
319 bump /= 2;
320 double newy = y + bump;
543 double s = (xnm * ymk - ynm * xmk) * detinv;
544 double t = (xlk * ymk - ylk * xmk) * detinv;
545 if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
546 s = s0 + s * (s1 - s0);
547 t = t0 + t * (t1 - t0);
548 if (s < 0 || s > 1 || t < 0 || t > 1) {
549 System.out.println("Uh oh!");
550 }
551 double y = (this.YforT(s) + that.YforT(t)) / 2;
552 if (y <= yrange[1] && y > yrange[0]) {
553 yrange[1] = y;
554 return true;
555 }
556 }
557 }
558 //System.out.println("Testing lines!");
559 }
560 return false;
561 }
562
563 public double refineTforY(double t0, double yt0, double y0) {
564 double t1 = 1;
565 while (true) {
566 double th = (t0 + t1) / 2;
567 if (th == t0 || th == t1) {
568 return t1;
569 }
570 double y = YforT(th);
571 if (y < y0) {
572 t0 = th;
573 yt0 = y;
574 } else if (y > y0) {
575 t1 = th;
576 } else {
577 return t1;
578 }
579 }
580 }
581
582 public boolean fairlyClose(double v1, double v2) {
583 return (Math.abs(v1 - v2) <
584 Math.max(Math.abs(v1), Math.abs(v2)) * 1E-10);
585 }
586
587 public abstract int getSegment(float coords[]);
588 }
|
264 }
265 yrange[1] = y1;
266 if (this.getXMax() <= that.getXMin()) {
267 if (this.getXMin() == that.getXMax()) {
268 return 0;
269 }
270 return -1;
271 }
272 if (this.getXMin() >= that.getXMax()) {
273 return 1;
274 }
275 // Parameter s for thi(s) curve and t for tha(t) curve
276 // [st]0 = parameters for top of current section of interest
277 // [st]1 = parameters for bottom of valid range
278 // [st]h = parameters for hypothesis point
279 // [d][xy]s = valuations of thi(s) curve at sh
280 // [d][xy]t = valuations of tha(t) curve at th
281 double s0 = this.TforY(y0);
282 double ys0 = this.YforT(s0);
283 if (ys0 < y0) {
284 s0 = refineTforY(s0, y0);
285 ys0 = this.YforT(s0);
286 }
287 double s1 = this.TforY(y1);
288 if (this.YforT(s1) < y0) {
289 s1 = refineTforY(s1, y0);
290 //System.out.println("s1 problem!");
291 }
292 double t0 = that.TforY(y0);
293 double yt0 = that.YforT(t0);
294 if (yt0 < y0) {
295 t0 = that.refineTforY(t0, y0);
296 yt0 = that.YforT(t0);
297 }
298 double t1 = that.TforY(y1);
299 if (that.YforT(t1) < y0) {
300 t1 = that.refineTforY(t1, y0);
301 //System.out.println("t1 problem!");
302 }
303 double xs0 = this.XforT(s0);
304 double xt0 = that.XforT(t0);
305 double scale = Math.max(Math.abs(y0), Math.abs(y1));
306 double ymin = Math.max(scale * 1E-14, 1E-300);
307 if (fairlyClose(xs0, xt0)) {
308 double bump = ymin;
309 double maxbump = Math.min(ymin * 1E13, (y1 - y0) * .1);
310 double y = y0 + bump;
311 while (y <= y1) {
312 if (fairlyClose(this.XforY(y), that.XforY(y))) {
313 if ((bump *= 2) > maxbump) {
314 bump = maxbump;
315 }
316 } else {
317 y -= bump;
318 while (true) {
319 bump /= 2;
320 double newy = y + bump;
543 double s = (xnm * ymk - ynm * xmk) * detinv;
544 double t = (xlk * ymk - ylk * xmk) * detinv;
545 if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
546 s = s0 + s * (s1 - s0);
547 t = t0 + t * (t1 - t0);
548 if (s < 0 || s > 1 || t < 0 || t > 1) {
549 System.out.println("Uh oh!");
550 }
551 double y = (this.YforT(s) + that.YforT(t)) / 2;
552 if (y <= yrange[1] && y > yrange[0]) {
553 yrange[1] = y;
554 return true;
555 }
556 }
557 }
558 //System.out.println("Testing lines!");
559 }
560 return false;
561 }
562
563 public double refineTforY(double t0, double y0) {
564 double t1 = 1;
565 while (true) {
566 double th = (t0 + t1) / 2;
567 if (th == t0 || th == t1) {
568 return t1;
569 }
570 double y = YforT(th);
571 if (y < y0) {
572 t0 = th;
573 } else if (y > y0) {
574 t1 = th;
575 } else {
576 return t1;
577 }
578 }
579 }
580
581 public boolean fairlyClose(double v1, double v2) {
582 return (Math.abs(v1 - v2) <
583 Math.max(Math.abs(v1), Math.abs(v2)) * 1E-10);
584 }
585
586 public abstract int getSegment(float coords[]);
587 }
|