pub const UP: u8 = 1;
pub const DOWN: u8 = 2;
pub const LEFT: u8 = 4;
pub const RIGHT: u8 = 8;
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Cell {
pub arms: u8,
pub color: usize,
pub node: bool,
}
impl Cell {
pub const fn line(arms: u8, color: usize) -> Self {
Self {
arms,
color,
node: false,
}
}
pub const fn glyph(self) -> char {
if self.node {
return '●';
}
match self.arms {
0 => ' ',
1..=3 => '│',
4 | 8 | 12 => '─',
5 => '╯',
6 => '╮',
7 => '┤',
9 => '╰',
10 => '╭',
11 => '├',
13 => '┴',
14 => '┬',
_ => '┼',
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_arm_set_and_the_node() {
let glyphs: String = (0..16).map(|arms| Cell::line(arms, 0).glyph()).collect();
assert_eq!(glyphs, " │││─╯╮┤─╰╭├─┴┬┼");
assert_eq!(
Cell {
node: true,
..Cell::default()
}
.glyph(),
'●'
);
}
}