ClosestNode no longer requires Region parameter, because regionmanager is passed.

This commit is contained in:
glax 2023-04-06 14:31:38 +02:00
parent 8813023cd6
commit f266c6c7e6

View File

@ -8,14 +8,9 @@ public static class Pathfinder
{ {
public static List<PathNode> CustomAStar(string workingDir, Coordinates start, Coordinates goal, Tag.SpeedType vehicle) public static List<PathNode> CustomAStar(string workingDir, Coordinates start, Coordinates goal, Tag.SpeedType vehicle)
{ {
RegionManager regionManager = new RegionManager(workingDir); RegionManager regionManager = new (workingDir);
Region? startRegion = regionManager.GetRegion(start); OsmNode? startNode = ClosestNodeToCoordinates(start, vehicle, ref regionManager);
Region? goalRegion = regionManager.GetRegion(goal); OsmNode? goalNode = ClosestNodeToCoordinates(goal, vehicle, ref regionManager);
if (startRegion is null || goalRegion is null)
return new List<PathNode>();
OsmNode? startNode = ClosestNodeToCoordinates(start, startRegion, vehicle, ref regionManager);
OsmNode? goalNode = ClosestNodeToCoordinates(goal, goalRegion, vehicle, ref regionManager);
if (startNode == null || goalNode == null) if (startNode == null || goalNode == null)
return new List<PathNode>(); return new List<PathNode>();
@ -71,10 +66,13 @@ public static class Pathfinder
return path; return path;
} }
private static OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Region region, Tag.SpeedType vehicle, ref RegionManager regionManager) public static OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Tag.SpeedType vehicle, ref RegionManager regionManager)
{ {
OsmNode? closest = null; OsmNode? closest = null;
double distance = double.MaxValue; double distance = double.MaxValue;
Region? region = regionManager.GetRegion(coordinates);
if (region is null)
return null;
foreach (OsmNode node in region.nodes) foreach (OsmNode node in region.nodes)
{ {
bool hasConnectionUsingVehicle = false; bool hasConnectionUsingVehicle = false;