ak_core/geometry/
pbc.rs

1use std::ops::Deref;
2
3#[derive(Clone, Copy, Debug)]
4pub struct Pbc(pub [bool; 3]);
5
6impl Pbc {
7    pub fn new(pbc: [bool; 3]) -> Self {
8        Self(pbc)
9    }
10
11    pub fn any(self) -> bool {
12        self.0.contains(&true)
13    }
14
15    pub fn all(self) -> bool {
16        self.0.iter().all(|f| *f)
17    }
18}
19
20impl Deref for Pbc {
21    type Target = [bool; 3];
22
23    fn deref(&self) -> &Self::Target {
24        &self.0
25    }
26}
27
28#[cfg(test)]
29mod tests {
30
31    use crate::geometry::pbc::Pbc;
32
33    #[test]
34    fn test_pbc() {
35        let pbc = Pbc::new([true, true, true]);
36        assert!(pbc.0[0]);
37        assert!(pbc.0[1]);
38        assert!(pbc.0[2]);
39    }
40
41    #[test]
42    fn test_pbc_deref() {
43        let pbc = Pbc::new([true, true, true]);
44        assert!(pbc[0]);
45        assert!(pbc[1]);
46        assert!(pbc[2]);
47    }
48
49    #[test]
50    fn test_pbc_any() {
51        let pbc = Pbc::new([true, false, false]);
52        assert!(pbc.any());
53    }
54
55    #[test]
56    fn test_pbc_any_false() {
57        let pbc = Pbc::new([false, false, false]);
58        assert!(!pbc.any());
59    }
60
61    #[test]
62    fn test_pbc_all() {
63        let pbc = Pbc::new([true, true, true]);
64        assert!(pbc.all());
65    }
66
67    #[test]
68    fn test_pbc_all_false() {
69        let pbc = Pbc::new([true, true, false]);
70        assert!(!pbc.all());
71    }
72}