diff --git a/packages/core/src/path.mjs b/packages/core/src/path.mjs index 265887071eb..22fcbfb846c 100644 --- a/packages/core/src/path.mjs +++ b/packages/core/src/path.mjs @@ -814,10 +814,10 @@ Path.prototype.split = function (point) { if (path.ops[1].type === 'line') { if (pointOnLine(path.ops[0].to, path.ops[1].to, point)) { firstHalf = divided.slice(0, pi) - firstHalf.push(new Path().__withLog(this.log).move(path.ops[0].to).line(point.copy())) + firstHalf.push(new Path().__withLog(this.log).move(path.ops[0].to).line(point)) pi++ secondHalf = divided.slice(pi) - secondHalf.unshift(new Path().__withLog(this.log).move(point.copy()).line(path.ops[1].to)) + secondHalf.unshift(new Path().__withLog(this.log).move(point).line(path.ops[1].to)) break } } else if (path.ops[1].type === 'curve') { diff --git a/packages/core/tests/path.test.mjs b/packages/core/tests/path.test.mjs index a3b0bee5fc0..3c448096ef2 100644 --- a/packages/core/tests/path.test.mjs +++ b/packages/core/tests/path.test.mjs @@ -600,6 +600,19 @@ describe('Path', () => { expect(halves[1].ops[0].to.y).to.equal(30) }) + it('Should split a path on roughly a line joint', () => { + const a = new Point(45, 60) + const b = new Point(10, 30) + const c = new Point(90, 30) + const test = new Path().move(a).line(b).line(c) + + let halves = test.split(new Point(10.1, 29.9)) + expect(halves[0].ops[1].to.x).to.equal(10.1) + expect(halves[0].ops[1].to.y).to.equal(29.9) + expect(halves[1].ops[0].to.x).to.equal(10.1) + expect(halves[1].ops[0].to.y).to.equal(29.9) + }) + it('Should split a path on a curve joint', () => { const a = new Point(45, 60) const b = new Point(10, 30)