diff --git a/src/macros/assert.rs b/src/macros/assert.rs index de93983b..46976693 100644 --- a/src/macros/assert.rs +++ b/src/macros/assert.rs @@ -6,7 +6,7 @@ macro_rules! assert_approx_eq_eps( let eps = &($eps); let (given_val, expected_val) = (&($given), &($expected)); if !ApproxEq::approx_eq_eps(given_val, expected_val, eps) { - panic!("assertion failed: `left ≈ right` (left: `{}`, right: `{}`, tolerance: `{}`)", + panic!("assertion failed: `left ≈ right` (left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)", *given_val, *expected_val, *eps ) } @@ -21,7 +21,7 @@ macro_rules! assert_approx_eq_ulps( let ulps = $ulps; let (given_val, expected_val) = (&($given), &($expected)); if !ApproxEq::approx_eq_ulps(given_val, expected_val, ulps) { - panic!("assertion failed: `left ≈ right` (left: `{}`, right: `{}`, tolerance: `{}`)", + panic!("assertion failed: `left ≈ right` (left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)", *given_val, *expected_val, ulps ) } @@ -34,7 +34,7 @@ macro_rules! assert_approx_eq( ($given: expr, $expected: expr) => ({ let (given_val, expected_val) = (&($given), &($expected)); if !ApproxEq::approx_eq(given_val, expected_val) { - panic!("assertion failed: `left ≈ right` (left: `{}`, right: `{}`, tolerance: `{}`)", + panic!("assertion failed: `left ≈ right` (left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)", *given_val, *expected_val, ApproxEq::approx_epsilon(Some(*given_val)) ) diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 4a9a406b..9b7cb5c0 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -12,7 +12,7 @@ use std::mem; use structs::dvec::DVec; use traits::operations::{Inv, Transpose, Mean, Cov}; use traits::structure::{Cast, ColSlice, RowSlice, Diag, Eye, Indexable, Shape, Zero, One, BaseNum}; -use std::fmt::{Show, Formatter, Result}; +use std::fmt::{Show, Formatter, Result, String}; /// Matrix with dimensions unknown at compile-time. @@ -633,7 +633,7 @@ impl> ApproxEq for DMat { } } -impl Show for DMat { +impl Show for DMat { fn fmt(&self, form:&mut Formatter) -> Result { for i in range(0u, self.nrows()) { for j in range(0u, self.ncols()) { diff --git a/src/structs/dvec_macros.rs b/src/structs/dvec_macros.rs index 660f7f91..3a5587c4 100644 --- a/src/structs/dvec_macros.rs +++ b/src/structs/dvec_macros.rs @@ -395,7 +395,7 @@ macro_rules! dvec_impl( ); macro_rules! small_dvec_impl ( - ($dvec: ident, $dim: expr $(,$idx: expr)*) => ( + ($dvec: ident, $dim: expr, $($idx: expr),*) => ( impl $dvec { #[inline] pub fn len(&self) -> uint { @@ -436,7 +436,7 @@ macro_rules! small_dvec_impl ( ); macro_rules! small_dvec_from_impl ( - ($dvec: ident, $dim: expr $(,$zeros: expr)*) => ( + ($dvec: ident, $dim: expr, $($zeros: expr),*) => ( impl $dvec { /// Builds a vector filled with a constant. #[inline] diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index 9760a354..a80fff78 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -1,13 +1,12 @@ #![macro_use] macro_rules! mat_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl $t { #[inline] - pub fn new($comp0: N $(, $compN: N )*) -> $t { + pub fn new($($compN: N ),+) -> $t { $t { - $comp0: $comp0 - $(, $compN: $compN )* + $($compN: $compN ),+ } } } @@ -76,76 +75,76 @@ macro_rules! at_fast_impl( ); macro_rules! mat_cast_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Cast<$t> for $t { #[inline] fn from(v: $t) -> $t { - $t::new(Cast::from(v.$comp0) $(, Cast::from(v.$compN))*) + $t::new($(Cast::from(v.$compN)),+) } } ) ); macro_rules! add_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Add<$t> for $t { type Output = $t; #[inline] fn add(self, right: $t) -> $t { - $t::new(self.$comp0 + right.$comp0 $(, self.$compN + right.$compN)*) + $t::new($(self.$compN + right.$compN),+) } } ) ); macro_rules! sub_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Sub<$t> for $t { type Output = $t; #[inline] fn sub(self, right: $t) -> $t { - $t::new(self.$comp0 - right.$comp0 $(, self.$compN - right.$compN)*) + $t::new($(self.$compN - right.$compN),+) } } ) ); macro_rules! mat_mul_scalar_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Mul for N { type Output = $t; #[inline] fn mul(self, right: N) -> $t { - $t::new(self.$comp0 * *right $(, self.$compN * *right)*) + $t::new($(self.$compN * *right),+) } } ) ); macro_rules! mat_div_scalar_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Div for $t { type Output = $t; #[inline] fn div(self, right: N) -> $t { - $t::new(self.$comp0 / *right $(, self.$compN / *right)*) + $t::new($(self.$compN / *right),+) } } ) ); macro_rules! mat_add_scalar_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Add for $t { type Output = $t; #[inline] fn add(self, right: N) -> $t { - $t::new(self.$comp0 + *right $(, self.$compN + *right)*) + $t::new($(self.$compN + *right),+) } } ) @@ -166,24 +165,24 @@ macro_rules! eye_impl( ); macro_rules! mat_sub_scalar_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl Sub for $t { type Output = $t; #[inline] fn sub(self, right: &N) -> $t { - $t::new(self.$comp0 - *right $(, self.$compN - *right)*) + $t::new($(self.$compN - *right),+) } } ) ); macro_rules! absolute_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Absolute<$t> for $t { #[inline] fn abs(m: &$t) -> $t { - $t::new(::abs(&m.$comp0) $(, ::abs(&m.$compN) )*) + $t::new($(::abs(&m.$compN) ),+) } } ) @@ -216,30 +215,29 @@ macro_rules! iterable_mut_impl( ); macro_rules! one_impl( - ($t: ident, $value0: expr $(, $valueN: expr)* ) => ( + ($t: ident, $($valueN: expr),+ ) => ( impl One for $t { #[inline] fn one() -> $t { - $t::new($value0() $(, $valueN() )*) + $t::new($($valueN() ),+) } } ) ); macro_rules! zero_impl( - ($t: ident, $comp0: ident $(, $compN: ident)* ) => ( + ($t: ident, $($compN: ident),+ ) => ( impl Zero for $t { #[inline] fn zero() -> $t { $t { - $comp0: ::zero() - $(, $compN: ::zero() )* + $($compN: ::zero() ),+ } } #[inline] fn is_zero(&self) -> bool { - ::is_zero(&self.$comp0) $(&& ::is_zero(&self.$compN) )* + $(::is_zero(&self.$compN) )&&+ } } ) diff --git a/src/structs/pnt_macros.rs b/src/structs/pnt_macros.rs index 34b4c627..f026a246 100644 --- a/src/structs/pnt_macros.rs +++ b/src/structs/pnt_macros.rs @@ -1,19 +1,18 @@ #![macro_use] macro_rules! orig_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl Orig for $t { #[inline] fn orig() -> $t { $t { - $comp0: ::zero() - $(, $compN: ::zero() )* + $($compN: ::zero() ),+ } } #[inline] fn is_orig(&self) -> bool { - self.$comp0.is_zero() $(&& self.$compN.is_zero() )* + $(self.$compN.is_zero() )&&+ } } ) @@ -33,40 +32,39 @@ macro_rules! pnt_sub_impl( ); macro_rules! pnt_add_vec_impl( - ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $tv: ident, $($compN: ident),+) => ( impl> Add<$tv> for $t { type Output = $t; #[inline] fn add(self, right: $tv) -> $t { - $t::new(self.$comp0 + right.$comp0 $(, self.$compN + right.$compN)*) + $t::new($(self.$compN + right.$compN),+) } } ) ); macro_rules! pnt_sub_vec_impl( - ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $tv: ident, $($compN: ident),+) => ( impl> Sub<$tv> for $t { type Output = $t; #[inline] fn sub(self, right: $tv) -> $t { - $t::new(self.$comp0 - right.$comp0 $(, self.$compN - right.$compN)*) + $t::new($(self.$compN - right.$compN),+) } } ) ); macro_rules! pnt_as_vec_impl( - ($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $tv: 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)* + $(self.$compN),+ ) } @@ -80,8 +78,7 @@ macro_rules! pnt_as_vec_impl( #[inline] fn set_coords(&mut self, v: $tv) { - self.$comp0 = v.$comp0; - $(self.$compN = v.$compN;)* + $(self.$compN = v.$compN;)+ } } @@ -105,13 +102,12 @@ macro_rules! pnt_as_vec_impl( ); macro_rules! pnt_to_homogeneous_impl( - ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $t2: ident, $extra: 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.$compN = self.$compN; )+ res.$extra = ::one(); res @@ -121,13 +117,12 @@ macro_rules! pnt_to_homogeneous_impl( ); macro_rules! pnt_from_homogeneous_impl( - ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $t2: ident, $extra: 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.$compN = v.$compN / v.$extra; )+ res } diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index a9ee942f..fc8295f6 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -1,18 +1,17 @@ #![macro_use] macro_rules! new_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl $t { /// Creates a new vector. #[inline] - pub fn new($comp0: N $( , $compN: N )*) -> $t { + pub fn new($($compN: N ),+) -> $t { $t { - $comp0: $comp0 - $(, $compN: $compN )* + $($compN: $compN ),+ } } } - ) + ); ); macro_rules! as_array_impl( @@ -79,91 +78,82 @@ macro_rules! at_fast_impl( // FIXME: N should be bounded by Ord instead of BaseFloat… // However, f32/f64 does not implement Ord… macro_rules! ord_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl POrd for $t { #[inline] fn inf(&self, other: &$t) -> $t { - $t::new(self.$comp0.min(other.$comp0) - $(, self.$compN.min(other.$compN))*) + $t::new($(self.$compN.min(other.$compN)),+) } #[inline] fn sup(&self, other: &$t) -> $t { - $t::new(self.$comp0.max(other.$comp0) - $(, self.$compN.max(other.$compN))*) + $t::new($(self.$compN.max(other.$compN)),+) } #[inline] #[allow(unused_mut)] // otherwise there will be a warning for is_eq or Vec1. - fn partial_cmp(&self, other: &$t) -> POrdering { - let is_lt = self.$comp0 < other.$comp0; - let mut is_eq = self.$comp0 == other.$comp0; - - if is_lt { // < - $( - if self.$compN > other.$compN { - return POrdering::NotComparable - } - )* - - POrdering::PartialLess - } - else { // >= - $( - if self.$compN < other.$compN { - return POrdering::NotComparable - } - else if self.$compN > other.$compN { - is_eq = false; - } - - )* - - if is_eq { - POrdering::PartialEqual - } - else { - POrdering::PartialGreater - } - } + fn partial_cmp(&self, other: &$t) -> POrdering { + let mut first = true; + let mut is_lt = false; + let mut is_eq = false; + $( + if first { + is_lt = self.$compN < other.$compN; + is_eq = self.$compN == other.$compN; + first = false; + } + else if is_lt { // < + if self.$compN > other.$compN { + return POrdering::NotComparable + } + } + else { // >= + if self.$compN < other.$compN { + return POrdering::NotComparable + } + else if self.$compN > other.$compN { + is_eq = false; + } + } + )+ + + if is_lt { + POrdering::PartialLess + } + else if is_eq { + POrdering::PartialEqual + } + else { + POrdering::PartialGreater + } } #[inline] fn partial_lt(&self, other: &$t) -> bool { - self.$comp0 < other.$comp0 $(&& self.$compN < other.$compN)* + $(self.$compN < other.$compN)&&+ } #[inline] fn partial_le(&self, other: &$t) -> bool { - self.$comp0 <= other.$comp0 $(&& self.$compN <= other.$compN)* + $(self.$compN <= other.$compN)&&+ } #[inline] fn partial_gt(&self, other: &$t) -> bool { - self.$comp0 > other.$comp0 $(&& self.$compN > other.$compN)* + $(self.$compN > other.$compN)&&+ } #[inline] fn partial_ge(&self, other: &$t) -> bool { - self.$comp0 >= other.$comp0 $(&& self.$compN >= other.$compN)* + $(self.$compN >= other.$compN)&&+ } } ) ); macro_rules! vec_axis_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl $t { - /// Create a unit vector with its `$comp0` component equal to 1.0. - #[inline] - pub fn $comp0() -> $t { - let mut res: $t = ::zero(); - - res.$comp0 = ::one(); - - res - } - $( /// Create a unit vector with its `$compN` component equal to 1.0. #[inline] @@ -174,17 +164,17 @@ macro_rules! vec_axis_impl( res } - )* + )+ } ) ); macro_rules! vec_cast_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Cast<$t> for $t { #[inline] fn from(v: $t) -> $t { - $t::new(Cast::from(v.$comp0) $(, Cast::from(v.$compN))*) + $t::new($(Cast::from(v.$compN)),+) } } ) @@ -255,14 +245,13 @@ macro_rules! index_impl( ); macro_rules! new_repeat_impl( - ($t: ident, $param: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $param: ident, $($compN: ident),+) => ( impl $t { /// Creates a new vector with all its components equal to a given value. #[inline] pub fn new_repeat($param: N) -> $t { $t{ - $comp0: $param - $(, $compN: $param )* + $($compN: $param ),+ } } } @@ -382,172 +371,183 @@ macro_rules! basis_impl( ); macro_rules! axpy_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Axpy for $t { #[inline] fn axpy(&mut self, a: &N, x: &$t) { - self.$comp0.axpy(a, &x.$comp0); - $( self.$compN.axpy(a, &x.$compN); )* + $( self.$compN.axpy(a, &x.$compN); )+ } } ) ); macro_rules! add_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Add<$t> for $t { type Output = $t; #[inline] fn add(self, right: $t) -> $t { - $t::new(self.$comp0 + right.$comp0 $(, self.$compN + right.$compN)*) + $t::new($(self.$compN + right.$compN),+) } } ) ); macro_rules! scalar_add_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( // $t against scalar impl> Add for $t { type Output = $t; #[inline] fn add(self, right: N) -> $t { - $t::new(self.$comp0 + right $(, self.$compN + right)*) + $t::new($(self.$compN + right),+) } } ) ); macro_rules! sub_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Sub<$t> for $t { type Output = $t; #[inline] fn sub(self, right: $t) -> $t { - $t::new(self.$comp0 - right.$comp0 $(, self.$compN - right.$compN)*) + $t::new($(self.$compN - right.$compN),+) } } ) ); macro_rules! scalar_sub_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Sub for $t { type Output = $t; #[inline] fn sub(self, right: N) -> $t { - $t::new(self.$comp0 - right $(, self.$compN - right)*) + $t::new($(self.$compN - right),+) } } ) ); macro_rules! mul_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Mul<$t> for $t { type Output = $t; #[inline] fn mul(self, right: $t) -> $t { - $t::new(self.$comp0 * right.$comp0 $(, self.$compN * right.$compN)*) + $t::new($(self.$compN * right.$compN),+) } } ) ); macro_rules! scalar_mul_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Mul for $t { type Output = $t; #[inline] fn mul(self, right: N) -> $t { - $t::new(self.$comp0 * right $(, self.$compN * right)*) + $t::new($(self.$compN * right),+) } } ) ); macro_rules! div_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Div<$t> for $t { type Output = $t; #[inline] fn div(self, right: $t) -> $t { - $t::new(self.$comp0 / right.$comp0 $(, self.$compN / right.$compN)*) + $t::new($(self.$compN / right.$compN),+) } } ) ); macro_rules! scalar_div_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Div for $t { type Output = $t; #[inline] fn div(self, right: N) -> $t { - $t::new(self.$comp0 / right $(, self.$compN / right)*) + $t::new($(self.$compN / right),+) } } ) ); macro_rules! neg_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl + Copy> Neg for $t { type Output = $t; #[inline] fn neg(self) -> $t { - $t::new(-self.$comp0 $(, -self.$compN )*) + $t::new($(-self.$compN ),+) } } ) ); +macro_rules! add ( + // base case + ($x:expr) => { + $x + }; + // `$x` followed by at least one `$y,` + ($x:expr, $($y:expr),+) => { + // call min! on the tail `$y` + Add::add($x, add!($($y),+)) + } +); + macro_rules! dot_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl Dot for $t { #[inline] fn dot(&self, other: &$t) -> N { - self.$comp0 * other.$comp0 $(+ self.$compN * other.$compN )* + add!($(self.$compN * other.$compN ),+) } } ) ); macro_rules! scalar_ops_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> ScalarMul for $t { #[inline] fn mul_s(&self, other: &N) -> $t { - $t::new(self.$comp0 * *other $(, self.$compN * *other)*) + $t::new($(self.$compN * *other),+) } } impl> ScalarDiv for $t { #[inline] fn div_s(&self, other: &N) -> $t { - $t::new(self.$comp0 / *other $(, self.$compN / *other)*) + $t::new($(self.$compN / *other),+) } } impl> ScalarAdd for $t { #[inline] fn add_s(&self, other: &N) -> $t { - $t::new(self.$comp0 + *other $(, self.$compN + *other)*) + $t::new($(self.$compN + *other),+) } } impl> ScalarSub for $t { #[inline] fn sub_s(&self, other: &N) -> $t { - $t::new(self.$comp0 - *other $(, self.$compN - *other)*) + $t::new($(self.$compN - *other),+) } } ) @@ -595,7 +595,7 @@ macro_rules! translation_impl( ); macro_rules! norm_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl Norm for $t { #[inline] fn sqnorm(&self) -> N { @@ -613,7 +613,6 @@ macro_rules! norm_impl( fn normalize(&mut self) -> N { let l = Norm::norm(self); - self.$comp0 = self.$comp0 / l; $(self.$compN = self.$compN / l;)* l @@ -623,7 +622,7 @@ macro_rules! norm_impl( ); macro_rules! approx_eq_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> ApproxEq for $t { #[inline] fn approx_epsilon(_: Option<$t>) -> N { @@ -637,33 +636,29 @@ macro_rules! approx_eq_impl( #[inline] fn approx_eq(&self, other: &$t) -> bool { - ApproxEq::approx_eq(&self.$comp0, &other.$comp0) - $(&& ApproxEq::approx_eq(&self.$compN, &other.$compN))* + $(ApproxEq::approx_eq(&self.$compN, &other.$compN))&&+ } #[inline] fn approx_eq_eps(&self, other: &$t, eps: &N) -> bool { - ApproxEq::approx_eq_eps(&self.$comp0, &other.$comp0, eps) - $(&& ApproxEq::approx_eq_eps(&self.$compN, &other.$compN, eps))* + $(ApproxEq::approx_eq_eps(&self.$compN, &other.$compN, eps))&&+ } #[inline] fn approx_eq_ulps(&self, other: &$t, ulps: u32) -> bool { - ApproxEq::approx_eq_ulps(&self.$comp0, &other.$comp0, ulps) - $(&& ApproxEq::approx_eq_ulps(&self.$compN, &other.$compN, ulps))* + $(ApproxEq::approx_eq_ulps(&self.$compN, &other.$compN, ulps))&&+ } } ) ); macro_rules! zero_one_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl One for $t { #[inline] fn one() -> $t { $t { - $comp0: ::one() - $(, $compN: ::one() )* + $($compN: ::one() ),+ } } } @@ -672,47 +667,52 @@ macro_rules! zero_one_impl( #[inline] fn zero() -> $t { $t { - $comp0: ::zero() - $(, $compN: ::zero() )* + $($compN: ::zero() ),+ } } #[inline] fn is_zero(&self) -> bool { - self.$comp0.is_zero() - $(&& self.$compN.is_zero() )* + $(self.$compN.is_zero() )&&+ } } ) ); macro_rules! from_iterator_impl( - ($t: ident, $param0: ident $(, $paramN: ident)*) => ( + ($t: ident, $param0: ident) => ( impl FromIterator for $t { #[inline] fn from_iter>(mut $param0: I) -> $t { - $t::new($param0.next().unwrap() $(, $paramN.next().unwrap())*) + $t::new($param0.next().unwrap()) + } + } + ); + ($t: ident, $param0: ident, $($paramN: ident),+) => ( + impl FromIterator for $t { + #[inline] + fn from_iter>(mut $param0: I) -> $t { + $t::new($param0.next().unwrap(), + $($paramN.next().unwrap()),+) } } ) ); macro_rules! bounded_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl Bounded for $t { #[inline] fn max_value() -> $t { $t { - $comp0: Bounded::max_value() - $(, $compN: Bounded::max_value() )* + $($compN: Bounded::max_value() ),+ } } #[inline] fn min_value() -> $t { $t { - $comp0: Bounded::min_value() - $(, $compN: Bounded::min_value() )* + $($compN: Bounded::min_value() ),+ } } } @@ -720,13 +720,12 @@ macro_rules! bounded_impl( ); macro_rules! vec_to_homogeneous_impl( - ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $t2: ident, $extra: ident, $($compN: ident),+) => ( impl ToHomogeneous<$t2> for $t { fn to_homogeneous(&self) -> $t2 { let mut res: $t2 = ::zero(); - res.$comp0 = self.$comp0; - $( res.$compN = self.$compN; )* + $( res.$compN = self.$compN; )+ res } @@ -735,13 +734,12 @@ macro_rules! vec_to_homogeneous_impl( ); macro_rules! vec_from_homogeneous_impl( - ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $t2: ident, $extra: ident, $($compN: ident),+) => ( impl + One + Zero> FromHomogeneous<$t2> for $t { fn from(v: &$t2) -> $t { let mut res: $t = ::zero(); - res.$comp0 = v.$comp0; - $( res.$compN = v.$compN; )* + $( res.$compN = v.$compN; )+ res } @@ -792,14 +790,13 @@ macro_rules! transform_impl( ); macro_rules! vec_as_pnt_impl( - ($tv: ident, $t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($tv: ident, $t: ident, $($compN: ident),+) => ( impl $tv { #[deprecated = "use `na::orig() + this_vector` instead."] #[inline] pub fn to_pnt(self) -> $t { $t::new( - self.$comp0 - $(, self.$compN)* + $(self.$compN),+ ) } @@ -839,11 +836,11 @@ macro_rules! num_float_vec_impl( ); macro_rules! absolute_vec_impl( - ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + ($t: ident, $($compN: ident),+) => ( impl> Absolute<$t> for $t { #[inline] fn abs(m: &$t) -> $t { - $t::new(::abs(&m.$comp0) $(, ::abs(&m.$compN) )*) + $t::new($(::abs(&m.$compN) ),+) } } ) diff --git a/tests/mat.rs b/tests/mat.rs index edaf1f05..5755b394 100644 --- a/tests/mat.rs +++ b/tests/mat.rs @@ -242,7 +242,7 @@ fn test_dmat_from_vec() { ] ); - println!("mat1: {}, mat2: {}", mat1, mat2); + println!("mat1: {:?}, mat2: {:?}", mat1, mat2); assert!(mat1 == mat2); } diff --git a/tests/quat.rs b/tests/quat.rs index 1c967ff0..11ec293f 100644 --- a/tests/quat.rs +++ b/tests/quat.rs @@ -52,7 +52,7 @@ fn test_quat_to_axis_angle() { let q = UnitQuat::new(axis_angle); - println!("{} {}", q.rotation(), axis_angle); + println!("{:?} {:?}", q.rotation(), axis_angle); assert!(na::approx_eq(&q.rotation(), &axis_angle)) } }