double to float

This commit is contained in:
C9Glax 2022-10-31 23:10:28 +01:00
parent 13dd052c3d
commit 77bc712eba
4 changed files with 12 additions and 12 deletions

View File

@ -3,8 +3,8 @@
public struct Edge public struct Edge
{ {
public Node neighbor { get; } public Node neighbor { get; }
public double weight { get; } public float weight { get; }
public Edge(Node neighbor, double weight) public Edge(Node neighbor, float weight)
{ {
this.neighbor = neighbor; this.neighbor = neighbor;
this.weight = weight; this.weight = weight;

View File

@ -4,21 +4,21 @@
{ {
public float lat { get; } public float lat { get; }
public float lon { get; } public float lon { get; }
public List<Edge> edges { get; } public HashSet<Edge> edges { get; }
public Node previousNode { get; set; } public Node previousNode { get; set; }
public double goalDistance { get; set; } public float goalDistance { get; set; }
public double pathLength { get; set; } public float pathLength { get; set; }
public Node(float lat, float lon) public Node(float lat, float lon)
{ {
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
this.edges = new List<Edge>(); this.edges = new();
this.previousNode = nullnode; this.previousNode = nullnode;
this.goalDistance = double.MaxValue; this.goalDistance = float.MaxValue;
this.pathLength = double.MaxValue; this.pathLength = float.MaxValue;
} }
public static Node nullnode = new(float.NaN, float.NaN); public static Node nullnode = new(float.NaN, float.NaN);
} }

View File

@ -2,12 +2,12 @@
public struct Utils public struct Utils
{ {
public static double DistanceBetweenNodes(Node n1, Node n2) public static float DistanceBetweenNodes(Node n1, Node n2)
{ {
return DistanceBetweenCoordinates(n1.lat, n1.lon, n2.lat, n2.lon); return DistanceBetweenCoordinates(n1.lat, n1.lon, n2.lat, n2.lon);
} }
public static double DistanceBetweenCoordinates(float lat1, float lon1, float lat2, float lon2) public static float DistanceBetweenCoordinates(float lat1, float lon1, float lat2, float lon2)
{ {
const int earthRadius = 6371; const int earthRadius = 6371;
double differenceLat = DegreesToRadians(lat2 - lat1); double differenceLat = DegreesToRadians(lat2 - lat1);
@ -19,7 +19,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 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)); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
return earthRadius * c; return Convert.ToSingle(earthRadius * c);
} }
private static double DegreesToRadians(double deg) private static double DegreesToRadians(double deg)

View File

@ -34,7 +34,7 @@ namespace astar
foreach(Node n in nodes.Values) foreach(Node n in nodes.Values)
{ {
n.previousNode = Node.nullnode; n.previousNode = Node.nullnode;
n.goalDistance = double.MaxValue; n.goalDistance = float.MaxValue;
} }
} }