clone Ratio64 explicitly
This commit is contained in:
parent
762f10fb01
commit
1dfc566453
@ -84,7 +84,7 @@ const fn gcd(mut a:u64,mut b:u64)->u64{
|
|||||||
};
|
};
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
#[derive(Clone,Copy,Hash)]
|
#[derive(Clone,Hash)]
|
||||||
pub struct Ratio64{
|
pub struct Ratio64{
|
||||||
num:i64,
|
num:i64,
|
||||||
den:u64,
|
den:u64,
|
||||||
@ -102,13 +102,22 @@ impl Ratio64{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mul_int(self,rhs:i64)->i64{
|
pub fn mul_int(&self,rhs:i64)->i64{
|
||||||
rhs*self.num/self.den as i64
|
rhs*self.num/self.den as i64
|
||||||
}
|
}
|
||||||
#[inline]
|
#[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
|
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
|
//from num_traits crate
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -51,12 +51,12 @@ impl UserSettings{
|
|||||||
}
|
}
|
||||||
pub fn calculate_sensitivity(&self)->Ratio64Vec2{
|
pub fn calculate_sensitivity(&self)->Ratio64Vec2{
|
||||||
match &self.sensitivity{
|
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{
|
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{
|
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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user