From f89cfacab2457602c5bd81ab9da35cede23584e2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 4 May 2016 17:37:45 -0700 Subject: [PATCH] [core] Inline LatLng::project definition the one place it's used --- include/mbgl/util/geo.hpp | 2 -- src/mbgl/annotation/point_annotation_impl.cpp | 11 ++++++++++- src/mbgl/util/geo.cpp | 12 ------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index f0c708dcd..cb9cb71fc 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -48,8 +48,6 @@ public: // Constructs a LatLng object with the top left position of the specified tile. LatLng(const TileID& id); - - ScreenCoordinate project() const; }; inline bool operator==(const LatLng& a, const LatLng& b) { diff --git a/src/mbgl/annotation/point_annotation_impl.cpp b/src/mbgl/annotation/point_annotation_impl.cpp index e073394f7..d3f0bce0a 100644 --- a/src/mbgl/annotation/point_annotation_impl.cpp +++ b/src/mbgl/annotation/point_annotation_impl.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace mbgl { @@ -12,7 +13,15 @@ void PointAnnotationImpl::updateLayer(const TileID& tileID, AnnotationTileLayer& std::unordered_map featureProperties; featureProperties.emplace("sprite", point.icon.empty() ? std::string("default_marker") : point.icon); - mbgl::ScreenCoordinate projected = point.position.project(); + // Clamp to the latitude limits of Web Mercator. + const double constrainedLatitude = util::clamp(point.position.latitude, -util::LATITUDE_MAX, util::LATITUDE_MAX); + + // Project a coordinate into unit space in a square map. + const double sine = std::sin(constrainedLatitude * util::DEG2RAD); + const double x = point.position.longitude / util::DEGREES_MAX + 0.5; + const double y = 0.5 - 0.25 * std::log((1.0 + sine) / (1.0 - sine)) / M_PI; + + vec2 projected(x, y); projected *= std::pow(2, tileID.z); projected.x = std::fmod(projected.x, 1); projected.y = std::fmod(projected.y, 1); diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp index 2cb5d0980..eb697f0b0 100644 --- a/src/mbgl/util/geo.cpp +++ b/src/mbgl/util/geo.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -13,17 +12,6 @@ LatLng::LatLng(const TileID& id) { latitude = util::RAD2DEG * std::atan(0.5 * (std::exp(n) - std::exp(-n))); } -ScreenCoordinate LatLng::project() const { - // Clamp to the latitude limits of Web Mercator. - const double constrainedLatitude = util::clamp(latitude, -util::LATITUDE_MAX, util::LATITUDE_MAX); - - // Project a coordinate into unit space in a square map. - const double sine = std::sin(constrainedLatitude * util::DEG2RAD); - const double x = longitude / util::DEGREES_MAX + 0.5; - const double y = 0.5 - 0.25 * std::log((1.0 + sine) / (1.0 - sine)) / M_PI; - return { x, y }; -} - LatLngBounds::LatLngBounds(const TileID& id) : sw(TileID{ id.z, id.x, id.y + 1, id.sourceZ }), ne(TileID{ id.z, id.x + 1, id.y, id.sourceZ }) {