summaryrefslogtreecommitdiff
path: root/src/mbgl/util/clip_id.hpp
blob: 2c128d2643f73878ff30091be5c9cfbec96ace3d (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef MBGL_UTIL_CLIP_IDS
#define MBGL_UTIL_CLIP_IDS

#include <mbgl/map/tile_id.hpp>

#include <bitset>
#include <string>
#include <list>
#include <set>
#include <vector>
#include <forward_list>
#include <map>

namespace mbgl {

class Tile;

struct ClipID {
    inline ClipID() {}
    inline ClipID(const std::string &mask_, const std::string &reference_) : mask(mask_), reference(reference_) {}

    std::bitset<8> mask;
    std::bitset<8> reference;

    inline bool operator==(const ClipID &other) const {
        return mask == other.mask && reference == other.reference;
    }

    inline ClipID& operator|=(const ClipID &other) {
        mask |= other.mask;
        reference |= other.reference;
        return *this;
    }
};

class ClipIDGenerator {
private:
    struct Leaf {
        Leaf(TileID, ClipID&);
        void add(const TileID &p);
        bool operator==(const Leaf &other) const;

        const TileID id;
        std::forward_list<TileID> children;
        ClipID& clip;
    };

    uint8_t bit_offset = 0;
    std::vector<Leaf> pool;

public:
    void update(std::forward_list<Tile *> tiles);

    std::map<TileID, ClipID> getStencils() const;
};


} // namespace mbgl

#endif