Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Variable labels stick to latest anchor if the view is tilted
Browse files Browse the repository at this point in the history
This is done in order to improve labels stability and for the performace reasons.
  • Loading branch information
pozdnyakov committed Mar 9, 2020
1 parent 97ad976 commit e5330b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set<ui
const auto prevAnchor = prevOffset->second.anchor;
auto found = std::find(variableTextAnchors.begin(), variableTextAnchors.end(), prevAnchor);
if (found != variableTextAnchors.begin() && found != variableTextAnchors.end()) {
std::vector<style::TextVariableAnchorType> filtered;
filtered.reserve(variableTextAnchors.size());
filtered.push_back(prevAnchor);
for (auto anchor : variableTextAnchors) {
if (anchor != prevAnchor) {
filtered.push_back(anchor);
std::vector<style::TextVariableAnchorType> filtered{prevAnchor};
if (!isTiltedView()) {
for (auto anchor : variableTextAnchors) {
if (anchor != prevAnchor) {
filtered.push_back(anchor);
}
}
}
variableTextAnchors = std::move(filtered);
Expand Down Expand Up @@ -657,22 +657,24 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set<ui

} else {
auto sortedSymbols = bucket.getSymbols(params.sortKeyRange);
if (auto* previousPlacement = getPrevPlacement()) {
std::stable_sort(
sortedSymbols.begin(), sortedSymbols.end(), [&](const SymbolInstance& a, const SymbolInstance& b) {
auto* aPlacement = previousPlacement->getSymbolPlacement(a);
auto* bPlacement = previousPlacement->getSymbolPlacement(b);
if (!aPlacement) {
// a < b, if 'a' is new and if 'b' was previously hidden.
return bPlacement && !bPlacement->placed();
}
if (!bPlacement) {
// a < b, if 'b' is new and 'a' was previously shown.
return aPlacement && aPlacement->placed();
}
// a < b, if 'a' was shown and 'b' was hidden.
return aPlacement->placed() && !bPlacement->placed();
});
auto* previousPlacement = getPrevPlacement();
if (previousPlacement && isTiltedView()) {
std::stable_sort(sortedSymbols.begin(),
sortedSymbols.end(),
[&previousPlacement](const SymbolInstance& a, const SymbolInstance& b) {
auto* aPlacement = previousPlacement->getSymbolPlacement(a);
auto* bPlacement = previousPlacement->getSymbolPlacement(b);
if (!aPlacement) {
// a < b, if 'a' is new and if 'b' was previously hidden.
return bPlacement && !bPlacement->placed();
}
if (!bPlacement) {
// a < b, if 'b' is new and 'a' was previously shown.
return aPlacement && aPlacement->placed();
}
// a < b, if 'a' was shown and 'b' was hidden.
return aPlacement->placed() && !bPlacement->placed();
});
}
for (const SymbolInstance& symbol : sortedSymbols) {
placeSymbol(symbol);
Expand Down Expand Up @@ -1199,6 +1201,10 @@ void Placement::markUsedOrientation(SymbolBucket& bucket,
}
}

bool Placement::isTiltedView() const {
return updateParameters->transformState.getPitch() != 0.0f;
}

float Placement::symbolFadeChange(TimePoint now) const {
if (transitionsEnabled() &&
transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) > Milliseconds(0)) {
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/text/placement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class Placement {
style::TextWritingModeType orientation) const;
void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&) const;
const Placement* getPrevPlacement() const { return prevPlacement ? prevPlacement->get() : nullptr; }
bool isTiltedView() const;

std::shared_ptr<const UpdateParameters> updateParameters;
CollisionIndex collisionIndex;
Expand Down

0 comments on commit e5330b8

Please sign in to comment.