namespace OSMDatastructure; public class Coordinates { public float latitude { get; } public float longitude { get; } public Coordinates(float latitude, float longitude) { this.latitude = latitude; this.longitude = longitude; } public override bool Equals(object? obj) { if (obj == null || obj.GetType() != this.GetType()) return false; Coordinates convObj = (Coordinates)obj; // ReSharper disable twice CompareOfFloatsByEqualityOperator static values return convObj.latitude == this.latitude && convObj.longitude == this.longitude; } private const float decimalCoordsSave = 10000; private const ulong offset = 10000000; //Latitude maxChars = 7 //Longitude maxChars = 8 public ulong GetHash() { ulong latHash = Convert.ToUInt64((this.latitude + 90) * decimalCoordsSave); ulong lonHash = Convert.ToUInt64((this.longitude + 180) * decimalCoordsSave); return latHash * offset + lonHash; } public ulong GetRegionHash() { float latRegion = this.latitude - this.latitude % Region.regionSize; float lonRegion = this.longitude - this.longitude % Region.regionSize; ulong latHash = Convert.ToUInt64((latRegion + 90) * decimalCoordsSave); ulong lonHash = Convert.ToUInt64((lonRegion + 180) * decimalCoordsSave); return latHash * offset + lonHash; } }