diff --git a/crates/kernel/src/issue_2005_tests.rs b/crates/kernel/src/issue_2005_tests.rs index 532a07b43..98c67eda9 100644 --- a/crates/kernel/src/issue_2005_tests.rs +++ b/crates/kernel/src/issue_2005_tests.rs @@ -31,8 +31,10 @@ fn circle_path() -> [PathSeg; 2] { fn tube(body: &Body, volume: f64, genus: usize) { let m = measure(body).unwrap(); assert!((m.volume - volume).abs() < volume * 0.01, "{m:?}, expected {volume}"); - // A closed orientable tube has Euler characteristic 2 - 2g. Coincident caps gave 2. - assert_eq!(m.vertices + m.faces + 2 * genus, m.edges + 2, "{m:?}"); + // A closed orientable tube of genus g: V - E + F - (L - F) = 2 - 2g (Euler-Poincare, L the + // loops: an annular face has two). Coincident caps gave 2 - 2g + 2. + let loops: usize = body.record().faces.iter().map(|f| f.loops.len()).sum(); + assert_eq!(m.vertices + 2 * m.faces + 2 * genus, m.edges + loops + 2, "{m:?}, {loops} loops"); // Every shell closed: each edge bounds two faces. assert!(body.record().edges.iter().all(|e| e.uses.len() >= 2)); let h = body.history().expect("sweep provenance"); diff --git a/crates/kernel/src/record_tests.rs b/crates/kernel/src/record_tests.rs index 54ac6c194..3590a7dca 100644 --- a/crates/kernel/src/record_tests.rs +++ b/crates/kernel/src/record_tests.rs @@ -439,13 +439,13 @@ fn check_sweep(b: &Body, plane: &Plane, r: &Region2, faces_per_segment: Option = (0..=40) .map(|i| { diff --git a/crates/kernel/src/smlib_sweeps.rs b/crates/kernel/src/smlib_sweeps.rs index 679a3630c..62386961f 100644 --- a/crates/kernel/src/smlib_sweeps.rs +++ b/crates/kernel/src/smlib_sweeps.rs @@ -565,9 +565,18 @@ mod imp { if runs.len() > 1 { return cornered(plane, pieces, path, &runs, translate); } - let (brep, _) = swept(plane, pieces, path, translate)?; + let (brep, [_, middle, last]) = swept(plane, pieces, path, translate)?; let body = body_of(&brep, "sweep")?; - let roles = roles(&body, plane, None, &seeds(plane, pieces, |q| q), &[], true)?; + // The walls known by the profile carried half way (past the start's edges: a wall the + // start touches by no edge, as round a closed path, and walls along later path segments). + let inside = seeds(plane, pieces, |q| apply(&middle, q)); + let start = path.first().map(crate::PathSeg::start); + let end = path.last().map(seg_ends).transpose()?.map(|(_, b)| b); + let roles = match (start, end) { + // Round a closed path there are no caps, and the start holds seams only. + (Some(a), Some(b)) if a.dist(b) <= 1e-6 => roles(&body, &plane.offset(body.size().max(1e-9) * 10.0), None, &[], &inside, false)?, + _ => roles(&body, plane, Some(&placed(plane, &last)), &seeds(plane, pieces, |q| q), &inside, false)?, + }; with_history(body, &roles, pieces) }