pub type Row = u16;
pub type Col = u16;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Pos {
pub offset: usize,
pub row: Row,
pub col: Col,
}
impl Pos {
pub const fn start() -> Self {
Pos {
offset: 0,
row: 1,
col: 1,
}
}
pub const fn right(self) -> Self {
Pos {
offset: self.offset + 1,
row: self.row,
col: self.col + 1,
}
}
pub const fn down(self) -> Self {
Pos {
offset: self.offset + 1,
row: self.row + 1,
col: 1,
}
}
}
impl Default for Pos {
fn default() -> Self {
Pos::start()
}
}
impl std::fmt::Display for Pos {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let Pos { offset, row, col } = *self;
write!(f, "Pos(offset {offset} column {col} row {row})")
}
}