diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-02 15:04:21 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-02 23:04:18 -0800 |
commit | 37c27f3a8f55ae74d7da9b5f45fa577de3af7f21 (patch) | |
tree | 88d479ad1d4a3559844c3fd8c82ab4a33c4bc55b /test | |
parent | 032c8fba3c8e3c122dd399b5c9341d92ad9d286f (diff) | |
download | qtlocation-mapboxgl-37c27f3a8f55ae74d7da9b5f45fa577de3af7f21.tar.gz |
[core] Improve LatLngBounds API
* Use "named constructors": empty, world, hull
* Make the two-argument constructor lenient (i.e., it is a hull operation)
* Add various accessors
* Enforce a single empty representation
Diffstat (limited to 'test')
-rw-r--r-- | test/map/transform.cpp | 10 | ||||
-rw-r--r-- | test/util/geo.cpp | 116 |
2 files changed, 101 insertions, 25 deletions
diff --git a/test/map/transform.cpp b/test/map/transform.cpp index 4a8b685564..8325e60ebf 100644 --- a/test/map/transform.cpp +++ b/test/map/transform.cpp @@ -142,18 +142,17 @@ TEST(Transform, PerspectiveProjection) { TEST(Transform, ConstrainHeightOnly) { MockView view; LatLng loc; - LatLngBounds bounds; Transform transform(view, ConstrainMode::HeightOnly); transform.resize({{ 1000, 1000 }}); transform.setScale(1024); - transform.setLatLng(bounds.sw); + transform.setLatLng(LatLngBounds::world().southwest()); loc = transform.getState().pointToLatLng({ 500, 500 }); ASSERT_NEAR(-85.021422866378714, loc.latitude, 0.0001); ASSERT_NEAR(180, std::abs(loc.longitude), 0.0001); - transform.setLatLng(bounds.ne); + transform.setLatLng(LatLngBounds::world().northeast()); loc = transform.getState().pointToLatLng({ 500, 500 }); ASSERT_NEAR(85.021422866378742, loc.latitude, 0.0001); ASSERT_NEAR(180, std::abs(loc.longitude), 0.0001); @@ -162,18 +161,17 @@ TEST(Transform, ConstrainHeightOnly) { TEST(Transform, ConstrainWidthAndHeight) { MockView view; LatLng loc; - LatLngBounds bounds; Transform transform(view, ConstrainMode::WidthAndHeight); transform.resize({{ 1000, 1000 }}); transform.setScale(1024); - transform.setLatLng(bounds.sw); + transform.setLatLng(LatLngBounds::world().southwest()); loc = transform.getState().pointToLatLng({ 500, 500 }); ASSERT_NEAR(-85.021422866378714, loc.latitude, 0.0001); ASSERT_NEAR(-179.65667724609375, loc.longitude, 0.0001); - transform.setLatLng(bounds.ne); + transform.setLatLng(LatLngBounds::world().northeast()); loc = transform.getState().pointToLatLng({ 500, 500 }); ASSERT_NEAR(85.021422866378742, loc.latitude, 0.0001); ASSERT_NEAR(179.65667724609358, std::abs(loc.longitude), 0.0001); diff --git a/test/util/geo.cpp b/test/util/geo.cpp index 88f8bc496b..96335c5dba 100644 --- a/test/util/geo.cpp +++ b/test/util/geo.cpp @@ -5,7 +5,86 @@ using namespace mbgl; -TEST(Geo, LatLngFromTileID) { +TEST(LatLngBounds, World) { + auto result = LatLngBounds::world(); + ASSERT_DOUBLE_EQ(-90, result.south()); + ASSERT_DOUBLE_EQ( 90, result.north()); + ASSERT_DOUBLE_EQ(-180, result.west()); + ASSERT_DOUBLE_EQ( 180, result.east()); +} + +TEST(LatLngBounds, Singleton) { + auto result = LatLngBounds::singleton({1, 2}); + ASSERT_DOUBLE_EQ(1, result.south()); + ASSERT_DOUBLE_EQ(1, result.north()); + ASSERT_DOUBLE_EQ(2, result.west()); + ASSERT_DOUBLE_EQ(2, result.east()); +} + +TEST(LatLngBounds, Hull) { + double s = 1, w = 2, n = 3, e = 4; + + auto swne = LatLngBounds::hull({s, w}, {n, e}); + ASSERT_DOUBLE_EQ(s, swne.south()); + ASSERT_DOUBLE_EQ(n, swne.north()); + ASSERT_DOUBLE_EQ(w, swne.west()); + ASSERT_DOUBLE_EQ(e, swne.east()); + + auto nesw = LatLngBounds::hull({n, e}, {s, w}); + ASSERT_DOUBLE_EQ(s, nesw.south()); + ASSERT_DOUBLE_EQ(n, nesw.north()); + ASSERT_DOUBLE_EQ(w, nesw.west()); + ASSERT_DOUBLE_EQ(e, nesw.east()); + + auto senw = LatLngBounds::hull({s, e}, {n, w}); + ASSERT_DOUBLE_EQ(s, senw.south()); + ASSERT_DOUBLE_EQ(n, senw.north()); + ASSERT_DOUBLE_EQ(w, senw.west()); + ASSERT_DOUBLE_EQ(e, senw.east()); + + auto nwse = LatLngBounds::hull({n, w}, {s, e}); + ASSERT_DOUBLE_EQ(s, nwse.south()); + ASSERT_DOUBLE_EQ(n, nwse.north()); + ASSERT_DOUBLE_EQ(w, nwse.west()); + ASSERT_DOUBLE_EQ(e, nwse.east()); +} + +TEST(LatLngBounds, Empty) { + ASSERT_TRUE(LatLngBounds::empty().isEmpty()); + ASSERT_FALSE(LatLngBounds::world().isEmpty()); +} + +TEST(LatLngBounds, Center) { + auto result = LatLngBounds::hull({1, 2}, {3, 4}).center(); + ASSERT_DOUBLE_EQ(2, result.latitude); + ASSERT_DOUBLE_EQ(3, result.longitude); +} + +TEST(LatLngBounds, Southwest) { + auto result = LatLngBounds::hull({1, 2}, {3, 4}).southwest(); + ASSERT_DOUBLE_EQ(1, result.latitude); + ASSERT_DOUBLE_EQ(2, result.longitude); +} + +TEST(LatLngBounds, Northeast) { + auto result = LatLngBounds::hull({1, 2}, {3, 4}).northeast(); + ASSERT_DOUBLE_EQ(3, result.latitude); + ASSERT_DOUBLE_EQ(4, result.longitude); +} + +TEST(LatLngBounds, Southeast) { + auto result = LatLngBounds::hull({1, 2}, {3, 4}).southeast(); + ASSERT_DOUBLE_EQ(1, result.latitude); + ASSERT_DOUBLE_EQ(4, result.longitude); +} + +TEST(LatLngBounds, Northwest) { + auto result = LatLngBounds::hull({1, 2}, {3, 4}).northwest(); + ASSERT_DOUBLE_EQ(3, result.latitude); + ASSERT_DOUBLE_EQ(2, result.longitude); +} + +TEST(LatLng, FromTileID) { for (int i = 0; i < 20; i++) { const LatLng ll{ TileID(i, 0, 0, 0) }; ASSERT_DOUBLE_EQ(-180, ll.longitude); @@ -25,37 +104,36 @@ TEST(Geo, LatLngFromTileID) { } } - -TEST(Geo, LatLngBoundsFromTileID) { +TEST(LatLngBounds, FromTileID) { { const LatLngBounds bounds{ TileID(0, 0, 0, 0) }; - ASSERT_DOUBLE_EQ(-180, bounds.sw.longitude); - ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.sw.latitude); - ASSERT_DOUBLE_EQ(180, bounds.ne.longitude); - ASSERT_DOUBLE_EQ(85.051128779806604, bounds.ne.latitude); + ASSERT_DOUBLE_EQ(-180, bounds.west()); + ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.south()); + ASSERT_DOUBLE_EQ(180, bounds.east()); + ASSERT_DOUBLE_EQ(85.051128779806604, bounds.north()); } { const LatLngBounds bounds{ TileID(1, 0, 1, 0) }; - ASSERT_DOUBLE_EQ(-180, bounds.sw.longitude); - ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.sw.latitude); - ASSERT_DOUBLE_EQ(0, bounds.ne.longitude); - ASSERT_DOUBLE_EQ(0, bounds.ne.latitude); + ASSERT_DOUBLE_EQ(-180, bounds.west()); + ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.south()); + ASSERT_DOUBLE_EQ(0, bounds.east()); + ASSERT_DOUBLE_EQ(0, bounds.north()); } { const LatLngBounds bounds{ TileID(1, 1, 1, 0) }; - ASSERT_DOUBLE_EQ(0, bounds.sw.longitude); - ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.sw.latitude); - ASSERT_DOUBLE_EQ(180, bounds.ne.longitude); - ASSERT_DOUBLE_EQ(0, bounds.ne.latitude); + ASSERT_DOUBLE_EQ(0, bounds.west()); + ASSERT_DOUBLE_EQ(-85.051128779806604, bounds.south()); + ASSERT_DOUBLE_EQ(180, bounds.east()); + ASSERT_DOUBLE_EQ(0, bounds.north()); } { const LatLngBounds bounds{ TileID(1, 0, 0, 0) }; - ASSERT_DOUBLE_EQ(-180, bounds.sw.longitude); - ASSERT_DOUBLE_EQ(0, bounds.sw.latitude); - ASSERT_DOUBLE_EQ(0, bounds.ne.longitude); - ASSERT_DOUBLE_EQ(85.051128779806604, bounds.ne.latitude); + ASSERT_DOUBLE_EQ(-180, bounds.west()); + ASSERT_DOUBLE_EQ(0, bounds.south()); + ASSERT_DOUBLE_EQ(0, bounds.east()); + ASSERT_DOUBLE_EQ(85.051128779806604, bounds.north()); } } |