1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use serde::{Deserialize, Serialize};
/// Crystal system classification (7 systems).
///
/// # Examples
///
/// ```
/// # use khanij::*;
/// let system = CrystalSystem::Cubic;
/// assert_eq!(system.symmetry_order(), 48);
///
/// let triclinic = CrystalSystem::Triclinic;
/// assert_eq!(triclinic.symmetry_order(), 2);
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum CrystalSystem {
Cubic, // a=b=c, α=β=γ=90°
Tetragonal, // a=b≠c, α=β=γ=90°
Orthorhombic, // a≠b≠c, α=β=γ=90°
Hexagonal, // a=b≠c, α=β=90° γ=120°
Trigonal, // a=b=c, α=β=γ≠90°
Monoclinic, // a≠b≠c, α=γ=90° β≠90°
Triclinic, // a≠b≠c, α≠β≠γ≠90°
}
impl CrystalSystem {
/// Number of symmetry elements.
///
/// # Examples
///
/// ```
/// # use khanij::*;
/// assert_eq!(CrystalSystem::Cubic.symmetry_order(), 48);
/// assert_eq!(CrystalSystem::Hexagonal.symmetry_order(), 24);
/// assert_eq!(CrystalSystem::Triclinic.symmetry_order(), 2);
/// ```
#[must_use]
pub fn symmetry_order(&self) -> u8 {
match self {
Self::Cubic => 48,
Self::Hexagonal => 24,
Self::Tetragonal => 16,
Self::Trigonal => 12,
Self::Orthorhombic => 8,
Self::Monoclinic => 4,
Self::Triclinic => 2,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn cubic_highest_symmetry() {
assert!(CrystalSystem::Cubic.symmetry_order() > CrystalSystem::Triclinic.symmetry_order());
}
#[test]
fn all_seven_systems() {
let systems = [
CrystalSystem::Cubic,
CrystalSystem::Tetragonal,
CrystalSystem::Orthorhombic,
CrystalSystem::Hexagonal,
CrystalSystem::Trigonal,
CrystalSystem::Monoclinic,
CrystalSystem::Triclinic,
];
assert_eq!(systems.len(), 7);
}
}