summaryrefslogtreecommitdiff
path: root/include/mbgl/map/tile.hpp
blob: 1ae13dd79d9ef25386b3ae74f48c695fa818997e (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef MBGL_MAP_TILE
#define MBGL_MAP_TILE

#include <mbgl/util/mat4.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>

#include <cstdint>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <forward_list>
#include <iosfwd>
#include <string>

namespace mbgl {

class TileData;
struct box;

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;
    }
};

class Tile : private util::noncopyable {
public:
    struct ID {
        const int16_t w = 0;
        const int8_t z = 0;
        const int32_t x = 0, y = 0;

        inline explicit ID(int8_t z_, int32_t x_, int32_t y_)
            : w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_) {}

        inline uint64_t to_uint64() const {
            return ((std::pow(2, z) * y + x) * 32) + z;
        }

        inline operator std::string() const {
            return std::to_string(z) + "/" + std::to_string(x) + "/" + std::to_string(y);
        }

        inline bool operator==(const ID& rhs) const {
            return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y;
        }

        inline bool operator!=(const ID& rhs) const {
            return !operator==(rhs);
        }

        inline bool operator<(const ID &rhs) const {
            if (w != rhs.w) return w < rhs.w;
            if (z != rhs.z) return z < rhs.z;
            if (x != rhs.x) return x < rhs.x;
            return y < rhs.y;
        }

        ID parent(int8_t z) const;
        ID normalized() const;
        std::forward_list<ID> children(int32_t z) const;
        bool isChildOf(const Tile::ID &id) const;
    };

    static std::forward_list<Tile::ID> cover(int8_t z, const box& bounds);

public:
    explicit Tile(const ID& id);

public:
    const Tile::ID id;
    ClipID clip;
    mat4 matrix;
    util::ptr<TileData> data;
};

}

#endif