diff options
Diffstat (limited to 'src/mbgl/text/collision_feature.cpp')
-rw-r--r-- | src/mbgl/text/collision_feature.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp index ee7322e692..c708f834da 100644 --- a/src/mbgl/text/collision_feature.cpp +++ b/src/mbgl/text/collision_feature.cpp @@ -14,7 +14,8 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates& line, const float padding, const style::SymbolPlacementType placement, IndexedSubfeature indexedFeature_, - const float overscaling) + const float overscaling, + const float rotate) : indexedFeature(std::move(indexedFeature_)) , alongLine(placement != style::SymbolPlacementType::Point) { if (top == 0 && bottom == 0 && left == 0 && right == 0) return; @@ -35,7 +36,28 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates& line, GeometryCoordinate anchorPoint = convertPoint<int16_t>(anchor.point); bboxifyLabel(line, anchorPoint, anchor.segment, length, height, overscaling); } else { - boxes.emplace_back(anchor.point, Point<float>{ 0, 0 }, x1, y1, x2, y2); + if (rotate) { + // Account for *-rotate in point collision boxes + // Doesn't account for icon-text-fit + const float rotateRadians = rotate * M_PI / 180.0; + + const Point<float> tl = util::rotate(Point<float>(x1, y1), rotateRadians); + const Point<float> tr = util::rotate(Point<float>(x2, y1), rotateRadians); + const Point<float> bl = util::rotate(Point<float>(x1, y2), rotateRadians); + const Point<float> br = util::rotate(Point<float>(x2, y2), rotateRadians); + + // Collision features require an "on-axis" geometry, + // so take the envelope of the rotated geometry + // (may be quite large for wide labels rotated 45 degrees) + const float xMin = std::min({tl.x, tr.x, bl.x, br.x}); + const float xMax = std::max({tl.x, tr.x, bl.x, br.x}); + const float yMin = std::min({tl.y, tr.y, bl.y, br.y}); + const float yMax = std::max({tl.y, tr.y, bl.y, br.y}); + + boxes.emplace_back(anchor.point, Point<float>{ 0, 0 }, xMin, yMin, xMax, yMax); + } else { + boxes.emplace_back(anchor.point, Point<float>{ 0, 0 }, x1, y1, x2, y2); + } } } |