Added Method for path-return (returns the path from current graph).

Added "tags" to return value for path.
This commit is contained in:
glax 2023-04-09 17:38:57 +02:00
parent 2904be84f0
commit e0bb3ce3de
4 changed files with 35 additions and 24 deletions

View File

@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using OSMDatastructure;
using OSMDatastructure.Graph;
namespace Pathfinding;
@ -8,7 +9,8 @@ public class PathNode : OsmNode
[JsonInclude]public new double currentPathWeight = double.MaxValue;
[JsonInclude]public new double currentPathLength = double.MaxValue;
[JsonInclude]public new double directDistanceToGoal = double.MaxValue;
[JsonInclude]public Dictionary<string, string> tags = new();
public PathNode(ulong nodeId, float lat, float lon) : base(nodeId, lat, lon)
{
}
@ -17,7 +19,7 @@ public class PathNode : OsmNode
{
}
public static PathNode? FromOsmNode(OsmNode? node)
public static PathNode? FromOsmNode(OsmNode? node, HashSet<Tag>? tags)
{
if (node is null)
return null;
@ -27,6 +29,12 @@ public class PathNode : OsmNode
currentPathWeight = double.IsPositiveInfinity(node.currentPathWeight) ? double.MaxValue : node.currentPathWeight,
directDistanceToGoal = node.directDistanceToGoal
};
if (tags != null)
foreach (Tag tag in tags)
{
retNode.tags.Add(tag.key.ToString(), tag.value.ToString());
}
return retNode;
}
}

View File

@ -30,4 +30,27 @@ public static partial class Pathfinder
return double.MaxValue;
return distance / speed;
}
private static List<PathNode> GetRouteFromCalc(OsmNode goalNode, RegionManager regionManager)
{
List<PathNode> path = new();
OsmNode? currentNode = goalNode;
while (currentNode is not null)
{
HashSet<Tag>? tags = null;
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);
}
currentNode = currentNode.previousPathNode;
PathNode? pn = PathNode.FromOsmNode(currentNode, tags);
if(pn is not null)
path.Add(pn!);
}
path.Reverse();
return path;
}
}

View File

@ -46,16 +46,6 @@ public static partial class Pathfinder
}
}
}
List<PathNode> path = new();
OsmNode? currentNode = goalNode;
while (currentNode is not null)
{
path.Add(PathNode.FromOsmNode(currentNode)!);
currentNode = currentNode.previousPathNode;
}
path.Reverse();
return path;
return GetRouteFromCalc(goalNode, regionManager);
}
}

View File

@ -50,16 +50,6 @@ public static partial class Pathfinder
}
}
}
List<PathNode> path = new();
OsmNode? currentNode = goalNode;
while (currentNode is not null)
{
path.Add(PathNode.FromOsmNode(currentNode)!);
currentNode = currentNode.previousPathNode;
}
path.Reverse();
return path;
return GetRouteFromCalc(goalNode, regionManager);
}
}