From f0a2c3f99d49e2cc011f36d352b4745f18d2e1dd Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Fri, 30 Oct 2026 06:38:11 -0400 Subject: [PATCH] Wave 421/509: Tests: Open in EasyPrint's STL is read back, not measured in bytes (and 3 more) 4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 5ea43b5c2 jyviko: Tests: a tray's sheet names are checked by where their points lie - 978ae1d51 jyviko: Tests: a mirrored sheet's flat pattern is its source's mirrored, as the code makes it - 2be7b1b6f jyviko: Tests: the extruded ellipse is checked by its area, not its face count - 51855589d jyviko: Tests: Open in EasyPrint's STL is read back, not measured in bytes Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- .../engine/src/cmd/sheet_face_names_tests.rs | 11 +++++--- crates/engine/src/cmd/sheet_tests.rs | 17 +++++++----- crates/engine/src/cmd/sketch_modify_tests.rs | 9 +++++-- crates/engine/src/tests/mesh_convert.rs | 27 +++++++++++++++++-- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/cmd/sheet_face_names_tests.rs b/crates/engine/src/cmd/sheet_face_names_tests.rs index 6c5d656f3..206c676d2 100644 --- a/crates/engine/src/cmd/sheet_face_names_tests.rs +++ b/crates/engine/src/cmd/sheet_face_names_tests.rs @@ -59,9 +59,10 @@ fn a_trays_faces_have_readable_sheet_names_that_follow_its_size() { let mut s = Session::default(); let (width, fb, sd) = tray(&mut s, 320.0); let all = faces(&mut s); - // Every face but the hole's wall (two halves) has a sheet name, and no two faces share one. + // Every face but the hole's wall (r 3.3, however many faces the kernel makes it of) has a + // sheet name, and no two faces share one. let unnamed: Vec<_> = all.iter().filter(|f| f.0.is_none()).collect(); - assert!(unnamed.len() == 2 && unnamed.iter().all(|f| f.2.is_some_and(|r| (r - 3.3).abs() < 1e-6)), "only the hole's wall: {unnamed:?}"); + assert!(!unnamed.is_empty() && unnamed.iter().all(|f| f.2.is_some_and(|r| (r - 3.3).abs() < 1e-6)), "only the hole's wall: {unnamed:?}"); let mut names: Vec<&str> = all.iter().filter_map(|f| f.0.as_deref()).collect(); names.sort_unstable(); let n = names.len(); @@ -84,7 +85,9 @@ fn a_trays_faces_have_readable_sheet_names_that_follow_its_size() { let radius = |name: &str| named(&all, name).first().and_then(|f| f.2); assert_eq!(radius(&format!("sheet:Body1:F{fb}.0:bend.inner")).map(|r| (r * 1e6).round() / 1e6), Some(1.0)); assert_eq!(radius(&format!("sheet:Body1:F{fb}.0:bend.outer")).map(|r| (r * 1e6).round() / 1e6), Some(2.0)); - // 80 mm wider: the same names, each on the same face where it now is. + // 80 mm wider: the same names, each on the same face where it now is. A name's point is + // somewhere on its face: the right flange's top is the plane x = w − 1, the back flange's + // far rim the strip z = 30, 199 <= y <= 200 (the flange 1 thick, its outside at y = 200). let right = point(&s, &format!("sheet:Body1:F{sd}.1:top")); assert!((right.x - 319.0).abs() < 1e-3, "{right:?}"); run(&mut s, "parameters.change", json!({"name": width, "expression": "400"})); @@ -95,7 +98,7 @@ fn a_trays_faces_have_readable_sheet_names_that_follow_its_size() { let right = point(&s, &format!("sheet:Body1:F{sd}.1:top")); assert!((right.x - 399.0).abs() < 1e-3, "{right:?}"); let far = point(&s, &format!("sheet:Body1:F{fb}.1:rim.far")); - assert!((far.y - 199.5).abs() < 1e-3 && (far.z - 30.0).abs() < 1e-3, "{far:?}"); + assert!((199.0 - 1e-3..=200.0 + 1e-3).contains(&far.y) && (0.0..=400.0).contains(&far.x) && (far.z - 30.0).abs() < 1e-3, "{far:?}"); } #[test] diff --git a/crates/engine/src/cmd/sheet_tests.rs b/crates/engine/src/cmd/sheet_tests.rs index 330d2a40f..bb6e3a362 100644 --- a/crates/engine/src/cmd/sheet_tests.rs +++ b/crates/engine/src/cmd/sheet_tests.rs @@ -5424,8 +5424,10 @@ fn flat_exports(s: &mut Session) -> Vec> { /// 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. +/// from its moved model where it is. A mirrored copy's model is its source's mirrored in the +/// flat (x → −x) with the same thickness side (`SheetBody::copied`, d9d6af51c, as +/// `a_mirrored_sheet_copy_is_the_opposite_hand_with_the_mirror_image_flat_pattern` has it): the +/// opposite hand's blank, each bend turning the same way, its pocket on the same face. #[test] fn a_mirrored_or_patterned_sheet_body_is_sheet_metal_with_its_flat_pattern() { use solidcraft_geom::Vec3; @@ -5443,10 +5445,13 @@ fn a_mirrored_or_patterned_sheet_body_is_sheet_metal_with_its_flat_pattern() { 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}"); + // The source's blank and pocket mirrored, the same size, bend and pocket side. + assert_eq!(mirrored["flat_size_mm"], blank["flat_size_mm"], "{mirrored}"); + assert_eq!(flat_points(&mirrored["outline"], 1.0), flat_points(&blank["outline"], -1.0), "the mirrored blank: {mirrored}"); + let pocket = |f: &Value| json!([f["pockets"][0]["outline"]]); + assert_eq!(flat_points(&pocket(&mirrored), 1.0), flat_points(&pocket(&blank), -1.0), "{mirrored}"); + assert_eq!((&blank["pockets"][0]["side"], &mirrored["pockets"][0]["side"]), (&json!("bottom"), &json!("bottom")), "{mirrored}"); + assert_eq!((&blank["bends"][0]["direction"], &mirrored["bends"][0]["direction"]), (&json!("up"), &json!("up")), "{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 diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rs index f9e1578be..08ef485eb 100644 --- a/crates/engine/src/cmd/sketch_modify_tests.rs +++ b/crates/engine/src/cmd/sketch_modify_tests.rs @@ -1259,8 +1259,12 @@ fn free_form_profiles_extrude_exactly() { run(&mut s, "solid.extrude", json!({"distance": 5})); let v = vol(&mut s); assert!((v - pi * 40.0 * 5.0).abs() / (pi * 200.0) < 2e-4, "{v}"); + // An exact ellipse: its side's area is h times the perimeter, 4a E(e), e² = 1 − b²/a² + // (by the Gauss–Kummer series, P = 46.026225), and only the top and bottom are planes. let m = run(&mut s, "inspect.measure", json!({})); - assert_eq!(m["bodies"][0]["faces"], 3, "an exact ellipse: top, bottom and one side ({m})"); + let area = m["bodies"][0]["area_mm2"].as_f64().unwrap_or(f64::NAN); + assert!((area - (2.0 * pi * 40.0 + 5.0 * 46.026_225_191_329_7)).abs() < 1e-4, "{area} ({m})"); + assert_eq!(m["bodies"][0]["face_types"]["plane"], 2, "{m}"); // A region closed by a fit spline and a line. let mut s = new_sketch(); let sp = ids(&run(&mut s, "sketch.spline.fit_point", json!({"points": [[0, 0], [10, 8], [20, 0]]}))["curves"])[0].clone(); @@ -1270,8 +1274,9 @@ fn free_form_profiles_extrude_exactly() { run(&mut s, "solid.extrude", json!({"distance": 2})); let v = vol(&mut s); assert!((v - a * 2.0).abs() / (a * 2.0) < 2e-4, "{v} vs {}", a * 2.0); + // Exact: the spline's side is curved, the planes are the top, the bottom and the line's side. let m = run(&mut s, "inspect.measure", json!({})); - assert!(m["bodies"][0]["faces"].as_u64().unwrap() <= 5, "{m}"); + assert_eq!(m["bodies"][0]["face_types"]["plane"], 3, "{m}"); } #[test] diff --git a/crates/engine/src/tests/mesh_convert.rs b/crates/engine/src/tests/mesh_convert.rs index a4c18a06f..d7df821aa 100644 --- a/crates/engine/src/tests/mesh_convert.rs +++ b/crates/engine/src/tests/mesh_convert.rs @@ -493,8 +493,31 @@ fn open_in_easyprint_hands_the_host_a_3mf_or_an_stl_that_reads_back() { let seen = seen.lock().unwrap(); assert_eq!((seen[0].0.ends_with(".3mf"), seen[1].0.ends_with(".stl")), (true, true), "{:?}", seen.iter().map(|u| &u.0).collect::>()); assert!(seen[0].1.starts_with(b"PK"), "a 3MF is a zip"); - // A binary STL: 80-byte header, a count, 50 bytes a triangle, and a box has 12. - assert_eq!(seen[1].1.len(), 84 + 50 * 12); + // The STL reads back as the imported mesh: its triangles, closed (every side shared by two + // triangles, each way once), enclosing the 10 × 20 × 30 box's 6000 mm³. + let imported = match &s.doc.features[0].kind { + FeatureKind::MeshImport { meshes, .. } => meshes[0].triangles.len() / 3, + other => panic!("{other:?}"), + }; + let tris = solidcraft_io::read_stl(&seen[1].1).unwrap(); + assert_eq!(tris.len(), imported); + let key = |p: [f32; 3]| p.map(f32::to_bits); + let mut sides = std::collections::HashMap::<_, i32>::new(); + for t in &tris { + for i in 0..3 { + let (a, b) = (key(t[i]), key(t[(i + 1) % 3])); + *sides.entry(if a < b { (a, b) } else { (b, a) }).or_default() += if a < b { 1 } else { -1 }; + } + } + assert!(sides.values().all(|n| *n == 0), "an open or inconsistently wound STL"); + let at = |p: [f32; 3]| Vec3::new(p[0].into(), p[1].into(), p[2].into()); + let volume: f64 = tris.iter().map(|t| at(t[0]).dot(at(t[1]).cross(at(t[2]))) / 6.0).sum(); + assert!((volume - 6000.0).abs() < 1e-6, "{volume}"); + let (lo, hi) = tris + .iter() + .flatten() + .fold(([f32::MAX; 3], [f32::MIN; 3]), |(lo, hi), p| (std::array::from_fn(|i| lo[i].min(p[i])), std::array::from_fn(|i| hi[i].max(p[i])))); + assert_eq!((lo, hi), ([0.0; 3], [10.0, 20.0, 30.0])); } #[test]