pub const BLANK: char = '\u{2800}';
pub const DOT_1: u8 = 0x01;
pub const DOT_2: u8 = 0x02;
pub const DOT_3: u8 = 0x04;
pub const DOT_4: u8 = 0x08;
pub const DOT_5: u8 = 0x10;
pub const DOT_6: u8 = 0x20;
pub const DOT_7: u8 = 0x40;
pub const DOT_8: u8 = 0x80;
pub const DOTS: [[u8; 2]; 4] = [
[DOT_1, DOT_4],
[DOT_2, DOT_5],
[DOT_3, DOT_6],
[DOT_7, DOT_8],
];
#[must_use]
pub const fn glyph(pattern: u8) -> char {
#[allow(clippy::as_conversions)]
match char::from_u32(0x2800 + pattern as u32) {
Some(c) => c,
None => BLANK,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn glyph_zero_is_blank() {
assert_eq!(glyph(0), BLANK);
}
#[test]
fn glyph_covers_the_full_byte_range() {
for pattern in 0..=u8::MAX {
let c = glyph(pattern);
assert_eq!(u32::from(c), 0x2800 + u32::from(pattern));
}
}
#[test]
fn dots_table_has_eight_distinct_bits() {
let mut seen = 0u8;
for row in DOTS {
for bit in row {
assert_eq!(seen & bit, 0, "bit {bit:#04x} reused");
seen |= bit;
}
}
assert_eq!(seen, 0xFF);
}
}