Emit floats an f32 can hold, and drop the format! that formats nothing

CI runs cargo fmt --check and clippy -D warnings, and this branch had
never been through either. Both would have failed it.

The bulk was the generated colour tables: eight significant figures where
an f32 carries about 7.2, so the eighth is noise that rounds away at
compile time and clippy's excessive_precision says so 109 times over.
Fixed in the generator rather than only in the file, so it stays fixed --
and the file is trimmed in place rather than re-derived, because
regenerating it needs a colour-science stack that has nothing to do with
the defect.

The format! in the composer is mine too, from extracting the rendering
tail: the braces in it were escaped because the text used to live inside a
larger template, and once extracted the escapes are noise and the call
formats nothing.

Also here, and clearly not mine: an unused import and a shadowed binding
in dr-gpu, and an unused import in a test. They are pre-existing --
clippy has been failing on master before this branch existed, on lints
like is_multiple_of that arrived with a toolchain rather than with
anyone's code. Fixed because CI cannot go green around them, and called
out because a merge commit is a bad place to quietly edit someone else's
crate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-25 22:28:14 +02:00
co-authored by Claude Opus 5
parent 6925aa2a86
commit 3b5952769b
18 changed files with 490 additions and 315 deletions
+13 -6
View File
@@ -155,7 +155,10 @@ impl Profile {
));
}
if self.density_curves.len() < 2 {
return Err(format!("{}: density_curves needs at least two samples", self.stock));
return Err(format!(
"{}: density_curves needs at least two samples",
self.stock
));
}
if self.log_exposure_max <= self.log_exposure_min {
return Err(format!(
@@ -184,8 +187,8 @@ impl Profile {
let span = self.log_exposure_max - self.log_exposure_min;
let mut out = [0.0f32; 3];
for (c, slot) in out.iter_mut().enumerate() {
let t = ((log_exposure[c] - self.log_exposure_min) / span).clamp(0.0, 1.0)
* last as f32;
let t =
((log_exposure[c] - self.log_exposure_min) / span).clamp(0.0, 1.0) * last as f32;
let i = (t.floor() as usize).min(last - 1);
let f = t - i as f32;
*slot = self.density_curves[i][c] * (1.0 - f) + self.density_curves[i + 1][c] * f;
@@ -232,8 +235,9 @@ where
{
use serde::de::Error as _;
let v = Vec::<f32>::deserialize(d)?;
v.try_into()
.map_err(|v: Vec<f32>| D::Error::custom(format!("expected {SPECTRUM} samples, got {}", v.len())))
v.try_into().map_err(|v: Vec<f32>| {
D::Error::custom(format!("expected {SPECTRUM} samples, got {}", v.len()))
})
}
#[cfg(test)]
@@ -338,7 +342,10 @@ mod tests {
let p = portra();
let blue = p.base_density[16]; // 460nm
let red = p.base_density[64]; // 700nm
assert!(blue > red + 0.2, "base density blue {blue} red {red} is not a mask");
assert!(
blue > red + 0.2,
"base density blue {blue} red {red} is not a mask"
);
}
#[test]