1
0
Fork 0

Fix and improve path intersection methods

- Add path.intersectsBeam() method
- Add utils.beamIntersectsLine() method
- Simplify calculation and improve precision on beam intersections
- Document return types properly
- beamIntersectsCurve now uses the proper function from Bezier library instead of emulating it by constructing a huge line
- docs: path.intersect... methods never return false, they simply return an empty array in case of no intersection
This commit is contained in:
Jonathan Haas 2024-09-25 14:06:17 +02:00
parent adf83eda8c
commit 4b83212f41
10 changed files with 262 additions and 39 deletions

View file

@ -603,6 +603,17 @@ describe('Path', () => {
expect(round(intersections[5].y)).to.equal(93.31)
})
it('Should find an intersection with a beam', () => {
const test = new Path()
.move(new Point(300, 400))
.line(new Point(300, 380))
.curve(new Point(350, 200), new Point(350, 100), new Point(350, 0))
let intersectsBeam = test.intersectsBeam(new Point(0, 370), new Point(100, 370))
expect(intersectsBeam.length).to.equal(1)
expect(round(intersectsBeam[0].x)).to.equal(302.75)
expect(round(intersectsBeam[0].y)).to.equal(370)
})
it('Should throw an error when running path.intersect on an identical path', () => {
const test = new Path()
expect(() => test.intersects(test)).to.throw()