OSMServer/OSMDatastructure/OsmNode.cs
2023-04-01 14:19:36 +02:00

54 lines
1.6 KiB
C#

namespace OSMDatastructure.Graph;
[Serializable]
public class OsmNode
{
public ulong nodeId { get; }
public HashSet<OsmEdge> edges { get; }
public Coordinates coordinates { get; }
[NonSerialized]public OsmNode? previousPathNode = null;
[NonSerialized]public double currentPathWeight = double.MaxValue;
[NonSerialized]public double currentPathLength = double.MaxValue;
[NonSerialized]public double directDistanceToGoal = double.MaxValue;
public OsmNode(ulong nodeId, float lat, float lon)
{
this.nodeId = nodeId;
this.edges = new();
this.coordinates = new Coordinates(lat, lon);
}
public OsmNode(ulong nodeId, Coordinates coordinates)
{
this.nodeId = nodeId;
this.edges = new();
this.coordinates = coordinates;
}
public OsmEdge? GetEdgeToNode(OsmNode n)
{
foreach (OsmEdge e in this.edges)
if (e.neighborId == n.nodeId)
return e;
return null;
}
public override bool Equals(object? obj)
{
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
}
public override int GetHashCode()
{
return HashCode.Combine(coordinates);
}
public override string ToString()
{
if(previousPathNode is not null)
return $"{nodeId} {coordinates} {edges.Count} {directDistanceToGoal} {currentPathWeight} {currentPathLength} {previousPathNode.nodeId}";
return
$"{nodeId} {coordinates} ec:{edges.Count} d:{directDistanceToGoal} w:{currentPathWeight} l:{currentPathLength} null";
}
}