OSMServer/OSMDatastructure/Coordinates.cs

56 lines
1.7 KiB
C#
Raw Normal View History

namespace OSMDatastructure.Graph;
2023-02-02 22:30:43 +01:00
2023-02-06 17:32:55 +01:00
public class Coordinates
2023-02-02 22:30:43 +01:00
{
2023-02-06 17:32:55 +01:00
public float latitude { get; }
public float longitude { get; }
2023-02-02 22:30:43 +01:00
2023-02-06 17:32:55 +01:00
public Coordinates(float latitude, float longitude)
{
this.latitude = latitude;
this.longitude = longitude;
}
2023-02-02 22:30:43 +01:00
2023-02-06 17:32:55 +01:00
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;
}
2023-02-06 17:32:55 +01:00
private const float decimalCoordsSave = 10000;
private const ulong offset = 10000000;
//Latitude maxChars = 7
//Longitude maxChars = 8
public override int GetHashCode()
2023-02-06 17:32:55 +01:00
{
return GetHashCode(latitude, longitude);
2023-02-06 17:32:55 +01:00
}
public static int GetRegionHashCode(float latitude, float longitude)
2023-02-07 23:53:25 +01:00
{
float latRegion = latitude - latitude % Region.RegionSize;
float lonRegion = longitude - longitude % Region.RegionSize;
return GetHashCode(latRegion, lonRegion);
2023-02-07 23:53:25 +01:00
}
public static int GetRegionHashCode(Coordinates coordinates)
2023-02-06 17:32:55 +01:00
{
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);
2023-02-02 22:30:43 +01:00
}
2023-02-08 18:08:49 +01:00
public override string ToString()
{
return string.Format("COORDINATES Lat: {0} Lon: {1}", this.latitude, this.longitude);
}
2023-02-02 22:30:43 +01:00
}