From 82ddda154f1ee5099d2e6d6cbfb4935c3ea83010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Wed, 28 Aug 2013 14:22:12 +0200 Subject: [PATCH] Update to work with the last compiler. Because of the unfortunate changes on type parameters resolution: - the Dim trait now needs an useless parameter to infer the Self type. - ApproxEps::epsilon() is broken. --- src/adaptors/rotmat.rs | 10 ++++++---- src/adaptors/transform.rs | 19 ++++++++++++------- src/dmat.rs | 13 ++++++++----- src/dvec.rs | 11 +++++++---- src/mat_macros.rs | 21 ++++++++++++--------- src/mat_spec.rs | 3 ++- src/tests/mat.rs | 4 ++-- src/tests/vec.rs | 4 ++-- src/traits/basis.rs | 2 +- src/traits/dim.rs | 2 +- src/traits/vector.rs | 2 +- src/vec0_spec.rs | 5 +++-- src/vec_macros.rs | 5 +++-- 13 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 1819d404..5d218ef8 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -54,7 +54,7 @@ impl Rotmat> { else { let mut axis = axisangle; let angle = axis.normalize(); - let _1 = One::one::(); + let _1: N = One::one(); let ux = axis.x.clone(); let uy = axis.y.clone(); let uz = axis.z.clone(); @@ -208,8 +208,9 @@ Rand for Rotmat> { impl Dim for Rotmat { #[inline] - fn dim() -> uint { - Dim::dim::() + fn dim(_: Option>) -> uint { + let _dim: Option = None; + Dim::dim(_dim) } } @@ -278,7 +279,8 @@ impl, M2> ToHomogeneous for Rotmat { impl, M: ApproxEq> ApproxEq for Rotmat { #[inline] fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() + // ApproxEq::::approx_epsilon() + fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.") } #[inline] diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index 9985fcad..af78d433 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -85,8 +85,9 @@ impl Transform>, Vec3> { impl Dim for Transform { #[inline] - fn dim() -> uint { - Dim::dim::() + fn dim(_: Option>) -> uint { + let _dim: Option = None; + Dim::dim(_dim) } } @@ -188,7 +189,7 @@ Rotation for Transform { #[inline] fn rotate_by(&mut self, rot: &AV) { // FIXME: this does not seem opitmal - let mut delta = One::one::(); + let mut delta: M = One::one(); delta.rotate_by(rot); self.submat.rotate_by(rot); self.subtrans = delta.rmul(&self.subtrans); @@ -197,7 +198,8 @@ Rotation for Transform { #[inline] fn rotated(&self, rot: &AV) -> Transform { // FIXME: this does not seem opitmal - let delta = One::one::().rotated(rot); + let _1: M = One::one(); + let delta = _1.rotated(rot); Transform::new(self.submat.rotated(rot), delta.rmul(&self.subtrans)) } @@ -283,7 +285,8 @@ ToHomogeneous for Transform { let mut res = self.submat.to_homogeneous(); // copy the translation - let dim = Dim::dim::(); + let _dim: Option = None; + let dim = Dim::dim(_dim); res.set_column(dim - 1, self.subtrans.to_homogeneous()); @@ -294,7 +297,8 @@ ToHomogeneous for Transform { impl + Dim, M2: FromHomogeneous, V> FromHomogeneous for Transform { fn from(m: &M) -> Transform { - Transform::new(FromHomogeneous::from(m), m.column(Dim::dim::() - 1)) + let _dim: Option = None; + Transform::new(FromHomogeneous::from(m), m.column(Dim::dim(_dim) - 1)) } } @@ -302,7 +306,8 @@ impl, M:ApproxEq, V:ApproxEq> ApproxEq for Transform { #[inline] fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() + fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.") + // ApproxEq::::approx_epsilon() } #[inline] diff --git a/src/dmat.rs b/src/dmat.rs index 56a1d427..150b9326 100644 --- a/src/dmat.rs +++ b/src/dmat.rs @@ -36,8 +36,8 @@ pub fn is_zero_mat(mat: &DMat) -> bool { /// components. #[inline] pub fn one_mat_with_dim(dim: uint) -> DMat { - let mut res = zero_mat_with_dim(dim); - let _1 = One::one::(); + let mut res = zero_mat_with_dim(dim); + let _1: N = One::one(); for i in range(0u, dim) { res.set(i, i, &_1); @@ -94,7 +94,7 @@ Mul, DMat> for DMat { for i in range(0u, dim) { for j in range(0u, dim) { - let mut acc = Zero::zero::(); + let mut acc: N = Zero::zero(); for k in range(0u, dim) { acc = acc + self.at(i, k) * other.at(k, j); @@ -161,7 +161,7 @@ Inv for DMat { fn inplace_inverse(&mut self) -> bool { let dim = self.dim; let mut res = one_mat_with_dim::(dim); - let _0T = Zero::zero::(); + let _0T: N = Zero::zero(); // inversion using Gauss-Jordan elimination for k in range(0u, dim) { @@ -256,7 +256,10 @@ impl Transpose for DMat { impl> ApproxEq for DMat { #[inline] fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() + fail!("Fix this.") + // let res: N = ApproxEq::::approx_epsilon(); + + // res } #[inline] diff --git a/src/dvec.rs b/src/dvec.rs index a7a9395e..a79a700c 100644 --- a/src/dvec.rs +++ b/src/dvec.rs @@ -21,7 +21,7 @@ pub struct DVec { /// * `dim` - The dimension of the vector. #[inline] pub fn zero_vec_with_dim(dim: uint) -> DVec { - DVec { at: from_elem(dim, Zero::zero::()) } + DVec { at: from_elem(dim, Zero::zero()) } } /// Tests if all components of the vector are zeroes. @@ -140,7 +140,7 @@ impl DVec { fn dot(&self, other: &DVec) -> N { assert!(self.at.len() == other.at.len()); - let mut res = Zero::zero::(); + let mut res: N = Zero::zero(); for i in range(0u, self.at.len()) { res = res + self.at[i] * other.at[i]; @@ -151,7 +151,7 @@ impl DVec { #[inline] fn sub_dot(&self, a: &DVec, b: &DVec) -> N { - let mut res = Zero::zero::(); + let mut res: N = Zero::zero(); for i in range(0u, self.at.len()) { res = res + (self.at[i] - a.at[i]) * b.at[i]; @@ -261,7 +261,10 @@ impl DVec { impl> ApproxEq for DVec { #[inline] fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() + fail!("Fix me.") + // let res: N = ApproxEq::::approx_epsilon(); + + // res } #[inline] diff --git a/src/mat_macros.rs b/src/mat_macros.rs index 814911ca..a4c7c2f2 100644 --- a/src/mat_macros.rs +++ b/src/mat_macros.rs @@ -136,7 +136,7 @@ macro_rules! one_impl( impl One for $t { #[inline] fn one() -> $t { - let (_0, _1) = (Zero::zero::(), One::one::()); + let (_0, _1): (N, N) = (Zero::zero(), One::one()); return $t::new($value0.clone() $(, $valueN.clone() )*) } } @@ -147,7 +147,7 @@ macro_rules! dim_impl( ($t: ident, $dim: expr) => ( impl Dim for $t { #[inline] - fn dim() -> uint { + fn dim(_: Option<$t>) -> uint { $dim } } @@ -194,7 +194,7 @@ macro_rules! column_impl( #[inline] fn column(&self, col: uint) -> $tv { - let mut res = Zero::zero::<$tv>(); + let mut res: $tv = Zero::zero(); for (i, e) in res.mut_iter().enumerate() { *e = self.at((i, col)); @@ -218,7 +218,7 @@ macro_rules! row_impl( #[inline] fn row(&self, row: uint) -> $tv { - let mut res = Zero::zero::<$tv>(); + let mut res: $tv = Zero::zero(); for (i, e) in res.mut_iter().enumerate() { *e = self.at((row, i)); @@ -239,7 +239,7 @@ macro_rules! mul_impl( for i in range(0u, $dim) { for j in range(0u, $dim) { - let mut acc = Zero::zero::(); + let mut acc: N = Zero::zero(); for k in range(0u, $dim) { acc = acc + self.at((i, k)) * other.at((k, j)); @@ -429,7 +429,8 @@ macro_rules! approx_eq_impl( impl> ApproxEq for $t { #[inline] fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() + fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.") + // ApproxEq::::approx_epsilon() } #[inline] @@ -499,10 +500,12 @@ macro_rules! outer_impl( impl + Zero + Clone> Outer<$t, $m> for $t { #[inline] fn outer(&self, other: &$t) -> $m { - let mut res = Zero::zero::<$m>(); + let mut res: $m = Zero::zero(); - for i in range(0u, Dim::dim::<$t>()) { - for j in range(0u, Dim::dim::<$t>()) { + let _dim: Option<$t> = None; + for i in range(0u, Dim::dim(_dim)) { + let _dim: Option<$t> = None; + for j in range(0u, Dim::dim(_dim)) { res.set((i, j), self.at(i) * other.at(j)) } } diff --git a/src/mat_spec.rs b/src/mat_spec.rs index a3e7453a..f3a96818 100644 --- a/src/mat_spec.rs +++ b/src/mat_spec.rs @@ -25,7 +25,8 @@ Inv for Mat1 { false } else { - self.m11 = One::one::() / self.m11; + let _1: N = One::one(); + self.m11 = _1 / self.m11; true } } diff --git a/src/tests/mat.rs b/src/tests/mat.rs index eab83bb2..fd595e65 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -104,7 +104,7 @@ fn test_inv_mat6() { #[test] fn test_rotation2() { do 10000.times { - let randmat = One::one::>>(); + let randmat: Rotmat> = One::one(); let ang = &Vec1::new(abs::(random()) % Real::pi()); assert!(randmat.rotated(ang).rotation().approx_eq(ang)); @@ -121,7 +121,7 @@ fn test_index_mat2() { #[test] fn test_inv_rotation3() { do 10000.times { - let randmat = One::one::>>(); + let randmat: Rotmat> = One::one(); let dir: Vec3 = random(); let ang = &(dir.normalized() * (abs::(random()) % Real::pi())); let rot = randmat.rotated(ang); diff --git a/src/tests/vec.rs b/src/tests/vec.rs index 0d290e17..a0735dd2 100644 --- a/src/tests/vec.rs +++ b/src/tests/vec.rs @@ -76,8 +76,8 @@ macro_rules! test_scalar_op_impl( macro_rules! test_basis_impl( ($t: ty) => ( do 10000.times { - do Basis::canonical_basis::<$t> |e1| { - do Basis::canonical_basis::<$t> |e2| { + do Basis::canonical_basis |e1: $t| { + do Basis::canonical_basis |e2: $t| { assert!(e1 == e2 || e1.dot(&e2).approx_eq(&Zero::zero())); true diff --git a/src/traits/basis.rs b/src/traits/basis.rs index aec2c6d6..1dbf80f8 100644 --- a/src/traits/basis.rs +++ b/src/traits/basis.rs @@ -11,7 +11,7 @@ pub trait Basis { fn canonical_basis_list() -> ~[Self] { let mut res = ~[]; - do Basis::canonical_basis:: |elem| { + do Basis::canonical_basis |elem| { res.push(elem); true diff --git a/src/traits/dim.rs b/src/traits/dim.rs index fe1eda44..234685a6 100644 --- a/src/traits/dim.rs +++ b/src/traits/dim.rs @@ -3,5 +3,5 @@ */ pub trait Dim { /// The dimension of the object. - fn dim() -> uint; + fn dim(unused_self: Option) -> uint; } diff --git a/src/traits/vector.rs b/src/traits/vector.rs index 3b3bcbf1..042a111a 100644 --- a/src/traits/vector.rs +++ b/src/traits/vector.rs @@ -9,7 +9,7 @@ use traits::scalar_op::{ScalarAdd, ScalarSub}; // NOTE: cant call that `Vector` because it conflicts with std::Vector /// Trait grouping most common operations on vectors. pub trait Vec: Dim + Sub + Add + Neg + Zero + Eq + Mul - + Div + + Div { /// Computes the dot (inner) product of two vectors. #[inline] diff --git a/src/vec0_spec.rs b/src/vec0_spec.rs index c7774876..adab375f 100644 --- a/src/vec0_spec.rs +++ b/src/vec0_spec.rs @@ -61,7 +61,7 @@ impl IterableMut for vec::Vec0 { impl Dim for vec::Vec0 { #[inline] - fn dim() -> uint { + fn dim(_: Option>) -> uint { 0 } } @@ -196,7 +196,8 @@ impl AlgebraicVec for vec::Vec0 { impl> ApproxEq for vec::Vec0 { #[inline] fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() + fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.") + // ApproxEq::::approx_epsilon() } #[inline] diff --git a/src/vec_macros.rs b/src/vec_macros.rs index 8b0ee6db..ba462ebb 100644 --- a/src/vec_macros.rs +++ b/src/vec_macros.rs @@ -174,7 +174,7 @@ macro_rules! dim_impl( ($t: ident, $dim: expr) => ( impl Dim for $t { #[inline] - fn dim() -> uint { + fn dim(_: Option<$t>) -> uint { $dim } } @@ -427,7 +427,8 @@ macro_rules! approx_eq_impl( impl> ApproxEq for $t { #[inline] fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() + fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.") + // ApproxEq::::approx_epsilon() } #[inline]