added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
@@ -0,0 +1,38 @@
var RADIUS = 6371;
var toRad = function(n) {
return n * Math.PI / 180;
};
var getDistance = function(from, to) {
var fromLat = from[0];
var fromLon = from[1];
var toLat = to[0];
var toLon = to[1];
var dLat = toRad(toLat - fromLat);
var dLon = toRad(toLon - fromLon);
var fromLat = toRad(fromLat);
var toLat = toRad(toLat);
var a = Math.pow(Math.sin(dLat / 2), 2) +
(Math.pow(Math.sin(dLon / 2), 2) * Math.cos(fromLat) * Math.cos(toLat));
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return RADIUS * c;
};
var measurePath = function(points) {
return points.reduce(function(memo, point) {
var distance = memo.lastPoint === null ? 0 : getDistance(memo.lastPoint, point);
return { lastPoint: point, distance: distance + memo.distance };
}, { lastPoint: null, distance: 0 }).distance;
};
module.exports = function(fromLat, fromLon, toLat, toLon) {
if(typeof fromLat === 'number'){
return getDistance([fromLat, fromLon], [toLat, toLon]);
} else {
return measurePath(fromLat);
}
};