infinite loop detect

This commit is contained in:
Quaternions 2025-02-05 14:47:57 -08:00
parent d384744d2d
commit eec6a1fa72

@ -35,6 +35,8 @@ pub enum PlanesToFacesError{
InitIntersection,
FindNewIntersection,
EmptyFaces,
InfiniteLoop1,
InfiniteLoop2,
}
impl std::fmt::Display for PlanesToFacesError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
@ -69,10 +71,17 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
edge_dir.dot(p.normal)
}).ok_or(PlanesToFacesError::InitFace2)?;
let mut detect_loop=200u8;
let mut intersection=solve3(face0,face1,face2).ok_or(PlanesToFacesError::InitIntersection)?;
// repeatedly update face0, face1 until all faces form part of the convex solid
'find: loop{
if let Some(a)=detect_loop.checked_sub(1){
detect_loop=a;
}else{
return Err(PlanesToFacesError::InfiniteLoop1);
}
// test if any *other* faces occlude the intersection
for new_face in &face_list{
// new face occludes intersection point
@ -126,6 +135,8 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
// Note that we chose face2 such that the 3 faces create a particular winding order.
// If we choose a consistent face to follow (face1, face2) it will always wind with a consistent chirality
let mut detect_loop=200u8;
// keep looping until we meet this face again
let face1=face1;
let mut face=Vec::new();
@ -165,6 +176,12 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
face2=new_face;
intersection=new_intersection;
if let Some(a)=detect_loop.checked_sub(1){
detect_loop=a;
}else{
return Err(PlanesToFacesError::InfiniteLoop2);
}
}
faces.push(face);