From 0992e85e6c71b39f3894539da3876637052e9ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Stepanovi=C4=87?= Date: Thu, 16 Feb 2023 15:54:07 +0000 Subject: [PATCH] remove ResultPoint trait uses of Point Point already has `x` and `y` properties, so accessing them with `getX()` and `getY()` is needlessly verbose. These calls have been removed, though the trait impl is still presen for the time being, since the OneDReader proc macro requires it. --- src/aztec/detector.rs | 42 +++++++------- .../detector/monochrome_rectangle_detector.rs | 10 ++-- .../detector/white_rectangle_detector.rs | 18 +++--- .../detector/datamatrix_detector.rs | 56 +++++++++---------- .../zxing_cpp_detector/cpp_new_detector.rs | 18 +++--- src/multi/by_quadrant_reader.rs | 4 +- src/multi/generic_multiple_barcode_reader.rs | 13 ++--- src/oned/one_d_reader.rs | 6 +- src/pdf417/decoder/bounding_box.rs | 26 ++++----- .../detection_result_row_indicator_column.rs | 10 ++-- .../decoder/pdf_417_scanning_decoder.rs | 6 +- src/pdf417/detector/pdf_417_detector.rs | 23 ++++---- src/pdf417/pdf_417_reader.rs | 6 +- src/qrcode/detector/qrcode_detector.rs | 40 ++++++------- src/result_point_utils.rs | 2 +- src/rxing_result_point.rs | 4 +- 16 files changed, 137 insertions(+), 147 deletions(-) diff --git a/src/aztec/detector.rs b/src/aztec/detector.rs index 4e3037f..4d1fea6 100644 --- a/src/aztec/detector.rs +++ b/src/aztec/detector.rs @@ -23,7 +23,7 @@ use crate::{ BitMatrix, DefaultGridSampler, GridSampler, Result, }, exceptions::Exceptions, - point, Point, ResultPoint, + point, Point, }; use super::aztec_detector_result::AztecDetectorRXingResult; @@ -403,10 +403,8 @@ impl<'a> Detector<'_> { // } //Compute the center of the rectangle - let mut cx = ((point_a.getX() + point_d.getX() + point_b.getX() + point_c.getX()) / 4.0) - .round() as i32; - let mut cy = ((point_a.getY() + point_d.getY() + point_b.getY() + point_c.getY()) / 4.0) - .round() as i32; + let mut cx = ((point_a.x + point_d.x + point_b.x + point_c.x) / 4.0).round() as i32; + let mut cy = ((point_a.y + point_d.y + point_b.y + point_c.y) / 4.0).round() as i32; // Redetermine the white rectangle starting from previously computed center. // This will ensure that we end up with a white rectangle in center bull's eye @@ -453,10 +451,8 @@ impl<'a> Detector<'_> { // } // Recompute the center of the rectangle - cx = ((point_a.getX() + point_d.getX() + point_b.getX() + point_c.getX()) / 4.0).round() - as i32; - cy = ((point_a.getY() + point_d.getY() + point_b.getY() + point_c.getY()) / 4.0).round() - as i32; + cx = ((point_a.x + point_d.x + point_b.x + point_c.x) / 4.0).round() as i32; + cy = ((point_a.y + point_d.y + point_b.y + point_c.y) / 4.0).round() as i32; AztecPoint::new(cx, cy) } @@ -506,14 +502,14 @@ impl<'a> Detector<'_> { high, // bottomright low, high, // bottomleft - top_left.getX(), - top_left.getY(), - top_right.getX(), - top_right.getY(), - bottom_right.getX(), - bottom_right.getY(), - bottom_left.getX(), - bottom_left.getY(), + top_left.x, + top_left.y, + top_right.x, + top_right.y, + bottom_right.x, + bottom_right.y, + bottom_left.x, + bottom_left.y, ) } @@ -530,10 +526,10 @@ impl<'a> Detector<'_> { let d = Self::distance(p1, p2); let module_size = d / size as f32; - let px = p1.getX(); - let py = p1.getY(); - let dx = module_size * (p2.getX() - p1.getX()) / d; - let dy = module_size * (p2.getY() - p1.getY()) / d; + let px = p1.x; + let py = p1.y; + let dx = module_size * (p2.x - p1.x) / d; + let dy = module_size * (p2.y - p1.y) / d; for i in 0..size { // for (int i = 0; i < size; i++) { if self.image.get( @@ -702,8 +698,8 @@ impl<'a> Detector<'_> { } fn is_valid(&self, point: Point) -> bool { - let x = point.getX().round() as i32; - let y = point.getY().round() as i32; + let x = point.x.round() as i32; + let y = point.y.round() as i32; self.is_valid_points(x, y) } diff --git a/src/common/detector/monochrome_rectangle_detector.rs b/src/common/detector/monochrome_rectangle_detector.rs index 6f99fe1..21fc072 100644 --- a/src/common/detector/monochrome_rectangle_detector.rs +++ b/src/common/detector/monochrome_rectangle_detector.rs @@ -19,7 +19,7 @@ use crate::{ common::{BitMatrix, Result}, - point, Exceptions, Point, ResultPoint, + point, Exceptions, Point, }; /** @@ -74,7 +74,7 @@ impl<'a> MonochromeRectangleDetector<'_> { bottom, halfWidth / 2, )?; - top = (pointA.getY() - 1f32) as i32; + top = (pointA.y - 1f32) as i32; let pointB = self.findCornerFromCenter( halfWidth, -deltaX, @@ -86,7 +86,7 @@ impl<'a> MonochromeRectangleDetector<'_> { bottom, halfHeight / 2, )?; - left = (pointB.getX() - 1f32) as i32; + left = (pointB.x - 1f32) as i32; let pointC = self.findCornerFromCenter( halfWidth, deltaX, @@ -98,7 +98,7 @@ impl<'a> MonochromeRectangleDetector<'_> { bottom, halfHeight / 2, )?; - right = (pointC.getX() + 1f32) as i32; + right = (pointC.x + 1f32) as i32; let pointD = self.findCornerFromCenter( halfWidth, 0, @@ -110,7 +110,7 @@ impl<'a> MonochromeRectangleDetector<'_> { bottom, halfWidth / 2, )?; - bottom = (pointD.getY() + 1f32) as i32; + bottom = (pointD.y + 1f32) as i32; // Go try to find point A again with better information -- might have been off at first. pointA = self.findCornerFromCenter( diff --git a/src/common/detector/white_rectangle_detector.rs b/src/common/detector/white_rectangle_detector.rs index 9b48db0..9a553b6 100644 --- a/src/common/detector/white_rectangle_detector.rs +++ b/src/common/detector/white_rectangle_detector.rs @@ -18,7 +18,7 @@ use crate::{ common::{BitMatrix, Result}, - point, Exceptions, Point, ResultPoint, + point, Exceptions, Point, }; /** @@ -326,14 +326,14 @@ impl<'a> WhiteRectangleDetector<'_> { // y y // - let yi = y.getX(); - let yj = y.getY(); - let zi = z.getX(); - let zj = z.getY(); - let xi = x.getX(); - let xj = x.getY(); - let ti = t.getX(); - let tj = t.getY(); + let yi = y.x; + let yj = y.y; + let zi = z.x; + let zj = z.y; + let xi = x.x; + let xj = x.y; + let ti = t.x; + let tj = t.y; if yi < self.width as f32 / 2.0f32 { [ diff --git a/src/datamatrix/detector/datamatrix_detector.rs b/src/datamatrix/detector/datamatrix_detector.rs index a91ec73..f9bd048 100644 --- a/src/datamatrix/detector/datamatrix_detector.rs +++ b/src/datamatrix/detector/datamatrix_detector.rs @@ -18,7 +18,7 @@ use crate::{ common::{ detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result, }, - point, Exceptions, Point, ResultPoint, + point, Exceptions, Point, }; use super::DatamatrixDetectorResult; @@ -102,14 +102,14 @@ impl<'a> Detector<'_> { } fn shiftPoint(p: Point, to: Point, div: u32) -> Point { - let x = (to.getX() - p.getX()) / (div as f32 + 1.0); - let y = (to.getY() - p.getY()) / (div as f32 + 1.0); - point(p.getX() + x, p.getY() + y) + let x = (to.x - p.x) / (div as f32 + 1.0); + let y = (to.y - p.y) / (div as f32 + 1.0); + point(p.x + x, p.y + y) } fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point { - let mut x = p.getX(); - let mut y = p.getY(); + let mut x = p.x; + let mut y = p.y; if x < fromX { x -= 1.0; @@ -233,12 +233,12 @@ impl<'a> Detector<'_> { trRight = self.transitionsBetween(pointCs, pointD); let candidate1 = point( - pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop as f32 + 1.0), - pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop as f32 + 1.0), + pointD.x + (pointC.x - pointB.x) / (trTop as f32 + 1.0), + pointD.y + (pointC.y - pointB.y) / (trTop as f32 + 1.0), ); let candidate2 = point( - pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight as f32 + 1.0), - pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight as f32 + 1.0), + pointD.x + (pointA.x - pointB.x) / (trRight as f32 + 1.0), + pointD.y + (pointA.y - pointB.y) / (trRight as f32 + 1.0), ); if !self.isValid(candidate1) { @@ -295,8 +295,8 @@ impl<'a> Detector<'_> { // WhiteRectangleDetector returns points inside of the rectangle. // I want points on the edges. - let centerX = (pointA.getX() + pointB.getX() + pointC.getX() + pointD.getX()) / 4.0; - let centerY = (pointA.getY() + pointB.getY() + pointC.getY() + pointD.getY()) / 4.0; + let centerX = (pointA.x + pointB.x + pointC.x + pointD.x) / 4.0; + let centerY = (pointA.y + pointB.y + pointC.y + pointD.y) / 4.0; pointA = Self::moveAway(pointA, centerX, centerY); pointB = Self::moveAway(pointB, centerX, centerY); pointC = Self::moveAway(pointC, centerX, centerY); @@ -319,10 +319,10 @@ impl<'a> Detector<'_> { } fn isValid(&self, p: Point) -> bool { - p.getX() >= 0.0 - && p.getX() <= self.image.getWidth() as f32 - 1.0 - && p.getY() > 0.0 - && p.getY() <= self.image.getHeight() as f32 - 1.0 + p.x >= 0.0 + && p.x <= self.image.getWidth() as f32 - 1.0 + && p.y > 0.0 + && p.y <= self.image.getHeight() as f32 - 1.0 } fn sampleGrid( @@ -348,14 +348,14 @@ impl<'a> Detector<'_> { dimensionY as f32 - 0.5, 0.5, dimensionY as f32 - 0.5, - topLeft.getX(), - topLeft.getY(), - topRight.getX(), - topRight.getY(), - bottomRight.getX(), - bottomRight.getY(), - bottomLeft.getX(), - bottomLeft.getY(), + topLeft.x, + topLeft.y, + topRight.x, + topRight.y, + bottomRight.x, + bottomRight.y, + bottomLeft.x, + bottomLeft.y, ) } @@ -364,10 +364,10 @@ impl<'a> Detector<'_> { */ fn transitionsBetween(&self, from: Point, to: Point) -> u32 { // See QR Code Detector, sizeOfBlackWhiteBlackRun() - let mut fromX = from.getX().floor() as i32; - let mut fromY = from.getY().floor() as i32; - let mut toX = to.getX().floor() as i32; - let mut toY = (self.image.getHeight() - 1).min(to.getY().floor() as u32) as i32; + let mut fromX = from.x.floor() as i32; + let mut fromY = from.y.floor() as i32; + let mut toX = to.x.floor() as i32; + let mut toY = (self.image.getHeight() - 1).min(to.y.floor() as u32) as i32; let steep = (toY - fromY).abs() > (toX - fromX).abs(); if steep { diff --git a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs index c97f231..d499263 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs @@ -20,7 +20,7 @@ use crate::{ DatamatrixDetectorResult, }, qrcode::encoder::ByteMatrix, - Exceptions, Point, ResultPoint, + Exceptions, Point, }; use super::{DMRegressionLine, EdgeTracer}; @@ -225,14 +225,14 @@ fn Scan( dimR as f32, 0.0, dimR as f32, - sourcePoints.topLeft().getX(), - sourcePoints.topLeft().getY(), - sourcePoints.topRight().getX(), - sourcePoints.topRight().getY(), - sourcePoints.bottomRight().getX(), - sourcePoints.bottomRight().getY(), - sourcePoints.bottomLeft().getX(), - sourcePoints.bottomLeft().getY(), + sourcePoints.topLeft().x, + sourcePoints.topLeft().y, + sourcePoints.topRight().x, + sourcePoints.topRight().y, + sourcePoints.bottomRight().x, + sourcePoints.bottomRight().y, + sourcePoints.bottomLeft().x, + sourcePoints.bottomLeft().y, ); // let res = grid_sampler.sample_grid(startTracer.img, dimT as u32, dimR as u32, &transform); diff --git a/src/multi/by_quadrant_reader.rs b/src/multi/by_quadrant_reader.rs index bb23fa7..348124c 100644 --- a/src/multi/by_quadrant_reader.rs +++ b/src/multi/by_quadrant_reader.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; use crate::common::Result; -use crate::{point, Exceptions, Point, RXingResult, Reader, ResultPoint}; +use crate::{point, Exceptions, Point, RXingResult, Reader}; /** * This class attempts to decode a barcode from an image, not by scanning the whole image, @@ -133,7 +133,7 @@ impl ByQuadrantReader { // result points .iter() - .map(|relative| point(relative.getX() + leftOffset, relative.getY() + topOffset)) + .map(|relative| point(relative.x + leftOffset, relative.y + topOffset)) .collect() } } diff --git a/src/multi/generic_multiple_barcode_reader.rs b/src/multi/generic_multiple_barcode_reader.rs index 3d2487d..af6b201 100644 --- a/src/multi/generic_multiple_barcode_reader.rs +++ b/src/multi/generic_multiple_barcode_reader.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use crate::{ common::Result, point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, RXingResult, - Reader, ResultPoint, + Reader, }; use super::MultipleBarcodeReader; @@ -115,8 +115,8 @@ impl GenericMultipleBarcodeReader { // if (point == null) { // continue; // } - let x = point.getX(); - let y = point.getY(); + let x = point.x; + let y = point.y; if x < minX { minX = x; } @@ -185,12 +185,7 @@ impl GenericMultipleBarcodeReader { let newPoints: Vec = oldPoints .iter() - .map(|oldPoint| { - point( - oldPoint.getX() + xOffset as f32, - oldPoint.getY() + yOffset as f32, - ) - }) + .map(|oldPoint| point(oldPoint.x + xOffset as f32, oldPoint.y + yOffset as f32)) .collect(); // let mut newPoints = Vec::with_capacity(oldPoints.len()); diff --git a/src/oned/one_d_reader.rs b/src/oned/one_d_reader.rs index e7e7f43..bd49c69 100644 --- a/src/oned/one_d_reader.rs +++ b/src/oned/one_d_reader.rs @@ -17,7 +17,7 @@ use crate::{ common::{BitArray, Result}, point, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, - RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, ResultPoint, + RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, }; /** @@ -117,8 +117,8 @@ pub trait OneDReader: Reader { // And remember to flip the result points horizontally. let points = result.getPointsMut(); if !points.is_empty() && points.len() >= 2 { - points[0] = point(width as f32 - points[0].getX() - 1.0, points[0].getY()); - points[1] = point(width as f32 - points[1].getX() - 1.0, points[1].getY()); + points[0] = point(width as f32 - points[0].x - 1.0, points[0].y); + points[1] = point(width as f32 - points[1].x - 1.0, points[1].y); } } return Ok(result); diff --git a/src/pdf417/decoder/bounding_box.rs b/src/pdf417/decoder/bounding_box.rs index 8adb723..e9eae48 100644 --- a/src/pdf417/decoder/bounding_box.rs +++ b/src/pdf417/decoder/bounding_box.rs @@ -18,7 +18,7 @@ use std::rc::Rc; use crate::{ common::{BitMatrix, Result}, - point, Exceptions, Point, ResultPoint, + point, Exceptions, Point, }; /** @@ -58,13 +58,13 @@ impl BoundingBox { if leftUnspecified { newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?; - newTopLeft = point(0.0, newTopRight.getY()); - newBottomLeft = point(0.0, newBottomRight.getY()); + newTopLeft = point(0.0, newTopRight.y); + newBottomLeft = point(0.0, newBottomRight.y); } else if rightUnspecified { newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?; newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?; - newTopRight = point(image.getWidth() as f32 - 1.0, newTopLeft.getY()); - newBottomRight = point(image.getWidth() as f32 - 1.0, newBottomLeft.getY()); + newTopRight = point(image.getWidth() as f32 - 1.0, newTopLeft.y); + newBottomRight = point(image.getWidth() as f32 - 1.0, newBottomLeft.y); } else { newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?; newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; @@ -74,10 +74,10 @@ impl BoundingBox { Ok(BoundingBox { image, - minX: newTopLeft.getX().min(newBottomLeft.getX()) as u32, - maxX: newTopRight.getX().max(newBottomRight.getX()) as u32, - minY: newTopLeft.getY().min(newTopRight.getY()) as u32, - maxY: newBottomLeft.getY().max(newBottomRight.getY()) as u32, + minX: newTopLeft.x.min(newBottomLeft.x) as u32, + maxX: newTopRight.x.max(newBottomRight.x) as u32, + minY: newTopLeft.y.min(newTopRight.y) as u32, + maxY: newBottomLeft.y.max(newBottomRight.y) as u32, topLeft: newTopLeft, bottomLeft: newBottomLeft, topRight: newTopRight, @@ -140,11 +140,11 @@ impl BoundingBox { if missingStartRows > 0 { let top = if isLeft { self.topLeft } else { self.topRight }; - let mut newMinY = top.getY() - missingStartRows as f32; + let mut newMinY = top.y - missingStartRows as f32; if newMinY < 0.0 { newMinY = 0.0; } - let newTop = point(top.getX(), newMinY); + let newTop = point(top.x, newMinY); if isLeft { newTopLeft = newTop; } else { @@ -158,11 +158,11 @@ impl BoundingBox { } else { self.bottomRight }; - let mut newMaxY = bottom.getY() as u32 + missingEndRows; + let mut newMaxY = bottom.y as u32 + missingEndRows; if newMaxY >= self.image.getHeight() { newMaxY = self.image.getHeight() - 1; } - let newBottom = point(bottom.getX(), newMaxY as f32); + let newBottom = point(bottom.x, newMaxY as f32); if isLeft { newBottomLeft = newBottom; } else { diff --git a/src/pdf417/decoder/detection_result_row_indicator_column.rs b/src/pdf417/decoder/detection_result_row_indicator_column.rs index 3653d5b..d714641 100644 --- a/src/pdf417/decoder/detection_result_row_indicator_column.rs +++ b/src/pdf417/decoder/detection_result_row_indicator_column.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use crate::{pdf417::pdf_417_common, ResultPoint}; +use crate::pdf417::pdf_417_common; use super::{ BarcodeMetadata, BarcodeValue, Codeword, DetectionRXingResultColumn, @@ -63,8 +63,8 @@ impl DetectionRXingResultRowIndicatorColumn for DetectionRXingResultColumn { boundingBox.getBottomRight() }; - let firstRow = self.imageRowToCodewordIndex(top.getY() as u32); - let lastRow = self.imageRowToCodewordIndex(bottom.getY() as u32); + let firstRow = self.imageRowToCodewordIndex(top.y as u32); + let lastRow = self.imageRowToCodewordIndex(bottom.y as u32); // We need to be careful using the average row height. Barcode could be skewed so that we have smaller and // taller rows let averageRowHeight: f64 = @@ -263,8 +263,8 @@ fn adjustIncompleteIndicatorColumnRowNumbers( } else { boundingBox.getBottomRight() }; - let firstRow = col.imageRowToCodewordIndex(top.getY() as u32); - let lastRow = col.imageRowToCodewordIndex(bottom.getY() as u32); + let firstRow = col.imageRowToCodewordIndex(top.y as u32); + let lastRow = col.imageRowToCodewordIndex(bottom.y as u32); let averageRowHeight: f64 = (lastRow as f64 - firstRow as f64) / barcodeMetadata.getRowCount() as f64; let codewords = col.getCodewordsMut(); diff --git a/src/pdf417/decoder/pdf_417_scanning_decoder.rs b/src/pdf417/decoder/pdf_417_scanning_decoder.rs index b808a8d..213cacd 100644 --- a/src/pdf417/decoder/pdf_417_scanning_decoder.rs +++ b/src/pdf417/decoder/pdf_417_scanning_decoder.rs @@ -19,7 +19,7 @@ use std::rc::Rc; use crate::{ common::{BitMatrix, DecoderRXingResult, Result}, pdf417::pdf_417_common, - Exceptions, Point, ResultPoint, + Exceptions, Point, }; use super::{ @@ -368,8 +368,8 @@ fn getRowIndicatorColumn<'a>( for i in 0..2 { // for (int i = 0; i < 2; i++) { let increment: i32 = if i == 0 { 1 } else { -1 }; - let mut startColumn: u32 = startPoint.getX() as u32; - let mut imageRow: i32 = startPoint.getY() as i32; + let mut startColumn: u32 = startPoint.x as u32; + let mut imageRow: i32 = startPoint.y as i32; while imageRow <= boundingBox.getMaxY() as i32 && imageRow >= boundingBox.getMinY() as i32 { // for (int imageRow = (int) startPoint.getY(); imageRow <= boundingBox.getMaxY() && // imageRow >= boundingBox.getMinY(); imageRow += increment) { diff --git a/src/pdf417/detector/pdf_417_detector.rs b/src/pdf417/detector/pdf_417_detector.rs index 836e2bc..a17ecf5 100644 --- a/src/pdf417/detector/pdf_417_detector.rs +++ b/src/pdf417/detector/pdf_417_detector.rs @@ -16,7 +16,7 @@ use crate::{ common::{BitMatrix, Result}, - point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, ResultPoint, + point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, }; use std::borrow::Cow; @@ -137,10 +137,10 @@ pub fn detect(multiple: bool, bitMatrix: &BitMatrix) -> Option Option Option<[ ); if let Some(result_4) = result[4] { - startColumn = result_4.getX() as u32; - startRow = result_4.getY() as u32; + startColumn = result_4.x as u32; + startRow = result_4.y as u32; } copyToRXingResult( &mut result, @@ -258,10 +258,7 @@ fn findRowsWithPattern( // Last row of the current symbol that contains pattern if found { let mut skippedRowCount = 0; - let mut previousRowLoc = [ - result[0].as_ref()?.getX() as u32, - result[1].as_ref()?.getX() as u32, - ]; + let mut previousRowLoc = [result[0].as_ref()?.x as u32, result[1].as_ref()?.x as u32]; while stopRow < height { if let Some(loc) = findGuardPattern( matrix, diff --git a/src/pdf417/pdf_417_reader.rs b/src/pdf417/pdf_417_reader.rs index 9caa419..d891365 100644 --- a/src/pdf417/pdf_417_reader.rs +++ b/src/pdf417/pdf_417_reader.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use crate::{ common::Result, multi::MultipleBarcodeReader, BarcodeFormat, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, RXingResult, RXingResultMetadataType, - RXingResultMetadataValue, Reader, ResultPoint, + RXingResultMetadataValue, Reader, }; use super::{ @@ -153,7 +153,7 @@ impl PDF417Reader { fn getMaxWidth(p1: &Option, p2: &Option) -> u64 { if let (Some(p1), Some(p2)) = (p1, p2) { - (p1.getX() - p2.getX()).abs() as u64 + (p1.x - p2.x).abs() as u64 } else { 0 } @@ -161,7 +161,7 @@ impl PDF417Reader { fn getMinWidth(p1: &Option, p2: &Option) -> u64 { if let (Some(p1), Some(p2)) = (p1, p2) { - (p1.getX() - p2.getX()).abs() as u64 + (p1.x - p2.x).abs() as u64 } else { u32::MAX as u64 } diff --git a/src/qrcode/detector/qrcode_detector.rs b/src/qrcode/detector/qrcode_detector.rs index 0c21cde..029e28c 100644 --- a/src/qrcode/detector/qrcode_detector.rs +++ b/src/qrcode/detector/qrcode_detector.rs @@ -186,14 +186,14 @@ impl<'a> Detector<'_> { let sourceBottomRightY: f32; if alignmentPattern.is_some() { let alignmentPattern = alignmentPattern?; - bottomRightX = alignmentPattern.getX(); - bottomRightY = alignmentPattern.getY(); + bottomRightX = alignmentPattern.x; + bottomRightY = alignmentPattern.y; sourceBottomRightX = dimMinusThree - 3.0; sourceBottomRightY = sourceBottomRightX; } else { // Don't have an alignment pattern, just make up the bottom-right point - bottomRightX = (topRight.getX() - topLeft.getX()) + bottomLeft.getX(); - bottomRightY = (topRight.getY() - topLeft.getY()) + bottomLeft.getY(); + bottomRightX = (topRight.x - topLeft.x) + bottomLeft.x; + bottomRightY = (topRight.y - topLeft.y) + bottomLeft.y; sourceBottomRightX = dimMinusThree; sourceBottomRightY = dimMinusThree; } @@ -207,14 +207,14 @@ impl<'a> Detector<'_> { sourceBottomRightY, 3.5, dimMinusThree, - topLeft.getX(), - topLeft.getY(), - topRight.getX(), - topRight.getY(), + topLeft.x, + topLeft.y, + topRight.x, + topRight.y, bottomRightX, bottomRightY, - bottomLeft.getX(), - bottomLeft.getY(), + bottomLeft.x, + bottomLeft.y, )) } @@ -231,7 +231,7 @@ impl<'a> Detector<'_> { *

Computes the dimension (number of modules on a size) of the QR Code based on the position * of the finder patterns and estimated module size.

*/ - fn computeDimension>( + fn computeDimension + Copy>( topLeft: T, topRight: T, bottomLeft: T, @@ -260,7 +260,7 @@ impl<'a> Detector<'_> { * @param bottomLeft detected bottom-left finder pattern center * @return estimated module size */ - pub fn calculateModuleSize>( + pub fn calculateModuleSize + Copy>( &self, topLeft: T, topRight: T, @@ -282,16 +282,16 @@ impl<'a> Detector<'_> { let otherPattern: Point = otherPattern.into(); let moduleSizeEst1 = self.sizeOfBlackWhiteBlackRunBothWays( - pattern.getX().floor() as u32, - pattern.getY().floor() as u32, - otherPattern.getX().floor() as u32, - otherPattern.getY().floor() as u32, + pattern.x.floor() as u32, + pattern.y.floor() as u32, + otherPattern.x.floor() as u32, + otherPattern.y.floor() as u32, ); let moduleSizeEst2 = self.sizeOfBlackWhiteBlackRunBothWays( - otherPattern.getX().floor() as u32, - otherPattern.getY().floor() as u32, - pattern.getX().floor() as u32, - pattern.getY().floor() as u32, + otherPattern.x.floor() as u32, + otherPattern.y.floor() as u32, + pattern.x.floor() as u32, + pattern.y.floor() as u32, ); if moduleSizeEst1.is_nan() { return moduleSizeEst2 / 7.0; diff --git a/src/result_point_utils.rs b/src/result_point_utils.rs index ffdd5f1..c8a4a33 100644 --- a/src/result_point_utils.rs +++ b/src/result_point_utils.rs @@ -6,7 +6,7 @@ use crate::Point; * * @param patterns array of three {@code Point} to order */ -pub fn orderBestPatterns>(patterns: &mut [T; 3]) { +pub fn orderBestPatterns + Copy>(patterns: &mut [T; 3]) { // Find distances between pattern centers let zeroOneDistance = Point::distance(patterns[0].into(), patterns[1].into()); let oneTwoDistance = Point::distance(patterns[1].into(), patterns[2].into()); diff --git a/src/rxing_result_point.rs b/src/rxing_result_point.rs index a48e6e8..81d1aa1 100644 --- a/src/rxing_result_point.rs +++ b/src/rxing_result_point.rs @@ -1,11 +1,12 @@ use std::{fmt, iter::Sum}; -use crate::ResultPoint; use std::hash::Hash; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::ResultPoint; + /** *

Encapsulates a point of interest in an image containing a barcode. Typically, this * would be the location of a finder pattern or the corner of the barcode, for example.

@@ -64,6 +65,7 @@ impl<'a> Sum<&'a Point> for Point { } } +/** This impl is temporary and is there to ease refactoring. */ impl ResultPoint for Point { fn getX(&self) -> f32 { self.x