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

Commit

Permalink
[core] Check if frameZoom is NaN in Transform::flyTo callback
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Jun 28, 2017
1 parent 433e54e commit 1df45a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
Point<double> framePoint = util::interpolate(startPoint, endPoint, us);
double frameZoom = startZoom + state.scaleZoom(1 / w(s));

// Zoom can be NaN if size is empty.
if (std::isnan(frameZoom)) {
frameZoom = zoom;
}

// Convert to geographic coordinates and set the new viewpoint.
LatLng frameLatLng = Projection::unproject(framePoint, startScale);
state.setLatLngZoom(frameLatLng, frameZoom);
Expand Down
5 changes: 5 additions & 0 deletions test/map/transform.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ TEST(Transform, InvalidZoom) {
cameraOptions.center = LatLng { util::LATITUDE_MAX, util::LONGITUDE_MAX };
cameraOptions.zoom = transform.getState().getMaxZoom();

// Executing flyTo with an empty size causes frameZoom to be NaN.
transform.flyTo(cameraOptions);
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());
ASSERT_DOUBLE_EQ(transform.getZoom(), transform.getState().getMaxZoom());

// Executing flyTo with maximum zoom level to the same zoom level causes
// frameZoom to be bigger than maximum zoom.
transform.resize(Size { 100, 100 });
Expand Down

0 comments on commit 1df45a5

Please sign in to comment.