2021-10-19 20:02:07 +08:00
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
|
|
|
use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB};
|
|
|
|
use crate::base::Scalar;
|
|
|
|
|
2021-10-19 20:21:26 +08:00
|
|
|
use crate::geometry::Scale;
|
2021-10-19 20:02:07 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2021-10-19 20:21:26 +08:00
|
|
|
* Give coordinates to Scale{1 .. 6}
|
2021-10-19 20:02:07 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
macro_rules! deref_impl(
|
|
|
|
($D: expr, $Target: ident $(, $comps: ident)*) => {
|
2021-10-19 20:21:26 +08:00
|
|
|
impl<T: Scalar> Deref for Scale<T, $D> {
|
2021-10-19 20:02:07 +08:00
|
|
|
type Target = $Target<T>;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn deref(&self) -> &Self::Target {
|
2021-10-19 20:21:26 +08:00
|
|
|
unsafe { &*(self as *const Scale<T, $D> as *const Self::Target) }
|
2021-10-19 20:02:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 20:21:26 +08:00
|
|
|
impl<T: Scalar> DerefMut for Scale<T, $D> {
|
2021-10-19 20:02:07 +08:00
|
|
|
#[inline]
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
2021-10-19 20:21:26 +08:00
|
|
|
unsafe { &mut *(self as *mut Scale<T, $D> as *mut Self::Target) }
|
2021-10-19 20:02:07 +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);
|