summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-11-02 11:59:52 -0700
committerChris Loer <chris.loer@mapbox.com>2017-11-02 12:58:21 -0700
commit5bc98440c9d94c6e749340c91c6443c95f6a09bc (patch)
tree3bdb079a02428d7cf40a9fc1c1ca94896994097b
parent486902be46974ae9829a7f42280153429a102a01 (diff)
downloadqtlocation-mapboxgl-5bc98440c9d94c6e749340c91c6443c95f6a09bc.tar.gz
Port GL JS logic for generating extra collision circles in overscaled tiles.
Unfortunately only re-enable one of the overscaling render tests -- the "Figueroa St" test works but gives somewhat different results than JS.
-rw-r--r--platform/node/test/ignores.json1
-rw-r--r--src/mbgl/layout/symbol_instance.cpp5
-rw-r--r--src/mbgl/layout/symbol_instance.hpp3
-rw-r--r--src/mbgl/layout/symbol_layout.cpp2
-rw-r--r--src/mbgl/text/collision_feature.cpp17
-rw-r--r--src/mbgl/text/collision_feature.hpp12
-rw-r--r--src/mbgl/text/placement.cpp10
7 files changed, 30 insertions, 20 deletions
diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json
index 81dff0bee4..61ac6ec3fe 100644
--- a/platform/node/test/ignores.json
+++ b/platform/node/test/ignores.json
@@ -51,7 +51,6 @@
"render-tests/text-pitch-alignment/map-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-alignment/map-text-rotation-alignment-viewport": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-alignment/viewport-overzoomed": "https://github.com/mapbox/mapbox-gl-js/issues/5095",
- "render-tests/text-pitch-alignment/viewport-overzoomed-single-glyph": "https://github.com/mapbox/mapbox-gl-js/issues/5095",
"render-tests/text-pitch-alignment/viewport-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-alignment/viewport-text-rotation-alignment-viewport": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-scaling/line-half": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp
index 9e0c939da1..461d50196d 100644
--- a/src/mbgl/layout/symbol_instance.cpp
+++ b/src/mbgl/layout/symbol_instance.cpp
@@ -24,7 +24,8 @@ SymbolInstance::SymbolInstance(Anchor& anchor_,
const GlyphPositionMap& positions,
const IndexedSubfeature& indexedFeature,
const std::size_t featureIndex_,
- const std::u16string& key_) :
+ const std::u16string& key_,
+ const float overscaling) :
anchor(anchor_),
insideTileBoundaries(0 <= anchor.point.x && 0 <= anchor.point.y && anchor.point.x < util::EXTENT && anchor.point.y < util::EXTENT),
line(line_),
@@ -33,7 +34,7 @@ SymbolInstance::SymbolInstance(Anchor& anchor_,
hasIcon(shapedIcon),
// Create the collision features that will be used to check whether this symbol instance can be placed
- textCollisionFeature(line_, anchor, shapedTextOrientations.first, textBoxScale, textPadding, textPlacement, indexedFeature),
+ textCollisionFeature(line_, anchor, shapedTextOrientations.first, textBoxScale, textPadding, textPlacement, indexedFeature, overscaling),
iconCollisionFeature(line_, anchor, shapedIcon, iconBoxScale, iconPadding, SymbolPlacementType::Point, indexedFeature),
featureIndex(featureIndex_),
textOffset(textOffset_),
diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp
index e8006e37b6..fcad947207 100644
--- a/src/mbgl/layout/symbol_instance.hpp
+++ b/src/mbgl/layout/symbol_instance.hpp
@@ -32,7 +32,8 @@ public:
const GlyphPositionMap&,
const IndexedSubfeature&,
const std::size_t featureIndex,
- const std::u16string& key);
+ const std::u16string& key,
+ const float overscaling);
Anchor anchor;
bool insideTileBoundaries;
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 0d833d65a5..77dc29ccf7 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -323,7 +323,7 @@ void SymbolLayout::addFeature(const std::size_t index,
addToBuffers, symbolInstances.size(),
textBoxScale, textPadding, textPlacement, textOffset,
iconBoxScale, iconPadding, iconPlacement, iconOffset,
- glyphPositionMap, indexedFeature, index, feature.text ? *feature.text : std::u16string{});
+ glyphPositionMap, indexedFeature, index, feature.text ? *feature.text : std::u16string{}, overscaling);
};
const auto& type = feature.getType();
diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp
index 72e2c726e0..6d6f2aabc7 100644
--- a/src/mbgl/text/collision_feature.cpp
+++ b/src/mbgl/text/collision_feature.cpp
@@ -12,7 +12,8 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates& line,
const float boxScale,
const float padding,
const style::SymbolPlacementType placement,
- IndexedSubfeature indexedFeature_)
+ IndexedSubfeature indexedFeature_,
+ const float overscaling)
: indexedFeature(std::move(indexedFeature_))
, alongLine(placement == style::SymbolPlacementType::Line) {
if (top == 0 && bottom == 0 && left == 0 && right == 0) return;
@@ -31,20 +32,26 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates& line,
height = std::max(10.0f * boxScale, height);
GeometryCoordinate anchorPoint = convertPoint<int16_t>(anchor.point);
- bboxifyLabel(line, anchorPoint, anchor.segment, length, height);
+ bboxifyLabel(line, anchorPoint, anchor.segment, length, height, overscaling);
} else {
boxes.emplace_back(anchor.point, Point<float>{ 0, 0 }, x1, y1, x2, y2);
}
}
void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoordinate& anchorPoint,
- const int segment, const float labelLength, const float boxSize) {
+ const int segment, const float labelLength, const float boxSize, const float overscaling) {
const float step = boxSize / 2;
const int nBoxes = std::floor(labelLength / step);
- // We calculate line collision boxes out to 300% of what would normally be our
+ // We calculate line collision circles out to 300% of what would normally be our
// max size, to allow collision detection to work on labels that expand as
// they move into the distance
- const int nPitchPaddingBoxes = std::floor(nBoxes / 2);
+ // Vertically oriented labels in the distant field can extend past this padding
+ // This is a noticeable problem in overscaled tiles where the pitch 0-based
+ // symbol spacing will put labels very close together in a pitched map.
+ // To reduce the cost of adding extra collision circles, we slowly increase
+ // them for overscaled tiles.
+ const float overscalingPaddingFactor = 1 + .4 * std::log(overscaling) / std::log(2);
+ const int nPitchPaddingBoxes = std::floor(nBoxes * overscalingPaddingFactor / 2);
// offset the center of the first box by half a box so that the edge of the
// box is at the edge of the label.
diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp
index 99a17693ae..b13b3087c5 100644
--- a/src/mbgl/text/collision_feature.hpp
+++ b/src/mbgl/text/collision_feature.hpp
@@ -50,8 +50,9 @@ public:
const float boxScale,
const float padding,
const style::SymbolPlacementType placement,
- const IndexedSubfeature& indexedFeature_)
- : CollisionFeature(line, anchor, shapedText.top, shapedText.bottom, shapedText.left, shapedText.right, boxScale, padding, placement, indexedFeature_) {}
+ const IndexedSubfeature& indexedFeature_,
+ const float overscaling)
+ : CollisionFeature(line, anchor, shapedText.top, shapedText.bottom, shapedText.left, shapedText.right, boxScale, padding, placement, indexedFeature_, overscaling) {}
// for icons
CollisionFeature(const GeometryCoordinates& line,
@@ -66,7 +67,7 @@ public:
(shapedIcon ? shapedIcon->bottom() : 0),
(shapedIcon ? shapedIcon->left() : 0),
(shapedIcon ? shapedIcon->right() : 0),
- boxScale, padding, placement, indexedFeature_) {}
+ boxScale, padding, placement, indexedFeature_, 1) {}
CollisionFeature(const GeometryCoordinates& line,
const Anchor&,
@@ -77,7 +78,8 @@ public:
const float boxScale,
const float padding,
const style::SymbolPlacementType,
- IndexedSubfeature);
+ IndexedSubfeature,
+ const float overscaling);
std::vector<CollisionBox> boxes;
IndexedSubfeature indexedFeature;
@@ -85,7 +87,7 @@ public:
private:
void bboxifyLabel(const GeometryCoordinates& line, GeometryCoordinate& anchorPoint,
- const int segment, const float length, const float height);
+ const int segment, const float length, const float height, const float overscaling);
};
} // namespace mbgl
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 99bb2f9d6d..9e133cb1ef 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -56,7 +56,7 @@ void Placement::placeLayer(RenderSymbolLayer& symbolLayer, const mat4& projMatri
const float scale = std::pow(2, state.getZoom() - renderTile.id.canonical.z);
- const float pixelRatio = util::EXTENT / (util::tileSize * renderTile.tile.id.overscaleFactor());
+ const float textPixelRatio = util::EXTENT / util::tileSize;
mat4 posMatrix;
state.matrixFor(posMatrix, renderTile.id);
@@ -74,7 +74,7 @@ void Placement::placeLayer(RenderSymbolLayer& symbolLayer, const mat4& projMatri
state,
pixelsToTileUnits);
- placeLayerBucket(symbolBucket, posMatrix, textLabelPlaneMatrix, iconLabelPlaneMatrix, scale, pixelRatio, showCollisionBoxes, seenCrossTileIDs);
+ placeLayerBucket(symbolBucket, posMatrix, textLabelPlaneMatrix, iconLabelPlaneMatrix, scale, textPixelRatio, showCollisionBoxes, seenCrossTileIDs);
}
}
@@ -84,7 +84,7 @@ void Placement::placeLayerBucket(
const mat4& textLabelPlaneMatrix,
const mat4& iconLabelPlaneMatrix,
const float scale,
- const float pixelRatio,
+ const float textPixelRatio,
const bool showCollisionBoxes,
std::unordered_set<uint32_t>& seenCrossTileIDs) {
@@ -114,7 +114,7 @@ void Placement::placeLayerBucket(
const float fontSize = evaluateSizeForFeature(partiallyEvaluatedTextSize, placedSymbol);
placeText = collisionIndex.placeFeature(symbolInstance.textCollisionFeature,
- posMatrix, textLabelPlaneMatrix, pixelRatio,
+ posMatrix, textLabelPlaneMatrix, textPixelRatio,
placedSymbol, scale, fontSize,
bucket.layout.get<TextAllowOverlap>(),
bucket.layout.get<TextPitchAlignment>() == style::AlignmentType::Map,
@@ -127,7 +127,7 @@ void Placement::placeLayerBucket(
const float fontSize = evaluateSizeForFeature(partiallyEvaluatedIconSize, placedSymbol);
placeIcon = collisionIndex.placeFeature(symbolInstance.iconCollisionFeature,
- posMatrix, iconLabelPlaneMatrix, pixelRatio,
+ posMatrix, iconLabelPlaneMatrix, textPixelRatio,
placedSymbol, scale, fontSize,
bucket.layout.get<IconAllowOverlap>(),
bucket.layout.get<IconPitchAlignment>() == style::AlignmentType::Map,