Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Increased precision of coordinate conversion methods
Browse files Browse the repository at this point in the history
Fixes #2230.
  • Loading branch information
1ec5 authored and incanus committed Sep 11, 2015
1 parent 26a5d12 commit f8ed28c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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,
Expand All @@ -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;
}
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/map/transform_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f8ed28c

Please sign in to comment.