From 07e23967d80d889a1ee6819a2a8b2fc9c2168616 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 16 Jan 2015 16:21:14 -0500 Subject: [PATCH] eamlessly join odd-length dasharrays js: 8314099fa4165714c743ebe891fcff0e618ebcde --- src/mbgl/geometry/line_atlas.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index fa5535a8c..b396d9325 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -57,6 +57,9 @@ LinePatternPos LineAtlas::addDash(const std::vector &dasharray, bool roun float stretch = width / length; float halfWidth = stretch * 0.5; + // If dasharray has an odd length, both the first and last parts + // are dashes and should be joined seamlessly. + bool oddLength = dasharray.size() % 2 == 1; for (int y = -n; y <= n; y++) { int row = nextRow + n + y; @@ -64,13 +67,22 @@ LinePatternPos LineAtlas::addDash(const std::vector &dasharray, bool roun float left = 0; float right = dasharray[0]; - int partIndex = 1; + unsigned int partIndex = 1; + + if (oddLength) { + left -= dasharray.back(); + } for (int x = 0; x < width; x++) { while (right < x / stretch) { left = right; right = right + dasharray[partIndex]; + + if (oddLength && partIndex == dasharray.size() - 1) { + right += dasharray.front(); + } + partIndex++; }