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

Commit

Permalink
wip fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
pozdnyakov committed Mar 23, 2020
1 parent 11ca744 commit fa41a2d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ void Placement::placeLayers(const RenderLayerReferences& layers) {
}

void Placement::placeLayer(const RenderLayer& layer) {
std::set<uint32_t> seenCrossTileIDs;
for (const BucketPlacementData& data : layer.getPlacementData()) {
Bucket& bucket = data.bucket;
bucket.place(*this, data, seenCrossTileIDs);
bucket.place(*this, data, seenLayerCrossTileIDs[layer.getID()]);
}
}

Expand Down Expand Up @@ -1159,7 +1158,7 @@ class StaticPlacement : public Placement {
StaticPlacement(std::shared_ptr<const UpdateParameters> updateParameters_)
: Placement(std::move(updateParameters_), nullopt) {}

private:
protected:
void commit() override;
float symbolFadeChange(TimePoint) const override { return 1.0f; }
bool hasTransitions(TimePoint) const override { return false; }
Expand Down Expand Up @@ -1306,21 +1305,32 @@ SymbolInstanceReferences TilePlacement::getSortedSymbols(const BucketPlacementDa

return intersects;
};

if (onlyLabelsIntersectingTileBorders) {
SymbolInstanceReferences filtered;
filtered.reserve(symbolInstances.size());
for (const SymbolInstance& symbol : symbolInstances) {
if (symbolIntersectsTileEdges(symbol)) filtered.push_back(symbol);
}
// Add more stability, sorting tile border labels by their Y position.
std::stable_sort(filtered.begin(), filtered.end(), [](const SymbolInstance& a, const SymbolInstance& b) {
return a.anchor.point.y < b.anchor.point.y;
});
return filtered;
if (!onlyLabelsIntersectingTileBorders) {
std::stable_sort(
symbolInstances.begin(),
symbolInstances.end(),
[&symbolIntersectsTileEdges](const SymbolInstance& a, const SymbolInstance& b) noexcept {
assert(!a.textCollisionFeature.alongLine);
assert(!b.textCollisionFeature.alongLine);
auto intersectsA = symbolIntersectsTileEdges(a);
auto intersectsB = symbolIntersectsTileEdges(b);
if (intersectsA) {
if (!intersectsB) return true;
// Both symbols are inrecepting the tile borders, we need a universal cross-tile rule
// to define which of them shall be placed first - use anchor `y` point.
return a.anchor.point.y < b.anchor.point.y;
}
return false;
});
}

return symbolInstances;

SymbolInstanceReferences filtered;
filtered.reserve(symbolInstances.size());
for (const SymbolInstance& symbol : symbolInstances) {
if (onlyLabelsIntersectingTileBorders == symbolIntersectsTileEdges(symbol)) filtered.push_back(symbol);
}
return filtered;
}

bool TilePlacement::stickToFirstVariableAnchor(const CollisionBox& box,
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 @@ -185,6 +185,7 @@ class Placement {
bool showCollisionBoxes = false;
// Used for debug purposes.
std::unordered_map<const CollisionFeature*, std::vector<ProjectedCollisionBox>> collisionCircles;
std::unordered_map<std::string, std::set<uint32_t>> seenLayerCrossTileIDs;
};

} // namespace mbgl

0 comments on commit fa41a2d

Please sign in to comment.