mapbox / cheap-ruler

Fast approximations for common geodesic measurements 🌐
https://www.mapbox.com/blog/cheap-ruler/
ISC License
418 stars 32 forks source link

refactoring index.js #28

Closed kkdd closed 7 years ago

kkdd commented 7 years ago

Hello, I would propose refactoring CheapRuler(coslat, units) where coslat = Math.cos(lat * Math.PI / 180)

mourner commented 7 years ago

Can you describe the purpose of this refactoring?

kkdd commented 7 years ago

In this request, cos(lat), which is required in CheapRuler(), would be precedently calculated in cheapRuler() or fromTile(). The path from "fromTile()" to "CheapRuler()" would consequently require less non-elementary functions than present.

mourner commented 7 years ago

I see now. Thanks for the PR! However I think that introducing this optimization reduces the clarity of the code for a very small benefit (since fromTile isn't expected to be called often anyway). So I'd prefer to leave it as is.