1
0
Fork 0

fix(core): Make Path.clean() check for valid paths before returning

A path that has no drawing operations or only a move operation causes
problems with the path offset code.

This will cause Path.clean() to return false in such a case, which in
turn will cause Path.__asPath() to return false when called from the
offset code.

We check this return value in the offset code and do not push this
segment to the offsetted path.

This fixes #3038
This closes #3056
This commit is contained in:
joostdecock 2023-04-10 11:27:07 +02:00
parent a764ebb6cb
commit 5ba6e12469

View file

@ -192,7 +192,8 @@ Path.prototype.clean = function () {
if (ops.length < this.ops.length) this.ops = ops
return this
// A path with not drawing operations or only a move is not path at all
return ops.length === 0 || (ops.length === 1 && ops[0].type === 'move') ? false : this
}
/**
@ -1311,7 +1312,10 @@ function __pathOffset(path, distance, log) {
{ x: cp2.x, y: cp2.y },
{ x: op.to.x, y: op.to.y }
)
for (let bezier of b.offset(distance)) offset.push(__asPath(bezier, path.log))
for (let bezier of b.offset(distance)) {
const segment = __asPath(bezier, path.log)
if (segment) offset.push(segment)
}
} else if (op.type === 'close') closed = true
if (op.to) current = op.to
if (!start) start = current