public bool CheckIntersectWithCircle(RXCircle circle) { Vector2 delta = circle.center - this.center; float radiusSumSquared = (circle.radius + this.radius) * (circle.radius + this.radius); return(delta.sqrMagnitude <= radiusSumSquared); }
// NOTE: Rect MUST be axis-aligned for this check public static bool CheckIntersectWithCircle(this Rect rect, RXCircle circle) { // Find the closest point to the circle center that's within the rectangle Vector2 closest = GetClosestInteriorPoint(rect, circle.center); // Calculate the distance between the circle's center and this closest point Vector2 deltaToClosest = circle.center - closest; // If the distance is less than the circle's radius, an intersection occurs bool intersection = (deltaToClosest.sqrMagnitude <= circle.radiusSquared); return(intersection); }