From 72b5511c2654ef2437ecb02ee7946e9b23b4a44a Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 6 Apr 2023 02:32:04 +0200 Subject: [PATCH] better readability --- Pathfinding/Pathfinder.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) 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