SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Wave 343/509: Tests: a face picked by point is found on a block of 256 drilled holes, as on #6720's thread (and 3 more)
jyviko74bca47120c7
diff --git a/crates/engine/src/cmd/joints_cam_tests.rs b/crates/engine/src/cmd/joints_cam_tests.rsindex 3ed46a7466..780426cd38 100644--- a/crates/engine/src/cmd/joints_cam_tests.rs+++ b/crates/engine/src/cmd/joints_cam_tests.rs@@ -158,7 +158,9 @@ fn picked_edges_give_the_sketch_s_table() {s.doc.assembly.links.first().map(|l| (l.lift.clone(), l.offset)).unwrap_or_default()};let (sketch, a) = table(json!({"sketch": "CamSketch"}));- let (edges, b) = table(json!({"edges": [[E + R, 0, 5]]}));+ // Picked on the rim a quarter turn from where the extruded circle's seam meets it: a pick on+ // that vertex could be either edge.+ let (edges, b) = table(json!({"edges": [[E, R, 5]]}));assert_eq!((sketch.len(), edges.len()), (360, 360));assert!(sketch.iter().zip(&edges).all(|(x, y)| close(*x, *y, 1e-3)) && close(a, b, 1e-3));// A second disc of the cam's component touching it in the same plane is not part of its loop.@@ -171,7 +173,7 @@ fn picked_edges_give_the_sketch_s_table() {assert!(touching.len() == 360 && touching.iter().zip(&sketch).all(|(x, y)| close(*x, *y, 1e-3)), "{touching:?}");let mut s = cam_on_base();tappet(&mut s, 0.0, E + R);- run(&mut s, "joint.cam", json!({"a": "Cam", "b": "Tappet", "profile": {"edges": [[E + R, 0, 5]]}}));+ run(&mut s, "joint.cam", json!({"a": "Cam", "b": "Tappet", "profile": {"edges": [[E, R, 5]]}}));assert!(matches!(s.doc.assembly.links.first().and_then(|l| l.coupling.clone()),Some(Coupling::Cam(c)) if matches!(&c.profile, CamProfile::Edges { names, .. } if names.first().is_some_and(|n| !n.is_empty()))diff --git a/crates/engine/src/cmd/script_tests.rs b/crates/engine/src/cmd/script_tests.rsindex 1528d61743..a091f1dc4b 100644--- a/crates/engine/src/cmd/script_tests.rs+++ b/crates/engine/src/cmd/script_tests.rs@@ -103,12 +103,13 @@ fn ids_names_suppression_marker_and_failures_survive() {run(&mut s, "parameters.add", json!({"name": "twice_depth", "expression": format!("{depth} * 2")}));run(&mut s, "parameters.comment", json!({"name": depth, "comment": "plate depth"}));run(&mut s, "parameters.favorite", json!({"name": depth}));- // A fillet that a parameter change makes too big fails, and the design keeps it.+ // A fillet that a parameter change makes impossible (a radius below zero) fails, and the+ // design keeps it. (A convex round wider than its faces is built now, by subtraction.)run(&mut s, "parameters.add", json!({"name": "r", "expression": "1 mm"}));// Pick only the plate's edge, clear of the overlapping box's edge.run(&mut s, "solid.fillet", json!({"edges": [[20, 0, 10]], "radius": "r"}));let fillet = s.doc.features.last().unwrap().id;- run(&mut s, "parameters.change", json!({"name": "r", "expression": "50 mm"}));+ run(&mut s, "parameters.change", json!({"name": "r", "expression": "-1 mm"}));assert!(s.model.result(fillet).and_then(|r| r.error.clone()).is_some(), "the fillet fails");run(&mut s, "timeline.rollback", json!({"position": 3}));let mut t = replay(&script(&mut s));diff --git a/crates/engine/src/cmd/sketch_face_tests.rs b/crates/engine/src/cmd/sketch_face_tests.rsindex c5934a4b92..6669201cf7 100644--- a/crates/engine/src/cmd/sketch_face_tests.rs+++ b/crates/engine/src/cmd/sketch_face_tests.rs@@ -764,17 +764,29 @@ fn a_sketch_on_a_face_meshes_its_body_once() {assert!(s.model.state().body("Base").unwrap().cached_mesh().is_some(), "the sketch's projection meshed a copy of the body");}/// Issue 6720: a face picked by its point alone was refused on a body with many faces. The-/// search charged the whole mesh once per face, and the 5 000 facets a modelled thread leaves-/// put a plain block past the limit. The search reads each face's own triangles now.+/// search charged the whole mesh once per face, and the 5 000 facets a modelled thread left put a+/// plain block past the limit. The search reads each face's own triangles now. A modelled thread+/// is a few exact helical faces on SMLib, so the many faces are a block drilled with 256 holes:+/// the old charge (every face times the whole mesh) is past the 2 000 000 budget, the new one+/// (the mesh once, plus a test per face) well inside it.#[test]-fn a_face_picked_by_point_on_a_block_with_a_modelled_thread_is_found() {+fn a_face_picked_by_point_on_a_block_with_many_faces_is_found() {let mut s = Session::default();run(&mut s, "solid.box", json!({"corner":[-20,-20,0],"length":40,"width":40,"height":20,"body_name":"Block"}));- run(&mut s, "solid.cylinder", json!({"base":[0,0,-1],"radius":3.4,"height":22,"body_name":"Bore"}));- run(&mut s, "solid.combine", json!({"target":"Block","tools":["Bore"],"operation":"cut"}));- run(&mut s, "solid.thread", json!({"face":[3.4,0,10],"designation":"M8","modeled":true}));- assert!(s.model.state().body("Block").unwrap().body.face_count() > 1000);- run(&mut s, "sketch.create", json!({"plane":{"face":[15,15,20],"fixed":true}}));+ run(&mut s, "sketch.create", json!({"plane":"XY","offset":20,"name":"Drills"}));+ for i in 0..16 {+ for j in 0..16 {+ run(&mut s, "sketch.point", json!({"point":[-15.0 + 2.0 * f64::from(i), -15.0 + 2.0 * f64::from(j)]}));+ }+ }+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.hole", json!({"sketch":"Drills","diameter":0.8}));+ let body = s.model.state().body("Block").unwrap().body.clone();+ // The search's own mesh (sketch_face: the tolerance it meshes the body at).+ let mesh = body.mesh(&solidcraft_kernel::MeshTolerance::chord((body.size() * 1e-4).max(1e-5))).unwrap();+ let (faces, triangles) = (body.face_count(), mesh.triangles.len());+ assert!(faces > 256 && faces * triangles > 2_000_000 && faces + triangles < 2_000_000, "{faces} faces, {triangles} triangles");+ run(&mut s, "sketch.create", json!({"plane":{"face":[19,19,20],"fixed":true}}));let plane = run(&mut s, "sketch.inspect", json!({}))["plane"].clone();assert!((plane["origin"][2].as_f64().unwrap() - 20.0).abs() < 1e-6, "{plane}");}diff --git a/crates/engine/src/cmd/sketch_project_tests.rs b/crates/engine/src/cmd/sketch_project_tests.rsindex 000d367591..7a49f87c1e 100644--- a/crates/engine/src/cmd/sketch_project_tests.rs+++ b/crates/engine/src/cmd/sketch_project_tests.rs@@ -871,11 +871,25 @@ fn intersect_keeps_its_exact_cuts() {let c = intersect_curves(&steps, plane).unwrap();assert!(c.len() == 1 && c[0]["type"] == "circle" && (c[0]["radius"].as_f64().unwrap() - radius).abs() < 1e-4, "{c:?}");}+ // The tilted cylinder's cut is an ellipse the section leaves as the mesh's segments, as many+ // as the tessellation crosses (21 on truck's mesh, 20 on SMLib's): each end on the cylinder+ // within the section's own reach of the surface, the display tolerance (a thousandth of the+ // mesh's size, doc::project::fit_segments), which the old pin of one end to 1e-4 assumed of+ // one mesh.let tilted = [("solid.cylinder", json!({"base": [0, 0, 0], "radius": 5, "height": 40, "axis": [1, 0, 1]}))];- let ends = line_ends(&intersect_curves(&tilted, json!({"plane": "XY", "offset": 10})).unwrap());- assert_eq!(ends.len(), 21);- let first = [2.941, -0.2891, 3.3932, -1.7819];- assert!(ends[0].iter().zip(first).all(|(a, b)| (a - b).abs() < 1e-4), "{:?}", ends[0]);+ let curves = intersect_curves(&tilted, json!({"plane": "XY", "offset": 10})).unwrap();+ let ends = line_ends(&curves);+ assert!(ends.len() == curves.len() && ends.len() >= 16, "{curves:?}");+ let axis = solidcraft_geom::Vec3::new(1.0, 0.0, 1.0).normalized().unwrap();+ // The cylinder's box: its axis 40 along (1, 0, 1)/√2 and its ends' discs of radius 5 span+ // (40 + 2·5)/√2 in x and z and 10 in y.+ let span = 50.0 * std::f64::consts::FRAC_1_SQRT_2;+ let reach = 1e-3 * (2.0 * span * span + 100.0).sqrt();+ for e in &ends {+ for p in [solidcraft_geom::Vec3::new(e[0], e[1], 10.0), solidcraft_geom::Vec3::new(e[2], e[3], 10.0)] {+ assert!(((p - axis * p.dot(axis)).len() - 5.0).abs() < reach, "{p:?}");+ }+ }}/// A plane crossing a curved face's rim cuts it on the surface, not on the mesh's chord: a