59 lines
1.3 KiB
C#
59 lines
1.3 KiB
C#
using System;
|
|
|
|
namespace FloodSWE.TileGraph
|
|
{
|
|
public readonly struct TileId : IEquatable<TileId>
|
|
{
|
|
public readonly int Lod;
|
|
public readonly int X;
|
|
public readonly int Y;
|
|
|
|
public TileId(int lod, int x, int y)
|
|
{
|
|
Lod = lod;
|
|
X = x;
|
|
Y = y;
|
|
}
|
|
|
|
public bool Equals(TileId other)
|
|
{
|
|
return Lod == other.Lod && X == other.X && Y == other.Y;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return obj is TileId other && Equals(other);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(Lod, X, Y);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"LOD{Lod} ({X},{Y})";
|
|
}
|
|
|
|
public static bool operator ==(TileId a, TileId b)
|
|
{
|
|
return a.Equals(b);
|
|
}
|
|
|
|
public static bool operator !=(TileId a, TileId b)
|
|
{
|
|
return !a.Equals(b);
|
|
}
|
|
|
|
public TileId Parent()
|
|
{
|
|
return Lod > 0 ? new TileId(Lod - 1, X >> 1, Y >> 1) : this;
|
|
}
|
|
|
|
public TileId Child(int childX, int childY)
|
|
{
|
|
return new TileId(Lod + 1, (X << 1) + childX, (Y << 1) + childY);
|
|
}
|
|
}
|
|
}
|