import {
bearingToAzimuth,
} from '@turf/helpers'
import turfBearing from '@turf/bearing'
import { convertCoordinates } from './projections'
import { getArea, getLength, getDistance } from 'ol/sphere'
/** Outils de calculs */
/**
* Calcule l'azimuth depuis le nord entre deux coordonées
* @param {Array<number>} fromCoordinate coordonnée de départ
* @param {Array<number>} toCoordinate coordonnée d'arrivée
* @param {string} coordProjection
* @returns {number} angle en degrée depuis le nord (clockwise)
*/
function getAzimuthBetweenCoordinates (fromCoordinate, toCoordinate, coordProjection) {
if (coordProjection && coordProjection !== 'EPSG:4326') {
fromCoordinate = convertCoordinates(fromCoordinate, coordProjection, 'EPSG:4326')
toCoordinate = convertCoordinates(toCoordinate, coordProjection, 'EPSG:4326')
}
return bearingToAzimuth(turfBearing(fromCoordinate, toCoordinate))
}
export const Calc = {
getAzimuthBetweenCoordinates,
getArea,
getLength,
getDistance,
}