diff --git a/src/array.rs b/src/array.rs index fe5cb8b..b277e5f 100644 --- a/src/array.rs +++ b/src/array.rs @@ -41,10 +41,6 @@ pub trait Array1: Index + IndexMut Element { mem::replace(&mut (*self)[i], src) } - - /// Apply a function to each element. - fn map(&mut self, op: F) -> Self - where F: FnMut(Element) -> Element; } /// A column-major array @@ -85,8 +81,4 @@ pub trait Array2+'static, Row: Array1, Element: let (bc, br) = b; unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) }; } - - /// Apply a function to each column. - fn map(&mut self, op: F) -> Self - where F: FnMut(&Column) -> Column; } diff --git a/src/matrix.rs b/src/matrix.rs index 27c23cc..9eb9d8d 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -473,13 +473,6 @@ impl Array2, Vector2, S> for Matrix2 { (&mut self[0]).swap_elems(a, b); (&mut self[1]).swap_elems(a, b); } - - #[inline] - fn map(&mut self, mut op: F) -> Matrix2 where F: FnMut(&Vector2) -> Vector2 { - self.x = op(&self.x); - self.y = op(&self.y); - *self - } } impl Array2, Vector3, S> for Matrix3 { @@ -496,14 +489,6 @@ impl Array2, Vector3, S> for Matrix3 { (&mut self[1]).swap_elems(a, b); (&mut self[2]).swap_elems(a, b); } - - #[inline] - fn map(&mut self, mut op: F) -> Matrix3 where F: FnMut(&Vector3) -> Vector3 { - self.x = op(&self.x); - self.y = op(&self.y); - self.z = op(&self.z); - *self - } } impl Array2, Vector4, S> for Matrix4 { @@ -522,15 +507,6 @@ impl Array2, Vector4, S> for Matrix4 { (&mut self[2]).swap_elems(a, b); (&mut self[3]).swap_elems(a, b); } - - #[inline] - fn map(&mut self, mut op: F) -> Matrix4 where F: FnMut(&Vector4) -> Vector4 { - self.x = op(&self.x); - self.y = op(&self.y); - self.z = op(&self.z); - self.w = op(&self.w); - *self - } } impl Matrix> for Matrix2 { diff --git a/src/point.rs b/src/point.rs index 037ccf8..2d6251a 100644 --- a/src/point.rs +++ b/src/point.rs @@ -113,14 +113,7 @@ pub trait Point>: Array1 + Clone { fn max(&self, p: &Self) -> Self; } -impl Array1 for Point2 { - #[inline] - fn map(&mut self, mut op: F) -> Point2 where F: FnMut(S) -> S { - self.x = op(self.x); - self.y = op(self.y); - *self - } -} +impl Array1 for Point2 {} impl Point> for Point2 { #[inline] @@ -220,15 +213,7 @@ impl ApproxEq for Point2 { } } -impl Array1 for Point3 { - #[inline] - fn map(&mut self, mut op: F) -> Point3 where F: FnMut(S) -> S { - self.x = op(self.x); - self.y = op(self.y); - self.z = op(self.z); - *self - } -} +impl Array1 for Point3 {} impl Point> for Point3 { #[inline] diff --git a/src/quaternion.rs b/src/quaternion.rs index 6280c45..3c241e6 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -40,16 +40,7 @@ pub struct Quaternion { pub v: Vector3, } -impl Array1 for Quaternion { - #[inline] - fn map(&mut self, mut op: F) -> Quaternion 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 Array1 for Quaternion {} impl Quaternion { /// Construct a new quaternion from one scalar component and three diff --git a/src/vector.rs b/src/vector.rs index 20edc63..d5b0392 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -236,12 +236,7 @@ macro_rules! vec { } } - impl<$S: Copy> Array1<$S> for $Self_<$S> { - #[inline] - fn map(&mut self, mut op: F) -> $Self_<$S> where F: FnMut($S) -> $S { - $(self.$field = op(self.$field);)+ *self - } - } + impl<$S: Copy> Array1<$S> for $Self_<$S> {} impl Vector for $Self_ { #[inline] fn from_value(s: S) -> $Self_ { $Self_ { $($field: s),+ } } diff --git a/tests/vector.rs b/tests/vector.rs index 65b0287..b5d79eb 100644 --- a/tests/vector.rs +++ b/tests/vector.rs @@ -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) )); } -#[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] fn test_cast() { assert_approx_eq!(Vector2::new(0.9f64, 1.5).cast(), Vector2::new(0.9f32, 1.5));