* Extrude: a profile edge short of a face is not grown through the skin beyond it (#1669) A cut or join profile edge that lies on a face of the target is grown off it by 0.5 % of the body, so that the tool's wall does not lie in the face. Whether it lies on a face was judged half a growth step either side of it: empty just outside, material just inside. An edge 0.25 mm short of a 3.75 mm wall's far face reads the same, and the growth cut through the skin it should leave (55 050 mm³ instead of 56 130 on the test's wall). Now the space just past the edge, 1e-4 of the body out, must already be as the operation wants too. In #1669, the pleat's window built directly at the far end of a case opened through the wall at 3.75 and 4 mm, while its mirror, built without the growth, rightly left the skin and then failed to join the loft through it. Built either way, the window now leaves the skin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Regression tests: the issue's pleats mirror and build at the far end (#1669) The issue's battery case at 3.5 mm: the mirror of the window and the pleat builds (it needed #1670's meshing of twisted faces), and at 3 mm the same window and pleat built directly at the far end of the finished case join it (they needed #1667's end rounds). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Far-end pleat test: the direct build matches the mirror's volume Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Erikas <erkexzcx@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
145 lines
6.4 KiB
Rust
145 lines
6.4 KiB
Rust
//! #1669: a window cut through a battery case's wall and a lofted pleat joined into it, mirrored
|
|
//! to the case's far end, and the same features built directly there.
|
|
|
|
use serde_json::{Value, json};
|
|
use solidcraft_engine::Session;
|
|
|
|
fn replay(script: &str) -> Session {
|
|
let mut s = Session::default();
|
|
let script: Value = serde_json::from_str(script).unwrap();
|
|
s.run_script(&script).unwrap();
|
|
s
|
|
}
|
|
|
|
fn volume(s: &Session, body: &str) -> f64 {
|
|
s.model.state().body(body).map(|b| solidcraft_kernel::measure(&b.body).unwrap().volume).unwrap_or(0.0)
|
|
}
|
|
|
|
/// #1669: an Extrude Cut whose profile stops 0.25 mm short of the far face of a 3.75 mm wall
|
|
/// leaves that skin. The profile's edge was taken for one lying on the face (the space half a
|
|
/// growth step past it was empty) and grown through the skin, until #1310 asked the faces the
|
|
/// growth sweeps instead. A pleat window built so at the far end of a case opened, where its
|
|
/// mirror rightly left the skin.
|
|
#[test]
|
|
fn cut_stopping_short_of_a_face_leaves_the_skin() {
|
|
let wall = |width: f64| {
|
|
let s = replay(
|
|
&json!({"commands": [
|
|
{"command": "solid.box", "params": {"corner": [-100, 0, 0], "length": 200, "width": width, "height": 95, "body_name": "Wall"}},
|
|
{"command": "sketch.create", "params": {"plane": "XY", "offset": -1}},
|
|
{"command": "sketch.rectangle.two_point", "params": {"p0": [-24, -0.5], "p1": [24, 3.5]}},
|
|
{"command": "sketch.finish", "params": {}},
|
|
{"command": "solid.extrude", "params": {"distance": 91, "operation": "cut", "targets": ["Wall"]}}
|
|
]})
|
|
.to_string(),
|
|
);
|
|
volume(&s, "Wall")
|
|
};
|
|
// 48 wide, 3.5 deep (of the wall's 3.75), 90 high.
|
|
let want = 200.0 * 3.75 * 95.0 - 48.0 * 3.5 * 90.0;
|
|
let v = wall(3.75);
|
|
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
|
|
// A profile ending on the far face still cuts clean through, as before.
|
|
let want = 200.0 * 3.5 * 95.0 - 48.0 * 3.5 * 90.0;
|
|
let v = wall(3.5);
|
|
assert!((v - want).abs() < 1e-6 * want, "{v} vs {want}");
|
|
}
|
|
|
|
/// The features of `s` that failed, with their errors.
|
|
fn feature_errors(s: &Session) -> Vec<(String, String)> {
|
|
s.model.results.iter().filter_map(|r| r.error.clone().map(|e| (r.name.clone(), e))).collect()
|
|
}
|
|
|
|
/// #1669: a window and a lofted pleat mirrored to the far end of a case shelled 3.5 mm. The
|
|
/// pleat's twisted faces were each meshed as two flat triangles (#1666), the joins were checked
|
|
/// against those meshes, and the mirror failed ("boolean Union: no result").
|
|
#[test]
|
|
fn mirrored_pleat_joins_into_a_thick_case_wall() {
|
|
let s = replay(include_str!("../../../examples/regressions/battery_case_pleats.json"));
|
|
let errors = feature_errors(&s);
|
|
assert!(errors.is_empty(), "{errors:?}");
|
|
}
|
|
|
|
/// #1669: at 3 mm, the same window and pleat built directly at the far end of the finished case
|
|
/// (a cut and a loft of their own, the mirror suppressed) failed to join as well: the end rounds
|
|
/// they meet had folded faces (#1667).
|
|
#[test]
|
|
fn pleat_built_at_the_far_end_joins_the_finished_case() {
|
|
let mut s = replay(include_str!("../../../examples/regressions/battery_case_pleats.json"));
|
|
s.execute("parameters.change", &json!({"name": "wall", "expression": "3 mm"})).unwrap();
|
|
let errors = feature_errors(&s);
|
|
assert!(errors.is_empty(), "{errors:?}");
|
|
// The case with the mirrored pleat, which the direct build must match.
|
|
let mirrored = volume(&s, "Case");
|
|
s.execute("timeline.suppress", &json!({"feature": "PleatFar", "suppressed": true})).unwrap();
|
|
let before = volume(&s, "Case");
|
|
// Mirrored about y = -99: y' = -198 - y.
|
|
let far = |points: &[[f64; 2]]| points.iter().map(|[x, y]| json!([x, -198.0 - y])).collect::<Vec<_>>();
|
|
let bottom = [
|
|
[-26.0, 3.0],
|
|
[-24.76384, 3.0],
|
|
[-16.0568, 14.97217],
|
|
[-8.0, 4.90117],
|
|
[0.0, 14.90117],
|
|
[8.0, 4.90117],
|
|
[16.0568, 14.97217],
|
|
[24.76384, 3.0],
|
|
[26.0, 3.0],
|
|
[26.0, 0.0],
|
|
[23.23616, 0.0],
|
|
[15.9432, 10.02783],
|
|
[8.0, 0.09883],
|
|
[0.0, 10.09883],
|
|
[-8.0, 0.09883],
|
|
[-15.9432, 10.02783],
|
|
[-23.23616, 0.0],
|
|
[-26.0, 0.0],
|
|
];
|
|
let top = [
|
|
[-26.0, 3.0],
|
|
[-24.0, 3.0],
|
|
[-16.0, 3.0],
|
|
[-8.0, 3.0],
|
|
[0.0, 3.0],
|
|
[8.0, 3.0],
|
|
[16.0, 3.0],
|
|
[24.0, 3.0],
|
|
[26.0, 3.0],
|
|
[26.0, 0.0],
|
|
[24.0, 0.0],
|
|
[16.0, 0.0],
|
|
[8.0, 0.0],
|
|
[0.0, 0.0],
|
|
[-8.0, 0.0],
|
|
[-16.0, 0.0],
|
|
[-24.0, 0.0],
|
|
[-26.0, 0.0],
|
|
];
|
|
let steps = json!([
|
|
{"command": "sketch.create", "params": {"plane": "XY", "offset": "-clear", "name": "FarCutSketch"}},
|
|
{"command": "sketch.rectangle.two_point", "params": {"p0": [-24, -197.5], "p1": [24, -201.5]}},
|
|
{"command": "sketch.finish", "params": {}},
|
|
{"command": "solid.extrude", "params": {"sketch": "FarCutSketch", "distance": "pleat_top + clear", "operation": "cut", "targets": ["Case"]}},
|
|
{"command": "sketch.create", "params": {"plane": "XY", "name": "FarBottom"}},
|
|
{"command": "sketch.line", "params": {"closed": true, "infer": false, "connect": false, "points": far(&bottom)}},
|
|
{"command": "sketch.finish", "params": {}},
|
|
{"command": "sketch.create", "params": {"plane": "XY", "offset": "pleat_top + 0.5 mm", "name": "FarTop"}},
|
|
{"command": "sketch.line", "params": {"closed": true, "infer": false, "connect": false, "points": far(&top)}},
|
|
{"command": "sketch.finish", "params": {}},
|
|
{"command": "solid.loft", "params": {"sections": [{"sketch": "FarBottom"}, {"sketch": "FarTop"}], "operation": "join", "targets": ["Case"]}}
|
|
]);
|
|
for c in steps.as_array().into_iter().flatten() {
|
|
let (id, p) = (c["command"].as_str().unwrap_or_default(), &c["params"]);
|
|
if let Err(e) = s.execute(id, p) {
|
|
panic!("{id}: {e}");
|
|
}
|
|
}
|
|
let errors = feature_errors(&s);
|
|
assert!(errors.is_empty(), "{errors:?}");
|
|
// The far pleat is the mirror's exact image, so the case comes out as with the mirror (and
|
|
// larger than without it: the loft outweighs its window).
|
|
let after = volume(&s, "Case");
|
|
assert!(after > before, "{after} after the far pleat, {before} before");
|
|
assert!((after - mirrored).abs() < 1e-6 * mirrored, "{after} built directly, {mirrored} mirrored");
|
|
}
|