Divide trait wip
This commit is contained in:
parent
44ac6fe4be
commit
fcf320c3a8
@ -136,6 +136,13 @@ macro_rules! impl_matrix {
|
||||
#[macro_export(local_inner_macros)]
|
||||
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>{
|
||||
type Output=ratio_ops::ratio::Ratio<Matrix<X,Y,T>,U>;
|
||||
#[inline]
|
||||
|
@ -170,6 +170,13 @@ macro_rules! impl_vector {
|
||||
#[macro_export(local_inner_macros)]
|
||||
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>{
|
||||
type Output=ratio_ops::ratio::Ratio<Vector<N,T>,U>;
|
||||
#[inline]
|
||||
|
@ -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>
|
||||
where
|
||||
Num:core::ops::Div<Den>,
|
||||
Num:Divide<Den>,
|
||||
{
|
||||
#[inline]
|
||||
pub fn divide(num:Num,den:Den)-><Num as core::ops::Div<Den>>::Output{
|
||||
num/den
|
||||
pub fn divide(self)-><Num as Divide<Den>>::Output{
|
||||
self.num.divide(self.den)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user