#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Window {
pub lo: i32,
}
impl Window {
#[must_use]
pub fn around(y: f64, (min_y, height): (i32, i32)) -> Window {
let top = min_y + height.max(256);
let want = (y.floor() as i32 - 128).div_euclid(16) * 16;
Window {
lo: want.clamp(min_y, top - 256),
}
}
#[must_use]
pub fn keeps(&self, y: f64, (min_y, height): (i32, i32)) -> bool {
let y = y.floor() as i32;
let at_floor = self.lo == min_y;
let at_top = self.lo + 256 >= min_y + height;
(at_floor || y >= self.lo + 32) && (at_top || y < self.lo + 224)
}
}