From 5790949e981fe6acec0263aa0ca6673a37868a01 Mon Sep 17 00:00:00 2001 From: Alexander Friedrich Date: Mon, 8 Jan 2024 17:46:23 +0100 Subject: [PATCH] show labels only if they are not hidden later --- shared/public/CollisionGrid.h | 17 +++++++--------- .../symbol/SymbolObjectCollisionWrapper.h | 6 ------ ...iled2dMapVectorSourceSymbolDataManager.cpp | 20 ++++--------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/shared/public/CollisionGrid.h b/shared/public/CollisionGrid.h index c12feadec..72121b220 100644 --- a/shared/public/CollisionGrid.h +++ b/shared/public/CollisionGrid.h @@ -98,32 +98,29 @@ class CollisionGrid { } } } + + bool collision = false; for (int16_t y = indexRange.yMin; y <= indexRange.yMax; y++) { for (int16_t x = indexRange.xMin; x <= indexRange.xMax; x++) { + if (!collision) { for (const auto &rect : gridRects[y][x]) { if (CollisionUtil::checkRectCollision(projectedRectangle, rect)) { - return 1; + collision = true; } } for (const auto &circle : gridCircles[y][x]) { if (CollisionUtil::checkRectCircleCollision(projectedRectangle, circle)) { - return 1; + collision = true; } } - - } - } - - // Only insert, when not colliding - for (int16_t y = indexRange.yMin; y <= indexRange.yMax; y++) { - for (int16_t x = indexRange.xMin; x <= indexRange.xMax; x++) { + } gridRects[y][x].push_back(projectedRectangle); } } - if (rectangle.contentHash != 0 && rectangle.symbolSpacing > 0) { spacedRects[rectangle.contentHash].push_back(projectedRectangle); } + if (collision) return 1; return 0; } diff --git a/shared/src/map/layers/tiled/vector/symbol/SymbolObjectCollisionWrapper.h b/shared/src/map/layers/tiled/vector/symbol/SymbolObjectCollisionWrapper.h index c19b713b0..5e794a297 100644 --- a/shared/src/map/layers/tiled/vector/symbol/SymbolObjectCollisionWrapper.h +++ b/shared/src/map/layers/tiled/vector/symbol/SymbolObjectCollisionWrapper.h @@ -42,12 +42,6 @@ class SymbolObjectCollisionWrapper { } bool operator<(const SymbolObjectCollisionWrapper &o) const { - if (isColliding != o.isColliding) { - return isColliding; - } - if (symbolObject->smallestVisibleZoom != o.symbolObject->smallestVisibleZoom) { - return symbolObject->smallestVisibleZoom > o.symbolObject->smallestVisibleZoom; - } if (symbolSortKey == o.symbolSortKey) { return symbolTileIndex > o.symbolTileIndex; } diff --git a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp index 3b293c5d6..25f6329c8 100644 --- a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp +++ b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp @@ -627,22 +627,10 @@ void Tiled2dMapVectorSourceSymbolDataManager::collisionDetection(std::vector(objectsIt->second)) { - symbolGroup.syncAccess([&allObjects, zoomIdentifier, persistingPlacement = persistingSymbolPlacement](auto group){ - const auto &objects = group->getSymbolObjectsForCollision(); - if (persistingPlacement) { - for (auto &object : objects) { - if (object.symbolObject->largestCollisionZoom == -1 || object.symbolObject->largestCollisionZoom < zoomIdentifier) { - allObjects.push_back(object); - } - else { - object.symbolObject->setHideFromCollision(true); - } - } - } else { - for(auto& o : objects) { - allObjects.push_back(o); - } - } + symbolGroup.syncAccess([&allObjects, zoomIdentifier](auto group){ + auto objects = group->getSymbolObjectsForCollision(); + allObjects.reserve(allObjects.size() + objects.size()); + allObjects.insert(allObjects.end(), std::make_move_iterator(objects.begin()), std::make_move_iterator(objects.end())); }); } }