const degrees_to_radians = Math.PI / 180;
const sin = (degrees: number) => Math.sin(degrees * degrees_to_radians);
const cos = (degrees: number) => Math.cos(degrees * degrees_to_radians);
type Coordinates = readonly [longitude: number, latitude: number];
export const haversine_distance = ([λ1, φ1]: Coordinates, [λ2, φ2]: Coordinates, radius = 6371) =>
2 * radius * Math.asin(Math.sqrt(sin((φ2 - φ1) / 2) ** 2 + cos(φ1) * cos(φ2) * sin((λ2 - λ1) / 2) ** 2));