diff --git a/crates/kernel/src/face_source_tests.rs b/crates/kernel/src/face_source_tests.rs index 6b52e8033..8c4e16c7d 100644 --- a/crates/kernel/src/face_source_tests.rs +++ b/crates/kernel/src/face_source_tests.rs @@ -27,6 +27,9 @@ fn box_certificates_are_six_construction_roles_with_dimension_stable_axes() { (Vec3::new(2., 3., 4.), Vec3::new(12., 23., 34.)), (Vec3::new(12., 23., 34.), Vec3::new(2., 3., 4.)), (Vec3::new(2., -8., 4.), Vec3::new(22., 43., 54.)), + // A side far shorter than the body (a 0.3 mm label of a metre): its walls' edges lie + // closer together than the sweep's body-sized nearness, and each keeps its own role. + (Vec3::new(500., -0.3, 1400.), Vec3::new(1500., 0., 1800.)), ] { let body = crate::box_solid(a, b).unwrap().with_box_certificate(42).unwrap(); let mut roles = std::collections::HashSet::new(); diff --git a/crates/kernel/src/smlib_sweeps.rs b/crates/kernel/src/smlib_sweeps.rs index c9bbd3214..6eb076766 100644 --- a/crates/kernel/src/smlib_sweeps.rs +++ b/crates/kernel/src/smlib_sweeps.rs @@ -289,12 +289,22 @@ mod imp { let end_cap: Vec = (0..n).map(|f| end.is_some_and(|e| flat(f, e))).collect(); let cap = |f: usize| start_cap.get(f).copied().unwrap_or(false) || end_cap.get(f).copied().unwrap_or(false); let mut swept: Vec> = vec![BTreeSet::new(); n]; - for (poly, fs) in m.edges.iter().zip(&m.edge_faces) { - if poly.len() < 2 || !poly.iter().all(|q| start.height(*q).abs() <= flat_tol) { - continue; - } - for s in edges { - if poly.windows(2).any(|w| s.at.dist_to_segment(w[0], w[1]) <= near) { + // Each seed lies on its own piece's edge (within the mesh's sag on a curve); `near` is + // sized to the body, so on a side shorter than it (a 0.3 mm wall of a 1 m label) the + // neighbours' edges are near too. The seed marks only the edges nearest it: the one it + // lies on, or both pieces of an edge split at its middle. + let start_edges: Vec<(&Vec, &Vec)> = m + .edges + .iter() + .zip(&m.edge_faces) + .filter(|(poly, _)| poly.len() >= 2 && poly.iter().all(|q| start.height(*q).abs() <= flat_tol)) + .collect(); + for s in edges { + let dist = |poly: &[Vec3]| poly.windows(2).map(|w| s.at.dist_to_segment(w[0], w[1])).fold(f64::INFINITY, f64::min); + let ds: Vec = start_edges.iter().map(|(poly, _)| dist(poly)).collect(); + let nearest = ds.iter().copied().fold(f64::INFINITY, f64::min); + for ((_, fs), d) in start_edges.iter().zip(&ds) { + if *d <= near && *d <= nearest + flat_tol { for f in fs.iter().map(|f| *f as usize).filter(|f| !cap(*f)) { if let Some(set) = swept.get_mut(f) { set.insert(s.piece);