public static bool TestIntersection(this Bounds bounds, BoundaryRect rect) { if (bounds is BoundaryCircle) { return rect.TestIntersection(bounds as BoundaryCircle); } else if (bounds is BoundaryRect) { return rect.TestIntersection(bounds as BoundaryRect); } else { throw new InvalidOperationException("Attempting to test boundary on unknown types"); } }
public static bool DoesCircleIntersectRect(BoundaryRect rect, BoundaryCircle circle) { // 2 cases: // case 1: the center of the circle is within the rect // case 2: the rectange has an edge that intersects the circle if (rect.ContainsPoint(circle.Center)) { return true; } else { return rect.Top.TestIntersection(circle) || rect.Bottom.TestIntersection(circle) || rect.Left.TestIntersection(circle) || rect.Right.TestIntersection(circle); } }
public static bool TestIntersection(this BoundaryCircle circle, BoundaryRect rect) { return DoesCircleIntersectRect(rect, circle); }