camera: clippy hygiene in night-merge channel loops and tests
- Commit
8c7b3d6e278edbe17d092819ace9fc0a33a311bd- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 22:01 UTC (4 days ago)
- Parents
9439a83
Workspace clippy flagged the fixed 0..3 channel loops in raw_night: they are now a gains zip, enumerate over the bilinear output, an iter_mut scale, a sum/min/max zip chain, and enumerate over the tone-mapped pixel -- each writing the same channels in the same order. In tests: a vec! passed by reference is now an array slice, a 0 + 1 argument is 1, a fill loop is slice fill, a one-element clone array is slice::from_ref, and parenthesised reference arguments in wave tests are plain references. Left standing: three noop-operation notes in seam_tests where 1 * 8 + col is deliberate row*width+col layout arithmetic. Verified: cargo clippy -p camera_stitch --all-targets shows only those three, cargo test -p camera_stitch (144 passed), fmt clean.
Diff
camera/src/main/rust/src/blend_tests.rs
diff --git a/camera/src/main/rust/src/blend_tests.rs b/camera/src/main/rust/src/blend_tests.rsindex 0e5822f3bf..62cbe19048 100644--- a/camera/src/main/rust/src/blend_tests.rs+++ b/camera/src/main/rust/src/blend_tests.rs@@ -28,7 +28,7 @@ fn box_blur_preserves_constant_plane_including_borders() { out[4 * 9 + 4] ); // A radius larger than the image and a non-square plane too.- let out2 = box_blur(&vec![3.5f32; 20], 5, 4, 3);+ let out2 = box_blur(&[3.5f32; 20], 5, 4, 3); assert!(out2.iter().all(|v| approx(*v, 3.5)), "small plane preserved: {out2:?}"); } @@ -56,7 +56,7 @@ fn reflect_101_mirrors_without_repeating_border() { assert_eq!(reflect_101(-3, 5), 3); // Degenerate widths collapse to 0 instead of looping forever. assert_eq!(reflect_101(7, 1), 0);- assert_eq!(reflect_101(-7, 0 + 1), 0);+ assert_eq!(reflect_101(-7, 1), 0); } #[test]@@ -137,9 +137,7 @@ fn content_rect_prefers_wide_short_over_narrow_tall_on_area() { // rectangle by area is the 5x1 row (area 5) vs 1x3 column (area 3) vs // any 2-wide sub-rectangle (area <= 4). let mut valid = vec![false; 25];- for x in 0..5 {- valid[x] = true;- }+ valid[..5].fill(true); for y in 0..3 { valid[y * 5] = true; }
camera/src/main/rust/src/night_tests.rs
diff --git a/camera/src/main/rust/src/night_tests.rs b/camera/src/main/rust/src/night_tests.rsindex 7b3cf23311..aac7754641 100644--- a/camera/src/main/rust/src/night_tests.rs+++ b/camera/src/main/rust/src/night_tests.rs@@ -74,7 +74,7 @@ fn solid(w: usize, h: usize, c: [u8; 4]) -> Rgba { fn align_and_merge_degenerate_inputs() { assert!(align_and_merge(&[]).is_none()); let one = solid(6, 4, [12, 34, 56, 255]);- let out = align_and_merge(&[one.clone()]).expect("single frame passes through");+ let out = align_and_merge(std::slice::from_ref(&one)).expect("single frame passes through"); assert_eq!(out.px, one.px); }
camera/src/main/rust/src/raw_night.rs
diff --git a/camera/src/main/rust/src/raw_night.rs b/camera/src/main/rust/src/raw_night.rsindex 1f0417982b..00d481da9c 100644--- a/camera/src/main/rust/src/raw_night.rs+++ b/camera/src/main/rust/src/raw_night.rs@@ -196,8 +196,8 @@ pub fn demosaic(frame: &RawFrame) -> LinearRgb { + at(x + 1, y + 1).0) * 0.25; }- for c in 0..3 {- rgb[c] *= frame.meta.gains[c];+ for (v, g) in rgb.iter_mut().zip(&frame.meta.gains) {+ *v *= g; } px[y as usize * w + x as usize] = rgb; }@@ -300,10 +300,10 @@ fn sample_linear_rgb(img: &LinearRgb, fx: f32, fy: f32) -> Option<[f32; 3]> { let y1 = (y0 + 1).min(img.h - 1); let (ax, ay) = (fx - x0 as f32, fy - y0 as f32); let mut out = [0f32; 3];- for c in 0..3 {+ for (c, o) in out.iter_mut().enumerate() { let top = img.px[y0 * img.w + x0][c] * (1.0 - ax) + img.px[y0 * img.w + x1][c] * ax; let bot = img.px[y1 * img.w + x0][c] * (1.0 - ax) + img.px[y1 * img.w + x1][c] * ax;- out[c] = top * (1.0 - ay) + bot * ay;+ *o = top * (1.0 - ay) + bot * ay; } Some(out) }@@ -351,17 +351,17 @@ pub fn merge_raw_linear(frames: &[RawFrame]) -> Option<LinearRgb> { let (sx, sy) = apply_h(&warp, x as f64, y as f64); let Some(mut c) = sample_linear_rgb(f, sx as f32, sy as f32) else { continue }; let norm = ref_scale / frames[i].meta.exposure_scale.max(1e-6);- for ch in 0..3 {- c[ch] *= norm;+ for v in &mut c {+ *v *= norm; } let diff = (c[0] - rp[0]).abs() + (c[1] - rp[1]).abs() + (c[2] - rp[2]).abs(); if diff > LINEAR_GHOST_THRESH { continue; }- for ch in 0..3 {- sum[ch] += c[ch];- min[ch] = min[ch].min(c[ch]);- max[ch] = max[ch].max(c[ch]);+ for (((s, mn), mx), v) in sum.iter_mut().zip(&mut min).zip(&mut max).zip(&c) {+ *s += *v;+ *mn = (*mn).min(*v);+ *mx = (*mx).max(*v); } count += 1; }@@ -382,12 +382,12 @@ pub fn tone_map(img: &LinearRgb, exposure_gain: f32) -> Rgba { let mut out = Rgba::new(img.w, img.h); for i in 0..img.w * img.h { let mut px = [0u8; 4];- for c in 0..3 {+ for (c, out_c) in px.iter_mut().take(3).enumerate() { let mut v = (img.px[i][c] * exposure_gain).max(0.0); if v > 0.8 { v = 0.8 + (v - 0.8) / (1.0 + (v - 0.8)); }- px[c] = (v.powf(1.0 / 2.2).clamp(0.0, 1.0) * 255.0).round() as u8;+ *out_c = (v.powf(1.0 / 2.2).clamp(0.0, 1.0) * 255.0).round() as u8; } px[3] = 255; out.px[i * 4..i * 4 + 4].copy_from_slice(&px);
camera/src/main/rust/src/wave_tests.rs
diff --git a/camera/src/main/rust/src/wave_tests.rs b/camera/src/main/rust/src/wave_tests.rsindex 2b0ec58937..f6f6bb04b1 100644--- a/camera/src/main/rust/src/wave_tests.rs+++ b/camera/src/main/rust/src/wave_tests.rs@@ -72,7 +72,7 @@ fn wave_correct_applies_one_common_rotation_to_all() { } for (i, rel) in rel_before.iter().enumerate() { let after = cams[i].r.transpose() * cams[i + 1].r;- assert!(approx(mdiff(&(after), &(rel)), 0.0, 1e-9), "relative rotation {i} changed");+ assert!(approx(mdiff(&after, rel), 0.0, 1e-9), "relative rotation {i} changed"); } } @@ -85,7 +85,7 @@ fn wave_correct_is_idempotent_up_to_tolerance() { let once: Vec<Matrix3<f64>> = cams.iter().map(|c| c.r).collect(); wave_correct_horizontal(&mut cams); for (c, before) in cams.iter().zip(once.iter()) {- assert!(mdiff(&(c.r), &(before)) < 1e-6, "second pass moved cameras");+ assert!(mdiff(&c.r, before) < 1e-6, "second pass moved cameras"); assert_rotation(&c.r); } }