use crate::Extent;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Count {
Stated(usize),
All,
AllAcross(usize),
Distributed(usize),
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(crate) enum GridCount {
Const(usize),
Extent(usize),
}
impl Count {
pub(crate) fn stated(self) -> Option<usize> {
match self {
Count::Stated(n) | Count::AllAcross(n) => Some(n),
Count::All | Count::Distributed(_) => None,
}
}
pub(crate) fn tiles(self, extent: usize, tile: usize) -> usize {
match self {
Count::Stated(n) | Count::Distributed(n) => n,
Count::All | Count::AllAcross(_) => extent.div_ceil(tile),
}
}
pub(crate) fn tiles_const(self, extent: Extent, tile: usize) -> Option<usize> {
match (self, extent) {
(Count::Stated(n) | Count::Distributed(n), _) => Some(n),
(_, Extent::Static(extent)) => Some(self.tiles(extent, tile)),
(_, Extent::Dynamic) => None,
}
}
pub(crate) fn grid(self, tile: usize) -> GridCount {
match self {
Count::Stated(n) | Count::Distributed(n) => GridCount::Const(n),
Count::All | Count::AllAcross(_) => GridCount::Extent(tile),
}
}
}
impl From<Count> for usize {
fn from(count: Count) -> usize {
count
.stated()
.expect("a units level's count is stated; every tile is the launch's")
}
}