From 0de308b21ded790a46399fabf753ab192ab8d1a9 Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:26:38 -0400 Subject: [PATCH] Wave 213/509: kernel: a tangent chain stops at a smooth edge (and 3 more) 4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - e6f993fff jyviko: Revert "kernel: merged topology counts no seam edge (a face on both sides of it)" - 4ea29e307 jyviko: kernel-cases: 818 counts its two cylinders' seams, as every case counts edges - de0e5bf52 jyviko: kernel: a tangent chain stops at a smooth edge - 369c897d8 jyviko: kernel, cli: clippy and the cli tests build again Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- Cargo.lock | 1 + apps/solidcraft-cli/Cargo.toml | 2 ++ crates/kernel/src/blend.rs | 18 ++++++++++++++---- crates/kernel/src/prism.rs | 5 +++-- crates/kernel/src/topo.rs | 10 ---------- .../expected.json | 6 +++--- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01aa3c652..2d7acdb88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4253,6 +4253,7 @@ dependencies = [ "serde_json", "solidcraft-engine", "solidcraft-gpu", + "solidcraft-kernel", "solidcraft-mcp", ] diff --git a/apps/solidcraft-cli/Cargo.toml b/apps/solidcraft-cli/Cargo.toml index e5da188ff..e0c2523af 100644 --- a/apps/solidcraft-cli/Cargo.toml +++ b/apps/solidcraft-cli/Cargo.toml @@ -38,3 +38,5 @@ serde_json = { workspace = true } [dev-dependencies] # Snapshot tests decode the pictures to compare them with a tolerance. image = { workspace = true } +# Tests measure meshes at their own tolerances. +solidcraft-kernel = { workspace = true } diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs index 5a0ba85e1..8b70cfbf3 100644 --- a/crates/kernel/src/blend.rs +++ b/crates/kernel/src/blend.rs @@ -88,9 +88,8 @@ impl Faces { } /// The outward unit normal of face `f` at `p` (a point within `accept` of its surface). - #[cfg(test)] pub(crate) fn normal_at(&self, f: usize, p: Vec3, accept: f64) -> Option { - let s = SurfaceEval::new(&self.rec.faces.get(f)?.surface).ok()?; + let s = SurfaceEval::new(self.rec.faces.get(f)?.parameters()).ok()?; let uv = s.project(p, None, accept)?; let (_, su, sv) = s.derivs(uv[0], uv[1])?; Some(su.cross(sv).normalized()? * self.side(f)?) @@ -392,7 +391,8 @@ pub fn chamfer_sides(body: &Body, edges: &[Vec3], d1: f64, side: ChamferSide, fl /// 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. An edge only one face uses -/// ends a chain. Picks that find no edge are refused. +/// ends a chain, and so does a smooth edge (its two faces meet tangentially, within 0.5°): it has +/// no corner to round. Picks that find no edge are refused. pub fn tangent_chain(body: &Body, picks: &[Vec3]) -> Result> { /// Edges meeting at an angle below this continue one another. const TANGENT_DEGREES: f64 = 0.5; @@ -421,6 +421,16 @@ pub fn tangent_chain(body: &Body, picks: &[Vec3]) -> Result> { if a == v { rec.tangent(e, false) } else { rec.tangent(e, true).map(|t| t * -1.0) } }; let cos = TANGENT_DEGREES.to_radians().cos(); + let accept = rec.rec.tolerance.max(1e-7) * 10.0; + // Whether edge `e`'s two faces meet tangentially at its start. + let smooth = |e: usize| -> bool { + let faces: Vec = rec.faces_of(e).into_iter().collect(); + let (Some(&a), Some(&b), Some((p, _))) = (faces.first(), faces.get(1), rec.ends(e)) else { return false }; + match (rec.normal_at(a as usize, p, accept), rec.normal_at(b as usize, p, accept)) { + (Some(na), Some(nb)) => faces.len() == 2 && na.dot(nb) > cos, + _ => false, + } + }; let mut k = 0; while k < chain.len() { let Some(&e) = chain.get(k) else { break }; @@ -429,7 +439,7 @@ pub fn tangent_chain(body: &Body, picks: &[Vec3]) -> Result> { for v in edge.vertices { let Some(d) = leaving(e, v) else { continue }; for (f, other) in rec.rec.edges.iter().enumerate() { - if chain.contains(&f) || other.uses.len() < 2 || !other.vertices.contains(&v) { + if chain.contains(&f) || other.uses.len() < 2 || !other.vertices.contains(&v) || smooth(f) { continue; } if leaving(f, v).is_some_and(|g| d.dot(g) < -cos) { diff --git a/crates/kernel/src/prism.rs b/crates/kernel/src/prism.rs index a22bce98f..4deb7ab5c 100644 --- a/crates/kernel/src/prism.rs +++ b/crates/kernel/src/prism.rs @@ -4,8 +4,7 @@ //! result's boundaries are the operands' curves, cut at their crossings and never refitted. //! Also the test of whether a record surface is a wall swept along a direction. -use solidcraft_geom::brep::Surface; -use solidcraft_geom::{Plane, Region2, Seg2, Vec2, Vec3}; +use solidcraft_geom::{Plane, Region2, Seg2, Vec2}; use crate::body::Body; use crate::{BoolOp, KernelError, Result}; @@ -111,6 +110,8 @@ struct Regions { #[cfg(feature = "smlib")] mod sheets { + use solidcraft_geom::Vec3; + use solidcraft_geom::brep::Surface; use solidcraft_geom::Loop2; use solidcraft_geom::brep::Loop; use solidcraft_smlib::{BooleanOp, Brep}; diff --git a/crates/kernel/src/topo.rs b/crates/kernel/src/topo.rs index e56f604f7..a9967a150 100644 --- a/crates/kernel/src/topo.rs +++ b/crates/kernel/src/topo.rs @@ -122,8 +122,6 @@ pub fn merged_topology(b: &Body, mesh: &Mesh) -> Result { let mut weld_e: HashMap<(usize, usize, (i64, i64, i64)), usize> = HashMap::new(); let mut welded_faces: Vec> = Vec::new(); let mut welded_ends: Vec<(usize, usize)> = Vec::new(); - // How many face uses each welded edge has (a seam: two, on one face). - let mut welded_uses: Vec = Vec::new(); // A record edge standing for each welded edge (for its points). let mut rep: Vec = Vec::new(); for (ei, (e, between)) in record.edges.iter().zip(edge_faces(record)).enumerate() { @@ -135,12 +133,8 @@ pub fn merged_topology(b: &Body, mesh: &Mesh) -> Result { if we == welded_faces.len() { welded_faces.push(Vec::new()); welded_ends.push((a, z)); - welded_uses.push(0); rep.push(ei as u32); } - if let Some(n) = welded_uses.get_mut(we) { - *n += e.uses.len(); - } if let Some(fs) = welded_faces.get_mut(we) { for f in between { if !fs.contains(&f) { @@ -212,12 +206,8 @@ pub fn merged_topology(b: &Body, mesh: &Mesh) -> Result { } continue; } - // An edge between two pieces of one merged face, or a seam (one face on both its sides), - // is no edge of the merged topology; one face on one side only is an open edge. - let seam = welded_uses.get(we).is_some_and(|n| *n >= 2); let pair = match gs[..] { [a, b] if a == b => continue, - [_] if seam => continue, [a, b] => (a.min(b), a.max(b)), [a] => (a, a), _ => (usize::MAX, usize::MAX), diff --git a/tests/kernel-cases/tessellation/818-blind-hole-splits-vertical-edges/expected.json b/tests/kernel-cases/tessellation/818-blind-hole-splits-vertical-edges/expected.json index 899094f85..04c464f11 100644 --- a/tests/kernel-cases/tessellation/818-blind-hole-splits-vertical-edges/expected.json +++ b/tests/kernel-cases/tessellation/818-blind-hole-splits-vertical-edges/expected.json @@ -4,11 +4,11 @@ ], "what": "a blind hole cut into a ring whose six concave corners are filleted: the cut used to split every vertical edge (the outer seam and all twelve fillet tangent edges) at the hole's depth, and the fillet corners drew black", "source": "analytic", - "method": "Ring: circle d=55 less the hexagon inscribed in r=25 (vertex at (0,25)), 10 mm tall. Hexagon area 3 sqrt(3)/2 25^2 = 1623.798. Each of its six concave corners (interior angle 120 deg) filled by a 4 mm round gains t r - r^2 (pi-120deg)/2 = 0.8600 (tangent length t = r/tan 60 = 2.3094). Plan area A_p = pi 27.5^2 - hexagon + 6 gain = 757.192. The hole d=3, 3 deep at (24,0) lies between the hexagon's flat (x=21.65) and the rim: V = 10 A_p - pi 1.5^2 3 = 7550.714. Area = top + bottom (2 A_p, the hole's floor replaces what its opening removes from the top) + outer wall 2 pi 27.5 10 + inner wall 10 (6 (25-2t) + 6 r (pi - 120deg)) + hole wall 2 pi 1.5 3 = 4744.733. Faces: 8 cylinders (outer, 6 rounds, hole) and 9 planes (top, bottom, 6 hexagon flats, hole floor). Edges, counting each whole curve once and no seams: top 1+12+1, bottom 1+12, vertical 12 tangent edges, hole floor 1 = 40; vertices 28.", + "method": "Ring: circle d=55 less the hexagon inscribed in r=25 (vertex at (0,25)), 10 mm tall. Hexagon area 3 sqrt(3)/2 25^2 = 1623.798. Each of its six concave corners (interior angle 120 deg) filled by a 4 mm round gains t r - r^2 (pi-120deg)/2 = 0.8600 (tangent length t = r/tan 60 = 2.3094). Plan area A_p = pi 27.5^2 - hexagon + 6 gain = 757.192. The hole d=3, 3 deep at (24,0) lies between the hexagon's flat (x=21.65) and the rim: V = 10 A_p - pi 1.5^2 3 = 7550.714. Area = top + bottom (2 A_p, the hole's floor replaces what its opening removes from the top) + outer wall 2 pi 27.5 10 + inner wall 10 (6 (25-2t) + 6 r (pi - 120deg)) + hole wall 2 pi 1.5 3 = 4744.733. Faces: 8 cylinders (outer, 6 rounds, hole) and 9 planes (top, bottom, 6 hexagon flats, hole floor). Edges, counting each whole curve once and each cylinder's seam (a whole circle is one closed edge): top 1+12+1, bottom 1+12, vertical 12 tangent edges, hole floor 1, seams of the outer wall and the hole wall 2 = 42; vertices 28.", "body_count": 1, "volume_mm3": 7550.714, "area_mm2": 4744.733, "faces": 17, - "edges": 40, + "edges": 42, "vertices": 28 -} \ No newline at end of file +}