diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index e37f10dc6d4..ac3988dc56c 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -175,7 +175,7 @@ double TransformState::yLat(double y_, double worldSize_) const { return 360.0f / M_PI * std::atan(std::exp(y2 * M_PI / 180.0f)) - 90.0f; } -float TransformState::zoomScale(float zoom) const { +double TransformState::zoomScale(double zoom) const { return std::pow(2.0f, zoom); } @@ -192,8 +192,8 @@ LatLng TransformState::pointToLatLng(const vec2 point) const { } TileCoordinate TransformState::latLngToCoordinate(const LatLng& latLng) const { - const float tileZoom = getIntegerZoom(); - const float k = zoomScale(tileZoom) / worldSize(); + const double tileZoom = getZoom(); + const double k = zoomScale(tileZoom) / worldSize(); return { lngX(latLng.longitude) * k, latY(latLng.latitude) * k, @@ -202,12 +202,12 @@ TileCoordinate TransformState::latLngToCoordinate(const LatLng& latLng) const { } LatLng TransformState::coordinateToLatLng(const TileCoordinate& coord) const { - const float worldSize_ = zoomScale(coord.zoom); + const double worldSize_ = zoomScale(coord.zoom); LatLng latLng = { yLat(coord.row, worldSize_), xLng(coord.column, worldSize_) }; - while (latLng.longitude < 180.0f) latLng.longitude += 360.0f; + while (latLng.longitude < -180.0f) latLng.longitude += 360.0f; while (latLng.longitude > 180.0f) latLng.longitude -= 360.0f; return latLng; } @@ -223,7 +223,7 @@ vec2 TransformState::coordinateToPoint(const TileCoordinate& coord) cons TileCoordinate TransformState::pointToCoordinate(const vec2 point) const { float targetZ = 0; - const float tileZoom = getIntegerZoom(); + const double tileZoom = getZoom(); mat4 mat = coordinatePointMatrix(tileZoom); @@ -259,11 +259,11 @@ TileCoordinate TransformState::pointToCoordinate(const vec2 point) const return { util::interpolate(x0, x1, t), util::interpolate(y0, y1, t), tileZoom }; } -mat4 TransformState::coordinatePointMatrix(float z) const { +mat4 TransformState::coordinatePointMatrix(double z) const { mat4 proj; getProjMatrix(proj); float s = util::tileSize * scale / std::pow(2, z); - matrix::scale(proj, proj, s , s, 1); + matrix::scale(proj, proj, s, s, 1); matrix::multiply(proj, getPixelMatrix(), proj); return proj; } diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index c3e1072c98e..6fcd35ffae0 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -83,10 +83,10 @@ class TransformState { double yLat(double y, double worldSize) const; double lngX(double lon) const; double latY(double lat) const; - float zoomScale(float zoom) const; + double zoomScale(double zoom) const; float worldSize() const; - mat4 coordinatePointMatrix(float z) const; + mat4 coordinatePointMatrix(double z) const; mat4 getPixelMatrix() const; private: