Sheet metal: a corner relief no longer depends on the order the corners are cut in (#3280)
* Sheet metal: a corner relief no longer depends on the order the corners are cut in The corner reliefs are planned against the base as it is before any of them is cut, and the two reliefs at the ends of one edge are compared with each other. Before, every relief was cut into the base as it went, so the corner after it saw the relief of the corner before it: the square relief reaches further from its corner than the round one does (4 / cos(α / 2) against 4), so on a short edge it was left out where the round one was cut, and which of the two corners kept its relief depended on the order the flanges were made in. The reliefs themselves are unchanged: a round about the corner through the angle the base fills there, or the square with that side (a kite where the corner is not square, its cuts square to the two edges). What is new is that they are planned first and cut together, so that a corner's relief depends on the base and on the other reliefs, and not on the order they are cut in. Two reliefs that would overlap are still refused, now with a note that says so. Covered: the four relief shapes at corners of 60° and 120°, with the flanges of equal and of unequal height, through the kernel and through the engine (where the flat pattern and the DXF keep one clean loop). Co-Authored-By: Claude Code <noreply@anthropic.com> * Sheet metal: cover the corner reliefs at a corner that is not square The engine and the UI had no test at all for a base whose corners are 60° and 120°: the flat pattern, the DXF, the unfold and the rule manager's own square relief were all untested there. They work; this says so. Co-Authored-By: Claude Code <noreply@anthropic.com> * Sheet metal: say what happens when a corner relief is left out The guide now says that the reliefs at the corners of one edge are cut together, and that two of them that would overlap leave the second one out. A relief that cannot be cut is reported, not dropped. Co-Authored-By: Claude Code <noreply@anthropic.com> * Sheet metal: write the corner relief's expected corners out The engine test hard-coded the corners of the trimmed base; it works them out instead, and the numbers the test and the sketch share are written with the precision they need. Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: jeremymiribung-blip <jeremymiribung-blip@users.noreply.github.com> Co-authored-by: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -3034,6 +3034,138 @@ fn corner_reliefs_of_the_rule_reach_the_part_the_flat_pattern_and_the_dxf() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The height of the rhombus of [`rhombus_sheet`]: 90 · sin 60°.
|
||||
const RHOMBUS_Y: f64 = 77.9422863406;
|
||||
/// Half of it, where the picks on the slanted sides lie.
|
||||
const RHOMBUS_Y_HALF: f64 = 38.9711431703;
|
||||
|
||||
/// A base flange on a rhombus whose corners are 60° and 120°, with a flange on each of its
|
||||
/// four edges: the two flanges of a corner meet there, and their bends stop short of it.
|
||||
fn rhombus_sheet(s: &mut Session, rule: Value) {
|
||||
let mut r = json!({"name": "AL2", "thickness": "2 mm", "k_factor": 0.5, "bend_radius": "1 mm", "gap": "0.5 mm", "active": true});
|
||||
if let (Some(r), Some(extra)) = (r.as_object_mut(), rule.as_object()) {
|
||||
r.extend(extra.clone());
|
||||
}
|
||||
run(s, "sheet.manage_rules", r);
|
||||
run(s, "sketch.create", json!({"plane": "XY", "name": "Base"}));
|
||||
run(s, "sketch.line", json!({"points": [[0, 0], [120, 0], [165, RHOMBUS_Y], [45, RHOMBUS_Y]], "closed": true}));
|
||||
run(s, "sketch.finish", json!({}));
|
||||
run(s, "sheet.flange", json!({"sketch": "Base"}));
|
||||
run(
|
||||
s,
|
||||
"sheet.flange",
|
||||
json!({"edges": [[60, 0, 2], [142.5, RHOMBUS_Y_HALF, 2], [105, RHOMBUS_Y, 2], [22.5, RHOMBUS_Y_HALF, 2]], "height": 38.6, "angle": "90 deg"}),
|
||||
);
|
||||
}
|
||||
|
||||
/// The corner of the trimmed base at the corner `c` of the base, whose edges leave it in the
|
||||
/// directions `dirs`: the two bend lines, each `s0` in from its edge, meet there.
|
||||
fn trimmed_corner(c: (f64, f64), dirs: [(f64, f64); 2], s0: f64) -> (f64, f64) {
|
||||
let (d0, d1) = (dirs[0], dirs[1]);
|
||||
let alpha = (d0.0 * d1.1 - d0.1 * d1.0).atan2(d0.0 * d1.0 + d0.1 * d1.1).abs();
|
||||
let (bx, by) = (d0.0 + d1.0, d0.1 + d1.1);
|
||||
let k = s0 / (alpha / 2.0).sin() / (bx * bx + by * by).sqrt();
|
||||
(c.0 + bx * k, c.1 + by * k)
|
||||
}
|
||||
|
||||
/// The far corner of the square relief at a corner of the base: `4 / (1 + cos α)` from the
|
||||
/// corner, on the bisector of its two edges.
|
||||
fn kite_vertex(c: (f64, f64), d1: (f64, f64), d2: (f64, f64)) -> (f64, f64) {
|
||||
let k = 4.0 / (1.0 + d1.0 * d2.0 + d1.1 * d2.1);
|
||||
(c.0 + (d1.0 + d2.0) * k, c.1 + (d1.1 + d2.1) * k)
|
||||
}
|
||||
|
||||
/// The corner reliefs at corners that are not square: a 60° and a 120° one, each of the four
|
||||
/// shapes. The relief is cut `size / 2` from the corner along both edges, the bends stop there,
|
||||
/// and the flat pattern and the DXF keep one clean loop.
|
||||
#[test]
|
||||
fn corner_reliefs_at_non_orthogonal_corners_reach_the_flat_pattern_and_the_dxf() {
|
||||
// The corners of the trimmed base: the two at 60° (6 mm from their corner, on the bisector)
|
||||
// and the two at 120° (3.464 mm from theirs), with the directions their edges leave in.
|
||||
let u = (0.5, RHOMBUS_Y / 90.0);
|
||||
let corners = [
|
||||
(trimmed_corner((0.0, 0.0), [(1.0, 0.0), u], 3.0), [(1.0, 0.0), u]),
|
||||
(trimmed_corner((120.0, 0.0), [(-1.0, 0.0), u], 3.0), [(-1.0, 0.0), u]),
|
||||
(trimmed_corner((165.0, RHOMBUS_Y), [(-u.0, -u.1), (-1.0, 0.0)], 3.0), [(-u.0, -u.1), (-1.0, 0.0)]),
|
||||
(trimmed_corner((45.0, RHOMBUS_Y), [(1.0, 0.0), (-u.0, -u.1)], 3.0), [(1.0, 0.0), (-u.0, -u.1)]),
|
||||
];
|
||||
let mut notch = Session::default();
|
||||
rhombus_sheet(&mut notch, json!({}));
|
||||
assert!(no_errors_or_warnings(¬ch), "{:?}", notch.model.results);
|
||||
let area0 = flat_area(&flat(&mut notch));
|
||||
for shape in ["notch", "round", "rectangular", "tear"] {
|
||||
let mut s = Session::default();
|
||||
rhombus_sheet(&mut s, json!({"corner_relief_shape": shape, "corner_relief": "8 mm"}));
|
||||
assert!(no_errors_or_warnings(&s), "{shape}: {:?}", s.model.results);
|
||||
// The flat pattern is one loop with no cut-outs.
|
||||
let f = flat(&mut s);
|
||||
assert_eq!(f["outline"].as_array().map(Vec::len), Some(1), "{shape}: {f}");
|
||||
assert_eq!(f["cutouts"], json!([]), "{shape}: {f}");
|
||||
// No hairline edges in it: no degenerate face.
|
||||
let shortest = f["outline"][0].as_array().map(|l| {
|
||||
l.windows(2)
|
||||
.map(|w| {
|
||||
let (x, y) = (
|
||||
w[1][0].as_f64().unwrap_or(f64::NAN) - w[0][0].as_f64().unwrap_or(f64::NAN),
|
||||
w[1][1].as_f64().unwrap_or(f64::NAN) - w[0][1].as_f64().unwrap_or(f64::NAN),
|
||||
);
|
||||
(x * x + y * y).sqrt()
|
||||
})
|
||||
.fold(f64::MAX, f64::min)
|
||||
});
|
||||
assert!(shortest.is_some_and(|d| d > 1e-3), "{shape}: the shortest edge of the flat pattern is {shortest:?}");
|
||||
// The folded part holds the flat pattern's material (K = 0.5 keeps the volume).
|
||||
let (v, area) = (volume(&mut s), flat_area(&f));
|
||||
assert!((v - area * 2.0).abs() < 1e-3 * v, "{shape}: {v} vs {}", area * 2.0);
|
||||
// The DXF: the relief at each of the four corners.
|
||||
let (arcs, ends) = relief_drawing(&mut s);
|
||||
match shape {
|
||||
"round" => {
|
||||
// A round about each corner, of radius 4.
|
||||
assert_eq!(arcs.len(), 4, "{shape}: {arcs:?}");
|
||||
for (c, _) in corners {
|
||||
assert!(
|
||||
arcs.iter().any(|(a, r)| (a.x - c.0).abs() < 1e-6 && (a.y - c.1).abs() < 1e-6 && (r - 4.0).abs() < 1e-6),
|
||||
"{shape}: {arcs:?}"
|
||||
);
|
||||
}
|
||||
// The base loses a sector of radius 4 at each corner and 4 mm of each of the two
|
||||
// bends there: 2 corners at 60° and 2 at 120°.
|
||||
let ba = std::f64::consts::PI;
|
||||
let want = 2.0 * (16.0 * (PI / 3.0) / 2.0) + 2.0 * (16.0 * (2.0 * PI / 3.0) / 2.0) + 4.0 * 2.0 * 4.0 * ba;
|
||||
assert!((area0 - area - want).abs() < 0.1, "{shape}: {} vs {want}", area0 - area);
|
||||
}
|
||||
"rectangular" => {
|
||||
// A kite at each corner, meeting 4 / cos(α / 2) from it on the bisector.
|
||||
assert!(arcs.is_empty(), "{shape}: {arcs:?}");
|
||||
for (c, [d1, d2]) in corners {
|
||||
let x = kite_vertex(c, d1, d2);
|
||||
assert!(ends.iter().any(|p| (p.x - x.0).abs() < 1e-6 && (p.y - x.1).abs() < 1e-6), "{shape}: no kite at {c:?}: {ends:?}");
|
||||
}
|
||||
let ba = std::f64::consts::PI;
|
||||
let want = 2.0 * (16.0 * (PI / 6.0).tan()) + 2.0 * (16.0 * (PI / 3.0).tan()) + 4.0 * 2.0 * 4.0 * ba;
|
||||
assert!((area0 - area - want).abs() < 0.1, "{shape}: {} vs {want}", area0 - area);
|
||||
}
|
||||
"tear" => {
|
||||
// The tear cuts the bend ends, not the base: no arc, and the base keeps its corners.
|
||||
assert!(arcs.is_empty(), "{shape}: {arcs:?}");
|
||||
assert!(area > area0, "{shape}: the tear takes nothing out of the base");
|
||||
}
|
||||
_ => {
|
||||
// The notch cuts nothing.
|
||||
assert!(arcs.is_empty(), "{shape}: {arcs:?}");
|
||||
assert!((area - area0).abs() < 1e-6, "{shape}: {area} vs {area0}");
|
||||
}
|
||||
}
|
||||
// Unfolding and refolding keep it.
|
||||
run(&mut s, "sheet.unfold", json!({}));
|
||||
run(&mut s, "sheet.refold", json!({}));
|
||||
assert!((volume(&mut s) - v).abs() < 1e-6 * v, "{shape}");
|
||||
let mut reopened = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
|
||||
assert!((volume(&mut reopened) - v).abs() < 1e-6 * v, "{shape}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_tear_of_the_rule_reaches_the_part_the_flat_pattern_and_the_dxf() {
|
||||
use std::f64::consts::SQRT_2;
|
||||
|
||||
Reference in New Issue
Block a user