Skip to content

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

Wave 405/509: Tests: a round wall is one face, its name without a piece number (and 3 more)

jyvikoa3224513564e
diff --git a/crates/engine/src/boolean_regression_tests.rs b/crates/engine/src/boolean_regression_tests.rs
index 76910333cc..69cb1f5c3a 100644
--- a/crates/engine/src/boolean_regression_tests.rs
+++ b/crates/engine/src/boolean_regression_tests.rs
@@ -1060,8 +1060,15 @@ fn cut_keeps_posts_joined_while_apart_in_one_body() {
// A cut through the middle of the case still leaves two bodies, and says it made the second.
s.execute("solid.box", &json!({"length": 2, "width": 80, "height": 80, "center": [0, 0, 20], "operation": "new", "body_name": "Saw"})).unwrap();
let saw = s.execute("solid.combine", &json!({"target": "Case", "tools": ["Saw"], "operation": "cut"})).unwrap();
- assert_eq!(saw["bodies"], json!(["Case", "Case (1)"]), "{saw}");
+ // `bodies` lists them in the kernel's order. The piece whose least face name sorts first keeps
+ // the name (`lineage::order_lumps`): the +x half, whose `F1:+x` sorts before the -x half's
+ // least, its piece of the case's `F1:+y`.
+ let mut bodies: Vec<&str> = saw["bodies"].as_array().unwrap().iter().filter_map(Value::as_str).collect();
+ bodies.sort_unstable();
+ assert_eq!(bodies, ["Case", "Case (1)"], "{saw}");
assert_eq!(saw["created_bodies"], json!(["Case (1)"]), "{saw}");
+ let low_x = |name: &str| s.model.state().body(name).unwrap().mesh().bounds().min.x;
+ assert!((low_x("Case") - 1.0).abs() < 1e-9 && (low_x("Case (1)") + 30.0).abs() < 1e-9);
let half = (60.0 - 2.0) / 2.0 * 40.0 * 10.0 + posts / 2.0;
for name in ["Case", "Case (1)"] {
assert!((volume(&s, name) - half).abs() < 1e-6 * half, "{name}: {} vs {half}", volume(&s, name));
diff --git a/crates/engine/src/cmd/config_certificate_tests.rs b/crates/engine/src/cmd/config_certificate_tests.rs
index 61d926c534..2301865959 100644
--- a/crates/engine/src/cmd/config_certificate_tests.rs
+++ b/crates/engine/src/cmd/config_certificate_tests.rs
@@ -49,22 +49,22 @@ fn certified_annulus_side_rows_follow_radius_edits_and_clone() {
run(&mut s, "sketch.finish", json!({}));
run(&mut s, "solid.extrude", json!({"distance":10,"profiles":[{"point":[9.5,0]}],"body_name":"Ring"}));
paint(&mut s, "Ring", json!([10, 0, 5]));
- assert_eq!(painted_radius(&s, "Ring", 10.), 2, "both constructed arc pieces share outer curve");
+ assert_eq!(painted_radius(&s, "Ring", 10.), 1, "the outer circle's wall is one face, closed along its seam");
let Column::FaceAppearance(target) = &s.doc.configs.columns[0] else { panic!() };
assert_eq!(target.certificate, Some(FaceCertificate::ExtrudeSide { sketch, curve: "outer".into() }));
run(&mut s, "parameters.change", json!({"name":dimensions[0],"expression":"12 mm"}));
run(&mut s, "parameters.change", json!({"name":dimensions[1],"expression":"9.25 mm"}));
run(&mut s, "config.activate", json!({"row":"Painted"}));
- assert_eq!(painted_radius(&s, "Ring", 12.), 2);
+ assert_eq!(painted_radius(&s, "Ring", 12.), 1);
run(&mut s, "component.paste_new", json!({"component":part,"translate":[30,0,0]}));
assert_eq!(s.doc.configs.columns.len(), 2);
run(&mut s, "config.activate", json!({"row":"Painted"}));
- assert_eq!(painted_radius(&s, "Ring (2)", 12.), 2);
+ assert_eq!(painted_radius(&s, "Ring (2)", 12.), 1);
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
let mut reopened = Session::new(reopened);
run(&mut reopened, "config.activate", json!({"row":"Painted"}));
- assert_eq!(painted_radius(&reopened, "Ring", 12.), 2);
- assert_eq!(painted_radius(&reopened, "Ring (2)", 12.), 2);
+ assert_eq!(painted_radius(&reopened, "Ring", 12.), 1);
+ assert_eq!(painted_radius(&reopened, "Ring (2)", 12.), 1);
run(&mut reopened, "config.activate", json!({"row":"Default"}));
assert!(reopened.doc.appearances.faces.is_empty());
}
@@ -227,11 +227,11 @@ fn certified_side_transfer_preserves_geometry_and_unsupported_taper_refuses_atom
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,20,0],"angle":90,"axis":[0,0,1],"capture":false}));
run(&mut s, "component.move_bodies", json!({"component":destination,"bodies":["Round"]}));
run(&mut s, "config.activate", json!({"row":"Painted"}));
- assert_eq!(painted_radius(&s, "Round", 10.), 2);
+ assert_eq!(painted_radius(&s, "Round", 10.), 1);
let before = s.world_state().unwrap().body("Round").unwrap().mesh().bounds();
let mut s = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
run(&mut s, "config.activate", json!({"row":"Painted"}));
- assert_eq!(painted_radius(&s, "Round", 10.), 2);
+ assert_eq!(painted_radius(&s, "Round", 10.), 1);
assert!(
s.world_state().unwrap().body("Round").unwrap().mesh().bounds().min.dist(before.min) < 1e-8,
"before {before:?}, reopened {:?}",
diff --git a/crates/engine/src/cmd/features_more_tests.rs b/crates/engine/src/cmd/features_more_tests.rs
index aeb96898db..2c7b0fef6b 100644
--- a/crates/engine/src/cmd/features_more_tests.rs
+++ b/crates/engine/src/cmd/features_more_tests.rs
@@ -1870,8 +1870,14 @@ fn fillets_on_tapered_bosses_saved_before_still_find_their_edges() {
let r = s.model.result(id).unwrap();
assert!(r.error.is_none() && r.warning.is_none(), "{name}: {:?} {:?}", r.error, r.warning);
}
- // The build that saved it measured 69454.885209 mm³.
- assert!((volume - 69454.8852092132).abs() < 1e-3, "{volume}");
+ // In closed form: the 80 × 40 × 20 block, the 20 × 20 boss 10 high tapered 5° in (a frustum,
+ // top 20 − 20 tan 5° square: 3660.251034), the Ø16 boss tapered alike (a cone frustum, top
+ // radius 8 − 10 tan 5°: 1798.751833); less the R1 round along a sloping corner (the corner's
+ // section, r²(cot φ/2 − (π − φ)/2) at its dihedral angle φ = 90.435°, times its length
+ // between z = 20 and 30: 2.124401) and the R0.5 round all round the cone's top (the section
+ // at the rim's 95°, turned about the axis by Pappus: 1.928463). The build that saved it,
+ // with truck, measured 69454.885209.
+ assert!((volume - 69454.950004).abs() < 1e-3, "{volume}");
assert_eq!(s.world_state().unwrap().bodies.len(), 1);
}
diff --git a/crates/engine/src/cmd/surface.rs b/crates/engine/src/cmd/surface.rs
index d9b6170424..2d7451ad34 100644
--- a/crates/engine/src/cmd/surface.rs
+++ b/crates/engine/src/cmd/surface.rs
@@ -1091,9 +1091,9 @@ mod tests {
}
}
- /// Offset Surface: a cylinder's side picked once with its chain (both halves) moved out to
- /// radius 12; a box top moved up exactly; a zero distance copies; past the axis refused, the
- /// design left as it was; undo, redo and reopening.
+ /// Offset Surface: a cylinder's side (one face, closed along its seam) picked with its chain
+ /// moved out to radius 12; a box top moved up exactly; a zero distance copies; past the axis
+ /// refused, the design left as it was; undo, redo and reopening.
#[test]
fn offset_surface_of_a_cylinder_and_a_box_top() {
let mut s = Session::default();
@@ -1101,7 +1101,7 @@ mod tests {
run(&mut s, "surface.offset", json!({"faces": [[10, 0, 10]], "chain": true, "distance": 2, "body": "Can", "body_name": "Sleeve"}));
let st = s.world_state().unwrap();
let sleeve = &st.body("Sleeve").unwrap().body;
- assert!(sleeve.is_surface() && sleeve.face_count() == 2);
+ assert!(sleeve.is_surface() && sleeve.face_count() == 1);
let want = 2.0 * std::f64::consts::PI * 12.0 * 20.0;
assert!((area(&s, "Sleeve") - want).abs() < want * 1e-3, "{} vs {want}", area(&s, "Sleeve")); // (measured on meshes)
assert!(st.body("Can").is_some(), "the source body stays");
@@ -1293,9 +1293,10 @@ mod tests {
/// Extend a cylinder strip: naturally 5 along its axis (10 · π/2 · 25, one face, still a
/// cylinder), up to the plane z = 30 (10 · π/2 · 30), and by tangent and curvature run-offs
- /// (a second face along a straight edge, 20 long: the tangent one a flat 5 × 20, the
- /// curvature one the parabola s ↦ s·R + ½κs²·n with the cylinder's κ = 1/10, its section
- /// ∫₀⁵ √(1 + κ²s²) ds long). Undo, redo and reopening; the default saves nothing new.
+ /// along a straight edge, 20 long: each SMLib's G1 or G2 extension of the surface, so the
+ /// strip stays one face (the tangent one a flat 5 × 20, the curvature one the parabola
+ /// s ↦ s·R + ½κs²·n with the cylinder's κ = 1/10, its section ∫₀⁵ √(1 + κ²s²) ds long).
+ /// Undo, redo and reopening; the default saves nothing new.
#[test]
fn extend_a_cylinder_strip_every_way() {
let pi = std::f64::consts::PI;
@@ -1326,7 +1327,7 @@ mod tests {
for (mode, run_off) in [("tangent", 5.0), ("curvature", parabola)] {
run(&mut s, "surface.extend", json!({"body": "Strip", "edges": [side], "distance": 5, "mode": mode}));
let st = s.world_state().unwrap();
- assert_eq!(st.body("Strip").unwrap().body.face_count(), 2, "{mode}");
+ assert_eq!(st.body("Strip").unwrap().body.face_count(), 1, "{mode}");
let want = 10.0 * pi / 2.0 * 20.0 + run_off * 20.0;
assert!((area(&s, "Strip") - want).abs() < want * 1e-3, "{mode}: {} vs {want}", area(&s, "Strip")); // (measured on meshes)
let cold = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
diff --git a/crates/engine/src/cmd/thin_extrude_tests.rs b/crates/engine/src/cmd/thin_extrude_tests.rs
index 332bdec3b4..9fd35741fb 100644
--- a/crates/engine/src/cmd/thin_extrude_tests.rs
+++ b/crates/engine/src/cmd/thin_extrude_tests.rs
@@ -371,10 +371,15 @@ fn the_round_sides_of_a_thin_ring_are_named_by_the_circle_they_run_beside() {
run(&mut s, "solid.extrude", json!({"sketch": "Outline", "thin": true, "thickness": 2, "distance": 5, "name": "Ring"}));
let world = s.world_state().unwrap();
let names = solidcraft_doc::naming::face_names(world.bodies.first().unwrap());
- // Each round side is two half cylinders, told apart by their numbers.
+ // Each round side is one cylinder, closed along its seam, so its name needs no number.
let walls: Vec<_> = names.iter().filter(|name| name.contains(":wall:")).collect();
- assert_eq!(walls.len(), 4, "{names:?}");
- for side in ["left", "right"] {
- assert_eq!(walls.iter().filter(|name| name.contains(&format!(":wall:c1:{side}#"))).count(), 2, "{walls:?}");
+ assert_eq!(walls.len(), 2, "{names:?}");
+ // The wall is 2 thick about the circle (radius 9 to 11). The circle runs counter-clockwise,
+ // so its left is the inner side; each name is found again at a point on its own wall.
+ for (side, radius) in [("left", 9.0), ("right", 11.0)] {
+ let name = format!("F2:wall:c1:{side}");
+ assert!(walls.contains(&&name), "{walls:?}");
+ let at = solidcraft_geom::Vec3::new(0.0, radius, 2.5);
+ assert_eq!(solidcraft_doc::naming::face_names_at(&s.model.state(), &[at]), vec![name.clone()]);
}
}