Game/RectF.cs

Axis-aligned rectangle value type for float coordinates. Stores left, bottom, right, top and provides width/height, corner properties, an open-interval intersection test and a point-inclusive containment test.

Native Interop
namespace BlockParty;

/// <summary>
/// Axis-aligned float rectangle matching the original GameAPI <c>RectF</c> used by the
/// collision code. Y is up (Bottom is less than Top). Constructed as (left, bottom, right, top).
/// </summary>
public struct RectF
{
	public float Left;
	public float Bottom;
	public float Right;
	public float Top;

	public RectF( float left, float bottom, float right, float top )
	{
		Left = left;
		Bottom = bottom;
		Right = right;
		Top = top;
	}

	public float Width => Right - Left;
	public float Height => Top - Bottom;

	public readonly Vector2 BottomLeft => new Vector2( Left, Bottom );
	public readonly Vector2 TopLeft => new Vector2( Left, Top );
	public readonly Vector2 BottomRight => new Vector2( Right, Bottom );
	public readonly Vector2 TopRight => new Vector2( Right, Top );

	/// <summary>True if this rect overlaps <paramref name="other"/> (open intervals — touching edges do not count).</summary>
	public readonly bool Intersects( RectF other )
	{
		return Left < other.Right && Right > other.Left &&
			   Bottom < other.Top && Top > other.Bottom;
	}

	/// <summary>True if the point lies within this rect (inclusive edges).</summary>
	public readonly bool Touches( Vector2 p )
	{
		return p.x >= Left && p.x <= Right && p.y >= Bottom && p.y <= Top;
	}
}