Added overlap detection against rectangles and points.

This commit is contained in:
Harrison Deng 2020-07-11 01:38:24 -05:00
parent d4efce48c3
commit ab58480434

View File

@ -1,4 +1,5 @@
using System.Drawing;
using System.Numerics;
namespace SlatedGameToolkit.Framework.Utilities
{
@ -12,5 +13,21 @@ namespace SlatedGameToolkit.Framework.Utilities
rect.Height *= multiplier;
return rect;
}
public static bool IsOverlapping(this RectangleF a, RectangleF b) {
if (a.Left > b.Right) return false;
if (a.Right < b.Left) return false;
if (a.Bottom > b.Top) return false;
if (a.Top < b.Bottom) return false;
return true;
}
public static bool IsWithin(this RectangleF rect, Vector2 vector) {
if (vector.X > rect.Right) return false;
if (vector.X < rect.Left) return false;
if (vector.Y > rect.Top) return false;
if (vector.Y < rect.Bottom) return false;
return true;
}
}
}