1#[derive(Clone, Debug)]
8pub struct RankMap {
9 width: u16,
10 height: u16,
11 ranks: Vec<Option<f32>>,
13}
14
15impl RankMap {
16 pub fn new(width: u16, height: u16) -> Self {
18 RankMap {
19 width,
20 height,
21 ranks: vec![None; width as usize * height as usize],
22 }
23 }
24
25 pub fn width(&self) -> u16 {
26 self.width
27 }
28
29 pub fn height(&self) -> u16 {
30 self.height
31 }
32
33 #[inline]
34 fn index(&self, x: u16, y: u16) -> usize {
35 y as usize * self.width as usize + x as usize
36 }
37
38 pub fn set(&mut self, x: u16, y: u16, rank: f32) {
40 let i = self.index(x, y);
41 self.ranks[i] = Some(rank);
42 }
43
44 #[inline]
46 pub fn rank_at(&self, x: u16, y: u16) -> Option<f32> {
47 self.ranks.get(self.index(x, y)).copied().flatten()
48 }
49
50 #[inline]
52 pub fn visible_at(&self, x: u16, y: u16, progress: f32) -> bool {
53 matches!(self.rank_at(x, y), Some(r) if r <= progress)
54 }
55
56 pub fn ink_count(&self) -> usize {
58 self.ranks.iter().filter(|r| r.is_some()).count()
59 }
60}