Skip to main content

use_uniform_polytope/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4/// Broad uniform polytope families.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum UniformPolytopeKind {
7    /// Regular polytopes.
8    Regular,
9    /// Quasiregular polytopes.
10    Quasiregular,
11    /// Archimedean solids and higher-dimensional analogues.
12    Archimedean,
13    /// Prismatic uniform families.
14    Prismatic,
15    /// Other named or not-yet-classified uniform families.
16    Other,
17}
18
19/// A lightweight uniform polytope descriptor.
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub struct UniformPolytope {
22    dimension: usize,
23    kind: UniformPolytopeKind,
24}
25
26impl UniformPolytope {
27    /// Creates a uniform polytope descriptor with positive dimension.
28    #[must_use]
29    pub const fn new(dimension: usize, kind: UniformPolytopeKind) -> Option<Self> {
30        if dimension > 0 {
31            Some(Self { dimension, kind })
32        } else {
33            None
34        }
35    }
36
37    /// Returns the dimension.
38    #[must_use]
39    pub const fn dimension(self) -> usize {
40        self.dimension
41    }
42
43    /// Returns the classification kind.
44    #[must_use]
45    pub const fn kind(self) -> UniformPolytopeKind {
46        self.kind
47    }
48}
49
50#[cfg(test)]
51mod tests {
52    use super::{UniformPolytope, UniformPolytopeKind};
53
54    #[test]
55    fn stores_uniform_polytope_metadata() {
56        let polytope = UniformPolytope::new(3, UniformPolytopeKind::Archimedean).expect("valid");
57
58        assert_eq!(polytope.dimension(), 3);
59        assert_eq!(polytope.kind(), UniformPolytopeKind::Archimedean);
60        assert_eq!(UniformPolytope::new(0, UniformPolytopeKind::Regular), None);
61    }
62}