Retire Remap: a translation shifts, and only a stretch needs a fraction
`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`.
This commit is contained in:
1 parent
78a53b6bf6
commit
db1751fdfd
5 files changed
+85
-99
No files matched your search
@@ -1,27 +0,0 @@
|
||||
//! What a drawing can be taken out of, and what it cannot.
|
||||
|
||||
use iris::core::{Remap, 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_box_can_be_carried_but_not_stretched() {
|
||||
let from = fixed(0.0, 164.0);
|
||||
assert!(Remap::new(from, UiRegion::FULL).is_none());
|
||||
assert!(Remap::new(from, fixed(0.5, 164.0)).is_some());
|
||||
assert!(Remap::new(from, fixed(0.0, 98.0)).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_relative_box_can_be_stretched_to_any_other() {
|
||||
let remap = Remap::new(UiRegion::FULL, fixed(0.0, 98.0)).expect("relative boxes remap");
|
||||
// A part that filled the window keeps filling what replaced it, which is
|
||||
// exactly what `outside` could not say for a box of a fixed length.
|
||||
assert_eq!(remap.apply(UiRegion::FULL), fixed(0.0, 98.0));
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//! 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
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user