diff options
author | Ansis Brammanis <brammanis@gmail.com> | 2015-08-26 11:14:08 -0400 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2015-09-11 15:13:45 -0700 |
commit | b05f5c5f7fbb9fa79b068e6a265e3d6c2a77026b (patch) | |
tree | d4477658122404f8eebdf58b43a2feee283fd42a /src/mbgl/map/transform_state.cpp | |
parent | 7971861aa5b0e5941dfdd0d78a54bc3aee9aee77 (diff) | |
download | qtlocation-mapboxgl-b05f5c5f7fbb9fa79b068e6a265e3d6c2a77026b.tar.gz |
increase precision for coordinate conversions
This fixes the earthquakes while panning at high zoom levels.
Cherry-picked from 9607171612c4a40e41eddaff5230ad571571a5b9 on the perspective-improved-gestures branch.
Diffstat (limited to 'src/mbgl/map/transform_state.cpp')
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index c672ca5dea..e37f10dc6d 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -157,21 +157,21 @@ float TransformState::getPitch() const { #pragma mark - Projection -float TransformState::lngX(float lng) const { +double TransformState::lngX(double lng) const { return (180.0f + lng) * worldSize() / 360.0f; } -float TransformState::latY(float lat) const { - float y_ = 180.0f / M_PI * std::log(std::tan(M_PI / 4 + lat * M_PI / 360.0f)); +double TransformState::latY(double lat) const { + double y_ = 180.0f / M_PI * std::log(std::tan(M_PI / 4 + lat * M_PI / 360.0f)); return (180.0f - y_) * worldSize() / 360.0f; } -float TransformState::xLng(float x_, float worldSize_) const { +double TransformState::xLng(double x_, double worldSize_) const { return x_ * 360.0f / worldSize_ - 180.0f; } -float TransformState::yLat(float y_, float worldSize_) const { - float y2 = 180.0f - y_ * 360.0f / worldSize_; +double TransformState::yLat(double y_, double worldSize_) const { + double y2 = 180.0f - y_ * 360.0f / worldSize_; return 360.0f / M_PI * std::atan(std::exp(y2 * M_PI / 180.0f)) - 90.0f; } @@ -245,17 +245,16 @@ TileCoordinate TransformState::pointToCoordinate(const vec2<double> point) const matrix::transformMat4(coord0, point0, inverted); matrix::transformMat4(coord1, point1, inverted); - float w0 = coord0[3]; - float w1 = coord1[3]; - float x0 = coord0[0] / w0; - float x1 = coord1[0] / w1; - float y0 = coord0[1] / w0; - float y1 = coord1[1] / w1; - float z0 = coord0[2] / w0; - float z1 = coord1[2] / w1; + double w0 = coord0[3]; + double w1 = coord1[3]; + double x0 = coord0[0] / w0; + double x1 = coord1[0] / w1; + double y0 = coord0[1] / w0; + double y1 = coord1[1] / w1; + double z0 = coord0[2] / w0; + double z1 = coord1[2] / w1; - - float t = z0 == z1 ? 0 : (targetZ - z0) / (z1 - z0); + double t = z0 == z1 ? 0 : (targetZ - z0) / (z1 - z0); return { util::interpolate(x0, x1, t), util::interpolate(y0, y1, t), tileZoom }; } |