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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#![allow(dead_code)]
use crate::transformation::*;
#[derive(Debug, Clone)]
pub struct MtriX {
pub serial_number: usize,
transformation: TransformationMatrix,
pub contained: bool,
rows_set: [bool; 3],
}
impl MtriX {
pub fn new() -> Self {
MtriX {
serial_number: 0,
transformation: TransformationMatrix::identity(),
contained: false,
rows_set: [true, true, true],
}
}
pub fn serial_number(&self) -> usize {
self.serial_number
}
pub fn set_serial_number(&mut self, new_value: usize) {
self.serial_number = new_value;
}
pub fn contained(&self) -> bool {
self.contained
}
pub fn set_contained(&mut self, new_value: bool) {
self.contained = new_value;
}
pub fn transformation(&self) -> &TransformationMatrix {
&self.transformation
}
pub fn set_transformation(&mut self, transformation: TransformationMatrix) {
self.transformation = transformation;
}
pub fn set_row(&mut self, row: usize, data: [f64; 4]) {
if row > 2 {
panic!(format!(
"Row in MtriX.set_row is too big (max 2, value: {})",
row
));
}
let mut matrix = self.transformation.matrix();
matrix[row] = data;
self.transformation.set_matrix(matrix);
if self.rows_set == [true, true, true] {
self.rows_set = [false, false, false];
}
self.rows_set[row] = true;
}
pub fn valid(&self) -> bool {
self.rows_set == [true, true, true]
}
}
impl PartialEq for MtriX {
fn eq(&self, other: &Self) -> bool {
self.transformation == other.transformation
&& self.serial_number == other.serial_number
&& self.contained == other.contained
}
}
impl Default for MtriX {
fn default() -> Self {
Self::new()
}
}