From a8f82a14a9766cc4ce623dd8e5c524cb6bc6d5f3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 11 Oct 2023 21:40:07 -0700 Subject: [PATCH] mul type is defined by lhs --- src/integer.rs | 42 ++++++++++++++++++++++++++++++------------ src/physics.rs | 4 ++-- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/integer.rs b/src/integer.rs index b7d5852..4cef070 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -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 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 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 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); diff --git a/src/physics.rs b/src/physics.rs index 759c17e..ed524dc 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -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),