Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Wave 342/509: UI tests: SMLib's cylinder has one wall and one edge per rim; split rims come from two arcs (and 3 more)

jyvikoc3670a705416
diff --git a/crates/gpu/tests/capture.rs b/crates/gpu/tests/capture.rs
index 4c618b2fc7..309c02e9d8 100644
--- a/crates/gpu/tests/capture.rs
+++ b/crates/gpu/tests/capture.rs
@@ -160,6 +160,8 @@ fn pictures_show_the_section_and_its_cap() {
let mut cam = view::home_camera(&s).unwrap();
cam.fov = fov;
let mut sc = view::scene(&s, &cam).unwrap();
+ // The cap in the cap colour: a part's hatch colour is the one its name picks (#8529).
+ sc.part_hatch = None;
// A marker inside the body, behind the cut face.
let red = Rgb(255, 0, 0);
sc.lines.push(SceneLine {
diff --git a/crates/kernel/tests/chamfer_curved_holder.rs b/crates/kernel/tests/chamfer_curved_holder.rs
index f45ab14a60..96196bb205 100644
--- a/crates/kernel/tests/chamfer_curved_holder.rs
+++ b/crates/kernel/tests/chamfer_curved_holder.rs
@@ -4,7 +4,7 @@
//! against the round wall instead of extending that short seam outside the solid.
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
-use solidcraft_kernel::{Body, BoolOp, boolean, chamfer, cylinder, extrude};
+use solidcraft_kernel::{Body, BoolOp, boolean, chamfer, cylinder, extrude, tangent_chain};
use std::f64::consts::PI;
fn holder() -> Body {
@@ -54,7 +54,9 @@ fn expected_removed(distance: f64) -> f64 {
#[test]
fn chamfer_the_top_lip_at_a_tangent_wall_junction() {
let body = holder();
- let made = chamfer(&body, &[Vec3::new(10.0, 10.0, 60.0)], 2.0).unwrap();
+ // The pick's tangent chain, as a chamfer feature selects it (the kernel blends the edges it
+ // is given).
+ let made = chamfer(&body, &tangent_chain(&body, &[Vec3::new(10.0, 10.0, 60.0)]).unwrap(), 2.0).unwrap();
assert!(made.validity().is_empty(), "{:?}", made.validity());
assert_eq!(made.crossed_face_loops().unwrap(), 0);
let history = made.history().expect("the chamfer retains exact face provenance");
@@ -115,7 +117,7 @@ fn plate_with_stadium(plate: f64) -> Body {
fn one_chamfer_pick_follows_the_tangent_chain_at_any_part_size() {
for plate in [140.0, 145.0, 250.0] {
let body = plate_with_stadium(plate);
- let made = chamfer(&body, &[Vec3::new(0.0, 5.0, 20.0)], 1.0).unwrap();
+ let made = chamfer(&body, &tangent_chain(&body, &[Vec3::new(0.0, 5.0, 20.0)]).unwrap(), 1.0).unwrap();
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);
diff --git a/crates/smlib/src/export/tests.rs b/crates/smlib/src/export/tests.rs
index 523d3a255f..daff933d4e 100644
--- a/crates/smlib/src/export/tests.rs
+++ b/crates/smlib/src/export/tests.rs
@@ -82,10 +82,19 @@ mod native_tests {
fn edges_are_on_smlibs_curves() {
let cyl = Brep::make_cylinder([0.0; 3], 5.0, 10.0).unwrap().to_native().unwrap();
let side = cyl.faces.iter().find(|f| matches!(f.surface, b::Surface::Cylinder { .. })).unwrap();
- assert!((side.domain[0][1] - side.domain[0][0] - TAU).abs() < 1e-12);
- assert_eq!(side.domain[1], [0.0, 10.0]);
+ // The side is on SMLib's NURBS form of the cylinder (its domain is the form's): the whole
+ // turn, so its domain's two u ends meet, from the base to the top.
+ let form = b::eval::SurfaceEval::new(side.parameters()).unwrap();
+ let [[u0, u1], [v0, v1]] = side.domain;
+ for v in [v0, v1] {
+ let (a, z) = (form.point([u0, v]).unwrap(), form.point([u1, v]).unwrap());
+ assert!(a.dist(z) < 1e-9, "{a:?} {z:?}");
+ }
+ let heights = [form.point([u0, v0]).unwrap().z, form.point([u0, v1]).unwrap().z];
+ assert!(heights.iter().any(|h| h.abs() < 1e-9) && heights.iter().any(|h| (h - 10.0).abs() < 1e-9), "{heights:?}");
for e in &cyl.edges {
- let eval = b::eval::CurveEval::new(&e.curve).unwrap();
+ // Evaluated on the curve its interval is on (a circle's NURBS form).
+ let eval = b::eval::CurveEval::new(e.parameters()).unwrap();
let [a, z] = e.interval;
// Ends on the edge's vertices.
for (t, v) in [(a, e.vertices[0]), (z, e.vertices[1])] {
@@ -94,6 +103,7 @@ mod native_tests {
assert!((p - Vec3::new(q[0], q[1], q[2])).len() < 1e-9, "{:?} at {t}", e.curve);
}
if let b::Curve::Circle { radius, .. } = e.curve {
+ let [a, z] = e.curve_interval().unwrap();
assert!((radius - 5.0).abs() < 1e-12 && (z - a - TAU).abs() < 1e-9);
}
}
@@ -126,7 +136,8 @@ mod native_tests {
p[0].abs() < 1e-9 && (p[1] - 14.5).abs() < 1e-9
})
};
- let middle = |e: &b::Edge| b::eval::CurveEval::new(&e.curve).unwrap().point(0.5 * (e.interval[0] + e.interval[1])).unwrap();
+ // On the curve the interval is on (a circle's NURBS form).
+ let middle = |e: &b::Edge| b::eval::CurveEval::new(e.parameters()).unwrap().point(0.5 * (e.interval[0] + e.interval[1])).unwrap();
let copies: Vec<&b::Edge> = record.edges.iter().filter(|e| on_line(e)).collect();
assert_eq!(copies.len(), 2);
for copy in copies {
diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rs
index 05564e2d6a..958d890b05 100644
--- a/crates/ui-egui/src/agent_chat/tests.rs
+++ b/crates/ui-egui/src/agent_chat/tests.rs
@@ -2293,12 +2293,17 @@ fn the_picks_go_with_the_next_message_once() {
}
/// Two clicks on two rims are two things, not four edges (a click on a rim selects both halves for
-/// the commands; the chat counts and describes what was clicked).
+/// the commands; the chat counts and describes what was clicked). The cylinder is a circle drawn
+/// as two half arcs, extruded, so each rim is in two halves.
#[test]
fn a_rim_clicked_once_is_one_item_not_its_pieces() {
use solidcraft_engine::Sel;
let (mut app, script, ctx) = app_with_script();
- app.run("solid.cylinder", json!({"radius": 10, "height": 20})).expect("a cylinder");
+ app.run("sketch.create", json!({"plane": "XY"})).expect("a sketch");
+ app.run("sketch.arc.three_point", json!({"start": [10, 0], "end": [-10, 0], "through": [0, 10]})).expect("an arc");
+ app.run("sketch.arc.three_point", json!({"start": [-10, 0], "end": [10, 0], "through": [0, -10]})).expect("an arc");
+ app.run("sketch.finish", json!({})).expect("the sketch");
+ app.run("solid.extrude", json!({"distance": 20})).expect("a cylinder");
let (name, top, bottom, mid_top, mid_bottom) = {
let st = crate::open_meshing::session_world(&app.session);
let body = &st.bodies[0];
diff --git a/crates/ui-egui/src/dialogs_coupling_tests.rs b/crates/ui-egui/src/dialogs_coupling_tests.rs
index f6c2f973a0..b95f3bd35b 100644
--- a/crates/ui-egui/src/dialogs_coupling_tests.rs
+++ b/crates/ui-egui/src/dialogs_coupling_tests.rs
@@ -54,8 +54,9 @@ fn picked_gear_faces_choose_their_joints_and_radii() {
let mut app = discs();
app.start("joint.gear");
let mut d = app.dialog.take().unwrap();
- // G2 first, G1 second: the joints follow the picks, whatever the dialog started on.
- for (i, p) in [Vec3::new(50.0, 0.0, 2.5), Vec3::new(10.0, 0.0, 2.5)].into_iter().enumerate() {
+ // G2 first, G1 second: the joints follow the picks, whatever the dialog started on. The
+ // discs touch at x = 10, on both walls, so G1 is picked on its far side.
+ for (i, p) in [Vec3::new(50.0, 0.0, 2.5), Vec3::new(-10.0, 0.0, 2.5)].into_iter().enumerate() {
d.active = i;
let pick = wall(&app, p);
d.pick(&app.session, pick);
diff --git a/crates/ui-egui/src/dialogs_frame_tests.rs b/crates/ui-egui/src/dialogs_frame_tests.rs
index 4a825f55c8..6cfdd64df7 100644
--- a/crates/ui-egui/src/dialogs_frame_tests.rs
+++ b/crates/ui-egui/src/dialogs_frame_tests.rs
@@ -139,7 +139,11 @@ fn a_whole_sketch_section_stays_whole_through_an_edit() {
let c = apply_commands(&app, &e).unwrap();
assert!(c[0].1["params"].get("profiles").is_none(), "{}", c[0].1);
run_all(&mut app, c);
- assert!((volume(&mut app) - before).abs() < 1e-6 * before, "still the ring, not the filled circle");
+ // To the accuracy SMLib measures at (1e-4 relative, the finest it takes: kernel
+ // `measure::ACCURACY`); the ring's exact π (20² − 17²) 600 = 209230.07 mm³ came out
+ // 209229.86 before the turn and 209230.43 after it. The filled circle would be 3.6 times it.
+ let after = volume(&mut app);
+ assert!((after - before).abs() < 1e-4 * before, "still the ring, not the filled circle: {after} mm³, {before} before");
// Unticked, the section is a built-in profile again.
let mut e = edit_dialog(&app, f, None).unwrap();
member(&mut e).whole = None;
diff --git a/crates/ui-egui/src/dialogs_motion.rs b/crates/ui-egui/src/dialogs_motion.rs
index 47f697b426..10b7d15682 100644
--- a/crates/ui-egui/src/dialogs_motion.rs
+++ b/crates/ui-egui/src/dialogs_motion.rs
@@ -1103,10 +1103,11 @@ mod tests {
assert!(matches!(&target.certificate, Some(solidcraft_engine::doc::config::FaceCertificate::ExtrudeSide { curve, .. }) if curve == "outer"));
let state = h.app.session.model.state();
let body = state.body("Ring").unwrap();
+ // The outer circle, one closed curve, is one wall face.
let indices = h.app.session.doc.configuration_face_indices(body, target).unwrap();
- assert_eq!(indices.len(), 2);
+ assert_eq!(indices.len(), 1);
let painted = h.app.session.doc.face_colors(body);
- assert_eq!(painted.len(), 2);
+ assert_eq!(painted.len(), 1);
assert!(painted.iter().all(|(index, _)| indices.contains(index)));
}
diff --git a/crates/ui-egui/src/round_pick_tests.rs b/crates/ui-egui/src/round_pick_tests.rs
index 00bb3efac7..f48c62663c 100644
--- a/crates/ui-egui/src/round_pick_tests.rs
+++ b/crates/ui-egui/src/round_pick_tests.rs
@@ -24,7 +24,9 @@ fn shaft() -> Harness {
h
}
-/// The shaft's wall, top rim and top cap, as picks.
+/// The shaft's wall, top rim and top cap, as picks. The rim is picked at the middle of its
+/// polyline: its first point is the vertex where the wall's seam meets it, as near the seam as
+/// the rim.
fn picks(h: &Harness) -> (Sel, Sel, Sel) {
use solidcraft_engine::kernel::{FaceSurface, face_surface};
let st = h.app.session.world_state().unwrap();
@@ -42,7 +44,7 @@ fn picks(h: &Harness) -> (Sel, Sel, Sel) {
.enumerate()
.find_map(|(index, e)| {
let c = solidcraft_engine::kernel::edge_circle(&b.body, index)?;
- (c.center.z > 9.0).then(|| Sel::Edge { body: "Shaft".into(), index, point: e[0] })
+ (c.center.z > 9.0).then(|| Sel::Edge { body: "Shaft".into(), index, point: crate::viewport::polyline_mid(e) })
})
.unwrap();
(wall, rim, cap)
diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs
index 29bce24f67..4a59d6adf8 100644
--- a/crates/ui-egui/src/viewport.rs
+++ b/crates/ui-egui/src/viewport.rs
@@ -8304,6 +8304,21 @@ mod tests {
app
}
+ /// A Ø20 × 20 cylinder whose wall and rims are each in two halves: a circle drawn as two
+ /// half arcs, extruded (one wall face per arc). SMLib's own cylinder has one wall and one
+ /// edge per rim; a rim or wall in pieces comes from a profile like this one or an import.
+ fn split_cylinder_app() -> SolveApp {
+ let mut s = solidcraft_engine::Session::default();
+ s.execute("sketch.create", &json!({"plane": "XY"})).unwrap();
+ s.execute("sketch.arc.three_point", &json!({"start": [10, 0], "end": [-10, 0], "through": [0, 10]})).unwrap();
+ s.execute("sketch.arc.three_point", &json!({"start": [-10, 0], "end": [10, 0], "through": [0, -10]})).unwrap();
+ s.execute("sketch.finish", &json!({})).unwrap();
+ s.execute("solid.extrude", &json!({"distance": 20})).unwrap();
+ let mut app = SolveApp::new(s, crate::Services::default());
+ app.set_origin_shown(false);
+ app
+ }
+
/// Moving the pointer across a face keeps its highlight (a scanned mesh is one face of
/// millions of triangles): only another face, edge or plane builds it again.
#[test]
@@ -8642,9 +8657,13 @@ mod tests {
})
})
.unwrap();
- assert!(mesh.seams[crease], "the fixture must exercise the coarse seam false positive");
+ // Truck's coarse seam fit took this crease for a seam between pieces of one surface;
+ // the seam flags now compare the exact surfaces (`topo::seam_flags`). Either way the
+ // certified crease is sharp, drawn in wireframe and picked. Its kink of a millionth is
+ // too close to tangent to show in the shading (`smooth_edges::Join`: smooth and a
+ // measured crease at once), so the shaded view leaves it out.
assert!(mesh.sharp_edges[crease]);
- assert!(mesh.shaded_edge_visible(crease));
+ assert!(mesh.edge_visible(crease) && !mesh.shaded_edge_visible(crease));
assert!(mesh.edge_pickable(crease));
assert!(mesh.edge_faces[crease].iter().any(|f| mesh.surface_patch(*f as usize).len() == 1));
let mid = polyline_mid(&mesh.edges[crease]);
@@ -8660,7 +8679,7 @@ mod tests {
#[test]
fn circular_items_measure_as_whole_rims_and_surfaces() {
- let mut app = cylinder_app();
+ let mut app = split_cylinder_app();
let st = app.session.world_state().unwrap();
let b = &st.bodies[0];
let m = b.mesh();
@@ -8741,7 +8760,7 @@ mod tests {
#[test]
fn circular_rim_hover_click_and_dialog_pick_include_both_halves() {
- let mut app = cylinder_app();
+ let mut app = split_cylinder_app();
let st = app.session.world_state().unwrap();
let b = &st.bodies[0];
let m = b.mesh();
@@ -8788,7 +8807,7 @@ mod tests {
#[test]
fn curved_face_hover_selection_and_dialogs_cross_the_seam() {
- let mut app = cylinder_app();
+ let mut app = split_cylinder_app();
let st = app.session.world_state().unwrap();
let b = &st.bodies[0];
let m = b.mesh();
@@ -9473,7 +9492,8 @@ mod tests {
fn cosmetic_threads_use_depth_tested_lines_and_keep_selection_and_wireframe() {
let mut s = solidcraft_engine::Session::default();
s.execute("solid.cylinder", &json!({"radius":3,"height":10})).unwrap();
- s.execute("solid.thread", &json!({"face":[3,0,5],"designation":"M6","length":5})).unwrap();
+ // A pick in the middle of a face free at both ends names the end the thread starts from.
+ s.execute("solid.thread", &json!({"face":[3,0,5],"designation":"M6","length":5,"from":[3,0,0]})).unwrap();
let mut app = SolveApp::new(s, crate::Services::default());
let count = |sc: GpuScene| {
sc.merged()