#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Polytope {
dimension: usize,
vertex_count: usize,
facet_count: usize,
}
impl Polytope {
#[must_use]
pub const fn new(dimension: usize, vertex_count: usize, facet_count: usize) -> Option<Self> {
if dimension > 0 && vertex_count > 0 && facet_count > 0 {
Some(Self {
dimension,
vertex_count,
facet_count,
})
} else {
None
}
}
#[must_use]
pub const fn dimension(self) -> usize {
self.dimension
}
#[must_use]
pub const fn vertex_count(self) -> usize {
self.vertex_count
}
#[must_use]
pub const fn facet_count(self) -> usize {
self.facet_count
}
}
#[cfg(test)]
mod tests {
use super::Polytope;
#[test]
fn stores_polytope_counts() {
let polytope = Polytope::new(4, 8, 16).expect("valid polytope");
assert_eq!(polytope.dimension(), 4);
assert_eq!(polytope.vertex_count(), 8);
assert_eq!(polytope.facet_count(), 16);
assert_eq!(Polytope::new(0, 8, 16), None);
}
}