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

@ -0,0 +1,45 @@
---
title: utils.beamIntersectsLine()
---
The `utils.beamIntersectsLine()` function finds the intersection between an endless
line (beam) and a (limited) line segment. Returns a [Point](/reference/api/point) object for the
intersection, or `false` if the beam doesn't intersect the line.
The first two points in the parameter list form the beam, the last two points form the line.
## Signature
```js
Point | false utils.beamIntersectsLine(
Point beamA,
Point beamB,
Point lineA,
Point lineB
)
```
## Example
<Example caption="A Utils.beamIntersectsLine() example">
```js
;({ Point, points, Path, paths, Snippet, snippets, utils, part }) => {
points.A = new Point(45, 20)
points.B = new Point(60, 15)
points.C = new Point(10, 10)
points.D = new Point(50, 40)
paths.AB = new Path().move(points.A).line(points.B).addClass('dotted')
paths.CD = new Path().move(points.C).line(points.D)
snippets.x = new Snippet(
'notch',
utils.beamIntersectsLine(points.A, points.B, points.C, points.D)
)
return part
}
```
</Example>