From c4dba062ebe8dea2a5235ad7f2fc738bb5c6e5e3 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Wed, 5 Feb 2025 11:21:45 -0800
Subject: [PATCH] no revisit

---
 lib/bsp_loader/src/brush.rs | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/lib/bsp_loader/src/brush.rs b/lib/bsp_loader/src/brush.rs
index 9c2f29f..469f7d2 100644
--- a/lib/bsp_loader/src/brush.rs
+++ b/lib/bsp_loader/src/brush.rs
@@ -70,18 +70,14 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
 		let mut intersection=solve3(face0,face1,face2).ok_or(PlanesToFacesError::InitIntersection)?;
 
 		// repeatedly update face0, face1 until all faces form part of the convex solid
+		let mut clone_every_loop:std::collections::HashSet<_>=face_list.iter().filter(|&new_face|
+			core::ptr::eq(face0,new_face)
+			|core::ptr::eq(face1,new_face)
+			|core::ptr::eq(face2,new_face)
+		).collect();
 		'find: loop{
 			// test if any *other* faces occlude the intersection
-			for new_face in &face_list{
-				if core::ptr::eq(face0,new_face){
-					continue;
-				}
-				if core::ptr::eq(face1,new_face){
-					continue;
-				}
-				if core::ptr::eq(face2,new_face){
-					continue;
-				}
+			for &new_face in &clone_every_loop{
 				// new face occludes intersection point
 				if new_face.dot*intersection.den<new_face.normal.dot(intersection.num){
 					// replace one of the faces with the new face
@@ -89,6 +85,7 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
 					if let Some(new_intersection)=solve3(face0,new_face,face2){
 						// face1 does not occlude (or intersect) the new intersection
 						if face1.dot*new_intersection.den>face1.normal.dot(new_intersection.num){
+							clone_every_loop.remove(new_face);
 							face1=new_face;
 							intersection=new_intersection;
 							continue 'find;
@@ -97,6 +94,7 @@ fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Result<Faces,Plan
 					if let Some(new_intersection)=solve3(face0,face1,new_face){
 						// face2 does not occlude (or intersect) the new intersection
 						if face2.dot*new_intersection.den>face2.normal.dot(new_intersection.num){
+							clone_every_loop.remove(new_face);
 							face2=new_face;
 							intersection=new_intersection;
 							continue 'find;