keep generic operators and only implement i64 convenience operator

This commit is contained in:
Quaternions 2024-09-05 16:17:47 -07:00
parent 488a6b6496
commit e375173625

View File

@ -128,15 +128,15 @@ macro_rules! impl_vector {
#[macro_export(local_inner_macros)] #[macro_export(local_inner_macros)]
macro_rules! impl_vector_operator { macro_rules! impl_vector_operator {
($trait: ident, $method: ident ) => { ($trait: ident, $method: ident ) => {
impl<const N:usize,T:core::ops::$trait<Output=T>> core::ops::$trait for Vector<N,T>{ impl<const N:usize,T:core::ops::$trait<U,Output=V>,U,V> core::ops::$trait<Vector<N,U>> for Vector<N,T>{
type Output=Self; type Output=Vector<N,V>;
fn $method(self,rhs:Self)->Self::Output{ fn $method(self,rhs:Vector<N,U>)->Self::Output{
self.map_zip(rhs,|(a,b)|a.$method(b)) self.map_zip(rhs,|(a,b)|a.$method(b))
} }
} }
impl<const N:usize,T:core::ops::$trait<Output=T>+Copy> core::ops::$trait<T> for Vector<N,T>{ impl<const N:usize,T:core::ops::$trait<i64,Output=T>> core::ops::$trait<i64> for Vector<N,T>{
type Output=Self; type Output=Self;
fn $method(self,rhs:T)->Self::Output{ fn $method(self,rhs:i64)->Self::Output{
self.map(|t|t.$method(rhs)) self.map(|t|t.$method(rhs))
} }
} }
@ -146,14 +146,14 @@ macro_rules! impl_vector_operator {
#[macro_export(local_inner_macros)] #[macro_export(local_inner_macros)]
macro_rules! impl_vector_assign_operator { macro_rules! impl_vector_assign_operator {
($trait: ident, $method: ident ) => { ($trait: ident, $method: ident ) => {
impl<const N:usize,T:core::ops::$trait> core::ops::$trait for Vector<N,T>{ impl<const N:usize,T:core::ops::$trait<U>,U> core::ops::$trait<Vector<N,U>> for Vector<N,T>{
fn $method(&mut self,rhs:Self){ fn $method(&mut self,rhs:Vector<N,U>){
self.array.iter_mut().zip(rhs.array) self.array.iter_mut().zip(rhs.array)
.for_each(|(a,b)|a.$method(b)) .for_each(|(a,b)|a.$method(b))
} }
} }
impl<const N:usize,T:core::ops::$trait+Copy> core::ops::$trait<T> for Vector<N,T>{ impl<const N:usize,T:core::ops::$trait<i64>> core::ops::$trait<i64> for Vector<N,T>{
fn $method(&mut self,rhs:T){ fn $method(&mut self,rhs:i64){
self.array.iter_mut() self.array.iter_mut()
.for_each(|t|t.$method(rhs)) .for_each(|t|t.$method(rhs))
} }