for ... advance -> foreach ... in
This commit is contained in:
parent
164ff5b1b2
commit
67dea17abe
|
@ -102,7 +102,7 @@ impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> DVec<N>
|
||||||
|
|
||||||
elt = elt - self.scalar_mul(&basis_element.dot(self));
|
elt = elt - self.scalar_mul(&basis_element.dot(self));
|
||||||
|
|
||||||
for res.iter().advance |v|
|
foreach v in res.iter()
|
||||||
{ elt = elt - v.scalar_mul(&elt.dot(v)) };
|
{ elt = elt - v.scalar_mul(&elt.dot(v)) };
|
||||||
|
|
||||||
if !elt.sqnorm().approx_eq(&Zero::zero())
|
if !elt.sqnorm().approx_eq(&Zero::zero())
|
||||||
|
|
|
@ -102,7 +102,7 @@ macro_rules! column_impl(
|
||||||
{
|
{
|
||||||
fn set_column(&mut self, col: uint, v: V)
|
fn set_column(&mut self, col: uint, v: V)
|
||||||
{
|
{
|
||||||
for v.iter().enumerate().advance |(i, e)|
|
foreach (i, e) in v.iter().enumerate()
|
||||||
{
|
{
|
||||||
if i == Dim::dim::<$t<N>>()
|
if i == Dim::dim::<$t<N>>()
|
||||||
{ break }
|
{ break }
|
||||||
|
@ -115,7 +115,7 @@ macro_rules! column_impl(
|
||||||
{
|
{
|
||||||
let mut res = Zero::zero::<V>();
|
let mut res = Zero::zero::<V>();
|
||||||
|
|
||||||
for res.mut_iter().enumerate().advance |(i, e)|
|
foreach (i, e) in res.mut_iter().enumerate()
|
||||||
{
|
{
|
||||||
if i >= Dim::dim::<$t<N>>()
|
if i >= Dim::dim::<$t<N>>()
|
||||||
{ break }
|
{ break }
|
||||||
|
|
|
@ -31,7 +31,7 @@ macro_rules! test_iterator_impl(
|
||||||
|
|
||||||
let nv: $t = v.iter().transform(|e| e * n).collect();
|
let nv: $t = v.iter().transform(|e| e * n).collect();
|
||||||
|
|
||||||
for mv.mut_iter().advance |e|
|
foreach e in mv.mut_iter()
|
||||||
{ *e = *e * n }
|
{ *e = *e * n }
|
||||||
|
|
||||||
assert!(nv == mv && nv == v.scalar_mul(&n));
|
assert!(nv == mv && nv == v.scalar_mul(&n));
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use std::cast;
|
use std::cast;
|
||||||
use std::num::{Zero, One, Algebraic, Bounded};
|
use std::num::{Zero, One, Algebraic, Bounded};
|
||||||
use std::vec::{VecIterator, VecMutIterator};
|
use std::vec::{VecIterator, VecMutIterator};
|
||||||
use std::iterator::{Iterator, IteratorUtil, FromIterator};
|
use std::iterator::{Iterator, FromIterator};
|
||||||
use std::cmp::ApproxEq;
|
use std::cmp::ApproxEq;
|
||||||
use std::uint::iterate;
|
|
||||||
use traits::iterable::{Iterable, IterableMut};
|
use traits::iterable::{Iterable, IterableMut};
|
||||||
use traits::basis::Basis;
|
use traits::basis::Basis;
|
||||||
use traits::dim::Dim;
|
use traits::dim::Dim;
|
||||||
|
@ -28,16 +27,16 @@ impl<N> vec::Vec0<N>
|
||||||
impl<N: Clone> Indexable<uint, N> for vec::Vec0<N>
|
impl<N: Clone> Indexable<uint, N> for vec::Vec0<N>
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn at(&self, i: uint) -> N
|
pub fn at(&self, _: uint) -> N
|
||||||
{ unsafe { cast::transmute::<&vec::Vec0<N>, &[N, ..0]>(self)[i].clone() } }
|
{ fail!("Cannot index a Vec0.") }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set(&mut self, i: uint, val: N)
|
pub fn set(&mut self, _: uint, _: N)
|
||||||
{ unsafe { cast::transmute::<&mut vec::Vec0<N>, &mut [N, ..0]>(self)[i] = val } }
|
{ }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn swap(&mut self, i1: uint, i2: uint)
|
pub fn swap(&mut self, _: uint, _: uint)
|
||||||
{ unsafe { cast::transmute::<&mut vec::Vec0<N>, &mut [N, ..0]>(self).swap(i1, i2) } }
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone> vec::Vec0<N>
|
impl<N: Clone> vec::Vec0<N>
|
||||||
|
@ -69,50 +68,11 @@ impl<N> Dim for vec::Vec0<N>
|
||||||
|
|
||||||
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for vec::Vec0<N>
|
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for vec::Vec0<N>
|
||||||
{
|
{
|
||||||
pub fn canonical_basis(f: &fn(vec::Vec0<N>))
|
pub fn canonical_basis(_: &fn(vec::Vec0<N>))
|
||||||
{
|
{ }
|
||||||
for iterate(0u, 0) |i|
|
|
||||||
{
|
|
||||||
let mut basis_element : vec::Vec0<N> = Zero::zero();
|
|
||||||
|
|
||||||
basis_element.set(i, One::one());
|
pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0<N>))
|
||||||
|
{ }
|
||||||
f(basis_element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn orthonormal_subspace_basis(&self, f: &fn(vec::Vec0<N>))
|
|
||||||
{
|
|
||||||
// compute the basis of the orthogonal subspace using Gram-Schmidt
|
|
||||||
// orthogonalization algorithm
|
|
||||||
let mut basis: ~[vec::Vec0<N>] = ~[];
|
|
||||||
|
|
||||||
for iterate(0u, 0) |i|
|
|
||||||
{
|
|
||||||
let mut basis_element : vec::Vec0<N> = Zero::zero();
|
|
||||||
|
|
||||||
basis_element.set(i, One::one());
|
|
||||||
|
|
||||||
if basis.len() == 0 - 1
|
|
||||||
{ break; }
|
|
||||||
|
|
||||||
let mut elt = basis_element.clone();
|
|
||||||
|
|
||||||
elt = elt - self.scalar_mul(&basis_element.dot(self));
|
|
||||||
|
|
||||||
for basis.iter().advance |v|
|
|
||||||
{ elt = elt - v.scalar_mul(&elt.dot(v)) };
|
|
||||||
|
|
||||||
if !elt.sqnorm().approx_eq(&Zero::zero())
|
|
||||||
{
|
|
||||||
let new_element = elt.normalized();
|
|
||||||
|
|
||||||
f(new_element.clone());
|
|
||||||
|
|
||||||
basis.push(new_element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Add<N,N>> Add<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N>
|
impl<N: Clone + Add<N,N>> Add<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N>
|
||||||
|
|
|
@ -150,7 +150,7 @@ impl UniformSphereSample for Vec2<f64>
|
||||||
{
|
{
|
||||||
pub fn sample(f: &fn(&'static Vec2<f64>))
|
pub fn sample(f: &fn(&'static Vec2<f64>))
|
||||||
{
|
{
|
||||||
for SAMPLES_2_F64.iter().advance |sample|
|
foreach sample in SAMPLES_2_F64.iter()
|
||||||
{ f(sample) }
|
{ f(sample) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ impl UniformSphereSample for Vec3<f64>
|
||||||
{
|
{
|
||||||
pub fn sample(f: &fn(&'static Vec3<f64>))
|
pub fn sample(f: &fn(&'static Vec3<f64>))
|
||||||
{
|
{
|
||||||
for SAMPLES_3_F64.iter().advance |sample|
|
foreach sample in SAMPLES_3_F64.iter()
|
||||||
{ f(sample) }
|
{ f(sample) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue