Grid/GridPos.cs

A small immutable value type representing an integer grid cell coordinate with X to the right and Y up. Provides Zero, addition and subtraction operators, and a ToString override.

namespace Coilgarden;

/// <summary>
/// An integer cell coordinate. X runs right, Y runs up.
/// <para>
/// Gameplay is resolved entirely in these coordinates, never in world space. That is
/// what makes collision exact and identical on every machine, and it is why the
/// presentation layer is free to interpolate as much as it likes without being able to
/// change a rule.
/// </para>
/// </summary>
public readonly record struct GridPos( int X, int Y )
{
	public static readonly GridPos Zero = new( 0, 0 );

	public static GridPos operator +( GridPos a, GridPos b ) => new( a.X + b.X, a.Y + b.Y );

	public static GridPos operator -( GridPos a, GridPos b ) => new( a.X - b.X, a.Y - b.Y );

	public override string ToString() => $"({X},{Y})";
}