mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Remove result_point_utils::distance()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<typename T> RegressionLine(PointT<T> a, PointT<T> b)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* 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
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<u32> {
|
||||
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,
|
||||
|
||||
@@ -57,18 +57,6 @@ pub fn orderBestPatterns<T: ResultPoint + Copy + Clone>(patterns: &mut [T; 3]) {
|
||||
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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user