SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Wave 196/509: kernel: the test target compiles: the last tests on the record and SMLib (and 3 more)
jyviko460f7fa0f7be
diff --git a/crates/kernel/src/assemble.rs b/crates/kernel/src/assemble.rsindex a33f86ad1d..b81478fd46 100644--- a/crates/kernel/src/assemble.rs+++ b/crates/kernel/src/assemble.rs@@ -11,7 +11,7 @@//! normal, as the record does.use solidcraft_geom::Vec3;-use solidcraft_geom::brep::eval::{CurveEval, SurfaceEval};+use solidcraft_geom::brep::eval::CurveEval;use solidcraft_geom::brep::pcurve::{EdgeUse, pcurves_within};use solidcraft_geom::brep::{Brep, Curve, Curve2, Edge, Face, Loop, Natural, OrientedEdge, OrientedFace, Region, Shell, Surface, VERSION, Vertex};@@ -129,18 +129,6 @@ impl Assembly {Ok(Assembly { tolerance: b.tolerance, vertices: b.vertices.clone(), edges, faces, regions: b.regions.clone(), shells: b.shells.len() })}- /// An empty sheet to build faces into: one open shell (shell 0) in the infinite region.- pub(crate) fn sheet(tolerance: f64) -> Assembly {- Assembly {- tolerance,- vertices: Vec::new(),- edges: Vec::new(),- faces: Vec::new(),- regions: vec![Region { shells: vec![0], void: false }],- shells: 1,- }- }-/// A new vertex at `p`.pub(crate) fn vertex(&mut self, p: Vec3) -> Result<u32> {if !p.is_finite() {@@ -397,13 +385,3 @@ pub(crate) fn natural_out(b: &Brep, face: usize) -> Option<bool> {_ => None,})}--/// The outward unit normal of face `face` of `b` at the parameters of `p`, a point on it.-pub(crate) fn outward_normal(b: &Brep, face: usize, p: Vec3) -> Option<Vec3> {- let f = b.faces.get(face)?;- let s = SurfaceEval::new(&f.surface).ok()?;- let uv = s.project(p, None, f64::INFINITY)?;- let (_, su, sv) = s.derivs(uv[0], uv[1])?;- let n = su.cross(sv).normalized()?;- Some(if natural_out(b, face)? { n } else { -n })-}diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rsindex 43b51b00eb..516bd5b9ec 100644--- a/crates/kernel/src/blend.rs+++ b/crates/kernel/src/blend.rs@@ -116,7 +116,7 @@ impl Faces {/// The unit direction into planar face `f` across the straight edge of `u`, square to the/// edge: the face lies to the left of its loop seen from its surface's natural normal.- pub(crate) fn into_face(&self, f: usize, u: &OrientedEdge) -> Option<Vec3> {+ pub(crate) fn direction_into_face(&self, f: usize, u: &OrientedEdge) -> Option<Vec3> {let (a, b) = self.ends(u.edge as usize)?;let dir = if u.forward { b - a } else { a - b };self.natural_plane_normal(f)?.cross(dir.normalized()?).normalized()@@ -167,7 +167,7 @@ pub(crate) fn curve_derivative(c: &Curve, t: f64) -> Option<Vec3> {let (_, su, sv) = e.derivs(uv[0], uv[1])?;Some(su.cross(sv))};- let along = normal(&*surfaces[0])?.cross(normal(&*surfaces[1])?);+ let along = normal(&surfaces[0])?.cross(normal(&surfaces[1])?);let along = along.normalized()?;if along.dot(curve_tangent(leader, t)?) < 0.0 { along * -1.0 } else { along }}diff --git a/crates/kernel/src/blend_fit.rs b/crates/kernel/src/blend_fit.rsindex a313f3ed22..7c346b3e00 100644--- a/crates/kernel/src/blend_fit.rs+++ b/crates/kernel/src/blend_fit.rs@@ -322,7 +322,7 @@ fn frame(rec: &Faces, e: usize) -> Option<Frame> {if !uses.is_empty() {return None;}- beside.push((n, rec.into_face(i, u)?));+ beside.push((n, rec.direction_into_face(i, u)?));chained |= rec.uses(i).filter(|x| x.edge as usize != e).any(|x| {let Some(other) = rec.rec.edges.get(x.edge as usize) else { return false };let [a, b] = other.vertices;diff --git a/crates/kernel/src/blend_variable.rs b/crates/kernel/src/blend_variable.rsindex cf21f7a086..d7544ced04 100644--- a/crates/kernel/src/blend_variable.rs+++ b/crates/kernel/src/blend_variable.rs@@ -34,7 +34,7 @@ fn edge_frame(rec: &Faces, e: usize) -> Result<EdgeFrame> {if uses.next().is_some() {return None;}- rec.into_face(f, u)+ rec.direction_into_face(f, u)};let (Some(t1), Some(t2)) = (into(i1), into(i2)) else { return Err(KernelError::Failed("blend: edge direction".into())) };let phi = t1.dot(t2).clamp(-1.0, 1.0).acos();diff --git a/crates/kernel/src/boolean_history_tests.rs b/crates/kernel/src/boolean_history_tests.rsindex d8157d13b7..213512342a 100644--- a/crates/kernel/src/boolean_history_tests.rs+++ b/crates/kernel/src/boolean_history_tests.rs@@ -310,15 +310,15 @@ fn trivial_paths() {assert!(h.faces.iter().all(|f| f.change == Change::Kept));}-/// A body in two pieces, cut a piece at a time: each piece's faces are the body's own.+/// A body in two pieces, cut: each piece's faces are the body's own.#[test]-fn by_lumps_composes_the_pieces() {+fn a_cut_of_two_pieces_composes_the_pieces() {let left = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);let right = boxed(20.0, 0.0, 0.0, 30.0, 10.0, 10.0);let a = boolean(&left, &right, BoolOp::Union).unwrap().unwrap();assert_eq!(a.shell_count(), 2);let b = crate::sphere(Vec3::new(15.0, 5.0, 10.0), 7.0).unwrap();- let r = crate::ops::by_lumps(&a, &b, a.lumps().unwrap(), b.lumps().unwrap(), BoolOp::Cut).unwrap().unwrap();+ let r = boolean(&a, &b, BoolOp::Cut).unwrap().unwrap();let h = verified(&r, &[&a, &b], 0.02);// Both pieces are bitten: the sphere's patches inside each line its bite.let bites: BTreeSet<_> = h.faces.iter().flat_map(|f| &f.origins).filter(|o| matches!(o, FaceOrigin::Face { operand: 1, .. })).collect();@@ -327,54 +327,6 @@ fn by_lumps_composes_the_pieces() {assert_eq!(targets.len(), 12);}-/// Two bodies touching along one whole face, back to back: glued, the two faces gone, the-/// coplanar sides each side of the seam merged.-#[test]-fn glue_merges_across_the_seam() {- let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);- let b = boxed(10.0, 0.0, 0.0, 20.0, 10.0, 10.0);- let r = crate::coplanar::glue(&a, &b).unwrap().unwrap();- let h = verified(&r, &[&a, &b], 0.02);- assert_eq!(changes(h), [2, 0, 0, 4, 0], "{}", show(h));- // The four seam edges went with the merged faces; the ends' edges are each box's.- assert_eq!(h.edges.len(), 12);- assert!(h.edges.iter().all(|e| !e.origins.is_empty()));-}--/// Coincident faces pushed apart: a cut flush with the target's top, and a union of bodies-/// standing on one floor (the floor that is cut back is both operands' floors).-#[test]-fn faces_pushed_apart() {- let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);- let tool = boxed(2.0, 2.0, 5.0, 8.0, 8.0, 10.0);- let r = crate::coplanar::boolean_apart(&a, &tool, BoolOp::Cut).unwrap().unwrap().unwrap();- let h = verified(&r, &[&a, &tool], 0.02);- // The pocket: its floor and four sides are the tool's.- let tool_faces: BTreeSet<_> = h.faces.iter().flat_map(|f| &f.origins).filter(|o| matches!(o, FaceOrigin::Face { operand: 1, .. })).collect();- assert_eq!(tool_faces.len(), 5, "{}", show(h));- let left = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);- let right = boxed(5.0, 3.0, 0.0, 15.0, 7.0, 4.0);- let r = crate::coplanar::boolean_apart(&left, &right, BoolOp::Union).unwrap().unwrap().unwrap();- let h = verified(&r, &[&left, &right], 0.02);- assert!(h.faces.iter().any(|f| f.change == Change::Merged && f.origins.len() == 2), "{}", show(h));-}--/// The exact polygon boolean: pieces of planar faces joined back into faces.-#[test]-fn planar_fallback() {- let a = boxed(0.0, 0.0, 0.0, 10.0, 10.0, 10.0);- let b = boxed(5.0, 5.0, 5.0, 15.0, 15.0, 15.0);- for (op, count) in [(BoolOp::Cut, 9), (BoolOp::Union, 12), (BoolOp::Intersect, 6)] {- let r = crate::polybool::planar_boolean(&a, &b, op).unwrap().unwrap();- let h = verified(&r, &[&a, &b], 0.02);- assert_eq!(h.faces.len(), count, "{op:?}\n{}", show(h));- assert!(h.faces.iter().all(|f| f.origins.len() == 1));- // Three faces of each meet three of the other's.- assert_eq!(meets(h).len(), 6, "{op:?}\n{}", show(h));- assert!(h.edges.iter().all(|e| e.origins.len() == 1), "{op:?}\n{}", show(h));- }-}-/// A boolean with a triangle mesh: the mesh's faces are its triangles (and it has no edges).#[test]fn faceted_tool() {@@ -433,24 +385,6 @@ fn regularized_step_cut() {assert_eq!(faces_of(h), faces_of(ph), "{}", show(h));}-/// A ring joined under a floor, its bore on the floor's hole (coincident cylinders): the ring's-/// bore is narrowed, the bodies joined, and the bore cut out again. The ring's bore is a circle-/// built in two arcs, and the recut wall is split where the cutting cylinder's own construction-/// splits it, so which arc each piece of it restores is not known: no history.-#[test]-fn bore_union_of_a_bore_in_two_arcs_has_no_history() {- let hole = crate::cylinder(Vec3::new(50.0, 40.0, -5.0), Vec3::Z, 10.0, 30.0).unwrap();- let floor = boolean(&boxed(0.0, 0.0, 0.0, 100.0, 80.0, 10.0), &hole, BoolOp::Cut).unwrap().unwrap();- let centre = solidcraft_geom::Vec2::new(50.0, 40.0);- let annulus = solidcraft_geom::Region2 {- outer: solidcraft_geom::Loop2::circle(centre, 20.0),- holes: vec![solidcraft_geom::Loop2::circle(centre, 10.0).reversed()],- };- let ring = crate::extrude(&solidcraft_geom::Plane::XY, &[annulus], -5.0, 2.0).unwrap().remove(0);- let r = crate::coplanar::bore_union(&floor, &ring, &|_| true).expect("the bores are recut");- assert!(r.history().is_none());-}-/// Bodies clearly apart, joined as one body of several pieces (`union_apart`): every face and/// edge is its piece's own, kept.#[test]diff --git a/crates/kernel/src/chamfer_sides_curved_tests.rs b/crates/kernel/src/chamfer_sides_curved_tests.rsindex 53e97e93d2..ed153c0dff 100644--- a/crates/kernel/src/chamfer_sides_curved_tests.rs+++ b/crates/kernel/src/chamfer_sides_curved_tests.rs@@ -210,8 +210,13 @@ fn too_large_or_unsupported_is_refused() {let tilted = crate::build::cylinder(Vec3::new(0.0, 0.0, -10.0), Vec3::new(1.0, 0.0, 2.0), 5.0, 40.0).unwrap();let cut = box_solid(Vec3::new(-50.0, -50.0, 10.0), Vec3::new(50.0, 50.0, 50.0)).unwrap();let t = boolean(&tilted, &cut, BoolOp::Cut).unwrap().unwrap();- let solid = t.deep_copy();- let rim = crate::body::Body::unique_edges(&solid).iter().filter_map(crate::blend::edge_mid).find(|m| (m.z - 10.0).abs() < 1e-6).unwrap();+ let rim = t+ .record()+ .edges+ .iter()+ .filter_map(|e| solidcraft_geom::brep::eval::CurveEval::new(&e.curve).ok()?.point(0.5 * (e.interval[0] + e.interval[1])))+ .find(|m| (m.z - 10.0).abs() < 1e-6)+ .unwrap();match chamfer_sides(&t, &[rim], 1.0, ChamferSide::Distance(2.0), false) {Err(KernelError::Failed(m)) => assert!(m.starts_with("not supported yet"), "{m}"),Err(e) => panic!("{e}"),diff --git a/crates/kernel/src/coplanar_tests.rs b/crates/kernel/src/coplanar_tests.rsindex 4ce8abb381..4c8209a792 100644--- a/crates/kernel/src/coplanar_tests.rs+++ b/crates/kernel/src/coplanar_tests.rs@@ -25,20 +25,19 @@ fn channel() -> Body {box_solid(Vec3::new(-20.0, 30.0, 10.0), Vec3::new(220.0, 70.0, 20.0)).unwrap()}-/// What the boolean of `a` and `b` adds to a's volume, the result's lumps, and how it was made.-fn change(a: &Body, b: &Body, op: BoolOp) -> (f64, usize, BooleanDiagnostics) {- let (r, how) = capture_boolean_diagnostics(|| boolean(a, b, op));- let r = r.unwrap().unwrap();- (measure(&r).unwrap().volume - measure(a).unwrap().volume, r.lumps().unwrap().len(), how)+/// What the boolean of `a` and `b` adds to a's volume, and the result's lumps.+fn change(a: &Body, b: &Body, op: BoolOp) -> (f64, usize) {+ let r = boolean(a, b, op).unwrap().unwrap();+ (measure(&r).unwrap().volume - measure(a).unwrap().volume, r.lumps().unwrap().len())}/// A channel cut along a block, up to the face a rib stands on. The channel's top lies in/// that face's plane and the rib bridges it.#[test]fn a_cut_up_to_a_face_leaves_what_stands_on_the_face() {- let (added, lumps, how) = change(&ribbed(), &channel(), BoolOp::Cut);+ let (added, lumps) = change(&ribbed(), &channel(), BoolOp::Cut);// It takes 200 x 40 x 10 of the block and nothing of the rib.- assert!((added + 80_000.0).abs() < 1e-6 && lumps == 1, "{added}, {lumps} lumps, {how:?}");+ assert!((added + 80_000.0).abs() < 1e-6 && lumps == 1, "{added}, {lumps} lumps");}/// The same with a round hole through the block beside the channel (r 4 at 30, 15: y 11 to@@ -48,9 +47,9 @@ fn a_cut_up_to_a_face_leaves_what_stands_on_the_face() {fn a_round_hole_beside_the_cut_changes_nothing() {let hole = cylinder(Vec3::new(30.0, 15.0, -1.0), Vec3::Z, 4.0, 22.0).unwrap();let drilled = boolean(&ribbed(), &hole, BoolOp::Cut).unwrap().unwrap();- let (added, lumps, how) = change(&drilled, &channel(), BoolOp::Cut);+ let (added, lumps) = change(&drilled, &channel(), BoolOp::Cut);// 200 x 40 x 10 again (the hole is measured on its mesh, before and after).- assert!((added + 80_000.0).abs() < 1e-3 && lumps == 1, "{added}, {lumps} lumps, {how:?}");+ assert!((added + 80_000.0).abs() < 1e-3 && lumps == 1, "{added}, {lumps} lumps");}/// A pocket whose top lies in the plane of the block's top face, and a pad whose foot does.@@ -59,12 +58,12 @@ fn faces_in_a_common_plane_cut_and_join() {let block = block(200.0, 100.0, 20.0);// A pocket 50 x 60 x 5 from the top face: 15 000 less.let pocket = box_solid(Vec3::new(75.0, 20.0, 15.0), Vec3::new(125.0, 80.0, 20.0)).unwrap();- let (added, _, how) = change(&block, &pocket, BoolOp::Cut);- assert!((added + 15_000.0).abs() < 1e-6, "{added}, {how:?}");+ let (added, _) = change(&block, &pocket, BoolOp::Cut);+ assert!((added + 15_000.0).abs() < 1e-6, "{added}");// A pad 50 x 60 x 10 on the top face: 30 000 more.let pad = box_solid(Vec3::new(75.0, 20.0, 20.0), Vec3::new(125.0, 80.0, 30.0)).unwrap();- let (added, lumps, how) = change(&block, &pad, BoolOp::Union);- assert!((added - 30_000.0).abs() < 1e-6 && lumps == 1, "{added}, {how:?}");+ let (added, lumps) = change(&block, &pad, BoolOp::Union);+ assert!((added - 30_000.0).abs() < 1e-6 && lumps == 1, "{added}");}/// A disc joined into a round hole it fills (issue: "boolean Union: no result" for a 1 mm@@ -78,10 +77,9 @@ fn a_disc_joined_into_the_hole_it_fills() {for (z0, z1) in [(0.0, 1.0), (5.0, 8.0), (19.0, 20.0)] {let disc = cylinder(Vec3::new(150.0, 50.0, z0), Vec3::Z, 20.0, z1 - z0).unwrap();let want = measure(&disc).unwrap().volume;- let (r, how) = capture_boolean_diagnostics(|| boolean(&drilled, &disc, BoolOp::Union));- let r = r.unwrap().unwrap();+ let r = boolean(&drilled, &disc, BoolOp::Union).unwrap().unwrap();let added = measure(&r).unwrap().volume - measure(&drilled).unwrap().volume;- assert!((added - want).abs() < want * 1e-3, "{z0}..{z1}: {added} vs {want}, {how:?}");+ assert!((added - want).abs() < want * 1e-3, "{z0}..{z1}: {added} vs {want}");assert!(r.lumps().unwrap().len() == 1 && r.validity().is_empty(), "{z0}..{z1}: {:?}", r.validity());}}diff --git a/crates/kernel/src/emboss.rs b/crates/kernel/src/emboss.rsindex a883c4bceb..e4abdac275 100644--- a/crates/kernel/src/emboss.rs+++ b/crates/kernel/src/emboss.rs@@ -485,7 +485,7 @@ fn newell(ring: &[Vec3]) -> Option<Vec3> {let mut s = Vec3::ZERO;for i in 0..n {let (a, b) = (*ring.get(i)?, *ring.get((i + 1) % n)?);- s = s + a.cross(b);+ s += a.cross(b);}s.normalized()}diff --git a/crates/kernel/src/fill.rs b/crates/kernel/src/fill.rsindex bfc5a342bd..0eccef7bd4 100644--- a/crates/kernel/src/fill.rs+++ b/crates/kernel/src/fill.rs@@ -155,13 +155,13 @@ fn general_fill(// Where a G1/G2 edge's neighbour and the one before disagree at their corner.let n = chain.len();let mut clash = vec![false; n];- for k in 0..n {+ for (k, slot) in clash.iter_mut().enumerate() {let prev = (k + n - 1) % n;let (Some(Some(a)), Some(Some(b))) = (beside.get(prev), beside.get(k)) else { continue };let (Some(ea), Some(eb)) = (edges.get(prev), edges.get(k)) else { continue };let (end, start) = (ea.knots.last().copied().unwrap_or(0.0), eb.knots.first().copied().unwrap_or(0.0));if let (Some(x), Some(y)) = (a.across(record, end)?, b.across(record, start)?) {- clash[k] = x.normal.dot(y.normal).abs() < (2.0 * PATCH_ANGLE_TOL_DEG).to_radians().cos();+ *slot = x.normal.dot(y.normal).abs() < (2.0 * PATCH_ANGLE_TOL_DEG).to_radians().cos();}}let mut across = |k: usize, ts: &[f64]| -> std::result::Result<Vec<Option<Across>>, String> {diff --git a/crates/kernel/src/history_tests.rs b/crates/kernel/src/history_tests.rsindex f8e59ee84c..41cc121d77 100644--- a/crates/kernel/src/history_tests.rs+++ b/crates/kernel/src/history_tests.rs@@ -66,7 +66,7 @@ fn substitute_a_body_made_from_a_sketch() {#[test]fn bodies_without_reported_history_have_none() {let a = box_solid(Vec3::ZERO, Vec3::new(4.0, 3.0, 1.0)).unwrap();- let bare = Body::new(a.deep_copy()).unwrap();+ let bare = Body::from_record(a.record().clone()).unwrap();assert!(bare.history().is_none());}diff --git a/crates/kernel/src/iges_out.rs b/crates/kernel/src/iges_out.rsindex cf5a5a1858..edef2b50e6 100644--- a/crates/kernel/src/iges_out.rs+++ b/crates/kernel/src/iges_out.rs@@ -311,9 +311,9 @@ fn shell(w: &mut W, b: &Brep, si: u32, paint: &HashMap<usize, [f32; 3]>) -> ResuNone => {let e = b.edges.get(u.edge as usize).ok_or_else(|| failed(format!("edge {}: no such edge", u.edge)))?;for v in e.vertices {- if !vidx.contains_key(&v) {+ if let std::collections::hash_map::Entry::Vacant(e) = vidx.entry(v) {let p = b.vertices.get(v as usize).ok_or_else(|| failed(format!("vertex {v}: no such vertex")))?.point;- vidx.insert(v, verts.len());+ e.insert(verts.len());verts.push(p);}}diff --git a/crates/kernel/src/issue_679_tests.rs b/crates/kernel/src/issue_679_tests.rsindex 08022ba5d0..81ea537578 100644--- a/crates/kernel/src/issue_679_tests.rs+++ b/crates/kernel/src/issue_679_tests.rs@@ -15,9 +15,8 @@ fn rect(x0: f64, y0: f64, x1: f64, y1: f64, z0: f64, z1: f64) -> Body {box_solid(Vec3::new(x0, y0, z0), Vec3::new(x1, y1, z1)).unwrap()}-fn fused(a: &Body, b: &Body) -> (Body, BooleanDiagnostics) {- let (r, d) = capture_boolean_diagnostics(|| boolean(a, b, BoolOp::Union));- (r.unwrap().unwrap(), d)+fn fused(a: &Body, b: &Body) -> Body {+ boolean(a, b, BoolOp::Union).unwrap().unwrap()}fn assert_one_solid(r: &Body, volume: f64, tol: f64, what: &str) {@@ -34,9 +33,8 @@ fn two_ls_up_and_down_fuse_into_one_solid() {let up = prism(&[[-10., -10.], [10., -10.], [10., 0.], [0., 0.], [0., 10.], [-10., 10.]], 0., 10.);let down = prism(&[[-10., 10.], [-10., 0.], [0., 0.], [0., -10.], [10., -10.], [10., 10.]], -10., 0.);for (a, b) in [(&up, &down), (&down, &up)] {- let (r, d) = fused(a, b);+ let r = fused(a, b);assert_one_solid(&r, 6000.0, 1e-6, "#679");- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "{d:?}");// Two tops, two bottoms, the two cells left open at z = 0, six sides.assert_eq!(r.face_count(), 12);}@@ -51,12 +49,12 @@ fn several_contact_regions_and_edge_contact() {let ups = boolean(&up, &up2, BoolOp::Union).unwrap().unwrap();// Down under both up cells, and under one more.let down = prism(&[[-10., -10.], [0., -10.], [0., 0.], [10., 0.], [10., 10.], [-10., 10.]], -5., 0.);- let (r, _) = fused(&ups, &down);+ let r = fused(&ups, &down);assert_one_solid(&r, 2.0 * 640.0 + 3.0 * 500.0, 1e-6, "two contacts");// Down under one up cell and beside the other: one face contact and one edge contact.// A plate under one block, flush with two of its sides and running on past the third.let down = rect(-10., -10., -2., 5., -5., 0.);- let (r, _) = fused(&up, &down);+ let r = fused(&up, &down);assert_one_solid(&r, 640.0 + 8.0 * 15.0 * 5.0, 1e-6, "contact and flush sides");}@@ -71,9 +69,8 @@ fn a_pad_half_past_the_edge_of_its_face_fuses() {let want = measure(&block).unwrap().volume + measure(&pad).unwrap().volume;assert!((want - (25.0 * 47.5 * 37.5 + std::f64::consts::PI * 25.0 * 2.5)).abs() < 0.1);for (a, b) in [(&block, &pad), (&pad, &block)] {- let (r, d) = fused(a, b);+ let r = fused(a, b);assert_one_solid(&r, want, 1e-6 * want, "#674");- assert!(d.events.is_empty(), "an exact join: {d:?}");let bounds = r.mesh(&crate::MeshTolerance::chord(0.01)).unwrap().bounds();assert!((bounds.min.y + 2.5).abs() < 1e-9 && (bounds.min.z + 5.0).abs() < 0.01, "{bounds:?}");}@@ -101,9 +98,8 @@ fn random_rectangles_either_side_of_a_plane_fuse_exactly() {let down = rect(x1, y1, x1 + w1, y1 + h1, -t1, 0.);let want = w0 * h0 * t0 + w1 * h1 * t1;let what = format!("case {case}: up {x0},{y0} {w0}x{h0}x{t0}, down {x1},{y1} {w1}x{h1}x{t1}");- let (r, d) = fused(&up, &down);+ let r = fused(&up, &down);assert_one_solid(&r, want, 1e-6 * want, &what);- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "{what}: {d:?}");done += 1;}assert_eq!(done, 30);diff --git a/crates/kernel/src/issue_851_tests.rs b/crates/kernel/src/issue_851_tests.rsindex 300c3a7b25..de12d5c7ad 100644--- a/crates/kernel/src/issue_851_tests.rs+++ b/crates/kernel/src/issue_851_tests.rs@@ -406,22 +406,6 @@ fn unfilleted_knife_edge_input_has_a_closed_display_plan() {}}-/// The construction does not depend on the faces being curved: at a box's corner it gives the-/// body the planar corner builder does (a sphere's octant where the three rounds meet).-#[test]-fn the_sphere_at_a_box_corner_is_the_planar_corner_builders() {- let b = box_solid(Vec3::ZERO, Vec3::new(30.0, 20.0, 10.0)).unwrap();- let picks = [Vec3::new(15.0, 0.0, 10.0), Vec3::new(0.0, 10.0, 10.0), Vec3::new(0.0, 0.0, 5.0)];- for r in [1.0, 2.5] {- let local = crate::blend_corner::fillet_radii(&b, &picks.iter().map(|p| (*p, r)).collect::<Vec<_>>()).unwrap();- let ball = crate::blend_vertex::fillet_ball_vertices(&b, &picks, r).unwrap_or_else(|e| panic!("r={r}: {e}"));- assert!(ball.validity().is_empty(), "r={r}: {:?}", ball.validity());- assert_eq!(ball.face_count(), local.face_count(), "r={r}");- let (a, c) = (planned_volume(&local), planned_volume(&ball));- assert!((a - c).abs() < 1e-3 * a, "r={r}: planar corner {a}, ball corner {c}");- }-}-/// Sizes at the ends of the range at a ball vertex: rounded or refused, never a panic.#[test]fn rounds_ending_in_a_sphere_of_any_size_never_panic() {diff --git a/crates/kernel/src/lib.rs b/crates/kernel/src/lib.rsindex 08579693fb..71d53757b7 100644--- a/crates/kernel/src/lib.rs+++ b/crates/kernel/src/lib.rs@@ -188,7 +188,8 @@ pub use native::{brep_record, decode_native_body, encode_native_body, native_prepub use offset::with_same_surface;pub use ops::{BoolOp, boolean, half_space, join_apart, place_matrix, split_by_plane, transform, transform_matrix, union_apart};pub use point_path::{- PathPiece, PointPath, SpaceBezier, curve_path, edge_path, face_section_along, iso_curves, project_onto_face, sketch_record_curve, sweep_point_path_with,+ PathPiece, PointPath, SpaceBezier, curve_path, edge_path, face_section_along, iso_curves, project_onto_face, sketch_record_curve,+ sweep_point_path_with,};pub use polybool::faceted_boolean;pub use polyhedron::{HalfSpace, convex_polyhedron, draft, offset_faces, shell};diff --git a/crates/kernel/src/matchsurf.rs b/crates/kernel/src/matchsurf.rsindex 623a1ef1fd..28bffd6199 100644--- a/crates/kernel/src/matchsurf.rs+++ b/crates/kernel/src/matchsurf.rs@@ -69,13 +69,13 @@ pub fn match_surface(body: &Body, faces: &[Vec3], target: &Body, target_pick: &[return Err(KernelError::Invalid("match rebuilds a surface body: this one is closed".into()));}let (record, target_record) = (body.record(), target.record());- let face = face_near(&record, faces, body.size() * 0.05 + 1e-6)?;- let original = Patch::of(&record, face)?;+ let face = face_near(record, faces, body.size() * 0.05 + 1e-6)?;+ let original = Patch::of(record, face)?;let chain = bridge::chain(target, target_pick)?;- let line = chain_polyline(&target_record, &chain)?;+ let line = chain_polyline(target_record, &chain)?;let near = nearest_side(&original, &line)?;let far = near.opposite();- let far_edges = side_edges(&record, face, &original, far, body.size() * 1e-6 + 1e-9)?;+ let far_edges = side_edges(record, face, &original, far, body.size() * 1e-6 + 1e-9)?;let (mid_near, mid_far) = (chain_mid(&line)?, original.at(far, 0.5)?);let leave = (mid_far - mid_near).normalized()@@ -111,7 +111,7 @@ pub fn match_surface(body: &Body, faces: &[Vec3], target: &Body, target_pick: &[for crown_near in CROWNS {for crown_far in CROWNS {let made = bridge::bridge(&near_frames, &far_frames, [order, Continuity::G1], [crown_near, crown_far])?;- let stray = deviation(&Patch::of(&made.record(), 0)?, &original)?;+ let stray = deviation(&Patch::of(made.record(), 0)?, &original)?;if best.as_ref().is_none_or(|(b, _)| stray < *b) {best = Some((stray, made));}@@ -124,11 +124,11 @@ pub fn match_surface(body: &Body, faces: &[Vec3], target: &Body, target_pick: &[// same way round, which is what a stitch, a thicken or a display of the result reads.let seam = chain_mid(&line)?;let made_record = made.record();- let turn = match (Patch::of(&made_record, 0)?.normal_near(seam), Patch::of(&target_record, target_face)?.normal_near(seam)) {+ let turn = match (Patch::of(made_record, 0)?.normal_near(seam), Patch::of(target_record, target_face)?.normal_near(seam)) {(Some((m, _)), Some((t, _))) => m.dot(t) < 0.0,_ => false,};- let kept = crate::surfaces::Parts::of(&made_record, &[(0, turn)])?.canonical()?;+ let kept = crate::surfaces::Parts::of(made_record, &[(0, turn)])?.canonical()?;let sheet = crate::surfaces::surface_body(&kept.brep)?;let history = History {operands: 2,@@ -147,12 +147,12 @@ pub fn seam_continuity(made: &Body, target: &Body, target_pick: &[Vec3]) -> Resutarget.require_brep("match")?;let (record, target_record) = (made.record(), target.record());let chain = bridge::chain(target, target_pick)?;- let poly = chain_polyline(&target_record, &chain)?;+ let poly = chain_polyline(target_record, &chain)?;// The face whose boundary runs along the chain: the one nearest it, so that a body that has// not been matched yet — where the seam is still some way off — can be measured too.let mid = chain_mid(&poly)?;let face = (0..record.faces.len())- .filter_map(|f| Patch::of(&record, f).ok().and_then(|p| p.normal_near(mid).map(|(_, d)| (d, p))))+ .filter_map(|f| Patch::of(record, f).ok().and_then(|p| p.normal_near(mid).map(|(_, d)| (d, p)))).min_by(|a, b| a.0.total_cmp(&b.0)).map(|(_, p)| p).ok_or_else(|| KernelError::Failed("match: the body has no faces".into()))?;@@ -165,7 +165,7 @@ pub fn seam_continuity(made: &Body, target: &Body, target_pick: &[Vec3]) -> Resulet Some(&(target_face, _)) = candidates.first() else {return Err(KernelError::Invalid("no face of the target holds the picked edges".into()));};- let target_patch = Patch::of(&target_record, target_face)?;+ let target_patch = Patch::of(target_record, target_face)?;let frames = bridge::frames(target, target_face, &chain, leave, STATIONS)?;let size = target.size();let (mut gap, mut deg, mut curv, mut bend) = (0.0f64, 0.0f64, 0.0f64, 0.0f64);@@ -472,7 +472,7 @@ fn support_faces(target: &Body, chain: &Chain, poly: &[Vec3], leave: Vec3) -> Reif !chain.iter().all(|(e, _)| bounds(f, *e)) {continue;}- let Some((n, d)) = Patch::of(&r, f).ok().and_then(|p| p.normal_near(mid)) else { continue };+ let Some((n, d)) = Patch::of(r, f).ok().and_then(|p| p.normal_near(mid)) else { continue };if d > tol {continue;}@@ -505,13 +505,13 @@ fn supply_order(target: &Body, candidates: &[(usize, f64)], chain: &Chain, leave}let r = target.record();let size = target.size();- let first_patch = Patch::of(&r, first)?;+ let first_patch = Patch::of(r, first)?;let primary: Vec<Frame> = bridge::frames(target, first, chain, leave, STATIONS)?;for &other in keep.iter().skip(1) {// A face that cannot be read along the whole chain says nothing here: the face the match// is built on is the one that must be able to supply it.let Ok(other_frames) = bridge::frames(target, other, chain, leave, STATIONS) else { continue };- let other_patch = Patch::of(&r, other)?;+ let other_patch = Patch::of(r, other)?;let mut worst_deg = 0.0f64;let mut worst = 0.0f64;let mut worst_change = 0.0f64;diff --git a/crates/kernel/src/matchsurf_tests.rs b/crates/kernel/src/matchsurf_tests.rsindex 8ce9bf418d..e7e9b0a1eb 100644--- a/crates/kernel/src/matchsurf_tests.rs+++ b/crates/kernel/src/matchsurf_tests.rs@@ -72,9 +72,9 @@ fn edge_at(body: &Body, p: Vec3) -> Chain {/// How far the rebuilt face's far boundary lies from the original one, in mm: the far row of the/// rebuilt surface sampled at its own stations, against the original boundary edge's own points.fn far_drift(made: &Body, sheet: &Body, far_mid: Vec3) -> f64 {- let patch = Patch::of(&made.record(), 0).unwrap();+ let patch = Patch::of(made.record(), 0).unwrap();let ((u0, u1), (_, v1)) = (patch.ranges[0], patch.ranges[1]);- let poly = chain_polyline(&sheet.record(), &edge_at(sheet, far_mid)).unwrap();+ let poly = chain_polyline(sheet.record(), &edge_at(sheet, far_mid)).unwrap();let mut worst = 0.0f64;for k in 0..=8 {let p = patch.surface.point([u0 + (u1 - u0) * k as f64 / 8.0, v1]).unwrap();@@ -87,7 +87,7 @@ fn far_drift(made: &Body, sheet: &Body, far_mid: Vec3) -> f64 {/// point, the unit tangent, the curvature vector and the change of that curvature, read off the/// finished surface (never from the construction).fn seam_at(body: &Body, t: f64) -> (Vec3, Vec3, Vec3, Vec3) {- Patch::of(&body.record(), 0).unwrap().seam_shape(Side::V0, t).unwrap()+ Patch::of(body.record(), 0).unwrap().seam_shape(Side::V0, t).unwrap()}/// The stations a seam is measured at, as fractions of its length.@@ -122,7 +122,7 @@ fn a_g2_match_meets_a_cylinder_with_its_own_curvature() {println!("g2: far boundary drift {drift:e} mm");assert!(drift < 1e-9, "the far boundary drifted {drift:e} mm");// The interior stays near the original: the crowning that leaves it closest.- let stray = deviation(&Patch::of(&made.record(), 0).unwrap(), &Patch::of(&sheet.record(), 0).unwrap()).unwrap();+ let stray = deviation(&Patch::of(made.record(), 0).unwrap(), &Patch::of(sheet.record(), 0).unwrap()).unwrap();println!("g2: interior stray {stray:.6} mm rms");// The seam moved 1 mm, so the face cannot be closer than that at the seam itself: over the// whole face the root mean square distance is well under half of it.diff --git a/crates/kernel/src/mesh_memo_tests.rs b/crates/kernel/src/mesh_memo_tests.rsindex d1c6247f1f..10ea9f3ab3 100644--- a/crates/kernel/src/mesh_memo_tests.rs+++ b/crates/kernel/src/mesh_memo_tests.rs@@ -35,8 +35,7 @@ fn regions_cut_from_a_body_keeping_its_meshes_are_unchanged() {);}let memo = kept.meshes.as_ref().unwrap();- assert_eq!(memo.shells.lock().unwrap().len(), 1, "one tolerance, one meshing");- assert!(!memo.made.lock().unwrap().is_empty());+ assert_eq!(memo.made.lock().unwrap().len(), 1, "one tolerance, one meshing");// A mesh from the memo is the mesh made afresh.let (a, b) = (kept.mesh(&crate::MeshTolerance::chord(0.05)).unwrap(), plate.mesh(&crate::MeshTolerance::chord(0.05)).unwrap());let (a2, _) = (kept.mesh(&crate::MeshTolerance::chord(0.05)).unwrap(), ());@@ -62,5 +61,4 @@ fn a_copy_with_another_solid_makes_its_own_meshes() {let _ = kept.mesh(&crate::MeshTolerance::chord(0.5)).unwrap();let m = swapped.mesh(&crate::MeshTolerance::chord(0.5)).unwrap();assert_eq!(m.triangles.len(), other.mesh(&crate::MeshTolerance::chord(0.5)).unwrap().triangles.len());- assert!(swapped.boolean_meshes(0.01).is_none());}diff --git a/crates/kernel/src/outline_tests.rs b/crates/kernel/src/outline_tests.rsindex 24ccd5a418..017dd54eb3 100644--- a/crates/kernel/src/outline_tests.rs+++ b/crates/kernel/src/outline_tests.rs@@ -40,7 +40,10 @@ fn a_lip_swept_on_a_round_rim_joins_it() {#[test]fn a_swept_lips_foot_is_a_plane() {let l = lip(0.0);- let foot = crate::coplanar::faces_in(&l, -Vec3::Z, -10.0, 1e-6);+ // The faces lying in the plane z = 10 facing down: planar, normal -z, through z = 10.+ let foot: Vec<usize> = (0..l.face_count())+ .filter(|&i| l.planar_face(i).is_some_and(|p| p.normal().dot(-Vec3::Z) > 1.0 - 1e-9 && (p.origin.z - 10.0).abs() < 1e-6))+ .collect();let m = l.mesh(&crate::MeshTolerance::chord(1e-5)).unwrap();let area: f64 = m.trianglesdiff --git a/crates/kernel/src/pinch_tests.rs b/crates/kernel/src/pinch_tests.rsindex 7a567dbb3c..18222c0e31 100644--- a/crates/kernel/src/pinch_tests.rs+++ b/crates/kernel/src/pinch_tests.rs@@ -41,10 +41,9 @@ fn disc_tangent_to_a_side_and_overhanging_joins() {let top = prism(disc(18.5, cy, r), 10., 20.);let want = 8990.0 + std::f64::consts::PI * r * r * 10.0;for (a, b) in [(&block, &top), (&top, &block)] {- let (res, d) = capture_boolean_diagnostics(|| boolean(a, b, BoolOp::Union));+ let res = boolean(a, b, BoolOp::Union);let res = res.unwrap().unwrap();assert_solid(&res, want, 1e-5, 1, &format!("disc at {cy}, r {r}"));- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "{d:?}");}}}@@ -129,10 +128,9 @@ fn hole_tangent_inside_a_stepped_boss_cuts_exactly() {for (z0, z1, want) in [(-1., 20., 2000. + 1000. - 25. * 15.), (6., 20., 2000. + 1000. - 25. * 9.), (-1., 4., 2000. + 1000. - 25. * 4.)] {let what = format!("hole z {z0}…{z1}, turned {turn}, flip {flip}");let hole = prism(circle(15., 5.), z0, z1);- let (res, d) = capture_boolean_diagnostics(|| boolean(&stepped, &hole, BoolOp::Cut));+ let res = boolean(&stepped, &hole, BoolOp::Cut);let res = res.unwrap_or_else(|e| panic!("{what}: {e}")).unwrap();assert_solid(&res, PI * want, 1e-5, 1, &what);- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "{what}: {d:?}");}}}@@ -146,10 +144,9 @@ fn hole_tangent_to_a_flat_side_of_a_stepped_block_cuts_exactly() {let boss = prism(rect(10., 10., 40., 30.), 5., 15.);let stepped = boolean(&block, &boss, BoolOp::Union).unwrap().unwrap();let hole = prism(disc(35., 20., 5.), -1., 20.);- let (res, d) = capture_boolean_diagnostics(|| boolean(&stepped, &hole, BoolOp::Cut));+ let res = boolean(&stepped, &hole, BoolOp::Cut);let res = res.unwrap().unwrap();assert_solid(&res, 8000. + 6000. - std::f64::consts::PI * 25. * 15., 1e-5, 1, "hole tangent to a flat side");- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "{d:?}");}/// A stepped block cut by a disc tangent to its back side from inside leaves two posts meeting@@ -163,7 +160,7 @@ fn stepped_cuts_touching_along_a_line_keep_their_pieces() {let back = prism(rect(0., 20., 25., 29.), 10., 20.);let stepped = boolean(&block, &back, BoolOp::Union).unwrap().unwrap();let tool = prism(disc(18.5, 4., 25.), -1., 21.);- let (res, d) = capture_boolean_diagnostics(|| boolean(&stepped, &tool, BoolOp::Cut));+ let res = boolean(&stepped, &tool, BoolOp::Cut);let res = res.unwrap().unwrap();let n = 400_000;let dx = 31.0 / n as f64;@@ -176,18 +173,14 @@ fn stepped_cuts_touching_along_a_line_keep_their_pieces() {.sum();let v = res.mesh(&crate::MeshTolerance::chord(1e-4)).unwrap().measure().volume;assert!((v - volume).abs() <= volume * 1e-4, "posts: volume {v} vs {volume}");- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "{d:?}");- let sewn = crate::prism::prism_boolean(&stepped, &tool, BoolOp::Cut);- assert!(!matches!(&sewn, Some(Ok(Some(b))) if b.shell_count() < 2), "posts sewn into one shell");let block = prism(rect(0., 0., 40., 40.), 0., 5.);let boss = prism(rect(10., 10., 40., 30.), 5., 15.);let stepped = boolean(&block, &boss, BoolOp::Union).unwrap().unwrap();let diamond = prism(poly(&[[30., 20.], [35., 15.], [40., 20.], [35., 25.]]), -1., 20.);- let (res, d) = capture_boolean_diagnostics(|| boolean(&stepped, &diamond, BoolOp::Cut));+ let res = boolean(&stepped, &diamond, BoolOp::Cut);let res = res.unwrap().unwrap();assert_solid(&res, 8000. + 6000. - 50. * 15., 1e-9, 1, "diamond hole with a corner on a stepped side");- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "{d:?}");}/// A row of holes each touching the next (a 5 mm pattern of Ø5 holes) through a stepped plate:@@ -199,9 +192,8 @@ fn row_of_touching_holes_through_a_stepped_plate_cuts_exactly() {let mut body = boolean(&plate, ¬ch, BoolOp::Cut).unwrap().unwrap();for x in [15.45, 20.45, 25.45] {let hole = prism(disc(x, 15.7, 2.5), -5., 7.5);- let (res, d) = capture_boolean_diagnostics(|| boolean(&body, &hole, BoolOp::Cut));+ let res = boolean(&body, &hole, BoolOp::Cut);body = res.unwrap().unwrap();- assert!(!d.events.iter().any(|e| e.strategy == BooleanStrategy::ToolNudge), "hole at {x}: {d:?}");}assert_solid(&body, 7312.5 - 3.0 * std::f64::consts::PI * 6.25 * 7.5, 1e-5, 1, "touching holes");}diff --git a/crates/kernel/src/prism_curve.rs b/crates/kernel/src/prism_curve.rsindex 62c5c58212..4fd305d5b9 100644--- a/crates/kernel/src/prism_curve.rs+++ b/crates/kernel/src/prism_curve.rs@@ -35,7 +35,7 @@ impl<'a> Run<'a> {}/// The parameters it runs from and to.- fn from_to(&self) -> (f64, f64) {+ fn ends_along(&self) -> (f64, f64) {let [t0, t1] = self.interval;if self.forward { (t0, t1) } else { (t1, t0) }}@@ -123,7 +123,7 @@ fn spans_of(run: &Run, work: &mut usize) -> Option<Vec<Vec<HPoint>>> {}Curve::Ellipse { frame, radii } => {let (x, y) = (v3(frame.x_axis), v3(frame.y_axis));- let (a, b) = run.from_to();+ let (a, b) = run.ends_along();return ellipse_spans(v3(frame.origin), x, y, *radii, a, b, work);}_ => return None,@@ -315,7 +315,7 @@ fn read(run: &Run, plane: &Plane, tol: f64, work: &mut usize, each_span: bool) -if matches!(run.curve, Curve::SurfaceIntersection { .. }) {return None;}- let (ts, te) = run.from_to();+ let (ts, te) = run.ends_along();if !ts.is_finite() || !te.is_finite() || run.interval[1] <= run.interval[0] {return None;}diff --git a/crates/kernel/src/seam_faces_tests.rs b/crates/kernel/src/seam_faces_tests.rsnew file mode 100644index 0000000000..f8c56a8968--- /dev/null+++ b/crates/kernel/src/seam_faces_tests.rs@@ -0,0 +1,76 @@+//! Round faces read from STEP: a whole turn bounded by one wire that runs along its seam twice.+//! A boolean whose intersection loop lies wholly inside such a face is exact.+use crate::*;+use solidcraft_geom::{Loop2, Plane, Region2, Vec2, Vec3};+use std::f64::consts::PI;++const R: f64 = 4.5;++fn volume(b: &Body) -> f64 {+ measure(b).unwrap().volume+}++fn rel(a: f64, b: f64) -> f64 {+ (a - b).abs() / b.abs().max(1e-12)+}++/// `body` written to STEP and read back: its round faces come back whole, as other systems+/// write them.+fn through_step(body: &Body) -> Body {+ step_import(&step_export(&[body], "t").unwrap()).unwrap().bodies.into_iter().next().unwrap().body+}++/// A pin of radius `R` along X, 40 long, centred on the origin.+fn pin() -> Body {+ cylinder(Vec3::new(-20.0, 0.0, 0.0), Vec3::X, R, 40.0).unwrap()+}++/// A block pressed into the top of the pin's side: 10 long, 6 wide, from 2 above the axis up.+fn block() -> Body {+ box_solid(Vec3::new(-5.0, -3.0, 2.0), Vec3::new(5.0, 3.0, 9.0)).unwrap()+}++/// The part of the pin inside [`block`]: the circle's segment above 2 and within 3 of the+/// middle, 10 long.+fn pressed_volume() -> f64 {+ let segment = 3.0 * (R * R - 9.0).sqrt() + R * R * (3.0 / R).asin() - 6.0 * 2.0;+ 10.0 * segment+}++/// The boolean, which must succeed (SMLib's, exact: there is no other).+fn exact(a: &Body, b: &Body, op: BoolOp) -> Option<Body> {+ boolean(a, b, op).unwrap()+}++#[test]+fn a_block_pressed_into_a_read_pins_side_is_intersected_and_cut_exactly() {+ let (read, block) = (through_step(&pin()), block());+ let want = pressed_volume();+ let shared = exact(&read, &block, BoolOp::Intersect).unwrap();+ assert!(rel(volume(&shared), want) < 1e-3, "{} {want}", volume(&shared));+ let dented = exact(&read, &block, BoolOp::Cut).unwrap();+ assert!(rel(volume(&dented), PI * R * R * 40.0 - want) < 1e-3, "{}", volume(&dented));+ // The operands' faces carry over: the dented pin's round face is still the pin's.+ assert!(dented.history().is_some());+}++#[test]+fn a_ball_pressed_into_a_read_pins_side_matches_the_built_pin() {+ let ball = sphere(Vec3::new(3.0, 1.0, 5.5), 3.0).unwrap();+ let built = volume(&boolean(&pin(), &ball, BoolOp::Intersect).unwrap().unwrap());+ let read = volume(&exact(&through_step(&pin()), &ball, BoolOp::Intersect).unwrap());+ assert!(rel(read, built) < 1e-3, "{read} {built}");+}++/// A cone's side read from STEP is one face along its seam as well.+#[test]+fn a_block_pressed_into_a_read_cones_side_matches_the_built_cone() {+ let outline =+ Region2 { outer: Loop2::polygon(&[Vec2::new(0.0, 0.0), Vec2::new(8.0, 0.0), Vec2::new(5.0, 20.0), Vec2::new(0.0, 20.0)]), holes: vec![] };+ let cone = revolve(&Plane::YZ, &[outline], Vec2::ZERO, Vec2::Y, 2.0 * PI).unwrap().pop().unwrap();+ let read = through_step(&cone);+ let block = box_solid(Vec3::new(-2.0, 4.0, 6.0), Vec3::new(2.0, 12.0, 12.0)).unwrap();+ let built = volume(&boolean(&cone, &block, BoolOp::Intersect).unwrap().unwrap());+ let read = volume(&exact(&read, &block, BoolOp::Intersect).unwrap());+ assert!(rel(read, built) < 1e-3, "{read} {built}");+}diff --git a/crates/kernel/src/surface_untrim.rs b/crates/kernel/src/surface_untrim.rsindex b25eaf6d0c..cacc94e779 100644--- a/crates/kernel/src/surface_untrim.rs+++ b/crates/kernel/src/surface_untrim.rs@@ -91,7 +91,7 @@ pub fn untrim(body: &Body, face: usize, holes: UntrimHoles, outer: bool, in_plac(Some(ob), Some(or)) => r.history().map_err(|e| failed("history", e))?.history(&[ob], &or).ok().map(|mut h| {// The untrimmed face is the face it was, bounded differently.for p in &mut h.faces {- if p.origins.iter().any(|o| *o == FaceOrigin::Face { operand: 0, face }) {+ if p.origins.contains(&FaceOrigin::Face { operand: 0, face }) {p.change = Change::Modified;}}diff --git a/crates/kernel/src/tess/surface.rs b/crates/kernel/src/tess/surface.rsindex ad2e5035e5..b2d31f2532 100644--- a/crates/kernel/src/tess/surface.rs+++ b/crates/kernel/src/tess/surface.rs@@ -34,7 +34,7 @@ pub(crate) enum Params {impl Params {/// The evaluator's parameters of the record's `uv`.- pub(crate) fn to_eval(&self, uv: [f64; 2]) -> [f64; 2] {+ pub(crate) fn to_eval(self, uv: [f64; 2]) -> [f64; 2] {let [u, v] = uv;match self {Params::Same => uv,diff --git a/crates/kernel/src/tests.rs b/crates/kernel/src/tests.rsindex af7c9fa828..308dd7d310 100644--- a/crates/kernel/src/tests.rs+++ b/crates/kernel/src/tests.rs@@ -2326,9 +2326,6 @@ fn orientation_mesh_reuses_missing_face_check_at_matching_tolerance() {present[face as usize] = true;}assert_eq!(body.unmeshed_faces(), present.iter().filter(|p| !**p).count());- if scale == 1.0 {- assert_eq!(body.coarse_missing, Some((tol, 0)));- }}}@@ -2473,7 +2470,7 @@ fn loft_joined_onto_a_box_top_is_one_shell() {// Overhanging the box edge (x = 20) the disc is not inside the top face: whatever the join// does, it never returns touching shells as one body.if let Ok(Some(r)) = boolean(&bx, &loft_at(17.0), BoolOp::Union) {- assert!(r.shell_count() == 1 || r.union_lumps().is_ok(), "{} touching shells", r.shell_count());+ assert!(r.shell_count() == 1 || r.lumps().is_ok(), "{} touching shells", r.shell_count());}}diff --git a/crates/kernel/src/thread_display_tests.rs b/crates/kernel/src/thread_display_tests.rsindex 390bb2d81d..40a845d67a 100644--- a/crates/kernel/src/thread_display_tests.rs+++ b/crates/kernel/src/thread_display_tests.rs@@ -200,7 +200,8 @@ fn threads() -> Vec<(String, Body, f64, f64, f64)> {fn thread_display_mesh_stays_on_its_surfaces() {for (name, b, d, p, turns) in threads() {let tol = tol(&b);- let plan = b.mesh_plan(&crate::MeshTolerance { chord: tol, angle: Some(DISPLAY_ANGLE) }).unwrap_or_else(|e| panic!("{name}: no display plan: {e}"));+ let plan =+ b.mesh_plan(&crate::MeshTolerance { chord: tol, angle: Some(DISPLAY_ANGLE) }).unwrap_or_else(|e| panic!("{name}: no display plan: {e}"));let mesh = plan.evaluate();let q = quality(&plan, &mesh);assert!(q.worst_sag <= 1.5 * tol, "{name}: a triangle lies {} mm off its surface (tolerance {tol})", q.worst_sag);@@ -238,7 +239,9 @@ fn thread_display_mesh_stays_on_its_surfaces() {#[test]fn thread_display_mesh_has_no_degenerate_or_flipped_triangles() {for (name, b, ..) in threads() {- let plan = b.mesh_plan(&crate::MeshTolerance { chord: tol(&b), angle: Some(DISPLAY_ANGLE) }).unwrap_or_else(|e| panic!("{name}: no display plan: {e}"));+ let plan = b+ .mesh_plan(&crate::MeshTolerance { chord: tol(&b), angle: Some(DISPLAY_ANGLE) })+ .unwrap_or_else(|e| panic!("{name}: no display plan: {e}"));let mesh = plan.evaluate();let q = quality(&plan, &mesh);assert!(q.tris > 1000, "{name}: {} triangles", q.tris);diff --git a/crates/kernel/tests/chamfer_curved_holder.rs b/crates/kernel/tests/chamfer_curved_holder.rsindex 1fc295d4af..7006535f0d 100644--- a/crates/kernel/tests/chamfer_curved_holder.rs+++ b/crates/kernel/tests/chamfer_curved_holder.rs@@ -59,7 +59,7 @@ fn chamfer_the_top_lip_at_a_tangent_wall_junction() {assert_eq!(made.crossed_face_loops().unwrap(), 0);let history = made.history().expect("the chamfer retains exact face provenance");assert!(history.faces.iter().any(|f| f.origins.iter().any(|o| matches!(o, solidcraft_kernel::history::FaceOrigin::Edge { operand: 0, .. }))));- let mesh = |body: &Body| body.mesh(&crate::MeshTolerance::chord(0.0005)).unwrap();+ let mesh = |body: &Body| body.mesh(&solidcraft_kernel::MeshTolerance::chord(0.0005)).unwrap();let before = mesh(&body).measure().volume;let after = mesh(&made);let removed = before - after.measure().volume;@@ -114,7 +114,7 @@ fn one_chamfer_pick_follows_the_tangent_chain_at_any_part_size() {assert!(made.validity().is_empty(), "{:?}", made.validity());// Two straight edges (c^2/2 * 40 each) and both end arcs (Pappus, c^2/2 * 2 pi (R - c/3)).let expected = 40.0 + 0.5 * 2.0 * PI * (5.0 - 1.0 / 3.0);- let volume = |b: &Body| b.mesh(&crate::MeshTolerance::chord(1e-4)).unwrap().measure().volume;+ let volume = |b: &Body| b.mesh(&solidcraft_kernel::MeshTolerance::chord(1e-4)).unwrap().measure().volume;let removed = volume(&body) - volume(&made);assert!((removed - expected).abs() < 0.3, "plate {plate}: removed {removed}, expected {expected}");assert_eq!(made.face_count(), body.face_count() + 4, "plate {plate}: one chamfer face per rim edge");diff --git a/crates/kernel/tests/revolve_on_axis.rs b/crates/kernel/tests/revolve_on_axis.rsindex ff7e8833ef..100aede34e 100644--- a/crates/kernel/tests/revolve_on_axis.rs+++ b/crates/kernel/tests/revolve_on_axis.rs@@ -75,7 +75,7 @@ fn a_half_slot_revolved_about_a_centreline_in_a_face_cuts_it() {for turn in [PI, -PI, TAU] {let tool = revolve(&plane, std::slice::from_ref(&r), Vec2::ZERO, Vec2::new(1.0, 0.0), turn).unwrap().pop().unwrap();// A half turn into the plate, or a full one, cuts a groove; a half turn out of it misses.- let into = turn.abs() > PI || tool.mesh(&crate::MeshTolerance::chord(0.01)).unwrap().bounds().min.z < 9.0;+ let into = turn.abs() > PI || tool.mesh(&solidcraft_kernel::MeshTolerance::chord(0.01)).unwrap().bounds().min.z < 9.0;let cut = boolean(&plate, &tool, BoolOp::Cut).unwrap().unwrap();assert!(cut.validity().is_empty(), "flip {flip}, {turn}: {:?}", cut.validity());let removed = whole - measure(&cut).unwrap().volume;