Build with this node

Start with a prompt in Studio, or copy it into your own coding agent.

Ask Studio

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

RoutineCodes
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
ccw3p1 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-5 rather than Math.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 n closes from corner 1023 to corner 0. n ≤ 0 reads nothing: outside, area 0.
  • cosAngleBetween and distLinePoint read at most three components; cosAngleBetween clamps to −1 to 1 and tolerates zero vectors.
  • clampLibroom keeps upstream's branch order, so reversed bounds return the minimum for values below it. libroom's Line<D> is not ported.

Algorithm properties and proofs

No Lean 4 proof is mapped to this node.

Explore proofs alongside performance

Dependencies

None: this node imports no other node.

Dependents

Used by