Change Fn to FnMut
This commit is contained in:
parent
a086b607a3
commit
f1fe7315f0
|
@ -750,7 +750,7 @@ pub fn from_homogeneous<M, Res: FromHomogeneous<M>>(m: &M) -> Res {
|
||||||
///
|
///
|
||||||
/// The number of sampling point is implementation-specific. It is always uniform.
|
/// The number of sampling point is implementation-specific. It is always uniform.
|
||||||
#[inline(always)]
|
#[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)
|
UniformSphereSample::sample(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -866,13 +866,13 @@ pub fn new_identity<M: Eye>(dim: uint) -> M {
|
||||||
|
|
||||||
/// Computes the canonical basis for a given dimension.
|
/// Computes the canonical basis for a given dimension.
|
||||||
#[inline(always)]
|
#[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)
|
Basis::canonical_basis(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the basis of the orthonormal subspace of a given vector.
|
/// Computes the basis of the orthonormal subspace of a given vector.
|
||||||
#[inline(always)]
|
#[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)
|
Basis::orthonormal_subspace_basis(v, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ impl<N: Clone + Copy> DMat<N> {
|
||||||
impl<N> DMat<N> {
|
impl<N> DMat<N> {
|
||||||
/// Builds a matrix filled with a given constant.
|
/// Builds a matrix filled with a given constant.
|
||||||
#[inline(always)]
|
#[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 {
|
DMat {
|
||||||
nrows: nrows,
|
nrows: nrows,
|
||||||
ncols: ncols,
|
ncols: ncols,
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl<N: Clone> DVec<N> {
|
||||||
impl<N> DVec<N> {
|
impl<N> DVec<N> {
|
||||||
/// Builds a vector filled with the result of a function.
|
/// Builds a vector filled with the result of a function.
|
||||||
#[inline(always)]
|
#[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() }
|
DVec { at: range(0, dim).map(|i| f(i)).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -481,7 +481,7 @@ macro_rules! small_dvec_from_impl (
|
||||||
impl<N: Zero> $dvec<N> {
|
impl<N: Zero> $dvec<N> {
|
||||||
/// Builds a vector filled with the result of a function.
|
/// Builds a vector filled with the result of a function.
|
||||||
#[inline(always)]
|
#[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);
|
assert!(dim <= $dim);
|
||||||
|
|
||||||
let mut at: [N; $dim] = [ $( $zeros, )* ];
|
let mut at: [N; $dim] = [ $( $zeros, )* ];
|
||||||
|
|
|
@ -74,12 +74,12 @@ impl<N: Copy> Row<Vec1<N>> for Vec2<N> {
|
||||||
|
|
||||||
impl<N: One> Basis for Vec1<N> {
|
impl<N: One> Basis for Vec1<N> {
|
||||||
#[inline(always)]
|
#[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()));
|
f(Vec1::new(::one()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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]
|
#[inline]
|
||||||
fn canonical_basis_element(i: uint) -> Option<Vec1<N>> {
|
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> {
|
impl<N: Copy + One + Zero + Neg<Output = N>> Basis for Vec2<N> {
|
||||||
#[inline(always)]
|
#[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 };
|
if !f(Vec2::new(::one(), ::zero())) { return };
|
||||||
f(Vec2::new(::zero(), ::one()));
|
f(Vec2::new(::zero(), ::one()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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));
|
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> {
|
impl<N: BaseFloat> Basis for Vec3<N> {
|
||||||
#[inline(always)]
|
#[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(::one(), ::zero(), ::zero())) { return };
|
||||||
if !f(Vec3::new(::zero(), ::one(), ::zero())) { return };
|
if !f(Vec3::new(::zero(), ::one(), ::zero())) { return };
|
||||||
f(Vec3::new(::zero(), ::zero(), ::one()));
|
f(Vec3::new(::zero(), ::zero(), ::one()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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 =
|
let a =
|
||||||
if n.x.abs() > n.y.abs() {
|
if n.x.abs() > n.y.abs() {
|
||||||
Norm::normalize_cpy(&Vec3::new(n.z, ::zero(), -n.x))
|
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> {
|
impl<N: One + Copy> UniformSphereSample for Vec1<N> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn sample<F: Fn(Vec1<N>)>(f: F) {
|
fn sample<F: FnMut(Vec1<N>)>(mut f: F) {
|
||||||
f(::one())
|
f(::one())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Cast<f64> + Copy> UniformSphereSample for Vec2<N> {
|
impl<N: Cast<f64> + Copy> UniformSphereSample for Vec2<N> {
|
||||||
#[inline(always)]
|
#[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() {
|
for sample in SAMPLES_2_F64.iter() {
|
||||||
f(Cast::from(*sample))
|
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> {
|
impl<N: Cast<f64> + Copy> UniformSphereSample for Vec3<N> {
|
||||||
#[inline(always)]
|
#[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() {
|
for sample in SAMPLES_3_F64.iter() {
|
||||||
f(Cast::from(*sample))
|
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> {
|
impl<N: Cast<f64> + Copy> UniformSphereSample for Vec4<N> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn sample<F: Fn(Vec4<N>)>(_: F) {
|
fn sample<F: FnMut(Vec4<N>)>(_: F) {
|
||||||
panic!("UniformSphereSample::<Vec4<N>>::sample : Not yet implemented.")
|
panic!("UniformSphereSample::<Vec4<N>>::sample : Not yet implemented.")
|
||||||
// for sample in SAMPLES_3_F32.iter() {
|
// for sample in SAMPLES_3_F32.iter() {
|
||||||
// f(Cast::from(*sample))
|
// f(Cast::from(*sample))
|
||||||
|
|
|
@ -92,10 +92,10 @@ impl<N> Dim for vec::Vec0<N> {
|
||||||
|
|
||||||
impl<N> Basis for vec::Vec0<N> {
|
impl<N> Basis for vec::Vec0<N> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn canonical_basis<F: Fn(vec::Vec0<N>) -> bool>(_: F) { }
|
fn canonical_basis<F: FnMut(vec::Vec0<N>) -> bool>(_: F) { }
|
||||||
|
|
||||||
#[inline(always)]
|
#[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)]
|
#[inline(always)]
|
||||||
fn canonical_basis_element(_: uint) -> Option<vec::Vec0<N>> {
|
fn canonical_basis_element(_: uint) -> Option<vec::Vec0<N>> {
|
||||||
|
|
|
@ -321,14 +321,14 @@ macro_rules! basis_impl(
|
||||||
($t: ident, $dim: expr) => (
|
($t: ident, $dim: expr) => (
|
||||||
impl<N: Copy + BaseFloat + ApproxEq<N>> Basis for $t<N> {
|
impl<N: Copy + BaseFloat + ApproxEq<N>> Basis for $t<N> {
|
||||||
#[inline]
|
#[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) {
|
for i in range(0u, $dim) {
|
||||||
if !f(Basis::canonical_basis_element(i).unwrap()) { return }
|
if !f(Basis::canonical_basis_element(i).unwrap()) { return }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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
|
// compute the basis of the orthogonal subspace using Gram-Schmidt
|
||||||
// orthogonalization algorithm
|
// orthogonalization algorithm
|
||||||
let mut basis: Vec<$t<N>> = Vec::new();
|
let mut basis: Vec<$t<N>> = Vec::new();
|
||||||
|
|
|
@ -266,7 +266,7 @@ pub trait FromHomogeneous<U> {
|
||||||
/// function.
|
/// function.
|
||||||
pub trait UniformSphereSample {
|
pub trait UniformSphereSample {
|
||||||
/// Iterate through the samples.
|
/// 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.
|
/// The zero element of a vector space, seen as an element of its embeding affine space.
|
||||||
|
|
|
@ -109,10 +109,10 @@ pub trait Bounded {
|
||||||
/// Traits of objects which can form a basis (typically vectors).
|
/// Traits of objects which can form a basis (typically vectors).
|
||||||
pub trait Basis {
|
pub trait Basis {
|
||||||
/// Iterates through the canonical basis of the space in which this object lives.
|
/// 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`.
|
/// 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.
|
/// Gets the ith element of the canonical basis.
|
||||||
fn canonical_basis_element(i: uint) -> Option<Self>;
|
fn canonical_basis_element(i: uint) -> Option<Self>;
|
||||||
|
|
Loading…
Reference in New Issue