Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/patternUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,20 @@ function projectPatternOnPointPath(pts, pattern) {
const endOffset = asRatioToPathLength(pattern.endOffset, totalPathLength);
const repeat = asRatioToPathLength(pattern.repeat, totalPathLength);

const repeatIntervalPixels = totalPathLength * repeat;
const startOffsetPixels = offset > 0 ? totalPathLength * offset : 0;
const endOffsetPixels = endOffset > 0 ? totalPathLength * endOffset : 0;

// 2. generate the positions of the pattern as offsets from the path start
const positionOffsets = [];
let positionOffset = startOffsetPixels;
do {
positionOffsets.push(positionOffset);
positionOffset += repeatIntervalPixels;
} while(repeatIntervalPixels > 0 && positionOffset < totalPathLength - endOffsetPixels);
if (repeat) {
const repeatIntervalPixels = totalPathLength * repeat;
const endOffsetPixels = endOffset > 0 ? totalPathLength * endOffset : 0;
let positionOffset = offset > 0 ? totalPathLength * offset : 0;

while(repeatIntervalPixels > 0 && positionOffset <= totalPathLength - endOffsetPixels) {
positionOffsets.push(positionOffset);
positionOffset += repeatIntervalPixels;
}
} else {
positionOffsets.push(offset > 0 ? totalPathLength * offset : 0);
}

// 3. projects offsets to segments
let segmentIndex = 0;
Expand Down