chrisveness / geodesy

Libraries of geodesy functions implemented in JavaScript
http://www.movable-type.co.uk/scripts/geodesy-library.html
MIT License
1.17k stars 203 forks source link

Confused about different LatLon classes, should there be a combined API? #95

Open JulianKingman opened 3 years ago

JulianKingman commented 3 years ago

I'm trying to do multiple calculations, and am finding I want to use more than one LatLon class (ie the ones from 'geodesy/latlon-nvector-ellipsoidal.js' and 'geodesy/latlon-ellipsoidal-vincenty.js'). What's the best way to go about doing this?

import LatLonNVector from 'geodesy/latlon-nvector-ellipsoidal.js';
import LatLonVincenty from 'geodesy/latlon-ellipsoidal-vincenty.js'

// do I have to do this twice?
const point1a = new LatLonNVector(52.205, 0.119);
const point1b = new LatLonVincenty(52.205, 0.119);

const point2a = new LatLonNVector(30, 0.5)
const point2b = new LatLonVincenty(30, 0.5)

// Would this accept a Vincenty point? Why doesn't it just take coordinates?
const delta = point1a.deltaTo(point2a)

// I used the NVector one accidentally, will this work, or fail? Are the LatLon types different, or interchangeable?
const distance = point1b.distanceTo(point2a)

Is there a reason the scripts are organized as they are? It kind of seems like there should just be a set of different functions, instead of different LatLon classes, since they only take coordinates and height anyway...

For example it could be like this:

import {getDistance, getDelta} from 'geodesy/ellipsoidal'

// points are simply coordinates, optional height parameter
const point1 = [52.205, 0.119];
const point2 = [30, 0.5];

// functions operate on points
const distance = getDistance(point1, point2);
const delta = getDelta(point1, point2);