clone Ratio64 explicitly

This commit is contained in:
Quaternions 2023-10-14 11:39:21 -07:00
parent 762f10fb01
commit 1dfc566453
2 changed files with 15 additions and 6 deletions

View File

@ -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]

View File

@ -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()),
}
}
}