diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index 5a8d495bacb..fc05cceb760 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -121,7 +121,7 @@ double TransformState::getZoom() const { } int32_t TransformState::getIntegerZoom() const { - return std::floor(getZoom()); + return getZoom(); } double TransformState::getZoomFraction() const { diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index 5c720d3f783..0cd92bfc2fe 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -103,6 +103,29 @@ TEST(Transform, InvalidBearing) { ASSERT_DOUBLE_EQ(2, transform.getAngle()); } +TEST(Transform, IntegerZoom) { + Transform transform; + + auto checkIntegerZoom = [&transform](uint8_t zoomInt, double zoom) { + double scale = transform.getState().zoomScale(zoom); + transform.setScale(scale); + ASSERT_DOUBLE_EQ(transform.getScale(), scale); + ASSERT_NEAR(transform.getZoom(), zoom, 0.0001); + ASSERT_EQ(transform.getState().getIntegerZoom(), zoomInt); + ASSERT_NEAR(transform.getState().getZoomFraction(), zoom - zoomInt, 0.0001); + }; + + for (uint8_t zoomInt = 0; zoomInt < 20; ++zoomInt) { + for (uint32_t percent = 0; percent < 100; ++percent) { + double zoom = zoomInt + (0.01 * percent); + checkIntegerZoom(zoomInt, zoom); + } + } + + // Special case zoom 20. + checkIntegerZoom(20, 20.0); +} + TEST(Transform, PerspectiveProjection) { LatLng loc;