Merge pull request #233 from bjz/remove-map-method

Remove {Array1, Array2}::map method
This commit is contained in:
Colin Sherratt 2015-09-29 02:22:51 -04:00
commit 5dd8bc7ef3
6 changed files with 4 additions and 71 deletions

View file

@ -41,10 +41,6 @@ pub trait Array1<Element: Copy>: Index<usize, Output=Element> + IndexMut<usize,
fn replace_elem(&mut self, i: usize, src: Element) -> Element { fn replace_elem(&mut self, i: usize, src: Element) -> Element {
mem::replace(&mut (*self)[i], src) mem::replace(&mut (*self)[i], src)
} }
/// Apply a function to each element.
fn map<F>(&mut self, op: F) -> Self
where F: FnMut(Element) -> Element;
} }
/// A column-major array /// A column-major array
@ -85,8 +81,4 @@ pub trait Array2<Column: Array1<Element>+'static, Row: Array1<Element>, Element:
let (bc, br) = b; let (bc, br) = b;
unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) }; unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) };
} }
/// Apply a function to each column.
fn map<F>(&mut self, op: F) -> Self
where F: FnMut(&Column) -> Column;
} }

View file

@ -473,13 +473,6 @@ impl<S: Copy + 'static> Array2<Vector2<S>, Vector2<S>, S> for Matrix2<S> {
(&mut self[0]).swap_elems(a, b); (&mut self[0]).swap_elems(a, b);
(&mut self[1]).swap_elems(a, b); (&mut self[1]).swap_elems(a, b);
} }
#[inline]
fn map<F>(&mut self, mut op: F) -> Matrix2<S> where F: FnMut(&Vector2<S>) -> Vector2<S> {
self.x = op(&self.x);
self.y = op(&self.y);
*self
}
} }
impl<S: Copy + 'static> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> { impl<S: Copy + 'static> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> {
@ -496,14 +489,6 @@ impl<S: Copy + 'static> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> {
(&mut self[1]).swap_elems(a, b); (&mut self[1]).swap_elems(a, b);
(&mut self[2]).swap_elems(a, b); (&mut self[2]).swap_elems(a, b);
} }
#[inline]
fn map<F>(&mut self, mut op: F) -> Matrix3<S> where F: FnMut(&Vector3<S>) -> Vector3<S> {
self.x = op(&self.x);
self.y = op(&self.y);
self.z = op(&self.z);
*self
}
} }
impl<S: Copy + 'static> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> { impl<S: Copy + 'static> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
@ -522,15 +507,6 @@ impl<S: Copy + 'static> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
(&mut self[2]).swap_elems(a, b); (&mut self[2]).swap_elems(a, b);
(&mut self[3]).swap_elems(a, b); (&mut self[3]).swap_elems(a, b);
} }
#[inline]
fn map<F>(&mut self, mut op: F) -> Matrix4<S> where F: FnMut(&Vector4<S>) -> Vector4<S> {
self.x = op(&self.x);
self.y = op(&self.y);
self.z = op(&self.z);
self.w = op(&self.w);
*self
}
} }
impl<S: BaseFloat> Matrix<S, Vector2<S>> for Matrix2<S> { impl<S: BaseFloat> Matrix<S, Vector2<S>> for Matrix2<S> {

View file

@ -113,14 +113,7 @@ pub trait Point<S: BaseNum, V: Vector<S>>: Array1<S> + Clone {
fn max(&self, p: &Self) -> Self; fn max(&self, p: &Self) -> Self;
} }
impl<S: BaseNum> Array1<S> for Point2<S> { impl<S: BaseNum> Array1<S> for Point2<S> {}
#[inline]
fn map<F>(&mut self, mut op: F) -> Point2<S> where F: FnMut(S) -> S {
self.x = op(self.x);
self.y = op(self.y);
*self
}
}
impl<S: BaseNum> Point<S, Vector2<S>> for Point2<S> { impl<S: BaseNum> Point<S, Vector2<S>> for Point2<S> {
#[inline] #[inline]
@ -220,15 +213,7 @@ impl<S: BaseFloat> ApproxEq<S> for Point2<S> {
} }
} }
impl<S: BaseNum> Array1<S> for Point3<S> { impl<S: BaseNum> Array1<S> for Point3<S> {}
#[inline]
fn map<F>(&mut self, mut op: F) -> Point3<S> where F: FnMut(S) -> S {
self.x = op(self.x);
self.y = op(self.y);
self.z = op(self.z);
*self
}
}
impl<S: BaseNum> Point<S, Vector3<S>> for Point3<S> { impl<S: BaseNum> Point<S, Vector3<S>> for Point3<S> {
#[inline] #[inline]

View file

@ -40,16 +40,7 @@ pub struct Quaternion<S> {
pub v: Vector3<S>, pub v: Vector3<S>,
} }
impl<S: Copy + BaseFloat> Array1<S> for Quaternion<S> { impl<S: Copy + BaseFloat> Array1<S> for Quaternion<S> {}
#[inline]
fn map<F>(&mut self, mut op: F) -> Quaternion<S> where F: FnMut(S) -> S {
self.s = op(self.s);
self.v.x = op(self.v.x);
self.v.y = op(self.v.y);
self.v.z = op(self.v.z);
*self
}
}
impl<S: BaseFloat> Quaternion<S> { impl<S: BaseFloat> Quaternion<S> {
/// Construct a new quaternion from one scalar component and three /// Construct a new quaternion from one scalar component and three

View file

@ -236,12 +236,7 @@ macro_rules! vec {
} }
} }
impl<$S: Copy> Array1<$S> for $Self_<$S> { impl<$S: Copy> Array1<$S> for $Self_<$S> {}
#[inline]
fn map<F>(&mut self, mut op: F) -> $Self_<$S> where F: FnMut($S) -> $S {
$(self.$field = op(self.$field);)+ *self
}
}
impl<S: BaseNum> Vector<S> for $Self_<S> { impl<S: BaseNum> Vector<S> for $Self_<S> {
#[inline] fn from_value(s: S) -> $Self_<S> { $Self_ { $($field: s),+ } } #[inline] fn from_value(s: S) -> $Self_<S> { $Self_ { $($field: s),+ } }

View file

@ -167,12 +167,6 @@ fn test_normalize() {
assert!(Vector4::new(1.0f64, 2.0f64, 4.0f64, 10.0f64).normalize().approx_eq( &Vector4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0) )); assert!(Vector4::new(1.0f64, 2.0f64, 4.0f64, 10.0f64).normalize().approx_eq( &Vector4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0) ));
} }
#[test]
fn test_map() {
assert_eq!(Vector3::new(7.12f64, 3.8f64, -6.98f64).map(|x| x.floor()), Vector3::new(7.0f64, 3.0f64, -7.0f64));
assert_eq!(Vector3::new(7.12f64, 3.8f64, -6.98f64).map(|x| x.max(0.0f64)), Vector3::new(7.12f64, 3.8f64, 0.0f64));
}
#[test] #[test]
fn test_cast() { fn test_cast() {
assert_approx_eq!(Vector2::new(0.9f64, 1.5).cast(), Vector2::new(0.9f32, 1.5)); assert_approx_eq!(Vector2::new(0.9f64, 1.5).cast(), Vector2::new(0.9f32, 1.5));