fullerene/
lib.rs

1#![doc(html_root_url = "https://docs.rs/Fullerene/0.4.1")]
2//! Fullerene on the ODE (Open Dynamics Engine) for Rust
3//!
4
5pub mod c60;
6pub mod dodecahedron;
7pub mod icosahedron;
8
9pub use c60::{C60, C60Center};
10pub use dodecahedron::{Dodecahedron, DodecahedronCenter};
11pub use icosahedron::Icosahedron;
12
13pub use ph_faces::{self, f_to_f32, f_to_f64, polyhedron::{self, PHF, TUV}};
14
15/// tests
16#[cfg(test)]
17mod tests {
18  use super::*;
19
20  /// [-- --nocapture] [-- --show-output]
21  #[test]
22  fn test_icosahedron() {
23    let icosa32_e = Icosahedron::new(1.0f32);
24    let icosa32 = icosa32_e.ph;
25    assert_eq!(icosa32.tri.len(), 20);
26    assert_eq!(icosa32.vtx.len(), 12);
27    let s32 = format!("{:?}", icosa32.vtx[0]);
28    println!("{}", s32);
29    assert_eq!(s32, "[0.0, -1.0, -1.618034]");
30
31    let icosa64_e = Icosahedron::new(1.0f64);
32    let icosa64 = icosa64_e.ph;
33    assert_eq!(icosa64.tri.len(), 20);
34    assert_eq!(icosa64.vtx.len(), 12);
35    let s64 = format!("{:?}", icosa64.vtx[0]);
36    println!("{}", s64);
37    assert_eq!(s64, "[0.0, -1.0, -1.618033988749895]");
38  }
39
40  #[test]
41  fn test_dodecahedron() {
42    let dodeca32_e = Dodecahedron::<f32>::new(1.0f32);
43    let dodeca32 = dodeca32_e.ph;
44    assert_eq!(dodeca32.tri.len(), 12); // 12(pentagon) x 3
45    assert_eq!(dodeca32.vtx.len(), 20);
46    let dodeca64_e = Dodecahedron::<f64>::new(1.0f64);
47    let dodeca64 = dodeca64_e.ph;
48    assert_eq!(dodeca64.tri.len(), 12); // 12(pentagon) x 3
49    assert_eq!(dodeca64.vtx.len(), 20);
50  }
51
52  #[test]
53  fn test_dodecahedron_center() {
54    let dodeca32_center_e = DodecahedronCenter::new(1.0f32);
55    let dodeca32_center = dodeca32_center_e.ph;
56    assert_eq!(dodeca32_center.tri.len(), 12); // 12 x 5
57    assert_eq!(dodeca32_center.vtx.len(), 32); // 20 + 12
58    let dodeca64_center_e = DodecahedronCenter::new(1.0f64);
59    let dodeca64_center = dodeca64_center_e.ph;
60    assert_eq!(dodeca64_center.tri.len(), 12); // 12 x 5
61    assert_eq!(dodeca64_center.vtx.len(), 32); // 20 + 12
62
63    let mt = [
64  [[20, 0, 4], [20, 4, 3], [20, 3, 2], [20, 2, 1], [20, 1, 0]], // 0
65  [[21, 4, 0], [21, 0, 7], [21, 7, 6], [21, 6, 5], [21, 5, 4]], // 4
66  [[22, 0, 1], [22, 1, 9], [22, 9, 8], [22, 8, 7], [22, 7, 0]], // 8
67  [[23, 1, 2], [23, 2, 11], [23, 11, 10], [23, 10, 9], [23, 9, 1]], // 9
68  [[24, 2, 3], [24, 3, 13], [24, 13, 12], [24, 12, 11], [24, 11, 2]], // 7
69  [[25, 3, 4], [25, 4, 5], [25, 5, 14], [25, 14, 13], [25, 13, 3]], // 1
70  [[26, 15, 14], [26, 14, 5], [26, 5, 6], [26, 6, 16], [26, 16, 15]], // 11
71  [[27, 16, 6], [27, 6, 7], [27, 7, 8], [27, 8, 17], [27, 17, 16]], // 5
72  [[28, 17, 8], [28, 8, 9], [28, 9, 10], [28, 10, 18], [28, 18, 17]], // 3
73  [[29, 18, 10], [29, 10, 11], [29, 11, 12], [29, 12, 19], [29, 19, 18]], // 6
74  [[30, 19, 12], [30, 12, 13], [30, 13, 14], [30, 14, 15], [30, 15, 19]], // 10
75  [[31, 19, 15], [31, 15, 16], [31, 16, 17], [31, 17, 18], [31, 18, 19]] // 2
76    ];
77    assert_eq!(dodeca32_center.tri, mt);
78    assert_eq!(dodeca64_center.tri, mt);
79  }
80
81  #[test]
82  fn test_fullerene() {
83    let c60_32_e = C60::<f32>::new(1.0f32);
84    let c60_32 = c60_32_e.ph;
85    assert_eq!(c60_32.tri.len(), 32); // 12(pentagon) x 3 + 20(hexagon) x 4
86    assert_eq!(c60_32.vtx.len(), 60);
87    let c60_64_e = C60::<f64>::new(1.0f64);
88    let c60_64 = c60_64_e.ph;
89    assert_eq!(c60_64.tri.len(), 32); // 12(pentagon) x 3 + 20(hexagon) x 4
90    assert_eq!(c60_64.vtx.len(), 60);
91  }
92
93  #[test]
94  fn test_fullerene_center() {
95    let c60_32_center_e = C60Center::new(1.0f32);
96    let c60_32_center = c60_32_center_e.ph;
97    assert_eq!(c60_32_center.tri.len(), 32); // 12 x 5 + 20 x 6
98    assert_eq!(c60_32_center.vtx.len(), 92); // 60 + 32
99    let c60_64_center_e = C60Center::new(1.0f64);
100    let c60_64_center = c60_64_center_e.ph;
101    assert_eq!(c60_64_center.tri.len(), 32); // 12 x 5 + 20 x 6
102    assert_eq!(c60_64_center.vtx.len(), 92); // 60 + 32
103  }
104}