From 3881df667214195bdac0be86f2678872554d8454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Stepanovi=C4=87?= Date: Thu, 16 Feb 2023 12:50:24 +0000 Subject: [PATCH] Remove result_point_utils::distance() --- .../zxing_cpp_detector/cpp_new_detector.rs | 9 ++++----- .../zxing_cpp_detector/dm_regression_line.rs | 8 ++++---- .../zxing_cpp_detector/regression_line.rs | 4 ---- .../detector/multi_finder_pattern_finder.rs | 18 ++++++++++++++---- src/qrcode/detector/finder_pattern.rs | 15 ++++++--------- src/qrcode/detector/qrcode_detector.rs | 18 ++++++++++++------ src/result_point_utils.rs | 12 ------------ 7 files changed, 40 insertions(+), 44 deletions(-) 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 5817b60..c97f231 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,6 @@ use crate::{ DatamatrixDetectorResult, }, qrcode::encoder::ByteMatrix, - result_point_utils::distance, Exceptions, Point, ResultPoint, }; @@ -101,8 +100,8 @@ fn Scan( let right = *t.front(); CHECK!(t.traceCorner(&mut t.left(), &mut br)?); - let lenL = distance(&tl, &bl) - 1.0; - let lenB = distance(&bl, &br) - 1.0; + let lenL = Point::distance(tl, bl) - 1.0; + let lenB = Point::distance(bl, br) - 1.0; CHECK!(lenL >= 8.0 && lenB >= 10.0 && lenB >= lenL / 4.0 && lenB <= lenL * 18.0); let mut maxStepSize: i32 = (lenB / 5.0 + 1.0) as i32; // datamatrix bottom dim is at least 10 @@ -129,8 +128,8 @@ fn Scan( CHECK!(t.traceGaps(t.left(), lineR, maxStepSize, lineT)?); CHECK!(t.traceCorner(&mut t.left(), &mut tr)?); - let lenT = distance(&tl, &tr) - 1.0; - let lenR = distance(&tr, &br) - 1.0; + let lenT = Point::distance(tl, tr) - 1.0; + let lenR = Point::distance(tr, br) - 1.0; CHECK!( (lenT - lenB).abs() / lenB < 0.5 diff --git a/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs b/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs index 2af2996..2641409 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs @@ -252,7 +252,7 @@ impl DMRegressionLine { // calculate the distance between the points projected onto the regression line for i in 1..self.points.len() { // for (size_t i = 1; i < _points.size(); ++i) - gapSizes.push(self.distance( + gapSizes.push(Point::distance( self.project(self.points[i]), self.project(self.points[i - 1]), ) as f64); @@ -273,7 +273,7 @@ impl DMRegressionLine { // calculate the width of 2 modules (first black pixel to first black pixel) let mut sumFront: f64 = - self.distance(beg, self.project(self.points[0])) as f64 - unitPixelDist; + Point::distance(beg, self.project(self.points[0])) as f64 - unitPixelDist; let mut sumBack: f64 = 0.0; // (last black pixel to last black pixel) for dist in gapSizes { // for (auto dist : gapSizes) { @@ -289,7 +289,7 @@ impl DMRegressionLine { modSizes.push( sumFront - + self.distance( + + Point::distance( end, self.project( self.points @@ -300,7 +300,7 @@ impl DMRegressionLine { ) as f64, ); modSizes[0] = 0.0; // the first element is an invalid sumBack value, would be pop_front() if vector supported this - let lineLength = self.distance(beg, end) as f64 - unitPixelDist; + let lineLength = Point::distance(beg, end) as f64 - unitPixelDist; let mut meanModSize = Self::average(&modSizes, |_: f64| true); // let meanModSize = average(modSizes, [](double){ return true; }); // #ifdef PRINT_DEBUG diff --git a/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs b/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs index be46cf1..a9ccd90 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs @@ -44,10 +44,6 @@ pub trait RegressionLine { fn evaluate(&mut self, points: &[Point]) -> bool; // { return self.evaluate_begin_end(&points.front(), &points.back() + 1); } fn evaluateSelf(&mut self) -> bool; - fn distance(&self, a: Point, b: Point) -> f32 { - crate::result_point_utils::distance(&a, &b) - } - // RegressionLine() { _points.reserve(16); } // arbitrary but plausible start size (tiny performance improvement) // template RegressionLine(PointT a, PointT b) diff --git a/src/multi/qrcode/detector/multi_finder_pattern_finder.rs b/src/multi/qrcode/detector/multi_finder_pattern_finder.rs index 43f88f1..d2505ef 100644 --- a/src/multi/qrcode/detector/multi_finder_pattern_finder.rs +++ b/src/multi/qrcode/detector/multi_finder_pattern_finder.rs @@ -19,7 +19,8 @@ use std::cmp::Ordering; use crate::{ common::{BitMatrix, Result}, qrcode::detector::{FinderPattern, FinderPatternFinder, FinderPatternInfo}, - result_point_utils, DecodeHintType, DecodingHintDictionary, Exceptions, PointCallback, + result_point_utils, DecodeHintType, DecodingHintDictionary, Exceptions, Point, PointCallback, + ResultPoint, }; // max. legal count of modules per QR code edge (177) @@ -174,9 +175,18 @@ impl<'a> MultiFinderPatternFinder<'_> { // Calculate the distances: a = topleft-bottomleft, b=topleft-topright, c = diagonal let info = FinderPatternInfo::new(test); - let dA = result_point_utils::distance(info.getTopLeft(), info.getBottomLeft()); - let dC = result_point_utils::distance(info.getTopRight(), info.getBottomLeft()); - let dB = result_point_utils::distance(info.getTopLeft(), info.getTopRight()); + let dA = Point::distance( + info.getTopLeft().to_rxing_result_point(), + info.getBottomLeft().to_rxing_result_point(), + ); + let dC = Point::distance( + info.getTopRight().to_rxing_result_point(), + info.getBottomLeft().to_rxing_result_point(), + ); + let dB = Point::distance( + info.getTopLeft().to_rxing_result_point(), + info.getTopRight().to_rxing_result_point(), + ); // Check the sizes let estimatedModuleCount = (dA + dB) / (p1.getEstimatedModuleSize() * 2.0); diff --git a/src/qrcode/detector/finder_pattern.rs b/src/qrcode/detector/finder_pattern.rs index 9d0c239..d39edc6 100644 --- a/src/qrcode/detector/finder_pattern.rs +++ b/src/qrcode/detector/finder_pattern.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use crate::{Point, ResultPoint}; +use crate::{point, Point, ResultPoint}; /** *

Encapsulates a finder pattern, which are the three square patterns found in @@ -27,23 +27,20 @@ use crate::{Point, ResultPoint}; pub struct FinderPattern { estimatedModuleSize: f32, count: usize, - point: (f32, f32), + point: Point, } impl ResultPoint for FinderPattern { fn getX(&self) -> f32 { - self.point.0 + self.point.x } fn getY(&self) -> f32 { - self.point.1 + self.point.y } fn to_rxing_result_point(&self) -> Point { - Point { - x: self.point.0, - y: self.point.1, - } + self.point } } @@ -56,7 +53,7 @@ impl FinderPattern { Self { estimatedModuleSize, count, - point: (posX, posY), + point: point(posX, posY), } } diff --git a/src/qrcode/detector/qrcode_detector.rs b/src/qrcode/detector/qrcode_detector.rs index fc23759..6d18a9d 100644 --- a/src/qrcode/detector/qrcode_detector.rs +++ b/src/qrcode/detector/qrcode_detector.rs @@ -20,8 +20,8 @@ use crate::{ common::{BitMatrix, DefaultGridSampler, GridSampler, PerspectiveTransform, Result}, point, qrcode::decoder::Version, - result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, - PointCallback, ResultPoint, + DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, PointCallback, + ResultPoint, }; use super::{ @@ -232,10 +232,16 @@ impl<'a> Detector<'_> { bottomLeft: &T, moduleSize: f32, ) -> Result { - let tltrCentersDimension = - (result_point_utils::distance(topLeft, topRight) / moduleSize).round() as i32; - let tlblCentersDimension = - (result_point_utils::distance(topLeft, bottomLeft) / moduleSize).round() as i32; + let tltrCentersDimension = (Point::distance( + topLeft.to_rxing_result_point(), + topRight.to_rxing_result_point(), + ) / moduleSize) + .round() as i32; + let tlblCentersDimension = (Point::distance( + topLeft.to_rxing_result_point(), + bottomLeft.to_rxing_result_point(), + ) / moduleSize) + .round() as i32; let mut dimension = ((tltrCentersDimension + tlblCentersDimension) / 2) + 7; match dimension & 0x03 { 0 => dimension += 1, diff --git a/src/result_point_utils.rs b/src/result_point_utils.rs index de673f5..193745d 100644 --- a/src/result_point_utils.rs +++ b/src/result_point_utils.rs @@ -57,18 +57,6 @@ pub fn orderBestPatterns(patterns: &mut [T; 3]) { patterns[2] = pc; } -/** - * @param pattern1 first pattern - * @param pattern2 second pattern - * @return distance between two points - */ -pub fn distance(pattern1: &T, pattern2: &T) -> f32 { - Point::distance( - pattern1.to_rxing_result_point(), - pattern2.to_rxing_result_point(), - ) -} - /** * Returns the z component of the cross product between vectors BC and BA. */