mul type is defined by lhs

This commit is contained in:
Quaternions 2023-10-11 21:40:07 -07:00
parent 101c92cba4
commit a8f82a14a9
2 changed files with 32 additions and 14 deletions

View File

@ -58,12 +58,6 @@ pub struct Ratio64{
}
impl Ratio64{
pub const ONE:Self=Ratio64{num:1,den:unsafe{std::num::NonZeroU64::new_unchecked(1)}};
pub fn mul_ratio(self,rhs:i64)->Self{
Self{
num:self.num*rhs,
den:self.den
}
}
pub fn mul_int(self,rhs:i64)->i64{
rhs*self.num/self.den.get() as i64
}
@ -71,6 +65,26 @@ impl Ratio64{
rhs*self.den.get() as i64/self.num
}
}
impl std::ops::Mul<i64> for Ratio64{
type Output=Ratio64;
#[inline]
fn mul(self,rhs:i64)->Self::Output {
Self{
num:self.num*rhs,
den:self.den,
}
}
}
impl std::ops::Div<u64> for Ratio64{
type Output=Ratio64;
#[inline]
fn div(self,rhs:u64)->Self::Output {
Self{
num:self.num,
den:std::num::NonZeroU64::new(self.den.get()*rhs).unwrap(),
}
}
}
#[derive(Clone,Hash)]
pub struct Ratio64Vec2{
pub x:Ratio64,
@ -78,12 +92,6 @@ pub struct Ratio64Vec2{
}
impl Ratio64Vec2{
pub const ONE:Self=Self{x:Ratio64::ONE,y:Ratio64::ONE};
pub fn mul_ratio(self,rhs:i64)->Self{
Self{
x:self.x.mul_ratio(rhs),
y:self.y.mul_ratio(rhs),
}
}
pub fn mul_int(self,rhs:glam::I64Vec2)->glam::I64Vec2{
glam::i64vec2(
self.x.mul_int(rhs.x),
@ -91,6 +99,16 @@ impl Ratio64Vec2{
)
}
}
impl std::ops::Mul<i64> for Ratio64Vec2{
type Output=Ratio64Vec2;
#[inline]
fn mul(self,rhs:i64)->Self::Output {
Self{
x:self.x*rhs,
y:self.y*rhs,
}
}
}
///[-1.0,1.0] = [-2^30,2^30]
pub struct Unit32(i32);

View File

@ -159,7 +159,7 @@ impl PhysicsCamera {
pub fn from_offset(offset:Planar64Vec3) -> Self {
Self{
offset,
sensitivity:Ratio64Vec2::ONE.mul_ratio(200_000),
sensitivity:Ratio64Vec2::ONE*200_000,
mouse:MouseState{pos:glam::IVec2::ZERO,time:-Time::ONE_NANOSECOND},//escape initialization hell divide by zero
clamped_mouse_pos:glam::IVec2::ZERO,
angle_pitch_lower_limit:-Angle32::FRAC_PI_2,
@ -218,7 +218,7 @@ impl std::default::Default for StyleModifiers{
Self{
controls_mask: !0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held: 0,
strafe_tick_rate:Ratio64::ONE.rhs_div_ratio(100),
strafe_tick_rate:Ratio64::ONE/100,
gravity: Planar64Vec3::int(0,100,0),
friction: Planar64::int(12)/10,
walk_accel: Planar64::int(90),