From 8574b8b72696352852defbcae99c6ab46ecb2e3d Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Tue, 16 Jul 2019 17:24:09 +0300 Subject: [core] Favor previous anchor only when still in the `text-variable-anchor` options Port of https://github.com/mapbox/mapbox-gl-js/pull/8473 --- src/mbgl/text/placement.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index 62110fefa7..130c2d050c 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -194,20 +194,24 @@ void Placement::placeBucket( const float textBoxScale = symbolInstance.textBoxScale; // If this symbol was in the last placement, shift the previously used - // anchor to the front of the anchor list. + // anchor to the front of the anchor list, only if the previous anchor + // is still in the anchor list. if (prevPlacement) { auto prevOffset = prevPlacement->variableOffsets.find(symbolInstance.crossTileID); - if (prevOffset != prevPlacement->variableOffsets.end() && - variableTextAnchors.front() != prevOffset->second.anchor) { - std::vector filtered; - filtered.reserve(variableTextAnchors.size()); - filtered.push_back(prevOffset->second.anchor); - for (auto anchor : variableTextAnchors) { - if (anchor != prevOffset->second.anchor) { - filtered.push_back(anchor); + if (prevOffset != prevPlacement->variableOffsets.end()) { + const auto prevAnchor = prevOffset->second.anchor; + auto found = std::find(variableTextAnchors.begin(), variableTextAnchors.end(), prevAnchor); + if (found != variableTextAnchors.begin() && found != variableTextAnchors.end()) { + std::vector filtered; + filtered.reserve(variableTextAnchors.size()); + filtered.push_back(prevAnchor); + for (auto anchor : variableTextAnchors) { + if (anchor != prevAnchor) { + filtered.push_back(anchor); + } } + variableTextAnchors = std::move(filtered); } - variableTextAnchors = std::move(filtered); } } -- cgit v1.2.1