summaryrefslogtreecommitdiff
path: root/include/mbgl/text/collision.hpp
blob: 3bf37a6a12e5020c3164f6d0ff5240bd096acccc (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
#ifndef MBGL_TEXT_COLLISION
#define MBGL_TEXT_COLLISION

#include <mbgl/text/types.hpp>

#pragma GCC diagnostic push
#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"
#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, PlacementBox> PlacementValue;
typedef bgi::rtree<PlacementValue, bgi::linear<16,4>> Tree;

class Collision {

public:
    Collision(float zoom, float tileExtent, float tileSize, float placementDepth = 1);

    float getPlacementScale(const GlyphBoxes &glyphs, float minPlacementScale, bool avoidEdges);
    PlacementRange getPlacementRange(const GlyphBoxes &glyphs, float placementScale,
                                     bool horizontal);
    void insert(const GlyphBoxes &glyphs, const CollisionAnchor &anchor, float placementScale,
                const PlacementRange &placementRange, bool horizontal);

private:
    Tree hTree;
    Tree cTree;
    PlacementValue leftEdge;
    PlacementValue topEdge;
    PlacementValue rightEdge;
    PlacementValue bottomEdge;

public:
    const float tilePixelRatio;
    const float zoom;
    const float maxPlacementScale;
};
}

#endif