summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/line_atlas.cpp
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2015-01-16 16:21:14 -0500
committerAnsis Brammanis <brammanis@gmail.com>2015-01-16 16:21:14 -0500
commit07e23967d80d889a1ee6819a2a8b2fc9c2168616 (patch)
tree79a7c818b1f721c1e06c08e6a249c565f743ac93 /src/mbgl/geometry/line_atlas.cpp
parent200b1ce449eb49e8c789aef7b23c59f00e7c681c (diff)
downloadqtlocation-mapboxgl-07e23967d80d889a1ee6819a2a8b2fc9c2168616.tar.gz
eamlessly join odd-length dasharrays
js: 8314099fa4165714c743ebe891fcff0e618ebcde
Diffstat (limited to 'src/mbgl/geometry/line_atlas.cpp')
-rw-r--r--src/mbgl/geometry/line_atlas.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index fa5535a8cd..b396d93259 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<float> &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<float> &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++;
}