From 89665326c2251608ac2f3408f73b781a23fb1ba5 Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Mon, 9 Dec 2019 15:23:12 +0200 Subject: [core] Add unit test for calculateTileDistances --- src/mbgl/layout/symbol_layout.cpp | 6 +++--- src/mbgl/layout/symbol_layout.hpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') 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 CalculateTileDistances(const GeometryCoordinates& line, const Anchor& anchor) { +std::vector SymbolLayout::calculateTileDistances(const GeometryCoordinates& line, const Anchor& anchor) { std::vector tileDistances(line.size()); if (anchor.segment) { std::size_t segment = *anchor.segment; assert(segment < line.size()); - auto sumForwardLength = util::dist(anchor.point, line[segment + 1]); + auto sumForwardLength = (segment + 1 < line.size()) ? util::dist(anchor.point, line[segment + 1]) : .0f; auto sumBackwardLength = util::dist(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 offset along x- and y- axis correspondingly. */ static std::array evaluateVariableOffset(style::SymbolAnchorType anchor, std::array textOffset); - + + static std::vector calculateTileDistances(const GeometryCoordinates& line, const Anchor& anchor); private: void addFeature(const size_t, -- cgit v1.2.1