Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
eamlessly join odd-length dasharrays
Browse files Browse the repository at this point in the history
js: 8314099fa4165714c743ebe891fcff0e618ebcde
  • Loading branch information
ansis committed Jan 16, 2015
1 parent 200b1ce commit 07e2396
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/mbgl/geometry/line_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,32 @@ 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;
int index = width * row;

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++;
}

Expand Down

0 comments on commit 07e2396

Please sign in to comment.