Fix boolean crash with self intersecting shape (#952)

This commit is contained in:
0HyperCube 2023-01-09 02:25:06 +00:00 committed by Keavon Chambers
parent de407f8b23
commit 2a27471363
1 changed files with 8 additions and 3 deletions

View File

@ -25,6 +25,7 @@ pub enum BooleanOperationError {
NoIntersections,
NothingDone, // Not necessarily an error
DirectionUndefined,
NoResult,
Unexpected, // For debugging, when complete nothing should be unexpected
}
@ -492,9 +493,13 @@ pub fn composite_boolean_operation(mut select: BooleanOperation, shapes: &mut Ve
match partial_union {
Ok(temp_union) => {
// The result of a successful union will be exactly one shape
shapes.push(RefCell::new(temp_union.into_iter().next().unwrap()));
shapes.swap_remove(subject_idx);
shapes.swap_remove(shape_idx);
if let Some(result) = temp_union.into_iter().next() {
shapes.push(RefCell::new(result));
shapes.swap_remove(subject_idx);
shapes.swap_remove(shape_idx);
} else {
return Err(BooleanOperationError::NoResult);
}
}
Err(BooleanOperationError::NothingDone) => shape_idx += 1,
Err(err) => return Err(err),