Prepress: keep catching panics around the linesweeper contour walk

The contour walk returns an error for inconsistent winding numbers, but
other degenerate input can still reach panics in linesweeper's walk and
sweep. Arrangement::regions and nonzero catch them again, so a crafted
path gives GeomError::Degenerate or keeps the even-odd path as it is,
instead of ending the process.
This commit is contained in:
dotCooCoo committed 2026-11-07 09:45:11 -08:00
1 parent 79e39a5aa4
commit d9f4b423eb
2 files changed
+12 -6

No files matched your search

+5 -2
View File
@@ -412,9 +412,12 @@ impl Arrangement {
}
/// The contours of `top`'s faces for which `inside` holds. The contour walk returns an error when the
/// sweep left winding numbers that disagree around a point; that input is degenerate.
/// sweep left winding numbers that disagree around a point, and can still panic on other degenerate
/// input; either way that input is degenerate.
fn contours(top: &Topology<Multi>, inside: impl Fn(&Multi) -> bool) -> Result<Contours, GeomError> {
top.try_contours(inside).map_err(|_| GeomError::Degenerate)
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| top.try_contours(inside)))
.map_err(|_| GeomError::Degenerate)?
.map_err(|_| GeomError::Degenerate)
}
/// A point as a map key (the arrangement's vertices are exact).
+7 -4
View File
@@ -1272,21 +1272,24 @@ fn dash_pattern(path: &BezPath, dashes: &[f32]) -> Option<Vec<f64>> {
}
/// `path` filled by `rule`, as a path filled nonzero. An even-odd path is rebuilt from its
/// boundary; if that fails it is kept as it is.
/// boundary; if that fails or panics it is kept as it is.
fn nonzero(path: &BezPath, rule: FillRule) -> BezPath {
if rule == FillRule::NonZero {
return path.clone();
}
let closed = closed(path);
match linesweeper::binary_op(&closed, &BezPath::new(), linesweeper::FillRule::EvenOdd, linesweeper::BinaryOp::Union) {
Ok(contours) => {
let op = catch_unwind(AssertUnwindSafe(|| {
linesweeper::binary_op(&closed, &BezPath::new(), linesweeper::FillRule::EvenOdd, linesweeper::BinaryOp::Union)
}));
match op {
Ok(Ok(contours)) => {
let mut out = BezPath::new();
for contour in contours.contours() {
out.extend(contour.path.iter());
}
out
}
Err(_) => closed,
Ok(Err(_)) | Err(_) => closed,
}
}