Wave 240/509: A converted sheet takes its rule's values at its own thickness (#4328) (and 3 more)

4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop.

- 610173e1f jyviko: combine: move each tool into its target's frame
- 3fb263d00 jyviko: hole: keep a countersink's tool within its rim above the face
- 1171c4c2a jyviko: A sheet metal body mirrored or patterned into new bodies is sheet metal (#3353)
- 5a9bf4742 jyviko: A converted sheet takes its rule's values at its own thickness (#4328)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-26 05:55:36 -04:00
parent 7c481d281f
commit cbd7b07767
8 changed files with 179 additions and 35 deletions
@@ -632,6 +632,23 @@ fn a_channel_with_its_bends_modelled_folds_back_into_itself_under_its_own_radius
assert!((volume(&mut s) - solid).abs() < 1e-3 * solid);
}
/// A rule's values follow the sheet's own thickness (#4328): an L shell 2 thick, its bend
/// modelled R 2 inside, converted under the default rule (2.5 thick, bends R `Thickness`) is a
/// sheet 2 thick bent R 2, the solid unchanged; an edge flange added to it bends R 2 as well.
#[test]
fn a_converted_shell_takes_its_rules_values_at_its_own_thickness() {
let mut s = Session::default();
let (outer, _) = bent_section(&mut s, &[(0.0, 40.0), (0.0, 0.0), (60.0, 0.0)], 2.0, 2.0, 100.0)[0];
let solid = volume(&mut s);
run(&mut s, "sheet.convert", json!({"body": "Section", "face": [30, 0, 50], "bends": [outer]}));
assert!((volume(&mut s) - solid).abs() < 1e-6 * solid, "{} vs {solid}", volume(&mut s));
let f = flat(&mut s);
assert_eq!((f["thickness"].as_f64(), f["bends"][0]["radius"].as_f64()), (Some(2.0), Some(2.0)), "{f}");
run(&mut s, "sheet.flange", json!({"edges": [[0, 40, 50]], "height": 10}));
let f = flat(&mut s);
assert_eq!(f["bends"][1]["radius"].as_f64(), Some(2.0), "{f}");
}
#[test]
fn a_filleted_edge_of_a_solid_block_is_a_bend() {
// A block's bottom edge rounded R 5: the faces either side meet at the old sharp edge,
+57
View File
@@ -5373,6 +5373,63 @@ fn flat_exports(s: &mut Session) -> Vec<std::result::Result<Value, String>> {
calls.iter().map(|(id, p)| s.execute(id, p).map_err(|e| e.to_string())).collect()
}
/// A sheet metal body mirrored, or patterned, into new bodies makes sheet metal bodies (#3353):
/// each copy has a flat pattern and a bend table, and a sheet metal feature on a copy rebuilds it
/// from its moved model where it is. A mirrored copy's model is its source's turned over: the
/// same blank, bent the other way, its pocket on the other face.
#[test]
fn a_mirrored_or_patterned_sheet_body_is_sheet_metal_with_its_flat_pattern() {
use solidcraft_geom::Vec3;
let mut s = Session::default();
run(&mut s, "sheet.manage_rules", json!({"name": "S", "thickness": "2 mm", "active": true, "bend_radius": "2 mm", "k_factor": 0.4}));
base(&mut s, 100.0, 60.0);
run(&mut s, "sheet.flange", json!({"edges": [[50, 0, 2]], "height": 20}));
rectangle_tool(&mut s, "Pocket", [20.0, 20.0], [30.0, 30.0]);
run(&mut s, "solid.extrude", json!({"sketch": "Pocket", "distance": 1, "operation": "cut"}));
let source = s.model.state().sheets[0].body.clone();
let before = volume(&mut s);
let blank = run(&mut s, "sheet.flat_pattern", json!({"body": source}));
run(&mut s, "solid.mirror", json!({"bodies": [source], "plane": "YZ"}));
let copy = s.model.state().bodies[1].name.clone();
assert!(rel(volume(&mut s), 2.0 * before) < 1e-9);
let mirrored = run(&mut s, "sheet.flat_pattern", json!({"body": copy}));
assert_eq!(mirrored["outline"], blank["outline"], "the same blank");
assert_eq!(blank["pockets"][0]["side"], "bottom");
assert_eq!(mirrored["pockets"][0]["side"], "top", "{mirrored}");
assert_eq!((&blank["bends"][0]["direction"], &mirrored["bends"][0]["direction"]), (&json!("up"), &json!("down")), "{mirrored}");
run(&mut s, "sheet.export_bend_table", json!({"body": copy}));
// The copy's model is where its body is: a flange on the copy rebuilds it in place, its
// first flange still up on the y = 0 edge and its pocket still from below.
run(&mut s, "sheet.flange", json!({"body": copy, "edges": [[-100, 30, 2]], "height": 10}));
let state = s.model.state();
let body = &state.body(&copy).expect("the copy").body;
for (p, inside) in [
(Vec3::new(-50.0, 1.0, 15.0), true),
(Vec3::new(-50.0, 1.0, -15.0), false),
(Vec3::new(-25.0, 25.0, 0.5), false),
(Vec3::new(-25.0, 25.0, 1.5), true),
(Vec3::new(-99.0, 30.0, 8.0), true),
(Vec3::new(-99.0, 30.0, -8.0), false),
] {
assert_eq!(body.contains(p), inside, "{p:?}");
}
drop(state);
let mut s = Session::default();
base(&mut s, 100.0, 60.0);
let source = s.model.state().sheets[0].body.clone();
run(&mut s, "solid.pattern.rectangular", json!({"bodies": [source], "dir1": [1, 0, 0], "count1": 2, "spacing1": 150}));
let state = s.model.state();
assert_eq!(state.sheets.len(), state.bodies.len(), "every copy is sheet metal");
let names: Vec<String> = state.bodies.iter().map(|b| b.name.clone()).collect();
drop(state);
for n in names {
run(&mut s, "sheet.flat_pattern", json!({"body": n}));
}
}
/// A mirror combined into a sheet, or a tab extruded onto it and joined, makes a part its
/// flat pattern does not have (the mirrored half, the tab): the flat pattern, the DXF and the
/// bend table are refused with the feature's name instead of writing the sheet without it.
@@ -133,3 +133,29 @@ fn a_far_body_does_not_change_a_countersunk_hole() {
assert_eq!(small_changed, large_changed, "bodies changed");
assert_eq!(large_changed, json!(["lid"]), "only the lid is drilled");
}
/// #5041: a countersunk Ø6.4 hole (Ø13.7, 90°) 0.15 mm from a wall standing on the plate cuts
/// nothing above the entry face: the countersink's rim (y 29.85) stays clear of the wall (y 30).
/// 10 faces: bottom, the two L-shaped ends, front and back, the plate top, the wall's front and
/// top, the cone and the bore.
#[test]
fn a_countersink_beside_a_wall_stays_below_the_face() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 40, "width": 40, "height": 8, "corner": [0, 0, 0]}));
run(&mut s, "solid.box", json!({"length": 40, "width": 10, "height": 30, "corner": [0, 30, 8], "operation": "join"}));
run(
&mut s,
"solid.hole",
json!({"position": [20, 23, 8], "direction": [0, 0, -1], "diameter": 6.4, "type": "countersink", "cs_diameter": 13.7, "cs_angle": 90}),
);
let st = s.model.state();
let [body] = st.bodies.as_slice() else { panic!("one body, got {}", st.bodies.len()) };
assert_eq!(body.body.face_count(), 10, "the wall is not notched");
// In the wall's foot, 0.4 mm above the face: still solid.
assert!(solid_at(&s, Vec3::new(20.0, 30.2, 8.4)), "the wall's foot is cut");
let (rr, r, h) = (6.85_f64, 3.2_f64, 3.65_f64);
let removed = PI * h / 3.0 * (rr * rr + rr * r + r * r) + PI * r * r * (8.0 - h);
let want = 24800.0 - removed;
let got = volume(&mut s);
assert!((got - want).abs() < 1e-3, "volume {got}, want {want}");
}