public LineSegment IntersectingSegmentWithLine([NotNull] Line line) { var n = this.Edges.Count; var intersections = new Either <Null, Point, LineSegment> [n]; for (int i = 0; i < n; i++) { intersections[i] = FastGeometry.IntersectLineAndSegment(line, this.Edges[i]); if (intersections[i].Is <LineSegment>(out var segment)) { return(segment); } } for (int current = 0; current < n; current++) { if (intersections[current].Is <Point>(out var currentIntersection)) { var previous = current == 0 ? n - 1 : current - 1; if (intersections[previous].Is <Point>() && currentIntersection == this.Edges[current].BasePoint) { intersections[current] = Null.Instance; } var next = current == n - 1 ? 0 : current + 1; if (intersections[next].Is <Point>() && currentIntersection == this.Edges[current].EndPoint) { intersections[current] = Null.Instance; } } } var distinct = intersections .Choose(intersection => (intersection.Is <Point>(out var point), point)) .ToList(); return(distinct.Count == 2 ? new LineSegment(distinct[0], distinct[1]) : null); }
public Either <Null, Point, LineSegment> IntersectWithSegment([NotNull] LineSegment segment) { return(FastGeometry.IntersectLineAndSegment(this, segment)); }
/// <summary> /// Checks if this Vector intersects the given line and returns the point if it does or null otherwise /// </summary> /// <param name="line">The line to check if this intersects with</param> /// <returns>returns the intersection point of the two lines or null if they do not</returns> public Either <Null, Point, LineSegment> IntersectWithLine([NotNull] Line passedLine) { return(FastGeometry.IntersectLineAndSegment(passedLine, this)); }