`Remap` existed to invert a composition, and a translation never needed one: shifting a box shifts everything composed into it by the same amount, because `lerp(s + d, e + d, t) == lerp(s, e, t) + d` on both channels. That holds whether or not the box has a relative extent, so the carry branch was answering a question it did not have to ask. So the decision is made once, before the walk, and neither relocation method branches. A translation is already one slot write. A change of length calls `UiRegion::stretch`, which re-expresses each part at its own fraction of the new box and needs `stretchable` -- a fixed length holds its parts as offsets from its start and keeps no fraction to stretch by. `Remap`, `UiScalar::outside`, `UiSpan::outside` and `LerpUtil::lerp_inv` are all gone with it. Nothing inverts a lerp any more: the one division is done against a denominator `stretchable` already established is not zero. What it gives up is the per-axis carry, so a box that changed length on one axis and not the other is redrawn where it used to be remapped. Counted: six of `tabs`'s fourteen relocations and five of `text`'s sixteen, and one extra redraw per frame on `replace_cost`'s 200 rows -- 354,310,889 instructions against 354,272,387, which is noise. Checked: fmt, clippy and 42 tests. `tabs` (with the image replay), `view`, `minimal` and `text` all still render byte-identical to `upstream/main`.
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
//! What a drawing can be taken out of, and what it cannot.
|
|
|
|
use iris::core::{UiRegion, UiScalar, UiSpan};
|
|
|
|
/// A box `size` tall whose top is `rel` of the way down the window.
|
|
fn fixed(rel: f32, size: f32) -> UiRegion {
|
|
UiRegion::new(
|
|
UiSpan::FULL,
|
|
UiSpan::new(UiScalar { rel, abs: 0.0 }, UiScalar { rel, abs: size }),
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn a_fixed_length_cannot_be_stretched_out_of() {
|
|
assert!(!fixed(0.0, 164.0).stretchable());
|
|
assert!(!fixed(0.5, 164.0).stretchable());
|
|
assert!(UiRegion::FULL.stretchable());
|
|
}
|
|
|
|
#[test]
|
|
fn a_stretch_keeps_each_part_at_its_fraction() {
|
|
let to = fixed(0.0, 98.0);
|
|
// A part filling the window fills what replaced it.
|
|
assert_eq!(UiRegion::FULL.stretch(&UiRegion::FULL, &to), to);
|
|
// And the middle half of it stays the middle half.
|
|
let half = UiRegion::new(
|
|
UiSpan::FULL,
|
|
UiSpan::new(UiScalar::rel(0.25), UiScalar::rel(0.75)),
|
|
);
|
|
assert_eq!(
|
|
half.stretch(&UiRegion::FULL, &to),
|
|
UiRegion::new(
|
|
UiSpan::FULL,
|
|
UiSpan::new(
|
|
UiScalar {
|
|
rel: 0.0,
|
|
abs: 24.5
|
|
},
|
|
UiScalar {
|
|
rel: 0.0,
|
|
abs: 73.5
|
|
}
|
|
)
|
|
)
|
|
);
|
|
}
|