AStar/astar/Route.cs

42 lines
1.5 KiB
C#
Raw Normal View History

2024-07-22 04:56:22 +02:00
namespace astar
2022-11-03 19:14:14 +01:00
{
2024-07-22 04:56:22 +02:00
public class Route(Graph graph, List<Step> steps, bool routeFound)
2022-11-03 19:14:14 +01:00
{
2024-07-22 04:56:22 +02:00
public Graph Graph { get; } = graph;
public List<Step> Steps { get; } = steps;
public bool RouteFound { get; } = routeFound;
public float Distance => Steps.Sum(step => step.Distance);
2022-11-03 19:14:14 +01:00
public ValueTuple<float, float> MinCoordinates()
2024-07-22 04:56:22 +02:00
{
float minLat = Graph.Nodes.MinBy(node => node.Value.Lat).Value.Lat;
float minLon = Graph.Nodes.MinBy(node => node.Value.Lon).Value.Lon;
return new ValueTuple<float, float>(minLat, minLon);
2024-07-22 04:56:22 +02:00
}
2022-11-03 19:14:14 +01:00
public ValueTuple<float, float> MaxCoordinates()
2022-11-03 19:14:14 +01:00
{
float maxLat = Graph.Nodes.MaxBy(node => node.Value.Lat).Value.Lat;
float maxLon = Graph.Nodes.MaxBy(node => node.Value.Lon).Value.Lon;
return new ValueTuple<float, float>(maxLat, maxLon);
}
public override string ToString()
{
return $"{string.Join("\n", Steps)}\n" +
$"Distance: {Distance:000000.00}m";
2022-11-03 19:14:14 +01:00
}
}
2024-07-22 04:56:22 +02:00
public struct Step(float distance, Node node1, Node node2)
2022-11-03 19:14:14 +01:00
{
2024-07-22 04:56:22 +02:00
public readonly Node Node1 = node1, Node2 = node2;
public readonly float Distance = distance;
2022-11-13 14:02:27 +01:00
2024-07-22 04:56:22 +02:00
public override string ToString()
2022-11-03 19:14:14 +01:00
{
2024-07-22 04:56:22 +02:00
return $"{Node1.Lat:00.000000} {Node1.Lon:000.000000} --- {Distance:0000.00}m ---> {Node2.Lat:00.000000} {Node2.Lon:000.000000}";
2022-11-03 19:14:14 +01:00
}
}
}