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;
|
||||
|
||||
[Serializable]
|
||||
@ -11,6 +14,14 @@ public class OsmNode
|
||||
[NonSerialized]public double currentPathWeight = double.MaxValue;
|
||||
[NonSerialized]public double currentPathLength = 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)
|
||||
{
|
||||
@ -28,10 +39,10 @@ public class OsmNode
|
||||
|
||||
public OsmEdge? GetEdgeToNode(OsmNode n)
|
||||
{
|
||||
foreach (OsmEdge e in this.edges)
|
||||
if (e.neighborId == n.nodeId)
|
||||
return e;
|
||||
return null;
|
||||
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)
|
||||
@ -39,15 +50,10 @@ public class OsmNode
|
||||
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} p:{previousPathNode.nodeId}";
|
||||
return
|
||||
$"{nodeId} {coordinates} ec:{edges.Count} d:{directDistanceToGoal} w:{currentPathWeight} l:{currentPathLength} null";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user