AStar/astar/Route.cs

46 lines
1.7 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
2024-07-23 17:07:31 +02:00
public TimeSpan Time => TimeSpan.FromHours(Steps.Sum(step => step.Distance / 1000 / step.Speed));
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" +
2024-07-23 17:07:31 +02:00
$"Distance: {Distance:000000.00}m\n" +
2024-07-23 23:54:09 +02:00
$"Time: {Time:hh\\:mm\\:ss}";
2022-11-03 19:14:14 +01:00
}
}
2024-07-23 17:07:31 +02:00
public struct Step(Node node1, Node node2, float distance, byte speed)
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;
2024-07-23 17:07:31 +02:00
public readonly byte Speed = speed;
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-23 17:07:31 +02:00
return $"{Node1.Lat:00.000000} {Node1.Lon:000.000000} --- {Distance:0000.00}m {Speed:000} ---> {Node2.Lat:00.000000} {Node2.Lon:000.000000}";
2022-11-03 19:14:14 +01:00
}
}
}