From 10e99a9cd216d8ec4ea3f14d2fd13faf1d5eca85 Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Fri, 3 Feb 2023 23:44:15 +0100 Subject: [PATCH] Expand PathNode --- Pathfinding/PathNode.cs | 18 ++++++++++++++++++ Pathfinding/Pathfinder.cs | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Pathfinding/PathNode.cs b/Pathfinding/PathNode.cs index 483224f..22a4791 100644 --- a/Pathfinding/PathNode.cs +++ b/Pathfinding/PathNode.cs @@ -1,9 +1,27 @@ +using OSMDatastructure; + namespace Pathfinding; public class PathNode : OSMDatastructure.Node { + PathNode? previousNode = null; + private Dictionary distanceDictionary = new(); + double currentWeight = double.MaxValue; + + public PathNode(float lat, float lon) : base(lat, lon) { } + + public double? DistanceTo(Connection connection) + { + if (!this.GetConnections().Contains(connection)) + return null; //TODO exception is not actually connected + if (!this.distanceDictionary.ContainsKey(connection)) + this.distanceDictionary.Add(connection, Utils.DistanceBetween(this, connection.endNodeCoordinates)); + return this.distanceDictionary[connection]; + } + + } \ No newline at end of file diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index f46a594..77d8ced 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -10,9 +10,10 @@ public class Pathfinder { RegionManager regionManager = new RegionManager(workingDir); Region startRegion = regionManager.GetRegion(start)!; //TODO null handling - Node startNode = ClosestNodeToCoordinates(start, startRegion)!; //TODO null handling + PathNode startNode = (PathNode)ClosestNodeToCoordinates(start, startRegion)!; //TODO null handling Region goalRegion = regionManager.GetRegion(goal)!; //TODO null handling - Node goalNode = ClosestNodeToCoordinates(goal, goalRegion)!; //TODO null handling + PathNode goalNode = (PathNode)ClosestNodeToCoordinates(goal, goalRegion)!; //TODO null handling + }