#![macro_escape] macro_rules! orig_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( impl Orig for $t { #[inline] fn orig() -> $t { $t { $comp0: ::zero() $(, $compN: ::zero() )* } } #[inline] fn is_orig(&self) -> bool { self.$comp0.is_zero() $(&& self.$compN.is_zero() )* } } ) ) macro_rules! pnt_sub_impl( ($t: ident, $tv: ident) => ( impl> Sub<$t, $tv> for $t { #[inline] fn sub(self, right: $t) -> $tv { *self.as_vec() - *right.as_vec() } } ) ) macro_rules! pnt_add_vec_impl( ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( impl> Add<$tv, $t> for $t { #[inline] fn add(self, right: $tv) -> $t { $t::new(self.$comp0 + right.$comp0 $(, self.$compN + right.$compN)*) } } ) ) macro_rules! pnt_sub_vec_impl( ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( impl> Sub<$tv, $t> for $t { #[inline] fn sub(self, right: $tv) -> $t { $t::new(self.$comp0 - right.$comp0 $(, self.$compN - right.$compN)*) } } ) ) macro_rules! pnt_as_vec_impl( ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( impl $t { /// Converts this point to its associated vector. #[inline] pub fn to_vec(self) -> $tv { $tv::new( self.$comp0 $(, self.$compN)* ) } /// Converts a reference to this point to a reference to its associated vector. #[inline] pub fn as_vec<'a>(&'a self) -> &'a $tv { unsafe { mem::transmute(self) } } #[inline] fn set_coords(&mut self, v: $tv) { self.$comp0 = v.$comp0; $(self.$compN = v.$compN;)* } } impl PntAsVec<$tv> for $t { #[inline] fn to_vec(self) -> $tv { self.to_vec() } #[inline] fn as_vec<'a>(&'a self) -> &'a $tv { self.as_vec() } #[inline] fn set_coords(&mut self, v: $tv) { self.set_coords(v) } } ) ) macro_rules! pnt_to_homogeneous_impl( ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( impl ToHomogeneous<$t2> for $t { fn to_homogeneous(&self) -> $t2 { let mut res: $t2 = Orig::orig(); res.$comp0 = self.$comp0; $( res.$compN = self.$compN; )* res.$extra = ::one(); res } } ) ) macro_rules! pnt_from_homogeneous_impl( ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( impl + One + Zero> FromHomogeneous<$t2> for $t { fn from(v: &$t2) -> $t { let mut res: $t = Orig::orig(); res.$comp0 = v.$comp0 / v.$extra; $( res.$compN = v.$compN / v.$extra; )* res } } ) ) macro_rules! num_float_pnt_impl( ($t: ident, $tv: ident) => ( impl NumPnt> for $t where N: BaseNum { } impl FloatPnt> for $t where N: BaseFloat + ApproxEq { } ) )