summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-12-04 14:24:16 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-01-08 12:43:26 +0200
commit2125548a6e36ff0c33acb78cc69d28cb7a7f2409 (patch)
tree081bedfe7995acfed6dc683478b106029f7c8b2f
parent5f031dfa56f28d60eefc4b87a2ab62d54a3ecd2d (diff)
downloadqtlocation-mapboxgl-2125548a6e36ff0c33acb78cc69d28cb7a7f2409.tar.gz
[core] Consolidate more logic in calculateVariableLayoutOffset()
-rw-r--r--src/mbgl/text/placement.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 2566ba4274..8fa91c24a7 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -122,13 +122,23 @@ void Placement::placeLayer(const RenderLayer& layer, const mat4& projMatrix, boo
}
namespace {
-Point<float> calculateVariableLayoutOffset(style::SymbolAnchorType anchor, float width, float height, std::array<float, 2> offset, float textBoxScale) {
+Point<float> calculateVariableLayoutOffset(style::SymbolAnchorType anchor,
+ float width,
+ float height,
+ std::array<float, 2> offset,
+ float textBoxScale,
+ bool rotateWithMap,
+ bool pitchWithMap,
+ float bearing) {
AnchorAlignment alignment = AnchorAlignment::getAnchorAlignment(anchor);
float shiftX = -(alignment.horizontalAlign - 0.5f) * width;
float shiftY = -(alignment.verticalAlign - 0.5f) * height;
auto variableOffset = SymbolLayout::evaluateVariableOffset(anchor, offset);
- return { shiftX + variableOffset[0] * textBoxScale,
- shiftY + variableOffset[1] * textBoxScale };
+ Point<float> shift{shiftX + variableOffset[0] * textBoxScale, shiftY + variableOffset[1] * textBoxScale};
+ if (rotateWithMap) {
+ shift = util::rotate(shift, pitchWithMap ? bearing : -bearing);
+ }
+ return shift;
}
} // namespace
@@ -322,12 +332,14 @@ void Placement::placeBucket(
for (size_t i = 0u; i < placementAttempts; ++i) {
auto anchor = variableTextAnchors[i % anchorsSize];
const bool allowOverlap = (i >= anchorsSize);
- shift = calculateVariableLayoutOffset(anchor, width, height, symbolInstance.variableTextOffset, textBoxScale);
- if (rotateWithMap) {
- float angle = pitchWithMap ? state.getBearing() : -state.getBearing();
- shift = util::rotate(shift, angle);
- }
-
+ shift = calculateVariableLayoutOffset(anchor,
+ width,
+ height,
+ symbolInstance.variableTextOffset,
+ textBoxScale,
+ rotateWithMap,
+ pitchWithMap,
+ state.getBearing());
textBoxes.clear();
placedFeature = collisionIndex.placeFeature(textCollisionFeature,
shift,
@@ -896,10 +908,10 @@ void Placement::updateBucketOpacities(SymbolBucket& bucket,
variableOffset.width,
variableOffset.height,
variableOffset.offset,
- variableOffset.textBoxScale);
- if (rotateWithMap) {
- shift = util::rotate(shift, pitchWithMap ? state.getBearing() : -state.getBearing());
- }
+ variableOffset.textBoxScale,
+ rotateWithMap,
+ pitchWithMap,
+ state.getBearing());
} else {
// No offset -> this symbol hasn't been placed since coming on-screen
// No single box is particularly meaningful and all of them would be too noisy