2018-12-26 22:18:03 +08:00
|
|
|
use std::mem;
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB};
|
2021-04-07 20:29:20 +08:00
|
|
|
use crate::base::Scalar;
|
2018-12-26 22:18:03 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::geometry::Translation;
|
2018-12-26 22:18:03 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Give coordinates to Translation{1 .. 6}
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
macro_rules! deref_impl(
|
2021-04-07 20:29:20 +08:00
|
|
|
($D: expr, $Target: ident $(, $comps: ident)*) => {
|
2021-04-11 17:00:38 +08:00
|
|
|
impl<T: Scalar> Deref for Translation<T, $D> {
|
|
|
|
type Target = $Target<T>;
|
2018-12-26 22:18:03 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
unsafe { mem::transmute(self) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
impl<T: Scalar> DerefMut for Translation<T, $D>
|
2021-04-07 20:29:20 +08:00
|
|
|
{
|
2018-12-26 22:18:03 +08:00
|
|
|
#[inline]
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
unsafe { mem::transmute(self) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-04-07 20:29:20 +08:00
|
|
|
deref_impl!(1, X, x);
|
|
|
|
deref_impl!(2, XY, x, y);
|
|
|
|
deref_impl!(3, XYZ, x, y, z);
|
|
|
|
deref_impl!(4, XYZW, x, y, z, w);
|
|
|
|
deref_impl!(5, XYZWA, x, y, z, w, a);
|
|
|
|
deref_impl!(6, XYZWAB, x, y, z, w, a, b);
|