[core] Avoid NaNs in TransformState unit conversions

Fix cases where e.g. state has either zero width or height, causing the
unit convertion functions would return NaNs.
This commit is contained in:
Bruno de Oliveira Abinader
2016-05-19 19:03:41 +03:00
parent b962b56072
commit f751d2c465
3 changed files with 63 additions and 16 deletions

View File

@@ -230,6 +230,10 @@ double TransformState::worldSize() const {
}
ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng) const {
if (width == 0 || height == 0) {
return {};
}
mat4 mat = coordinatePointMatrix(getZoom());
vec4 p;
Point<double> pt = project(latLng) / double(util::tileSize);
@@ -239,6 +243,10 @@ ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng)
}
LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, LatLng::WrapMode wrapMode) const {
if (width == 0 || height == 0) {
return {};
}
float targetZ = 0;
mat4 mat = coordinatePointMatrix(getZoom());