28 lines
865 B
C#
28 lines
865 B
C#
using UnityEngine;
|
|
|
|
public readonly struct AsrsRect
|
|
{
|
|
public readonly int MinX, MinY, MaxX, MaxY; // inclusive
|
|
|
|
public AsrsRect(int minX, int minY, int maxX, int maxY)
|
|
{
|
|
MinX = minX; MinY = minY; MaxX = maxX; MaxY = maxY;
|
|
}
|
|
|
|
public static AsrsRect FromTwoPoints(Vector2Int a, Vector2Int b)
|
|
{
|
|
int minX = Mathf.Min(a.x, b.x);
|
|
int maxX = Mathf.Max(a.x, b.x);
|
|
int minY = Mathf.Min(a.y, b.y);
|
|
int maxY = Mathf.Max(a.y, b.y);
|
|
return new AsrsRect(minX, minY, maxX, maxY);
|
|
}
|
|
|
|
public bool Contains(int x, int y)
|
|
=> x >= MinX && x <= MaxX && y >= MinY && y <= MaxY;
|
|
|
|
public bool EqualsTo(in AsrsRect other)
|
|
=> MinX == other.MinX && MinY == other.MinY && MaxX == other.MaxX && MaxY == other.MaxY;
|
|
|
|
public override string ToString() => $"[{MinX},{MinY}]~[{MaxX},{MaxY}]";
|
|
} |