public static bool IsOffscreen(Rectangle extent, BoundingCircle bounds) { // Offscreen if closest point on extent is > radius distance away. AABB extentAABB = new AABB(new Vector2(extent.Left, extent.Top), new Vector2(extent.Right, extent.Bottom)); Vector2 closestPoint = extentAABB.ClosestPointTo(bounds.Position); Vector2 displacement = closestPoint - bounds.Position; return displacement.LengthSquared() > bounds.Radius * bounds.Radius; }
public void Add(AABB box) { if (box.Min.X < Min.X) { Min.X = box.Min.X; } if (box.Max.X > Max.X) { Max.X = box.Max.X; } if (box.Min.Y < Min.Y) { Min.Y = box.Min.Y; } if (box.Max.Y > Max.Y) { Max.Y = box.Max.Y; } }
public bool Intersects(AABB box) { return Min.X <= box.Max.X && Max.X >= box.Min.X && Min.Y <= box.Max.Y && Max.Y >= box.Min.Y; }