Update to work with the last Rust api.
This commit is contained in:
parent
ef718028e8
commit
3858c63291
|
@ -195,7 +195,7 @@ impl<M: RMul<V> + LMul<V>, V> Rotate<V> for Rotmat<M> {
|
||||||
|
|
||||||
impl<M: RMul<V> + LMul<V>, V> Transform<V> for Rotmat<M> {
|
impl<M: RMul<V> + LMul<V>, V> Transform<V> for Rotmat<M> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transform_vec(&self, v: &V) -> V {
|
fn transform(&self, v: &V) -> V {
|
||||||
self.rotate(v)
|
self.rotate(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,8 +244,8 @@ Transformation<Transform<M, V>> for Transform<M, V> {
|
||||||
impl<M: Ts<V>, V: Add<V, V> + Sub<V, V>>
|
impl<M: Ts<V>, V: Add<V, V> + Sub<V, V>>
|
||||||
Ts<V> for Transform<M, V> {
|
Ts<V> for Transform<M, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transform_vec(&self, v: &V) -> V {
|
fn transform(&self, v: &V) -> V {
|
||||||
self.submat.transform_vec(v) + self.subtrans
|
self.submat.transform(v) + self.subtrans
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::num::{One, Zero};
|
use std::num::{One, Zero};
|
||||||
use std::vec::from_elem;
|
use std::vec::from_elem;
|
||||||
use std::cmp::ApproxEq;
|
use std::cmp::ApproxEq;
|
||||||
use std::iterator::IteratorUtil;
|
|
||||||
use traits::inv::Inv;
|
use traits::inv::Inv;
|
||||||
use traits::division_ring::DivisionRing;
|
use traits::division_ring::DivisionRing;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
|
|
16
src/dvec.rs
16
src/dvec.rs
|
@ -2,7 +2,7 @@ use std::num::{Zero, One, Algebraic};
|
||||||
use std::vec::{VecIterator, VecMutIterator};
|
use std::vec::{VecIterator, VecMutIterator};
|
||||||
use std::vec::from_elem;
|
use std::vec::from_elem;
|
||||||
use std::cmp::ApproxEq;
|
use std::cmp::ApproxEq;
|
||||||
use std::iterator::{FromIterator, IteratorUtil};
|
use std::iterator::FromIterator;
|
||||||
use traits::iterable::{Iterable, IterableMut};
|
use traits::iterable::{Iterable, IterableMut};
|
||||||
use traits::ring::Ring;
|
use traits::ring::Ring;
|
||||||
use traits::division_ring::DivisionRing;
|
use traits::division_ring::DivisionRing;
|
||||||
|
@ -117,7 +117,7 @@ impl<N: Add<N,N>> Add<DVec<N>, DVec<N>> for DVec<N> {
|
||||||
fn add(&self, other: &DVec<N>) -> DVec<N> {
|
fn add(&self, other: &DVec<N>) -> DVec<N> {
|
||||||
assert!(self.at.len() == other.at.len());
|
assert!(self.at.len() == other.at.len());
|
||||||
DVec {
|
DVec {
|
||||||
at: self.at.iter().zip(other.at.iter()).transform(|(a, b)| *a + *b).collect()
|
at: self.at.iter().zip(other.at.iter()).map(|(a, b)| *a + *b).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ impl<N: Sub<N,N>> Sub<DVec<N>, DVec<N>> for DVec<N> {
|
||||||
fn sub(&self, other: &DVec<N>) -> DVec<N> {
|
fn sub(&self, other: &DVec<N>) -> DVec<N> {
|
||||||
assert!(self.at.len() == other.at.len());
|
assert!(self.at.len() == other.at.len());
|
||||||
DVec {
|
DVec {
|
||||||
at: self.at.iter().zip(other.at.iter()).transform(|(a, b)| *a - *b).collect()
|
at: self.at.iter().zip(other.at.iter()).map(|(a, b)| *a - *b).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ impl<N: Sub<N,N>> Sub<DVec<N>, DVec<N>> for DVec<N> {
|
||||||
impl<N: Neg<N>> Neg<DVec<N>> for DVec<N> {
|
impl<N: Neg<N>> Neg<DVec<N>> for DVec<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn neg(&self) -> DVec<N> {
|
fn neg(&self) -> DVec<N> {
|
||||||
DVec { at: self.at.iter().transform(|a| -a).collect() }
|
DVec { at: self.at.iter().map(|a| -a).collect() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ impl<N: Ring> SubDot<N> for DVec<N> {
|
||||||
impl<N: Mul<N, N>> ScalarMul<N> for DVec<N> {
|
impl<N: Mul<N, N>> ScalarMul<N> for DVec<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn scalar_mul(&self, s: &N) -> DVec<N> {
|
fn scalar_mul(&self, s: &N) -> DVec<N> {
|
||||||
DVec { at: self.at.iter().transform(|a| a * *s).collect() }
|
DVec { at: self.at.iter().map(|a| a * *s).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -185,7 +185,7 @@ impl<N: Mul<N, N>> ScalarMul<N> for DVec<N> {
|
||||||
impl<N: Div<N, N>> ScalarDiv<N> for DVec<N> {
|
impl<N: Div<N, N>> ScalarDiv<N> for DVec<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn scalar_div(&self, s: &N) -> DVec<N> {
|
fn scalar_div(&self, s: &N) -> DVec<N> {
|
||||||
DVec { at: self.at.iter().transform(|a| a / *s).collect() }
|
DVec { at: self.at.iter().map(|a| a / *s).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -199,7 +199,7 @@ impl<N: Div<N, N>> ScalarDiv<N> for DVec<N> {
|
||||||
impl<N: Add<N, N>> ScalarAdd<N> for DVec<N> {
|
impl<N: Add<N, N>> ScalarAdd<N> for DVec<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn scalar_add(&self, s: &N) -> DVec<N> {
|
fn scalar_add(&self, s: &N) -> DVec<N> {
|
||||||
DVec { at: self.at.iter().transform(|a| a + *s).collect() }
|
DVec { at: self.at.iter().map(|a| a + *s).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -213,7 +213,7 @@ impl<N: Add<N, N>> ScalarAdd<N> for DVec<N> {
|
||||||
impl<N: Sub<N, N>> ScalarSub<N> for DVec<N> {
|
impl<N: Sub<N, N>> ScalarSub<N> for DVec<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn scalar_sub(&self, s: &N) -> DVec<N> {
|
fn scalar_sub(&self, s: &N) -> DVec<N> {
|
||||||
DVec { at: self.at.iter().transform(|a| a - *s).collect() }
|
DVec { at: self.at.iter().map(|a| a - *s).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use std::cast;
|
use std::cast;
|
||||||
use std::num::{One, Zero};
|
use std::num::{One, Zero};
|
||||||
use std::cmp::ApproxEq;
|
use std::cmp::ApproxEq;
|
||||||
use std::iterator::IteratorUtil;
|
|
||||||
use std::vec::{VecIterator, VecMutIterator};
|
use std::vec::{VecIterator, VecMutIterator};
|
||||||
use vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
|
use vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
|
||||||
use traits::dim::Dim;
|
use traits::dim::Dim;
|
||||||
|
|
|
@ -204,14 +204,14 @@ macro_rules! transform_impl(
|
||||||
impl<N: Clone + DivisionRing + Eq>
|
impl<N: Clone + DivisionRing + Eq>
|
||||||
Transform<$v<N>> for $t<N> {
|
Transform<$v<N>> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transform_vec(&self, v: &$v<N>) -> $v<N> {
|
fn transform(&self, v: &$v<N>) -> $v<N> {
|
||||||
self.rmul(v)
|
self.rmul(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_transform(&self, v: &$v<N>) -> $v<N> {
|
fn inv_transform(&self, v: &$v<N>) -> $v<N> {
|
||||||
match self.inverse() {
|
match self.inverse() {
|
||||||
Some(t) => t.transform_vec(v),
|
Some(t) => t.transform(v),
|
||||||
None => fail!("Cannot use inv_transform on a non-inversible matrix.")
|
None => fail!("Cannot use inv_transform on a non-inversible matrix.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#[test]
|
#[test]
|
||||||
use std::iterator::IteratorUtil;
|
|
||||||
#[test]
|
|
||||||
use std::num::{Zero, One};
|
use std::num::{Zero, One};
|
||||||
#[test]
|
#[test]
|
||||||
use std::rand::{random};
|
use std::rand::{random};
|
||||||
|
@ -28,7 +26,7 @@ macro_rules! test_iterator_impl(
|
||||||
let mut mv: $t = v.clone();
|
let mut mv: $t = v.clone();
|
||||||
let n: $n = random();
|
let n: $n = random();
|
||||||
|
|
||||||
let nv: $t = v.iter().transform(|e| e * n).collect();
|
let nv: $t = v.iter().map(|e| e * n).collect();
|
||||||
|
|
||||||
for e in mv.mut_iter() {
|
for e in mv.mut_iter() {
|
||||||
*e = *e * n
|
*e = *e * n
|
||||||
|
|
|
@ -15,10 +15,8 @@ pub trait Transformation<M> {
|
||||||
/// Trait of objects able to transform other objects. This is typically implemented by matrices which
|
/// Trait of objects able to transform other objects. This is typically implemented by matrices which
|
||||||
/// transform vectors.
|
/// transform vectors.
|
||||||
pub trait Transform<V> {
|
pub trait Transform<V> {
|
||||||
// XXX: sadly we cannot call this `transform` as it conflicts with the
|
|
||||||
// iterators' `transform` function (which seems always exist).
|
|
||||||
/// Apply a transformation to an object.
|
/// Apply a transformation to an object.
|
||||||
fn transform_vec(&self, &V) -> V;
|
fn transform(&self, &V) -> V;
|
||||||
/// Apply an inverse transformation to an object.
|
/// Apply an inverse transformation to an object.
|
||||||
fn inv_transform(&self, &V) -> V;
|
fn inv_transform(&self, &V) -> V;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue