diff --git a/src/integer.rs b/src/integer.rs index 4549eef..efd1a8a 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -84,7 +84,7 @@ const fn gcd(mut a:u64,mut b:u64)->u64{ }; a } -#[derive(Clone,Copy,Hash)] +#[derive(Clone,Hash)] pub struct Ratio64{ num:i64, den:u64, @@ -102,13 +102,22 @@ impl Ratio64{ } } #[inline] - pub fn mul_int(self,rhs:i64)->i64{ + pub fn mul_int(&self,rhs:i64)->i64{ rhs*self.num/self.den as i64 } #[inline] - pub fn rhs_div_int(self,rhs:i64)->i64{ + pub fn rhs_div_int(&self,rhs:i64)->i64{ rhs*self.den as i64/self.num } + #[inline] + pub fn mul_ref(&self,rhs:&Ratio64)->Ratio64{ + let (num,den)=(self.num*rhs.num,self.den*rhs.den); + let d=gcd(num.unsigned_abs(),den); + Self{ + num:num/d as i64, + den:den/d, + } + } } //from num_traits crate #[inline] diff --git a/src/settings.rs b/src/settings.rs index 2abb85b..24ac840 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -51,12 +51,12 @@ impl UserSettings{ } pub fn calculate_sensitivity(&self)->Ratio64Vec2{ match &self.sensitivity{ - &Sensitivity::Exactly{x,y}=>Ratio64Vec2::new(x,y), + Sensitivity::Exactly{x,y}=>Ratio64Vec2::new(x.clone(),y.clone()), Sensitivity::SpecifyXDeriveY{x,y}=>match y{ - &DerivedSensitivity::FromRatio(ratio)=>Ratio64Vec2::new(*x,*x*ratio), + DerivedSensitivity::FromRatio(ratio)=>Ratio64Vec2::new(x.clone(),x.mul_ref(ratio)), } Sensitivity::SpecifyYDeriveX{x,y}=>match x{ - &DerivedSensitivity::FromRatio(ratio)=>Ratio64Vec2::new(*y*ratio,*y), + DerivedSensitivity::FromRatio(ratio)=>Ratio64Vec2::new(y.mul_ref(ratio),y.clone()), } } }