From 0633645f2401e4b15345a1c863e5a2d6aaeac72f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 11:13:18 -0800 Subject: [PATCH] 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. --- crates/three-d/src/lib.rs | 22 ++++++++++------------ crates/three-d/src/tests/cut_sides.rs | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/crates/three-d/src/lib.rs b/crates/three-d/src/lib.rs index 2790458cc8..e1cd292f1f 100644 --- a/crates/three-d/src/lib.rs +++ b/crates/three-d/src/lib.rs @@ -1089,6 +1089,7 @@ fn cut_region(points: &[Point], closed: bool, axis: f64) -> Vec> { 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> { .map(|s| s.anchors.iter().map(|a| a.p).collect::>()) .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>, bool)>) -> Vec Vec { - 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, 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 { }; 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 = 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) } } diff --git a/crates/three-d/src/tests/cut_sides.rs b/crates/three-d/src/tests/cut_sides.rs index 9d78da3e9d..70b73a4860 100644 --- a/crates/three-d/src/tests/cut_sides.rs +++ b/crates/three-d/src/tests/cut_sides.rs @@ -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");