2023-03-14 17:00:59 +01:00
|
|
|
namespace OSMDatastructure.Graph;
|
2023-02-06 17:32:55 +01:00
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
[Serializable]
|
2023-02-07 23:52:23 +01:00
|
|
|
public class OsmNode
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-03-30 18:24:57 +02:00
|
|
|
public ulong nodeId { get; }
|
2023-03-31 21:55:43 +02:00
|
|
|
public HashSet<OsmWay> edges { get; }
|
2023-02-06 17:32:55 +01:00
|
|
|
public Coordinates coordinates { get; }
|
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
[NonSerialized]public OsmNode? previousPathNode = null;
|
|
|
|
[NonSerialized]public double currentPathWeight = double.MaxValue;
|
|
|
|
[NonSerialized]public double currentPathLength = double.MaxValue;
|
|
|
|
[NonSerialized]public double directDistanceToGoal = double.MaxValue;
|
2023-02-06 17:32:55 +01:00
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
public OsmNode(ulong nodeId, float lat, float lon)
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-03-30 18:24:57 +02:00
|
|
|
this.nodeId = nodeId;
|
2023-02-06 17:32:55 +01:00
|
|
|
this.edges = new();
|
|
|
|
this.coordinates = new Coordinates(lat, lon);
|
|
|
|
}
|
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
public OsmNode(ulong nodeId, Coordinates coordinates)
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-03-30 18:24:57 +02:00
|
|
|
this.nodeId = nodeId;
|
2023-02-06 17:32:55 +01:00
|
|
|
this.edges = new();
|
2023-02-07 23:52:23 +01:00
|
|
|
this.coordinates = coordinates;
|
2023-02-06 17:32:55 +01:00
|
|
|
}
|
|
|
|
|
2023-03-31 21:55:43 +02:00
|
|
|
public OsmWay? GetEdgeToNode(OsmNode n)
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-03-31 21:55:43 +02:00
|
|
|
foreach (OsmWay e in this.edges)
|
2023-03-30 18:24:57 +02:00
|
|
|
if (e.neighborId == n.nodeId)
|
2023-02-06 17:32:55 +01:00
|
|
|
return e;
|
|
|
|
return null;
|
|
|
|
}
|
2023-02-08 18:08:01 +01:00
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
{
|
2023-03-30 18:24:57 +02:00
|
|
|
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
|
2023-02-08 18:08:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return HashCode.Combine(coordinates);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2023-02-08 18:49:47 +01:00
|
|
|
if(this.previousPathNode != null)
|
|
|
|
return string.Format(
|
2023-02-08 19:09:46 +01:00
|
|
|
"NODE {0} Edges-Count: {1} previousPathNode: {2} currentPathWeight: {3} currentPathLength: {4} directDistanceToGoal: {5}",
|
2023-02-08 18:49:47 +01:00
|
|
|
this.coordinates.ToString(), this.edges.Count, this.previousPathNode.coordinates.ToString(),
|
2023-02-08 19:09:46 +01:00
|
|
|
this.currentPathWeight, this.currentPathLength, this.directDistanceToGoal);
|
2023-02-08 18:49:47 +01:00
|
|
|
else
|
|
|
|
return string.Format(
|
2023-02-08 19:09:46 +01:00
|
|
|
"NODE {0} Edges-Count: {1} previousPathNode: NO PREVIOUS NODE currentPathWeight: {2} currentPathLength: {3} directDistanceToGoal: {4}",
|
2023-02-08 18:49:47 +01:00
|
|
|
this.coordinates.ToString(), this.edges.Count,
|
2023-02-08 19:09:46 +01:00
|
|
|
this.currentPathWeight, this.currentPathLength, this.directDistanceToGoal);
|
2023-02-08 18:08:01 +01:00
|
|
|
}
|
2023-02-06 17:32:55 +01:00
|
|
|
}
|