Module boolean

Source
Expand description

Scalar reference implementation of solid booleans (ADR 0012, ADR 0017 §5).

§Why this exists

ADR 0012 requires a scalar reference to land before an optimized provider, so conformance has something to be judged against. Booleans skipped that step: axiolid-mesh-boolean-boolmesh arrived first and was, for a while, the only definition of a correct result. A suite that only ever runs one implementation cannot tell “correct” from “self-consistent”.

§What “reference” means here

Correctness first, speed never. This deliberately uses the most direct algorithm that can be reasoned about line by line, because its job is to be obviously right, not fast:

  • Classification is by exact orient3d signs and ray parity, not by floating-point distance comparisons.
  • Work is O(n·m) with no acceleration structure. A BVH would be a second thing to get wrong, and an oracle with its own bugs is worse than none.

§Independence

This shares no code path with boolmesh. It does not subdivide against the other operand’s triangles; it classifies whole triangles by containment and keeps or drops them. That makes it a genuinely independent implementation for differential testing, at the cost of only being exact for operands whose surfaces do not interpenetrate.

§Honest limits

ScalarBoolean refuses inputs it cannot answer exactly rather than guessing. It is exact for:

  • disjoint operands (all four operations),
  • nested operands (one strictly inside the other),
  • identical operands,
  • properly intersecting surfaces, via crate::exact_boolean, which computes the intersection curve, retriangulates both operands along it, and keeps the pieces the operation asks for.

It still reports GeomError::Unsupported for coplanar faces that share an AREA – two solids flush over a whole face. The shared region’s boundary is currently derived per triangle pair, which yields edges interior to that region and a curve that branches. Continuing would produce a plausible wrong answer (measured: a Difference volume of 2.67 where the geometry says 8), so it refuses instead. Resolving it needs the overlap of the two face SETS per plane rather than of individual triangle pairs.

A refusal is typed, so a registry treats it as retryable and another provider answers.

Those cases already pin the algebra: identity, annihilation, idempotence, and containment. See tests/oracle.rs.

Structs§

ScalarBoolean
Portable scalar boolean reference.