use crate::grid::dimension::{Dimension, Estimate};
#[derive(Debug, Clone)]
pub struct StaticDimension {
width: DimensionValue,
height: DimensionValue,
}
impl StaticDimension {
pub fn new(width: DimensionValue, height: DimensionValue) -> Self {
Self { width, height }
}
}
impl From<StaticDimension> for (DimensionValue, DimensionValue) {
fn from(value: StaticDimension) -> Self {
(value.width, value.height)
}
}
impl Dimension for StaticDimension {
fn get_width(&self, column: usize) -> usize {
self.width.get(column)
}
fn get_height(&self, row: usize) -> usize {
self.height.get(row)
}
}
impl<R, C> Estimate<R, C> for StaticDimension {
fn estimate(&mut self, _: R, _: &C) {}
}
#[derive(Debug, Clone)]
pub enum DimensionValue {
Exact(usize),
List(Vec<usize>),
Partial(Vec<usize>, usize),
}
impl DimensionValue {
pub fn get(&self, col: usize) -> usize {
match self {
DimensionValue::Exact(val) => *val,
DimensionValue::List(cols) => cols[col],
DimensionValue::Partial(cols, val) => {
if cols.len() > col {
cols[col]
} else {
*val
}
}
}
}
}