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
75
76
#![allow(dead_code)]

#[derive(Debug, Clone)]
/// A unit cell of a crystal, containing its dimensions and angles
pub struct UnitCell {
    /// a-axis dimension
    a: f64,
    /// b-axis dimension
    b: f64,
    /// c-axis dimension
    c: f64,
    /// alpha angle in degrees
    alpha: f64,
    /// beta angle in degrees
    beta: f64,
    /// gamma angle in degrees
    gamma: f64,
}

impl UnitCell {
    /// Create a new UnitCell construct.
    /// ## Arguments
    /// * `a` - a-axis dimension
    /// * `b` - b-axis dimension
    /// * `c` - c-axis dimension
    /// * `alpha` - alpha angle in degrees
    /// * `beta` - beta angle in degrees
    /// * `gamma` - gamma angle in degrees
    pub fn new(a: f64, b: f64, c: f64, alpha: f64, beta: f64, gamma: f64) -> UnitCell {
        UnitCell {
            a,
            b,
            c,
            alpha,
            beta,
            gamma,
        }
    }
    /// Get the a-axis dimension
    pub fn a(&self) -> f64 {
        self.a
    }
    /// Get the b-axis dimension
    pub fn b(&self) -> f64 {
        self.b
    }
    /// Get the c-axis dimension
    pub fn c(&self) -> f64 {
        self.c
    }
    /// Get the alpha angle in degrees
    pub fn alpha(&self) -> f64 {
        self.alpha
    }
    /// Get the beta angle in degrees
    pub fn beta(&self) -> f64 {
        self.beta
    }
    /// Get the gamma angle in degrees
    pub fn gamma(&self) -> f64 {
        self.gamma
    }
    /// Get the dimensions in a tuple (a, b, c)
    pub fn size(&self) -> (f64, f64, f64) {
        (self.a, self.b, self.c)
    }
}

impl PartialEq for UnitCell {
    fn eq(&self, other: &Self) -> bool {
        self.size() == other.size()
            && self.alpha == other.alpha
            && self.beta == other.beta
            && self.gamma == other.gamma
    }
}