diff --git a/src/mat2.rs b/src/mat2.rs index bdfbb84..1727c80 100644 --- a/src/mat2.rs +++ b/src/mat2.rs @@ -218,8 +218,7 @@ impl Mat2 { #[inline] pub fn mul_t(&self, value: T) -> Mat2 { - Mat2::from_cols(self.col(0).mul_t(value), - self.col(1).mul_t(value)) + self.map(|&c| c.mul_t(value)) } #[inline] @@ -248,8 +247,7 @@ impl Mat2 { #[inline] pub fn mul_self_t(&mut self, value: T) { - self.x.mul_self_t(value); - self.y.mul_self_t(value); + self.map_mut(|x| x.mul_self_t(value)) } #[inline] @@ -337,7 +335,7 @@ impl ToMat4 for Mat2 { impl Neg> for Mat2 { #[inline] pub fn neg(&self) -> Mat2 { - Mat2::from_cols(-self.col(0), -self.col(1)) + self.map(|&x| -x) } } diff --git a/src/mat3.rs b/src/mat3.rs index 7f1b3f6..02e4492 100644 --- a/src/mat3.rs +++ b/src/mat3.rs @@ -259,9 +259,7 @@ impl Mat3 { #[inline] pub fn mul_t(&self, value: T) -> Mat3 { - Mat3::from_cols(self.col(0).mul_t(value), - self.col(1).mul_t(value), - self.col(2).mul_t(value)) + self.map(|&c| c.mul_t(value)) } #[inline] @@ -302,9 +300,7 @@ impl Mat3 { #[inline] pub fn mul_self_t(&mut self, value: T) { - self.col_mut(0).mul_self_t(value); - self.col_mut(1).mul_self_t(value); - self.col_mut(2).mul_self_t(value); + self.map_mut(|x| x.mul_self_t(value)) } #[inline] @@ -372,7 +368,7 @@ impl ToMat4 for Mat3 { impl Neg> for Mat3 { #[inline] pub fn neg(&self) -> Mat3 { - Mat3::from_cols(-self.col(0), -self.col(1), -self.col(2)) + self.map(|&x| -x) } } diff --git a/src/mat4.rs b/src/mat4.rs index 3f80402..7c493b4 100644 --- a/src/mat4.rs +++ b/src/mat4.rs @@ -301,10 +301,7 @@ impl Mat4 { #[inline] pub fn mul_t(&self, value: T) -> Mat4 { - Mat4::from_cols(self.col(0).mul_t(value), - self.col(1).mul_t(value), - self.col(2).mul_t(value), - self.col(3).mul_t(value)) + self.map(|&c| c.mul_t(value)) } #[inline] @@ -356,10 +353,7 @@ impl Mat4 { #[inline] pub fn mul_self_t(&mut self, value: T) { - self.col_mut(0).mul_self_t(value); - self.col_mut(1).mul_self_t(value); - self.col_mut(2).mul_self_t(value); - self.col_mut(3).mul_self_t(value); + self.map_mut(|x| x.mul_self_t(value)) } #[inline] @@ -423,7 +417,7 @@ impl Mat4 { impl Neg> for Mat4 { #[inline] pub fn neg(&self) -> Mat4 { - Mat4::from_cols(-self.col(0), -self.col(1), -self.col(2), -self.col(3)) + self.map(|&x| -x) } } diff --git a/src/quat.rs b/src/quat.rs index 26e5e0b..82f94cc 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -128,10 +128,7 @@ impl Quat { /// The multiplicative identity, ie: `q = 1 + 0i + 0j + 0i` #[inline] pub fn identity() -> Quat { - Quat::new(One::one(), - Zero::zero(), - Zero::zero(), - Zero::zero()) + Quat::from_sv(One::one(), Vec3::zero()) } /// The additive identity, ie: `q = 0 + 0i + 0j + 0i` @@ -191,19 +188,13 @@ impl Quat { /// The result of multiplying the quaternion a scalar #[inline] pub fn mul_t(&self, value: T) -> Quat { - Quat::new(*self.index(0) * value, - *self.index(1) * value, - *self.index(2) * value, - *self.index(3) * value) + self.map(|&x| x * value) } /// The result of dividing the quaternion a scalar #[inline] pub fn div_t(&self, value: T) -> Quat { - Quat::new(*self.index(0) / value, - *self.index(1) / value, - *self.index(2) / value, - *self.index(3) / value) + self.map(|&x| x / value) } /// The result of multiplying the quaternion by a vector @@ -323,10 +314,7 @@ impl ToMat3 for Quat { impl Neg> for Quat { #[inline] pub fn neg(&self) -> Quat { - Quat::new(-*self.index(0), - -*self.index(1), - -*self.index(2), - -*self.index(3)) + self.map(|&x| -x) } } diff --git a/src/vec2.rs b/src/vec2.rs index 6768cc2..c94c4f0 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -62,8 +62,6 @@ impl Dimensional for Vec2 { pub fn map_mut(&mut self, f: &fn(&mut T)) { f(self.index_mut(0)); f(self.index_mut(1)); - f(self.index_mut(2)); - f(self.index_mut(3)); } } @@ -110,32 +108,27 @@ impl Vec2 { #[inline] pub fn add_t(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) + value, - *self.index(1) + value) + self.map(|&x| x + value) } #[inline] pub fn sub_t(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) - value, - *self.index(1) - value) + self.map(|&x| x - value) } #[inline] pub fn mul_t(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) * value, - *self.index(1) * value) + self.map(|&x| x * value) } #[inline] pub fn div_t(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) / value, - *self.index(1) / value) + self.map(|&x| x / value) } #[inline] pub fn rem_t(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) % value, - *self.index(1) % value) + self.map(|&x| x % value) } #[inline] @@ -170,38 +163,32 @@ impl Vec2 { #[inline] pub fn neg_self(&mut self) { - *self.index_mut(0) = -*self.index(0); - *self.index_mut(1) = -*self.index(1); + self.map_mut(|x| *x = -*x) } #[inline] pub fn add_self_t(&mut self, value: T) { - *self.index_mut(0) += value; - *self.index_mut(1) += value; + self.map_mut(|x| *x += value) } #[inline] pub fn sub_self_t(&mut self, value: T) { - *self.index_mut(0) -= value; - *self.index_mut(1) -= value; + self.map_mut(|x| *x -= value) } #[inline] pub fn mul_self_t(&mut self, value: T) { - *self.index_mut(0) *= value; - *self.index_mut(1) *= value; + self.map_mut(|x| *x *= value) } #[inline] pub fn div_self_t(&mut self, value: T) { - *self.index_mut(0) /= value; - *self.index_mut(1) /= value; + self.map_mut(|x| *x /= value) } #[inline] pub fn rem_self_t(&mut self, value: T) { - *self.index_mut(0) %= value; - *self.index_mut(1) %= value; + self.map_mut(|x| *x %= value) } #[inline] @@ -255,7 +242,7 @@ impl Vec2 { impl Neg> for Vec2 { #[inline] pub fn neg(&self) -> Vec2 { - Vec2::new(-self.index(0), -self.index(1)) + self.map(|&x| -x) } } @@ -425,7 +412,7 @@ impl Vec2 { #[inline] pub fn not(&self) -> Vec2 { - Vec2::new(!*self.index(0), !*self.index(1)) + self.map(|&x| !x) } } diff --git a/src/vec3.rs b/src/vec3.rs index aa28467..1ceff1f 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -63,7 +63,6 @@ impl Dimensional for Vec3 { f(self.index_mut(0)); f(self.index_mut(1)); f(self.index_mut(2)); - f(self.index_mut(3)); } } @@ -116,37 +115,27 @@ impl Vec3 { #[inline] pub fn add_t(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) + value, - *self.index(1) + value, - *self.index(2) + value) + self.map(|&x| x + value) } #[inline] pub fn sub_t(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) - value, - *self.index(1) - value, - *self.index(2) - value) + self.map(|&x| x - value) } #[inline] pub fn mul_t(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) * value, - *self.index(1) * value, - *self.index(2) * value) + self.map(|&x| x * value) } #[inline] pub fn div_t(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) / value, - *self.index(1) / value, - *self.index(2) / value) + self.map(|&x| x / value) } #[inline] pub fn rem_t(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) % value, - *self.index(1) % value, - *self.index(2) % value) + self.map(|&x| x % value) } #[inline] @@ -186,44 +175,32 @@ impl Vec3 { #[inline] pub fn neg_self(&mut self) { - *self.index_mut(0) = -*self.index(0); - *self.index_mut(1) = -*self.index(1); - *self.index_mut(2) = -*self.index(2); + self.map_mut(|x| *x = -*x) } #[inline] pub fn add_self_t(&mut self, value: T) { - *self.index_mut(0) += value; - *self.index_mut(1) += value; - *self.index_mut(2) += value; + self.map_mut(|x| *x += value) } #[inline] pub fn sub_self_t(&mut self, value: T) { - *self.index_mut(0) -= value; - *self.index_mut(1) -= value; - *self.index_mut(2) -= value; + self.map_mut(|x| *x -= value) } #[inline] pub fn mul_self_t(&mut self, value: T) { - *self.index_mut(0) *= value; - *self.index_mut(1) *= value; - *self.index_mut(2) *= value; + self.map_mut(|x| *x *= value) } #[inline] pub fn div_self_t(&mut self, value: T) { - *self.index_mut(0) /= value; - *self.index_mut(1) /= value; - *self.index_mut(2) /= value; + self.map_mut(|x| *x /= value) } #[inline] pub fn rem_self_t(&mut self, value: T) { - *self.index_mut(0) %= value; - *self.index_mut(1) %= value; - *self.index_mut(2) %= value; + self.map_mut(|x| *x %= value) } #[inline] @@ -289,7 +266,7 @@ impl Vec3 { impl Neg> for Vec3 { #[inline] pub fn neg(&self) -> Vec3 { - Vec3::new(-self.index(0), -self.index(1), -self.index(2)) + self.map(|&x| -x) } } @@ -472,7 +449,7 @@ impl Vec3 { #[inline] pub fn not(&self) -> Vec3 { - Vec3::new(!*self.index(0), !*self.index(1), !*self.index(2)) + self.map(|&x| !x) } } diff --git a/src/vec4.rs b/src/vec4.rs index 0597595..9954090 100644 --- a/src/vec4.rs +++ b/src/vec4.rs @@ -122,42 +122,27 @@ impl Vec4 { #[inline] pub fn add_t(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) + value, - *self.index(1) + value, - *self.index(2) + value, - *self.index(3) + value) + self.map(|&x| x + value) } #[inline] pub fn sub_t(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) - value, - *self.index(1) - value, - *self.index(2) - value, - *self.index(3) - value) + self.map(|&x| x - value) } #[inline] pub fn mul_t(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) * value, - *self.index(1) * value, - *self.index(2) * value, - *self.index(3) * value) + self.map(|&x| x * value) } #[inline] pub fn div_t(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) / value, - *self.index(1) / value, - *self.index(2) / value, - *self.index(3) / value) + self.map(|&x| x / value) } #[inline] pub fn rem_t(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) % value, - *self.index(1) % value, - *self.index(2) % value, - *self.index(3) % value) + self.map(|&x| x % value) } #[inline] @@ -202,50 +187,32 @@ impl Vec4 { #[inline] pub fn neg_self(&mut self) { - *self.index_mut(0) = -*self.index(0); - *self.index_mut(1) = -*self.index(1); - *self.index_mut(2) = -*self.index(2); - *self.index_mut(3) = -*self.index(3); + self.map_mut(|x| *x = -*x) } #[inline] pub fn add_self_t(&mut self, value: T) { - *self.index_mut(0) += value; - *self.index_mut(1) += value; - *self.index_mut(2) += value; - *self.index_mut(3) += value; + self.map_mut(|x| *x += value) } #[inline] pub fn sub_self_t(&mut self, value: T) { - *self.index_mut(0) -= value; - *self.index_mut(1) -= value; - *self.index_mut(2) -= value; - *self.index_mut(3) -= value; + self.map_mut(|x| *x -= value) } #[inline] pub fn mul_self_t(&mut self, value: T) { - *self.index_mut(0) *= value; - *self.index_mut(1) *= value; - *self.index_mut(2) *= value; - *self.index_mut(3) *= value; + self.map_mut(|x| *x *= value) } #[inline] pub fn div_self_t(&mut self, value: T) { - *self.index_mut(0) /= value; - *self.index_mut(1) /= value; - *self.index_mut(2) /= value; - *self.index_mut(3) /= value; + self.map_mut(|x| *x /= value) } #[inline] pub fn rem_self_t(&mut self, value: T) { - *self.index_mut(0) %= value; - *self.index_mut(1) %= value; - *self.index_mut(2) %= value; - *self.index_mut(3) %= value; + self.map_mut(|x| *x %= value) } #[inline] @@ -300,7 +267,7 @@ impl Vec4 { impl Neg> for Vec4 { #[inline] pub fn neg(&self) -> Vec4 { - Vec4::new(-self.index(0), -self.index(1), -self.index(2), -self.index(3)) + self.map(|&x| -x) } } @@ -495,9 +462,7 @@ impl Vec4 { } #[inline] - pub fn not(&self) -> Vec4 { - Vec4::new(!*self.index(0), !*self.index(1), !*self.index(2), !*self.index(3)) - } + pub fn not(&self) -> Vec4 { self.map(|&x| !x) } } #[cfg(test)]