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
use vector::{Vector2, Vector3, Vector4};
macro_rules! matrix {
($name:ident : $vec:ident[ $($field:ident = $index:expr),* ] = $fixed:ty) => {
#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)]
#[repr(C)]
#[allow(missing_docs)]
pub struct $name<T> {
$( pub $field : $vec<T>, )*
}
impl<T: Copy> From<$fixed> for $name<T> {
fn from(m: $fixed) -> Self {
$name {
$(
$field: m[$index].into(),
)*
}
}
}
impl<T> Into<$fixed> for $name<T> {
fn into(self) -> $fixed {
[$( self.$field.into() ),*]
}
}
}
}
macro_rules! transpose {
($name:ident : $vec:ident[$( $field:ident [ $($sub:ident),* ] ),* ] = $transposed:ident) => {
impl<T> From<$transposed<T>> for $name<T> {
fn from(m: $transposed<T>) -> Self {
$name {
$(
$field: $vec {
$(
$sub: m.$sub.$field,
)*
},
)*
}
}
}
}
}
matrix!( RowMatrix2 : Vector2[x=0,y=1] = [[T; 2]; 2]);
transpose!( RowMatrix2 : Vector2[x[x,y],y[x,y]] = ColumnMatrix2 );
matrix!( RowMatrix2x3 : Vector2[x=0,y=1,z=2] = [[T; 2]; 3]);
transpose!( RowMatrix2x3 : Vector2[x[x,y],y[x,y],z[x,y]] = ColumnMatrix3x2 );
matrix!( RowMatrix3 : Vector3[x=0,y=1,z=2] = [[T; 3]; 3]);
transpose!( RowMatrix3 : Vector3[x[x,y,z],y[x,y,z],z[x,y,z]] = ColumnMatrix3 );
matrix!( RowMatrix3x4 : Vector3[x=0,y=1,z=2,w=3] = [[T; 3]; 4]);
transpose!( RowMatrix3x4 : Vector3[x[x,y,z],y[x,y,z],z[x,y,z],w[x,y,z]] = ColumnMatrix4x3 );
matrix!( RowMatrix4 : Vector4[x=0,y=1,z=2,w=3] = [[T; 4]; 4]);
transpose!( RowMatrix4 : Vector4[x[x,y,z,w],y[x,y,z,w],z[x,y,z,w],w[x,y,z,w]] = ColumnMatrix4 );
matrix!( ColumnMatrix2 : Vector2[x=0,y=1] = [[T; 2]; 2]);
transpose!( ColumnMatrix2 : Vector2[x[x,y],y[x,y]] = RowMatrix2 );
matrix!( ColumnMatrix3x2 : Vector3[x=0,y=1] = [[T; 3]; 2]);
transpose!( ColumnMatrix3x2 : Vector3[x[x,y,z],y[x,y,z]] = RowMatrix2x3 );
matrix!( ColumnMatrix3 : Vector3[x=0,y=1,z=2] = [[T; 3]; 3]);
transpose!( ColumnMatrix3 : Vector3[x[x,y,z],y[x,y,z],z[x,y,z]] = RowMatrix3 );
matrix!( ColumnMatrix4x3 : Vector4[x=0,y=1,z=2] = [[T; 4]; 3]);
transpose!( ColumnMatrix4x3 : Vector4[x[x,y,z,w],y[x,y,z,w],z[x,y,z,w]] = RowMatrix3x4 );
matrix!( ColumnMatrix4 : Vector4[x=0,y=1,z=2,w=3] = [[T; 4]; 4]);
transpose!( ColumnMatrix4 : Vector4[x[x,y,z,w],y[x,y,z,w],z[x,y,z,w],w[x,y,z,w]] = RowMatrix4 );