diff --git a/Source/Engine/Core/Math/Rectangle.cs b/Source/Engine/Core/Math/Rectangle.cs index d1fb16abc..885cf6d37 100644 --- a/Source/Engine/Core/Math/Rectangle.cs +++ b/Source/Engine/Core/Math/Rectangle.cs @@ -284,6 +284,17 @@ namespace FlaxEngine Vector2 toExpand = Size * (scale - 1.0f) * 0.5f; return new Rectangle(Location - toExpand * 0.5f, Size + toExpand); } + + /// + /// Computed nearest distance between 2 rectangles. + /// + /// Firat rectangle + /// Second rectangle + /// Resulting distance, 0 if overlapping + public static float Distance(Rectangle a, Rectangle b) + { + return Vector2.Max(Vector2.Zero, Vector2.Abs(a.Center - b.Center) - (a.Size * 0.5f - b.Size * 0.5f)).Length; + } /// /// Calculates a rectangle that includes the margins (inside).