From cdee5b824903c6f69df90231d75521c7e130175b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 6 Dec 2019 18:11:25 -0500 Subject: [core] increase padding in CollisionIndex for MapMode::Tile (#15880) * [core] fix cutoff cross-tile labels in MapMode::Tile Increase the CollisionIndex's padding so that more of a tile's data gets considered when checking for collisions. This should fix clipped variable placement text labels. --- src/mbgl/text/collision_index.cpp | 38 ++++++++++++++++++++++++-------------- src/mbgl/text/collision_index.hpp | 3 ++- src/mbgl/text/placement.cpp | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp index c83b117b9a..4ffe66b98f 100644 --- a/src/mbgl/text/collision_index.cpp +++ b/src/mbgl/text/collision_index.cpp @@ -22,20 +22,30 @@ namespace mbgl { // the viewport for collision detection so that the bulk of the changes // occur offscreen. Making this constant greater increases label // stability, but it's expensive. -static const float viewportPadding = 100; - -CollisionIndex::CollisionIndex(const TransformState& transformState_) - : transformState(transformState_) - , collisionGrid(transformState.getSize().width + 2 * viewportPadding, transformState.getSize().height + 2 * viewportPadding, 25) - , ignoredGrid(transformState.getSize().width + 2 * viewportPadding, transformState.getSize().height + 2 * viewportPadding, 25) - , screenRightBoundary(transformState.getSize().width + viewportPadding) - , screenBottomBoundary(transformState.getSize().height + viewportPadding) - , gridRightBoundary(transformState.getSize().width + 2 * viewportPadding) - , gridBottomBoundary(transformState.getSize().height + 2 * viewportPadding) - , pitchFactor(std::cos(transformState.getPitch()) * transformState.getCameraToCenterDistance()) -{} - -float CollisionIndex::approximateTileDistance(const TileDistance& tileDistance, const float lastSegmentAngle, const float pixelsToTileUnits, const float cameraToAnchorDistance, const bool pitchWithMap) { +static const float viewportPaddingDefault = 100; +// Viewport padding must be much larger for static tiles to avoid clipped labels. +static const float viewportPaddingForStaticTiles = 1024; + +CollisionIndex::CollisionIndex(const TransformState& transformState_, MapMode& mapMode) + : transformState(transformState_), + viewportPadding(mapMode == MapMode::Tile ? viewportPaddingForStaticTiles : viewportPaddingDefault), + collisionGrid(transformState.getSize().width + 2 * viewportPadding, + transformState.getSize().height + 2 * viewportPadding, + 25), + ignoredGrid(transformState.getSize().width + 2 * viewportPadding, + transformState.getSize().height + 2 * viewportPadding, + 25), + screenRightBoundary(transformState.getSize().width + viewportPadding), + screenBottomBoundary(transformState.getSize().height + viewportPadding), + gridRightBoundary(transformState.getSize().width + 2 * viewportPadding), + gridBottomBoundary(transformState.getSize().height + 2 * viewportPadding), + pitchFactor(std::cos(transformState.getPitch()) * transformState.getCameraToCenterDistance()) {} + +float CollisionIndex::approximateTileDistance(const TileDistance& tileDistance, + const float lastSegmentAngle, + const float pixelsToTileUnits, + const float cameraToAnchorDistance, + const bool pitchWithMap) { // This is a quick and dirty solution for chosing which collision circles to use (since collision circles are // laid out in tile units). Ideally, I think we should generate collision circles on the fly in viewport coordinates // at the time we do collision detection. diff --git a/src/mbgl/text/collision_index.hpp b/src/mbgl/text/collision_index.hpp index 4e8a2fdb62..b9e618bd24 100644 --- a/src/mbgl/text/collision_index.hpp +++ b/src/mbgl/text/collision_index.hpp @@ -20,7 +20,7 @@ class CollisionIndex { public: using CollisionGrid = GridIndex; - explicit CollisionIndex(const TransformState&); + explicit CollisionIndex(const TransformState&, MapMode&); std::pair placeFeature(const CollisionFeature& feature, Point shift, @@ -72,6 +72,7 @@ private: const TransformState transformState; + const float viewportPadding; CollisionGrid collisionGrid; CollisionGrid ignoredGrid; diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index ecc8f93032..7964ad24c7 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -95,7 +95,7 @@ Placement::Placement(const TransformState& state_, style::TransitionOptions transitionOptions_, const bool crossSourceCollisions, optional> prevPlacement_) - : collisionIndex(state_), + : collisionIndex(state_, mapMode_), mapMode(mapMode_), transitionOptions(std::move(transitionOptions_)), placementZoom(state_.getZoom()), -- cgit v1.2.1