public CurveLink(Curve curve, double ystart, double yend, int etag) { _curve = curve; _ytop = ystart; _ybot = yend; _etag = etag; if (_ytop < curve.GetYTop() || _ybot > curve.GetYBot()) { throw new SystemException("bad curvelink [" + _ytop + "=>" + _ybot + "] for " + curve); } }
public bool Absorb(Curve curve, double ystart, double yend, int etag) { if (_curve != curve || _etag != etag || _ybot < ystart || _ytop > yend) { return false; } if (ystart < curve.GetYTop() || yend > curve.GetYBot()) { throw new SystemException("bad curvelink [" + ystart + "=>" + yend + "] for " + curve); } _ytop = Math.Min(_ytop, ystart); _ybot = Math.Max(_ybot, yend); return true; }
public int CompareTo(Curve that, double[] yrange) { /* System.out.println(this+".compareTo("+that+")"); System.out.println("target range = "+yrange[0]+"=>"+yrange[1]); */ double y0 = yrange[0]; double y1 = yrange[1]; y1 = Math.Min(Math.Min(y1, GetYBot()), that.GetYBot()); if (y1 <= yrange[0]) { throw new SystemException("backstepping from " + yrange[0] + " to " + y1); } yrange[1] = y1; if (GetXMax() <= that.GetXMin()) { if (GetXMin() == that.GetXMax()) { return 0; } return -1; } if (GetXMin() >= that.GetXMax()) { return 1; } // Parameter s for thi(s) curve and t for tha(t) curve // [st]0 = parameters for top of current section of interest // [st]1 = parameters for bottom of valid range // [st]h = parameters for hypothesis point // [d][xy]s = valuations of thi(s) curve at sh // [d][xy]t = valuations of tha(t) curve at th double s0 = TforY(y0); double ys0 = YforT(s0); if (ys0 < y0) { s0 = RefineTforY(s0, ys0, y0); ys0 = YforT(s0); } double s1 = TforY(y1); if (YforT(s1) < y0) { s1 = RefineTforY(s1, YforT(s1), y0); //System.out.println("s1 problem!"); } double t0 = that.TforY(y0); double yt0 = that.YforT(t0); if (yt0 < y0) { t0 = that.RefineTforY(t0, yt0, y0); yt0 = that.YforT(t0); } double t1 = that.TforY(y1); if (that.YforT(t1) < y0) { t1 = that.RefineTforY(t1, that.YforT(t1), y0); //System.out.println("t1 problem!"); } double xs0 = XforT(s0); double xt0 = that.XforT(t0); double scale = Math.Max(Math.Abs(y0), Math.Abs(y1)); double ymin = Math.Max(scale * 1E-14, 1E-300); if (FairlyClose(xs0, xt0)) { double bump = ymin; double maxbump = Math.Min(ymin * 1E13, (y1 - y0) * .1); double y = y0 + bump; while (y <= y1) { if (FairlyClose(XforY(y), that.XforY(y))) { if ((bump *= 2) > maxbump) { bump = maxbump; } } else { y -= bump; while (true) { bump /= 2; double newy = y + bump; if (newy <= y) { break; } if (FairlyClose(XforY(newy), that.XforY(newy))) { y = newy; } } break; } y += bump; } if (y > y0) { if (y < y1) { yrange[1] = y; } return 0; } } while (s0 < s1 && t0 < t1) { double sh = NextVertical(s0, s1); double xsh = XforT(sh); double ysh = YforT(sh); double th = that.NextVertical(t0, t1); double xth = that.XforT(th); double yth = that.YforT(th); /* System.out.println("sh = "+sh); System.out.println("th = "+th); */ try { if (FindIntersect(that, yrange, ymin, 0, 0, s0, xs0, ys0, sh, xsh, ysh, t0, xt0, yt0, th, xth, yth)) { break; } } catch (Exception) { return 0; } if (ysh < yth) { if (ysh > yrange[0]) { if (ysh < yrange[1]) { yrange[1] = ysh; } break; } s0 = sh; xs0 = xsh; ys0 = ysh; } else { if (yth > yrange[0]) { if (yth < yrange[1]) { yrange[1] = yth; } break; } t0 = th; xt0 = xth; yt0 = yth; } } double ymid = (yrange[0] + yrange[1]) / 2; return Orderof(XforY(ymid), that.XforY(ymid)); }