deduplicate ahead of time

This commit is contained in:
Quaternions 2025-02-05 10:48:37 -08:00
parent 067b5eee3c
commit af3f9cf1fe

@ -43,16 +43,10 @@ impl std::fmt::Display for BrushToMeshError{
}
impl core::error::Error for BrushToMeshError{}
fn planes_to_faces(face_list:Vec<Face>)->Option<Faces>{
fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Option<Faces>{
let mut faces=Vec::new();
// for each face, determine one edge at a time until you complete the face
let mut dedup=std::collections::HashSet::new();
'face: for face0 in &face_list{
// don't generate duplicate faces
if !dedup.insert(face0){
continue 'face;
}
// 1. find first edge
// 2. follow edges around face
@ -156,7 +150,7 @@ fn planes_to_faces(face_list:Vec<Face>)->Option<Faces>{
// find the next face moving clockwise around face0
let (new_face,new_intersection,_)=face_list.iter().filter_map(|new_face|{
// ignore faces we've seen before
// ignore faces that are part of the current edge
if core::ptr::eq(face0,new_face)
|core::ptr::eq(face2,new_face){
return None;
@ -168,6 +162,7 @@ fn planes_to_faces(face_list:Vec<Face>)->Option<Faces>{
if d_new_intersection.le_ratio(d_intersection){
return None;
}
Some((new_face,new_intersection,d_new_intersection))
}).min_by_key(|&(_,_,d)|d)?;
@ -202,7 +197,7 @@ pub fn brush_to_mesh(bsp:&vbsp::Bsp,brush:&vbsp::Brush)->Result<model::Mesh,Brus
normal:valve_transform(plane.normal.into()),
dot:valve_transform_dist(plane.dist.into()),
})
}).collect::<Option<Vec<_>>>().ok_or(BrushToMeshError::MissingPlane)?;
}).collect::<Option<std::collections::HashSet<_>>>().ok_or(BrushToMeshError::MissingPlane)?;
if face_list.len()<4{
return Err(BrushToMeshError::InvalidFaceCount{count:face_list.len()});