summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/check_max_angle.cpp11
-rw-r--r--src/mbgl/text/collision_feature.cpp20
-rw-r--r--src/mbgl/text/collision_feature.hpp8
-rw-r--r--src/mbgl/text/get_anchors.cpp6
4 files changed, 25 insertions, 20 deletions
diff --git a/src/mbgl/text/check_max_angle.cpp b/src/mbgl/text/check_max_angle.cpp
index 9109235798..0569767634 100644
--- a/src/mbgl/text/check_max_angle.cpp
+++ b/src/mbgl/text/check_max_angle.cpp
@@ -19,20 +19,19 @@ bool checkMaxAngle(const GeometryCoordinates& line,
const float windowSize,
const float maxAngle) {
// horizontal labels always pass
- if (anchor.segment < 0) return true;
+ if (!anchor.segment) return true;
GeometryCoordinate anchorPoint = convertPoint<int16_t>(anchor.point);
GeometryCoordinate &p = anchorPoint;
- int index = anchor.segment + 1;
+ std::size_t index = *anchor.segment + 1;
float anchorDistance = 0;
// move backwards along the line to the first segment the label appears on
while (anchorDistance > -labelLength / 2) {
- index--;
-
// there isn't enough room for the label after the beginning of the line
- if (index < 0) return false;
+ if (index == 0u) return false;
+ index--;
anchorDistance -= util::dist<float>(line[index], p);
p = line[index];
}
@@ -48,7 +47,7 @@ bool checkMaxAngle(const GeometryCoordinates& line,
while (anchorDistance < labelLength / 2) {
// there isn't enough room for the label before the end of the line
- if (index + 1 >= (int)line.size()) return false;
+ if (index + 1 >= line.size()) return false;
auto& prev = line[index - 1];
auto& current = line[index];
diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp
index f9f6b3a4a5..744ba916c6 100644
--- a/src/mbgl/text/collision_feature.cpp
+++ b/src/mbgl/text/collision_feature.cpp
@@ -34,7 +34,7 @@ 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, overscaling);
+ bboxifyLabel(line, anchorPoint, anchor.segment.value_or(0u), length, height, overscaling);
} else {
if (rotate) {
// Account for *-rotate in point collision boxes
@@ -61,8 +61,12 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates& line,
}
}
-void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoordinate& anchorPoint,
- const int segment, const float labelLength, const float boxSize, const float overscaling) {
+void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line,
+ GeometryCoordinate& anchorPoint,
+ std::size_t segment,
+ const float labelLength,
+ const float boxSize,
+ const float overscaling) {
const float step = boxSize / 2;
const int nBoxes = std::max(static_cast<int>(std::floor(labelLength / step)), 1);
@@ -82,16 +86,14 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoo
const float firstBoxOffset = -boxSize / 2;
GeometryCoordinate &p = anchorPoint;
- int index = segment + 1;
+ std::size_t index = segment + 1;
float anchorDistance = firstBoxOffset;
const float labelStartDistance = -labelLength / 2;
const float paddingStartDistance = labelStartDistance - labelLength / 8;
// move backwards along the line to the first segment the label appears on
do {
- index--;
-
- if (index < 0) {
+ if (index == 0u) {
if (anchorDistance > labelStartDistance) {
// there isn't enough room for the label after the beginning of the line
// checkMaxAngle should have already caught this
@@ -104,6 +106,7 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoo
}
}
+ index--;
anchorDistance -= util::dist<float>(line[index], p);
p = line[index];
} while (anchorDistance > paddingStartDistance);
@@ -131,7 +134,7 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoo
index++;
// There isn't enough room before the end of the line.
- if (index + 1 >= (int)line.size()) return;
+ if (index + 1 >= line.size()) return;
segmentLength = util::dist<float>(line[index], line[index + 1]);
}
@@ -159,5 +162,4 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoo
}
}
-
} // namespace mbgl
diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp
index 8767a5b6f7..ebda4a5673 100644
--- a/src/mbgl/text/collision_feature.hpp
+++ b/src/mbgl/text/collision_feature.hpp
@@ -122,8 +122,12 @@ public:
bool alongLine;
private:
- void bboxifyLabel(const GeometryCoordinates& line, GeometryCoordinate& anchorPoint,
- const int segment, const float length, const float height, const float overscaling);
+ void bboxifyLabel(const GeometryCoordinates& line,
+ GeometryCoordinate& anchorPoint,
+ std::size_t segment,
+ const float length,
+ const float height,
+ const float overscaling);
};
} // namespace mbgl
diff --git a/src/mbgl/text/get_anchors.cpp b/src/mbgl/text/get_anchors.cpp
index c38e181181..a2401a020a 100644
--- a/src/mbgl/text/get_anchors.cpp
+++ b/src/mbgl/text/get_anchors.cpp
@@ -40,7 +40,7 @@ static Anchors resample(const GeometryCoordinates& line,
assert(spacing > 0.0);
- int i = 0;
+ std::size_t i = 0u;
for (auto it = line.begin(), end = line.end() - 1; it != end; it++, i++) {
const GeometryCoordinate& a = *(it);
const GeometryCoordinate& b = *(it + 1);
@@ -147,8 +147,8 @@ optional<Anchor> getCenterAnchor(const GeometryCoordinates& line,
float prevDistance = 0;
const float centerDistance = getLineLength(line) / 2;
-
- int i = 0;
+
+ std::size_t i = 0u;
for (auto it = line.begin(), end = line.end() - 1; it != end; it++, i++) {
const GeometryCoordinate& a = *(it);
const GeometryCoordinate& b = *(it + 1);