diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-07-16 18:53:56 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-07-16 18:53:56 -0700 |
commit | 4ea281c750c5afcc68f2832bb42d98a1cbce6735 (patch) | |
tree | 60bc7d3ccba2c54859e2e023997cc027cc67aea7 /include/mbgl/map/tile.hpp | |
parent | c1a64dc5fa73b54cc5de77629781dfc74302a1e7 (diff) | |
download | qtlocation-mapboxgl-4ea281c750c5afcc68f2832bb42d98a1cbce6735.tar.gz |
rename llmr => mbgl
Diffstat (limited to 'include/mbgl/map/tile.hpp')
-rw-r--r-- | include/mbgl/map/tile.hpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/include/mbgl/map/tile.hpp b/include/mbgl/map/tile.hpp new file mode 100644 index 0000000000..7e868afad9 --- /dev/null +++ b/include/mbgl/map/tile.hpp @@ -0,0 +1,73 @@ +#ifndef MBGL_MAP_TILE +#define MBGL_MAP_TILE + +#include <mbgl/util/vec.hpp> +#include <mbgl/util/mat4.hpp> +#include <mbgl/util/noncopyable.hpp> + +#include <cstdint> +#include <forward_list> +#include <string> +#include <bitset> +#include <memory> + +namespace mbgl { + +class TileData; + +struct ClipID { + explicit ClipID() {} + explicit ClipID(const std::bitset<8> &mask, uint8_t length) : mask(mask), length(length) {} + explicit ClipID(const std::string &mask, uint8_t length) : mask(mask), length(length) {} + std::bitset<8> mask; + uint8_t length = 0; +}; + +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 { + 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; + }; + +public: + explicit Tile(const ID& id); + +public: + const Tile::ID id; + ClipID clip; + mat4 matrix; + std::shared_ptr<TileData> data; +}; + +} + +#endif |