summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-12 00:50:00 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-13 21:38:20 +0200
commit8e30a4a0806e970e727c3563b8ed57dbaf9a0fa0 (patch)
tree792abd2a0b6d19aac7e60d83cfa4c2d88893b936 /test
parenta396c6a7f082749476f332c976912f37cbd93c92 (diff)
downloadqtlocation-mapboxgl-8e30a4a0806e970e727c3563b8ed57dbaf9a0fa0.tar.gz
[core] Harden Transform anchor & padding usage
Use optional values for anchor & padding in Map and Transform functions instead of NaNs. Added unit tests to stress some edge cases.
Diffstat (limited to 'test')
-rw-r--r--test/map/transform.cpp81
1 files changed, 77 insertions, 4 deletions
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index 4a040e9022..c490ca4894 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -222,17 +222,90 @@ TEST(Transform, Anchor) {
ASSERT_DOUBLE_EQ(10, transform.getZoom());
ASSERT_DOUBLE_EQ(0, transform.getAngle());
+ const ScreenCoordinate invalidAnchorPoint = ScreenCoordinate::null();
+ const ScreenCoordinate anchorPoint = { 150, 150 };
+
+ const LatLng anchorLatLng = transform.getState().screenCoordinateToLatLng(anchorPoint);
+ ASSERT_NE(latLng.latitude, anchorLatLng.latitude);
+ ASSERT_NE(latLng.longitude, anchorLatLng.longitude);
+
+ transform.setLatLngZoom(latLng, 2);
+ transform.scaleBy(1);
+ ASSERT_DOUBLE_EQ(4, transform.getScale());
+ ASSERT_DOUBLE_EQ(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_DOUBLE_EQ(latLng.longitude, transform.getLatLng().longitude);
+
+ transform.scaleBy(1.5, invalidAnchorPoint);
+ ASSERT_DOUBLE_EQ(6, transform.getScale());
+ ASSERT_DOUBLE_EQ(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_DOUBLE_EQ(latLng.longitude, transform.getLatLng().longitude);
+
+ transform.scaleBy(2, anchorPoint);
+ ASSERT_DOUBLE_EQ(12, transform.getScale());
+ ASSERT_NE(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_NE(latLng.longitude, transform.getLatLng().longitude);
+
+ transform.setLatLngZoom(latLng, 10);
+ transform.setScale(2 << 2);
+ ASSERT_DOUBLE_EQ(2 << 2, transform.getScale());
+ ASSERT_NEAR(latLng.latitude, transform.getLatLng().latitude, 0.000001);
+ ASSERT_NEAR(latLng.longitude, transform.getLatLng().longitude, 0.000001);
+
+ transform.setScale(2 << 4, invalidAnchorPoint);
+ ASSERT_DOUBLE_EQ(2 << 4, transform.getScale());
+ ASSERT_NEAR(latLng.latitude, transform.getLatLng().latitude, 0.000001);
+ ASSERT_NEAR(latLng.longitude, transform.getLatLng().longitude, 0.000001);
+
+ transform.setScale(2 << 6, anchorPoint);
+ ASSERT_DOUBLE_EQ(2 << 6, transform.getScale());
+ ASSERT_NE(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_NE(latLng.longitude, transform.getLatLng().longitude);
+
+ transform.setLatLngZoom(latLng, 10);
+ transform.setZoom(2);
+ ASSERT_DOUBLE_EQ(2, transform.getZoom());
+ ASSERT_NEAR(latLng.latitude, transform.getLatLng().latitude, 0.000001);
+ ASSERT_NEAR(latLng.longitude, transform.getLatLng().longitude, 0.000001);
+
+ transform.setZoom(4, invalidAnchorPoint);
+ ASSERT_DOUBLE_EQ(4, transform.getZoom());
+ ASSERT_NEAR(latLng.latitude, transform.getLatLng().latitude, 0.000001);
+ ASSERT_NEAR(latLng.longitude, transform.getLatLng().longitude, 0.000001);
+
+ transform.setZoom(8, anchorPoint);
+ ASSERT_DOUBLE_EQ(8, transform.getZoom());
+ ASSERT_NE(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_NE(latLng.longitude, transform.getLatLng().longitude);
+
+ transform.setLatLngZoom(latLng, 10);
transform.setAngle(M_PI_4);
ASSERT_NEAR(M_PI_4, transform.getAngle(), 0.000001);
ASSERT_DOUBLE_EQ(latLng.latitude, transform.getLatLng().latitude);
ASSERT_DOUBLE_EQ(latLng.longitude, transform.getLatLng().longitude);
- const ScreenCoordinate anchorPoint = { 150, 150 };
- const LatLng anchorLatLng = transform.getState().screenCoordinateToLatLng(anchorPoint);
+ transform.setAngle(0, invalidAnchorPoint);
+ ASSERT_DOUBLE_EQ(0, transform.getAngle());
+ ASSERT_DOUBLE_EQ(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_DOUBLE_EQ(latLng.longitude, transform.getLatLng().longitude);
+
transform.setAngle(-45 * util::DEG2RAD, anchorPoint);
ASSERT_NEAR(-45 / util::RAD2DEG, transform.getAngle(), 0.000001);
- ASSERT_NE(latLng.latitude, transform.getLatLng().latitude);
- ASSERT_NE(latLng.longitude, transform.getLatLng().longitude);
+ ASSERT_NEAR(anchorLatLng.latitude, transform.getLatLng().latitude, 1);
+ ASSERT_NEAR(anchorLatLng.longitude, transform.getLatLng().longitude, 1);
+
+ transform.setLatLngZoom(latLng, 10);
+ transform.setPitch(10 * util::DEG2RAD);
+ ASSERT_DOUBLE_EQ(10 / util::RAD2DEG, transform.getPitch());
+ ASSERT_DOUBLE_EQ(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_DOUBLE_EQ(latLng.longitude, transform.getLatLng().longitude);
+
+ transform.setPitch(15 * util::DEG2RAD, invalidAnchorPoint);
+ ASSERT_DOUBLE_EQ(15 / util::RAD2DEG, transform.getPitch());
+ ASSERT_DOUBLE_EQ(latLng.latitude, transform.getLatLng().latitude);
+ ASSERT_DOUBLE_EQ(latLng.longitude, transform.getLatLng().longitude);
+
+ transform.setPitch(20 * util::DEG2RAD, anchorPoint);
+ ASSERT_DOUBLE_EQ(20 / util::RAD2DEG, transform.getPitch());
ASSERT_NEAR(anchorLatLng.latitude, transform.getLatLng().latitude, 1);
ASSERT_NEAR(anchorLatLng.longitude, transform.getLatLng().longitude, 1);
}