Created
January 4, 2018 20:23
-
-
Save wallw-teal/0c0aab1776646faf8fc89968764f6e90 to your computer and use it in GitHub Desktop.
Demonstrate geomagjs issue in Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script src="http://cmweiss.github.io/geomagjs/cof2Obj.js"></script> | |
<script src="http://cmweiss.github.io/geomagjs/geomag.js"></script> | |
<pre id="results"></pre> | |
<script> | |
// ********** Helper Stuff; Ignore ********* | |
function x2str(x) { | |
return x.toString(); | |
} | |
function log() { | |
var msg = Array.prototype.map.call(arguments, x2str).join(' '); | |
msg = msg.replace(/\n/g, '<br/>'); | |
var el = document.getElementById('results'); | |
el.innerHTML += msg + '<br/>'; | |
console.log(msg); | |
if (window.dump) { | |
dump(msg); | |
} | |
} | |
// ********** Here's the test ********* | |
var date = new Date(1488386496470); | |
var precision = 1E-8 | |
log('date', date.toISOString()); | |
var sets = [{ | |
coord: [5, 10], | |
bearing: 42.99295488826924, | |
expected: 44.22244309187904 | |
}, { | |
coord: [5, 10], | |
bearing: 44.14439180550811, | |
expected: 45.37388000911791 | |
}, { | |
coord: [-50, 80], | |
bearing: 72.03828683714403, | |
expected: 112.16177561564162 | |
}, { | |
coord: [-50, 80], | |
bearing: 149.74888585793278, | |
expected: 189.87237463643038 | |
}]; | |
var error = false; | |
fetch('http://cmweiss.github.io/geomagjs/WMM.COF', { | |
method: 'get' | |
}).then(function(response) { | |
return response.text(); | |
}).then(function(cof) { | |
var wmm = cof2Obj(cof); | |
var gm = geoMagFactory(wmm); | |
var error = false; | |
sets.forEach((item) => { | |
var result = item.bearing - gm(item.coord[1], item.coord[0], 0, date).dec; | |
result = result < 0 ? result + 360 : result; | |
if (Math.abs(result - item.expected) > precision) { | |
log('whoops: ', result, ' was expected as ', item.expected); | |
error = true; | |
} | |
}); | |
if (!error) { | |
log('Test passed!'); | |
} | |
}).catch(function(err) { | |
log('There was an error accessing or loading something. Check the dev console.'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment