moved to correct namespacefolder
This commit is contained in:
54
OSMDatastructure/Graph/Coordinates.cs
Normal file
54
OSMDatastructure/Graph/Coordinates.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace OSMDatastructure.Graph;
|
||||
|
||||
[Serializable]
|
||||
public class Coordinates
|
||||
{
|
||||
public float latitude { get; }
|
||||
public float longitude { get; }
|
||||
|
||||
[JsonConstructor]
|
||||
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;
|
||||
}
|
||||
|
||||
public static ulong GetRegionHashCode(float latitude, float longitude)
|
||||
{
|
||||
float latRegion = latitude - latitude % Region.RegionSize;
|
||||
float lonRegion = longitude - longitude % Region.RegionSize;
|
||||
return GetHashCode(latRegion, lonRegion);
|
||||
}
|
||||
|
||||
public static ulong GetRegionHashCode(Coordinates coordinates)
|
||||
{
|
||||
return GetRegionHashCode(coordinates.latitude, coordinates.longitude);
|
||||
}
|
||||
|
||||
private const float decimalCoordsSave = 10000; //Latitude maxChars = 7
|
||||
private const ulong offset = 10000000; //Longitude maxChars = 8
|
||||
public static ulong GetHashCode(float latitude, float longitude)
|
||||
{
|
||||
ulong latHash = Convert.ToUInt64((latitude + 90) * decimalCoordsSave);
|
||||
ulong lonHash = Convert.ToUInt64((longitude + 180) * decimalCoordsSave);
|
||||
return latHash * offset + lonHash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return
|
||||
$"lat:{latitude.ToString(NumberFormatInfo.InvariantInfo)} lon:{longitude.ToString(CultureInfo.InvariantCulture)}";
|
||||
}
|
||||
}
|
27
OSMDatastructure/Graph/OsmEdge.cs
Normal file
27
OSMDatastructure/Graph/OsmEdge.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace OSMDatastructure.Graph;
|
||||
|
||||
[Serializable]
|
||||
public class OsmEdge
|
||||
{
|
||||
public ulong wayId { get; }
|
||||
public ulong startId { get; }
|
||||
public ulong neighborId { get; }
|
||||
public ulong neighborRegion { get; }
|
||||
|
||||
|
||||
[JsonConstructor]
|
||||
public OsmEdge(ulong wayId, ulong startId, ulong neighborId, ulong neighborRegion)
|
||||
{
|
||||
this.wayId = wayId;
|
||||
this.startId = startId;
|
||||
this.neighborId = neighborId;
|
||||
this.neighborRegion = neighborRegion;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"w:{wayId} n1:{startId} n2:{neighborId} in r:{neighborRegion}";
|
||||
}
|
||||
}
|
61
OSMDatastructure/Graph/OsmNode.cs
Normal file
61
OSMDatastructure/Graph/OsmNode.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace OSMDatastructure.Graph;
|
||||
|
||||
[Serializable]
|
||||
public class OsmNode
|
||||
{
|
||||
public ulong nodeId { get; }
|
||||
public HashSet<OsmEdge> edges { get; set; }
|
||||
public Coordinates coordinates { get; }
|
||||
|
||||
[JsonIgnore][NonSerialized]public OsmNode? previousPathNode = null;
|
||||
[JsonIgnore][NonSerialized]public double currentPathWeight = double.MaxValue;
|
||||
[JsonIgnore][NonSerialized]public double currentPathLength = double.MaxValue;
|
||||
[JsonIgnore][NonSerialized]public double directDistanceToGoal = double.MaxValue;
|
||||
|
||||
[OnDeserialized]
|
||||
internal void SetDefaultValues(StreamingContext context)
|
||||
{
|
||||
currentPathWeight = double.MaxValue;
|
||||
currentPathLength = double.MaxValue;
|
||||
directDistanceToGoal = double.MaxValue;
|
||||
}
|
||||
|
||||
public OsmNode(ulong nodeId, float lat, float lon)
|
||||
{
|
||||
this.nodeId = nodeId;
|
||||
this.edges = new();
|
||||
this.coordinates = new Coordinates(lat, lon);
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public OsmNode(ulong nodeId, Coordinates coordinates)
|
||||
{
|
||||
this.nodeId = nodeId;
|
||||
this.edges = new();
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
public OsmEdge? GetEdgeToNode(OsmNode n)
|
||||
{
|
||||
HashSet<OsmEdge> e = edges.Where(edge => edge.neighborId == n.nodeId).ToHashSet();
|
||||
if (e.Count > 0)
|
||||
return e.First();
|
||||
else return null;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if(previousPathNode is not null)
|
||||
return $"{nodeId} {coordinates} ec:{edges.Count} d:{directDistanceToGoal} w:{currentPathWeight} l:{currentPathLength} p:{previousPathNode.nodeId}";
|
||||
return
|
||||
$"{nodeId} {coordinates} ec:{edges.Count} d:{directDistanceToGoal} w:{currentPathWeight} l:{currentPathLength} null";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user