Added currentPathLength to OsmNode
This commit is contained in:
parent
55b9e87b7e
commit
d3680565fc
@ -7,6 +7,7 @@ public class OsmNode
|
|||||||
|
|
||||||
public OsmNode? previousPathNode = null;
|
public OsmNode? previousPathNode = null;
|
||||||
public double currentPathWeight = double.MaxValue;
|
public double currentPathWeight = double.MaxValue;
|
||||||
|
public double currentPathLength = double.MaxValue;
|
||||||
public double directDistanceToGoal = double.MaxValue;
|
public double directDistanceToGoal = double.MaxValue;
|
||||||
|
|
||||||
public OsmNode(float lat, float lon)
|
public OsmNode(float lat, float lon)
|
||||||
@ -43,13 +44,13 @@ public class OsmNode
|
|||||||
{
|
{
|
||||||
if(this.previousPathNode != null)
|
if(this.previousPathNode != null)
|
||||||
return string.Format(
|
return string.Format(
|
||||||
"NODE {0} Edges-Count: {1} previousPathNode: {2} currentPathWeight: {3} directDistanceToGoal: {4}",
|
"NODE {0} Edges-Count: {1} previousPathNode: {2} currentPathWeight: {3} currentPathLength: {4} directDistanceToGoal: {5}",
|
||||||
this.coordinates.ToString(), this.edges.Count, this.previousPathNode.coordinates.ToString(),
|
this.coordinates.ToString(), this.edges.Count, this.previousPathNode.coordinates.ToString(),
|
||||||
this.currentPathWeight, this.directDistanceToGoal);
|
this.currentPathWeight, this.currentPathLength, this.directDistanceToGoal);
|
||||||
else
|
else
|
||||||
return string.Format(
|
return string.Format(
|
||||||
"NODE {0} Edges-Count: {1} previousPathNode: NO PREVIOUS NODE currentPathWeight: {2} directDistanceToGoal: {3}",
|
"NODE {0} Edges-Count: {1} previousPathNode: NO PREVIOUS NODE currentPathWeight: {2} currentPathLength: {3} directDistanceToGoal: {4}",
|
||||||
this.coordinates.ToString(), this.edges.Count,
|
this.coordinates.ToString(), this.edges.Count,
|
||||||
this.currentPathWeight, this.directDistanceToGoal);
|
this.currentPathWeight, this.currentPathLength, this.directDistanceToGoal);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,6 +28,7 @@ public class Pathfinder
|
|||||||
List<OsmNode> toVisit = new() { startNode };
|
List<OsmNode> toVisit = new() { startNode };
|
||||||
OsmNode closestNodeToGoal = toVisit.First();
|
OsmNode closestNodeToGoal = toVisit.First();
|
||||||
closestNodeToGoal.currentPathWeight = 0;
|
closestNodeToGoal.currentPathWeight = 0;
|
||||||
|
closestNodeToGoal.currentPathLength = 0;
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
|
|
||||||
while (toVisit.Count > 0 && !stop)
|
while (toVisit.Count > 0 && !stop)
|
||||||
@ -57,6 +58,7 @@ public class Pathfinder
|
|||||||
{
|
{
|
||||||
neighbor.previousPathNode = closestNodeToGoal;
|
neighbor.previousPathNode = closestNodeToGoal;
|
||||||
neighbor.currentPathWeight = newPotentialWeight;
|
neighbor.currentPathWeight = newPotentialWeight;
|
||||||
|
neighbor.currentPathLength = closestNodeToGoal.currentPathLength + Utils.DistanceBetween(closestNodeToGoal, neighbor);
|
||||||
|
|
||||||
if (neighbor.Equals(goalNode))
|
if (neighbor.Equals(goalNode))
|
||||||
stop = true;
|
stop = true;
|
||||||
|
Reference in New Issue
Block a user