summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-01-22 17:57:59 -0800
committerAnsis Brammanis <brammanis@gmail.com>2016-01-22 18:00:49 -0800
commit5cd123422ed026912c53c44a393f141f990a09df (patch)
tree10c072d3b8c666db4ada0fb03b5eb1580bc5ad5e
parent556690fae81fa657d7888c29a3d5e02aad1489f1 (diff)
downloadqtlocation-mapboxgl-5cd123422ed026912c53c44a393f141f990a09df.tar.gz
[core] fix missing icon collision boxes
port https://github.com/mapbox/mapbox-gl-js/pull/1981
-rw-r--r--package.json2
-rw-r--r--src/mbgl/text/collision_feature.cpp20
-rw-r--r--src/mbgl/text/collision_feature.hpp8
3 files changed, 19 insertions, 11 deletions
diff --git a/package.json b/package.json
index 901519dd4c..93568a2eb9 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,7 @@
],
"devDependencies": {
"aws-sdk": "^2.2.21",
- "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#1b9035a02f8f23bf72a197c2a8d8f910d935346f",
+ "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#7a17d43bd8482a01dc165de6fff6ae4c33c4fc5d",
"node-gyp": "^3.2.1",
"request": "^2.67.0",
"tape": "^4.2.2"
diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp
index a84e75c85a..186fb39b5d 100644
--- a/src/mbgl/text/collision_feature.cpp
+++ b/src/mbgl/text/collision_feature.cpp
@@ -5,7 +5,7 @@ namespace mbgl {
CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
const float top, const float bottom, const float left, const float right,
- const float boxScale, const float padding, const bool alongLine) {
+ const float boxScale, const float padding, const bool alongLine, const bool straight) {
if (top == 0 && bottom == 0 && left == 0 && right == 0) return;
@@ -22,14 +22,24 @@ CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const An
height = std::max(10.0f * boxScale, height);
- bboxifyLabel(line, anchor, length, height);
+ Coordinate anchorPoint(int16_t(anchor.x), int16_t(anchor.y));
+
+ if (straight) {
+ // used for icon labels that are aligned with the line, but don't curve along it
+ const vec2<double> vector = util::unit(vec2<double>(line[anchor.segment + 1] - line[anchor.segment])) * length;
+ const std::vector<Coordinate> newLine({ anchorPoint - vector, anchorPoint + vector });
+ bboxifyLabel(newLine, anchorPoint, 0, length, height);
+ } else {
+ // used for text labels that curve along a line
+ bboxifyLabel(line, anchorPoint, anchor.segment, length, height);
+ }
} else {
boxes.emplace_back(anchor, x1, y1, x2, y2, std::numeric_limits<float>::infinity());
}
}
void CollisionFeature::bboxifyLabel(const std::vector<Coordinate> &line,
- const Anchor &anchor, const float labelLength, const float boxSize) {
+ Coordinate &anchorPoint, const int segment, const float labelLength, const float boxSize) {
const float step = boxSize / 2;
const unsigned int nBoxes = std::floor(labelLength / step);
@@ -38,10 +48,8 @@ void CollisionFeature::bboxifyLabel(const std::vector<Coordinate> &line,
// box is at the edge of the label.
const float firstBoxOffset = -boxSize / 2;
- Coordinate anchorPoint = Coordinate{ (int16_t)anchor.x, (int16_t)anchor.y };
-
Coordinate &p = anchorPoint;
- int index = anchor.segment + 1;
+ int index = segment + 1;
float anchorDistance = firstBoxOffset;
// move backwards along the line to the first segment the label appears on
diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp
index f112e17d85..a9d227de1b 100644
--- a/src/mbgl/text/collision_feature.hpp
+++ b/src/mbgl/text/collision_feature.hpp
@@ -37,7 +37,7 @@ namespace mbgl {
const float boxScale, const float padding, const bool alongLine)
: CollisionFeature(line, anchor,
shapedText.top, shapedText.bottom, shapedText.left, shapedText.right,
- boxScale, padding, alongLine) {}
+ boxScale, padding, alongLine, false) {}
// for icons
inline explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
@@ -45,17 +45,17 @@ namespace mbgl {
const float boxScale, const float padding, const bool alongLine)
: CollisionFeature(line, anchor,
shapedIcon.top, shapedIcon.bottom, shapedIcon.left, shapedIcon.right,
- boxScale, padding, alongLine) {}
+ boxScale, padding, alongLine, true) {}
explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor,
const float top, const float bottom, const float left, const float right,
- const float boxScale, const float padding, const bool alongLine);
+ const float boxScale, const float padding, const bool alongLine, const bool straight);
std::vector<CollisionBox> boxes;
private:
- void bboxifyLabel(const std::vector<Coordinate> &line, const Anchor &anchor, const float length, const float height);
+ void bboxifyLabel(const std::vector<Coordinate> &line, Coordinate &anchorPoint, const int segment, const float length, const float height);
};
} // namespace mbgl