From 375f9f94b6a5348ced58fa0621a8618d1c5ed075 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Fri, 27 Oct 2017 16:23:32 -0700 Subject: [core] Add LatLngBounds::contains(const LatLngBounds&) --- include/mbgl/util/geo.hpp | 7 +++++++ test/util/geo.test.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 6d725b102b..54a8c99fab 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -161,6 +161,13 @@ public: point.longitude() <= ne.longitude()); } + bool contains(const LatLngBounds& area) const { + return (area.ne.latitude() <= ne.latitude() && + area.sw.latitude() >= sw.latitude() && + area.ne.longitude() <= ne.longitude() && + area.sw.longitude() >= sw.longitude()); + } + bool intersects(const LatLngBounds area) const { return (area.ne.latitude() > sw.latitude() && area.sw.latitude() < ne.latitude() && diff --git a/test/util/geo.test.cpp b/test/util/geo.test.cpp index d0d01b6f88..38f29d1dd4 100644 --- a/test/util/geo.test.cpp +++ b/test/util/geo.test.cpp @@ -220,3 +220,9 @@ TEST(LatLngBounds, FromTileID) { ASSERT_DOUBLE_EQ(util::LATITUDE_MAX, bounds.north()); } } + +TEST(LatLngBounds, Contains) { + const LatLngBounds bounds( CanonicalTileID(4,2,6)); + const LatLngBounds innerBounds( CanonicalTileID(9,82,197)); + EXPECT_TRUE(bounds.contains(innerBounds)); +} -- cgit v1.2.1