From d8f8a41dcc7c24e3537dea50207a5111b7dfb7b4 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 9 Apr 2023 17:52:37 +0200 Subject: [PATCH] Renamed PathNode distance and weight to include "delta". Added directDistanceDelta --- Pathfinding/PathNode.cs | 12 +++++++----- Pathfinding/Pathfinder.cs | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Pathfinding/PathNode.cs b/Pathfinding/PathNode.cs index 138392c..a526339 100644 --- a/Pathfinding/PathNode.cs +++ b/Pathfinding/PathNode.cs @@ -7,10 +7,11 @@ namespace Pathfinding; public class PathNode : OsmNode { [JsonInclude]public new double directDistanceToGoal = double.MaxValue; + [JsonInclude]public double directDistanceDelta = double.MaxValue; [JsonInclude]public new double currentPathLength = double.MaxValue; - [JsonInclude]public double distanceBetweenNodes = double.MaxValue; + [JsonInclude]public double pathDistanceDelta = double.MaxValue; [JsonInclude]public new double currentPathWeight = double.MaxValue; - [JsonInclude]public double weightBetweenNodes = double.MaxValue; + [JsonInclude]public double pathWeightDelta = double.MaxValue; [JsonInclude]public Dictionary tags = new(); public PathNode(ulong nodeId, float lat, float lon) : base(nodeId, lat, lon) @@ -21,7 +22,7 @@ public class PathNode : OsmNode { } - public static PathNode? FromOsmNode(OsmNode? node, HashSet? tags, double distance, double weight) + public static PathNode? FromOsmNode(OsmNode? node, HashSet? tags, double pathDistanceDelta, double pathWeightDelta, double directDistanceDelta) { if (node is null) return null; @@ -30,8 +31,9 @@ public class PathNode : OsmNode currentPathLength = node.currentPathLength, currentPathWeight = double.IsPositiveInfinity(node.currentPathWeight) ? double.MaxValue : node.currentPathWeight, directDistanceToGoal = node.directDistanceToGoal, - distanceBetweenNodes = distance, - weightBetweenNodes = weight + directDistanceDelta = directDistanceDelta, + pathDistanceDelta = pathDistanceDelta, + pathWeightDelta = pathWeightDelta }; if (tags != null) foreach (Tag tag in tags) diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index 09a6fa1..6307b16 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -38,17 +38,20 @@ public static partial class Pathfinder while (currentNode is not null) { HashSet? tags = null; - double distance = 0; - double weight = 0; + double pathDistanceDelta = 0; + double pathWeightDelta = 0; + double directDistanceDelta = 0; if (currentNode.previousPathNode is not null) { OsmEdge edge = currentNode.previousPathNode!.edges.First(e => e.neighborId.Equals(currentNode.nodeId)); tags = regionManager.GetRegion(currentNode.coordinates)!.tagManager.GetTagsForWayId(edge.wayId); - distance = currentNode.currentPathLength - currentNode.previousPathNode.currentPathLength; - weight = currentNode.currentPathWeight - currentNode.previousPathNode.currentPathWeight; + pathDistanceDelta = currentNode.currentPathLength - currentNode.previousPathNode.currentPathLength; + pathWeightDelta = currentNode.currentPathWeight - currentNode.previousPathNode.currentPathWeight; + directDistanceDelta = + currentNode.directDistanceToGoal - currentNode.previousPathNode.directDistanceToGoal; } - PathNode? pn = PathNode.FromOsmNode(currentNode, tags, distance, weight); + PathNode? pn = PathNode.FromOsmNode(currentNode, tags, pathDistanceDelta, pathWeightDelta, directDistanceDelta); if(pn is not null) path.Add(pn!); currentNode = currentNode.previousPathNode;