move function into struct impls

This commit is contained in:
Quaternions 2024-08-22 11:51:44 -07:00
parent f3314308ef
commit a916068d16

View File

@ -34,6 +34,10 @@ impl Contact{
fn relative_dot(&self,direction:Planar64Vec3)->Planar64{
(direction-self.velocity).dot(self.normal)
}
/// Calculate the time of intersection. (previously get_touch_time)
fn solve(&self,ray:&Ray)->Planar64{
(self.position-ray.origin).dot(self.normal)/(ray.direction-self.velocity).dot(self.normal)
}
}
//A reference to a Contact and its respective index, paired together
@ -288,9 +292,6 @@ fn get_best_push_ray_and_indices(
}
}
fn get_touch_time(ray:&Ray,c:&Contact)->Planar64{
(ray.origin-c.position).dot(c.normal)/(c.velocity-ray.direction).dot(c.normal)
}
fn get_first_touch(conts:&Vec<Contact>,ray:&Ray,indices:&Indices)->Option<(Planar64,usize)>{
conts.iter()
.enumerate()
@ -298,7 +299,7 @@ fn get_first_touch(conts:&Vec<Contact>,ray:&Ray,indices:&Indices)->Option<(Plana
!indices.contains(&i)
&&contact.relative_dot(ray.direction)< -EPSILON
)
.map(|(i,contact)|(get_touch_time(ray,contact),i))
.map(|(i,contact)|(contact.solve(ray),i))
.min_by_key(|&(t,_)|t)
}