From e4b6d375f89e6e96cb5bb4ad7b1d36492d22226c Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 18 Sep 2023 21:51:21 +0100 Subject: [PATCH] Brush vertices are now checked against all brush planes for validity --- csg/src/brush.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/csg/src/brush.rs b/csg/src/brush.rs index 1af0949..b8568b7 100644 --- a/csg/src/brush.rs +++ b/csg/src/brush.rs @@ -41,6 +41,8 @@ impl Brush { return vec![]; } + // Test all permutations of brush planes for intersections + let mut intersections = vec![]; let mut vs = vec![]; let len = self.planes.len(); for i in 0..(len - 2) { @@ -51,13 +53,28 @@ impl Brush { self.planes[j].plane, self.planes[k].plane, ) { - // TODO: Validate that the found intersection is within all brush planes - vs.push(intersection.get_intersection_point()) + intersections.push(intersection) } } } } + // Validate intersections against other brush planes + // TODO: No need to check against planes that are part of the intersection + for intersection in intersections { + let mut valid = true; + for bplane in &self.planes { + if !intersection.in_halfspace_mat(&bplane.plane) { + valid = false; + break; + } + } + + if valid { + vs.push(intersection.get_intersection_point()); + } + } + vs } }