From dfb8766e381157ec79dfd3c7d143addd065d0b38 Mon Sep 17 00:00:00 2001 From: Norbert Nemec Date: Sun, 1 Sep 2019 20:35:27 +0200 Subject: [PATCH] drop redundant impl_vector_default --- src/vector.rs | 273 -------------------------------------------------- 1 file changed, 273 deletions(-) diff --git a/src/vector.rs b/src/vector.rs index 8ddfe4d..8a7e091 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -364,276 +364,6 @@ macro_rules! impl_vector { } } -// Utility macro for generating associated functions for the vectors -// mainly duplication -#[cfg(feature = "simd")] -macro_rules! impl_vector_default { - ($VectorN:ident { $($field:ident),+ }, $n:expr, $constructor:ident) => { - impl $VectorN { - /// Construct a new vector, using the provided values. - #[inline] - pub const fn new($($field: S),+) -> $VectorN { - $VectorN { $($field: $field),+ } - } - - /// Perform the given operation on each field in the vector, returning a new point - /// constructed from the operations. - #[inline] - pub fn map(self, mut f: F) -> $VectorN - where F: FnMut(S) -> U - { - $VectorN { $($field: f(self.$field)),+ } - } - - /// Construct a new vector where each component is the result of - /// applying the given operation to each pair of components of the - /// given vectors. - #[inline] - pub fn zip(self, v2: $VectorN, mut f: F) -> $VectorN - where F: FnMut(S, S2) -> S3 - { - $VectorN { $($field: f(self.$field, v2.$field)),+ } - } - } - - /// The short constructor. - #[inline] - pub const fn $constructor($($field: S),+) -> $VectorN { - $VectorN::new($($field),+) - } - - impl $VectorN { - /// Component-wise casting to another type. - #[inline] - pub fn cast(&self) -> Option<$VectorN> { - $( - let $field = match NumCast::from(self.$field) { - Some(field) => field, - None => return None - }; - )+ - Some($VectorN { $($field),+ }) - } - } - - impl MetricSpace for $VectorN { - type Metric = S; - - #[inline] - fn distance2(self, other: Self) -> S { - (other - self).magnitude2() - } - } - - impl Array for $VectorN { - type Element = S; - - #[inline] - fn len() -> usize { - $n - } - - #[inline] - fn from_value(scalar: S) -> $VectorN { - $VectorN { $($field: scalar),+ } - } - - #[inline] - fn sum(self) -> S where S: Add { - fold_array!(add, { $(self.$field),+ }) - } - - #[inline] - fn product(self) -> S where S: Mul { - fold_array!(mul, { $(self.$field),+ }) - } - - fn is_finite(&self) -> bool where S: BaseFloat { - $(self.$field.is_finite())&&+ - } - } - - impl Zero for $VectorN { - #[inline] - fn zero() -> $VectorN { - $VectorN::from_value(S::zero()) - } - - #[inline] - fn is_zero(&self) -> bool { - *self == $VectorN::zero() - } - } - - impl iter::Sum<$VectorN> for $VectorN { - #[inline] - fn sum>>(iter: I) -> $VectorN { - iter.fold($VectorN::zero(), Add::add) - } - } - - impl<'a, S: 'a + BaseNum> iter::Sum<&'a $VectorN> for $VectorN { - #[inline] - fn sum>>(iter: I) -> $VectorN { - iter.fold($VectorN::zero(), Add::add) - } - } - - impl VectorSpace for $VectorN { - type Scalar = S; - } - - impl> Neg for $VectorN { - type Output = $VectorN; - - #[inline] - default_fn!( neg(self) -> $VectorN { $VectorN::new($(-self.$field),+) } ); - } - - impl approx::AbsDiffEq for $VectorN { - type Epsilon = S::Epsilon; - - #[inline] - fn default_epsilon() -> S::Epsilon { - S::default_epsilon() - } - - #[inline] - fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool { - $(S::abs_diff_eq(&self.$field, &other.$field, epsilon))&&+ - } - } - - impl approx::RelativeEq for $VectorN { - #[inline] - fn default_max_relative() -> S::Epsilon { - S::default_max_relative() - } - - #[inline] - fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { - $(S::relative_eq(&self.$field, &other.$field, epsilon, max_relative))&&+ - } - } - - impl approx::UlpsEq for $VectorN { - #[inline] - fn default_max_ulps() -> u32 { - S::default_max_ulps() - } - - #[inline] - fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { - $(S::ulps_eq(&self.$field, &other.$field, epsilon, max_ulps))&&+ - } - } - - #[cfg(feature = "rand")] - impl Distribution<$VectorN> for Standard - where Standard: Distribution, - S: BaseFloat { - #[inline] - fn sample(&self, rng: &mut R) -> $VectorN { - $VectorN { $($field: rng.gen()),+ } - } - } - - impl Bounded for $VectorN { - #[inline] - fn min_value() -> $VectorN { - $VectorN { $($field: S::min_value()),+ } - } - - #[inline] - fn max_value() -> $VectorN { - $VectorN { $($field: S::max_value()),+ } - } - } - - impl_operator!( Add<$VectorN > for $VectorN { - fn add(lhs, rhs) -> $VectorN { $VectorN::new($(lhs.$field + rhs.$field),+) } - }); - impl_assignment_operator!( AddAssign<$VectorN > for $VectorN { - fn add_assign(&mut self, other) { $(self.$field += other.$field);+ } - }); - - impl_operator!( Sub<$VectorN > for $VectorN { - fn sub(lhs, rhs) -> $VectorN { $VectorN::new($(lhs.$field - rhs.$field),+) } - }); - impl_assignment_operator!( SubAssign<$VectorN > for $VectorN { - fn sub_assign(&mut self, other) { $(self.$field -= other.$field);+ } - }); - - impl_operator!( Mul for $VectorN { - fn mul(vector, scalar) -> $VectorN { $VectorN::new($(vector.$field * scalar),+) } - }); - impl_assignment_operator!( MulAssign for $VectorN { - fn mul_assign(&mut self, scalar) { $(self.$field *= scalar);+ } - }); - - impl_operator!( Div for $VectorN { - fn div(vector, scalar) -> $VectorN { $VectorN::new($(vector.$field / scalar),+) } - }); - impl_assignment_operator!( DivAssign for $VectorN { - fn div_assign(&mut self, scalar) { $(self.$field /= scalar);+ } - }); - - impl_operator!( Rem for $VectorN { - fn rem(vector, scalar) -> $VectorN { $VectorN::new($(vector.$field % scalar),+) } - }); - impl_assignment_operator!( RemAssign for $VectorN { - fn rem_assign(&mut self, scalar) { $(self.$field %= scalar);+ } - }); - - impl ElementWise for $VectorN { - #[inline] default_fn!( add_element_wise(self, rhs: $VectorN) -> $VectorN { $VectorN::new($(self.$field + rhs.$field),+) } ); - #[inline] default_fn!( sub_element_wise(self, rhs: $VectorN) -> $VectorN { $VectorN::new($(self.$field - rhs.$field),+) } ); - #[inline] default_fn!( mul_element_wise(self, rhs: $VectorN) -> $VectorN { $VectorN::new($(self.$field * rhs.$field),+) } ); - #[inline] default_fn!( div_element_wise(self, rhs: $VectorN) -> $VectorN { $VectorN::new($(self.$field / rhs.$field),+) } ); - #[inline] fn rem_element_wise(self, rhs: $VectorN) -> $VectorN { $VectorN::new($(self.$field % rhs.$field),+) } - - #[inline] default_fn!( add_assign_element_wise(&mut self, rhs: $VectorN) { $(self.$field += rhs.$field);+ } ); - #[inline] default_fn!( sub_assign_element_wise(&mut self, rhs: $VectorN) { $(self.$field -= rhs.$field);+ } ); - #[inline] default_fn!( mul_assign_element_wise(&mut self, rhs: $VectorN) { $(self.$field *= rhs.$field);+ } ); - #[inline] default_fn!( div_assign_element_wise(&mut self, rhs: $VectorN) { $(self.$field /= rhs.$field);+ } ); - #[inline] fn rem_assign_element_wise(&mut self, rhs: $VectorN) { $(self.$field %= rhs.$field);+ } - } - - impl ElementWise for $VectorN { - #[inline] default_fn!( add_element_wise(self, rhs: S) -> $VectorN { $VectorN::new($(self.$field + rhs),+) } ); - #[inline] default_fn!( sub_element_wise(self, rhs: S) -> $VectorN { $VectorN::new($(self.$field - rhs),+) } ); - #[inline] default_fn!( mul_element_wise(self, rhs: S) -> $VectorN { $VectorN::new($(self.$field * rhs),+) } ); - #[inline] default_fn!( div_element_wise(self, rhs: S) -> $VectorN { $VectorN::new($(self.$field / rhs),+) } ); - #[inline] fn rem_element_wise(self, rhs: S) -> $VectorN { $VectorN::new($(self.$field % rhs),+) } - - #[inline] default_fn!( add_assign_element_wise(&mut self, rhs: S) { $(self.$field += rhs);+ } ); - #[inline] default_fn!( sub_assign_element_wise(&mut self, rhs: S) { $(self.$field -= rhs);+ } ); - #[inline] default_fn!( mul_assign_element_wise(&mut self, rhs: S) { $(self.$field *= rhs);+ } ); - #[inline] default_fn!( div_assign_element_wise(&mut self, rhs: S) { $(self.$field /= rhs);+ } ); - #[inline] fn rem_assign_element_wise(&mut self, rhs: S) { $(self.$field %= rhs);+ } - } - - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - impl_scalar_ops!($VectorN { $($field),+ }); - - impl_index_operators!($VectorN, $n, S, usize); - impl_index_operators!($VectorN, $n, [S], Range); - impl_index_operators!($VectorN, $n, [S], RangeTo); - impl_index_operators!($VectorN, $n, [S], RangeFrom); - impl_index_operators!($VectorN, $n, [S], RangeFull); - } -} - macro_rules! impl_scalar_ops { ($VectorN:ident<$S:ident> { $($field:ident),+ }) => { impl_operator!(Mul<$VectorN<$S>> for $S { @@ -651,10 +381,7 @@ macro_rules! impl_scalar_ops { impl_vector!(Vector1 { x }, 1, vec1); impl_vector!(Vector2 { x, y }, 2, vec2); impl_vector!(Vector3 { x, y, z }, 3, vec3); -#[cfg(not(feature = "simd"))] impl_vector!(Vector4 { x, y, z, w }, 4, vec4); -#[cfg(feature = "simd")] -impl_vector_default!(Vector4 { x, y, z, w }, 4, vec4); impl_fixed_array_conversions!(Vector1 { x: 0 }, 1); impl_fixed_array_conversions!(Vector2 { x: 0, y: 1 }, 2);