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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use crate::;
use *;
/// 4x4 matrix with double precision
///
/// It has the same layout as `[Fvec4; 4]`, so it is aligned to 16 bytes.
///
/// ## Examples
///
/// ```
/// use mafs::{Mat4, Fmat4, Vec4, Fvec4};
///
/// // Construction
/// let m1 = Fmat4::from_columns(
/// Fvec4::new(1.0, 2.0, 3.0, 4.0),
/// Fvec4::new(5.0, 6.0, 7.0, 8.0),
/// Fvec4::new(9.0, 10.0, 11.0, 12.0),
/// Fvec4::new(13.0, 14.0, 15.0, 16.0),
/// );
/// let m2 = Fmat4::from_columns(
/// Fvec4::new(17.0, 18.0, 19.0, 20.0),
/// Fvec4::new(21.0, 22.0, 23.0, 24.0),
/// Fvec4::new(25.0, 26.0, 27.0, 28.0),
/// Fvec4::new(29.0, 30.0, 31.0, 32.0),
/// );
///
/// // Matrix-Vector arithmetics
/// let v = Fvec4::new(17.0, 18.0, 19.0, 20.0);
/// assert_eq!(m1 * v, Fvec4::new(538.0, 612.0, 686.0, 760.0));
///
/// // Matrix-Matrix arithmetics
/// assert_eq!(m1 + m2, Fmat4::from_columns(
/// Fvec4::new(18.0, 20.0, 22.0, 24.0),
/// Fvec4::new(26.0, 28.0, 30.0, 32.0),
/// Fvec4::new(34.0, 36.0, 38.0, 40.0),
/// Fvec4::new(42.0, 44.0, 46.0, 48.0),
/// ));
/// assert_eq!(m1 - m2, Fmat4::from_columns(
/// Fvec4::new(-16.0, -16.0, -16.0, -16.0),
/// Fvec4::new(-16.0, -16.0, -16.0, -16.0),
/// Fvec4::new(-16.0, -16.0, -16.0, -16.0),
/// Fvec4::new(-16.0, -16.0, -16.0, -16.0),
/// ));
/// assert_eq!(m1 * m2, Fmat4::from_columns(
/// Fvec4::new(538.0, 612.0, 686.0, 760.0),
/// Fvec4::new(650.0, 740.0, 830.0, 920.0),
/// Fvec4::new(762.0, 868.0, 974.0, 1080.0),
/// Fvec4::new(874.0, 996.0, 1118.0, 1240.0),
/// ));
///
/// // Transpose
/// assert_eq!(m1.transpose(), Fmat4::from_columns(
/// Fvec4::new(1.0, 5.0, 9.0, 13.0),
/// Fvec4::new(2.0, 6.0, 10.0, 14.0),
/// Fvec4::new(3.0, 7.0, 11.0, 15.0),
/// Fvec4::new(4.0, 8.0, 12.0, 16.0),
/// ));
///
/// // Inverse of transformation matrices
/// let rotation_matrix = Fmat4::from_columns(
/// Fvec4::new(1.0, 0.0, 0.0, 0.0),
/// Fvec4::new(0.0, 1.0f32.cos(), -1.0f32.sin(), 0.0),
/// Fvec4::new(0.0, 1.0f32.sin(), 1.0f32.cos(), 0.0),
/// Fvec4::new(0.0, 0.0, 0.0, 1.0),
/// );
/// assert_eq!(rotation_matrix.inverse_se3(), rotation_matrix.transpose());
/// let rotation_and_translation = Fmat4::from_columns(
/// Fvec4::new( 0.6666666666666666, 0.6666666666666666, -0.3333333333333333, 0.0),
/// Fvec4::new(-0.3333333333333333, 0.6666666666666666, 0.6666666666666666, 0.0),
/// Fvec4::new( 0.6666666666666666, -0.3333333333333333, 0.6666666666666666, 0.0),
/// Fvec4::new( -4.0, 5.0, 6.0, 1.0),
/// );
/// assert_eq!(rotation_and_translation.inverse_se3(), Fmat4::from_columns(
/// Fvec4::new(0.6666667, -0.33333334, 0.6666667, 0.0),
/// Fvec4::new(0.6666667, 0.6666667, -0.33333334, 0.0),
/// Fvec4::new(-0.33333334, 0.6666667, 0.6666667, 0.0),
/// Fvec4::new(1.3333334, -8.666667, 0.33333337, 1.0),
/// ));
/// ```
implement_matops!;