@maruaudio/dsp/acoustics/geometry holds the 2-D and 3-D point, segment, plane and polygon routines that room walls and image sources build on, ported from pyroomacoustics' libroom geometry.cpp. It answers orientation (ccw3p, isLeft), segment intersection (checkIntersection2dSegments, intersection2dSegments, intersection3dSegmentPlane, onSegment), point-in-polygon by Sunday's winding number (isInside2dPolygon), signed polygon area (area2dPolygon), the cosine between vectors and the distance from a line to a point. Points are (buffer, offset) pairs in caller-owned Float64Arrays, as in @maru/acoustics-vec3.
Lifecycle
None: pure functions with upstream's integer return codes and ACOUSTICS_LIBROOM_EPS (1e-5 m). No allocation, recursion or closures.
| Routine | Codes |
|---|---|
| 2-D segments | −1 none, 0 proper crossing, 1 endpoint of a, 2 endpoint of b, 3 both |
| Segment and plane | −1 none (or lying in the plane), 0 interior crossing, 1 endpoint on the plane |
| Point in polygon | −1 outside, 0 inside, 1 on the boundary |
ccw3p | 1 counter-clockwise, −1 clockwise, 0 collinear within eps |
An intersection point is written to out only when there is an intersection.
When to use it
Wall intersection, reflection and visibility tests in a room model, or any place that must reproduce libroom's codes so results compare with upstream.
Limits
- f64 where upstream used f32, and eps compared as f64
1e-5rather thanMath.fround(1e-5); a tie within about 3e-13 of eps may move. - Polygons read at most 1,024 corners (a cap upstream lacks); a larger
ncloses from corner 1023 to corner 0.n ≤ 0reads nothing: outside, area 0. cosAngleBetweenanddistLinePointread at most three components;cosAngleBetweenclamps to −1 to 1 and tolerates zero vectors.clampLibroomkeeps upstream's branch order, so reversed bounds return the minimum for values below it. libroom'sLine<D>is not ported.