56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
namespace OSMDatastructure.Graph;
|
|
|
|
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 override int GetHashCode()
|
|
{
|
|
return GetHashCode(latitude, longitude);
|
|
}
|
|
|
|
public static int GetRegionHashCode(float latitude, float longitude)
|
|
{
|
|
float latRegion = latitude - latitude % Region.RegionSize;
|
|
float lonRegion = longitude - longitude % Region.RegionSize;
|
|
return GetHashCode(latRegion, lonRegion);
|
|
}
|
|
|
|
public static int GetRegionHashCode(Coordinates coordinates)
|
|
{
|
|
float latRegion = coordinates.latitude - coordinates.latitude % Region.RegionSize;
|
|
float lonRegion = coordinates.longitude - coordinates.longitude % Region.RegionSize;
|
|
return GetHashCode(latRegion, lonRegion);
|
|
}
|
|
|
|
public static int GetHashCode(float latitude, float longitude)
|
|
{
|
|
return HashCode.Combine(latitude, longitude);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("COORDINATES Lat: {0} Lon: {1}", this.latitude, this.longitude);
|
|
}
|
|
} |