#[derive(Clone, Debug)]
pub struct RankMap {
width: u16,
height: u16,
ranks: Vec<Option<f32>>,
}
impl RankMap {
pub fn new(width: u16, height: u16) -> Self {
RankMap {
width,
height,
ranks: vec![None; width as usize * height as usize],
}
}
pub fn width(&self) -> u16 {
self.width
}
pub fn height(&self) -> u16 {
self.height
}
#[inline]
fn index(&self, x: u16, y: u16) -> usize {
y as usize * self.width as usize + x as usize
}
pub fn set(&mut self, x: u16, y: u16, rank: f32) {
let i = self.index(x, y);
self.ranks[i] = Some(rank);
}
#[inline]
pub fn rank_at(&self, x: u16, y: u16) -> Option<f32> {
self.ranks.get(self.index(x, y)).copied().flatten()
}
#[inline]
pub fn visible_at(&self, x: u16, y: u16, progress: f32) -> bool {
matches!(self.rank_at(x, y), Some(r) if r <= progress)
}
pub fn ink_count(&self) -> usize {
self.ranks.iter().filter(|r| r.is_some()).count()
}
}