From 36c769346c47923534afc50d82c7e5ee417cf489 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 6 Sep 2024 11:44:43 -0700 Subject: [PATCH] use inline const constructor because it's a little bit prettier --- fixed_wide_vectors/src/macros/fixed_wide.rs | 14 +++++------ fixed_wide_vectors/src/macros/matrix.rs | 28 ++++++++++----------- fixed_wide_vectors/src/macros/vector.rs | 28 ++++++++++----------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/fixed_wide_vectors/src/macros/fixed_wide.rs b/fixed_wide_vectors/src/macros/fixed_wide.rs index cc213c5..0a2e0eb 100644 --- a/fixed_wide_vectors/src/macros/fixed_wide.rs +++ b/fixed_wide_vectors/src/macros/fixed_wide.rs @@ -88,11 +88,11 @@ macro_rules! impl_vector_3_wide_cross { paste::item!{ #[inline] pub fn [](self,rhs:Vector<3,fixed_wide::fixed::Fixed<{$rhs},{$rhs*32}>>)->Vector<3,fixed_wide::fixed::Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>>{ - Vector{array:[ + Vector::new([ self.y.[](rhs.z)-self.z.[](rhs.y), self.z.[](rhs.x)-self.x.[](rhs.z), self.x.[](rhs.y)-self.y.[](rhs.x), - ]} + ]) } } } @@ -130,8 +130,8 @@ macro_rules! impl_matrix_wide_dot { #[inline] pub fn [](self,rhs:Matrix>)->Matrix>{ let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter().cycle()); - Matrix{ - array:self.array.map(|axis| + Matrix::new( + self.array.map(|axis| core::array::from_fn(|_| // axis dot product with transposed rhs array axis.iter().zip( @@ -141,7 +141,7 @@ macro_rules! impl_matrix_wide_dot { ).sum() ) ) - } + ) } } } @@ -192,11 +192,11 @@ macro_rules! impl_matrix_wide_3x3_adjugate_not_const_generic { impl Matrix<3,3,fixed_wide::fixed::Fixed<$n,{$n*32}>>{ paste::item!{ pub fn [](self)->Matrix<3,3,fixed_wide::fixed::Fixed<{$n*2},{$n*2*32}>>{ - Matrix{array:[ + Matrix::new([ [self.y_axis.y.[](self.z_axis.z)-self.y_axis.z.[](self.z_axis.y),self.x_axis.z.[](self.z_axis.y)-self.x_axis.y.[](self.z_axis.z),self.x_axis.y.[](self.y_axis.z)-self.x_axis.z.[](self.y_axis.y)], [self.y_axis.z.[](self.z_axis.x)-self.y_axis.x.[](self.z_axis.z),self.x_axis.x.[](self.z_axis.z)-self.x_axis.z.[](self.z_axis.x),self.x_axis.z.[](self.y_axis.x)-self.x_axis.x.[](self.y_axis.z)], [self.y_axis.x.[](self.z_axis.y)-self.y_axis.y.[](self.z_axis.x),self.x_axis.y.[](self.z_axis.x)-self.x_axis.x.[](self.z_axis.y),self.x_axis.x.[](self.y_axis.y)-self.x_axis.y.[](self.y_axis.x)], - ]} + ]) } } } diff --git a/fixed_wide_vectors/src/macros/matrix.rs b/fixed_wide_vectors/src/macros/matrix.rs index 269cdcb..e5ec16e 100644 --- a/fixed_wide_vectors/src/macros/matrix.rs +++ b/fixed_wide_vectors/src/macros/matrix.rs @@ -16,21 +16,21 @@ macro_rules! impl_matrix { where F:Fn(T)->U { - Matrix{ - array:self.array.map(|inner|inner.map(&f)), - } + Matrix::new( + self.array.map(|inner|inner.map(&f)), + ) } #[inline] pub fn transpose(self)->Matrix{ //how did I think of this let mut array_of_iterators=self.array.map(|axis|axis.into_iter()); - Matrix{ - array:core::array::from_fn(|_| + Matrix::new( + core::array::from_fn(|_| array_of_iterators.each_mut().map(|iter| iter.next().unwrap() ) ) - } + ) } #[inline] // MatY.MatX = MatY @@ -41,8 +41,8 @@ macro_rules! impl_matrix { U:Copy, { let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter().cycle()); - Matrix{ - array:self.array.map(|axis| + Matrix::new( + self.array.map(|axis| core::array::from_fn(|_| // axis dot product with transposed rhs array axis.iter().zip( @@ -52,7 +52,7 @@ macro_rules! impl_matrix { ).sum() ) ) - } + ) } } impl Matrix @@ -60,17 +60,15 @@ macro_rules! impl_matrix { T:Copy { pub const fn from_value(value:T)->Self{ - Self{ - array:[[value;X];Y] - } + Self::new([[value;X];Y]) } } impl Default for Matrix{ fn default()->Self{ - Self{ - array:core::array::from_fn(|_|core::array::from_fn(|_|Default::default())) - } + Self::new( + core::array::from_fn(|_|core::array::from_fn(|_|Default::default())) + ) } } #[cfg(feature="fixed_wide")] diff --git a/fixed_wide_vectors/src/macros/vector.rs b/fixed_wide_vectors/src/macros/vector.rs index 8d26a27..9d976e9 100644 --- a/fixed_wide_vectors/src/macros/vector.rs +++ b/fixed_wide_vectors/src/macros/vector.rs @@ -16,9 +16,9 @@ macro_rules! impl_vector { where F:Fn(T)->U { - Vector{ - array:self.array.map(f), - } + Vector::new( + self.array.map(f) + ) } #[inline] pub fn map_zip(self,other:Vector,f:F)->Vector @@ -26,25 +26,23 @@ macro_rules! impl_vector { F:Fn((T,U))->V, { let mut iter=self.array.into_iter().zip(other.array); - Vector{ - array:core::array::from_fn(|_|f(iter.next().unwrap())), - } + Vector::new( + core::array::from_fn(|_|f(iter.next().unwrap())), + ) } } impl Vector{ #[inline(always)] pub const fn from_value(value:T)->Self{ - Self{ - array:[value;N] - } + Self::new([value;N]) } } impl Default for Vector{ fn default()->Self{ - Self{ - array:core::array::from_fn(|_|Default::default()) - } + Self::new( + core::array::from_fn(|_|Default::default()) + ) } } @@ -93,9 +91,9 @@ macro_rules! impl_vector { impl,V> core::ops::Neg for Vector{ type Output=Vector; fn neg(self)->Self::Output{ - Vector{ - array:self.array.map(|t|-t) - } + Vector::new( + self.array.map(|t|-t) + ) } }