Merge pull request #70 from bfops/fnmut

Change Fn to FnMut
This commit is contained in:
Sébastien Crozet 2015-01-07 22:45:39 +01:00
commit c708632036
9 changed files with 23 additions and 23 deletions

View File

@ -746,7 +746,7 @@ pub fn from_homogeneous<M, Res: FromHomogeneous<M>>(m: &M) -> Res {
///
/// The number of sampling point is implementation-specific. It is always uniform.
#[inline(always)]
pub fn sample_sphere<V: UniformSphereSample, F: Fn(V)>(f: F) {
pub fn sample_sphere<V: UniformSphereSample, F: FnMut(V)>(f: F) {
UniformSphereSample::sample(f)
}
@ -862,13 +862,13 @@ pub fn new_identity<M: Eye>(dim: uint) -> M {
/// Computes the canonical basis for a given dimension.
#[inline(always)]
pub fn canonical_basis<V: Basis, F: Fn(V) -> bool>(f: F) {
pub fn canonical_basis<V: Basis, F: FnMut(V) -> 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<V: Basis, F: Fn(V) -> bool>(v: &V, f: F) {
pub fn orthonormal_subspace_basis<V: Basis, F: FnMut(V) -> bool>(v: &V, f: F) {
Basis::orthonormal_subspace_basis(v, f)
}

View File

@ -127,7 +127,7 @@ impl<N: Clone + Copy> DMat<N> {
impl<N> DMat<N> {
/// Builds a matrix filled with a given constant.
#[inline(always)]
pub fn from_fn<F: Fn(uint, uint) -> N>(nrows: uint, ncols: uint, f: F) -> DMat<N> {
pub fn from_fn<F: FnMut(uint, uint) -> N>(nrows: uint, ncols: uint, mut f: F) -> DMat<N> {
DMat {
nrows: nrows,
ncols: ncols,

View File

@ -55,7 +55,7 @@ impl<N: Clone> DVec<N> {
impl<N> DVec<N> {
/// Builds a vector filled with the result of a function.
#[inline(always)]
pub fn from_fn<F: Fn(uint) -> N>(dim: uint, f: F) -> DVec<N> {
pub fn from_fn<F: FnMut(uint) -> N>(dim: uint, mut f: F) -> DVec<N> {
DVec { at: range(0, dim).map(|i| f(i)).collect() }
}

View File

@ -481,7 +481,7 @@ macro_rules! small_dvec_from_impl (
impl<N: Zero> $dvec<N> {
/// Builds a vector filled with the result of a function.
#[inline(always)]
pub fn from_fn<F: Fn(uint) -> N>(dim: uint, f: F) -> $dvec<N> {
pub fn from_fn<F: FnMut(uint) -> N>(dim: uint, mut f: F) -> $dvec<N> {
assert!(dim <= $dim);
let mut at: [N; $dim] = [ $( $zeros, )* ];

View File

@ -74,12 +74,12 @@ impl<N: Copy> Row<Vec1<N>> for Vec2<N> {
impl<N: One> Basis for Vec1<N> {
#[inline(always)]
fn canonical_basis<F: Fn(Vec1<N>) -> bool>(f: F) {
fn canonical_basis<F: FnMut(Vec1<N>) -> bool>(mut f: F) {
f(Vec1::new(::one()));
}
#[inline(always)]
fn orthonormal_subspace_basis<F: Fn(Vec1<N>) -> bool>(_: &Vec1<N>, _: F) { }
fn orthonormal_subspace_basis<F: FnMut(Vec1<N>) -> bool>(_: &Vec1<N>, _: F) { }
#[inline]
fn canonical_basis_element(i: uint) -> Option<Vec1<N>> {
@ -94,13 +94,13 @@ impl<N: One> Basis for Vec1<N> {
impl<N: Copy + One + Zero + Neg<Output = N>> Basis for Vec2<N> {
#[inline(always)]
fn canonical_basis<F: Fn(Vec2<N>) -> bool>(f: F) {
fn canonical_basis<F: FnMut(Vec2<N>) -> bool>(mut f: F) {
if !f(Vec2::new(::one(), ::zero())) { return };
f(Vec2::new(::zero(), ::one()));
}
#[inline]
fn orthonormal_subspace_basis<F: Fn(Vec2<N>) -> bool>(n: &Vec2<N>, f: F) {
fn orthonormal_subspace_basis<F: FnMut(Vec2<N>) -> bool>(n: &Vec2<N>, mut f: F) {
f(Vec2::new(-n.y, n.x));
}
@ -120,14 +120,14 @@ impl<N: Copy + One + Zero + Neg<Output = N>> Basis for Vec2<N> {
impl<N: BaseFloat> Basis for Vec3<N> {
#[inline(always)]
fn canonical_basis<F: Fn(Vec3<N>) -> bool>(f: F) {
fn canonical_basis<F: FnMut(Vec3<N>) -> 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<F: Fn(Vec3<N>) -> bool>(n: &Vec3<N>, f: F) {
fn orthonormal_subspace_basis<F: FnMut(Vec3<N>) -> bool>(n: &Vec3<N>, 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<f64>; 42] = [
impl<N: One + Copy> UniformSphereSample for Vec1<N> {
#[inline(always)]
fn sample<F: Fn(Vec1<N>)>(f: F) {
fn sample<F: FnMut(Vec1<N>)>(mut f: F) {
f(::one())
}
}
impl<N: Cast<f64> + Copy> UniformSphereSample for Vec2<N> {
#[inline(always)]
fn sample<F: Fn(Vec2<N>)>(f: F) {
fn sample<F: FnMut(Vec2<N>)>(mut f: F) {
for sample in SAMPLES_2_F64.iter() {
f(Cast::from(*sample))
}
@ -246,7 +246,7 @@ impl<N: Cast<f64> + Copy> UniformSphereSample for Vec2<N> {
impl<N: Cast<f64> + Copy> UniformSphereSample for Vec3<N> {
#[inline(always)]
fn sample<F: Fn(Vec3<N>)>(f: F) {
fn sample<F: FnMut(Vec3<N>)>(mut f: F) {
for sample in SAMPLES_3_F64.iter() {
f(Cast::from(*sample))
}
@ -255,7 +255,7 @@ impl<N: Cast<f64> + Copy> UniformSphereSample for Vec3<N> {
impl<N: Cast<f64> + Copy> UniformSphereSample for Vec4<N> {
#[inline(always)]
fn sample<F: Fn(Vec4<N>)>(_: F) {
fn sample<F: FnMut(Vec4<N>)>(_: F) {
panic!("UniformSphereSample::<Vec4<N>>::sample : Not yet implemented.")
// for sample in SAMPLES_3_F32.iter() {
// f(Cast::from(*sample))

View File

@ -92,10 +92,10 @@ impl<N> Dim for vec::Vec0<N> {
impl<N> Basis for vec::Vec0<N> {
#[inline(always)]
fn canonical_basis<F: Fn(vec::Vec0<N>) -> bool>(_: F) { }
fn canonical_basis<F: FnMut(vec::Vec0<N>) -> bool>(_: F) { }
#[inline(always)]
fn orthonormal_subspace_basis<F: Fn(vec::Vec0<N>) -> bool>(_: &vec::Vec0<N>, _: F) { }
fn orthonormal_subspace_basis<F: FnMut(vec::Vec0<N>) -> bool>(_: &vec::Vec0<N>, _: F) { }
#[inline(always)]
fn canonical_basis_element(_: uint) -> Option<vec::Vec0<N>> {

View File

@ -321,14 +321,14 @@ macro_rules! basis_impl(
($t: ident, $dim: expr) => (
impl<N: Copy + BaseFloat + ApproxEq<N>> Basis for $t<N> {
#[inline]
fn canonical_basis<F: Fn($t<N>) -> bool>(f: F) {
fn canonical_basis<F: FnMut($t<N>) -> bool>(mut f: F) {
for i in range(0u, $dim) {
if !f(Basis::canonical_basis_element(i).unwrap()) { return }
}
}
#[inline]
fn orthonormal_subspace_basis<F: Fn($t<N>) -> bool>(n: &$t<N>, f: F) {
fn orthonormal_subspace_basis<F: FnMut($t<N>) -> bool>(n: &$t<N>, mut f: F) {
// compute the basis of the orthogonal subspace using Gram-Schmidt
// orthogonalization algorithm
let mut basis: Vec<$t<N>> = Vec::new();

View File

@ -266,7 +266,7 @@ pub trait FromHomogeneous<U> {
/// function.
pub trait UniformSphereSample {
/// Iterate through the samples.
fn sample<F: Fn(Self)>(F);
fn sample<F: FnMut(Self)>(F);
}
/// The zero element of a vector space, seen as an element of its embeding affine space.

View File

@ -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<F: Fn(Self) -> bool>(F);
fn canonical_basis<F: FnMut(Self) -> bool>(F);
/// Iterates through a basis of the subspace orthogonal to `self`.
fn orthonormal_subspace_basis<F: Fn(Self) -> bool>(&Self, F);
fn orthonormal_subspace_basis<F: FnMut(Self) -> bool>(&Self, F);
/// Gets the ith element of the canonical basis.
fn canonical_basis_element(i: uint) -> Option<Self>;