Changed distance back to double

This commit is contained in:
C9Glax 2022-11-13 13:21:24 +01:00
parent a971e4ed6c
commit 23bab6a593
3 changed files with 9 additions and 8 deletions

View File

@ -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)

View File

@ -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();

View File

@ -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);