summaryrefslogtreecommitdiff
path: root/src/mbgl/layout
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-12-09 15:23:12 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-12-09 17:26:13 +0200
commit89665326c2251608ac2f3408f73b781a23fb1ba5 (patch)
tree0d17ccea6e047343d347340b159fdb6b48d3910d /src/mbgl/layout
parentd36958997b7db19d9d5e9ec8e5ea06210a598502 (diff)
downloadqtlocation-mapboxgl-89665326c2251608ac2f3408f73b781a23fb1ba5.tar.gz
[core] Add unit test for calculateTileDistances
Diffstat (limited to 'src/mbgl/layout')
-rw-r--r--src/mbgl/layout/symbol_layout.cpp6
-rw-r--r--src/mbgl/layout/symbol_layout.hpp3
2 files changed, 5 insertions, 4 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 2e339af482..fc8af2c076 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -693,12 +693,12 @@ bool SymbolLayout::anchorIsTooClose(const std::u16string& text, const float repe
// Analog of `addToLineVertexArray` in JS. This version doesn't need to build up a line array like the
// JS version does, but it uses the same logic to calculate tile distances.
-std::vector<float> CalculateTileDistances(const GeometryCoordinates& line, const Anchor& anchor) {
+std::vector<float> SymbolLayout::calculateTileDistances(const GeometryCoordinates& line, const Anchor& anchor) {
std::vector<float> tileDistances(line.size());
if (anchor.segment) {
std::size_t segment = *anchor.segment;
assert(segment < line.size());
- auto sumForwardLength = util::dist<float>(anchor.point, line[segment + 1]);
+ auto sumForwardLength = (segment + 1 < line.size()) ? util::dist<float>(anchor.point, line[segment + 1]) : .0f;
auto sumBackwardLength = util::dist<float>(anchor.point, line[segment]);
for (std::size_t i = segment + 1; i < line.size(); ++i) {
tileDistances[i] = sumForwardLength;
@@ -842,7 +842,7 @@ std::size_t SymbolLayout::addSymbolGlyphQuads(SymbolBucket& bucket,
symbolInstance.textOffset,
writingMode,
symbolInstance.line(),
- CalculateTileDistances(symbolInstance.line(), symbolInstance.anchor),
+ calculateTileDistances(symbolInstance.line(), symbolInstance.anchor),
placedIconIndex);
placedIndex = bucket.text.placedSymbols.size() - 1;
PlacedSymbol& placedSymbol = bucket.text.placedSymbols.back();
diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp
index 8f6e4595e3..57a104bf45 100644
--- a/src/mbgl/layout/symbol_layout.hpp
+++ b/src/mbgl/layout/symbol_layout.hpp
@@ -55,7 +55,8 @@ public:
* @return std::array<float, 2> offset along x- and y- axis correspondingly.
*/
static std::array<float, 2> evaluateVariableOffset(style::SymbolAnchorType anchor, std::array<float, 2> textOffset);
-
+
+ static std::vector<float> calculateTileDistances(const GeometryCoordinates& line, const Anchor& anchor);
private:
void addFeature(const size_t,