Divide twice in a range's inverse, not four times

Which end of the answer each bound comes from is known from the sign of the
fraction before dividing; taking the min and max of four divisions asked the
question twice. A division is the most expensive thing in that function and
it runs per child per axis.

`many` 0.283 ms a frame to 0.278. Small, and strictly less work.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iris-aiandClaude Opus 5 committed 2026-09-16 04:06:46 -04:00
1 parent 97cc8b32ed
commit f11f5f4825
1 file changed
+5 -4
+5 -4
View File
@@ -64,11 +64,12 @@ impl Holds {
let half_rel = REL_SHIFT - 1;
let lo = ((self.lo.raw() as i64 - px) * 2 - 3) << half_rel;
let hi = ((self.hi.raw() as i64 - px) * 2 + 3) << half_rel;
let (a, b) = (div_toward(lo, rel, true), div_toward(hi, rel, false));
let (c, d) = (div_toward(lo, rel, false), div_toward(hi, rel, true));
// Dividing by a negative turns the ends around, so which end each
// bound comes from is decided before dividing rather than by taking
// the min and max of four divisions.
match rel > 0 {
true => Self::raws(a, b),
false => Self::raws(d, c),
true => Self::raws(div_toward(lo, rel, true), div_toward(hi, rel, false)),
false => Self::raws(div_toward(hi, rel, true), div_toward(lo, rel, false)),
}
}