All files / core/geo ellipsoid.ts

100% Statements 12/12
100% Branches 14/14
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39  23x           23x   23x 23x 23x   23x 23x                 159220x 670x 670x       3015x                  
/** WGS84 ellipsoid constants. */
export const WGS84 = {
  a: 6378137.0,
  f: 1 / 298.257223563,
} as const
 
/** The datum every position in the app is on. AGeoP-21 (D.2.1) asks that the datum is always stated. */
export const DATUM_LABEL = 'WGS 84'
 
export const b = WGS84.a * (1 - WGS84.f)
export const e2 = WGS84.f * (2 - WGS84.f)
export const e = Math.sqrt(e2)
 
export const DEG = Math.PI / 180
export const RAD = 180 / Math.PI
 
export interface LatLon {
  lat: number
  lon: number
}
 
/** Wrap a longitude into [-180, 180). */
export function wrapLon(lon: number): number {
  if (lon >= -180 && lon < 180) return lon
  const w = ((((lon + 180) % 360) + 360) % 360) - 180
  return w === -180 && lon > 0 ? 180 - 1e-12 : w
}
 
export function isValidLatLon(p: LatLon): boolean {
  return (
    Number.isFinite(p.lat) &&
    Number.isFinite(p.lon) &&
    p.lat >= -90 &&
    p.lat <= 90 &&
    p.lon >= -180 &&
    p.lon <= 180
  )
}