Remove Array::{map, bimap} functions

This commit is contained in:
Brendan Zabarauskas 2013-09-14 11:53:12 +10:00
parent ce5b2e9243
commit 68e03cd392
4 changed files with 28 additions and 49 deletions

View file

@ -40,17 +40,6 @@ pub trait Array
*self.mut_i(b) = tmp;
}
#[inline]
fn map<U: Clone, SliceU, UU: Array<U, SliceU>>(&self, f: &fn(&T) -> U) -> UU {
Array::build(|i| f(self.i(i)))
}
#[inline]
fn bimap<U: Clone, SliceU, UU: Array<U, SliceU>,
V: Clone, SliceV, VV: Array<V, SliceV>>(&self, other: &UU, f: &fn(&T, &U) -> V) -> VV {
Array::build(|i| f(self.i(i), other.i(i)))
}
fn zip(&self, f: &fn(&T, &T) -> T) -> T;
}

View file

@ -224,9 +224,9 @@ pub trait Matrix
#[inline] fn neg_self(&mut self) { for c in self.mut_iter() { *c = c.neg() } }
#[inline] fn mul_s(&self, s: S) -> Self { self.map(|c| c.mul_s(s.clone())) }
#[inline] fn div_s(&self, s: S) -> Self { self.map(|c| c.div_s(s.clone())) }
#[inline] fn rem_s(&self, s: S) -> Self { self.map(|c| c.rem_s(s.clone())) }
#[inline] fn mul_s(&self, s: S) -> Self { Array::build(|i| self.i(i).mul_s(s.clone())) }
#[inline] fn div_s(&self, s: S) -> Self { Array::build(|i| self.i(i).div_s(s.clone())) }
#[inline] fn rem_s(&self, s: S) -> Self { Array::build(|i| self.i(i).rem_s(s.clone())) }
#[inline] fn mul_self_s(&mut self, s: S) { for c in self.mut_iter() { *c = c.mul_s(s.clone()) } }
#[inline] fn div_self_s(&mut self, s: S) { for c in self.mut_iter() { *c = c.div_s(s.clone()) } }
@ -234,8 +234,8 @@ pub trait Matrix
#[inline] fn mul_v(&self, v: &V) -> V { Array::build(|i| self.r(i).dot(v)) }
#[inline] fn add_m(&self, other: &Self) -> Self { self.bimap(other, |a, b| a.add_v(b) ) }
#[inline] fn sub_m(&self, other: &Self) -> Self { self.bimap(other, |a, b| a.sub_v(b) ) }
#[inline] fn add_m(&self, other: &Self) -> Self { Array::build(|i| self.i(i).add_v(other.i(i))) }
#[inline] fn sub_m(&self, other: &Self) -> Self { Array::build(|i| self.i(i).sub_v(other.i(i))) }
#[inline] fn add_self_m(&mut self, other: &Self) { for (a, b) in self.mut_iter().zip(other.iter()) { *a = a.add_v(b) } }
#[inline] fn sub_self_m(&mut self, other: &Self) { for (a, b) in self.mut_iter().zip(other.iter()) { *a = a.sub_v(b) } }
@ -278,9 +278,9 @@ pub trait Matrix
fn is_symmetric(&self) -> bool;
}
impl<S: Clone + Float> Neg<Mat2<S>> for Mat2<S> { #[inline] fn neg(&self) -> Mat2<S> { self.map(|c| c.neg()) } }
impl<S: Clone + Float> Neg<Mat3<S>> for Mat3<S> { #[inline] fn neg(&self) -> Mat3<S> { self.map(|c| c.neg()) } }
impl<S: Clone + Float> Neg<Mat4<S>> for Mat4<S> { #[inline] fn neg(&self) -> Mat4<S> { self.map(|c| c.neg()) } }
impl<S: Clone + Float> Neg<Mat2<S>> for Mat2<S> { #[inline] fn neg(&self) -> Mat2<S> { Array::build(|i| self.i(i).neg()) } }
impl<S: Clone + Float> Neg<Mat3<S>> for Mat3<S> { #[inline] fn neg(&self) -> Mat3<S> { Array::build(|i| self.i(i).neg()) } }
impl<S: Clone + Float> Neg<Mat4<S>> for Mat4<S> { #[inline] fn neg(&self) -> Mat4<S> { Array::build(|i| self.i(i).neg()) } }
impl<S: Clone + Float>
Matrix<S, [Vec2<S>, ..2], Vec2<S>, [S, ..2]>

View file

@ -62,12 +62,12 @@ pub trait Point
>
: Array<S, Slice>
{
#[inline] fn mul_s(&self, s: S) -> Self { self.map(|x| x.mul(&s)) }
#[inline] fn div_s(&self, s: S) -> Self { self.map(|x| x.div(&s)) }
#[inline] fn rem_s(&self, s: S) -> Self { self.map(|x| x.rem(&s)) }
#[inline] fn mul_s(&self, s: S) -> Self { Array::build(|i| self.i(i).mul(&s)) }
#[inline] fn div_s(&self, s: S) -> Self { Array::build(|i| self.i(i).div(&s)) }
#[inline] fn rem_s(&self, s: S) -> Self { Array::build(|i| self.i(i).rem(&s)) }
#[inline] fn add_v(&self, other: &V) -> Self { self.bimap(other, |a, b| a.add(b) ) }
#[inline] fn sub_p(&self, other: &Self) -> V { self.bimap(other, |a, b| a.sub(b) ) }
#[inline] fn add_v(&self, other: &V) -> Self { Array::build(|i| self.i(i).add(other.i(i))) }
#[inline] fn sub_p(&self, other: &Self) -> V { Array::build(|i| self.i(i).sub(other.i(i))) }
#[inline] fn mul_self_s(&mut self, s: S) { for x in self.mut_iter() { *x = x.mul(&s) } }
#[inline] fn div_self_s(&mut self, s: S) { for x in self.mut_iter() { *x = x.div(&s) } }

View file

@ -103,17 +103,17 @@ pub trait Vector
+ Neg<Self>
+ Zero + One
{
#[inline] fn add_s(&self, s: S) -> Self;
#[inline] fn sub_s(&self, s: S) -> Self;
#[inline] fn mul_s(&self, s: S) -> Self;
#[inline] fn div_s(&self, s: S) -> Self;
#[inline] fn rem_s(&self, s: S) -> Self;
#[inline] fn add_s(&self, s: S) -> Self { Array::build(|i| self.i(i).add(&s)) }
#[inline] fn sub_s(&self, s: S) -> Self { Array::build(|i| self.i(i).sub(&s)) }
#[inline] fn mul_s(&self, s: S) -> Self { Array::build(|i| self.i(i).mul(&s)) }
#[inline] fn div_s(&self, s: S) -> Self { Array::build(|i| self.i(i).div(&s)) }
#[inline] fn rem_s(&self, s: S) -> Self { Array::build(|i| self.i(i).rem(&s)) }
#[inline] fn add_v(&self, other: &Self) -> Self;
#[inline] fn sub_v(&self, other: &Self) -> Self;
#[inline] fn mul_v(&self, other: &Self) -> Self;
#[inline] fn div_v(&self, other: &Self) -> Self;
#[inline] fn rem_v(&self, other: &Self) -> Self;
#[inline] fn add_v(&self, other: &Self) -> Self { Array::build(|i| self.i(i).add(other.i(i))) }
#[inline] fn sub_v(&self, other: &Self) -> Self { Array::build(|i| self.i(i).sub(other.i(i))) }
#[inline] fn mul_v(&self, other: &Self) -> Self { Array::build(|i| self.i(i).mul(other.i(i))) }
#[inline] fn div_v(&self, other: &Self) -> Self { Array::build(|i| self.i(i).div(other.i(i))) }
#[inline] fn rem_v(&self, other: &Self) -> Self { Array::build(|i| self.i(i).rem(other.i(i))) }
#[inline] fn neg_self(&mut self);
@ -145,29 +145,19 @@ pub trait Vector
#[inline] fn comp_max(&self) -> S { self.iter().max().unwrap().clone() }
}
#[inline] fn dot<S: Clone + Num + Ord, Slice, V: Vector<S, Slice>>(a: V, b: V) -> S { a.dot(&b) }
impl<S: Clone + Num + Ord> One for Vec2<S> { #[inline] fn one() -> Vec2<S> { Vec2::ident() } }
impl<S: Clone + Num + Ord> One for Vec3<S> { #[inline] fn one() -> Vec3<S> { Vec3::ident() } }
impl<S: Clone + Num + Ord> One for Vec4<S> { #[inline] fn one() -> Vec4<S> { Vec4::ident() } }
impl<S: Clone + Num + Ord> Neg<Vec2<S>> for Vec2<S> { #[inline] fn neg(&self) -> Vec2<S> { Vec2::new(-self.x, -self.y) } }
impl<S: Clone + Num + Ord> Neg<Vec3<S>> for Vec3<S> { #[inline] fn neg(&self) -> Vec3<S> { Vec3::new(-self.x, -self.y, -self.z) } }
impl<S: Clone + Num + Ord> Neg<Vec4<S>> for Vec4<S> { #[inline] fn neg(&self) -> Vec4<S> { Vec4::new(-self.x, -self.y, -self.z, -self.w) } }
impl<S: Clone + Num + Ord> Neg<Vec2<S>> for Vec2<S> { #[inline] fn neg(&self) -> Vec2<S> { Array::build(|i| self.i(i).neg()) } }
impl<S: Clone + Num + Ord> Neg<Vec3<S>> for Vec3<S> { #[inline] fn neg(&self) -> Vec3<S> { Array::build(|i| self.i(i).neg()) } }
impl<S: Clone + Num + Ord> Neg<Vec4<S>> for Vec4<S> { #[inline] fn neg(&self) -> Vec4<S> { Array::build(|i| self.i(i).neg()) } }
macro_rules! vector(
(impl $Self:ident <$S:ident> $Slice:ty { $x:ident, $($xs:ident),+ }) => (
impl<$S: Clone + Num + Ord> Vector<$S, $Slice> for $Self<$S> {
#[inline] fn add_s(&self, s: S) -> $Self<$S> { $Self::new(self.$x.add(&s), $(self.$xs.add(&s)),+) }
#[inline] fn sub_s(&self, s: S) -> $Self<$S> { $Self::new(self.$x.sub(&s), $(self.$xs.sub(&s)),+) }
#[inline] fn mul_s(&self, s: S) -> $Self<$S> { $Self::new(self.$x.mul(&s), $(self.$xs.mul(&s)),+) }
#[inline] fn div_s(&self, s: S) -> $Self<$S> { $Self::new(self.$x.div(&s), $(self.$xs.div(&s)),+) }
#[inline] fn rem_s(&self, s: S) -> $Self<$S> { $Self::new(self.$x.rem(&s), $(self.$xs.rem(&s)),+) }
#[inline] fn add_v(&self, other: &$Self<$S>) -> $Self<$S> { $Self::new(self.$x.add(&other.$x), $(self.$xs.add(&other.$xs)),+) }
#[inline] fn sub_v(&self, other: &$Self<$S>) -> $Self<$S> { $Self::new(self.$x.sub(&other.$x), $(self.$xs.sub(&other.$xs)),+) }
#[inline] fn mul_v(&self, other: &$Self<$S>) -> $Self<$S> { $Self::new(self.$x.mul(&other.$x), $(self.$xs.mul(&other.$xs)),+) }
#[inline] fn div_v(&self, other: &$Self<$S>) -> $Self<$S> { $Self::new(self.$x.div(&other.$x), $(self.$xs.div(&other.$xs)),+) }
#[inline] fn rem_v(&self, other: &$Self<$S>) -> $Self<$S> { $Self::new(self.$x.rem(&other.$x), $(self.$xs.rem(&other.$xs)),+) }
#[inline] fn neg_self(&mut self) { self.$x = -self.$x; $(self.$xs = -self.$xs;)+ }
#[inline] fn add_self_s(&mut self, s: S) { self.$x = self.$x.add(&s); $(self.$xs = self.$x.add(&s);)+ }