From 67f8569178a56df36c0f6178e1cec9773d27ba69 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 9 Jan 2025 05:56:11 -0800 Subject: [PATCH] push_solve infallible type signature --- strafe-client/src/physics.rs | 10 ++-------- strafe-client/src/push_solve.rs | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/strafe-client/src/physics.rs b/strafe-client/src/physics.rs index c6c4491..8f75b92 100644 --- a/strafe-client/src/physics.rs +++ b/strafe-client/src/physics.rs @@ -773,10 +773,7 @@ impl TouchingState{ normal:n, } }).collect(); - match crate::push_solve::push_solve(&contacts,*velocity){ - Some(new_velocity)=>*velocity=new_velocity, - None=>println!("Algorithm silently failing :)"), - } + *velocity=crate::push_solve::push_solve(&contacts,*velocity); } fn constrain_acceleration(&self,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,acceleration:&mut Planar64Vec3){ let contacts=self.contacts.iter().map(|contact|{ @@ -787,10 +784,7 @@ impl TouchingState{ normal:n, } }).collect(); - match crate::push_solve::push_solve(&contacts,*acceleration){ - Some(new_acceleration)=>*acceleration=new_acceleration, - None=>println!("Algorithm silently failing :)"), - } + *acceleration=crate::push_solve::push_solve(&contacts,*acceleration); } fn predict_collision_end(&self,collector:&mut instruction::InstructionCollector,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,body:&Body,time:Time){ let relative_body=crate::body::VirtualBody::relative(&Body::ZERO,body).body(time); diff --git a/strafe-client/src/push_solve.rs b/strafe-client/src/push_solve.rs index 62f1ff9..937b299 100644 --- a/strafe-client/src/push_solve.rs +++ b/strafe-client/src/push_solve.rs @@ -164,8 +164,8 @@ fn is_space_enclosed_4( ||is_space_enclosed_3(b,c,d) } -const fn get_push_ray_0(point:Planar64Vec3)->Option{ - Some(Ray{origin:point,direction:vec3::ZERO}) +const fn get_push_ray_0(point:Planar64Vec3)->Ray{ + Ray{origin:point,direction:vec3::ZERO} } fn get_push_ray_1(point:Planar64Vec3,c0:&Contact)->Option{ let direction=solve1(c0)?.divide().fix_1(); @@ -204,11 +204,8 @@ fn get_push_ray_3(point:Planar64Vec3,c0:&Contact,c1:&Contact,c2:&Contact)->Optio Some(Ray{origin,direction}) } -const fn get_best_push_ray_and_conts_0<'a>(point:Planar64Vec3)->Option<(Ray,Conts<'a>)>{ - match get_push_ray_0(point){ - Some(ray)=>Some((ray,Conts::new_const())), - None=>None, - } +const fn get_best_push_ray_and_conts_0<'a>(point:Planar64Vec3)->(Ray,Conts<'a>){ + (get_push_ray_0(point),Conts::new_const()) } fn get_best_push_ray_and_conts_1(point:Planar64Vec3,c0:&Contact)->Option<(Ray,Conts)>{ get_push_ray_1(point,c0) @@ -287,7 +284,7 @@ fn get_best_push_ray_and_conts<'a>( &[c0,c1,c2]=>get_best_push_ray_and_conts_3(point,c0,c1,c2), &[c0,c1]=>get_best_push_ray_and_conts_2(point,c0,c1), &[c0]=>get_best_push_ray_and_conts_1(point,c0), - &[]=>get_best_push_ray_and_conts_0(point), + &[]=>Some(get_best_push_ray_and_conts_0(point)), _=>unreachable!(), } } @@ -302,17 +299,17 @@ fn get_first_touch<'a>(contacts:&'a Vec,ray:&Ray,conts:&Conts)->Option< .min_by_key(|&(t,_)|t) } -pub fn push_solve(contacts:&Vec,point:Planar64Vec3)->Option{ +pub fn push_solve(contacts:&Vec,point:Planar64Vec3)->Planar64Vec3{ const ZERO:Ratio,Fixed<1,32>>=Ratio::new(Fixed::ZERO,Fixed::EPSILON); - let (mut ray,mut conts)=get_best_push_ray_and_conts_0(point)?; + let (mut ray,mut conts)=get_best_push_ray_and_conts_0(point); loop{ let (next_t,next_cont)=match get_first_touch(contacts,&ray,&conts){ Some((t,conts))=>(t,conts), - None=>return Some(ray.origin), + None=>return ray.origin, }; if ZERO.le_ratio(next_t){ - return Some(ray.origin); + return ray.origin; } //push_front @@ -328,7 +325,7 @@ pub fn push_solve(contacts:&Vec,point:Planar64Vec3)->Option(ray,conts)=(new_ray,new_conts), - None=>return Some(meet_point), + None=>return meet_point, } } } @@ -346,7 +343,7 @@ mod tests{ } ]; assert_eq!( - Some(vec3::ZERO), + vec3::ZERO, push_solve(&contacts,vec3::NEG_Y) ); }