summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-18 11:29:58 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-19 08:11:41 +0300
commitf01a829dc9e076abeb7df90259e8e5c7d9cfbad6 (patch)
treed852d68a4629044c138ad4445c4d7e3c37079af0 /include
parent3a12dd2d4fec398bc84f88cfddc2ac4a37c3a7f1 (diff)
downloadqtlocation-mapboxgl-f01a829dc9e076abeb7df90259e8e5c7d9cfbad6.tar.gz
[core] Move TransformState::worldSize() to Projection
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/projection.hpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp
index eb45088580..0b6e9f6bf1 100644
--- a/include/mbgl/util/projection.hpp
+++ b/include/mbgl/util/projection.hpp
@@ -8,14 +8,20 @@
namespace mbgl {
+// Spherical Mercator projection
+// http://docs.openlayers.org/library/spherical_mercator.html
class Projection {
-
public:
+ // Map pixel width at given scale.
+ static double worldSize(double scale) {
+ return scale * util::tileSize;
+ }
+
static double getMetersPerPixelAtLatitude(double lat, double zoom) {
const double constrainedZoom = util::clamp(zoom, util::MIN_ZOOM, util::MAX_ZOOM);
- const double mapPixelWidthAtZoom = std::pow(2.0, constrainedZoom) * util::tileSize;
+ const double constrainedScale = std::pow(2.0, constrainedZoom);
const double constrainedLatitude = util::clamp(lat, -util::LATITUDE_MAX, util::LATITUDE_MAX);
- return std::cos(constrainedLatitude * util::DEG2RAD) * util::M2PI * util::EARTH_RADIUS_M / mapPixelWidthAtZoom;
+ return std::cos(constrainedLatitude * util::DEG2RAD) * util::M2PI * util::EARTH_RADIUS_M / worldSize(constrainedScale);
}
static ProjectedMeters projectedMetersForLatLng(const LatLng& latLng) {
@@ -32,7 +38,7 @@ public:
}
static LatLng latLngForProjectedMeters(const ProjectedMeters& projectedMeters) {
- double latitude = (2 * std::atan(std::exp(projectedMeters.northing / util::EARTH_RADIUS_M)) - (M_PI / 2)) * util::RAD2DEG;
+ double latitude = (2 * std::atan(std::exp(projectedMeters.northing / util::EARTH_RADIUS_M)) - (M_PI / 2.0)) * util::RAD2DEG;
double longitude = projectedMeters.easting * util::RAD2DEG / util::EARTH_RADIUS_M;
latitude = util::clamp(latitude, -util::LATITUDE_MAX, util::LATITUDE_MAX);