summaryrefslogtreecommitdiff
path: root/src/mbgl/text/collision_tile.hpp
blob: b0c56e6f5b5dbf28f64e1d5733bc86332ea1eeaf (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
#ifndef MBGL_TEXT_COLLISION_TILE
#define MBGL_TEXT_COLLISION_TILE

#include <mbgl/text/collision_feature.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wshadow"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wdeprecated-register"
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#else
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/index/rtree.hpp>
#pragma GCC diagnostic pop

namespace mbgl {

    namespace bg = boost::geometry;
    namespace bgm = bg::model;
    namespace bgi = bg::index;
    typedef bgm::point<float, 2, bg::cs::cartesian> Point;
    typedef bgm::box<Point> Box;
    typedef std::pair<Box, CollisionBox> CollisionTreeBox;
    typedef bgi::rtree<CollisionTreeBox, bgi::linear<16,4>> Tree;

class CollisionTile {

    public:
    inline explicit CollisionTile(float _zoom, float tileExtent, float tileSize, float angle_, bool debug_) :
        zoom(_zoom), tilePixelRatio(tileExtent / tileSize), debug(debug_) { reset(angle_, 0); }

    void reset(const float angle, const float pitch);
    float placeFeature(const CollisionFeature &feature);
    void insertFeature(CollisionFeature &feature, const float minPlacementScale);

    void setDebug(bool debug_) { debug = debug_; }
    bool getDebug() { return debug; }

    const float zoom;
    const float tilePixelRatio;
    float angle = 0;

    const float minScale = 0.5f;
    const float maxScale = 2.0f;

    private:

    Box getTreeBox(const vec2<float> &anchor, const CollisionBox &box);

    Tree tree;
    std::array<float, 4> rotationMatrix;
    float yStretch;
    bool debug;

};
}

#endif