22 lines
970 B
C#
22 lines
970 B
C#
using System;
|
|
|
|
namespace Grid {
|
|
public struct GridPosition : IEquatable<GridPosition> {
|
|
public int X { get; }
|
|
public int Z { get; }
|
|
|
|
public GridPosition(int x, int z) {
|
|
X = x;
|
|
Z = z;
|
|
}
|
|
|
|
public override string ToString() => $"{X};{Z}";
|
|
public static bool operator ==(GridPosition a, GridPosition b) => a.X == b.X && a.Z == b.Z;
|
|
public static bool operator !=(GridPosition a, GridPosition b) => a.X != b.X || a.Z != b.Z;
|
|
public override bool Equals(object obj) => obj is GridPosition other && Equals(other);
|
|
public override int GetHashCode() => HashCode.Combine(X, Z);
|
|
public bool Equals(GridPosition other) => X == other.X && Z == other.Z;
|
|
public static GridPosition operator +(GridPosition a, GridPosition b) => new(a.X + b.X, a.Z + b.Z);
|
|
public static GridPosition operator -(GridPosition a, GridPosition b) => new(a.X - b.X, a.Z - b.Z);
|
|
}
|
|
} |