From d87ebc5f73cf097ac4f2176a215864fe19ef24f9 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sat, 13 Jan 2024 18:11:55 -0600 Subject: [PATCH] chore: clippy cleanup --- .../base_extentions/qrcode_version.rs | 33 +++++++++---------- src/qrcode/cpp_port/detector.rs | 10 +++--- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/common/cpp_essentials/base_extentions/qrcode_version.rs b/src/common/cpp_essentials/base_extentions/qrcode_version.rs index b6b7084..0216f14 100644 --- a/src/common/cpp_essentials/base_extentions/qrcode_version.rs +++ b/src/common/cpp_essentials/base_extentions/qrcode_version.rs @@ -150,7 +150,7 @@ impl Version { let square = |s: i32| point(s, s); let valid = |v: i32, max: i32| v >= 1 && v <= max; - match (qr_type) { + match qr_type { Type::Model1 => { if valid(version, 32) { square(17 + 4 * version) @@ -183,7 +183,7 @@ impl Version { } pub fn IsValidSize(size: PointI, qr_type: Type) -> bool { - match (qr_type) { + match qr_type { Type::Model1 => size.x == size.y && size.x >= 21 && size.x <= 145 && (size.x % 4 == 1), Type::Model2 => size.x == size.y && size.x >= 21 && size.x <= 177 && (size.x % 4 == 1), Type::Micro => size.x == size.y && size.x >= 11 && size.x <= 17 && (size.x % 2 == 1), @@ -200,40 +200,39 @@ impl Version { } } pub fn HasValidSizeType(bitMatrix: &BitMatrix, qr_type: Type) -> bool { - return Self::IsValidSize( + Self::IsValidSize( point(bitMatrix.width() as i32, bitMatrix.height() as i32), qr_type, - ); + ) } pub fn HasValidSize(matrix: &BitMatrix) -> bool { - return Self::HasValidSizeType(matrix, Type::Model1) + Self::HasValidSizeType(matrix, Type::Model1) || Self::HasValidSizeType(matrix, Type::Model2) || Self::HasValidSizeType(matrix, Type::Micro) - || Self::HasValidSizeType(matrix, Type::RectMicro); + || Self::HasValidSizeType(matrix, Type::RectMicro) } - fn IndexOf(points: &[PointI], search: PointI) -> i32 { + fn IndexOf(_points: &[PointI], search: PointI) -> i32 { RMQR_SIZES .iter() - .position(|p| *p == search) - .and_then(|x| Some(x as i32)) + .position(|p| *p == search).map(|x| x as i32) .unwrap_or(-1) } pub fn NumberPoint(size: PointI) -> u32 { - if (size.x != size.y) { - return (Self::IndexOf(&RMQR_SIZES, size) + 1) as u32; - } else if (Self::IsValidSize(size, Type::Model2)) { - return ((size.x as i32 - 17) / 4) as u32; - } else if (Self::IsValidSize(size, Type::Micro)) { - return ((size.x as i32 - 9) / 2) as u32; + if size.x != size.y { + (Self::IndexOf(&RMQR_SIZES, size) + 1) as u32 + } else if Self::IsValidSize(size, Type::Model2) { + ((size.x - 17) / 4) as u32 + } else if Self::IsValidSize(size, Type::Micro) { + ((size.x - 9) / 2) as u32 } else { - return 0; + 0 } } pub fn Number(bitMatrix: &BitMatrix) -> u32 { - return Self::NumberPoint(point(bitMatrix.width() as i32, bitMatrix.height() as i32)); + Self::NumberPoint(point(bitMatrix.width() as i32, bitMatrix.height() as i32)) } } diff --git a/src/qrcode/cpp_port/detector.rs b/src/qrcode/cpp_port/detector.rs index e330e52..93d7ed7 100644 --- a/src/qrcode/cpp_port/detector.rs +++ b/src/qrcode/cpp_port/detector.rs @@ -13,7 +13,7 @@ use crate::{ Exceptions, point, }; use multimap::MultiMap; -use num::Integer; + use crate::{ common::{ @@ -570,7 +570,7 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result= Version::SymbolSize(7, Type::Model2).x as i32 { + if dimension >= Version::SymbolSize(7, Type::Model2).x { let version = ReadVersion(image, dimension as u32, mod2Pix); // if the version bits are garbage -> discard the detection @@ -995,12 +995,12 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result { let dimW = (width as f32 / moduleSize as f32).floor() as u32; let dimH = (height as f32 / moduleSize as f32).floor() as u32; - if (!Version::IsValidSize(point(dimW as i32, dimH as i32), Type::RectMicro)) + if !Version::IsValidSize(point(dimW as i32, dimH as i32), Type::RectMicro) {return Err(Exceptions::NOT_FOUND);} // Finder sub pattern let subdiagonal : SubPattern = EdgeTracer::new(image, br, point_i(-1, -1)).readPatternFromBlack(1,None).ok_or(Exceptions::ILLEGAL_STATE)?; - let subdiagonal_hld = diagonal.to_vec().into(); + let subdiagonal_hld = subdiagonal.to_vec().into(); let view = PatternView::new(&subdiagonal_hld); if IsPattern::(&view, &SUBPATTERN, None, 0.0, 0.0) != 0.0 {return Err(Exceptions::NOT_FOUND);} @@ -1012,7 +1012,7 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result { // skip corner / finder / sub pattern edge cur.stepToEdge(Some(2 + i32::from(cur.isWhite())), None, None); let timing : TimingPattern = cur.readPattern(None).ok_or(Exceptions::ILLEGAL_STATE)?; - let timing_hld = diagonal.to_vec().into(); + let timing_hld = timing.to_vec().into(); let view = PatternView::new(&timing_hld); if !(IsPattern::(&view, &TIMINGPATTERN, None, 0.0, 0.0) != 0.0) {return Err(Exceptions::NOT_FOUND);}