summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2016-07-14 14:14:57 -0400
committerJason Wray <jason@mapbox.com>2016-07-15 12:20:56 -0400
commit09221ecf1a6f85b73a501b3ae90869dd5a4b033a (patch)
tree991ce6d8a943a0701f5d88a609b82d996ffa7f98 /src
parentd303980e75d85ac88c382cac54c55cc7ee74534e (diff)
downloadqtlocation-mapboxgl-09221ecf1a6f85b73a501b3ae90869dd5a4b033a.tar.gz
[core] Guard against camera's `minScale` being NaN
Fixes a bug where calculating the padded bounds for a single point would cause division by zero, resulting in NaN for `minScale`. This invalid `minScale` would then be used to create an invalid padded `centerPixel`.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index b08d3ef710..24c39fe243 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -503,13 +503,16 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional
double height = nePixel.y - swPixel.y;
// Calculate the zoom level.
- double scaleX = getWidth() / width;
- double scaleY = getHeight() / height;
- if (padding && *padding) {
- scaleX -= (padding->left + padding->right) / width;
- scaleY -= (padding->top + padding->bottom) / height;
+ double minScale = INFINITY;
+ if (width > 0 || height > 0) {
+ double scaleX = getWidth() / width;
+ double scaleY = getHeight() / height;
+ if (padding && *padding) {
+ scaleX -= (padding->left + padding->right) / width;
+ scaleY -= (padding->top + padding->bottom) / height;
+ }
+ minScale = util::min(scaleX, scaleY);
}
- double minScale = ::fmin(scaleX, scaleY);
double zoom = util::log2(getScale() * minScale);
zoom = util::clamp(zoom, getMinZoom(), getMaxZoom());