Rectangle distance

Will be usefull for my UI nav
This commit is contained in:
Nejcraft
2021-07-16 04:32:47 +02:00
committed by GitHub
parent 8ae3c23ec8
commit af8856188d

View File

@@ -284,6 +284,17 @@ namespace FlaxEngine
Vector2 toExpand = Size * (scale - 1.0f) * 0.5f;
return new Rectangle(Location - toExpand * 0.5f, Size + toExpand);
}
/// <summary>
/// Computed nearest distance between 2 rectangles.
/// </summary>
/// <param name="w">Firat rectangle</param>
/// <param name="b">Second rectangle</param>
/// <returns>Resulting distance, 0 if overlapping</returns>
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;
}
/// <summary>
/// Calculates a rectangle that includes the margins (inside).