Rectangle distance
Will be usefull for my UI nav
This commit is contained in:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user