forked from 1b-agent/opencadstudio-upstream
fix: address open PR review findings
This commit is contained in:
1 parent
3fe91fa6e1
commit
2f741d689f
8 files changed
+36
-13
No files matched your search
+12
-1
@@ -110,7 +110,12 @@ pub fn format_length(value: f64) -> String {
|
||||
/// rotation leaves coordinates like -1e-15 behind, which read as `-0.0000`.
|
||||
fn without_negative_zero(text: String) -> String {
|
||||
match text.strip_prefix('-') {
|
||||
Some(rest) if !rest.chars().any(|c| matches!(c, '1'..='9')) => rest.to_string(),
|
||||
Some(rest)
|
||||
if rest.chars().any(|c| c.is_ascii_digit())
|
||||
&& !rest.chars().any(|c| matches!(c, '1'..='9')) =>
|
||||
{
|
||||
rest.to_string()
|
||||
}
|
||||
_ => text,
|
||||
}
|
||||
}
|
||||
@@ -1276,4 +1281,10 @@ mod negative_zero_format_tests {
|
||||
assert_eq!(angle(0, 0, -45f64.to_radians()), "-45°");
|
||||
assert_eq!(angle(1, 1, -0.0001f64.to_radians()), "-0d0'0.4\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_negative_infinite_value_keeps_its_sign() {
|
||||
assert_eq!(length(2, 4, f64::NEG_INFINITY), "-inf");
|
||||
assert_eq!(angle(0, 0, f64::NEG_INFINITY), "-inf°");
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -75,7 +75,12 @@ pub fn parse_obj(src: &str, color: [f32; 4]) -> Option<MeshModel> {
|
||||
for (vi, (pos_i, norm_i)) in face_verts.iter().enumerate() {
|
||||
let pos = *positions.get(*pos_i).unwrap_or(&[0.0; 3]);
|
||||
verts.push(pos);
|
||||
let norm = norm_i.and_then(|ni| normals_raw.get(ni).copied());
|
||||
let norm = norm_i
|
||||
.and_then(|ni| normals_raw.get(ni).copied())
|
||||
.filter(|n| {
|
||||
n.iter().all(|value| value.is_finite())
|
||||
&& n.iter().map(|value| value * value).sum::<f32>() > 1e-12
|
||||
});
|
||||
has_normal.push(norm.is_some());
|
||||
norms.push(norm.unwrap_or([0.0, 0.0, 0.0]));
|
||||
indices.push(vi as u32);
|
||||
@@ -153,6 +158,13 @@ mod tests {
|
||||
assert_normals(&mesh.normals, [0.0, 0.0, 1.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_zero_normal_gets_the_face_normal() {
|
||||
let src = format!("{SQUARE}vn 0 0 0\nf 1//1 2//1 3//1\n");
|
||||
let mesh = parse_obj(&src, COLOR).expect("mesh");
|
||||
assert_normals(&mesh.normals, [0.0, 0.0, 1.0]);
|
||||
}
|
||||
|
||||
/// Only the vertex with a bad index is filled; its neighbours keep theirs.
|
||||
#[test]
|
||||
fn only_the_vertex_without_a_normal_is_filled() {
|
||||
|
||||
Reference in new issue
Block a user