From 585a9213ce0dc9bd704407686b190348468b484a Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 9 Apr 2023 16:29:09 +0200 Subject: [PATCH] Fixed result to correct time and no path error handling --- API/Program.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/API/Program.cs b/API/Program.cs index 09daf67..a195c59 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -19,7 +19,7 @@ app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lon { DateTime startCalc = DateTime.Now; List result = Pathfinder.AStarDistance("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd)); - PathResult pathResult = new PathResult(startCalc - DateTime.Now, result); + PathResult pathResult = new PathResult(DateTime.Now - startCalc, result); return pathResult; } ); @@ -48,15 +48,18 @@ app.Run(); internal class PathResult { [JsonInclude]public TimeSpan calcTime; - [JsonInclude] public double pathWeight; - [JsonInclude] public double pathTravelDistance; + [JsonInclude] public double pathWeight = double.PositiveInfinity; + [JsonInclude] public double pathTravelDistance = double.PositiveInfinity; [JsonInclude]public List pathNodes; public PathResult(TimeSpan calcTime, List pathNodes) { this.calcTime = calcTime; this.pathNodes = pathNodes; - this.pathWeight = pathNodes.Last().currentPathWeight; - this.pathTravelDistance = pathNodes.Last().currentPathLength; + if (pathNodes.Count > 0) + { + this.pathWeight = pathNodes.Last().currentPathWeight; + this.pathTravelDistance = pathNodes.Last().currentPathLength; + } } } \ No newline at end of file