diff --git a/core/src/orientation/pos.rs b/core/src/orientation/pos.rs index 28fd20a..495575b 100644 --- a/core/src/orientation/pos.rs +++ b/core/src/orientation/pos.rs @@ -282,7 +282,26 @@ impl UiSpan { self.end += offset; } + /// The whole of the box it sits in: a span that composes to nothing and + /// a parent that changes nothing. + pub const fn is_full(&self) -> bool { + self.start.rel.raw() == Rel::ZERO.raw() + && self.start.px.raw() == Px::ZERO.raw() + && self.end.rel.raw() == Rel::ONE.raw() + && self.end.px.raw() == Px::ZERO.raw() + } + pub const fn within(&self, parent: &Self) -> Self { + // A part that is the whole box is the box, and a box composed through + // the whole of its parent is itself. Both are exact -- multiplying by + // one rounds to what it started as -- and both are common enough to + // be worth four comparisons rather than four multiplies to find out. + if self.is_full() { + return *parent; + } + if parent.is_full() { + return *self; + } Self { start: self.start.within(parent), end: self.end.within(parent),