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
use crate::{
    matrix::{impl_matrix, AsMutMatrixParts, AsRefMatrixParts, FromMatrixParts, MatrixScalar},
    vector::{impl_vector, AsMutVectorParts, AsRefVectorParts, FromVectorParts, VectorScalar},
};

impl_vector!(2, nalgebra::VectorView2<'_, T>);
impl_vector!(2, nalgebra::VectorViewMut2<'_, T>);
impl_vector!(2, nalgebra::Vector2<T>);

impl_vector!(3, nalgebra::VectorView3<'_, T>);
impl_vector!(3, nalgebra::VectorViewMut3<'_, T>);
impl_vector!(3, nalgebra::Vector3<T>);

impl_vector!(4, nalgebra::VectorView4<'_, T>);
impl_vector!(4, nalgebra::VectorViewMut4<'_, T>);
impl_vector!(4, nalgebra::Vector4<T>);

impl_matrix!(2, 2, nalgebra::MatrixView2<'_, T>);
impl_matrix!(2, 2, nalgebra::MatrixViewMut2<'_, T>);
impl_matrix!(2, 2, nalgebra::Matrix2<T>);

impl_matrix!(3, 2, nalgebra::MatrixView2x3<'_, T>);
impl_matrix!(4, 2, nalgebra::MatrixView2x4<'_, T>);
impl_matrix!(2, 3, nalgebra::MatrixView3x2<'_, T>);
impl_matrix!(3, 2, nalgebra::MatrixViewMut2x3<'_, T>);
impl_matrix!(4, 2, nalgebra::MatrixViewMut2x4<'_, T>);
impl_matrix!(2, 3, nalgebra::MatrixViewMut3x2<'_, T>);
impl_matrix!(3, 2, nalgebra::Matrix2x3<T>);
impl_matrix!(4, 2, nalgebra::Matrix2x4<T>);
impl_matrix!(2, 3, nalgebra::Matrix3x2<T>);

impl_matrix!(3, 3, nalgebra::MatrixView3<'_, T>);
impl_matrix!(3, 3, nalgebra::MatrixViewMut3<'_, T>);
impl_matrix!(3, 3, nalgebra::Matrix3<T>);

impl_matrix!(4, 3, nalgebra::MatrixView3x4<'_, T>);
impl_matrix!(2, 4, nalgebra::MatrixView4x2<'_, T>);
impl_matrix!(3, 4, nalgebra::MatrixView4x3<'_, T>);
impl_matrix!(4, 3, nalgebra::MatrixViewMut3x4<'_, T>);
impl_matrix!(2, 4, nalgebra::MatrixViewMut4x2<'_, T>);
impl_matrix!(3, 4, nalgebra::MatrixViewMut4x3<'_, T>);
impl_matrix!(4, 3, nalgebra::Matrix3x4<T>);
impl_matrix!(2, 4, nalgebra::Matrix4x2<T>);
impl_matrix!(3, 4, nalgebra::Matrix4x3<T>);

impl_matrix!(4, 4, nalgebra::MatrixView4<'_, T>);
impl_matrix!(4, 4, nalgebra::MatrixViewMut4<'_, T>);
impl_matrix!(4, 4, nalgebra::Matrix4<T>);

impl<T: VectorScalar, S, const N: usize> AsRefVectorParts<T, N>
    for nalgebra::Matrix<T, nalgebra::Const<N>, nalgebra::Const<1>, S>
where
    Self: AsRef<[T; N]>,
{
    fn as_ref_parts(&self) -> &[T; N] {
        self.as_ref()
    }
}

impl<T: VectorScalar, S, const N: usize> AsMutVectorParts<T, N>
    for nalgebra::Matrix<T, nalgebra::Const<N>, nalgebra::Const<1>, S>
where
    Self: AsMut<[T; N]>,
{
    fn as_mut_parts(&mut self) -> &mut [T; N] {
        self.as_mut()
    }
}

impl<T: VectorScalar, const N: usize> FromVectorParts<T, N> for nalgebra::SMatrix<T, N, 1> {
    fn from_parts(parts: [T; N]) -> Self {
        Self::from_array_storage(nalgebra::ArrayStorage([parts]))
    }
}

impl<T: MatrixScalar, S, const C: usize, const R: usize> AsRefMatrixParts<T, C, R>
    for nalgebra::Matrix<T, nalgebra::Const<R>, nalgebra::Const<C>, S>
where
    Self: AsRef<[[T; R]; C]>,
{
    fn as_ref_parts(&self) -> &[[T; R]; C] {
        self.as_ref()
    }
}

impl<T: MatrixScalar, S, const C: usize, const R: usize> AsMutMatrixParts<T, C, R>
    for nalgebra::Matrix<T, nalgebra::Const<R>, nalgebra::Const<C>, S>
where
    Self: AsMut<[[T; R]; C]>,
{
    fn as_mut_parts(&mut self) -> &mut [[T; R]; C] {
        self.as_mut()
    }
}

impl<T: MatrixScalar, const C: usize, const R: usize> FromMatrixParts<T, C, R>
    for nalgebra::SMatrix<T, R, C>
{
    fn from_parts(parts: [[T; R]; C]) -> Self {
        Self::from_array_storage(nalgebra::ArrayStorage(parts))
    }
}