From e6c955a958c8cd3898228523918a6b5538543cd6 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 17 Nov 2023 13:43:44 -0800 Subject: [PATCH] combine crawl into one loop --- src/face_crawler.rs | 14 -------------- src/model_physics.rs | 19 +++++++------------ 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/face_crawler.rs b/src/face_crawler.rs index 391b566..012a198 100644 --- a/src/face_crawler.rs +++ b/src/face_crawler.rs @@ -111,17 +111,3 @@ pub fn crawl_fev(mut fev:FEV,mesh:&imp } } } -pub enum CrawlResult{ - Closest(FEV), - Hit(F,Time), -} -pub fn crawl_fev_from_negative_infinity(mut fev:FEV,mesh:&impl MeshQuery,relative_body:&Body,time_limit:Time)->CrawlResult{ - let mut time=Time::MIN; - loop{ - match next_transition(&fev,time,mesh,relative_body,time_limit){ - Transition::Miss=>return CrawlResult::Closest(fev), - Transition::Next(next_fev,next_time)=>(fev,time)=(next_fev,next_time), - Transition::Hit(face,time)=>return CrawlResult::Hit(face,time),//algorithm breaks down inside without full fat voronoi - } - } -} diff --git a/src/model_physics.rs b/src/model_physics.rs index b0021eb..250398a 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -356,23 +356,18 @@ impl MinkowskiMesh<'_>{ pub fn predict_collision_in(&self,relative_body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(MinkowskiFace,crate::integer::Time)>{ (-relative_body.clone()).infinity_dir().map_or(None,|dir|{ let start_vert=FEV::::Vert(self.farthest_vert(dir)); - match crate::face_crawler::crawl_fev_from_negative_infinity(start_vert,self,relative_body,relative_body.time){ - crate::face_crawler::CrawlResult::Closest(fev)=>{ - crate::face_crawler::crawl_fev(fev,self,relative_body,relative_body.time,time_limit) - }, - crate::face_crawler::CrawlResult::Hit(_,_)=>None,//already in or passed - } + let start_time=crate::integer::Time::MIN;//relative_body.time + crate::face_crawler::crawl_fev(start_vert,self,relative_body,start_time,time_limit) }) } pub fn predict_collision_out(&self,relative_body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(MinkowskiFace,crate::integer::Time)>{ + //This doesn't work if the out-path goes back in. it must be the final exit. relative_body.infinity_dir().map_or(None,|dir|{ let start_vert=FEV::::Vert(self.farthest_vert(dir)); - match crate::face_crawler::crawl_fev_from_negative_infinity(start_vert,self,&-relative_body.clone(),-time_limit){ - crate::face_crawler::CrawlResult::Closest(fev)=>{ - crate::face_crawler::crawl_fev(fev,self,&-relative_body.clone(),-time_limit,-relative_body.time).map(|t|(t.0,-t.1)) - }, - crate::face_crawler::CrawlResult::Hit(face,time)=>Some((face,-time)), - } + let start_time=crate::integer::Time::MIN;//-time_limit + crate::face_crawler::crawl_fev(start_vert,self,&-relative_body.clone(),start_time,-relative_body.time) + .filter(|t|-t.1Option<(MinkowskiEdge,crate::integer::Time)>{