summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-07-11 22:32:51 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-07-17 11:22:38 +0300
commitf4e850f8e37d12b7619065988eff8bc408bdc391 (patch)
treeb9288b43b932bf42c571261379e0fc8aecc12760
parent07b0021ce3f92bdca3821381c026751a17d6565e (diff)
downloadqtlocation-mapboxgl-upstream/covered-by-grandchildren.tar.gz
[core] coveredByChildren is false if at least one child is uncoveredupstream/covered-by-grandchildren
-rw-r--r--src/mbgl/algorithm/covered_by_children.hpp16
-rw-r--r--test/algorithm/covered_by_children.test.cpp44
2 files changed, 55 insertions, 5 deletions
diff --git a/src/mbgl/algorithm/covered_by_children.hpp b/src/mbgl/algorithm/covered_by_children.hpp
index ad2f1dd5dd..fe5af3f3db 100644
--- a/src/mbgl/algorithm/covered_by_children.hpp
+++ b/src/mbgl/algorithm/covered_by_children.hpp
@@ -8,15 +8,23 @@ namespace algorithm {
template <typename Iterator>
bool coveredByChildren(const UnwrappedTileID& id, Iterator it, const Iterator& end) {
for (const auto& child : id.children()) {
- it = std::lower_bound(it, end, child, [](auto& a, auto& b) { return std::get<0>(a) < b; });
+ it = std::lower_bound(it, end, child, [](const auto& a, const auto& b) { return std::get<0>(a) < b; });
+
+ // Child is not present, neither its grandchildren.
if (it == end) {
return false;
- } else if (std::get<0>(*it) != child) {
- return coveredByChildren(child, it, end);
+ }
+
+ // Child is not present, but its grandchildren are.
+ if (std::get<0>(*it) != child) {
+ // This child is not covered by its grandchildren.
+ if (!coveredByChildren(child, it, end)) {
+ return false;
+ }
}
}
- // We looked at all four immediate children and verified that they're covered.
+ // We looked at all four children (recursively) and verified that they're covered.
return true;
}
diff --git a/test/algorithm/covered_by_children.test.cpp b/test/algorithm/covered_by_children.test.cpp
index b2a219bf29..84f5aa6a21 100644
--- a/test/algorithm/covered_by_children.test.cpp
+++ b/test/algorithm/covered_by_children.test.cpp
@@ -8,6 +8,48 @@ using namespace mbgl;
using List = std::map<UnwrappedTileID, bool>;
+TEST(CoveredByChildren, GrandChildren) {
+ const List list {
+ { UnwrappedTileID{ 0, 0, 0 }, true },
+ // These grandchildren covers 1/0/0, but 1/0/0 only covers a quarter of
+ // 0/0/0.
+ { UnwrappedTileID{ 2, 0, 0 }, true },
+ { UnwrappedTileID{ 2, 0, 1 }, true },
+ { UnwrappedTileID{ 2, 1, 0 }, true },
+ { UnwrappedTileID{ 2, 1, 1 }, true },
+ };
+ EXPECT_FALSE(algorithm::coveredByChildren(UnwrappedTileID{ 0, 0, 0 }, list));
+
+ const List list2 {
+ { UnwrappedTileID{ 0, 0, 0 }, true },
+
+ // Children of 1/0/0
+ { UnwrappedTileID{ 2, 0, 0 }, true },
+ { UnwrappedTileID{ 2, 0, 1 }, true },
+ { UnwrappedTileID{ 2, 1, 0 }, true },
+ { UnwrappedTileID{ 2, 1, 1 }, true },
+
+ // Children of 1/0/1
+ { UnwrappedTileID{ 2, 0, 2 }, true },
+ { UnwrappedTileID{ 2, 0, 3 }, true },
+ { UnwrappedTileID{ 2, 1, 2 }, true },
+ { UnwrappedTileID{ 2, 1, 3 }, true },
+
+ // Children of 1/1/0
+ { UnwrappedTileID{ 2, 2, 0 }, true },
+ { UnwrappedTileID{ 2, 2, 1 }, true },
+ { UnwrappedTileID{ 2, 3, 0 }, true },
+ { UnwrappedTileID{ 2, 3, 1 }, true },
+
+ // Children of 1/0/1
+ { UnwrappedTileID{ 2, 2, 2 }, true },
+ { UnwrappedTileID{ 2, 2, 3 }, true },
+ { UnwrappedTileID{ 2, 3, 2 }, true },
+ { UnwrappedTileID{ 2, 3, 3 }, true },
+ };
+ EXPECT_TRUE(algorithm::coveredByChildren(UnwrappedTileID{ 0, 0, 0 }, list2));
+}
+
TEST(CoveredByChildren, NotCovered) {
const List list1;
EXPECT_FALSE(algorithm::coveredByChildren(UnwrappedTileID{ 0, 0, 0 }, list1));
@@ -24,7 +66,7 @@ TEST(CoveredByChildren, NotCovered) {
const List list3{
{ UnwrappedTileID{ 0, 0, 0 }, true },
- // all four child tiles, with with a different wrap index
+ // all four child tiles, with a different wrap index
{ UnwrappedTileID{ 1, { 1, 0, 0 } }, true },
{ UnwrappedTileID{ 1, { 1, 0, 1 } }, true },
{ UnwrappedTileID{ 1, { 1, 1, 0 } }, true },