- Check all tooltips for clipping

This commit is contained in:
Infi
2025-03-15 14:00:26 +01:00
parent 14cb3af13a
commit a6b71f50e6
5 changed files with 74 additions and 26 deletions
+40
View File
@@ -0,0 +1,40 @@
using System.Numerics;
namespace ChatTwo.Util;
public static class MathUtil
{
public struct Rectangle
{
public int X;
public int Y;
public int Width;
public int Height;
public static Rectangle FromPosAndSize(Vector2 pos, Vector2 size)
{
return new Rectangle
{
X = (int) pos.X,
Y = (int) pos.Y,
Width = (int) size.X,
Height = (int) size.Y
};
}
public int SizeX => X + Width;
public int SizeY => Y + Height;
}
// From: https://stackoverflow.com/a/306379
public static bool CheckRectOverlap(Rectangle a, Rectangle b)
{
bool ValueInRange(int value, int min, int max)
=> value > min && value < max;
var xOverlap = ValueInRange(a.X, b.X, b.X + b.Width) || ValueInRange(b.X, a.X, a.X + a.Width);
var yOverlap = ValueInRange(a.Y, b.Y, b.Y + b.Height) || ValueInRange(b.Y, a.Y, a.Y + a.Height);
return xOverlap && yOverlap;
}
}