Added Method for path-return (returns the path from current graph).
Added "tags" to return value for path.
This commit is contained in:
parent
2904be84f0
commit
e0bb3ce3de
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user