/// <summary> /// Calculate Euclidean distance between a point and a finite line segment. /// </summary> /// /// <param name="point">The point to calculate the distance to.</param> /// /// <returns>Returns the Euclidean distance between this line segment and the specified point. Unlike /// <see cref="Line2D.DistanceToPoint"/>, this returns the distance from the finite segment. (0,0) is 5 units /// from the segment (0,5)-(0,8), but is 0 units from the line through those points.</returns> /// public float DistanceToPoint(Vector2 point) { float segmentDistance; switch (LocateProjection(point)) { case ProjectionLocation.RayA: segmentDistance = point.DistanceTo(_start); break; case ProjectionLocation.RayB: segmentDistance = point.DistanceTo(_end); break; default: segmentDistance = _line.DistanceToPoint(point); break; } ; return(segmentDistance); }