diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-09-10 13:39:47 -0700 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2015-09-11 15:31:02 -0700 |
commit | f8ed28cca0ba160d658958f7b0f8a3312fa62d23 (patch) | |
tree | 8a022d228a9e0f2e2a53e93e518c8182f35709ea | |
parent | 26a5d128b46febc1ca2ed41e468c59c66d90af1d (diff) | |
download | qtlocation-mapboxgl-f8ed28cca0ba160d658958f7b0f8a3312fa62d23.tar.gz |
Increased precision of coordinate conversion methods
Fixes #2230.
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 4 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index e37f10dc6d..ac3988dc56 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<double> 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<double> TransformState::coordinateToPoint(const TileCoordinate& coord) cons TileCoordinate TransformState::pointToCoordinate(const vec2<double> 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<double> 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 c3e1072c98..6fcd35ffae 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -83,10 +83,10 @@ private: 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: |