#![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, $trhs: ident) => ( impl> $trhs> for $t { #[inline] fn binop(left: &$t, right: &$t) -> $tv { *left.as_vec() - *right.as_vec() } } ) ) macro_rules! pnt_add_vec_impl( ($t: ident, $tv: ident, $trhs: ident, $comp0: ident $(,$compN: ident)*) => ( impl> $trhs> for $tv { #[inline] fn binop(left: &$t, right: &$tv) -> $t { $t::new(left.$comp0 + right.$comp0 $(, left.$compN + right.$compN)*) } } ) ) macro_rules! pnt_sub_vec_impl( ($t: ident, $tv: ident, $trhs: ident, $comp0: ident $(,$compN: ident)*) => ( impl> $trhs> for $tv { #[inline] fn binop(left: &$t, right: &$tv) -> $t { $t::new(left.$comp0 - right.$comp0 $(, left.$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.clone(); $( res.$compN = self.$compN.clone(); )* 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.clone() / v.$extra; $( res.$compN = v.$compN.clone() / v.$extra; )* res } } ) ) macro_rules! num_float_pnt_impl( ($t: ident, $tv: ident $(,$trhs: ident)*) => ( impl NumPnt> for $t where N: BaseNum + Zero $(+ $trhs>)* { } impl FloatPnt> for $t where N: BaseNum + One + Zero + ApproxEq + BaseFloat $(+ $trhs>)* { } ) )