Fixed deserialization issue with wrong default values
ToString() uniform
This commit is contained in:
parent
8cf13efae3
commit
2826ff2502
@ -1,3 +1,6 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace OSMDatastructure.Graph;
|
namespace OSMDatastructure.Graph;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -12,6 +15,14 @@ public class OsmNode
|
|||||||
[NonSerialized]public double currentPathLength = double.MaxValue;
|
[NonSerialized]public double currentPathLength = double.MaxValue;
|
||||||
[NonSerialized]public double directDistanceToGoal = double.MaxValue;
|
[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)
|
public OsmNode(ulong nodeId, float lat, float lon)
|
||||||
{
|
{
|
||||||
this.nodeId = nodeId;
|
this.nodeId = nodeId;
|
||||||
@ -28,10 +39,10 @@ public class OsmNode
|
|||||||
|
|
||||||
public OsmEdge? GetEdgeToNode(OsmNode n)
|
public OsmEdge? GetEdgeToNode(OsmNode n)
|
||||||
{
|
{
|
||||||
foreach (OsmEdge e in this.edges)
|
HashSet<OsmEdge> e = edges.Where(edge => edge.neighborId == n.nodeId).ToHashSet();
|
||||||
if (e.neighborId == n.nodeId)
|
if (e.Count > 0)
|
||||||
return e;
|
return e.First();
|
||||||
return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
@ -39,15 +50,10 @@ public class OsmNode
|
|||||||
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
|
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return HashCode.Combine(coordinates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
if(previousPathNode is not null)
|
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} p:{previousPathNode.nodeId}";
|
||||||
return
|
return
|
||||||
$"{nodeId} {coordinates} ec:{edges.Count} d:{directDistanceToGoal} w:{currentPathWeight} l:{currentPathLength} null";
|
$"{nodeId} {coordinates} ec:{edges.Count} d:{directDistanceToGoal} w:{currentPathWeight} l:{currentPathLength} null";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user