#![allow(missing_docs)]
use std::ops::{Deref, DerefMut};
use crate::base::dimension::{U1, U2, U3, U4, U5, U6};
use crate::base::storage::{IsContiguous, RawStorage, RawStorageMut};
use crate::base::{Matrix, Scalar};
macro_rules! coords_impl(
($T: ident; $($comps: ident),*) => {
#[repr(C)]
#[derive(Eq, PartialEq, Clone, Hash, Debug, Copy)]
#[cfg_attr(feature = "serde-serialize-no-std", derive(Serialize, Deserialize))]
pub struct $T<T: Scalar> {
$(pub $comps: T),*
}
}
);
macro_rules! deref_impl(
($R: ty, $C: ty; $Target: ident) => {
impl<T: Scalar, S> Deref for Matrix<T, $R, $C, S>
where S: RawStorage<T, $R, $C> + IsContiguous {
type Target = $Target<T>;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*(self.data.ptr() as *const Self::Target) }
}
}
impl<T: Scalar, S> DerefMut for Matrix<T, $R, $C, S>
where S: RawStorageMut<T, $R, $C> + IsContiguous {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self.data.ptr_mut() as *mut Self::Target) }
}
}
}
);
coords_impl!(X; x);
coords_impl!(XY; x, y);
coords_impl!(XYZ; x, y, z);
coords_impl!(XYZW; x, y, z, w);
coords_impl!(XYZWA; x, y, z, w, a);
coords_impl!(XYZWAB; x, y, z, w, a, b);
coords_impl!(IJKW; i, j, k, w);
coords_impl!(M2x2; m11, m21,
m12, m22);
coords_impl!(M2x3; m11, m21,
m12, m22,
m13, m23);
coords_impl!(M2x4; m11, m21,
m12, m22,
m13, m23,
m14, m24);
coords_impl!(M2x5; m11, m21,
m12, m22,
m13, m23,
m14, m24,
m15, m25);
coords_impl!(M2x6; m11, m21,
m12, m22,
m13, m23,
m14, m24,
m15, m25,
m16, m26);
coords_impl!(M3x2; m11, m21, m31,
m12, m22, m32);
coords_impl!(M3x3; m11, m21, m31,
m12, m22, m32,
m13, m23, m33);
coords_impl!(M3x4; m11, m21, m31,
m12, m22, m32,
m13, m23, m33,
m14, m24, m34);
coords_impl!(M3x5; m11, m21, m31,
m12, m22, m32,
m13, m23, m33,
m14, m24, m34,
m15, m25, m35);
coords_impl!(M3x6; m11, m21, m31,
m12, m22, m32,
m13, m23, m33,
m14, m24, m34,
m15, m25, m35,
m16, m26, m36);
coords_impl!(M4x2; m11, m21, m31, m41,
m12, m22, m32, m42);
coords_impl!(M4x3; m11, m21, m31, m41,
m12, m22, m32, m42,
m13, m23, m33, m43);
coords_impl!(M4x4; m11, m21, m31, m41,
m12, m22, m32, m42,
m13, m23, m33, m43,
m14, m24, m34, m44);
coords_impl!(M4x5; m11, m21, m31, m41,
m12, m22, m32, m42,
m13, m23, m33, m43,
m14, m24, m34, m44,
m15, m25, m35, m45);
coords_impl!(M4x6; m11, m21, m31, m41,
m12, m22, m32, m42,
m13, m23, m33, m43,
m14, m24, m34, m44,
m15, m25, m35, m45,
m16, m26, m36, m46);
coords_impl!(M5x2; m11, m21, m31, m41, m51,
m12, m22, m32, m42, m52);
coords_impl!(M5x3; m11, m21, m31, m41, m51,
m12, m22, m32, m42, m52,
m13, m23, m33, m43, m53);
coords_impl!(M5x4; m11, m21, m31, m41, m51,
m12, m22, m32, m42, m52,
m13, m23, m33, m43, m53,
m14, m24, m34, m44, m54);
coords_impl!(M5x5; m11, m21, m31, m41, m51,
m12, m22, m32, m42, m52,
m13, m23, m33, m43, m53,
m14, m24, m34, m44, m54,
m15, m25, m35, m45, m55);
coords_impl!(M5x6; m11, m21, m31, m41, m51,
m12, m22, m32, m42, m52,
m13, m23, m33, m43, m53,
m14, m24, m34, m44, m54,
m15, m25, m35, m45, m55,
m16, m26, m36, m46, m56);
coords_impl!(M6x2; m11, m21, m31, m41, m51, m61,
m12, m22, m32, m42, m52, m62);
coords_impl!(M6x3; m11, m21, m31, m41, m51, m61,
m12, m22, m32, m42, m52, m62,
m13, m23, m33, m43, m53, m63);
coords_impl!(M6x4; m11, m21, m31, m41, m51, m61,
m12, m22, m32, m42, m52, m62,
m13, m23, m33, m43, m53, m63,
m14, m24, m34, m44, m54, m64);
coords_impl!(M6x5; m11, m21, m31, m41, m51, m61,
m12, m22, m32, m42, m52, m62,
m13, m23, m33, m43, m53, m63,
m14, m24, m34, m44, m54, m64,
m15, m25, m35, m45, m55, m65);
coords_impl!(M6x6; m11, m21, m31, m41, m51, m61,
m12, m22, m32, m42, m52, m62,
m13, m23, m33, m43, m53, m63,
m14, m24, m34, m44, m54, m64,
m15, m25, m35, m45, m55, m65,
m16, m26, m36, m46, m56, m66);
deref_impl!(U1, U1; X);
deref_impl!(U2, U1; XY);
deref_impl!(U3, U1; XYZ);
deref_impl!(U4, U1; XYZW);
deref_impl!(U5, U1; XYZWA);
deref_impl!(U6, U1; XYZWAB);
deref_impl!(U1, U2; XY);
deref_impl!(U1, U3; XYZ);
deref_impl!(U1, U4; XYZW);
deref_impl!(U1, U5; XYZWA);
deref_impl!(U1, U6; XYZWAB);
deref_impl!(U2, U2; M2x2);
deref_impl!(U2, U3; M2x3);
deref_impl!(U2, U4; M2x4);
deref_impl!(U2, U5; M2x5);
deref_impl!(U2, U6; M2x6);
deref_impl!(U3, U2; M3x2);
deref_impl!(U3, U3; M3x3);
deref_impl!(U3, U4; M3x4);
deref_impl!(U3, U5; M3x5);
deref_impl!(U3, U6; M3x6);
deref_impl!(U4, U2; M4x2);
deref_impl!(U4, U3; M4x3);
deref_impl!(U4, U4; M4x4);
deref_impl!(U4, U5; M4x5);
deref_impl!(U4, U6; M4x6);
deref_impl!(U5, U2; M5x2);
deref_impl!(U5, U3; M5x3);
deref_impl!(U5, U4; M5x4);
deref_impl!(U5, U5; M5x5);
deref_impl!(U5, U6; M5x6);
deref_impl!(U6, U2; M6x2);
deref_impl!(U6, U3; M6x3);
deref_impl!(U6, U4; M6x4);
deref_impl!(U6, U5; M6x5);
deref_impl!(U6, U6; M6x6);