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

Commit

Permalink
[core] Cleanup TransformState::getIntegerZoom
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Oct 31, 2016
1 parent 384f1a1 commit 7b3e24d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ double TransformState::getZoom() const {
}

int32_t TransformState::getIntegerZoom() const {
return std::floor(getZoom());
return getZoom();
}

double TransformState::getZoomFraction() const {
Expand Down
23 changes: 23 additions & 0 deletions test/map/transform.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 7b3e24d

Please sign in to comment.