Use primary constructor for Rectangle

This commit is contained in:
Stefan Müller 2025-09-27 23:33:34 +02:00
parent 6f86e3576a
commit d92487ffc7

View File

@ -4,28 +4,22 @@ namespace SpatialCollections
{ {
public enum IntersectionType { Contains, Intersects, Disjoint } public enum IntersectionType { Contains, Intersects, Disjoint }
public class Rectangle public class Rectangle(Vector2 min, Vector2 max)
{ {
/// <summary> /// <summary>
/// Vector containing the lowest X and Y coordinates contained in the rectangle. /// Vector containing the lowest X and Y coordinates contained in the rectangle.
/// </summary> /// </summary>
public Vector2 Min; public Vector2 Min = min;
/// <summary> /// <summary>
/// Vector containing the highest X and Y coordinates contained in the rectangle. /// Vector containing the highest X and Y coordinates contained in the rectangle.
/// </summary> /// </summary>
public Vector2 Max; public Vector2 Max = max;
public Vector2 Center => (Max + Min) * 0.5f; public Vector2 Center => (Max + Min) * 0.5f;
public Vector2 Size => Max - Min; public Vector2 Size => Max - Min;
public Rectangle(Vector2 min, Vector2 max)
{
Min = min;
Max = max;
}
public bool Contains(Vector2 position) public bool Contains(Vector2 position)
{ {
return Min.X <= position.X && position.X <= Max.X && Min.Y <= position.Y && position.Y <= Max.Y; return Min.X <= position.X && position.X <= Max.X && Min.Y <= position.Y && position.Y <= Max.Y;