summaryrefslogtreecommitdiff
path: root/src/mbgl/text/collision_feature.hpp
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2015-03-31 18:53:49 -0700
committerAnsis Brammanis <brammanis@gmail.com>2015-04-01 16:11:48 -0700
commit8fd42f371fd5e5581d3ce8307873664deb40a371 (patch)
treefcedced64e51127b2736da6155fe01adf0bf7ae1 /src/mbgl/text/collision_feature.hpp
parent128ed1f26fa2688a10f3738222da033337c7b0e5 (diff)
downloadqtlocation-mapboxgl-8fd42f371fd5e5581d3ce8307873664deb40a371.tar.gz
start porting CollisionTile and CollisionFeature
Diffstat (limited to 'src/mbgl/text/collision_feature.hpp')
-rw-r--r--src/mbgl/text/collision_feature.hpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp
new file mode 100644
index 0000000000..a16f58c8ed
--- /dev/null
+++ b/src/mbgl/text/collision_feature.hpp
@@ -0,0 +1,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 Anchor &_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
+ const Anchor anchor;
+
+ // distances to the edges from the anchor
+ const float x1;
+ const float y1;
+ const float x2;
+ const float y2;
+
+ // the box is only valid for scales < maxScale.
+ // The box does not block other boxes at scales >= maxScale;
+ const 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