/// <summary> /// Calculates the intersection point of two segments /// </summary> /// <param name="other">The line to intersect with this one.</param> /// <param name="segment">Segment intersection; the point must be contained in the line segment. If not contained, the returned Vector has int.MaxValue.</param> /// <returns></returns> public virtual Vector2 IntersectionPoint(Segment2D other) { Vector2 point = base.IntersectionPoint(other); if (float.IsNaN(point.x) || float.IsInfinity(point.x)) { return(new Vector2(float.NaN, float.NaN)); } if (Contains(point) && other.Contains(point)) { return(point); } return(new Vector2(float.NaN, float.NaN)); }
public virtual bool Intersects(Segment2D segment) { Vector2 point = IntersectionPoint(segment); return !point.IsNaN() && !point.IsInfinity() && Contains(point) && segment.Contains(point); }