From fa6d4ac0bc39b8aa97ddddfbe600505af447b37e Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Sat, 9 Apr 2016 00:41:26 +0200 Subject: [PATCH] Add faster version of WGS84 -> Web Mercator --- src/util/coordinate_calculation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index 8450d41de..063261d88 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -315,9 +315,9 @@ FloatLatitude yToLat(const double y) double latToY(const FloatLatitude latitude) { - const double normalized_lat = 90. + static_cast(latitude); - - const double y = RAD_TO_DEGREE * std::log(std::tan(normalized_lat * DEGREE_TO_RAD * 0.5)); + // apparently this is the (faster) version of the canonical log(tan()) version + const double f = std::sin(DEGREE_TO_RAD * static_cast(latitude)); + const double y = RAD_TO_DEGREE * 0.5 * std::log((1 + f) / (1 - f)); const auto clamped_y = std::max(-180., std::min(180., y)); return clamped_y; }