From f4ab9403a4c27e9b8a4f8f2ca238b25e819a5571 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 28 Aug 2024 10:47:30 -0700 Subject: [PATCH] oh my god use tabs --- fixed_wide_vectors/src/affine.rs | 4 +- fixed_wide_vectors/src/macros/mod.rs | 480 +++++++++++++------------- fixed_wide_vectors/src/macros/wide.rs | 44 +-- fixed_wide_vectors/src/vector.rs | 18 +- 4 files changed, 273 insertions(+), 273 deletions(-) diff --git a/fixed_wide_vectors/src/affine.rs b/fixed_wide_vectors/src/affine.rs index f1d3fc3..d4bcc00 100644 --- a/fixed_wide_vectors/src/affine.rs +++ b/fixed_wide_vectors/src/affine.rs @@ -5,8 +5,8 @@ use fixed_wide_traits::wide::WideDot; // mat4x3.wide_dot(vec3.extend(1)) pub struct Affine{ - pub matrix:M, - pub offset:T, + pub matrix:M, + pub offset:T, } impl Affine{ diff --git a/fixed_wide_vectors/src/macros/mod.rs b/fixed_wide_vectors/src/macros/mod.rs index 0d9be65..4cf9651 100644 --- a/fixed_wide_vectors/src/macros/mod.rs +++ b/fixed_wide_vectors/src/macros/mod.rs @@ -5,277 +5,277 @@ pub mod wide; #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_vector { - ( $struct: ident { $($field: ident), + }, ( $($generic: ident), + ), $size: expr ) => { - impl $struct { - /// Constructs a new vector with the specified values for each field. - /// - /// # Example - /// - /// ``` - /// use fixed_wide_vectors::Vector2; - /// - /// let vec2 = Vector2::new(0, 0); - /// - /// assert_eq!(vec2.x, 0); - /// assert_eq!(vec2.y, 0); - /// ``` - #[inline(always)] - pub const fn new( $($field: T), + ) -> Self { - Self { - $( $field ), + - } - } + ( $struct: ident { $($field: ident), + }, ( $($generic: ident), + ), $size: expr ) => { + impl $struct { + /// Constructs a new vector with the specified values for each field. + /// + /// # Example + /// + /// ``` + /// use fixed_wide_vectors::Vector2; + /// + /// let vec2 = Vector2::new(0, 0); + /// + /// assert_eq!(vec2.x, 0); + /// assert_eq!(vec2.y, 0); + /// ``` + #[inline(always)] + pub const fn new( $($field: T), + ) -> Self { + Self { + $( $field ), + + } + } - /// Consumes the vector and returns its values as an array. - /// - /// # Example - /// - /// ``` - /// use fixed_wide_vectors::Vector2; - /// - /// let vec2 = Vector2::new(0, 0); - /// let array = vec2.to_array(); - /// - /// assert_eq!(array, [0, 0]); - /// ``` - #[inline(always)] - pub fn to_array(self) -> [T; $size] { - [ $(self.$field), + ] - } + /// Consumes the vector and returns its values as an array. + /// + /// # Example + /// + /// ``` + /// use fixed_wide_vectors::Vector2; + /// + /// let vec2 = Vector2::new(0, 0); + /// let array = vec2.to_array(); + /// + /// assert_eq!(array, [0, 0]); + /// ``` + #[inline(always)] + pub fn to_array(self) -> [T; $size] { + [ $(self.$field), + ] + } - /// Consumes the vector and returns its values as a tuple. - /// - /// # Example - /// - /// ``` - /// use fixed_wide_vectors::Vector2; - /// - /// let vec2 = Vector2::new(0, 0); - /// let tuple = vec2.to_tuple(); - /// - /// assert_eq!(tuple, (0, 0)); - /// ``` - #[inline(always)] - pub fn to_tuple(self) -> ( $($generic), + ) { - ( $(self.$field), + ) - } + /// Consumes the vector and returns its values as a tuple. + /// + /// # Example + /// + /// ``` + /// use fixed_wide_vectors::Vector2; + /// + /// let vec2 = Vector2::new(0, 0); + /// let tuple = vec2.to_tuple(); + /// + /// assert_eq!(tuple, (0, 0)); + /// ``` + #[inline(always)] + pub fn to_tuple(self) -> ( $($generic), + ) { + ( $(self.$field), + ) + } - /// Consumes the vector and returns a new vector with the given function applied on each field. - /// - /// # Example - /// - /// ``` - /// use fixed_wide_vectors::Vector2; - /// - /// let vec2 = Vector2::new(1, 2) - /// .map(|i| i * 2); - /// - /// assert_eq!(vec2, Vector2::new(2, 4)); - /// ``` - #[inline] - pub fn map(self, f: F) -> $struct - where - F: Fn(T) -> U - { - $struct { - $( $field: f(self.$field) ), + - } - } - } + /// Consumes the vector and returns a new vector with the given function applied on each field. + /// + /// # Example + /// + /// ``` + /// use fixed_wide_vectors::Vector2; + /// + /// let vec2 = Vector2::new(1, 2) + /// .map(|i| i * 2); + /// + /// assert_eq!(vec2, Vector2::new(2, 4)); + /// ``` + #[inline] + pub fn map(self, f: F) -> $struct + where + F: Fn(T) -> U + { + $struct { + $( $field: f(self.$field) ), + + } + } + } - impl $struct { - /// Constructs a vector using the given `value` as the value for all of its fields. - /// - /// # Example - /// - /// ``` - /// use fixed_wide_vectors::Vector2; - /// - /// let vec2 = Vector2::from_value(0); - /// - /// assert_eq!(vec2, Vector2::new(0, 0)); - /// ``` - #[inline(always)] - pub const fn from_value(value: T) -> Self { - Self { - $( $field: value ), + - } - } - } + impl $struct { + /// Constructs a vector using the given `value` as the value for all of its fields. + /// + /// # Example + /// + /// ``` + /// use fixed_wide_vectors::Vector2; + /// + /// let vec2 = Vector2::from_value(0); + /// + /// assert_eq!(vec2, Vector2::new(0, 0)); + /// ``` + #[inline(always)] + pub const fn from_value(value: T) -> Self { + Self { + $( $field: value ), + + } + } + } - impl From<[T; $size]> for $struct { - fn from(from: [T; $size]) -> Self { - let mut iterator = from.into_iter(); + impl From<[T; $size]> for $struct { + fn from(from: [T; $size]) -> Self { + let mut iterator = from.into_iter(); - Self { - // SAFETY: We know the size of `from` so `iterator.next()` is always `Some(..)` - $( $field: unsafe { iterator.next().unwrap_unchecked() } ), + - } - } - } + Self { + // SAFETY: We know the size of `from` so `iterator.next()` is always `Some(..)` + $( $field: unsafe { iterator.next().unwrap_unchecked() } ), + + } + } + } - impl From<($($generic), +)> for $struct { - fn from(from: ($($generic), +)) -> Self { - let ( $($field), + ) = from; + impl From<($($generic), +)> for $struct { + fn from(from: ($($generic), +)) -> Self { + let ( $($field), + ) = from; - Self { - $( $field ), + - } - } - } + Self { + $( $field ), + + } + } + } - impl core::fmt::Debug for $struct { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let identifier = core::stringify!($struct); + impl core::fmt::Debug for $struct { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let identifier = core::stringify!($struct); - f.debug_struct(identifier) - $( .field( core::stringify!($field), &self.$field ) ) + - .finish() - } - } + f.debug_struct(identifier) + $( .field( core::stringify!($field), &self.$field ) ) + + .finish() + } + } - impl PartialEq for $struct { - fn eq(&self, other: &Self) -> bool { - $( self.$field == other.$field ) && + - } - } + impl PartialEq for $struct { + fn eq(&self, other: &Self) -> bool { + $( self.$field == other.$field ) && + + } + } - impl Eq for $struct { } + impl Eq for $struct { } - impl core::hash::Hash for $struct { - fn hash(&self, state: &mut H) { - $( self.$field.hash(state); ) + - } - } + impl core::hash::Hash for $struct { + fn hash(&self, state: &mut H) { + $( self.$field.hash(state); ) + + } + } - impl Clone for $struct { - fn clone(&self) -> Self { - Self { - $( $field: self.$field.clone() ), + - } - } - } + impl Clone for $struct { + fn clone(&self) -> Self { + Self { + $( $field: self.$field.clone() ), + + } + } + } - impl Copy for $struct { } + impl Copy for $struct { } - impl Default for $struct { - fn default() -> Self { - Self { - $( $field: T::default() ), + - } - } - } + impl Default for $struct { + fn default() -> Self { + Self { + $( $field: T::default() ), + + } + } + } - impl $struct { - pub fn min(self, rhs: Self) -> $struct { - $struct{ - $( $field: self.$field.min(rhs.$field) ), + - } - } - pub fn max(self, rhs: Self) -> $struct { - $struct{ - $( $field: self.$field.max(rhs.$field) ), + - } - } - pub fn cmp(self, rhs: Self) -> $struct { - $struct{ - $( $field: self.$field.cmp(&rhs.$field) ), + - } - } - pub fn lt(self, rhs: Self) -> $struct { - $struct{ - $( $field: self.$field.lt(&rhs.$field) ), + - } - } - pub fn gt(self, rhs: Self) -> $struct { - $struct{ - $( $field: self.$field.gt(&rhs.$field) ), + - } - } - pub fn ge(self, rhs: Self) -> $struct { - $struct{ - $( $field: self.$field.ge(&rhs.$field) ), + - } - } - pub fn le(self, rhs: Self) -> $struct { - $struct{ - $( $field: self.$field.le(&rhs.$field) ), + - } - } - } + impl $struct { + pub fn min(self, rhs: Self) -> $struct { + $struct{ + $( $field: self.$field.min(rhs.$field) ), + + } + } + pub fn max(self, rhs: Self) -> $struct { + $struct{ + $( $field: self.$field.max(rhs.$field) ), + + } + } + pub fn cmp(self, rhs: Self) -> $struct { + $struct{ + $( $field: self.$field.cmp(&rhs.$field) ), + + } + } + pub fn lt(self, rhs: Self) -> $struct { + $struct{ + $( $field: self.$field.lt(&rhs.$field) ), + + } + } + pub fn gt(self, rhs: Self) -> $struct { + $struct{ + $( $field: self.$field.gt(&rhs.$field) ), + + } + } + pub fn ge(self, rhs: Self) -> $struct { + $struct{ + $( $field: self.$field.ge(&rhs.$field) ), + + } + } + pub fn le(self, rhs: Self) -> $struct { + $struct{ + $( $field: self.$field.le(&rhs.$field) ), + + } + } + } - impl> core::ops::Neg for $struct { - type Output = Self; + impl> core::ops::Neg for $struct { + type Output = Self; - fn neg(self) -> Self::Output { - Self { - $( $field: -self.$field ), + - } - } - } + fn neg(self) -> Self::Output { + Self { + $( $field: -self.$field ), + + } + } + } - // Impl arithmetic pperators - $crate::impl_operator!( $struct { $($field), + }, AddAssign, add_assign ); - $crate::impl_operator!( $struct { $($field), + }, Add, add, Self ); - $crate::impl_operator!( $struct { $($field), + }, SubAssign, sub_assign ); - $crate::impl_operator!( $struct { $($field), + }, Sub, sub, Self ); - $crate::impl_operator!( $struct { $($field), + }, MulAssign, mul_assign ); - $crate::impl_operator!( $struct { $($field), + }, Mul, mul, Self ); - $crate::impl_operator!( $struct { $($field), + }, DivAssign, div_assign ); - $crate::impl_operator!( $struct { $($field), + }, Div, div, Self ); - $crate::impl_operator!( $struct { $($field), + }, RemAssign, rem_assign ); - $crate::impl_operator!( $struct { $($field), + }, Rem, rem, Self ); + // Impl arithmetic pperators + $crate::impl_operator!( $struct { $($field), + }, AddAssign, add_assign ); + $crate::impl_operator!( $struct { $($field), + }, Add, add, Self ); + $crate::impl_operator!( $struct { $($field), + }, SubAssign, sub_assign ); + $crate::impl_operator!( $struct { $($field), + }, Sub, sub, Self ); + $crate::impl_operator!( $struct { $($field), + }, MulAssign, mul_assign ); + $crate::impl_operator!( $struct { $($field), + }, Mul, mul, Self ); + $crate::impl_operator!( $struct { $($field), + }, DivAssign, div_assign ); + $crate::impl_operator!( $struct { $($field), + }, Div, div, Self ); + $crate::impl_operator!( $struct { $($field), + }, RemAssign, rem_assign ); + $crate::impl_operator!( $struct { $($field), + }, Rem, rem, Self ); - // Impl bitwise operators - $crate::impl_operator!( $struct { $($field), + }, BitAndAssign, bitand_assign ); - $crate::impl_operator!( $struct { $($field), + }, BitAnd, bitand, Self ); - $crate::impl_operator!( $struct { $($field), + }, BitOrAssign, bitor_assign ); - $crate::impl_operator!( $struct { $($field), + }, BitOr, bitor, Self ); - $crate::impl_operator!( $struct { $($field), + }, BitXorAssign, bitxor_assign ); - $crate::impl_operator!( $struct { $($field), + }, BitXor, bitxor, Self ); + // Impl bitwise operators + $crate::impl_operator!( $struct { $($field), + }, BitAndAssign, bitand_assign ); + $crate::impl_operator!( $struct { $($field), + }, BitAnd, bitand, Self ); + $crate::impl_operator!( $struct { $($field), + }, BitOrAssign, bitor_assign ); + $crate::impl_operator!( $struct { $($field), + }, BitOr, bitor, Self ); + $crate::impl_operator!( $struct { $($field), + }, BitXorAssign, bitxor_assign ); + $crate::impl_operator!( $struct { $($field), + }, BitXor, bitxor, Self ); - // Impl floating-point based methods - $crate::impl_wide_operations!( $struct { $($field), + }, $size ); - }; + // Impl floating-point based methods + $crate::impl_wide_operations!( $struct { $($field), + }, $size ); + }; } #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_operator { - ( $struct: ident { $($field: ident), + }, $trait: ident, $method: ident, $output: ty ) => { - impl> core::ops::$trait for $struct { - type Output = $output; + ( $struct: ident { $($field: ident), + }, $trait: ident, $method: ident, $output: ty ) => { + impl> core::ops::$trait for $struct { + type Output = $output; - fn $method(self, other: Self) -> Self::Output { - Self { - $( $field: self.$field.$method(other.$field) ), + - } - } - } + fn $method(self, other: Self) -> Self::Output { + Self { + $( $field: self.$field.$method(other.$field) ), + + } + } + } - impl + Copy> core::ops::$trait for $struct { - type Output = $output; + impl + Copy> core::ops::$trait for $struct { + type Output = $output; - fn $method(self, other: T) -> Self::Output { - Self { - $( $field: self.$field.$method(other) ), + - } - } - } - }; + fn $method(self, other: T) -> Self::Output { + Self { + $( $field: self.$field.$method(other) ), + + } + } + } + }; - ( $struct: ident { $($field: ident), + }, $trait: ident, $method: ident ) => { - impl core::ops::$trait for $struct { - fn $method(&mut self, other: Self) { - $( self.$field.$method(other.$field) ); + - } - } + ( $struct: ident { $($field: ident), + }, $trait: ident, $method: ident ) => { + impl core::ops::$trait for $struct { + fn $method(&mut self, other: Self) { + $( self.$field.$method(other.$field) ); + + } + } - impl core::ops::$trait for $struct { - fn $method(&mut self, other: T) { - $( self.$field.$method(other) ); + - } - } - }; + impl core::ops::$trait for $struct { + fn $method(&mut self, other: T) { + $( self.$field.$method(other) ); + + } + } + }; } diff --git a/fixed_wide_vectors/src/macros/wide.rs b/fixed_wide_vectors/src/macros/wide.rs index 01da30b..dc73596 100644 --- a/fixed_wide_vectors/src/macros/wide.rs +++ b/fixed_wide_vectors/src/macros/wide.rs @@ -1,34 +1,34 @@ #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_wide_operations { - ( $struct: ident { $($field: ident), + }, $size: expr ) => { - impl> fixed_wide_traits::wide::WideMul for $struct { + ( $struct: ident { $($field: ident), + }, $size: expr ) => { + impl> fixed_wide_traits::wide::WideMul for $struct { type Output=$struct; - #[inline] - fn wide_mul(self, rhs: Self) -> Self::Output { - $struct{ - $( $field: self.$field.wide_mul(rhs.$field) ), + - } - } + #[inline] + fn wide_mul(self, rhs: Self) -> Self::Output { + $struct{ + $( $field: self.$field.wide_mul(rhs.$field) ), + + } + } } impl,U,T:fixed_wide_traits::wide::WideMul> fixed_wide_traits::wide::WideDot<$struct> for $struct { type Output=V; #[inline] fn wide_dot(self, rhs: $struct) -> Self::Output { $crate::sum_repeating!( - $( + (self.$field.wide_mul(rhs.$field)) ) + - ) + $( + (self.$field.wide_mul(rhs.$field)) ) + + ) } } - impl,T:Copy+fixed_wide_traits::wide::WideMul> $struct { - #[inline] - pub fn wide_length_squared(&self) -> U { - $crate::sum_repeating!( - $( + self.$field.wide_mul(self.$field) ) + - ) - } - } - }; + impl,T:Copy+fixed_wide_traits::wide::WideMul> $struct { + #[inline] + pub fn wide_length_squared(&self) -> U { + $crate::sum_repeating!( + $( + self.$field.wide_mul(self.$field) ) + + ) + } + } + }; } @@ -37,7 +37,7 @@ macro_rules! impl_wide_operations { #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! sum_repeating { - ( + $($item: tt) * ) => { - $($item) * - }; + ( + $($item: tt) * ) => { + $($item) * + }; } diff --git a/fixed_wide_vectors/src/vector.rs b/fixed_wide_vectors/src/vector.rs index 2767ad8..6e7dae6 100644 --- a/fixed_wide_vectors/src/vector.rs +++ b/fixed_wide_vectors/src/vector.rs @@ -14,8 +14,8 @@ /// assert_eq!(vec2.y, 4); /// ``` pub struct Vector2 { - pub x: T, - pub y: T, + pub x: T, + pub y: T, } @@ -34,9 +34,9 @@ pub struct Vector2 { /// assert_eq!(vec3.z, 6); /// ``` pub struct Vector3 { - pub x: T, - pub y: T, - pub z: T, + pub x: T, + pub y: T, + pub z: T, } @@ -56,10 +56,10 @@ pub struct Vector3 { /// assert_eq!(vec4.w, 8); /// ``` pub struct Vector4 { - pub x: T, - pub y: T, - pub z: T, - pub w: T, + pub x: T, + pub y: T, + pub z: T, + pub w: T, }