Module rect_fast

Module rect_fast 

Source
Expand description

Analytic fast path for axis-aligned rectangular openings cut through an axis-aligned box host (the dominant case: rectangular windows/doors in a straight wall). This sidesteps the exact mesh-arrangement CSG kernel — which is at its single-threaded, memory-bandwidth-bound floor — for openings that need no exact arithmetic at all.

WATERTIGHTNESS RECIPE (the make-or-break the prior subtract_box_fast attempt got wrong by recomputing rim coords on an incommensurate grid):

  • Build the cut on ONE canonical grid whose lines are the host edges plus every opening edge, each value SNAPPED to the kernel’s own power-of-two SNAP_GRID = 1/65536 (the grid the host operand already lives on).
  • CONFORMING-split every face by the crossing grid lines (no T-junctions): the front/back faces become a grid of cells with hole cells omitted; the side faces are split at the hole grid lines so their shared edge with the annulus matches sub-edge for sub-edge.
  • Every vertex reads its position from the SAME snapped grid value, so two faces meeting at a shared line emit BIT-IDENTICAL f32 → watertight by construction (value identity, not a numeric hash-match).
  • Per-face flat normals; vertices are NEVER welded across creases (#846).

GATING: this is a PURE OPTIMIZATION. It returns None (→ caller falls back to the exact kernel) the moment any precondition fails — non-box host, non- through opening, opening off the face, or a NEAR-EDGE feature whose grid lines would collapse into each other at the host’s f32 magnitude (the robustness gate that replaces a hard dependency on the per-element local frame).

Structs§

RectFastStats
Telemetry: why the fast path fired or deferred, so the real fire-rate on a void-heavy model is measurable (the prior attempt shipped at fired=0).

Functions§

enabled
Escape hatch: IFC_LITE_RECT_FAST=0 is the GLOBAL rect-fast kill switch. It forces every opening back through the exact kernel (parity debugging / bisection) by disabling BOTH the legacy world-axis-aligned path gated here AND the parametric placement-frame path (param_enabled honours it), so setting this single flag is sufficient to route all rectangular openings through CSG. Default ON: the path is a pure optimization that defers on any precondition miss. To disable only the parametric path, set IFC_LITE_RECT_PARAM=0 instead.
param_enabled
PARAMETRIC rectangular-opening fast path (placement-frame, ground-truth-exact cut). DEFAULT ON – opt out with IFC_LITE_RECT_PARAM=0 (parametric path only), IFC_LITE_RECT_FAST=0 (the GLOBAL rect-fast kill switch: disables this path AND the legacy enabled path, preserving the documented single-flag parity/bisection hatch), or param_set_enabled_override. Gated separately from enabled because it is a deliberate behaviour change: it emits the analytic box-minus-boxes solid, which is MORE correct than the exact kernel on engulfing-opening walls. Corpus-validated ON (tests/rect_param_validate.rs A/B over 5 real models): every non-firing element byte-identical ON vs OFF, every firing host watertight and matching the analytic ground truth. wasm has no env, so std::env::var errs there and the default is ON on both targets – native==wasm stays in lockstep; the wasm-side setRectParamFastPath override remains the programmatic escape hatch (and, being an explicit per-process call, takes precedence over both env flags).
param_record_fire
Count one parametric fast-path fire (the analytic cut was emitted).
param_set_enabled_override
Test-only: force param_enabled() on/off (or None for the env default).
subtract_rect_openings
Result of the cut: a watertight Mesh, or None to defer to the exact kernel. openings are world AABBs (min,max) of axis-aligned rectangular cutters. Handles WINDOWS, DOORS (flush to an edge), recesses, and overlapping openings uniformly via a 3D CELLULAR decomposition: split the host box by every opening plane on all three axes, mark each cell solid (in the host, outside every opening) or void, and emit each cell face that borders a void cell or the grid boundary. Watertight by construction — adjacent cells share snapped grid vertices bit-identically, so no T-junctions and no cracks.
take_param_fires
Read + reset the parametric fast-path fire counter.