Add distance calculation based on haversine
Alire installation and checkup / build (ubuntu-20.04) (push) Failing after 4m0s

This commit is contained in:
Nina Chlóe Kassandra Reiß
2026-06-15 05:38:52 +02:00
parent 4af251007f
commit 64cfecef9a
2 changed files with 46 additions and 1 deletions
+37
View File
@@ -1,3 +1,5 @@
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
package body Grl.Coordinates is package body Grl.Coordinates is
function To_DD (DM_Base : Coordinate) return Coordinate is function To_DD (DM_Base : Coordinate) return Coordinate is
@@ -37,4 +39,39 @@ package body Grl.Coordinates is
return DD_Target; return DD_Target;
end To_DD; end To_DD;
function Plane_Distance (Origin, Destination : Coordinate) return H is
Heuristic : H;
A : H;
DD_Origin : constant Coordinate := To_DD (Origin);
DD_Destination : constant Coordinate := To_DD (Destination);
Earth_Radius : constant H := 6_371_000.0; -- M
Delta_Phi : constant H := -- Latitude difference
H (DD_Destination.DD.Latitude - DD_Origin.DD.Latitude);
Delta_Lambda : constant H := -- Longitude difference
H (DD_Destination.DD.Longitude - DD_Origin.DD.Longitude);
-- @name Hav
-- @return Float
-- @parameter Theta:Float
-- @variable Fraction : Float
-- @description Compute Haversine function.
function Hav (Theta : H) return Float is
Fraction : Float;
begin
Fraction := Float (Theta) / 2.0;
return Sin (Fraction)**2;
end Hav;
begin
A :=
H (Hav (Delta_Phi) +
Cos (Float (DD_Origin.DD.Latitude)) *
Cos (Float (DD_Destination.DD.Latitude)) * Hav (Delta_Lambda));
-- Haversine formula
Heuristic := Earth_Radius * H (2.0 * Arcsin (Sqrt (Float (A))));
return Heuristic;
end Plane_Distance;
end Grl.Coordinates; end Grl.Coordinates;
+8
View File
@@ -118,4 +118,12 @@ is
(DM_Base.Form = DD) or else (DM_Base.Form = DMS) (DM_Base.Form = DD) or else (DM_Base.Form = DMS)
or else (DM_Base.Form = DDM); or else (DM_Base.Form = DDM);
-- @name Plane_Distance
-- @return H
-- @parameter Origin:Coordinate
-- @parameter Destination:Coordinate
-- @variable Heuristic : H
-- @description Calculate heuristic between coordinates.
function Plane_Distance (Origin, Destination : Coordinate) return H;
end Grl.Coordinates; end Grl.Coordinates;