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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-30 06:38:11 -04:00
parent 54c3b1e90e
commit f0a2c3f99d
4 changed files with 50 additions and 14 deletions
+25 -2
View File
@@ -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::<Vec<_>>());
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]