fix: address open pull request review findings

This commit is contained in:
Hakan Seven committed 2026-09-14 19:58:35 +03:00
1 parent 2d20bdd51c
commit f2fd2ae5ad
7 files changed
+86 -449

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ pub fn build_step(meshes: &[&MeshModel]) -> Option<String> {
let nx = ab[1] * ac[2] - ab[2] * ac[1];
let ny = ab[2] * ac[0] - ab[0] * ac[2];
let nz = ab[0] * ac[1] - ab[1] * ac[0];
let len = (nx * nx + ny * ny + nz * nz).sqrt();
let len = nx.hypot(ny).hypot(nz);
let n = if len == 0.0 && i0 < normals.len() {
normals[i0]
} else {
+11 -1
View File
@@ -48,7 +48,7 @@ pub fn build_stl(meshes: &[&MeshModel]) -> Option<Vec<u8>> {
let nx = ab[1] * ac[2] - ab[2] * ac[1];
let ny = ab[2] * ac[0] - ab[0] * ac[2];
let nz = ab[0] * ac[1] - ab[1] * ac[0];
let len = (nx * nx + ny * ny + nz * nz).sqrt();
let len = nx.hypot(ny).hypot(nz);
let normal = if len == 0.0 && i0 < mesh.normals.len() {
mesh.normals[i0]
} else {
@@ -159,6 +159,16 @@ mod tests {
assert_eq!(first_facet_normal(&stl), [0.0, 0.0, 1.0]);
}
#[test]
fn a_facet_whose_squared_cross_product_underflows_keeps_its_own_normal() {
let mesh = triangle(
vec![[0.0, 0.0, 0.0], [1.0e-12, 0.0, 0.0], [0.0, 1.0e-12, 0.0]],
vec![[0.0, 1.0, 0.0]; 3],
);
let stl = build_stl(&[&mesh]).expect("stl");
assert_eq!(first_facet_normal(&stl), [0.0, 0.0, 1.0]);
}
/// A facet with no area has no normal of its own, so it keeps the one
/// the mesh gives it rather than a zero vector.
#[test]