Skip to main content

use_archimedean/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4/// The thirteen Archimedean solids.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum ArchimedeanSolid {
7    /// Truncated tetrahedron.
8    TruncatedTetrahedron,
9    /// Cuboctahedron.
10    Cuboctahedron,
11    /// Truncated cube.
12    TruncatedCube,
13    /// Truncated octahedron.
14    TruncatedOctahedron,
15    /// Rhombicuboctahedron.
16    Rhombicuboctahedron,
17    /// Truncated cuboctahedron.
18    TruncatedCuboctahedron,
19    /// Snub cube.
20    SnubCube,
21    /// Icosidodecahedron.
22    Icosidodecahedron,
23    /// Truncated dodecahedron.
24    TruncatedDodecahedron,
25    /// Truncated icosahedron.
26    TruncatedIcosahedron,
27    /// Rhombicosidodecahedron.
28    Rhombicosidodecahedron,
29    /// Truncated icosidodecahedron.
30    TruncatedIcosidodecahedron,
31    /// Snub dodecahedron.
32    SnubDodecahedron,
33}
34
35impl ArchimedeanSolid {
36    /// Returns the common lowercase name.
37    #[must_use]
38    pub const fn name(self) -> &'static str {
39        match self {
40            Self::TruncatedTetrahedron => "truncated tetrahedron",
41            Self::Cuboctahedron => "cuboctahedron",
42            Self::TruncatedCube => "truncated cube",
43            Self::TruncatedOctahedron => "truncated octahedron",
44            Self::Rhombicuboctahedron => "rhombicuboctahedron",
45            Self::TruncatedCuboctahedron => "truncated cuboctahedron",
46            Self::SnubCube => "snub cube",
47            Self::Icosidodecahedron => "icosidodecahedron",
48            Self::TruncatedDodecahedron => "truncated dodecahedron",
49            Self::TruncatedIcosahedron => "truncated icosahedron",
50            Self::Rhombicosidodecahedron => "rhombicosidodecahedron",
51            Self::TruncatedIcosidodecahedron => "truncated icosidodecahedron",
52            Self::SnubDodecahedron => "snub dodecahedron",
53        }
54    }
55
56    /// Returns a compact vertex face-configuration string.
57    #[must_use]
58    pub const fn face_configuration(self) -> &'static str {
59        match self {
60            Self::TruncatedTetrahedron => "3.6.6",
61            Self::Cuboctahedron => "3.4.3.4",
62            Self::TruncatedCube => "3.8.8",
63            Self::TruncatedOctahedron => "4.6.6",
64            Self::Rhombicuboctahedron => "3.4.4.4",
65            Self::TruncatedCuboctahedron => "4.6.8",
66            Self::SnubCube => "3.3.3.3.4",
67            Self::Icosidodecahedron => "3.5.3.5",
68            Self::TruncatedDodecahedron => "3.10.10",
69            Self::TruncatedIcosahedron => "5.6.6",
70            Self::Rhombicosidodecahedron => "3.4.5.4",
71            Self::TruncatedIcosidodecahedron => "4.6.10",
72            Self::SnubDodecahedron => "3.3.3.3.5",
73        }
74    }
75}
76
77#[cfg(test)]
78mod tests {
79    use super::ArchimedeanSolid;
80
81    #[test]
82    fn exposes_cuboctahedron_metadata() {
83        let solid = ArchimedeanSolid::Cuboctahedron;
84
85        assert_eq!(solid.name(), "cuboctahedron");
86        assert_eq!(solid.face_configuration(), "3.4.3.4");
87        assert_eq!(
88            ArchimedeanSolid::TruncatedIcosahedron.face_configuration(),
89            "5.6.6"
90        );
91    }
92}