internal double GetClosestPoint(Point2d point, Line2d line, ref bool start) { if (line == null) { return(Double.PositiveInfinity); } double distance = new Vector2d(line.StartPoint, point).Length; start = true; double endDistance = new Vector2d(line.EndPoint, point).Length; if (endDistance < distance) { start = false; distance = endDistance; } return(distance); }
public static Value FromLine2d(GridBasis basis, int ordinal, Line2d line, bool snap) { PointAxis2d.Value p0 = PointAxis2d.Value.FromPoint2d(basis, ordinal, line.StartPoint, snap); if (p0 == null) { return(null); } PointAxis2d.Value p1 = PointAxis2d.Value.FromPoint2d(basis, ordinal, line.EndPoint, snap); if (p1 == null) { return(null); } if (p0.Abscissa != p1.Abscissa) { return(null); } return(new Value(p0.Abscissa, new Range1d(p0.Ordinate, p1.Ordinate))); }
public Point2d Intersect(Line2d line, bool clip, bool allowOneFail) { Vector2d p = new Vector2d(m_start); Vector2d q = new Vector2d(line.StartPoint); Vector2d r = new Vector2d(p, m_end); Vector2d s = new Vector2d(q, line.EndPoint); double rxs = r.Cross(s); // Parallel (could be collinear) if (rxs.IsZero()) { return(null); } double t = q.Subtract(p).Cross(s) / rxs; if (clip) { bool tFail = (t.CompareLess(0) || t.CompareGreater(1)); if (tFail && !allowOneFail) { return(null); } double u = q.Subtract(p).Cross(r) / rxs; bool uFail = (u.CompareLess(0) || u.CompareGreater(1)); if (uFail && !allowOneFail) { return(null); } if (allowOneFail && tFail && uFail) { return(null); } } return(p.Add(r.Scale(t))); }
internal Line2d Join(Line2d current) { if (m_start.Compare(current.StartPoint)) { return(new Line2d(current.EndPoint, m_end)); } if (m_end.Compare(current.StartPoint)) { return(new Line2d(current.EndPoint, m_start)); } if (m_start.Compare(current.EndPoint)) { return(new Line2d(current.StartPoint, m_end)); } if (m_end.Compare(current.EndPoint)) { return(new Line2d(current.StartPoint, m_start)); } return(null); }
internal Line2d(Line2d other) { m_start = new Point2d(other.StartPoint); m_end = new Point2d(other.EndPoint); }
public Point2d Intersect(Line2d line, bool clip = false) { return(Intersect(line, clip, false)); }
internal Point2d GetPoint(Line2d line, bool start) { return(start ? line.StartPoint : line.EndPoint); }