summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-05-19 19:03:41 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-05-20 16:18:07 +0300
commitf751d2c46528ac4301ef3753c468950051937940 (patch)
treede8859aadb87cdcb02a1d828087e53bef19d75b6 /test
parentb962b56072255c818f441a2f0c8fbeb27e7f78bc (diff)
downloadqtlocation-mapboxgl-f751d2c46528ac4301ef3753c468950051937940.tar.gz
[core] Avoid NaNs in TransformState unit conversions
Fix cases where e.g. state has either zero width or height, causing the unit convertion functions would return NaNs.
Diffstat (limited to 'test')
-rw-r--r--test/map/transform.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index 3cf542c4f3..afb655abca 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -474,3 +474,43 @@ TEST(Transform, Camera) {
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());
ASSERT_FALSE(transform.inTransition());
}
+
+TEST(Transform, DefaultTransform) {
+ Transform transform;
+ const TransformState& state = transform.getState();
+
+ LatLng nullIsland, latLng = {};
+ ScreenCoordinate center, point = {};
+ const uint16_t min = std::numeric_limits<uint16_t>::min();
+ const uint16_t max = std::numeric_limits<uint16_t>::max();
+
+ auto testConversions = [&](const LatLng& coord, const ScreenCoordinate& screenCoord) {
+ latLng = state.screenCoordinateToLatLng(center);
+ ASSERT_NEAR(latLng.latitude, coord.latitude, 0.000001);
+ ASSERT_NEAR(latLng.longitude, coord.longitude, 0.000001);
+ point = state.latLngToScreenCoordinate(nullIsland);
+ ASSERT_DOUBLE_EQ(point.x, screenCoord.x);
+ ASSERT_DOUBLE_EQ(point.y, screenCoord.y);
+ };
+
+ testConversions(nullIsland, center);
+
+ // Cannot assign the current size.
+ ASSERT_FALSE(transform.resize({{}}));
+
+ ASSERT_TRUE(transform.resize({{ min, max }}));
+ testConversions(nullIsland, center);
+
+ ASSERT_TRUE(transform.resize({{ max, min }}));
+ testConversions(nullIsland, center);
+
+ ASSERT_TRUE(transform.resize({{ min, min }}));
+ testConversions(nullIsland, center);
+
+ center = { max / 2., max / 2. };
+
+ // -1 evaluates to UINT_MAX.
+ ASSERT_TRUE(transform.resize({{ static_cast<uint16_t>(-1), static_cast<uint16_t>(-1) }}));
+ ASSERT_FALSE(transform.resize({{ max, max }}));
+ testConversions(nullIsland, center);
+}