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

What does the TODO comment about wrapping the latitude -315° mean? #87

Closed dzfranklin closed 3 years ago

dzfranklin commented 4 years ago

In dms.js:320 there is the line

return Math.abs((degrees%360 + 270)%360 - 180) - 90; // triangle wave p:360 a:±90 TODO: fix e.g. -315°

I don't understand what the comment means, or what implications this has.

chrisveness commented 3 years ago

I've been meaning to fix this for a long time!

I struggled originally to get the wrap90() and wrap180() functions to work correctly for all inputs of negative degrees (< -270°); spending a bit more time on it, I've worked out that this was because the JavaScript '%' operator is a 'rem' operator rather than a 'mod' operator, which handles negative dividends differently; I've also worked out the full forms of the triangle/sawtooth wave functions and based the code more closely on those so that the operation is clearer.

wrap90() and wrap180() now work correctly for all inputs.