From f1fe7315f052b86539821b2808397641f7425c76 Mon Sep 17 00:00:00 2001 From: Ben Foppa Date: Wed, 7 Jan 2015 15:16:56 -0500 Subject: [PATCH] Change Fn to FnMut --- src/lib.rs | 6 +++--- src/structs/dmat.rs | 2 +- src/structs/dvec.rs | 2 +- src/structs/dvec_macros.rs | 2 +- src/structs/spec/vec.rs | 20 ++++++++++---------- src/structs/spec/vec0.rs | 4 ++-- src/structs/vec_macros.rs | 4 ++-- src/traits/geometry.rs | 2 +- src/traits/structure.rs | 4 ++-- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e24ca3a5..a13a5f51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -750,7 +750,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: F) { +pub fn sample_sphere(f: F) { UniformSphereSample::sample(f) } @@ -866,13 +866,13 @@ pub fn new_identity(dim: uint) -> M { /// Computes the canonical basis for a given dimension. #[inline(always)] -pub fn canonical_basis bool>(f: F) { +pub fn canonical_basis bool>(f: F) { Basis::canonical_basis(f) } /// Computes the basis of the orthonormal subspace of a given vector. #[inline(always)] -pub fn orthonormal_subspace_basis bool>(v: &V, f: F) { +pub fn orthonormal_subspace_basis bool>(v: &V, f: F) { Basis::orthonormal_subspace_basis(v, f) } diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 496c88e1..4a9a406b 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -127,7 +127,7 @@ impl DMat { impl DMat { /// Builds a matrix filled with a given constant. #[inline(always)] - pub fn from_fn N>(nrows: uint, ncols: uint, f: F) -> DMat { + pub fn from_fn N>(nrows: uint, ncols: uint, mut f: F) -> DMat { DMat { nrows: nrows, ncols: ncols, diff --git a/src/structs/dvec.rs b/src/structs/dvec.rs index f973af94..a8e8a5d8 100644 --- a/src/structs/dvec.rs +++ b/src/structs/dvec.rs @@ -55,7 +55,7 @@ impl DVec { impl DVec { /// Builds a vector filled with the result of a function. #[inline(always)] - pub fn from_fn N>(dim: uint, f: F) -> DVec { + pub fn from_fn N>(dim: uint, mut f: F) -> DVec { DVec { at: range(0, dim).map(|i| f(i)).collect() } } diff --git a/src/structs/dvec_macros.rs b/src/structs/dvec_macros.rs index 5cdef332..6799f83a 100644 --- a/src/structs/dvec_macros.rs +++ b/src/structs/dvec_macros.rs @@ -481,7 +481,7 @@ macro_rules! small_dvec_from_impl ( impl $dvec { /// Builds a vector filled with the result of a function. #[inline(always)] - pub fn from_fn N>(dim: uint, f: F) -> $dvec { + pub fn from_fn N>(dim: uint, mut f: F) -> $dvec { assert!(dim <= $dim); let mut at: [N; $dim] = [ $( $zeros, )* ]; diff --git a/src/structs/spec/vec.rs b/src/structs/spec/vec.rs index 2d07afab..c1485536 100644 --- a/src/structs/spec/vec.rs +++ b/src/structs/spec/vec.rs @@ -74,12 +74,12 @@ impl Row> for Vec2 { impl Basis for Vec1 { #[inline(always)] - fn canonical_basis) -> bool>(f: F) { + fn canonical_basis) -> bool>(mut f: F) { f(Vec1::new(::one())); } #[inline(always)] - fn orthonormal_subspace_basis) -> bool>(_: &Vec1, _: F) { } + fn orthonormal_subspace_basis) -> bool>(_: &Vec1, _: F) { } #[inline] fn canonical_basis_element(i: uint) -> Option> { @@ -94,13 +94,13 @@ impl Basis for Vec1 { impl> Basis for Vec2 { #[inline(always)] - fn canonical_basis) -> bool>(f: F) { + fn canonical_basis) -> bool>(mut f: F) { if !f(Vec2::new(::one(), ::zero())) { return }; f(Vec2::new(::zero(), ::one())); } #[inline] - fn orthonormal_subspace_basis) -> bool>(n: &Vec2, f: F) { + fn orthonormal_subspace_basis) -> bool>(n: &Vec2, mut f: F) { f(Vec2::new(-n.y, n.x)); } @@ -120,14 +120,14 @@ impl> Basis for Vec2 { impl Basis for Vec3 { #[inline(always)] - fn canonical_basis) -> bool>(f: F) { + fn canonical_basis) -> bool>(mut f: F) { if !f(Vec3::new(::one(), ::zero(), ::zero())) { return }; if !f(Vec3::new(::zero(), ::one(), ::zero())) { return }; f(Vec3::new(::zero(), ::zero(), ::one())); } #[inline(always)] - fn orthonormal_subspace_basis) -> bool>(n: &Vec3, f: F) { + fn orthonormal_subspace_basis) -> bool>(n: &Vec3, mut f: F) { let a = if n.x.abs() > n.y.abs() { Norm::normalize_cpy(&Vec3::new(n.z, ::zero(), -n.x)) @@ -230,14 +230,14 @@ static SAMPLES_3_F64: [Vec3; 42] = [ impl UniformSphereSample for Vec1 { #[inline(always)] - fn sample)>(f: F) { + fn sample)>(mut f: F) { f(::one()) } } impl + Copy> UniformSphereSample for Vec2 { #[inline(always)] - fn sample)>(f: F) { + fn sample)>(mut f: F) { for sample in SAMPLES_2_F64.iter() { f(Cast::from(*sample)) } @@ -246,7 +246,7 @@ impl + Copy> UniformSphereSample for Vec2 { impl + Copy> UniformSphereSample for Vec3 { #[inline(always)] - fn sample)>(f: F) { + fn sample)>(mut f: F) { for sample in SAMPLES_3_F64.iter() { f(Cast::from(*sample)) } @@ -255,7 +255,7 @@ impl + Copy> UniformSphereSample for Vec3 { impl + Copy> UniformSphereSample for Vec4 { #[inline(always)] - fn sample)>(_: F) { + fn sample)>(_: F) { panic!("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 db3a0c3f..713c874e 100644 --- a/src/structs/spec/vec0.rs +++ b/src/structs/spec/vec0.rs @@ -92,10 +92,10 @@ impl Dim for vec::Vec0 { impl Basis for vec::Vec0 { #[inline(always)] - fn canonical_basis) -> bool>(_: F) { } + fn canonical_basis) -> bool>(_: F) { } #[inline(always)] - fn orthonormal_subspace_basis) -> bool>(_: &vec::Vec0, _: F) { } + fn orthonormal_subspace_basis) -> bool>(_: &vec::Vec0, _: F) { } #[inline(always)] fn canonical_basis_element(_: uint) -> Option> { diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index aa2573f6..08a99c14 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -321,14 +321,14 @@ macro_rules! basis_impl( ($t: ident, $dim: expr) => ( impl> Basis for $t { #[inline] - fn canonical_basis) -> bool>(f: F) { + fn canonical_basis) -> bool>(mut f: F) { for i in range(0u, $dim) { if !f(Basis::canonical_basis_element(i).unwrap()) { return } } } #[inline] - fn orthonormal_subspace_basis) -> bool>(n: &$t, f: F) { + fn orthonormal_subspace_basis) -> bool>(n: &$t, mut f: F) { // compute the basis of the orthogonal subspace using Gram-Schmidt // orthogonalization algorithm let mut basis: Vec<$t> = Vec::new(); diff --git a/src/traits/geometry.rs b/src/traits/geometry.rs index eda796dc..f797db14 100644 --- a/src/traits/geometry.rs +++ b/src/traits/geometry.rs @@ -266,7 +266,7 @@ pub trait FromHomogeneous { /// function. pub trait UniformSphereSample { /// Iterate through the samples. - fn sample(F); + fn sample(F); } /// The zero element of a vector space, seen as an element of its embeding affine space. diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 5ffa712d..a78ba246 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -109,10 +109,10 @@ pub trait Bounded { /// 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 bool>(F); + fn canonical_basis bool>(F); /// Iterates through a basis of the subspace orthogonal to `self`. - fn orthonormal_subspace_basis bool>(&Self, F); + fn orthonormal_subspace_basis bool>(&Self, F); /// Gets the ith element of the canonical basis. fn canonical_basis_element(i: uint) -> Option;