diff --git a/core/src/orientation/pos.rs b/core/src/orientation/pos.rs index 566274b..28fd20a 100644 --- a/core/src/orientation/pos.rs +++ b/core/src/orientation/pos.rs @@ -292,6 +292,15 @@ impl UiSpan { pub const fn len(&self) -> Len { self.end - self.start } + + /// Both ends by the same amount, which is what moving a box without + /// changing its length does to every part of it. + pub const fn translated(self, by: Len) -> Self { + Self { + start: self.start + by, + end: self.end + by, + } + } } #[repr(C)] @@ -302,6 +311,17 @@ pub struct UiRegion { } impl UiRegion { + /// Every part of the box by the same amount on each axis. Done to the + /// whole region rather than an end at a time, because that is what it is + /// -- and because four adds in a row are four adds, where four asked for + /// separately are four sequences. + pub const fn translated(self, x: Len, y: Len) -> Self { + Self { + x: self.x.translated(x), + y: self.y.translated(y), + } + } + pub const FULL: Self = Self { x: UiSpan::FULL, y: UiSpan::FULL, diff --git a/core/src/ui/render_state.rs b/core/src/ui/render_state.rs index 664e0e3..8d4c15a 100644 --- a/core/src/ui/render_state.rs +++ b/core/src/ui/render_state.rs @@ -1090,6 +1090,14 @@ impl RegionRemap { } fn apply(&self, region: UiRegion) -> UiRegion { + // A box that only moved carries every part of itself by the same two + // amounts, and that is the common move. Asking it once for the whole + // region is what lets it be eight adds in a row rather than four + // sequences with a branch each -- measured, it is where the time in a + // move goes. + if let [AxisRemap::Translate(x), AxisRemap::Translate(y)] = self.axes { + return region.translated(x, y); + } UiRegion { x: self.axes[0].apply_span(region.x), y: self.axes[1].apply_span(region.y),