This commit is contained in:
Javier Casares 2026-10-12 13:25:09 +00:00
commit e1f5a47c96
22 changed files with 3155 additions and 0 deletions

View file

@ -0,0 +1,42 @@
<?php
/**
* Haversine distance from Font del Bosc.
*
* @package FontdelboscCombustible
*/
declare( strict_types=1 );
defined( 'ABSPATH' ) || exit;
/**
* Distance calculations against the fixed origin point.
*/
final class Fontdelbosc_Combustible_Geo {
/**
* Reference latitude of Font del Bosc.
*/
public const ORIGIN_LAT = 41.4819;
/**
* Reference longitude of Font del Bosc.
*/
public const ORIGIN_LON = 1.6483;
/**
* Great-circle distance in km from Font del Bosc to a point.
*
* @param float $lat2 Target latitude.
* @param float $lon2 Target longitude.
*/
public static function haversine( float $lat2, float $lon2 ): float {
$r = 6371;
$dlat = deg2rad( $lat2 - self::ORIGIN_LAT );
$dlon = deg2rad( $lon2 - self::ORIGIN_LON );
$a = ( sin( $dlat / 2 ) ** 2 )
+ ( cos( deg2rad( self::ORIGIN_LAT ) ) * cos( deg2rad( $lat2 ) ) * ( sin( $dlon / 2 ) ** 2 ) );
return 2 * $r * asin( sqrt( $a ) );
}
}