From ef999a4eb083e44374fd158d920356df0912ae82 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 28 Apr 2023 19:41:23 -0500 Subject: [PATCH] clippy fix --- src/buffered_image_luminance_source.rs | 3 +- src/client/result/EmailAddressResultParser.rs | 4 -- .../result/ExpandedProductResultParser.rs | 2 +- src/client/result/ResultParser.rs | 2 +- src/common/bit_array.rs | 2 +- .../base_extentions/qr_ec_level.rs | 2 +- .../base_extentions/qrcode_version.rs | 2 +- .../fast_edge_to_edge_counter.rs | 10 ++--- src/common/cpp_essentials/matrix.rs | 6 +-- src/common/cpp_essentials/pattern.rs | 38 +++++++++---------- src/common/hybrid_binarizer.rs | 8 ++-- src/common/quad.rs | 16 ++++---- src/datamatrix/data_matrix_reader.rs | 2 +- src/datamatrix/encoder/c40_encoder.rs | 4 +- src/datamatrix/encoder/high_level_encoder.rs | 8 ++-- src/datamatrix/encoder/text_encoder.rs | 4 +- src/datamatrix/encoder/x12_encoder.rs | 4 +- src/luma_luma_source.rs | 3 +- src/oned/code_128_writer.rs | 6 +-- src/oned/code_39_reader.rs | 4 +- src/oned/code_93_reader.rs | 4 +- .../decoder/pdf_417_decoder_test_case.rs | 2 +- .../encoder/pdf_417_high_level_encoder.rs | 6 +-- src/qrcode/cpp_port/bitmatrix_parser.rs | 18 ++++----- src/qrcode/cpp_port/data_mask.rs | 2 +- src/qrcode/cpp_port/decoder.rs | 10 ++--- src/qrcode/cpp_port/detector.rs | 32 ++++++++-------- src/qrcode/cpp_port/qr_cpp_reader.rs | 2 +- src/qrcode/cpp_port/test/QRDataMaskTest.rs | 24 ++++++------ src/qrcode/cpp_port/test/QRVersionTest.rs | 6 +-- src/qrcode/decoder/error_correction_level.rs | 4 +- src/qrcode/decoder/mode.rs | 12 +++--- src/qrcode/encoder/minimal_encoder.rs | 2 +- src/qrcode/encoder/qrcode_encoder.rs | 2 +- src/qrcode/qr_code_reader.rs | 2 +- tests/common/multiimage_span.rs | 1 - 36 files changed, 122 insertions(+), 137 deletions(-) diff --git a/src/buffered_image_luminance_source.rs b/src/buffered_image_luminance_source.rs index 1811f50..a736ec1 100644 --- a/src/buffered_image_luminance_source.rs +++ b/src/buffered_image_luminance_source.rs @@ -127,8 +127,7 @@ impl LuminanceSource for BufferedImageLuminanceSource { .collect::>(); // get all the rows we want to look at let data = unmanaged - .chunks_exact(self.image.width() as usize) - .into_iter() // Get rows + .chunks_exact(self.image.width() as usize) // Get rows .flat_map(|f| { f.iter() .skip(row_skip as usize) diff --git a/src/client/result/EmailAddressResultParser.rs b/src/client/result/EmailAddressResultParser.rs index 7329a8e..c255d60 100644 --- a/src/client/result/EmailAddressResultParser.rs +++ b/src/client/result/EmailAddressResultParser.rs @@ -63,7 +63,6 @@ pub fn parse(result: &RXingResult) -> Option { } else { COMMA .split(hostEmail) - .into_iter() .map(|s| s.to_owned()) .collect() }; @@ -81,7 +80,6 @@ pub fn parse(result: &RXingResult) -> Option { if let Some(tosString) = nv.get("to") { tos = COMMA .split(tosString) - .into_iter() .map(|s| s.to_owned()) .collect(); } @@ -92,7 +90,6 @@ pub fn parse(result: &RXingResult) -> Option { if let Some(ccString) = nv.get("cc") { ccs = COMMA .split(ccString) - .into_iter() .map(|s| s.to_owned()) .collect(); } @@ -102,7 +99,6 @@ pub fn parse(result: &RXingResult) -> Option { if let Some(bccString) = nv.get("bcc") { bccs = COMMA .split(bccString) - .into_iter() .map(|s| s.to_owned()) .collect(); } diff --git a/src/client/result/ExpandedProductResultParser.rs b/src/client/result/ExpandedProductResultParser.rs index 63eb29c..02e535c 100644 --- a/src/client/result/ExpandedProductResultParser.rs +++ b/src/client/result/ExpandedProductResultParser.rs @@ -251,7 +251,7 @@ fn findAIvalue(i: usize, rawText: &str) -> Option { if currentChar == ')' { return Some(buf); } - if !('0'..='9').contains(¤tChar) { + if !currentChar.is_ascii_digit() { return None; } buf.push(currentChar); diff --git a/src/client/result/ResultParser.rs b/src/client/result/ResultParser.rs index 997ab23..b411f62 100644 --- a/src/client/result/ResultParser.rs +++ b/src/client/result/ResultParser.rs @@ -227,7 +227,7 @@ pub fn unescapeBackslash(escaped: &str) -> String { } pub fn parseHexDigit(c: char) -> i32 { - if ('0'..='9').contains(&c) { + if c.is_ascii_digit() { return (c as u8 - b'0') as i32; } if ('a'..='f').contains(&c) { diff --git a/src/common/bit_array.rs b/src/common/bit_array.rs index 127f10f..e353974 100644 --- a/src/common/bit_array.rs +++ b/src/common/bit_array.rs @@ -431,7 +431,7 @@ impl Into> for BitArray { let mut array = vec![false; self.size]; for pixel in 0..self.size { - array[pixel] = bool::from(self.get(pixel)); + array[pixel] = self.get(pixel); } array diff --git a/src/common/cpp_essentials/base_extentions/qr_ec_level.rs b/src/common/cpp_essentials/base_extentions/qr_ec_level.rs index 730f0b7..00a5cf0 100644 --- a/src/common/cpp_essentials/base_extentions/qr_ec_level.rs +++ b/src/common/cpp_essentials/base_extentions/qr_ec_level.rs @@ -22,7 +22,7 @@ impl ErrorCorrectionLevel { ErrorCorrectionLevel::H, ErrorCorrectionLevel::Q, ]; - return LEVEL_FOR_BITS[bits as usize & 0x3]; + LEVEL_FOR_BITS[bits as usize & 0x3] } pub fn ECLevelFromBits(bits: u8, isMicro: bool) -> Self { diff --git a/src/common/cpp_essentials/base_extentions/qrcode_version.rs b/src/common/cpp_essentials/base_extentions/qrcode_version.rs index de8cad7..b471e35 100644 --- a/src/common/cpp_essentials/base_extentions/qrcode_version.rs +++ b/src/common/cpp_essentials/base_extentions/qrcode_version.rs @@ -88,7 +88,7 @@ impl Version { return Self::getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail - return Err(Exceptions::ILLEGAL_STATE); + Err(Exceptions::ILLEGAL_STATE) } pub const fn isMicroQRCode(&self) -> bool { diff --git a/src/common/cpp_essentials/fast_edge_to_edge_counter.rs b/src/common/cpp_essentials/fast_edge_to_edge_counter.rs index d28729c..5ee59ba 100644 --- a/src/common/cpp_essentials/fast_edge_to_edge_counter.rs +++ b/src/common/cpp_essentials/fast_edge_to_edge_counter.rs @@ -38,13 +38,13 @@ impl<'a> FastEdgeToEdgeCounter<'a> { } else { i32::MAX }; - let stepsToBorder = std::cmp::min(maxStepsX, maxStepsY) as i32; + let stepsToBorder = std::cmp::min(maxStepsX, maxStepsY); FastEdgeToEdgeCounter { p, stride, stepsToBorder, - _arr: cur.p().y as isize * stride as isize, //cur.img().getRow(cur.p().y as u32), + _arr: cur.p().y as isize * stride, //cur.img().getRow(cur.p().y as u32), under_arry: cur.img(), //.into(), } } @@ -66,15 +66,15 @@ impl<'a> FastEdgeToEdgeCounter<'a> { // if !(self.under_arry[idx_pt] // == self.under_arry[self.p as usize]) - if !(self.under_arry.get_index(idx_pt) == self.under_arry.get_index(self.p as usize)) { + if self.under_arry.get_index(idx_pt) != self.under_arry.get_index(self.p as usize) { break; } } // while (p[steps * stride] == p[0]); - self.p = (self.p as isize + (steps as isize * self.stride)).abs() as u32; + self.p = (self.p as isize + (steps as isize * self.stride)).unsigned_abs() as u32; self.stepsToBorder -= steps; - return steps as u32; + steps as u32 } #[inline(always)] diff --git a/src/common/cpp_essentials/matrix.rs b/src/common/cpp_essentials/matrix.rs index 8830292..69b689f 100644 --- a/src/common/cpp_essentials/matrix.rs +++ b/src/common/cpp_essentials/matrix.rs @@ -10,7 +10,7 @@ pub struct Matrix { impl Matrix { pub fn with_data(width: usize, height: usize, data: Vec>) -> Result> { - if width != 0 && data.len() / width as usize != height as usize { + if width != 0 && data.len() / width != height { return Err(Exceptions::illegal_argument_with( "invalid size: width * height is too big", )); @@ -23,7 +23,7 @@ impl Matrix { } pub fn new(width: usize, height: usize) -> Result> { - if width != 0 && (width * height) / width as usize != height as usize { + if width != 0 && (width * height) / width != height { return Err(Exceptions::illegal_argument_with( "invalid size: width * height is too big", )); @@ -60,7 +60,7 @@ impl Matrix { // } fn get_offset(x: usize, y: usize, width: usize) -> usize { - (y * width + x) as usize + y * width + x } pub fn get(&self, x: usize, y: usize) -> Option { diff --git a/src/common/cpp_essentials/pattern.rs b/src/common/cpp_essentials/pattern.rs index 2054117..f800bc7 100644 --- a/src/common/cpp_essentials/pattern.rs +++ b/src/common/cpp_essentials/pattern.rs @@ -310,7 +310,7 @@ impl<'a> std::ops::Index for PatternView<'_> { fn index(&self, index: isize) -> &Self::Output { if self.count == self.data.len() { - return &self.data[index.abs() as usize]; + return &self.data[index.unsigned_abs()]; } if index > self.data.0.len() as isize { @@ -353,7 +353,7 @@ impl<'a> std::ops::Index for PatternView<'_> { impl<'a> Into> for &PatternView<'a> { fn into(self) -> Vec { - let mut v = vec![PatternType::default(); self.count as usize]; + let mut v = vec![PatternType::default(); self.count]; for i in 0..self.count { v[i] = self[i]; } @@ -420,11 +420,11 @@ pub struct FixedPattern Into> - for FixedPattern +impl From> + for Pattern { - fn into(self) -> Pattern { - self.data + fn from(val: FixedPattern) -> Self { + val.data } } @@ -446,7 +446,7 @@ impl FixedPattern BarAndSpace { - return BarAndSpaceSum::(&self.data); + BarAndSpaceSum::(&self.data) } } @@ -584,11 +584,11 @@ pub fn IsRightGuard( ) != 0.0 } -pub fn FindLeftGuardBy<'a, const LEN: usize, Pred: Fn(&PatternView, Option) -> bool>( - view: PatternView<'a>, +pub fn FindLeftGuardBy) -> bool>( + view: PatternView<'_>, minSize: usize, isGuard: Pred, -) -> Result> { +) -> Result> { const PREV_IDX: isize = -1; if view.size() < minSize { @@ -601,11 +601,7 @@ pub fn FindLeftGuardBy<'a, const LEN: usize, Pred: Fn(&PatternView, Option) } let end = Into::::into(view.end().ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?) - minSize; while (window.start + window.current) < end { - let prev = if let Some(v) = window.try_get_index(PREV_IDX) { - Some(v as f32) - } else { - None - }; + let prev = window.try_get_index(PREV_IDX).map(|v| v as f32); if isGuard(&window, prev) { return Ok(window); } @@ -631,18 +627,18 @@ pub fn FindLeftGuard<'a, const LEN: usize, const SUM: usize, const IS_SPARCE: bo { return false; } - return IsPattern::( + IsPattern::( window, pattern, spaceInPixel, minQuietZone, 0.0, - ) != 0.0; + ) != 0.0 }) } -pub fn NormalizedE2EPattern<'a, const LEN: usize, const LEN_MINUS_2: usize, const SUM: usize>( - view: &'a PatternView, +pub fn NormalizedE2EPattern( + view: &PatternView, ) -> [PatternType; LEN_MINUS_2] { let moduleSize: f32 = Into::::into(view.sum(Some(LEN))) / SUM as f32; @@ -656,8 +652,8 @@ pub fn NormalizedE2EPattern<'a, const LEN: usize, const LEN_MINUS_2: usize, cons e2e } -pub fn NormalizedPattern<'a, const LEN: usize, const SUM: usize>( - view: &'a PatternView, +pub fn NormalizedPattern( + view: &PatternView, ) -> Result<[PatternType; LEN]> { let moduleSize: f32 = (Into::::into(view.sum(Some(LEN))) / SUM) as f32; let mut err = SUM as isize; diff --git a/src/common/hybrid_binarizer.rs b/src/common/hybrid_binarizer.rs index 663e38d..c2df49f 100644 --- a/src/common/hybrid_binarizer.rs +++ b/src/common/hybrid_binarizer.rs @@ -113,7 +113,9 @@ impl HybridBinarizer { let source = ghb.get_luminance_source(); let width = source.get_width(); let height = source.get_height(); - let matrix = if width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION { + + // dbg!(matrix.to_string()); + if width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION { let luminances = source.get_matrix(); let mut sub_width = width >> BLOCK_SIZE_POWER; if (width & BLOCK_SIZE_MASK) != 0 { @@ -146,9 +148,7 @@ impl HybridBinarizer { // If the image is too small, fall back to the global histogram approach. let m = ghb.get_black_matrix()?; Ok(m.clone()) - }; - // dbg!(matrix.to_string()); - matrix + } } /** diff --git a/src/common/quad.rs b/src/common/quad.rs index 2c920af..54518cd 100644 --- a/src/common/quad.rs +++ b/src/common/quad.rs @@ -58,20 +58,20 @@ impl Quadrilateral { Quadrilateral([ Point { - x: margin as f32, - y: margin as f32, + x: margin, + y: margin, }, Point { - x: width as f32 - margin as f32, - y: margin as f32, + x: width as f32 - margin, + y: margin, }, Point { - x: width as f32 - margin as f32, - y: height as f32 - margin as f32, + x: width as f32 - margin, + y: height as f32 - margin, }, Point { - x: margin as f32, - y: height as f32 - margin as f32, + x: margin, + y: height as f32 - margin, }, ]) } diff --git a/src/datamatrix/data_matrix_reader.rs b/src/datamatrix/data_matrix_reader.rs index d276e24..3750347 100644 --- a/src/datamatrix/data_matrix_reader.rs +++ b/src/datamatrix/data_matrix_reader.rs @@ -218,7 +218,7 @@ impl DataMatrixReader { let iOffset = top + y as f32 * moduleSize as f32; for x in 0..matrixWidth { // for (int x = 0; x < matrixWidth; x++) { - if image.get_point(point(left as f32 + x as f32 * moduleSize as f32, iOffset)) { + if image.get_point(point(left + x as f32 * moduleSize as f32, iOffset)) { bits.set(x, y); } } diff --git a/src/datamatrix/encoder/c40_encoder.rs b/src/datamatrix/encoder/c40_encoder.rs index 827d132..1be2b2a 100644 --- a/src/datamatrix/encoder/c40_encoder.rs +++ b/src/datamatrix/encoder/c40_encoder.rs @@ -246,11 +246,11 @@ impl C40Encoder { sb.push('\u{3}'); return 1; } - if ('0'..='9').contains(&c) { + if c.is_ascii_digit() { sb.push((c as u8 - 48 + 4) as char); return 1; } - if ('A'..='Z').contains(&c) { + if c.is_ascii_uppercase() { sb.push((c as u8 - 65 + 14) as char); return 1; } diff --git a/src/datamatrix/encoder/high_level_encoder.rs b/src/datamatrix/encoder/high_level_encoder.rs index 5a87ff1..1592180 100644 --- a/src/datamatrix/encoder/high_level_encoder.rs +++ b/src/datamatrix/encoder/high_level_encoder.rs @@ -551,7 +551,7 @@ fn getMinimumCount(mins: &[u8]) -> u32 { } pub fn isDigit(ch: char) -> bool { - ('0'..='9').contains(&ch) + ch.is_ascii_digit() } pub fn isExtendedASCII(ch: char) -> bool { @@ -559,15 +559,15 @@ pub fn isExtendedASCII(ch: char) -> bool { } pub fn isNativeC40(ch: char) -> bool { - (ch == ' ') || ('0'..='9').contains(&ch) || ('A'..='Z').contains(&ch) + (ch == ' ') || ch.is_ascii_digit() || ch.is_ascii_uppercase() } pub fn isNativeText(ch: char) -> bool { - (ch == ' ') || ('0'..='9').contains(&ch) || ('a'..='z').contains(&ch) + (ch == ' ') || ch.is_ascii_digit() || ch.is_ascii_lowercase() } pub fn isNativeX12(ch: char) -> bool { - isX12TermSep(ch) || (ch == ' ') || ('0'..='9').contains(&ch) || ('A'..='Z').contains(&ch) + isX12TermSep(ch) || (ch == ' ') || ch.is_ascii_digit() || ch.is_ascii_uppercase() } fn isX12TermSep(ch: char) -> bool { diff --git a/src/datamatrix/encoder/text_encoder.rs b/src/datamatrix/encoder/text_encoder.rs index 217233e..aa1e478 100644 --- a/src/datamatrix/encoder/text_encoder.rs +++ b/src/datamatrix/encoder/text_encoder.rs @@ -41,11 +41,11 @@ impl TextEncoder { sb.push('\u{3}'); return 1; } - if ('0'..='9').contains(&c) { + if c.is_ascii_digit() { sb.push((c as u8 - 48 + 4) as char); return 1; } - if ('a'..='z').contains(&c) { + if c.is_ascii_lowercase() { sb.push((c as u8 - 97 + 14) as char); return 1; } diff --git a/src/datamatrix/encoder/x12_encoder.rs b/src/datamatrix/encoder/x12_encoder.rs index 1c12a31..8cb9aae 100644 --- a/src/datamatrix/encoder/x12_encoder.rs +++ b/src/datamatrix/encoder/x12_encoder.rs @@ -66,9 +66,9 @@ impl X12Encoder { '>' => sb.push('\u{2}'), ' ' => sb.push('\u{3}'), _ => { - if ('0'..='9').contains(&c) { + if c.is_ascii_digit() { sb.push((c as u8 - 48 + 4) as char); - } else if ('A'..='Z').contains(&c) { + } else if c.is_ascii_uppercase() { sb.push((c as u8 - 65 + 14) as char); } else { high_level_encoder::illegalCharacter(c)?; diff --git a/src/luma_luma_source.rs b/src/luma_luma_source.rs index ce15bbd..9b525ee 100644 --- a/src/luma_luma_source.rs +++ b/src/luma_luma_source.rs @@ -34,7 +34,6 @@ impl LuminanceSource for Luma8LuminanceSource { .take((self.dimensions.1 * self.original_dimension.0) as usize) .collect::>() .chunks_exact(self.original_dimension.0 as usize) - .into_iter() .flat_map(|f| { f.iter() .skip((self.origin.0) as usize) @@ -182,7 +181,7 @@ mod tests { let square = Luma8LuminanceSource::new(src_square, 3, 3); let rect_tall = Luma8LuminanceSource::new(src_rect.clone(), 3, 4); - let rect_wide = Luma8LuminanceSource::new(src_rect.clone(), 4, 3); + let rect_wide = Luma8LuminanceSource::new(src_rect, 4, 3); let rotated_square = square.rotate_counter_clockwise().expect("rotate"); // print_matrix(&src_rect, 4, 3); diff --git a/src/oned/code_128_writer.rs b/src/oned/code_128_writer.rs index 540ede1..f335eb9 100644 --- a/src/oned/code_128_writer.rs +++ b/src/oned/code_128_writer.rs @@ -348,14 +348,14 @@ fn findCType(value: &str, start: usize) -> Option { if c == ESCAPE_FNC_1 { return Some(CType::Fnc1); } - if !('0'..='9').contains(&c) { + if !c.is_ascii_digit() { return Some(CType::Uncodable); } if start + 1 >= last { return Some(CType::OneDigit); } let c = value.chars().nth(start + 1)?; - if !('0'..='9').contains(&c) { + if !c.is_ascii_digit() { return Some(CType::OneDigit); } Some(CType::TwoDigits) @@ -638,7 +638,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}"; } fn isDigit(c: char) -> bool { - ('0'..='9').contains(&c) + c.is_ascii_digit() } fn canEncode(contents: &str, charset: Charset, position: usize) -> bool { diff --git a/src/oned/code_39_reader.rs b/src/oned/code_39_reader.rs index 8fe3624..cae4bb3 100644 --- a/src/oned/code_39_reader.rs +++ b/src/oned/code_39_reader.rs @@ -335,7 +335,7 @@ impl Code39Reader { match c { '+' => { // +A to +Z map to a to z - if ('A'..='Z').contains(&next) { + if next.is_ascii_uppercase() { decodedChar = char::from_u32(next as u32 + 32) .ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?; } else { @@ -344,7 +344,7 @@ impl Code39Reader { } '$' => { // $A to $Z map to control codes SH to SB - if ('A'..='Z').contains(&next) { + if next.is_ascii_uppercase() { decodedChar = char::from_u32(next as u32 - 64) .ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?; } else { diff --git a/src/oned/code_93_reader.rs b/src/oned/code_93_reader.rs index 168b8b8..1423222 100644 --- a/src/oned/code_93_reader.rs +++ b/src/oned/code_93_reader.rs @@ -250,7 +250,7 @@ impl Code93Reader { match c { 'd' => { // +A to +Z map to a to z - if ('A'..='Z').contains(&next) { + if next.is_ascii_uppercase() { decodedChar = char::from_u32(next as u32 + 32).ok_or(Exceptions::PARSE)?; } else { @@ -259,7 +259,7 @@ impl Code93Reader { } 'a' => { // $A to $Z map to control codes SH to SB - if ('A'..='Z').contains(&next) { + if next.is_ascii_uppercase() { decodedChar = char::from_u32(next as u32 - 64).ok_or(Exceptions::PARSE)?; } else { diff --git a/src/pdf417/decoder/pdf_417_decoder_test_case.rs b/src/pdf417/decoder/pdf_417_decoder_test_case.rs index e7cfeae..3c7819f 100644 --- a/src/pdf417/decoder/pdf_417_decoder_test_case.rs +++ b/src/pdf417/decoder/pdf_417_decoder_test_case.rs @@ -566,7 +566,7 @@ fn generateText( for j in 0..wordLength.ceil() as u32 { // for (int j = 0; j < wordLength; j++) { let mut c = chars[maxIndex]; - if j == 0 && ('a'..='z').contains(&c) && random.next_bool() { + if j == 0 && c.is_ascii_lowercase() && random.next_bool() { c = char::from_u32(c as u32 - 'a' as u32 + 'A' as u32).unwrap(); } result.push(c); diff --git a/src/pdf417/encoder/pdf_417_high_level_encoder.rs b/src/pdf417/encoder/pdf_417_high_level_encoder.rs index 2133370..d397fe1 100644 --- a/src/pdf417/encoder/pdf_417_high_level_encoder.rs +++ b/src/pdf417/encoder/pdf_417_high_level_encoder.rs @@ -667,15 +667,15 @@ fn encodeNumeric( } fn isDigit(ch: char) -> bool { - ('0'..='9').contains(&ch) + ch.is_ascii_digit() } fn isAlphaUpper(ch: char) -> bool { - ch == ' ' || ('A'..='Z').contains(&ch) + ch == ' ' || ch.is_ascii_uppercase() } fn isAlphaLower(ch: char) -> bool { - ch == ' ' || ('a'..='z').contains(&ch) + ch == ' ' || ch.is_ascii_lowercase() } fn isMixed(ch: char) -> bool { diff --git a/src/qrcode/cpp_port/bitmatrix_parser.rs b/src/qrcode/cpp_port/bitmatrix_parser.rs index 3059453..dc6e270 100644 --- a/src/qrcode/cpp_port/bitmatrix_parser.rs +++ b/src/qrcode/cpp_port/bitmatrix_parser.rs @@ -24,9 +24,9 @@ pub fn getBit(bitMatrix: &BitMatrix, x: u32, y: u32, mirrored: Option) -> pub fn hasValidDimension(bitMatrix: &BitMatrix, isMicro: bool) -> bool { let dimension = bitMatrix.height(); if isMicro { - dimension >= 11 && dimension <= 17 && (dimension % 2) == 1 + (11..=17).contains(&dimension) && (dimension % 2) == 1 } else { - dimension >= 21 && dimension <= 177 && (dimension % 4) == 1 + (21..=177).contains(&dimension) && (dimension % 4) == 1 } } @@ -57,7 +57,7 @@ pub fn ReadVersion(bitMatrix: &BitMatrix) -> Result { } } - return Err(Exceptions::FORMAT); + Err(Exceptions::FORMAT) } pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result { @@ -110,10 +110,10 @@ pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result) -> let isMicro = isMicro.unwrap_or(false); let mut maskIndex = maskIndex; if isMicro { - if maskIndex < 0 || maskIndex >= 4 { + if !(0..4).contains(&maskIndex) { return Err(Exceptions::illegal_argument_with( "QRCode maskIndex out of range", )); diff --git a/src/qrcode/cpp_port/decoder.rs b/src/qrcode/cpp_port/decoder.rs index 25738af..d13bd64 100644 --- a/src/qrcode/cpp_port/decoder.rs +++ b/src/qrcode/cpp_port/decoder.rs @@ -48,7 +48,7 @@ pub fn CorrectErrors(codewordBytes: &mut [u8], numDataCodewords: u32) -> Result< // We don't care about errors in the error-correction codewords codewordBytes[..numDataCodewords as usize].copy_from_slice( &codewordsInts[..numDataCodewords as usize] - .into_iter() + .iter() .copied() .map(|i| i as u8) .collect::>(), @@ -332,7 +332,7 @@ pub fn DecodeBitStream( { result += crate::common::cpp_essentials::util::ToString(appInd as usize, 2)?; - } else if (appInd >= 165 && appInd <= 190) || (appInd >= 197 && appInd <= 222) + } else if (165..=190).contains(&appInd) || (197..=222).contains(&appInd) // "A-Za-z" { result += (appInd - 100) as u8; @@ -403,14 +403,14 @@ pub fn Decode(bits: &BitMatrix) -> Result> { }; // Read codewords - let codewords = ReadCodewords(bits, &version, &formatInfo)?; + let codewords = ReadCodewords(bits, version, &formatInfo)?; if codewords.is_empty() { return Err(Exceptions::format_with("Failed to read codewords")); } // Separate into data blocks let dataBlocks: Vec = - DataBlock::getDataBlocks(&codewords, &version, formatInfo.error_correction_level)?; + DataBlock::getDataBlocks(&codewords, version, formatInfo.error_correction_level)?; if dataBlocks.is_empty() { return Err(Exceptions::format_with("Failed to get data blocks")); } @@ -438,7 +438,7 @@ pub fn Decode(bits: &BitMatrix) -> Result> { // Decode the contents of that stream of bytes Ok( - DecodeBitStream(&resultBytes, &version, formatInfo.error_correction_level)? + DecodeBitStream(&resultBytes, version, formatInfo.error_correction_level)? .withIsMirrored(formatInfo.isMirrored), ) } diff --git a/src/qrcode/cpp_port/detector.rs b/src/qrcode/cpp_port/detector.rs index 79aa5f7..ed948ca 100644 --- a/src/qrcode/cpp_port/detector.rs +++ b/src/qrcode/cpp_port/detector.rs @@ -41,7 +41,7 @@ const SUM: usize = 7; const PATTERN: FixedPattern = FixedPattern::new([1, 1, 3, 1, 1]); const E2E: bool = true; -fn FindPattern<'a>(view: PatternView<'a>) -> Result> { +fn FindPattern(view: PatternView<'_>) -> Result> { FindLeftGuardBy::( view, LEN, @@ -162,7 +162,7 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern // for (int i = 0; i < nbPatterns - 2; i++) { for j in (i + 1)..(nbPatterns - 1) { // for (int j = i + 1; j < nbPatterns - 1; j++) { - for k in (j + 1)..(nbPatterns - 0) { + for k in (j + 1)..nbPatterns { // for (int k = j + 1; k < nbPatterns - 0; k++) { let mut a = &patterns[i]; let mut b = &patterns[j]; @@ -201,7 +201,7 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern let moduleCount = (distAB + distBC) / (2.0 * (a.size + b.size + c.size) as f64 / (3.0 * 7.0)) + 7.0; - if moduleCount < 21.0 * 0.9 || moduleCount > 177.0 * 1.5 + if !(21.0 * 0.9..=177.0 * 1.5).contains(&moduleCount) // moduleCount may be overestimated, see above { continue; @@ -399,7 +399,7 @@ pub fn Mod2Pix( ) -> Result { let mut quad = Quadrilateral::rectangle(dimension, dimension, Some(3.5)); // let quad = Rectangle(dimension, dimension, 3.5); - quad[2] = quad[2] - brOffset; + quad[2] -= brOffset; PerspectiveTransform::quadrilateralToQuadrilateral(quad, pix) // return {quad, pix}; @@ -497,15 +497,13 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result left.dim { top } else { left } - } else { - if top.err < left.err { top } else { left } - }; + } else if top.err < left.err { top } else { left }; let mut dimension = best.dim; let moduleSize = (best.ms + 1.0) as i32; @@ -563,10 +561,10 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result= Version::DimensionOfVersion(7, false) as i32 { - let version = ReadVersion(image, dimension as u32, mod2Pix.clone()); + let version = ReadVersion(image, dimension as u32, mod2Pix); // if the version bits are garbage -> discard the detection - if !version.is_ok() + if version.is_err() || (version.as_ref().unwrap().getDimensionForVersion() as i32 - dimension).abs() > 8 { /*return DetectorResult();*/ @@ -609,7 +607,7 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result Result { if dimension < MIN_MODULES as i32 || dimension > MAX_MODULES as i32 || !image.is_in(point( - left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize as f32, + left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, )) { @@ -899,7 +897,7 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result { let bottom = top + height - 1; // allow corners be moved one pixel inside to accommodate for possible aliasing artifacts - let diagonal: Pattern = EdgeTracer::new(&image, point_i(left, top), point_i(1, 1)) + let diagonal: Pattern = EdgeTracer::new(image, point_i(left, top), point_i(1, 1)) .readPatternFromBlack(1, None) .ok_or(Exceptions::ILLEGAL_STATE)?; let diag_hld = diagonal.to_vec().into(); @@ -915,8 +913,8 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result { if dimension < MIN_MODULES || dimension > MAX_MODULES || !image.is_in(point( - left as f32 + moduleSize as f32 / 2.0 + (dimension - 1) as f32 * moduleSize, - top as f32 + moduleSize as f32 / 2.0 + (dimension - 1) as f32 * moduleSize, + left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, + top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, )) { return Err(Exceptions::NOT_FOUND); @@ -997,7 +995,7 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result Result= 0x00 && bits <= 0x05) || (bits >= 0x07 && bits <= 0x09) || bits == 0x0d { + if (0x00..=0x05).contains(&bits) || (0x07..=0x09).contains(&bits) || bits == 0x0d { return Mode::try_from(bits); } } else { @@ -188,12 +188,12 @@ impl Mode { }; match self { - Mode::NUMERIC=> return [10, 12, 14][i], - Mode::ALPHANUMERIC=> return [9, 11, 13][i], - Mode::BYTE=> return [8, 16, 16][i], + Mode::NUMERIC=> [10, 12, 14][i], + Mode::ALPHANUMERIC=> [9, 11, 13][i], + Mode::BYTE=> [8, 16, 16][i], Mode::KANJI| // [[fallthrough]]; - Mode::HANZI=> return [8, 10, 12][i], - _=> return 0, + Mode::HANZI=> [8, 10, 12][i], + _=> 0, } } } diff --git a/src/qrcode/encoder/minimal_encoder.rs b/src/qrcode/encoder/minimal_encoder.rs index 42a9cb4..ffda8fc 100644 --- a/src/qrcode/encoder/minimal_encoder.rs +++ b/src/qrcode/encoder/minimal_encoder.rs @@ -209,7 +209,7 @@ impl MinimalEncoder { pub fn isNumeric(c: &str) -> bool { if c.len() == 1 { if let Some(ch) = c.chars().next() { - return ('0'..='9').contains(&ch); + return ch.is_ascii_digit(); } } false diff --git a/src/qrcode/encoder/qrcode_encoder.rs b/src/qrcode/encoder/qrcode_encoder.rs index abd4243..934eaab 100644 --- a/src/qrcode/encoder/qrcode_encoder.rs +++ b/src/qrcode/encoder/qrcode_encoder.rs @@ -310,7 +310,7 @@ fn chooseModeWithEncoding(content: &str, encoding: CharacterSet) -> Mode { let mut has_numeric = false; let mut has_alphanumeric = false; for c in content.chars() { - if ('0'..='9').contains(&c) { + if c.is_ascii_digit() { has_numeric = true; } else if getAlphanumericCode(c as u32) != -1 { has_alphanumeric = true; diff --git a/src/qrcode/qr_code_reader.rs b/src/qrcode/qr_code_reader.rs index d690cf2..dceccdc 100644 --- a/src/qrcode/qr_code_reader.rs +++ b/src/qrcode/qr_code_reader.rs @@ -250,6 +250,6 @@ impl QRCodeReader { if x == width || y == height { return Err(Exceptions::NOT_FOUND); } - Ok((x - leftTopBlack.x) as f32 / 7.0) + Ok((x - leftTopBlack.x) / 7.0) } } diff --git a/tests/common/multiimage_span.rs b/tests/common/multiimage_span.rs index 43b048a..1f66f6a 100644 --- a/tests/common/multiimage_span.rs +++ b/tests/common/multiimage_span.rs @@ -120,7 +120,6 @@ impl MultiImageSpanAbstractBlackBoxTestCase .map(|r| r.unwrap().path()) // This is safe, since we only have the Ok variants .filter(|r| r.is_file()) // Filter out non-folders