summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-18 12:12:57 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-19 08:11:41 +0300
commit2188d68b6c09dec676c294223aa7d1a4c24c85f0 (patch)
tree8b2d18726e7e3bc3990536e29a2500a9889fd006 /include
parentf01a829dc9e076abeb7df90259e8e5c7d9cfbad6 (diff)
downloadqtlocation-mapboxgl-2188d68b6c09dec676c294223aa7d1a4c24c85f0.tar.gz
[core] Move TransformState::{un,}project() to Projection
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/projection.hpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp
index 0b6e9f6bf1..4212e5da7a 100644
--- a/include/mbgl/util/projection.hpp
+++ b/include/mbgl/util/projection.hpp
@@ -46,6 +46,22 @@ public:
return LatLng(latitude, longitude);
}
+
+ static Point<double> project(const LatLng& latLng, double scale) {
+ return Point<double> {
+ util::LONGITUDE_MAX + latLng.longitude,
+ util::LONGITUDE_MAX - util::RAD2DEG * std::log(std::tan(M_PI / 4 + latLng.latitude * M_PI / util::DEGREES_MAX))
+ } * worldSize(scale) / util::DEGREES_MAX;
+ }
+
+ static LatLng unproject(const Point<double>& p, double scale, LatLng::WrapMode wrapMode = LatLng::Unwrapped) {
+ auto p2 = p * util::DEGREES_MAX / worldSize(scale);
+ return LatLng {
+ util::DEGREES_MAX / M_PI * std::atan(std::exp((util::LONGITUDE_MAX - p2.y) * util::DEG2RAD)) - 90.0,
+ p2.x - util::LONGITUDE_MAX,
+ wrapMode
+ };
+ }
};
} // namespace mbgl