From 23bab6a593e8363f0358e8cb1fd692bde54cf2a5 Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Sun, 13 Nov 2022 13:21:24 +0100 Subject: [PATCH] Changed distance back to double --- Graph/Utils.cs | 9 +++++---- OpenStreetMap Importer/Importer.cs | 4 ++-- astar/Astar.cs | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Graph/Utils.cs b/Graph/Utils.cs index 30f60ea..ab6f989 100644 --- a/Graph/Utils.cs +++ b/Graph/Utils.cs @@ -1,13 +1,14 @@ -namespace Graph{ +namespace Graph +{ public struct Utils { - public static float DistanceBetweenNodes(Node n1, Node n2) + public static double DistanceBetweenNodes(Node n1, Node n2) { return DistanceBetweenCoordinates(n1.lat, n1.lon, n2.lat, n2.lon); } - public static float DistanceBetweenCoordinates(float lat1, float lon1, float lat2, float lon2) + public static double DistanceBetweenCoordinates(float lat1, float lon1, float lat2, float lon2) { const int earthRadius = 6371000; double differenceLat = DegreesToRadians(lat2 - lat1); @@ -19,7 +20,7 @@ double a = Math.Sin(differenceLat / 2) * Math.Sin(differenceLat / 2) + Math.Sin(differenceLon / 2) * Math.Sin(differenceLon / 2) * Math.Cos(lat1Rads) * Math.Cos(lat2Rads); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); - return Convert.ToSingle(earthRadius * c); + return earthRadius * c; } private static double DegreesToRadians(double deg) diff --git a/OpenStreetMap Importer/Importer.cs b/OpenStreetMap Importer/Importer.cs index b52a23a..656dca0 100644 --- a/OpenStreetMap Importer/Importer.cs +++ b/OpenStreetMap Importer/Importer.cs @@ -159,7 +159,7 @@ namespace OpenStreetMap_Importer _n1 = _graph[_currentWay.nodeIds[_nodeIdIndex]]; _n2 = _graph[_currentWay.nodeIds[_nodeIdIndex + 1]]; - _distance = Utils.DistanceBetweenNodes(_n1, _n2); + _distance = Convert.ToSingle(Utils.DistanceBetweenNodes(_n1, _n2)); _time = _distance / _currentWay.GetMaxSpeed(); if (!_currentWay.IsOneWay()) { @@ -184,7 +184,7 @@ namespace OpenStreetMap_Importer for(int _nodeIdIndex = 0; _nodeIdIndex < _currentWay.nodeIds.Count - 1; _nodeIdIndex++) { _n2 = _graph[_currentWay.nodeIds[_nodeIdIndex + 1]]; - _distance += Utils.DistanceBetweenNodes(_currentNode, _n2); + _distance += Convert.ToSingle(Utils.DistanceBetweenNodes(_currentNode, _n2)); if (occuranceCount[_currentWay.nodeIds[_nodeIdIndex]] > 1 || _nodeIdIndex == _currentWay.nodeIds.Count - 2) //junction found { _time = _distance / _currentWay.GetMaxSpeed(); diff --git a/astar/Astar.cs b/astar/Astar.cs index 6a149fe..8b06c43 100644 --- a/astar/Astar.cs +++ b/astar/Astar.cs @@ -29,7 +29,7 @@ namespace astar toVisit.Add(start); Node currentNode = start; start.timeRequired = 0; - start.goalDistance = Utils.DistanceBetweenNodes(start, goal); + start.goalDistance = Convert.ToSingle(Utils.DistanceBetweenNodes(start, goal)); while (toVisit.Count > 0 && toVisit[0].timeRequired < goal.timeRequired) { if(currentNode == goal) @@ -43,7 +43,7 @@ namespace astar { if (e.neighbor.timeRequired > currentNode.timeRequired + e.time) { - e.neighbor.goalDistance = Utils.DistanceBetweenNodes(e.neighbor, goal); + e.neighbor.goalDistance = Convert.ToSingle(Utils.DistanceBetweenNodes(e.neighbor, goal)); e.neighbor.timeRequired = currentNode.timeRequired + e.time; e.neighbor.previousNode = currentNode; toVisit.Add(e.neighbor);