summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-04-23 19:22:37 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-04-28 20:50:18 +0300
commite44598704d82db099f173295839113e3090d8094 (patch)
treee6c58894e7773e80d2de99e143a05c5fe28fbc30
parent34e475c3ace28ff774d4669e1c3ecc0d6aea2ca3 (diff)
downloadqtlocation-mapboxgl-e44598704d82db099f173295839113e3090d8094.tar.gz
[core] Label intersection prioritization
-rw-r--r--src/mbgl/text/placement.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 9618e5471a..7bf360a746 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -1242,11 +1242,12 @@ void StaticPlacement::commit() {
/// Placement for Tile map mode.
struct Intersection {
- Intersection(const SymbolInstance& symbol_, PlacementContext ctx_, IntersectStatus status_)
- : symbol(symbol_), ctx(std::move(ctx_)), status(status_) {}
+ Intersection(const SymbolInstance& symbol_, PlacementContext ctx_, IntersectStatus status_, std::size_t priority_)
+ : symbol(symbol_), ctx(std::move(ctx_)), status(status_), priority(priority_) {}
std::reference_wrapper<const SymbolInstance> symbol;
PlacementContext ctx;
IntersectStatus status;
+ std::size_t priority; // less means more important
};
class TilePlacement : public StaticPlacement {
@@ -1281,6 +1282,7 @@ private:
std::vector<PlacedSymbolData> placedSymbolsData;
std::vector<Intersection> intersections;
bool populateIntersections = false;
+ std::size_t intersectionPriority{};
bool collectData = false;
};
@@ -1288,6 +1290,7 @@ void TilePlacement::placeLayers(const RenderLayerReferences& layers) {
placedSymbolsData.clear();
seenCrossTileIDs.clear();
intersections.clear();
+ intersectionPriority = 0u;
// Populale intersections.
populateIntersections = true;
for (auto it = layers.crbegin(); it != layers.crend(); ++it) {
@@ -1295,6 +1298,7 @@ void TilePlacement::placeLayers(const RenderLayerReferences& layers) {
}
std::stable_sort(intersections.begin(), intersections.end(), [](const Intersection& a, const Intersection& b) {
+ if (a.priority != b.priority) return a.priority < b.priority;
uint8_t flagsA = a.status.flags;
uint8_t flagsB = b.status.flags;
// Items arranged as: VerticalBorders & HorizontalBorders (3) ->
@@ -1456,8 +1460,10 @@ void TilePlacement::placeSymbolBucket(const BucketPlacementData& params, std::se
for (const SymbolInstance& symbol : symbolInstances) {
auto intersectStatus = symbolIntersectsTileEdges(symbol);
if (intersectStatus.flags == IntersectStatus::None) continue;
- intersections.emplace_back(symbol, ctx, intersectStatus);
+ intersections.emplace_back(symbol, ctx, intersectStatus, intersectionPriority);
}
+
+ ++intersectionPriority;
}
bool TilePlacement::canPlaceAtVariableAnchor(const CollisionBox& box,