Initial commit

This commit is contained in:
Juho Teperi
2013-05-13 11:43:34 +03:00
commit fbf8fb087a
44 changed files with 2425 additions and 0 deletions

26
app/scripts/libs/math.js Normal file
View File

@@ -0,0 +1,26 @@
'use strict';
define([
'config',
'libs/airports'
], function (cfg, airports) {
var toRad = function toRad(n) {
return n * Math.PI / 180;
};
var haversine = function haversine(from, to) {
var dLat = toRad(to.get('lat') - from.get('lat'));
var dLon = toRad(to.get('long') - from.get('long'));
var lat1 = toRad(from.get('lat'));
var lat2 = toRad(to.get('lat'));
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return cfg.R * c;
};
return {
toRad: toRad,
haversine: haversine
};
});