summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-03-08 13:59:31 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-05-10 14:50:56 +0200
commitecc8e018faff02e8f0bb2a6c11db361f454c555e (patch)
tree0aefbbfd24263e0cbc711a2a081ae9fc4aed5147 /src/mbgl
parent82ebcfa14e2eb8d13c3eca9c2eb5adaa229f4182 (diff)
downloadqtlocation-mapboxgl-ecc8e018faff02e8f0bb2a6c11db361f454c555e.tar.gz
[core] add algorithm for detecting whether an ordered map contains covering children
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/algorithm/covered_by_children.hpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mbgl/algorithm/covered_by_children.hpp b/src/mbgl/algorithm/covered_by_children.hpp
new file mode 100644
index 0000000000..766a67acac
--- /dev/null
+++ b/src/mbgl/algorithm/covered_by_children.hpp
@@ -0,0 +1,34 @@
+#ifndef MBGL_ALGORITHM_COVERED_BY_CHILDREN
+#define MBGL_ALGORITHM_COVERED_BY_CHILDREN
+
+#include <mbgl/tile/tile_id.hpp>
+
+namespace mbgl {
+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; });
+ if (it == end) {
+ return false;
+ } else if (std::get<0>(*it) != child) {
+ return coveredByChildren(child, it, end);
+ }
+ }
+
+ // We looked at all four immediate children and verified that they're covered.
+ return true;
+}
+
+template <typename Container>
+bool coveredByChildren(const UnwrappedTileID& id, const Container& container) {
+ return coveredByChildren(
+ id, container.upper_bound(id),
+ container.lower_bound(UnwrappedTileID{ static_cast<int16_t>(id.wrap + 1), { 0, 0, 0 } }));
+}
+
+} // namespace algorithm
+} // namespace mbgl
+
+#endif \ No newline at end of file