fix(core): Fix bug in path.shiftAlong
This bug would be triggered by an edge-case where we have a path that is made up of multiple curves/lines. If the distance to shift lies just beyond the end of one segment, yet the remaining distance is smaller than the step (by default that means smaller than 1/25mm) no point would be returned. This closes #1140
This commit is contained in:
parent
736ce6d854
commit
c463b10e43
5 changed files with 42 additions and 4 deletions
|
@ -429,8 +429,9 @@ Path.prototype.shiftAlong = function (distance, stepsPerMm = 25) {
|
|||
let op = this.ops[i]
|
||||
if (op.type === 'line') {
|
||||
let thisLen = op.to.dist(current)
|
||||
if (Math.abs((len + thisLen) - distance) < 0.1) return op.to
|
||||
if (len + thisLen > distance) return current.shiftTowards(op.to, distance - len)
|
||||
else len += thisLen
|
||||
len += thisLen
|
||||
} else if (op.type === 'curve') {
|
||||
let bezier = new Bezier(
|
||||
{ x: current.x, y: current.y },
|
||||
|
@ -439,9 +440,9 @@ Path.prototype.shiftAlong = function (distance, stepsPerMm = 25) {
|
|||
{ x: op.to.x, y: op.to.y }
|
||||
)
|
||||
let thisLen = bezier.length()
|
||||
if (len + thisLen > distance)
|
||||
return shiftAlongBezier(distance - len, bezier, thisLen * stepsPerMm)
|
||||
else len += thisLen
|
||||
if (Math.abs((len + thisLen) - distance) < 0.1) return op.to
|
||||
if (len + thisLen > distance) return shiftAlongBezier(distance - len, bezier, thisLen * stepsPerMm)
|
||||
len += thisLen
|
||||
}
|
||||
current = op.to
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue