From 27f491ffaae68ffda78b5ed0f5a5395500ba4b7f Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Fri, 14 Oct 2022 17:40:16 -0500 Subject: [PATCH] working through clippy errors --- src/buffered_image_luminance_source.rs | 3 ++- src/common/mod.rs | 12 ++++++------ src/lib.rs | 7 ++----- src/qrcode/decoder/data_block.rs | 5 +++-- src/qrcode/qr_code_reader.rs | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/buffered_image_luminance_source.rs b/src/buffered_image_luminance_source.rs index ae96e6e..752d889 100644 --- a/src/buffered_image_luminance_source.rs +++ b/src/buffered_image_luminance_source.rs @@ -26,7 +26,8 @@ use imageproc::geometric_transformations::rotate_about_center; use crate::LuminanceSource; -const MINUS_45_IN_RADIANS: f32 = -0.7853981633974483; // Math.toRadians(-45.0) +// const MINUS_45_IN_RADIANS: f32 = -0.7853981633974483; // Math.toRadians(-45.0) +const MINUS_45_IN_RADIANS : f32 = std::f32::consts::FRAC_PI_4; /** * This LuminanceSource implementation is meant for J2SE clients and our blackbox unit tests. diff --git a/src/common/mod.rs b/src/common/mod.rs index 84ebd7f..4d61b2c 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -3158,10 +3158,10 @@ impl ECIInput for MinimalECIInput { * if the value at the {@code index} argument is an ECI (@see #isECI) */ fn charAt(&self, index: usize) -> Result { - if (index < 0 || index >= self.length()) { + if index >= self.length() { return Err(Exceptions::IndexOutOfBoundsException(index.to_string())); } - if (self.isECI(index as u32)?) { + if self.isECI(index as u32)? { return Err(Exceptions::IllegalArgumentException(format!( "value at {} is not a character but an ECI", index @@ -3195,7 +3195,7 @@ impl ECIInput for MinimalECIInput { * if a value in the range {@code start}-{@code end} is an ECI (@see #isECI) */ fn subSequence(&self, start: usize, end: usize) -> Result, Exceptions> { - if start < 0 || start > end || end > self.length() { + if start > end || end > self.length() { return Err(Exceptions::IndexOutOfBoundsException(start.to_string())); } let mut result = String::new(); @@ -3224,7 +3224,7 @@ impl ECIInput for MinimalECIInput { * {@code length()} */ fn isECI(&self, index: u32) -> Result { - if index < 0 || index >= self.length() as u32 { + if index >= self.length() as u32 { return Err(Exceptions::IndexOutOfBoundsException(index.to_string())); } Ok(self.bytes[index as usize] > 255 && self.bytes[index as usize] <= u16::MAX) @@ -3249,7 +3249,7 @@ impl ECIInput for MinimalECIInput { * if the value at the {@code index} argument is not an ECI (@see #isECI) */ fn getECIValue(&self, index: usize) -> Result { - if index < 0 || index >= self.length() { + if index >= self.length() { return Err(Exceptions::IndexOutOfBoundsException(index.to_string())); } if !self.isECI(index as u32)? { @@ -3336,7 +3336,7 @@ impl MinimalECIInput { * {@code length()} */ pub fn isFNC1(&self, index: usize) -> Result { - if index < 0 || index >= self.length() { + if index >= self.length() { return Err(Exceptions::IndexOutOfBoundsException(index.to_string())); } Ok(self.bytes[index] == 1000) diff --git a/src/lib.rs b/src/lib.rs index 7df1f96..04ff633 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1351,9 +1351,6 @@ pub struct Dimension { impl Dimension { pub fn new(width: usize, height: usize) -> Result { - if width < 0 || height < 0 { - return Err(Exceptions::IllegalArgumentException("".to_owned())); - } Ok(Self { width, height }) } @@ -2028,7 +2025,7 @@ impl PlanarYUVLuminanceSource { impl LuminanceSource for PlanarYUVLuminanceSource { fn getRow(&self, y: usize, row: &Vec) -> Vec { - if y < 0 || y >= self.getHeight() { + if y >= self.getHeight() { //throw new IllegalArgumentException("Requested row is outside the image: " + y); panic!("Requested row is outside the image: {}", y); } @@ -2178,7 +2175,7 @@ pub struct RGBLuminanceSource { impl LuminanceSource for RGBLuminanceSource { fn getRow(&self, y: usize, row: &Vec) -> Vec { - if y < 0 || y >= self.getHeight() { + if y >= self.getHeight() { panic!("Requested row is outside the image: {}", y); } let width = self.getWidth(); diff --git a/src/qrcode/decoder/data_block.rs b/src/qrcode/decoder/data_block.rs index 3d01014..d2ab921 100755 --- a/src/qrcode/decoder/data_block.rs +++ b/src/qrcode/decoder/data_block.rs @@ -90,9 +90,10 @@ impl DataBlock { // (where n may be 0) have 1 more byte. Figure out where these start. let shorterBlocksTotalCodewords = result[0].codewords.len(); let mut longerBlocksStartAt = result.len() - 1; - while (longerBlocksStartAt >= 0) { + loop { + //while longerBlocksStartAt >= 0 { let numCodewords = result[longerBlocksStartAt].codewords.len(); - if (numCodewords == shorterBlocksTotalCodewords) { + if numCodewords == shorterBlocksTotalCodewords { break; } longerBlocksStartAt-=1; diff --git a/src/qrcode/qr_code_reader.rs b/src/qrcode/qr_code_reader.rs index 8759290..a487db4 100644 --- a/src/qrcode/qr_code_reader.rs +++ b/src/qrcode/qr_code_reader.rs @@ -175,7 +175,7 @@ impl QRCodeReader { } let matrixWidth = ((right as f32 - left as f32 + 1.0) / moduleSize).round() as u32; let matrixHeight = ((bottom as f32 - top as f32 + 1.0) / moduleSize).round() as u32; - if matrixWidth <= 0 || matrixHeight <= 0 { + if matrixWidth == 0 || matrixHeight == 0 { return Err(Exceptions::NotFoundException("".to_owned())); } if matrixHeight != matrixWidth {