diff --git a/src/bench/mat.rs b/src/bench/mat.rs index 3b14cde7..3ee2f010 100644 --- a/src/bench/mat.rs +++ b/src/bench/mat.rs @@ -8,11 +8,11 @@ macro_rules! bench_mul_mat( let a: $t = random(); let mut b: $t = random(); - do $bh.iter { - do 1000.times { + $bh.iter(|| { + 1000.times(|| { b = a * b; - } - } + }) + }) } } ) @@ -48,11 +48,11 @@ macro_rules! bench_mul_dmat( let a: DMat = DMat::new_random($nrows, $ncols); let mut b: DMat = DMat::new_random($nrows, $ncols); - do $bh.iter { - do 1000.times { + $bh.iter(|| { + 1000.times(|| { b = a * b; - } - } + }) + }) } } ) @@ -88,11 +88,11 @@ macro_rules! bench_mul_mat_vec( let m : $tm = random(); let mut v : $tv = random(); - do $bh.iter { - do 1000.times { + $bh.iter(|| { + 1000.times(|| { v = m * v - } - } + }) + }) } } ) @@ -128,11 +128,11 @@ macro_rules! bench_mul_dmat_dvec( let m : DMat = DMat::new_random($nrows, $ncols); let mut v : DVec = DVec::new_random($ncols); - do $bh.iter { - do 1000.times { + $bh.iter(|| { + 1000.times(|| { v = m * v - } - } + }) + }) } } ) diff --git a/src/bench/vec.rs b/src/bench/vec.rs index 4948afd5..f9f108d1 100644 --- a/src/bench/vec.rs +++ b/src/bench/vec.rs @@ -10,11 +10,11 @@ macro_rules! bench_dot_vec( let b: $t = random(); let mut d = 0.0; - do $bh.iter { - do 1000.times { + $bh.iter(|| { + 1000.times(|| { d = d + na::dot(&a, &b); - } - } + }) + }) } } ) diff --git a/src/na.rs b/src/na.rs index e2cfd7ce..aab2cea4 100644 --- a/src/na.rs +++ b/src/na.rs @@ -477,7 +477,7 @@ pub fn from_homogeneous>(m: &M) -> Res { /// /// The number of sampling point is implementation-specific. It is always uniform. #[inline(always)] -pub fn sample_sphere(f: &fn(V)) { +pub fn sample_sphere(f: |V| -> ()) { UniformSphereSample::sample(f) } @@ -560,13 +560,13 @@ pub fn mean>(observations: &M) -> N { /// Computes the canonical basis for a given dimension. #[inline(always)] -pub fn canonical_basis(f: &fn(V) -> bool) { +pub fn canonical_basis(f: |V| -> bool) { Basis::canonical_basis(f) } /// Computes the basis of the orthonormal subspace of a given vector. #[inline(always)] -pub fn orthonormal_subspace_basis(v: &V, f: &fn(V) -> bool) { +pub fn orthonormal_subspace_basis(v: &V, f: |V| -> bool) { Basis::orthonormal_subspace_basis(v, f) } diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 9ca6bc99..a10d8a00 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -137,7 +137,7 @@ impl DMat { impl DMat { /// Builds a matrix filled with a given constant. #[inline(always)] - pub fn from_fn(nrows: uint, ncols: uint, f: &fn(uint, uint) -> N) -> DMat { + pub fn from_fn(nrows: uint, ncols: uint, f: |uint, uint| -> N) -> DMat { DMat { nrows: nrows, ncols: ncols, @@ -510,18 +510,14 @@ impl> ApproxEq for DMat { fn approx_eq(&self, other: &DMat) -> bool { let mut zip = self.mij.iter().zip(other.mij.iter()); - do zip.all |(a, b)| { - a.approx_eq(b) - } + zip.all(|(a, b)| a.approx_eq(b)) } #[inline] fn approx_eq_eps(&self, other: &DMat, epsilon: &N) -> bool { let mut zip = self.mij.iter().zip(other.mij.iter()); - do zip.all |(a, b)| { - a.approx_eq_eps(b, epsilon) - } + zip.all(|(a, b)| a.approx_eq_eps(b, epsilon)) } } diff --git a/src/structs/dvec.rs b/src/structs/dvec.rs index 2da09dba..e82fa3a6 100644 --- a/src/structs/dvec.rs +++ b/src/structs/dvec.rs @@ -138,7 +138,7 @@ impl DVec { impl DVec { /// Builds a vector filled with the result of a function. #[inline(always)] - pub fn from_fn(dim: uint, f: &fn(uint) -> N) -> DVec { + pub fn from_fn(dim: uint, f: |uint| -> N) -> DVec { DVec { at: vec::from_fn(dim, |i| f(i)) } } } @@ -329,18 +329,14 @@ impl> ApproxEq for DVec { fn approx_eq(&self, other: &DVec) -> bool { let mut zip = self.at.iter().zip(other.at.iter()); - do zip.all |(a, b)| { - a.approx_eq(b) - } + zip.all(|(a, b)| a.approx_eq(b)) } #[inline] fn approx_eq_eps(&self, other: &DVec, epsilon: &N) -> bool { let mut zip = self.at.iter().zip(other.at.iter()); - do zip.all |(a, b)| { - a.approx_eq_eps(b, epsilon) - } + zip.all(|(a, b)| a.approx_eq_eps(b, epsilon)) } } diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index 6118dfb7..9b5da7db 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -448,18 +448,14 @@ macro_rules! approx_eq_impl( fn approx_eq(&self, other: &$t) -> bool { let mut zip = self.iter().zip(other.iter()); - do zip.all |(a, b)| { - a.approx_eq(b) - } + zip.all(|(a, b)| a.approx_eq(b)) } #[inline] fn approx_eq_eps(&self, other: &$t, epsilon: &N) -> bool { let mut zip = self.iter().zip(other.iter()); - do zip.all |(a, b)| { - a.approx_eq_eps(b, epsilon) - } + zip.all(|(a, b)| a.approx_eq_eps(b, epsilon)) } } ) diff --git a/src/structs/spec/vec.rs b/src/structs/spec/vec.rs index ab660f5e..394d1570 100644 --- a/src/structs/spec/vec.rs +++ b/src/structs/spec/vec.rs @@ -70,37 +70,37 @@ impl Row> for Vec2 { impl Basis for Vec1 { #[inline(always)] - fn canonical_basis(f: &fn(Vec1) -> bool) { + fn canonical_basis(f: |Vec1| -> bool) { f(Vec1::new(One::one())); } #[inline(always)] - fn orthonormal_subspace_basis(_: &Vec1, _: &fn(Vec1) -> bool ) { } + fn orthonormal_subspace_basis(_: &Vec1, _: |Vec1| -> bool ) { } } impl> Basis for Vec2 { #[inline(always)] - fn canonical_basis(f: &fn(Vec2) -> bool) { + fn canonical_basis(f: |Vec2| -> bool) { if !f(Vec2::new(One::one(), Zero::zero())) { return }; f(Vec2::new(Zero::zero(), One::one())); } #[inline] - fn orthonormal_subspace_basis(n: &Vec2, f: &fn(Vec2) -> bool) { + fn orthonormal_subspace_basis(n: &Vec2, f: |Vec2| -> bool) { f(Vec2::new(-n.y, n.x.clone())); } } impl Basis for Vec3 { #[inline(always)] - fn canonical_basis(f: &fn(Vec3) -> bool) { + fn canonical_basis(f: |Vec3| -> bool) { if !f(Vec3::new(One::one(), Zero::zero(), Zero::zero())) { return }; if !f(Vec3::new(Zero::zero(), One::one(), Zero::zero())) { return }; f(Vec3::new(Zero::zero(), Zero::zero(), One::one())); } #[inline(always)] - fn orthonormal_subspace_basis(n: &Vec3, f: &fn(Vec3) -> bool) { + fn orthonormal_subspace_basis(n: &Vec3, f: |Vec3| -> bool) { let a = if n.x.clone().abs() > n.y.clone().abs() { Norm::normalize_cpy(&Vec3::new(n.z.clone(), Zero::zero(), -n.x)) @@ -187,14 +187,14 @@ static SAMPLES_3_F32: [Vec3, ..42] = [ impl UniformSphereSample for Vec1 { #[inline(always)] - fn sample(f: &fn(Vec1)) { + fn sample(f: |Vec1| -> ()) { f(One::one()) } } impl + Clone> UniformSphereSample for Vec2 { #[inline(always)] - fn sample(f: &fn(Vec2)) { + fn sample(f: |Vec2| -> ()) { for sample in SAMPLES_2_F32.iter() { f(Cast::from(*sample)) } @@ -203,7 +203,7 @@ impl + Clone> UniformSphereSample for Vec2 { impl + Clone> UniformSphereSample for Vec3 { #[inline(always)] - fn sample(f: &fn(Vec3)) { + fn sample(f: |Vec3| -> ()) { for sample in SAMPLES_3_F32.iter() { f(Cast::from(*sample)) } @@ -212,7 +212,7 @@ impl + Clone> UniformSphereSample for Vec3 { impl + Clone> UniformSphereSample for Vec4 { #[inline(always)] - fn sample(_: &fn(Vec4)) { + fn sample(_: |Vec4| -> ()) { fail!("UniformSphereSample::>::sample : Not yet implemented.") // for sample in SAMPLES_3_F32.iter() { // f(Cast::from(*sample)) diff --git a/src/structs/spec/vec0.rs b/src/structs/spec/vec0.rs index f4c928a0..1b1a9b90 100644 --- a/src/structs/spec/vec0.rs +++ b/src/structs/spec/vec0.rs @@ -63,10 +63,10 @@ impl Dim for vec::Vec0 { impl Basis for vec::Vec0 { #[inline(always)] - fn canonical_basis(_: &fn(vec::Vec0) -> bool) { } + fn canonical_basis(_: |vec::Vec0| -> bool) { } #[inline(always)] - fn orthonormal_subspace_basis(_: &vec::Vec0, _: &fn(vec::Vec0) -> bool) { } + fn orthonormal_subspace_basis(_: &vec::Vec0, _: |vec::Vec0| -> bool) { } } impl Add> for vec::Vec0 { diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 4021e7d8..f8067002 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -215,7 +215,7 @@ macro_rules! basis_impl( ($t: ident, $trhs: ident, $dim: expr) => ( impl + $trhs>> Basis for $t { #[inline] - fn canonical_basis(f: &fn($t) -> bool) { + fn canonical_basis(f: |$t| -> bool) { for i in range(0u, $dim) { let mut basis_element : $t = Zero::zero(); @@ -228,7 +228,7 @@ macro_rules! basis_impl( } #[inline] - fn orthonormal_subspace_basis(n: &$t, f: &fn($t) -> bool) { + fn orthonormal_subspace_basis(n: &$t, f: |$t| -> bool) { // compute the basis of the orthogonal subspace using Gram-Schmidt // orthogonalization algorithm let mut basis: ~[$t] = ~[]; diff --git a/src/tests/mat.rs b/src/tests/mat.rs index 47cf1f2a..b190a884 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -6,21 +6,21 @@ use na; macro_rules! test_inv_mat_impl( ($t: ty) => ( - do 10000.times { + 10000.times(|| { let randmat : $t = random(); assert!((na::inv(&randmat).unwrap() * randmat).approx_eq(&na::one())); - } + }) ); ) macro_rules! test_transpose_mat_impl( ($t: ty) => ( - do 10000.times { + 10000.times(|| { let randmat : $t = random(); assert!(na::transpose(&na::transpose(&randmat)) == randmat); - } + }) ); ) @@ -86,12 +86,12 @@ fn test_inv_mat6() { #[test] fn test_rotation2() { - do 10000.times { + 10000.times(|| { let randmat: na::Rot2 = na::one(); let ang = Vec1::new(abs::(random()) % Real::pi()); assert!(na::rotation(&na::append_rotation(&randmat, &ang)).approx_eq(&ang)); - } + }) } #[test] @@ -103,14 +103,14 @@ fn test_index_mat2() { #[test] fn test_inv_rotation3() { - do 10000.times { + 10000.times(|| { let randmat: Rot3 = na::one(); let dir: Vec3 = random(); let ang = na::normalize(&dir) * (abs::(random()) % Real::pi()); let rot = na::append_rotation(&randmat, &ang); assert!((na::transpose(&rot) * rot).approx_eq(&na::one())); - } + }) } #[test] diff --git a/src/tests/vec.rs b/src/tests/vec.rs index ac2a6c78..bcd74f65 100644 --- a/src/tests/vec.rs +++ b/src/tests/vec.rs @@ -6,7 +6,7 @@ use na; macro_rules! test_iterator_impl( ($t: ty, $n: ty) => ( - do 10000.times { + 10000.times(|| { let v: $t = random(); let mut mv: $t = v.clone(); let n: $n = random(); @@ -18,24 +18,24 @@ macro_rules! test_iterator_impl( } assert!(nv == mv && nv == v * n); - } + }) ) ) macro_rules! test_commut_dot_impl( ($t: ty) => ( - do 10000.times { + 10000.times(|| { let v1 : $t = random(); let v2 : $t = random(); assert!(na::dot(&v1, &v2).approx_eq(&na::dot(&v2, &v1))); - } + }) ); ) macro_rules! test_scalar_op_impl( ($t: ty, $n: ty) => ( - do 10000.times { + 10000.times(|| { let v1 : $t = random(); let n : $n = random(); @@ -52,62 +52,62 @@ macro_rules! test_scalar_op_impl( v1 = v1 / n; assert!(v1.approx_eq(&v0)); - } + }) ); ) macro_rules! test_basis_impl( ($t: ty) => ( - do 10000.times { - do na::canonical_basis |e1: $t| { - do na::canonical_basis |e2: $t| { + 10000.times(|| { + na::canonical_basis(|e1: $t| { + na::canonical_basis(|e2: $t| { assert!(e1 == e2 || na::dot(&e1, &e2).approx_eq(&na::zero())); true - } + }); assert!(na::norm(&e1).approx_eq(&na::one())); true - } - } + }) + }) ); ) macro_rules! test_subspace_basis_impl( ($t: ty) => ( - do 10000.times { + 10000.times(|| { let v : $t = random(); let v1 = na::normalize(&v); - do na::orthonormal_subspace_basis(&v1) |e1| { + na::orthonormal_subspace_basis(&v1, |e1| { // check vectors are orthogonal to v1 assert!(na::dot(&v1, &e1).approx_eq(&na::zero())); // check vectors form an orthonormal basis assert!(na::norm(&e1).approx_eq(&na::one())); // check vectors form an ortogonal basis - do na::orthonormal_subspace_basis(&v1) |e2| { + na::orthonormal_subspace_basis(&v1, |e2| { assert!(e1 == e2 || na::dot(&e1, &e2).approx_eq(&na::zero())); true - } + }); true - } - } + }) + }) ); ) #[test] fn test_cross_vec3() { - do 10000.times { + 10000.times(|| { let v1 : Vec3 = random(); let v2 : Vec3 = random(); let v3 : Vec3 = na::cross(&v1, &v2); assert!(na::dot(&v3, &v2).approx_eq(&na::zero())); assert!(na::dot(&v3, &v1).approx_eq(&na::zero())); - } + }) } #[test] diff --git a/src/traits/geometry.rs b/src/traits/geometry.rs index eae6433f..1bf295e0 100644 --- a/src/traits/geometry.rs +++ b/src/traits/geometry.rs @@ -278,5 +278,5 @@ pub trait FromHomogeneous { /// function. pub trait UniformSphereSample { /// Iterate through the samples. - fn sample(&fn(Self)); + fn sample(|Self| -> ()); } diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 116f3b9d..ac664003 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -57,10 +57,10 @@ impl + VecExt + Basis + Round> AlgebraicVecE /// Traits of objects which can form a basis (typically vectors). pub trait Basis { /// Iterates through the canonical basis of the space in which this object lives. - fn canonical_basis(&fn(Self) -> bool); + fn canonical_basis(|Self| -> bool); /// Iterates through a basis of the subspace orthogonal to `self`. - fn orthonormal_subspace_basis(&Self, &fn(Self) -> bool); + fn orthonormal_subspace_basis(&Self, |Self| -> bool); } /// Trait to access rows of a matrix or a vector.