#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CellGeometry {
pub glyph_w: u8,
pub glyph_h: u8,
pub scale: u16,
}
impl CellGeometry {
#[must_use]
pub const fn new(glyph_w: u8, glyph_h: u8, scale: u16) -> Self {
Self {
glyph_w,
glyph_h,
scale,
}
}
#[must_use]
pub const fn cell_size(&self) -> (u32, u32) {
(
self.glyph_w as u32 * self.scale as u32,
self.glyph_h as u32 * self.scale as u32,
)
}
#[must_use]
pub const fn surface_size(&self, cols: u16, rows: u16) -> (u32, u32) {
let (cell_w, cell_h) = self.cell_size();
(cols as u32 * cell_w, rows as u32 * cell_h)
}
}
#[cfg(test)]
mod tests {
use super::CellGeometry;
#[test]
fn cell_size_is_glyph_times_scale() {
assert_eq!(CellGeometry::new(8, 16, 1).cell_size(), (8, 16));
assert_eq!(CellGeometry::new(8, 16, 2).cell_size(), (16, 32));
assert_eq!(CellGeometry::new(6, 12, 3).cell_size(), (18, 36));
}
#[test]
fn surface_size_is_grid_times_cell() {
assert_eq!(CellGeometry::new(8, 16, 1).surface_size(80, 25), (640, 400));
assert_eq!(
CellGeometry::new(8, 16, 2).surface_size(80, 25),
(1280, 800)
);
}
#[test]
fn zero_grid_is_zero_surface() {
assert_eq!(CellGeometry::new(8, 16, 2).surface_size(0, 0), (0, 0));
}
}