using System;
public struct GridPosition : IEquatable<GridPosition>
{
public int x;
public int z;
public GridPosition(int x, int z)
{
this.x = x;
this.z = z;
}
public GridPosition((int x, int z) position)
{
this.x = position.x;
this.z = position.z;
}
public override bool Equals(object obj)
{
return obj is GridPosition position &&
x == position.x &&
z == position.z;
}
public bool Equals(GridPosition other)
{
return this == other;
}
public override int GetHashCode()
{
return HashCode.Combine(x, z);
}
public override string ToString()
{
return $"{x},{z}";
}
public static bool operator == (GridPosition a, GridPosition b) {
return ((a.x == b.x) && (a.z == b.z));
}
public static bool operator != (GridPosition a, GridPosition b) {
return !(a == b);
}
public static GridPosition operator + (GridPosition a, GridPosition b) {
// return new GridPosition(a.x + b.x, a.z + b.z);
return a + (b.x, b.z);
}
public static GridPosition operator + (GridPosition a, (int x, int z) b) {
return new GridPosition(a.x + b.x, a.z + b.z);
}
public static GridPosition operator - (GridPosition a, GridPosition b) {
// return new GridPosition(a.x - b.x, a.z - b.z);
return a - (b.x, b.z);
}
public static GridPosition operator - (GridPosition a, (int x, int z) b) {
return new GridPosition(a.x - b.x, a.z - b.z);
}
public bool IsInCircularRange(GridPosition inRelationToGridPosition, int distance) =>
(Math.Abs(x - inRelationToGridPosition.x) + Math.Abs(z - inRelationToGridPosition.z) <= distance);
}