mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-31 13:38:14 -06:00
Merge PR #2540
This commit is contained in:
@@ -24,7 +24,7 @@ impl Lut3d {
|
||||
let mut data = Vec::new();
|
||||
let three = |rest: &str| -> Option<[f32; 3]> {
|
||||
let v: Vec<f32> = rest.split_whitespace().filter_map(|x| x.parse().ok()).collect();
|
||||
(v.len() == 3).then(|| [v[0], v[1], v[2]])
|
||||
(v.len() == 3 && v.iter().all(|x| x.is_finite())).then(|| [v[0], v[1], v[2]])
|
||||
};
|
||||
for line in text.lines() {
|
||||
let l = line.trim();
|
||||
@@ -140,4 +140,19 @@ mod tests {
|
||||
assert!(Lut3d::parse_cube("LUT_1D_SIZE 4\n0 0 0").is_err());
|
||||
assert!(Lut3d::parse_cube("LUT_3D_SIZE 2\n0 0 0\n").is_err(), "too few entries");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_finite_entries_rejected() {
|
||||
let bad_line = |body: &str| {
|
||||
let e = Lut3d::parse_cube(body).expect_err(body);
|
||||
assert!(e.starts_with("bad line"), "{e}");
|
||||
};
|
||||
bad_line(&format!("LUT_3D_SIZE 2\n{}", "-inf inf nan\n".repeat(8)));
|
||||
bad_line(&format!("LUT_3D_SIZE 2\n{}", "1e39 0 0\n".repeat(8)));
|
||||
bad_line(&format!("LUT_3D_SIZE 2\n-inf 0 0\n{}", "0 0 0\n".repeat(7)));
|
||||
let ok = cube(|c| c, 2);
|
||||
assert!(Lut3d::parse_cube(&ok).is_ok());
|
||||
assert!(Lut3d::parse_cube(&format!("DOMAIN_MIN nan 0 0\n{ok}")).is_err());
|
||||
assert!(Lut3d::parse_cube(&format!("DOMAIN_MAX inf 1 1\n{ok}")).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user