summaryrefslogtreecommitdiff
path: root/include/mbgl/text/types.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/text/types.hpp')
-rw-r--r--include/mbgl/text/types.hpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/include/mbgl/text/types.hpp b/include/mbgl/text/types.hpp
new file mode 100644
index 0000000000..9a9284b588
--- /dev/null
+++ b/include/mbgl/text/types.hpp
@@ -0,0 +1,109 @@
+#ifndef MBGL_TEXT_TYPES
+#define MBGL_TEXT_TYPES
+
+#include <mbgl/util/vec.hpp>
+#include <mbgl/util/rect.hpp>
+#include <array>
+#include <vector>
+
+namespace mbgl {
+
+typedef vec2<float> CollisionPoint;
+typedef vec2<float> CollisionAnchor;
+
+typedef std::array<float, 2> PlacementRange;
+typedef float CollisionAngle;
+typedef std::vector<CollisionAngle> CollisionAngles;
+typedef std::array<CollisionAngle, 2> CollisionRange;
+typedef std::vector<CollisionRange> CollisionList;
+typedef std::array<CollisionPoint, 4> CollisionCorners;
+
+struct CollisionRect {
+ CollisionPoint tl;
+ CollisionPoint br;
+ inline explicit CollisionRect() {}
+ inline explicit CollisionRect(CollisionPoint::Type ax,
+ CollisionPoint::Type ay,
+ CollisionPoint::Type bx,
+ CollisionPoint::Type by)
+ : tl(ax, ay), br(bx, by) {}
+ inline explicit CollisionRect(const CollisionPoint &tl,
+ const CollisionPoint &br)
+ : tl(tl), br(br) {}
+};
+
+// These are the glyph boxes that we want to have placed.
+struct GlyphBox {
+ explicit GlyphBox() {}
+ explicit GlyphBox(const CollisionRect &bbox, const CollisionRect &box,
+ float minScale)
+ : bbox(bbox), box(box), minScale(minScale) {}
+ explicit GlyphBox(const CollisionRect &box, float minScale, float maxScale,
+ const CollisionAnchor &anchor, bool rotate)
+ : anchor(anchor),
+ box(box),
+ rotate(rotate),
+ minScale(minScale),
+ maxScale(maxScale) {}
+
+ CollisionAnchor anchor;
+ CollisionRect bbox;
+ CollisionRect box;
+ bool rotate = false;
+ float minScale = 0.0f;
+ float maxScale = std::numeric_limits<float>::infinity();
+};
+
+typedef std::vector<GlyphBox> GlyphBoxes;
+
+
+// TODO: Transform the vec2<float>s to vec2<int16_t> to save bytes
+struct PlacedGlyph {
+ explicit PlacedGlyph(const vec2<float> &tl, const vec2<float> &tr,
+ const vec2<float> &bl, const vec2<float> &br,
+ const Rect<uint16_t> &tex, float angle, const GlyphBox &glyphBox)
+ : tl(tl),
+ tr(tr),
+ bl(bl),
+ br(br),
+ tex(tex),
+ angle(angle),
+ glyphBox(glyphBox) {}
+
+ vec2<float> tl, tr, bl, br;
+ Rect<uint16_t> tex;
+ float angle;
+ GlyphBox glyphBox;
+};
+
+typedef std::vector<PlacedGlyph> PlacedGlyphs;
+
+// These are the placed boxes contained in the rtree.
+struct PlacementBox {
+ CollisionAnchor anchor;
+ CollisionRect bbox;
+ CollisionRect box;
+ bool rotate = false;
+ PlacementRange placementRange = {{0.0f, 0.0f}};
+ float placementScale = 0.0f;
+ float maxScale = std::numeric_limits<float>::infinity();
+ float padding = 0.0f;
+};
+
+struct PlacementProperty {
+ explicit PlacementProperty() {}
+ explicit PlacementProperty(float zoom, const PlacementRange &rotationRange)
+ : zoom(zoom), rotationRange(rotationRange) {}
+
+ inline operator bool() const {
+ return !isnan(zoom) && zoom != std::numeric_limits<float>::infinity() &&
+ rotationRange[0] != rotationRange[1];
+ }
+
+ float zoom = std::numeric_limits<float>::infinity();
+ PlacementRange rotationRange = {{0.0f, 0.0f}};
+};
+
+}
+
+#endif