Skip to content

Commit c49b344

Browse files
MagicalTuxclaude
andcommitted
style: apply rustfmt across recent additions
CI's cargo fmt --check has been failing since the QR/rotated-1D/App Clip work landed unformatted. No functional changes; tests, clippy and doc builds verified clean locally with --all-features. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c4c43f8 commit c49b344

13 files changed

Lines changed: 186 additions & 86 deletions

File tree

‎examples/cropdecode.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ fn main() {
3737
let (cw, ch) = (x1 - x0, y1 - y0);
3838
let mut crop = vec![0u8; cw * ch];
3939
for y in 0..ch {
40-
crop[y * cw..(y + 1) * cw]
41-
.copy_from_slice(&luma[(y0 + y) * w + x0..(y0 + y) * w + x1]);
40+
crop[y * cw..(y + 1) * cw].copy_from_slice(&luma[(y0 + y) * w + x0..(y0 + y) * w + x1]);
4241
}
4342
let frame = anyd::GrayFrame::new(&crop, cw, ch).unwrap();
4443
if let Some(out) = dump {

‎src/codes/appclip/codec.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ const TEMPLATE_BITS: [bool; 8] = [false, true, false, true, false, true, false,
4343
/// Encode a compressed-URL payload (≤ 16 bytes) into the final ring bit vector.
4444
pub fn encode_payload(payload: &[u8]) -> Result<Vec<bool>> {
4545
let trimmed: &[u8] = {
46-
let start = payload.iter().position(|&b| b != 0).unwrap_or(payload.len());
46+
let start = payload
47+
.iter()
48+
.position(|&b| b != 0)
49+
.unwrap_or(payload.len());
4750
&payload[start..]
4851
};
4952
if trimmed.len() > 16 {
@@ -60,7 +63,10 @@ pub fn encode_payload(payload: &[u8]) -> Result<Vec<bool>> {
6063
let scrambled: Vec<u8> = (0..total).map(|i| padded[total - 1 - i] ^ 0xA5).collect();
6164

6265
let gf256 = Gf::f256();
63-
let gaps_syms: Vec<usize> = scrambled[..fp.gaps_data].iter().map(|&b| b as usize).collect();
66+
let gaps_syms: Vec<usize> = scrambled[..fp.gaps_data]
67+
.iter()
68+
.map(|&b| b as usize)
69+
.collect();
6470
let mut gaps_bits = symbols_to_bits(&rs_encode(&gf256, &gaps_syms, fp.gaps_parity), 8);
6571

6672
// Invert so the gaps ring always holds more zero (visible) than one bits.
@@ -183,7 +189,8 @@ fn symbols_to_bits(symbols: &[usize], bits_per: usize) -> Vec<bool> {
183189
}
184190

185191
fn bits_to_symbol(bits: &[bool]) -> usize {
186-
bits.iter().fold(0usize, |acc, &b| (acc << 1) | usize::from(b))
192+
bits.iter()
193+
.fold(0usize, |acc, &b| (acc << 1) | usize::from(b))
187194
}
188195

189196
#[cfg(test)]

‎src/codes/appclip/gf.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ fn syndromes(gf: &Gf, codeword: &[usize], num_parity: usize) -> Vec<usize> {
133133
(0..num_parity)
134134
.map(|si| {
135135
let root = gf.pow((gf.fcr + si) as isize);
136-
codeword.iter().fold(0usize, |acc, &sym| gf.mul(acc, root) ^ sym)
136+
codeword
137+
.iter()
138+
.fold(0usize, |acc, &sym| gf.mul(acc, root) ^ sym)
137139
})
138140
.collect()
139141
}

‎src/codes/appclip/huffman.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,13 @@ impl MultiCoder {
244244

245245
/// Decode symbols from `data` at `*pos` until `stop` is produced (included in the
246246
/// result), the bits run out, or no code matches.
247-
pub fn decode(&self, data: &[bool], pos: &mut usize, stop: Option<char>, start_ctx: &str) -> String {
247+
pub fn decode(
248+
&self,
249+
data: &[bool],
250+
pos: &mut usize,
251+
stop: Option<char>,
252+
start_ctx: &str,
253+
) -> String {
248254
let (mut node, mut depth) = (0usize, 0usize);
249255
for c in start_ctx.chars() {
250256
let Some(idx) = self.symbol_index(c) else {

‎src/codes/appclip/scan.rs‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,14 @@ impl Gray {
164164
let inv = 1.0 / scale;
165165
for y in 0..dh {
166166
let sy0 = (y as f64 * inv) as usize;
167-
let sy1 = (((y + 1) as f64 * inv).ceil() as usize).min(self.h).max(sy0 + 1);
167+
let sy1 = (((y + 1) as f64 * inv).ceil() as usize)
168+
.min(self.h)
169+
.max(sy0 + 1);
168170
for x in 0..dw {
169171
let sx0 = (x as f64 * inv) as usize;
170-
let sx1 = (((x + 1) as f64 * inv).ceil() as usize).min(self.w).max(sx0 + 1);
172+
let sx1 = (((x + 1) as f64 * inv).ceil() as usize)
173+
.min(self.w)
174+
.max(sx0 + 1);
171175
let mut sum = 0.0;
172176
for sy in sy0..sy1 {
173177
for sx in sx0..sx1 {
@@ -701,7 +705,14 @@ fn sample_positions(gray: &Gray, x: &Xform, theta_deg: f64) -> Option<Vec<Positi
701705
for pos in 0..n {
702706
let angle = (ring_rot + theta_deg + pos as f64 * bit_angle).to_radians();
703707

704-
let boundary = patch(gray, x, radius, angle, jitter, &[-STROKE * 0.22, 0.0, STROKE * 0.22])?;
708+
let boundary = patch(
709+
gray,
710+
x,
711+
radius,
712+
angle,
713+
jitter,
714+
&[-STROKE * 0.22, 0.0, STROKE * 0.22],
715+
)?;
705716
let bg_off = STROKE * 0.85;
706717
let inner = patch(gray, x, radius - bg_off, angle, jitter * 0.6, &[0.0])?;
707718
let outer = patch(gray, x, radius + bg_off, angle, jitter * 0.6, &[0.0])?;
@@ -867,7 +878,10 @@ fn decode_candidate(gray: &Gray, field: &EdgeField, cand: Candidate) -> Option<S
867878
x.angle.to_degrees(),
868879
x.sx,
869880
x.sy,
870-
thetas.iter().map(|t| (t * 10.0).round() / 10.0).collect::<Vec<_>>()
881+
thetas
882+
.iter()
883+
.map(|t| (t * 10.0).round() / 10.0)
884+
.collect::<Vec<_>>()
871885
);
872886
}
873887
for theta in thetas {
@@ -923,8 +937,8 @@ fn decode_attempts(samples: &[PositionSample]) -> Vec<Vec<bool>> {
923937
mi += 1;
924938
}
925939
}
926-
let penalty = f64::from(template_mismatch(&bits)) * 10.0
927-
+ (visible_count as f64 - 64.0).abs();
940+
let penalty =
941+
f64::from(template_mismatch(&bits)) * 10.0 + (visible_count as f64 - 64.0).abs();
928942
attempts.push((penalty, bits));
929943
}
930944
}

‎src/codes/appclip/svg.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@ fn write_logo(s: &mut String, logo: LogoKind, pal: &Palette) {
246246
LogoKind::Camera => {
247247
s.push_str(" <g id=\"Logo\" data-logo-type=\"Camera\" transform=\"translate(293.275699 293.275699) scale(1.874000 1.874000)\">\n");
248248
for p in CAMERA_PATHS {
249-
let _ = writeln!(s, " <path d=\"{p}\" style=\"fill:{}\"/>", pal.foreground.hex());
249+
let _ = writeln!(
250+
s,
251+
" <path d=\"{p}\" style=\"fill:{}\"/>",
252+
pal.foreground.hex()
253+
);
250254
}
251255
}
252256
}

‎src/codes/appclip/tables.rs‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,25 @@ pub(super) const FIXED6_ALPHABET: &[u8; 64] =
327327

328328
/// Host coder alphabet: `- . 0-9 a-z |` (39 symbols).
329329
pub(super) const HOST_SYMBOLS: [&str; 39] = [
330-
"-", ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f",
331-
"g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
332-
"y", "z", "|",
330+
"-", ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g",
331+
"h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
332+
"|",
333333
];
334334

335335
/// Combined path/query coder alphabet (75 symbols).
336336
pub(super) const CPQ_SYMBOLS: [&str; 75] = [
337-
"#", "%", "&", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
338-
":", ";", "=", "?", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
339-
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", "a", "b", "c", "d", "e",
340-
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
341-
"x", "y", "z",
337+
"#", "%", "&", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":",
338+
";", "=", "?", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
339+
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", "a", "b", "c", "d", "e", "f", "g", "h",
340+
"i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
342341
];
343342

344343
/// Segmented path/query coder alphabet (71 symbols).
345344
pub(super) const SPQ_SYMBOLS: [&str; 71] = [
346-
"&", "+", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "=", "?", "A",
347-
"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
348-
"T", "U", "V", "W", "X", "Y", "Z", "_", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
349-
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "|",
345+
"&", "+", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "=", "?", "A", "B",
346+
"C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
347+
"V", "W", "X", "Y", "Z", "_", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
348+
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "|",
350349
];
351350

352351
/// Index of a word in [`KNOWN_WORDS`].

‎src/codes/appclip/url.rs‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::sync::OnceLock;
1212

1313
use super::huffman::{HuffmanCoder, MultiCoder, Trie};
1414
use super::tables::{
15-
CPQ_SYMBOLS, FIXED6_ALPHABET, FIXED_TLDS, HOST_SYMBOLS, HUFFMAN_TLDS, KNOWN_WORDS,
16-
SPQ_SYMBOLS, fixed6_index, known_word_index,
15+
CPQ_SYMBOLS, FIXED_TLDS, FIXED6_ALPHABET, HOST_SYMBOLS, HUFFMAN_TLDS, KNOWN_WORDS, SPQ_SYMBOLS,
16+
fixed6_index, known_word_index,
1717
};
1818
use crate::error::{Error, Result};
1919

@@ -140,7 +140,9 @@ fn choose_path_query(path: &str, query: &str, fragment: &str) -> Result<(String,
140140
(Some(t), Some(p)) if t.len() < p.len() => Ok((t, true)),
141141
(_, Some(p)) => Ok((p, false)),
142142
(Some(t), None) => Ok((t, true)),
143-
(None, None) => Err(Error::invalid_parameter("App Clip path/query not encodable")),
143+
(None, None) => Err(Error::invalid_parameter(
144+
"App Clip path/query not encodable",
145+
)),
144146
}
145147
}
146148

@@ -491,7 +493,9 @@ enum Component {
491493
fn parse_url(raw: &str) -> Result<ParsedUrl> {
492494
let scheme = "https://";
493495
if raw.len() < scheme.len() || !raw[..scheme.len()].eq_ignore_ascii_case(scheme) {
494-
return Err(Error::invalid_parameter("App Clip URL scheme must be https"));
496+
return Err(Error::invalid_parameter(
497+
"App Clip URL scheme must be https",
498+
));
495499
}
496500
let rest = &raw[scheme.len()..];
497501
let authority_end = rest.find(['/', '?', '#']).unwrap_or(rest.len());
@@ -800,7 +804,11 @@ fn decode_segmented(data: &[bool], pos: &mut usize) -> Result<String> {
800804

801805
fn build_segmented_path(parts: &[String], root_only: bool, trailing_slash: bool) -> String {
802806
if parts.is_empty() {
803-
return if root_only { "/".to_string() } else { String::new() };
807+
return if root_only {
808+
"/".to_string()
809+
} else {
810+
String::new()
811+
};
804812
}
805813
let mut path = format!("/{}", parts.join("/"));
806814
if trailing_slash {
@@ -845,9 +853,7 @@ fn decode_segmented_query(data: &[bool], pos: &mut usize) -> Result<String> {
845853
(key, value)
846854
}
847855
_ => {
848-
return Err(Error::undecodable(
849-
"App Clip segmented query type invalid",
850-
));
856+
return Err(Error::undecodable("App Clip segmented query type invalid"));
851857
}
852858
};
853859
if !first {

‎src/codes/qr/sample.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,9 @@ impl Located {
760760
for &dv in &OFF {
761761
for &du in &OFF {
762762
let (px, py) = map(gx + du, gy + dv);
763-
if sample_dark_local(frame, px, py, integral, radius, midpoint, backstop)
764-
{
763+
if sample_dark_local(
764+
frame, px, py, integral, radius, midpoint, backstop,
765+
) {
765766
votes_dark += 1;
766767
}
767768
}

‎src/imgproc/orient.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ pub fn dominant_gradient_angle(frame: &GrayFrame<'_>) -> Option<f32> {
3737
let mut total = 0.0f32;
3838
for y in 1..h - 1 {
3939
for x in 1..w - 1 {
40-
let gx = f32::from(frame.get_unchecked(x + 1, y))
41-
- f32::from(frame.get_unchecked(x - 1, y));
42-
let gy = f32::from(frame.get_unchecked(x, y + 1))
43-
- f32::from(frame.get_unchecked(x, y - 1));
40+
let gx =
41+
f32::from(frame.get_unchecked(x + 1, y)) - f32::from(frame.get_unchecked(x - 1, y));
42+
let gy =
43+
f32::from(frame.get_unchecked(x, y + 1)) - f32::from(frame.get_unchecked(x, y - 1));
4444
let mag2 = gx * gx + gy * gy;
4545
if mag2 < MIN_MAG2 {
4646
continue;

0 commit comments

Comments
 (0)