protected static bool Near([NotNull] Pnt p0, [NotNull] Pnt l0, [NotNull] Pnt p1, [NotNull] Pnt l1, double r2, double l12, ref double tMin, ref double tMax, ref NearSegment hullStartNear, ref NearSegment hullEndNear) { double cMin, cMax; double u0 = (p0 + tMin * l0 - p1) * l1 / l12; double u1 = (p0 + tMax * l0 - p1) * l1 / l12; if (u0 < 0) { if (SegmentUtils.CutLineCircle(p0, l0, p1, r2, out cMin, out cMax) == false) { return(false); } hullStartNear = Near(cMin, cMax); // Debug.Assert(cMin > tMin); numerical exceptions possible tMin = cMin; if (u1 < 0) { //Debug.Assert(cMax < tMax); numerical exceptions possible tMax = cMax; } } else if (u0 > 1) { if (SegmentUtils.CutLineCircle(p0, l0, p1 + l1, r2, out cMin, out cMax) == false) { return(false); } hullEndNear = Near(cMin, cMax); //Debug.Assert(cMin > tMin); numerical exceptions possible tMin = cMin; if (u1 > 1) { //Debug.Assert(cMax < tMax); numerical exceptions possible tMax = cMax; } } if (u1 < 0 && u0 >= 0) { if (SegmentUtils.CutLineCircle(p0, l0, p1, r2, out cMin, out cMax) == false) { //throw new InvalidProgramException( // "error in software design assumption"); numerical exceptions possible tMax = tMin + u0 / (u0 - u1) * (tMax - tMin); hullStartNear = Near(tMin, tMax); } else { hullStartNear = Near(cMin, cMax); //Debug.Assert(cMax < tMax); numerical exceptions possible tMax = cMax; } } else if (u1 > 1 && u0 <= 1) { if (SegmentUtils.CutLineCircle(p0, l0, p1 + l1, r2, out cMin, out cMax) == false) { //throw new InvalidProgramException( // "error in software design assumption"); numerical exceptions possible tMax = tMin + (1 - u0) / (u1 - u0) * (tMax - tMin); hullEndNear = Near(tMin, tMax); } else { hullEndNear = Near(cMin, cMax); //Debug.Assert(cMax < tMax); numerical exceptions possible tMax = cMax; } } return(true); }