Added overlap detection against rectangles and points.
This commit is contained in:
parent
d4efce48c3
commit
ab58480434
@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace SlatedGameToolkit.Framework.Utilities
|
namespace SlatedGameToolkit.Framework.Utilities
|
||||||
{
|
{
|
||||||
@ -12,5 +13,21 @@ namespace SlatedGameToolkit.Framework.Utilities
|
|||||||
rect.Height *= multiplier;
|
rect.Height *= multiplier;
|
||||||
return rect;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user