Remove obsolete closure syntax
This commit is contained in:
parent
bbd1136c29
commit
1429cbf34e
|
@ -87,6 +87,7 @@ Feel free to add your project to this list if you happen to use **nalgebra**!
|
||||||
#![feature(default_type_params)]
|
#![feature(default_type_params)]
|
||||||
#![feature(associated_types)]
|
#![feature(associated_types)]
|
||||||
#![feature(old_orphan_check)]
|
#![feature(old_orphan_check)]
|
||||||
|
#![feature(unboxed_closures)]
|
||||||
#![doc(html_root_url = "http://nalgebra.org/doc")]
|
#![doc(html_root_url = "http://nalgebra.org/doc")]
|
||||||
|
|
||||||
extern crate "rustc-serialize" as rustc_serialize;
|
extern crate "rustc-serialize" as rustc_serialize;
|
||||||
|
@ -749,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: |V| -> ()) {
|
pub fn sample_sphere<V: UniformSphereSample, F: Fn(V)>(f: F) {
|
||||||
UniformSphereSample::sample(f)
|
UniformSphereSample::sample(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,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: |V| -> bool) {
|
pub fn canonical_basis<V: Basis, F: Fn(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>(v: &V, f: |V| -> bool) {
|
pub fn orthonormal_subspace_basis<V: Basis, F: Fn(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(nrows: uint, ncols: uint, f: |uint, uint| -> N) -> DMat<N> {
|
pub fn from_fn<F: Fn(uint, uint) -> N>(nrows: uint, ncols: uint, 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(dim: uint, f: |uint| -> N) -> DVec<N> {
|
pub fn from_fn<F: Fn(uint) -> N>(dim: uint, f: F) -> DVec<N> {
|
||||||
DVec { at: range(0, dim).map(|i| f(i)).collect() }
|
DVec { at: range(0, dim).map(|i| f(i)).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ macro_rules! dvec_impl(
|
||||||
/// Builds a vector filled with random values.
|
/// Builds a vector filled with random values.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_random(dim: uint) -> $dvec<N> {
|
pub fn new_random(dim: uint) -> $dvec<N> {
|
||||||
$dvec::from_fn(dim, |_| rand::random())
|
$dvec::from_fn(dim, |&: _| rand::random())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(dim: uint, f: |uint| -> N) -> $dvec<N> {
|
pub fn from_fn<F: Fn(uint) -> N>(dim: uint, 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: |Vec1<N>| -> bool) {
|
fn canonical_basis<F: Fn(Vec1<N>) -> bool>(f: F) {
|
||||||
f(Vec1::new(::one()));
|
f(Vec1::new(::one()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn orthonormal_subspace_basis(_: &Vec1<N>, _: |Vec1<N>| -> bool) { }
|
fn orthonormal_subspace_basis<F: Fn(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: |Vec2<N>| -> bool) {
|
fn canonical_basis<F: Fn(Vec2<N>) -> bool>(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(n: &Vec2<N>, f: |Vec2<N>| -> bool) {
|
fn orthonormal_subspace_basis<F: Fn(Vec2<N>) -> bool>(n: &Vec2<N>, 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: |Vec3<N>| -> bool) {
|
fn canonical_basis<F: Fn(Vec3<N>) -> bool>(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(n: &Vec3<N>, f: |Vec3<N>| -> bool) {
|
fn orthonormal_subspace_basis<F: Fn(Vec3<N>) -> bool>(n: &Vec3<N>, 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: |Vec1<N>| -> ()) {
|
fn sample<F: Fn(Vec1<N>)>(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: |Vec2<N>| -> ()) {
|
fn sample<F: Fn(Vec2<N>)>(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: |Vec3<N>| -> ()) {
|
fn sample<F: Fn(Vec3<N>)>(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(_: |Vec4<N>| -> ()) {
|
fn sample<F: Fn(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(_: |vec::Vec0<N>| -> bool) { }
|
fn canonical_basis<F: Fn(vec::Vec0<N>) -> bool>(_: F) { }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn orthonormal_subspace_basis(_: &vec::Vec0<N>, _: |vec::Vec0<N>| -> bool) { }
|
fn orthonormal_subspace_basis<F: Fn(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: |$t<N>| -> bool) {
|
fn canonical_basis<F: Fn($t<N>) -> bool>(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(n: &$t<N>, f: |$t<N>| -> bool) {
|
fn orthonormal_subspace_basis<F: Fn($t<N>) -> bool>(n: &$t<N>, 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(|Self| -> ());
|
fn sample<F: Fn(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(|Self| -> bool);
|
fn canonical_basis<F: Fn(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(&Self, |Self| -> bool);
|
fn orthonormal_subspace_basis<F: Fn(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