Remove result_point_utils::distance()

This commit is contained in:
Vukašin Stepanović
2023-02-16 12:50:24 +00:00
parent 39b4866e47
commit 3881df6672
7 changed files with 40 additions and 44 deletions

View File

@@ -20,7 +20,6 @@ use crate::{
DatamatrixDetectorResult, DatamatrixDetectorResult,
}, },
qrcode::encoder::ByteMatrix, qrcode::encoder::ByteMatrix,
result_point_utils::distance,
Exceptions, Point, ResultPoint, Exceptions, Point, ResultPoint,
}; };
@@ -101,8 +100,8 @@ fn Scan(
let right = *t.front(); let right = *t.front();
CHECK!(t.traceCorner(&mut t.left(), &mut br)?); CHECK!(t.traceCorner(&mut t.left(), &mut br)?);
let lenL = distance(&tl, &bl) - 1.0; let lenL = Point::distance(tl, bl) - 1.0;
let lenB = distance(&bl, &br) - 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); 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 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.traceGaps(t.left(), lineR, maxStepSize, lineT)?);
CHECK!(t.traceCorner(&mut t.left(), &mut tr)?); CHECK!(t.traceCorner(&mut t.left(), &mut tr)?);
let lenT = distance(&tl, &tr) - 1.0; let lenT = Point::distance(tl, tr) - 1.0;
let lenR = distance(&tr, &br) - 1.0; let lenR = Point::distance(tr, br) - 1.0;
CHECK!( CHECK!(
(lenT - lenB).abs() / lenB < 0.5 (lenT - lenB).abs() / lenB < 0.5

View File

@@ -252,7 +252,7 @@ impl DMRegressionLine {
// calculate the distance between the points projected onto the regression line // calculate the distance between the points projected onto the regression line
for i in 1..self.points.len() { for i in 1..self.points.len() {
// for (size_t i = 1; i < _points.size(); ++i) // 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]),
self.project(self.points[i - 1]), self.project(self.points[i - 1]),
) as f64); ) as f64);
@@ -273,7 +273,7 @@ impl DMRegressionLine {
// calculate the width of 2 modules (first black pixel to first black pixel) // calculate the width of 2 modules (first black pixel to first black pixel)
let mut sumFront: f64 = 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) let mut sumBack: f64 = 0.0; // (last black pixel to last black pixel)
for dist in gapSizes { for dist in gapSizes {
// for (auto dist : gapSizes) { // for (auto dist : gapSizes) {
@@ -289,7 +289,7 @@ impl DMRegressionLine {
modSizes.push( modSizes.push(
sumFront sumFront
+ self.distance( + Point::distance(
end, end,
self.project( self.project(
self.points self.points
@@ -300,7 +300,7 @@ impl DMRegressionLine {
) as f64, ) as f64,
); );
modSizes[0] = 0.0; // the first element is an invalid sumBack value, would be pop_front() if vector supported this 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 mut meanModSize = Self::average(&modSizes, |_: f64| true);
// let meanModSize = average(modSizes, [](double){ return true; }); // let meanModSize = average(modSizes, [](double){ return true; });
// #ifdef PRINT_DEBUG // #ifdef PRINT_DEBUG

View File

@@ -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 evaluate(&mut self, points: &[Point]) -> bool; // { return self.evaluate_begin_end(&points.front(), &points.back() + 1); }
fn evaluateSelf(&mut self) -> bool; 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) // RegressionLine() { _points.reserve(16); } // arbitrary but plausible start size (tiny performance improvement)
// template<typename T> RegressionLine(PointT<T> a, PointT<T> b) // template<typename T> RegressionLine(PointT<T> a, PointT<T> b)

View File

@@ -19,7 +19,8 @@ use std::cmp::Ordering;
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
qrcode::detector::{FinderPattern, FinderPatternFinder, FinderPatternInfo}, 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) // 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 // Calculate the distances: a = topleft-bottomleft, b=topleft-topright, c = diagonal
let info = FinderPatternInfo::new(test); let info = FinderPatternInfo::new(test);
let dA = result_point_utils::distance(info.getTopLeft(), info.getBottomLeft()); let dA = Point::distance(
let dC = result_point_utils::distance(info.getTopRight(), info.getBottomLeft()); info.getTopLeft().to_rxing_result_point(),
let dB = result_point_utils::distance(info.getTopLeft(), info.getTopRight()); 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 // Check the sizes
let estimatedModuleCount = (dA + dB) / (p1.getEstimatedModuleSize() * 2.0); let estimatedModuleCount = (dA + dB) / (p1.getEstimatedModuleSize() * 2.0);

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::{Point, ResultPoint}; use crate::{point, Point, ResultPoint};
/** /**
* <p>Encapsulates a finder pattern, which are the three square patterns found in * <p>Encapsulates a finder pattern, which are the three square patterns found in
@@ -27,23 +27,20 @@ use crate::{Point, ResultPoint};
pub struct FinderPattern { pub struct FinderPattern {
estimatedModuleSize: f32, estimatedModuleSize: f32,
count: usize, count: usize,
point: (f32, f32), point: Point,
} }
impl ResultPoint for FinderPattern { impl ResultPoint for FinderPattern {
fn getX(&self) -> f32 { fn getX(&self) -> f32 {
self.point.0 self.point.x
} }
fn getY(&self) -> f32 { fn getY(&self) -> f32 {
self.point.1 self.point.y
} }
fn to_rxing_result_point(&self) -> Point { fn to_rxing_result_point(&self) -> Point {
Point { self.point
x: self.point.0,
y: self.point.1,
}
} }
} }
@@ -56,7 +53,7 @@ impl FinderPattern {
Self { Self {
estimatedModuleSize, estimatedModuleSize,
count, count,
point: (posX, posY), point: point(posX, posY),
} }
} }

View File

@@ -20,8 +20,8 @@ use crate::{
common::{BitMatrix, DefaultGridSampler, GridSampler, PerspectiveTransform, Result}, common::{BitMatrix, DefaultGridSampler, GridSampler, PerspectiveTransform, Result},
point, point,
qrcode::decoder::Version, qrcode::decoder::Version,
result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, PointCallback,
PointCallback, ResultPoint, ResultPoint,
}; };
use super::{ use super::{
@@ -232,10 +232,16 @@ impl<'a> Detector<'_> {
bottomLeft: &T, bottomLeft: &T,
moduleSize: f32, moduleSize: f32,
) -> Result<u32> { ) -> Result<u32> {
let tltrCentersDimension = let tltrCentersDimension = (Point::distance(
(result_point_utils::distance(topLeft, topRight) / moduleSize).round() as i32; topLeft.to_rxing_result_point(),
let tlblCentersDimension = topRight.to_rxing_result_point(),
(result_point_utils::distance(topLeft, bottomLeft) / moduleSize).round() as i32; ) / 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; let mut dimension = ((tltrCentersDimension + tlblCentersDimension) / 2) + 7;
match dimension & 0x03 { match dimension & 0x03 {
0 => dimension += 1, 0 => dimension += 1,

View File

@@ -57,18 +57,6 @@ pub fn orderBestPatterns<T: ResultPoint + Copy + Clone>(patterns: &mut [T; 3]) {
patterns[2] = pc; patterns[2] = pc;
} }
/**
* @param pattern1 first pattern
* @param pattern2 second pattern
* @return distance between two points
*/
pub fn distance<T: ResultPoint>(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. * Returns the z component of the cross product between vectors BC and BA.
*/ */