pdbtbx/read/pdb/
temporary_structs.rs

1use crate::TransformationMatrix;
2
3/// To help build a a matrix from separate rows
4pub struct BuildUpMatrix {
5    /// First row
6    pub row0: Option<[f64; 4]>,
7    /// Second row
8    pub row1: Option<[f64; 4]>,
9    /// Third row
10    pub row2: Option<[f64; 4]>,
11}
12
13impl BuildUpMatrix {
14    /// Create an empty struct
15    pub const fn empty() -> Self {
16        BuildUpMatrix {
17            row0: None,
18            row1: None,
19            row2: None,
20        }
21    }
22    /// Consume this struct and get the transformation matrix, if any row is not defined it returns None
23    pub const fn get_matrix(&self) -> Option<TransformationMatrix> {
24        match self {
25            BuildUpMatrix {
26                row0: Some(r1),
27                row1: Some(r2),
28                row2: Some(r3),
29            } => Some(TransformationMatrix::from_matrix([*r1, *r2, *r3])),
30            _ => None,
31        }
32    }
33    /// Determine if all rows are set
34    pub const fn is_set(&self) -> bool {
35        matches!(
36            self,
37            BuildUpMatrix {
38                row0: Some(_),
39                row1: Some(_),
40                row2: Some(_),
41            }
42        )
43    }
44    /// Determine if at least one row is set
45    pub const fn is_partly_set(&self) -> bool {
46        self.row0.is_some() || self.row1.is_some() || self.row2.is_some()
47    }
48    /// Set a specified row
49    pub fn set_row(&mut self, row: usize, data: [f64; 4]) {
50        match row {
51            0 => self.row0 = Some(data),
52            1 => self.row1 = Some(data),
53            2 => self.row2 = Some(data),
54            _ => panic!("Invalid value in 'set_row' on a BuildUpMatrix"),
55        }
56    }
57}