Skip inverse arithmetic for unrestricted layout validity

This commit is contained in:
iris-ai committed 2026-09-17 15:53:24 -04:00
1 parent 39f7b08c6c
commit c330ecec2b
1 file changed
+13
+13
View File
@@ -52,6 +52,9 @@ impl Holds {
/// allowance: inverting it is two divisions and nothing else, and the /// allowance: inverting it is two divisions and nothing else, and the
/// whole of a box maps back to itself. /// whole of a box maps back to itself.
pub const fn through(self, len: Len) -> Self { pub const fn through(self, len: Len) -> Self {
if self.lo.raw() == Px::MIN.raw() && self.hi.raw() == Px::MAX.raw() {
return Self::ANY;
}
let rel = len.rel.raw() as i64; let rel = len.rel.raw() as i64;
if rel == 0 { if rel == 0 {
return Self::ANY; return Self::ANY;
@@ -92,6 +95,16 @@ mod tests {
use super::*; use super::*;
use crate::Rel; use crate::Rel;
#[test]
fn an_unrestricted_range_stays_unrestricted_through_any_length() {
for rel in [-2.0, -0.5, 0.0, 0.5, 1.0, 2.0] {
for px in [-8, 0, 8] {
let len = Len::from_parts(Rel::from_f32(rel), Px::from_int(px));
assert_eq!(Holds::ANY.through(len), Holds::ANY);
}
}
}
#[test] #[test]
fn through_reverses_a_range_for_a_negative_fraction() { fn through_reverses_a_range_for_a_negative_fraction() {
// `10 - box / 2` is between 20 and 40 for boxes from -60 to -20. // `10 - box / 2` is between 20 and 40 for boxes from -60 to -20.