Skip to main content

use_catalan_solid/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4use use_archimedean::ArchimedeanSolid;
5
6/// The thirteen Catalan solids.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum CatalanSolid {
9    /// Triakis tetrahedron.
10    TriakisTetrahedron,
11    /// Rhombic dodecahedron.
12    RhombicDodecahedron,
13    /// Triakis octahedron.
14    TriakisOctahedron,
15    /// Tetrakis hexahedron.
16    TetrakisHexahedron,
17    /// Deltoidal icositetrahedron.
18    DeltoidalIcositetrahedron,
19    /// Disdyakis dodecahedron.
20    DisdyakisDodecahedron,
21    /// Pentagonal icositetrahedron.
22    PentagonalIcositetrahedron,
23    /// Rhombic triacontahedron.
24    RhombicTriacontahedron,
25    /// Triakis icosahedron.
26    TriakisIcosahedron,
27    /// Pentakis dodecahedron.
28    PentakisDodecahedron,
29    /// Deltoidal hexecontahedron.
30    DeltoidalHexecontahedron,
31    /// Disdyakis triacontahedron.
32    DisdyakisTriacontahedron,
33    /// Pentagonal hexecontahedron.
34    PentagonalHexecontahedron,
35}
36
37impl CatalanSolid {
38    /// Returns the common lowercase name.
39    #[must_use]
40    pub const fn name(self) -> &'static str {
41        match self {
42            Self::TriakisTetrahedron => "triakis tetrahedron",
43            Self::RhombicDodecahedron => "rhombic dodecahedron",
44            Self::TriakisOctahedron => "triakis octahedron",
45            Self::TetrakisHexahedron => "tetrakis hexahedron",
46            Self::DeltoidalIcositetrahedron => "deltoidal icositetrahedron",
47            Self::DisdyakisDodecahedron => "disdyakis dodecahedron",
48            Self::PentagonalIcositetrahedron => "pentagonal icositetrahedron",
49            Self::RhombicTriacontahedron => "rhombic triacontahedron",
50            Self::TriakisIcosahedron => "triakis icosahedron",
51            Self::PentakisDodecahedron => "pentakis dodecahedron",
52            Self::DeltoidalHexecontahedron => "deltoidal hexecontahedron",
53            Self::DisdyakisTriacontahedron => "disdyakis triacontahedron",
54            Self::PentagonalHexecontahedron => "pentagonal hexecontahedron",
55        }
56    }
57
58    /// Returns the Archimedean solid dual to this Catalan solid.
59    #[must_use]
60    pub const fn dual_archimedean(self) -> ArchimedeanSolid {
61        match self {
62            Self::TriakisTetrahedron => ArchimedeanSolid::TruncatedTetrahedron,
63            Self::RhombicDodecahedron => ArchimedeanSolid::Cuboctahedron,
64            Self::TriakisOctahedron => ArchimedeanSolid::TruncatedCube,
65            Self::TetrakisHexahedron => ArchimedeanSolid::TruncatedOctahedron,
66            Self::DeltoidalIcositetrahedron => ArchimedeanSolid::Rhombicuboctahedron,
67            Self::DisdyakisDodecahedron => ArchimedeanSolid::TruncatedCuboctahedron,
68            Self::PentagonalIcositetrahedron => ArchimedeanSolid::SnubCube,
69            Self::RhombicTriacontahedron => ArchimedeanSolid::Icosidodecahedron,
70            Self::TriakisIcosahedron => ArchimedeanSolid::TruncatedDodecahedron,
71            Self::PentakisDodecahedron => ArchimedeanSolid::TruncatedIcosahedron,
72            Self::DeltoidalHexecontahedron => ArchimedeanSolid::Rhombicosidodecahedron,
73            Self::DisdyakisTriacontahedron => ArchimedeanSolid::TruncatedIcosidodecahedron,
74            Self::PentagonalHexecontahedron => ArchimedeanSolid::SnubDodecahedron,
75        }
76    }
77}
78
79#[cfg(test)]
80mod tests {
81    use super::CatalanSolid;
82    use use_archimedean::ArchimedeanSolid;
83
84    #[test]
85    fn exposes_dual_archimedean_metadata() {
86        let solid = CatalanSolid::RhombicDodecahedron;
87
88        assert_eq!(solid.name(), "rhombic dodecahedron");
89        assert_eq!(solid.dual_archimedean(), ArchimedeanSolid::Cuboctahedron);
90    }
91}