using System; namespace Mapbox.Map { /// /// Unwrapped tile identifier in a slippy map. Similar to , /// but might go around the globe. /// public struct UnwrappedTileId : IEquatable { /// The zoom level. public readonly int Z; /// The X coordinate in the tile grid. public readonly int X; /// The Y coordinate in the tile grid. public readonly int Y; /// /// Initializes a new instance of the struct, /// representing a tile coordinate in a slippy map that might go around the /// globe. /// /// The z coordinate. /// The x coordinate. /// The y coordinate. public UnwrappedTileId(int z, int x, int y) { this.Z = z; this.X = x; this.Y = y; } /// Gets the canonical tile identifier. /// The canonical tile identifier. public CanonicalTileId Canonical { get { return new CanonicalTileId(this); } } /// /// Returns a that represents the current /// . /// /// /// A that represents the current /// . /// public override string ToString() { return this.Z + "/" + this.X + "/" + this.Y; } public bool Equals(UnwrappedTileId other) { return this.X == other.X && this.Y == other.Y && this.Z == other.Z; } public override int GetHashCode() { return (X << 6) ^ (Y << 16) ^ (Z << 8); } public override bool Equals(object obj) { return this.X == ((UnwrappedTileId)obj).X && this.Y == ((UnwrappedTileId)obj).Y && this.Z == ((UnwrappedTileId)obj).Z; } public static bool operator ==(UnwrappedTileId a, UnwrappedTileId b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; } public static bool operator !=(UnwrappedTileId a, UnwrappedTileId b) { return !(a == b); } public UnwrappedTileId North { get { return new UnwrappedTileId(Z, X, Y - 1); } } public UnwrappedTileId East { get { return new UnwrappedTileId(Z, X + 1, Y); } } public UnwrappedTileId South { get { return new UnwrappedTileId(Z, X, Y + 1); } } public UnwrappedTileId West { get { return new UnwrappedTileId(Z, X - 1, Y); } } public UnwrappedTileId NorthEast { get { return new UnwrappedTileId(Z, X + 1, Y - 1); } } public UnwrappedTileId SouthEast { get { return new UnwrappedTileId(Z, X + 1, Y + 1); } } public UnwrappedTileId NorthWest { get { return new UnwrappedTileId(Z, X - 1, Y - 1); } } public UnwrappedTileId SouthWest { get { return new UnwrappedTileId(Z, X - 1, Y + 1); } } } }