summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryanhamley <ryan.hamley@mapbox.com>2018-10-11 15:35:10 -0700
committerryanhamley <ryan.hamley@mapbox.com>2018-10-11 15:35:10 -0700
commite9190fc59e84801bc80f6890597ab40ce93652aa (patch)
treed49ba8b053a42089afd70653f23a846a9c879d56
parent391331f3c554d18d0ef48fcfc7a89f5b5f51621b (diff)
downloadqtlocation-mapboxgl-upstream/bounds-tests.tar.gz
-rw-r--r--test/map/transform.test.cpp14
-rw-r--r--test/util/geo.test.cpp33
2 files changed, 37 insertions, 10 deletions
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp
index 0aa87afe52..3513050d0d 100644
--- a/test/map/transform.test.cpp
+++ b/test/map/transform.test.cpp
@@ -554,7 +554,6 @@ TEST(Transform, DefaultTransform) {
TEST(Transform, LatLngBounds) {
const LatLng nullIsland {};
const LatLng sanFrancisco { 37.7749, -122.4194 };
- const LatLng wrappedSanFrancisco { 37.7749, 237.5806};
Transform transform;
transform.resize({ 1000, 1000 });
@@ -580,10 +579,15 @@ TEST(Transform, LatLngBounds) {
ASSERT_EQ(transform.getLatLng(), sanFrancisco);
transform.setLatLngBounds(LatLngBounds::hull({ -90.0, -180.0 }, { 0.0, 180.0 }));
- // ensure a wrapped coordinate works
- transform.setLatLng(wrappedSanFrancisco);
- ASSERT_EQ(transform.getLatLng().latitude(), 0.0);
- ASSERT_EQ(transform.getLatLng().longitude(), sanFrancisco.longitude());
+ // test that we can limit the bounds vertically while allowing unlimited horizontal scrolling
+ transform.setLatLng(LatLng {45, -180});
+ ASSERT_EQ(transform.getLatLng().latitude(), 0);
+ ASSERT_EQ(transform.getLatLng().longitude(), -180);
+
+ transform.setLatLngBounds(LatLngBounds::hull({ -90.0, -180.0 }, { 0.0, 179.0 }));
+ transform.setLatLng(LatLng {45, 179.5});
+ ASSERT_EQ(transform.getLatLng().latitude(), 0);
+ ASSERT_EQ(transform.getLatLng().longitude(), 179);
transform.setLatLng(sanFrancisco);
ASSERT_EQ(transform.getLatLng().latitude(), 0.0);
diff --git a/test/util/geo.test.cpp b/test/util/geo.test.cpp
index f1fe3a755d..23c2a1ea13 100644
--- a/test/util/geo.test.cpp
+++ b/test/util/geo.test.cpp
@@ -187,31 +187,54 @@ TEST(LatLng, Boundaries) {
ASSERT_DOUBLE_EQ(0.5, coordinate.longitude());
}
-TEST(LatLngBounds, Antimeridian) {
- // Bounding box less than 180° that does not cross antimeridian
- //southwest northeast
+TEST(LatLngBounds, CoordinateWrapping) {
+ // Bounding box less than 180° from west to east that does not cross antimeridian
auto boundsNormalLT = LatLngBounds::hull({-90.0, -20.0},{90.0, 20.0});
ASSERT_DOUBLE_EQ(-20, boundsNormalLT.west());
+ // test that the bounds contains the wrapped bounding coordinates
+ EXPECT_FALSE(boundsNormalLT.contains(LatLng{-90.0, 340.0}));
+ EXPECT_TRUE(boundsNormalLT.contains(LatLng{-90.0, 340.0}, LatLng::Wrapped));
ASSERT_DOUBLE_EQ(20, boundsNormalLT.east());
+ EXPECT_FALSE(boundsNormalLT.contains(LatLng{90.0, 380.0}));
+ EXPECT_TRUE(boundsNormalLT.contains(LatLng{90.0, 380.0}, LatLng::Wrapped));
// Bounding box greater than 180° that does not cross antimeridian
auto boundsNormalGT = LatLngBounds::hull({-90.0, -100.0},{90.0, 100.0});
ASSERT_DOUBLE_EQ(-100, boundsNormalGT.west());
+ EXPECT_FALSE(boundsNormalGT.contains(LatLng{-90.0, 260.0}));
+ EXPECT_TRUE(boundsNormalGT.contains(LatLng{-90.0, 260.0}, LatLng::Wrapped));
ASSERT_DOUBLE_EQ(100, boundsNormalGT.east());
+ EXPECT_FALSE(boundsNormalGT.contains(LatLng{90.0, 460.0}));
+ EXPECT_TRUE(boundsNormalGT.contains(LatLng{90.0, 460.0}, LatLng::Wrapped));
// Bounding box less than 180° that crosses the antimeridian
- auto boundsAntimeridianLT = LatLngBounds::hull({-90.0, -200.0},{90.0, 160.0});
+ auto boundsAntimeridianLT = LatLngBounds::hull({-90.0, -200.0},{90.0, -160.0});
+
+ // test that bounding box spans antimeridian
+ EXPECT_FALSE(boundsAntimeridianLT.contains(LatLng{0, 0}));
+ EXPECT_TRUE(boundsAntimeridianLT.contains(LatLng{0, -180}));
ASSERT_DOUBLE_EQ(-200, boundsAntimeridianLT.west());
- ASSERT_DOUBLE_EQ(160, boundsAntimeridianLT.east());
+ EXPECT_FALSE(boundsAntimeridianLT.contains(LatLng{-90.0, 160.0}));
+ EXPECT_TRUE(boundsAntimeridianLT.contains(LatLng{-90.0, 160.0}, LatLng::Wrapped));
+ ASSERT_DOUBLE_EQ(-160, boundsAntimeridianLT.east());
+ EXPECT_FALSE(boundsAntimeridianLT.contains(LatLng{90.0, 200.0}));
+ EXPECT_TRUE(boundsAntimeridianLT.contains(LatLng{90.0, 200.0}, LatLng::Wrapped));
// Bounding box greater than 180° that crosses the antimeridian
auto boundsAntimeridianGT = LatLngBounds::hull({-90.0, -270.0},{90.0, 0.0});
+ EXPECT_FALSE(boundsAntimeridianLT.contains(LatLng{0, -300}));
+ EXPECT_TRUE(boundsAntimeridianLT.contains(LatLng{0, -180}));
+
ASSERT_DOUBLE_EQ(-270, boundsAntimeridianGT.west());
+ EXPECT_FALSE(boundsAntimeridianGT.contains(LatLng{-90.0, 90.0}));
+ EXPECT_TRUE(boundsAntimeridianGT.contains(LatLng{-90.0, 90.0}, LatLng::Wrapped));
ASSERT_DOUBLE_EQ(0, boundsAntimeridianGT.east());
+ EXPECT_FALSE(boundsAntimeridianGT.contains(LatLng{90.0, 360.0}));
+ EXPECT_TRUE(boundsAntimeridianGT.contains(LatLng{90.0, 360.0}, LatLng::Wrapped));
}
TEST(LatLngBounds, FromTileID) {