From fcf320c3a8ee5da3311f429707e33ec357d09f8e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 11 Sep 2024 12:59:33 -0700 Subject: [PATCH] Divide trait wip --- linear_ops/src/macros/matrix.rs | 7 +++++++ linear_ops/src/macros/vector.rs | 7 +++++++ ratio_ops/src/ratio.rs | 12 +++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/linear_ops/src/macros/matrix.rs b/linear_ops/src/macros/matrix.rs index ead9f0a..184b2c9 100644 --- a/linear_ops/src/macros/matrix.rs +++ b/linear_ops/src/macros/matrix.rs @@ -136,6 +136,13 @@ macro_rules! impl_matrix { #[macro_export(local_inner_macros)] macro_rules! impl_matrix_deferred_division { () => { + impl,U:Copy,V> ratio_ops::ratio::Divide for Matrix{ + type Output=Matrix; + #[inline] + fn divide(self,rhs:U)->Self::Output{ + self.map(|t|t.divide(rhs)) + } + } impl core::ops::Div for Matrix{ type Output=ratio_ops::ratio::Ratio,U>; #[inline] diff --git a/linear_ops/src/macros/vector.rs b/linear_ops/src/macros/vector.rs index 2cd63fb..b375509 100644 --- a/linear_ops/src/macros/vector.rs +++ b/linear_ops/src/macros/vector.rs @@ -170,6 +170,13 @@ macro_rules! impl_vector { #[macro_export(local_inner_macros)] macro_rules! impl_vector_deferred_division { () => { + impl,U:Copy,V> ratio_ops::ratio::Divide for Vector{ + type Output=Vector; + #[inline] + fn divide(self,rhs:U)->Self::Output{ + self.map(|t|t.divide(rhs)) + } + } impl core::ops::Div for Vector{ type Output=ratio_ops::ratio::Ratio,U>; #[inline] diff --git a/ratio_ops/src/ratio.rs b/ratio_ops/src/ratio.rs index 7f806da..fdb5f39 100644 --- a/ratio_ops/src/ratio.rs +++ b/ratio_ops/src/ratio.rs @@ -10,13 +10,19 @@ impl Ratio{ } } +/// The actual divide implementation, Div is replaced with a Ratio constructor +pub trait Divide{ + type Output; + fn divide(self,rhs:Rhs)->Self::Output; +} + impl Ratio where - Num:core::ops::Div, + Num:Divide, { #[inline] - pub fn divide(num:Num,den:Den)->>::Output{ - num/den + pub fn divide(self)->>::Output{ + self.num.divide(self.den) } }