Compare commits

...

1 Commits

Author SHA1 Message Date
fcf320c3a8 Divide trait wip 2024-09-11 12:59:33 -07:00
3 changed files with 23 additions and 3 deletions

View File

@ -136,6 +136,13 @@ macro_rules! impl_matrix {
#[macro_export(local_inner_macros)] #[macro_export(local_inner_macros)]
macro_rules! impl_matrix_deferred_division { macro_rules! impl_matrix_deferred_division {
() => { () => {
impl<const X:usize,const Y:usize,T:ratio_ops::ratio::Divide<U,Output=V>,U:Copy,V> ratio_ops::ratio::Divide<U> for Matrix<X,Y,T>{
type Output=Matrix<X,Y,V>;
#[inline]
fn divide(self,rhs:U)->Self::Output{
self.map(|t|t.divide(rhs))
}
}
impl<const X:usize,const Y:usize,T,U> core::ops::Div<U> for Matrix<X,Y,T>{ impl<const X:usize,const Y:usize,T,U> core::ops::Div<U> for Matrix<X,Y,T>{
type Output=ratio_ops::ratio::Ratio<Matrix<X,Y,T>,U>; type Output=ratio_ops::ratio::Ratio<Matrix<X,Y,T>,U>;
#[inline] #[inline]

View File

@ -170,6 +170,13 @@ macro_rules! impl_vector {
#[macro_export(local_inner_macros)] #[macro_export(local_inner_macros)]
macro_rules! impl_vector_deferred_division { macro_rules! impl_vector_deferred_division {
() => { () => {
impl<const N:usize,T:ratio_ops::ratio::Divide<U,Output=V>,U:Copy,V> ratio_ops::ratio::Divide<U> for Vector<N,T>{
type Output=Vector<N,V>;
#[inline]
fn divide(self,rhs:U)->Self::Output{
self.map(|t|t.divide(rhs))
}
}
impl<const N:usize,T,U> core::ops::Div<U> for Vector<N,T>{ impl<const N:usize,T,U> core::ops::Div<U> for Vector<N,T>{
type Output=ratio_ops::ratio::Ratio<Vector<N,T>,U>; type Output=ratio_ops::ratio::Ratio<Vector<N,T>,U>;
#[inline] #[inline]

View File

@ -10,13 +10,19 @@ impl<Num,Den> Ratio<Num,Den>{
} }
} }
/// The actual divide implementation, Div is replaced with a Ratio constructor
pub trait Divide<Rhs=Self>{
type Output;
fn divide(self,rhs:Rhs)->Self::Output;
}
impl<Num,Den> Ratio<Num,Den> impl<Num,Den> Ratio<Num,Den>
where where
Num:core::ops::Div<Den>, Num:Divide<Den>,
{ {
#[inline] #[inline]
pub fn divide(num:Num,den:Den)-><Num as core::ops::Div<Den>>::Output{ pub fn divide(self)-><Num as Divide<Den>>::Output{
num/den self.num.divide(self.den)
} }
} }