2016-12-05 05:44:42 +08:00
|
|
|
use std::mem;
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::base::allocator::Allocator;
|
|
|
|
use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB};
|
|
|
|
use crate::base::dimension::{U1, U2, U3, U4, U5, U6};
|
|
|
|
use crate::base::{DefaultAllocator, Scalar};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::geometry::Point;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
* Give coordinates to Point{1 .. 6}
|
2016-12-05 05:44:42 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
macro_rules! deref_impl(
|
|
|
|
($D: ty, $Target: ident $(, $comps: ident)*) => {
|
2019-12-17 07:09:14 +08:00
|
|
|
impl<N: Scalar> Deref for Point<N, $D>
|
2017-08-03 01:37:44 +08:00
|
|
|
where DefaultAllocator: Allocator<N, $D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
type Target = $Target<N>;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
unsafe { mem::transmute(self) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
impl<N: Scalar> DerefMut for Point<N, $D>
|
2017-08-03 01:37:44 +08:00
|
|
|
where DefaultAllocator: Allocator<N, $D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
unsafe { mem::transmute(self) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
deref_impl!(U1, X, x);
|
|
|
|
deref_impl!(U2, XY, x, y);
|
|
|
|
deref_impl!(U3, XYZ, x, y, z);
|
|
|
|
deref_impl!(U4, XYZW, x, y, z, w);
|
|
|
|
deref_impl!(U5, XYZWA, x, y, z, w, a);
|
|
|
|
deref_impl!(U6, XYZWAB, x, y, z, w, a, b);
|