- API 12
- Cleanup
This commit is contained in:
+21
-12
@@ -4,30 +4,39 @@ namespace ChatTwo.Util;
|
||||
|
||||
public static class MathUtil
|
||||
{
|
||||
public struct Rectangle
|
||||
public record Rectangle
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
public int Width;
|
||||
public int Height;
|
||||
|
||||
public static Rectangle FromPosAndSize(Vector2 pos, Vector2 size)
|
||||
public int SizeX;
|
||||
public int SizeY;
|
||||
|
||||
public Rectangle(int x, int y, int width, int height)
|
||||
{
|
||||
return new Rectangle
|
||||
{
|
||||
X = (int) pos.X,
|
||||
Y = (int) pos.Y,
|
||||
Width = (int) size.X,
|
||||
Height = (int) size.Y
|
||||
};
|
||||
X = x;
|
||||
Y = y;
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
||||
SizeX = X + Width;
|
||||
SizeY = Y + Height;
|
||||
}
|
||||
|
||||
public int SizeX => X + Width;
|
||||
public int SizeY => Y + Height;
|
||||
public Rectangle(Vector2 pos, Vector2 size)
|
||||
: this((int) pos.X, (int) pos.Y, (int) size.X, (int) size.Y) { }
|
||||
}
|
||||
|
||||
// From: https://stackoverflow.com/a/306379
|
||||
public static bool CheckRectOverlap(Rectangle a, Rectangle b)
|
||||
/// <summary>
|
||||
/// Checks if two rectangles overlap at any point.
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <returns>True if overlapping</returns>
|
||||
public static bool HasOverlap(this Rectangle a, Rectangle b)
|
||||
{
|
||||
bool ValueInRange(int value, int min, int max)
|
||||
=> value > min && value < max;
|
||||
|
||||
Reference in New Issue
Block a user