#3830: keep four .3dl tokens and a spare mesh row at small limits

This commit is contained in:
arnav-hiwarkar committed 2026-11-18 15:38:08 +05:30
1 parent 648ae78591
commit bf31b65271
2 files changed
+9 -2

No files matched your search

+4 -2
View File
@@ -59,7 +59,7 @@ pub(super) fn parse_3dl_limited(text: &str, max_side: usize) -> Option<Lut> {
}
continue;
}
let v: Vec<f64> = l.split_whitespace().filter_map(|t| t.parse().ok()).take(max_side.saturating_add(1)).collect();
let v: Vec<f64> = l.split_whitespace().filter_map(|t| t.parse().ok()).take(max_side.max(3).saturating_add(1)).collect();
if v.len() > 3 && mesh.is_none() && rows.is_empty() {
// The mesh length is the lattice side: refuse one no lattice reader accepts (#3830).
if v.len() > max_side {
@@ -67,7 +67,9 @@ pub(super) fn parse_3dl_limited(text: &str, max_side: usize) -> Option<Lut> {
}
mesh = Some(v);
} else if v.len() == 3 {
if rows.len() >= max_side.saturating_pow(3) {
// One spare row while no mesh is known: a 3-entry mesh reads as a data row until the
// count tells them apart below.
if rows.len() >= max_side.saturating_pow(3).saturating_add(usize::from(mesh.is_none())) {
return None;
}
rows.push([v[0], v[1], v[2]]);
+5
View File
@@ -583,4 +583,9 @@ fn a_3dl_lattice_is_capped_at_the_largest_side() {
assert!(lut::parse_3dl_limited(&table_3dl(5, mesh), 4).is_none(), "mesh {mesh}");
assert!(lut::parse_3dl_limited(&table_3dl(5, mesh), 5).is_some(), "mesh {mesh}");
}
// A 3-entry mesh reads as a 28th row until the count separates it, and a four-value row is
// still refused at the smallest limit.
assert!(lut::parse_3dl_limited(&table_3dl(3, true), 3).is_some_and(|l| l.n3 == 3));
let four = table_3dl(2, false).replacen("7 7 7", "7 7 7 7", 1);
assert!(lut::parse_3dl_limited(&four, 2).is_none());
}