All files / core/domain latLon.ts

83.33% Statements 5/6
100% Branches 0/0
50% Functions 1/2
100% Lines 4/4

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            8x       8x   8x     18x              
import { Number, Schema } from 'effect'
 
import type * as Geo from '../geo/ellipsoid'
import { wrapLon } from '../geo/ellipsoid'
 
/** A WGS84 position. The maths layer (src/geo) declares the same shape without Effect. */
export const LatLon = Schema.Struct({ lat: Schema.Finite, lon: Schema.Finite })
export type LatLon = typeof LatLon.Type
 
// NOTE: compile-time check that this Schema and the maths layer's LatLon stay the same shape.
export const toGeo = (point: LatLon): Geo.LatLon => point
 
const MAX_LATITUDE = 90
 
/** Clamp the latitude to the poles and wrap the longitude into [-180, 180). */
export const clampToWorld = (point: LatLon): LatLon => ({
  lat: Number.clamp(point.lat, {
    minimum: -MAX_LATITUDE,
    maximum: MAX_LATITUDE,
  }),
  lon: wrapLon(point.lon),
})