push_solve infallible type signature
This commit is contained in:
parent
121c9c5258
commit
67f8569178
@ -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<PhysicsInternalInstruction,TimeInner>,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,body:&Body,time:Time){
|
||||
let relative_body=crate::body::VirtualBody::relative(&Body::ZERO,body).body(time);
|
||||
|
@ -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<Ray>{
|
||||
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<Ray>{
|
||||
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<Contact>,ray:&Ray,conts:&Conts)->Option<
|
||||
.min_by_key(|&(t,_)|t)
|
||||
}
|
||||
|
||||
pub fn push_solve(contacts:&Vec<Contact>,point:Planar64Vec3)->Option<Planar64Vec3>{
|
||||
pub fn push_solve(contacts:&Vec<Contact>,point:Planar64Vec3)->Planar64Vec3{
|
||||
const ZERO:Ratio<Fixed<1,32>,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<Contact>,point:Planar64Vec3)->Option<Planar64Vec
|
||||
let meet_point=ray.extrapolate(next_t);
|
||||
match get_best_push_ray_and_conts(meet_point,conts){
|
||||
Some((new_ray,new_conts))=>(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)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user