EdgeWeight rewrite
This commit is contained in:
parent
05ae0bff6e
commit
5efec08bbc
@ -19,12 +19,15 @@ public static partial class Pathfinder
|
|||||||
return retTuple;
|
return retTuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double EdgeWeight(OsmNode node1, OsmNode node2, ulong wayId, Tag.SpeedType vehicle, ref RegionManager regionManager)
|
private static double EdgeWeight(OsmNode node1, OsmEdge edge, Tag.SpeedType vehicle, RegionManager regionManager)
|
||||||
{
|
{
|
||||||
|
OsmNode? node2 = regionManager.GetNode(edge.neighborId, edge.neighborRegion);
|
||||||
|
if (node2 is null)
|
||||||
|
return double.MaxValue;
|
||||||
double distance = Utils.DistanceBetween(node1, node2);
|
double distance = Utils.DistanceBetween(node1, node2);
|
||||||
double speed = regionManager.GetSpeedForEdge(node1, wayId, vehicle);
|
double speed = regionManager.GetSpeedForEdge(node1, edge.wayId, vehicle);
|
||||||
if (speed is not 0)
|
if (speed is 0)
|
||||||
return distance / speed;
|
return double.MaxValue;
|
||||||
return double.PositiveInfinity;
|
return distance / speed;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,6 +32,8 @@ public static partial class Pathfinder
|
|||||||
{
|
{
|
||||||
neighbor.previousPathNode = closestNodeToGoal;
|
neighbor.previousPathNode = closestNodeToGoal;
|
||||||
neighbor.currentPathLength = newPotentialLength;
|
neighbor.currentPathLength = newPotentialLength;
|
||||||
|
neighbor.currentPathWeight = closestNodeToGoal.currentPathWeight +
|
||||||
|
EdgeWeight(closestNodeToGoal, edge, Tag.SpeedType.road, regionManager);
|
||||||
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
neighbor.directDistanceToGoal = Utils.DistanceBetween(neighbor, goalNode);
|
||||||
|
|
||||||
if (neighbor.Equals(goalNode))
|
if (neighbor.Equals(goalNode))
|
||||||
|
@ -29,8 +29,7 @@ public static partial class Pathfinder
|
|||||||
if (neighbor is not null)
|
if (neighbor is not null)
|
||||||
{
|
{
|
||||||
double newPotentialWeight = closestNodeToGoal.currentPathLength +
|
double newPotentialWeight = closestNodeToGoal.currentPathLength +
|
||||||
EdgeWeight(closestNodeToGoal, neighbor, edge.wayId, vehicle,
|
EdgeWeight(closestNodeToGoal, edge, vehicle, regionManager);
|
||||||
ref regionManager);
|
|
||||||
if (newPotentialWeight < neighbor.currentPathWeight)
|
if (newPotentialWeight < neighbor.currentPathWeight)
|
||||||
{
|
{
|
||||||
neighbor.previousPathNode = closestNodeToGoal;
|
neighbor.previousPathNode = closestNodeToGoal;
|
||||||
|
Reference in New Issue
Block a user