summaryrefslogtreecommitdiff
path: root/src/mbgl/algorithm/covered_by_children.hpp
blob: 766a67acac83e93d9571b1b40a42d553f4c123d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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