diff options
-rw-r--r-- | include/mbgl/util/constants.hpp | 1 | ||||
-rw-r--r-- | include/mbgl/util/geo.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/constants.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/util/geo.cpp | 4 |
7 files changed, 16 insertions, 14 deletions
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index 27a92181d2..5bfb252bce 100644 --- a/include/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -20,6 +20,7 @@ extern const double M2PI; extern const double EARTH_RADIUS_M; extern const double LATITUDE_MAX; extern const double LONGITUDE_MAX; +extern const double DEGREES_MAX; extern const double PITCH_MAX; extern const double MIN_ZOOM; extern const double MAX_ZOOM; diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 5636cd0bdf..755abeda21 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -33,7 +33,7 @@ public: coordinate so that interpolating between the two endpoints will cross it. */ void unwrapForShortestPath(const LatLng& start) { if (std::abs(start.longitude) + std::abs(longitude) > util::LONGITUDE_MAX) { - longitude += (start.longitude > 0 && longitude < 0) ? 360 : -360; + longitude += (start.longitude > 0 && longitude < 0) ? util::DEGREES_MAX : -util::DEGREES_MAX; } } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 060c169d6d..74e43a62fe 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -122,7 +122,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim Duration duration = animation.duration ? *animation.duration : Duration::zero(); const double startWorldSize = state.worldSize(); - state.Bc = startWorldSize / 360; + state.Bc = startWorldSize / util::DEGREES_MAX; state.Cc = startWorldSize / util::M2PI; const double startScale = state.scale; @@ -290,7 +290,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima } const double startWorldSize = state.worldSize(); - state.Bc = startWorldSize / 360; + state.Bc = startWorldSize / util::DEGREES_MAX; state.Cc = startWorldSize / util::M2PI; state.panning = true; diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index b7671058e7..b9d30cf8bb 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -218,21 +218,21 @@ bool TransformState::isGestureInProgress() const { #pragma mark - Projection double TransformState::lngX(double lng) const { - return (util::LONGITUDE_MAX + lng) * worldSize() / 360.0f; + return (util::LONGITUDE_MAX + lng) * worldSize() / util::DEGREES_MAX; } double TransformState::latY(double lat) const { - double y_ = util::RAD2DEG * std::log(std::tan(M_PI / 4 + lat * M_PI / 360.0f)); - return (util::LONGITUDE_MAX - y_) * worldSize() / 360.0f; + double y_ = util::RAD2DEG * std::log(std::tan(M_PI / 4 + lat * M_PI / util::DEGREES_MAX)); + return (util::LONGITUDE_MAX - y_) * worldSize() / util::DEGREES_MAX; } double TransformState::xLng(double x_, double worldSize_) const { - return x_ * 360.0f / worldSize_ - util::LONGITUDE_MAX; + return x_ * util::DEGREES_MAX / worldSize_ - util::LONGITUDE_MAX; } double TransformState::yLat(double y_, double worldSize_) const { - double y2 = util::LONGITUDE_MAX - y_ * 360.0f / worldSize_; - return 360.0f / M_PI * std::atan(std::exp(y2 * util::DEG2RAD)) - 90.0f; + double y2 = util::LONGITUDE_MAX - y_ * util::DEGREES_MAX / worldSize_; + return util::DEGREES_MAX / M_PI * std::atan(std::exp(y2 * util::DEG2RAD)) - 90.0f; } double TransformState::zoomScale(double zoom) const { @@ -357,7 +357,7 @@ void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& an void TransformState::setLatLngZoom(const LatLng &latLng, double zoom) { double newScale = zoomScale(zoom); const double newWorldSize = newScale * util::tileSize; - Bc = newWorldSize / 360; + Bc = newWorldSize / util::DEGREES_MAX; Cc = newWorldSize / util::M2PI; const double m = 1 - 1e-15; @@ -378,7 +378,7 @@ void TransformState::setScalePoint(const double newScale, const ScreenCoordinate scale = constrainedScale; x = constrainedPoint.x; y = constrainedPoint.y; - Bc = worldSize() / 360; + Bc = worldSize() / util::DEGREES_MAX; Cc = worldSize() / util::M2PI; } diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index e122fd8ac1..4c8c9f37b5 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -115,7 +115,7 @@ private: double pitch = 0.0; // cache values for spherical mercator math - double Bc = (scale * util::tileSize) / 360; + double Bc = (scale * util::tileSize) / util::DEGREES_MAX; double Cc = (scale * util::tileSize) / util::M2PI; }; diff --git a/src/mbgl/util/constants.cpp b/src/mbgl/util/constants.cpp index ead115532f..7ff00800ae 100644 --- a/src/mbgl/util/constants.cpp +++ b/src/mbgl/util/constants.cpp @@ -26,6 +26,7 @@ const double M2PI = 2 * M_PI; const double EARTH_RADIUS_M = 6378137; const double LATITUDE_MAX = 85.051128779806604; const double LONGITUDE_MAX = 180; +const double DEGREES_MAX = 360; const double PITCH_MAX = M_PI / 3; const double MIN_ZOOM = 0.0; const double MAX_ZOOM = 25.5; diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp index f08dca7272..bf7cf38117 100644 --- a/src/mbgl/util/geo.cpp +++ b/src/mbgl/util/geo.cpp @@ -7,7 +7,7 @@ namespace mbgl { LatLng::LatLng(const TileID& id) { - longitude = id.x / std::pow(2.0, id.z) * 360.0 - util::LONGITUDE_MAX; + longitude = id.x / std::pow(2.0, id.z) * util::DEGREES_MAX - util::LONGITUDE_MAX; const double n = M_PI - 2.0 * M_PI * id.y / std::pow(2.0, id.z); latitude = util::RAD2DEG * std::atan(0.5 * (std::exp(n) - std::exp(-n))); } @@ -18,7 +18,7 @@ ScreenCoordinate LatLng::project() const { // Project a coordinate into unit space in a square map. const double sine = std::sin(constrainedLatitude * util::DEG2RAD); - const double x = longitude / 360.0 + 0.5; + 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 }; } |