Ray against boxes
64-bitCalls back for every item whose box a ray passes through.
t₀ = max(nearₐ), t₁ = min(farₐ); hit if t₀ ≤ t₁
Slab test in 64-bit with the inverse direction 1 / d. If a slab distance is NaN (origin on a slab plane with zero direction) the ray is kept only if the origin lies inside that slab. The test is on boxes, not on the item itself.
ray(o, d, cb, tmax = Infinity) {
const ix = 1 / d[0], iy = 1 / d[1], iz = 1 / d[2];
return this.walk((lo, hi) => {
let t0 = 0, t1 = typeof tmax === 'number' ? tmax : tmax.t;
for (let a = 0; a < 3; a++) {
const inv = a === 0 ? ix : a === 1 ? iy : iz;
let n = (lo[a] - o[a]) * inv, f = (hi[a] - o[a]) * inv;
if (Number.isNaN(n) || Number.isNaN(f)) { if (o[a] < lo[a] || o[a] > hi[a]) return false; continue; } // along a side
if (n > f) { const s = n; n = f; f = s; }
if (n > t0) t0 = n;
if (f < t1) t1 = f;
if (t0 > t1) return false;
}
return true;
}, cb);
}