diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index b1568f8..030e49d 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -39,7 +39,7 @@ public static class Pathfinder { double newPotentialWeight = closestNodeToGoal.currentPathWeight + EdgeWeight(closestNodeToGoal, neighbor, edge.wayId, vehicle, ref regionManager); - if (neighbor.currentPathWeight > newPotentialWeight) + if (newPotentialWeight < neighbor.currentPathWeight) { neighbor.previousPathNode = closestNodeToGoal; neighbor.currentPathWeight = newPotentialWeight; @@ -79,15 +79,15 @@ public static class Pathfinder double distance = double.MaxValue; foreach (OsmNode node in region.nodes) { - bool hasConnection = false; + bool hasConnectionUsingVehicle = false; foreach (OsmEdge edge in node.edges) { double speed = GetSpeed(node, edge.wayId, vehicle, ref regionManager); if (speed != 0) - hasConnection = true; + hasConnectionUsingVehicle = true; } double nodeDistance = Utils.DistanceBetween(node, coordinates); - if (nodeDistance < distance && hasConnection) + if (nodeDistance < distance && hasConnectionUsingVehicle) { closest = node; distance = nodeDistance; @@ -110,12 +110,12 @@ public static class Pathfinder return 0; case Tag.SpeedType.car: case Tag.SpeedType.road: - byte? maxspeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed); - if (maxspeed is not null) - return (double)maxspeed; - maxspeed = Tag.defaultSpeedCar[wayType]; - if(maxspeed is not 0) - return (byte)maxspeed; + byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed); + if (maxSpeed is not null) + return (double)maxSpeed; + maxSpeed = Tag.defaultSpeedCar[wayType]; + if(maxSpeed is not 0) + return (byte)maxSpeed; return 0; default: return 0; @@ -128,7 +128,6 @@ public static class Pathfinder double speed = GetSpeed(node1, wayId, vehicle, ref regionManager); if (speed is not 0) return distance / speed; - else - return double.PositiveInfinity; + return double.PositiveInfinity; } } \ No newline at end of file