#ifndef LLMR_TEXT_COLLISION #define LLMR_TEXT_COLLISION #include #include #include #include #include namespace llmr { // These are the glyph boxes that we want to have placed. struct GlyphBox { GlyphBox() {} GlyphBox(const CollisionRect &bbox, const CollisionRect &box, float minScale) : bbox(bbox), box(box), minScale(minScale) {} CollisionAnchor anchor; CollisionRect bbox; CollisionRect box; bool rotate = false; float minScale = 0.0f; float maxScale = std::numeric_limits::infinity(); }; typedef std::vector GlyphBoxes; // 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::infinity(); float padding = 0.0f; }; struct Placement { Placement() {} Placement(float zoom, const PlacementRange &rotationRange) : zoom(zoom), rotationRange(rotationRange) {} float zoom = -1.0f; PlacementRange rotationRange = {{0.0f, 0.0f}}; }; class Collision { typedef boost::geometry::model::point Point; typedef boost::geometry::model::box Box; typedef std::pair PlacementValue; typedef boost::geometry::index::rtree< PlacementValue, boost::geometry::index::quadratic<16>> Tree; public: Collision(); Placement place(const GlyphBoxes &boxes, const CollisionAnchor &anchor, float minPlacementScale, float maxPlacementScale, float padding, bool horizontal); float getPlacementScale(const GlyphBoxes &glyphs, float minPlacementScale, float maxPlacementScale, float pad); PlacementRange getPlacementRange(const GlyphBoxes &glyphs, float placementScale); void insert(const GlyphBoxes &glyphs, const CollisionAnchor &anchor, float placementScale, const PlacementRange &placementRange, bool horizontal, float padding); private: Tree tree; }; } #endif