summaryrefslogtreecommitdiff
path: root/src/mbgl/text/collision_feature.hpp
blob: 06056c2a20e6ed50389efc66cc158c8dc199ef89 (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
#ifndef MBGL_TEXT_COLLISION_FEATURE
#define MBGL_TEXT_COLLISION_FEATURE

#include <mbgl/util/vec.hpp>
#include <mbgl/geometry/anchor.hpp>
#include <mbgl/text/shaping.hpp>
#include <vector>

namespace mbgl {
    class CollisionBox {
        public:
            explicit CollisionBox(const vec2<float> &_anchor, float _x1, float _y1, float _x2, float _y2, float _maxScale) :
                anchor(_anchor), x1(_x1), y1(_y1), x2(_x2), y2(_y2), maxScale(_maxScale) {}

            // the box is centered around the anchor point
            vec2<float> anchor;

            // distances to the edges from the anchor
            float x1;
            float y1;
            float x2;
            float y2;

            // the box is only valid for scales < maxScale.
            // The box does not block other boxes at scales >= maxScale;
            float maxScale;

            // the scale at which the label can first be shown
            float placementScale = 0.0f;
    };

    class CollisionFeature {
        public:
            // for text
            inline explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
                    const Shaping &shapedText,
                    const float boxScale, const float padding, const bool alongLine)
                : CollisionFeature(line, anchor,
                        shapedText.top, shapedText.bottom, shapedText.left, shapedText.right,
                        boxScale, padding, alongLine) {}

            // for icons
            inline explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
                    const PositionedIcon &shapedIcon,
                    const float boxScale, const float padding, const bool alongLine)
                : CollisionFeature(line, anchor,
                        shapedIcon.top, shapedIcon.bottom, shapedIcon.left, shapedIcon.right,
                        boxScale, padding, alongLine) {}

            explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
                    const float top, const float bottom, const float left, const float right,
                    const float boxScale, const float padding, const bool alongLine);


            std::vector<CollisionBox> boxes;

        private:
            void bboxifyLabel(const std::vector<Coordinate> &line, const Anchor &anchor, const float length, const float height);
    };
}

#endif