use_uniform_polytope/
lib.rs1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum UniformPolytopeKind {
7 Regular,
9 Quasiregular,
11 Archimedean,
13 Prismatic,
15 Other,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub struct UniformPolytope {
22 dimension: usize,
23 kind: UniformPolytopeKind,
24}
25
26impl UniformPolytope {
27 #[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 #[must_use]
39 pub const fn dimension(self) -> usize {
40 self.dimension
41 }
42
43 #[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}