Revolve: a cut side whose holes cannot be found within the limit is refused

When the search for holes in a partial sweep's cut sides passes its work
limit, Revolve now reports the profile as too complex instead of closing
the cut sides with every hole filled.
This commit is contained in:
dotCooCoo
2026-11-15 11:13:18 -08:00
parent 817f258d9d
commit 0633645f24
2 changed files with 33 additions and 12 deletions
+10 -12
View File
@@ -1089,6 +1089,7 @@ fn cut_region(points: &[Point], closed: bool, axis: f64) -> Vec<Vec<Point>> {
return vec![];
}
let crossed = PathData::new(vec![vectorcraft_geom::SubPath::polyline(&ring, true)]);
// A loop thinner than 0.000001 pt is left out, as the solids' rings leave out such debris.
match vectorcraft_pathops::try_unite_all_with(&[(&crossed, FillRule::NonZero)], 1e-6) {
Ok(loops) => loops
.subpaths
@@ -1096,7 +1097,8 @@ fn cut_region(points: &[Point], closed: bool, axis: f64) -> Vec<Vec<Point>> {
.map(|s| s.anchors.iter().map(|a| a.p).collect::<Vec<_>>())
.filter(|l| l.len() >= 3 && ring_area(l).abs() > 1e-10)
.collect(),
// Past the boolean's limits, the region is kept as the profile draws it.
// Past the boolean's limits the region is kept as the profile draws it, as the solids'
// rings keep theirs.
Err(_) if ring_area(&ring).abs() > 1e-10 => vec![ring],
Err(_) => vec![],
}
@@ -1204,13 +1206,12 @@ fn oriented(regions: impl IntoIterator<Item = (Vec<Vec<Point>>, bool)>) -> Vec<V
/// Whether each of the closed contours `contours` of `path` walls a hole under `rule`: the fill is
/// outside it and not inside at most of its segments' middles. An open contour, or every contour
/// when there is only one or the search passes its limits, walls none.
fn holes_of(path: &PathData, rule: FillRule, contours: &[usize]) -> Vec<bool> {
let none = vec![false; contours.len()];
/// when there is only one, walls none. An error when the search passes its limits.
fn holes_of(path: &PathData, rule: FillRule, contours: &[usize]) -> Result<Vec<bool>, String> {
if contours.len() < 2 {
return none;
return Ok(vec![false; contours.len()]);
}
let Ok(mut search) = HoleSearch::new(path, rule) else { return none };
let mut search = HoleSearch::new(path, rule)?;
let mut out = Vec::with_capacity(contours.len());
for &k in contours {
let Some(sp) = path.subpaths.get(k).filter(|sp| sp.closed) else {
@@ -1219,14 +1220,11 @@ fn holes_of(path: &PathData, rule: FillRule, contours: &[usize]) -> Vec<bool> {
};
let mut walls = 0;
for segment in 0..sp.anchors.len() {
match search.is_hole(k, sp.segment(segment).eval(0.5)) {
Ok(hole) => walls += usize::from(hole),
Err(_) => return none,
}
walls += usize::from(search.is_hole(k, sp.segment(segment).eval(0.5))?);
}
out.push(walls * 2 > sp.anchors.len());
}
out
Ok(out)
}
impl CutRegions {
@@ -1279,7 +1277,7 @@ impl CutRegions {
lose_mesh(draw, mesh, lost, e)?;
}
let contours: Vec<usize> = self.drawn.iter().map(|(_, k)| *k).collect();
let holes = holes_of(path, rule, &contours);
let holes = holes_of(path, rule, &contours)?;
cut_faces(at, &oriented(self.drawn.iter().map(|(r, _)| r.clone()).zip(holes)), eye, light)
}
}
+23
View File
@@ -126,6 +126,29 @@ fn the_mesh_closes_a_cut_side_that_crosses_itself_with_both_of_its_loops() {
assert!((start - 1000.0).abs() < 1e-6, "{start}");
}
#[test]
fn a_region_thinner_than_a_millionth_of_a_point_is_debris_and_closes_no_cut_side() {
// 0.0000005 pt wide and 80 pt tall, beside a square 40 pt across.
let path = profile("M40 10 L40.0000005 10 L40.0000005 90 L40 90 Z M50 10 L90 10 L90 50 L50 50 Z");
let bounds = path.bounds().unwrap();
let o = Revolve { angle: 90.0, offset: 10.0, ..options() };
let mesh = revolve_mesh(&path, FillRule::NonZero, bounds, o).unwrap();
let start = area_facing(&mesh, [0.0, 0.0, -1.0]);
assert!((start - 40.0 * 40.0).abs() < 1e-6, "{start}");
}
#[test]
fn cut_sides_whose_holes_cannot_be_found_within_the_limit_are_refused() {
// 2,100 squares on top of each other: each test of a point meets every square.
let square = "M20 10 L60 10 L60 50 L20 50 Z ";
let path = profile(&square.repeat(2100));
let bounds = path.bounds().unwrap();
let o = Revolve { angle: 90.0, offset: 10.0, ..options() };
assert_eq!(revolve(&path, bounds, o).err().as_deref(), Some(TOO_COMPLEX_PROFILE));
// Hollow, the sweep has no cut sides to close.
assert!(revolve(&path, bounds, Revolve { cap_ends: false, ..o }).is_ok());
}
#[test]
fn visibility_keeps_both_of_two_separate_regions_wound_opposite_ways() {
let path = profile("M20 10 L30 10 L30 50 L20 50 Z M40 10 L40 50 L50 50 L50 10 Z");