1
0
Fork 0

Add test case for code coverage, and implement two Joost comments.

This commit is contained in:
woutervdub 2023-12-16 22:09:22 +00:00
parent e1fa8286d4
commit 3cef72975e
2 changed files with 15 additions and 2 deletions

View file

@ -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') {

View file

@ -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)