SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Wave 328/509: Kernel: an extrusion's wall seed marks only the edges nearest it (and 3 more)
jyvikof3b8ae549745
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex c09cda3f51..1c5b63cbab 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -3226,7 +3226,8 @@ pub fn edge_refs(st: &ModelState, body: &Option<crate::BodyName>, pts: &[Vec3])}/// Persistent names of the edges picked at `pts`, each on the body it lies on (see-/// [`picked_bodies`]).+/// [`picked_bodies`]): of the edge a blend takes at each pick (at a vertex where a seam meets a+/// rim, the rim), else of the nearest edge.pub fn edge_names_for(st: &ModelState, body: &Option<crate::BodyName>, pts: &[Vec3]) -> Vec<String> {let Some(on) = picked_bodies(st, body, pts) else { return Vec::new() };let mut out = vec![String::new(); pts.len()];@@ -3240,7 +3241,14 @@ pub fn edge_names_for(st: &ModelState, body: &Option<crate::BodyName>, pts: &[Ve// The body's names are worked out once for all its picks.let idx: Vec<usize> = on.iter().enumerate().filter(|(_, t)| **t == ti).map(|(i, _)| i).collect();let at: Vec<Vec3> = idx.iter().filter_map(|i| pts.get(*i).copied()).collect();- for (i, n) in idx.into_iter().zip(crate::naming::edge_names_at(b, &at)) {+ let names = match kernel::blend_edges(&b.body, &at) {+ Ok(edges) => {+ let all = crate::naming::edge_names(b);+ edges.iter().map(|e| all.get(*e).cloned().unwrap_or_default()).collect()+ }+ Err(_) => crate::naming::edge_names_at(b, &at),+ };+ for (i, n) in idx.into_iter().zip(names) {if let Some(slot) = out.get_mut(i) {*slot = n;}diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rsindex f48ea25662..5098f69f98 100644--- a/crates/kernel/src/blend.rs+++ b/crates/kernel/src/blend.rs@@ -617,6 +617,13 @@ pub fn chamfer_sides(body: &Body, edges: &[Vec3], d1: f64, side: ChamferSide, flcrate::blend_smlib::chamfer_sides(body, edges, d1, side, flip)}+/// The edge each pick takes, as a blend takes it (an index in the body's edge order, the order+/// of its mesh's edges): the nearest, and at a vertex where a seam or a smooth join meets a sharp+/// edge (a cylinder's seam at its rim), the sharp edge. Picks that find no edge are refused.+pub fn blend_edges(body: &Body, picks: &[Vec3]) -> Result<Vec<usize>> {+ crate::blend_smlib::picked_edges(body, picks).map(|(edges, _)| edges)+}+/// The picked edges' tangent chains, for a blend that is to run along them: `picks` (each the/// nearest edge of `body` to it), then a point on every other edge that continues one of them/// tangentially (within 0.5° at a shared vertex), until no more do. Each pick takes its edge as adiff --git a/crates/kernel/src/face_source_tests.rs b/crates/kernel/src/face_source_tests.rsindex 6b52e8033b..c46f0008bf 100644--- a/crates/kernel/src/face_source_tests.rs+++ b/crates/kernel/src/face_source_tests.rs@@ -27,6 +27,12 @@ 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.)),+ // Far thinner than the body's flatness tolerance (0.1 µm in 14 mm): each cap is in its+ // own plane only.+ (Vec3::ZERO, Vec3::new(10., 10., 1e-4)),] {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/lib.rs b/crates/kernel/src/lib.rsindex d0a75cf887..350f646a78 100644--- a/crates/kernel/src/lib.rs+++ b/crates/kernel/src/lib.rs@@ -155,8 +155,8 @@ mod validity;pub mod watch;pub use blend::{- ChamferSide, chamfer, chamfer_sides, fillet, fillet_each, fillet_g2, fillet_g2_corners, fillet_least_setback, fillet_max, fillet_max_each,- fillet_setback, tangent_chain,+ ChamferSide, blend_edges, chamfer, chamfer_sides, fillet, fillet_each, fillet_g2, fillet_g2_corners, fillet_least_setback, fillet_max,+ fillet_max_each, fillet_setback, tangent_chain,};pub use blend_corner::fillet_radii;pub use blend_variable::{RadiusSpline, Taper, fillet_chord, fillet_tapered, fillet_variable, fillet_variable_points, fillet_variable_spline, taper};diff --git a/crates/kernel/src/smlib_sweeps.rs b/crates/kernel/src/smlib_sweeps.rsindex c9bbd3214e..679a3630c6 100644--- a/crates/kernel/src/smlib_sweeps.rs+++ b/crates/kernel/src/smlib_sweeps.rs@@ -272,7 +272,17 @@ mod imp {let m = body.mesh(&crate::MeshTolerance::chord(mesh_tol))?;let faces = face_tris(&m);let n = body.face_count();- let flat_tol = size * 1e-5 + 1e-9;+ // A cap's points lie on its plane to the evaluation's precision. Sized to the body, the+ // flatness tolerance can exceed the gap between parallel start and end planes (a box+ // 0.1 µm thick in a 14 mm body), which would put each cap in both: it stays under a+ // quarter of that gap. Planes that coincide (the ends of a half turn) are told apart by+ // the profile's edges instead.+ let gap = end+ .filter(|e| e.normal().cross(start.normal()).len() < 1e-9)+ .map(|e| start.height(e.origin).abs())+ .filter(|g| *g > size * 1e-9)+ .unwrap_or(f64::INFINITY);+ let flat_tol = (size * 1e-5 + 1e-9).min(0.25 * gap);let near = 3.0 * mesh_tol + flat_tol;let flat = |f: usize, pl: &Plane| {faces.get(f).is_some_and(|ft| !ft.tris.is_empty() && ft.tris.iter().all(|(t, _)| t.iter().all(|q| pl.height(*q).abs() <= flat_tol)))@@ -289,12 +299,22 @@ mod imp {let end_cap: Vec<bool> = (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<BTreeSet<usize>> = 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<Vec3>, &Vec<u32>)> = 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<f64> = 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);