Replace placement calls with region nodes
This commit is contained in:
1 parent
f437495309
commit
71c9c39523
23 files changed
+374
-170
No files matched your search
+30
-13
@@ -25,11 +25,27 @@ impl Holds {
|
||||
};
|
||||
|
||||
pub const fn at(len: f32) -> Self {
|
||||
Self { lo: len, hi: len }
|
||||
Self::tolerant(len, len)
|
||||
}
|
||||
|
||||
const fn tolerant(lo: f32, hi: f32) -> Self {
|
||||
Self {
|
||||
lo: lo - HOLDS_EPSILON_PX,
|
||||
hi: hi + HOLDS_EPSILON_PX,
|
||||
}
|
||||
}
|
||||
|
||||
/// A range whose endpoints are exact, for a widget decision with a hard
|
||||
/// boundary rather than an accumulated coordinate-rounding difference.
|
||||
pub fn exact(range: RangeInclusive<f32>) -> Self {
|
||||
Self {
|
||||
lo: *range.start(),
|
||||
hi: *range.end(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains(&self, len: f32) -> bool {
|
||||
len >= self.lo - HOLDS_EPSILON_PX && len <= self.hi + HOLDS_EPSILON_PX
|
||||
len >= self.lo && len <= self.hi
|
||||
}
|
||||
|
||||
pub fn and(self, other: Self) -> Self {
|
||||
@@ -57,10 +73,7 @@ impl Holds {
|
||||
|
||||
impl From<RangeInclusive<f32>> for Holds {
|
||||
fn from(range: RangeInclusive<f32>) -> Self {
|
||||
Self {
|
||||
lo: *range.start(),
|
||||
hi: *range.end(),
|
||||
}
|
||||
Self::tolerant(*range.start(), *range.end())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,12 +83,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn through_reverses_a_range_for_a_negative_fraction() {
|
||||
assert_eq!(
|
||||
Holds { lo: 20.0, hi: 40.0 }.through(UiScalar::new(-0.5, 10.0)),
|
||||
Holds {
|
||||
lo: -60.0,
|
||||
hi: -20.0
|
||||
}
|
||||
);
|
||||
let holds = Holds::from(20.0..=40.0).through(UiScalar::new(-0.5, 10.0));
|
||||
assert!((holds.lo - -60.1).abs() < 0.001);
|
||||
assert!((holds.hi - -19.9).abs() < 0.001);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_exact_open_boundary_does_not_admit_the_boundary() {
|
||||
let boundary = 10.0_f32;
|
||||
let above = Holds::exact(boundary.next_up()..=f32::INFINITY);
|
||||
assert!(!above.contains(boundary));
|
||||
assert!(above.contains(boundary.next_up()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user