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.
This commit is contained in:
Ansis Brammanis
2015-08-26 11:14:08 -04:00
committed by Justin R. Miller
parent 7782802f37
commit b4b56c951e
5 changed files with 27 additions and 28 deletions

View File

@@ -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 };
}

View File

@@ -79,10 +79,10 @@ private:
// logical dimensions
uint16_t width = 0, height = 0;
float xLng(float x, float worldSize) const;
float yLat(float y, float worldSize) const;
float lngX(float lon) const;
float latY(float lat) const;
double xLng(double x, double worldSize) const;
double yLat(double y, double worldSize) const;
double lngX(double lon) const;
double latY(double lat) const;
float zoomScale(float zoom) const;
float worldSize() const;