#[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_vector { () => { impl Vector{ #[inline(always)] pub const fn new(array:[T;N])->Self{ Self{array} } #[inline(always)] pub fn to_array(self)->[T;N]{ self.array } #[inline] pub fn map(self,f:F)->Vector where F:Fn(T)->U { Vector{ array:self.array.map(f), } } #[inline] pub fn map_zip(self,other:Vector,f:F)->Vector where 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())), } } } impl Vector{ #[inline(always)] pub const fn from_value(value:T)->Self{ Self{ array:[value;N] } } } impl Default for Vector{ fn default()->Self{ Self{ array:core::array::from_fn(|_|Default::default()) } } } impl Vector{ #[inline] pub fn min(self,rhs:Self)->Self{ self.map_zip(rhs,|(a,b)|a.min(b)) } #[inline] pub fn max(self,rhs:Self)->Self{ self.map_zip(rhs,|(a,b)|a.max(b)) } #[inline] pub fn cmp(self,rhs:Self)->Vector{ self.map_zip(rhs,|(a,b)|a.cmp(&b)) } #[inline] pub fn lt(self,rhs:Self)->Vector{ self.map_zip(rhs,|(a,b)|a.lt(&b)) } #[inline] pub fn gt(self,rhs:Self)->Vector{ self.map_zip(rhs,|(a,b)|a.gt(&b)) } #[inline] pub fn ge(self,rhs:Self)->Vector{ self.map_zip(rhs,|(a,b)|a.ge(&b)) } #[inline] pub fn le(self,rhs:Self)->Vector{ self.map_zip(rhs,|(a,b)|a.le(&b)) } } impl Vector{ const ALL:[bool;N]=[true;N]; const NONE:[bool;N]=[false;N]; #[inline] pub fn all(&self)->bool{ core::matches!(self.array,ALL) } #[inline] pub fn any(&self)->bool{ !core::matches!(self.array,NONE) } } impl> core::ops::Neg for Vector{ type Output=Self; fn neg(self)->Self::Output{ Self{ array:self.array.map(|t|-t) } } } } } #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_vector_named_fields { ( $struct:ident, $size: expr ) => { impl core::ops::Deref for Vector<$size,T>{ type Target=$struct; fn deref(&self)->&Self::Target{ unsafe{core::mem::transmute(&self.array)} } } impl core::ops::DerefMut for Vector<$size,T>{ fn deref_mut(&mut self)->&mut Self::Target{ unsafe{core::mem::transmute(&mut self.array)} } } } }