diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-03-08 23:45:57 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-03-10 03:36:46 +0200 |
commit | b33b2f1515060d0c447fdf09f52935db1c076430 (patch) | |
tree | 4f50560f9732156180f1ce37583305cd0ea057ef /test | |
parent | e8d1276bb10159423fb6b0b07cd02d5cced96f05 (diff) | |
download | qtlocation-mapboxgl-b33b2f1515060d0c447fdf09f52935db1c076430.tar.gz |
[core] Check for NaNs in EdgeInsets
Diffstat (limited to 'test')
-rw-r--r-- | test/map/transform.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/test/map/transform.cpp b/test/map/transform.cpp index 4412b78b04..ada20c5872 100644 --- a/test/map/transform.cpp +++ b/test/map/transform.cpp @@ -182,7 +182,7 @@ TEST(Transform, ConstrainHeightOnly) { transform.setLatLng(LatLngBounds::world().southwest()); loc = transform.getLatLng(); ASSERT_NEAR(-util::LATITUDE_MAX, loc.latitude, 0.001); - ASSERT_NEAR(-util::LONGITUDE_MAX, loc.longitude, 0.001); + ASSERT_NEAR(util::LONGITUDE_MAX, std::abs(loc.longitude), 0.001); transform.setLatLng(LatLngBounds::world().northeast()); loc = transform.getLatLng(); @@ -253,8 +253,14 @@ TEST(Transform, Padding) { }); EdgeInsets padding; + + padding.top = 0; + ASSERT_FALSE(bool(padding)); + + padding.top = NAN; + ASSERT_FALSE(bool(padding)); + padding.top = 1000.0 / 2.0; - ASSERT_GT(padding.top, 0); ASSERT_TRUE(bool(padding)); const LatLng shiftedCenter = transform.getLatLng(padding); @@ -263,3 +269,31 @@ TEST(Transform, Padding) { ASSERT_DOUBLE_EQ(manualShiftedCenter.latitude, shiftedCenter.latitude); ASSERT_DOUBLE_EQ(manualShiftedCenter.longitude, shiftedCenter.longitude); } + +TEST(Transform, MoveBy) { + MockView view; + Transform transform(view, ConstrainMode::HeightOnly); + transform.resize({{ 1000, 1000 }}); + transform.setLatLngZoom({ 0, 0 }, 10); + + LatLng trueCenter = transform.getLatLng(); + ASSERT_DOUBLE_EQ(0, trueCenter.latitude); + ASSERT_DOUBLE_EQ(0, trueCenter.longitude); + ASSERT_DOUBLE_EQ(10, transform.getZoom()); + + for (uint8_t x = 0; x < 20; ++x) { + bool odd = x % 2; + bool forward = x % 10; + + LatLng coordinate = transform.screenCoordinateToLatLng({ odd ? 400. : 600., forward ? 400. : 600 }); + transform.moveBy({ odd ? 100. : -100., forward ? 100. : -100 }); + + trueCenter = transform.getLatLng(); + ASSERT_NEAR(coordinate.latitude, trueCenter.latitude, 0.0001); + ASSERT_NEAR(coordinate.longitude, trueCenter.longitude, 0.0001); + } + + // We have ~1.1 precision loss for each coordinate for 20 rounds of moveBy. + ASSERT_NEAR(0, trueCenter.latitude, 1.1); + ASSERT_NEAR(0, trueCenter.longitude, 1.1); +} |