Added weight and distance delta to pathnode
This commit is contained in:
parent
e0bb3ce3de
commit
206f9c5811
@ -6,9 +6,11 @@ namespace Pathfinding;
|
||||
|
||||
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 new double currentPathLength = double.MaxValue;
|
||||
[JsonInclude]public double distanceBetweenNodes = double.MaxValue;
|
||||
[JsonInclude]public new double currentPathWeight = double.MaxValue;
|
||||
[JsonInclude]public double weightBetweenNodes = double.MaxValue;
|
||||
[JsonInclude]public Dictionary<string, string> tags = new();
|
||||
|
||||
public PathNode(ulong nodeId, float lat, float lon) : base(nodeId, lat, lon)
|
||||
@ -19,15 +21,17 @@ public class PathNode : OsmNode
|
||||
{
|
||||
}
|
||||
|
||||
public static PathNode? FromOsmNode(OsmNode? node, HashSet<Tag>? tags)
|
||||
public static PathNode? FromOsmNode(OsmNode? node, HashSet<Tag>? tags, double distance, double weight)
|
||||
{
|
||||
if (node is null)
|
||||
return null;
|
||||
PathNode retNode = new PathNode(node.nodeId, node.coordinates)
|
||||
PathNode retNode = new(node.nodeId, node.coordinates)
|
||||
{
|
||||
currentPathLength = node.currentPathLength,
|
||||
currentPathWeight = double.IsPositiveInfinity(node.currentPathWeight) ? double.MaxValue : node.currentPathWeight,
|
||||
directDistanceToGoal = node.directDistanceToGoal
|
||||
directDistanceToGoal = node.directDistanceToGoal,
|
||||
distanceBetweenNodes = distance,
|
||||
weightBetweenNodes = weight
|
||||
};
|
||||
if (tags != null)
|
||||
foreach (Tag tag in tags)
|
||||
|
@ -38,16 +38,20 @@ public static partial class Pathfinder
|
||||
while (currentNode is not null)
|
||||
{
|
||||
HashSet<Tag>? tags = null;
|
||||
double distance = 0;
|
||||
double weight = 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;
|
||||
}
|
||||
|
||||
currentNode = currentNode.previousPathNode;
|
||||
PathNode? pn = PathNode.FromOsmNode(currentNode, tags);
|
||||
PathNode? pn = PathNode.FromOsmNode(currentNode, tags, distance, weight);
|
||||
if(pn is not null)
|
||||
path.Add(pn!);
|
||||
currentNode = currentNode.previousPathNode;
|
||||
}
|
||||
|
||||
path.Reverse();
|
||||
|
Loading…
Reference in New Issue
Block a user