bsp_loader: implement precise width conversion

This commit is contained in:
2025-03-13 16:12:02 -07:00
parent 0fc1ec3086
commit 77ee36fa72

@ -34,6 +34,7 @@ pub enum PlanesToFacesError{
InitFace2, InitFace2,
InitIntersection, InitIntersection,
FindNewIntersection, FindNewIntersection,
// Narrow(strafesnet_common::integer::NarrowError),
EmptyFaces, EmptyFaces,
InfiniteLoop1, InfiniteLoop1,
InfiniteLoop2, InfiniteLoop2,
@ -81,12 +82,12 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
// test if any *other* faces occlude the intersection // test if any *other* faces occlude the intersection
for new_face in &face_list{ for new_face in &face_list{
// new face occludes intersection point // new face occludes intersection point
if (new_face.dot.fix_2()/Planar64::ONE).lt_ratio(new_face.normal.dot(intersection.num)/intersection.den){ if (new_face.dot.widen_2()/Planar64::ONE).lt_ratio(new_face.normal.dot(intersection.num)/intersection.den){
// replace one of the faces with the new face // replace one of the faces with the new face
// dont' try to replace face0 because we are exploring that face in particular // dont' try to replace face0 because we are exploring that face in particular
if let Some(new_intersection)=solve3(face0,new_face,face2){ if let Some(new_intersection)=solve3(face0,new_face,face2){
// face1 does not occlude (or intersect) the new intersection // face1 does not occlude (or intersect) the new intersection
if (face1.dot.fix_2()/Planar64::ONE).gt_ratio(face1.normal.dot(new_intersection.num)/new_intersection.den){ if (face1.dot.widen_2()/Planar64::ONE).gt_ratio(face1.normal.dot(new_intersection.num)/new_intersection.den){
face1=new_face; face1=new_face;
intersection=new_intersection; intersection=new_intersection;
continue 'find; continue 'find;
@ -94,7 +95,7 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
} }
if let Some(new_intersection)=solve3(face0,face1,new_face){ if let Some(new_intersection)=solve3(face0,face1,new_face){
// face2 does not occlude (or intersect) the new intersection // face2 does not occlude (or intersect) the new intersection
if (face2.dot.fix_2()/Planar64::ONE).gt_ratio(face2.normal.dot(new_intersection.num)/new_intersection.den){ if (face2.dot.widen_2()/Planar64::ONE).gt_ratio(face2.normal.dot(new_intersection.num)/new_intersection.den){
face2=new_face; face2=new_face;
intersection=new_intersection; intersection=new_intersection;
continue 'find; continue 'find;
@ -119,7 +120,7 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
continue; continue;
} }
// new_face occludes intersection meaning intersection is not on convex solid and face0 is degenrate // new_face occludes intersection meaning intersection is not on convex solid and face0 is degenrate
if (new_face.dot.fix_2()/Planar64::ONE).lt_ratio(new_face.normal.dot(intersection.num)/intersection.den){ if (new_face.dot.widen_2()/Planar64::ONE).lt_ratio(new_face.normal.dot(intersection.num)/intersection.den){
// abort! reject face0 entirely // abort! reject face0 entirely
continue 'face; continue 'face;
} }
@ -137,7 +138,7 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
loop{ loop{
// push point onto vertices // push point onto vertices
// problem: this may push a vertex that does not fit in the fixed point range and is thus meaningless // problem: this may push a vertex that does not fit in the fixed point range and is thus meaningless
face.push(intersection.divide().fix_1()); face.push(intersection.divide().narrow_1().unwrap());
// we looped back around to face1, we're done! // we looped back around to face1, we're done!
if core::ptr::eq(face1,face2){ if core::ptr::eq(face1,face2){