mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
refactor ResultPoint trait bounds into Into<Point> bounds
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
//Point
|
||||
|
||||
use crate::{Point, ResultPoint};
|
||||
use crate::{point, Point, ResultPoint};
|
||||
|
||||
/**
|
||||
* <p>Encapsulates an alignment pattern, which are the smaller square patterns found in
|
||||
@@ -27,23 +27,26 @@ use crate::{Point, ResultPoint};
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct AlignmentPattern {
|
||||
estimatedModuleSize: f32,
|
||||
point: (f32, f32),
|
||||
point: Point,
|
||||
}
|
||||
|
||||
impl From<&AlignmentPattern> for Point {
|
||||
fn from(value: &AlignmentPattern) -> Self {
|
||||
value.point
|
||||
}
|
||||
}
|
||||
|
||||
impl ResultPoint for AlignmentPattern {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +54,7 @@ impl AlignmentPattern {
|
||||
pub fn new(posX: f32, posY: f32, estimatedModuleSize: f32) -> Self {
|
||||
Self {
|
||||
estimatedModuleSize,
|
||||
point: (posX, posY),
|
||||
point: point(posX, posY),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,13 +167,18 @@ impl<'a> Detector<'_> {
|
||||
Ok(QRCodeDetectorResult::new(bits, points))
|
||||
}
|
||||
|
||||
fn createTransform<T: ResultPoint, X: ResultPoint>(
|
||||
topLeft: &T,
|
||||
topRight: &T,
|
||||
bottomLeft: &T,
|
||||
alignmentPattern: Option<&X>,
|
||||
fn createTransform<T: Into<Point>, X: Into<Point>>(
|
||||
topLeft: T,
|
||||
topRight: T,
|
||||
bottomLeft: T,
|
||||
alignmentPattern: Option<X>,
|
||||
dimension: u32,
|
||||
) -> Option<PerspectiveTransform> {
|
||||
let topLeft: Point = topLeft.into();
|
||||
let topRight: Point = topRight.into();
|
||||
let bottomLeft: Point = bottomLeft.into();
|
||||
let alignmentPattern: Option<Point> = alignmentPattern.map(Into::into);
|
||||
|
||||
let dimMinusThree = dimension as f32 - 3.5;
|
||||
let bottomRightX: f32;
|
||||
let bottomRightY: f32;
|
||||
@@ -226,22 +231,16 @@ impl<'a> Detector<'_> {
|
||||
* <p>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.</p>
|
||||
*/
|
||||
fn computeDimension<T: ResultPoint>(
|
||||
topLeft: &T,
|
||||
topRight: &T,
|
||||
bottomLeft: &T,
|
||||
fn computeDimension<T: Into<Point>>(
|
||||
topLeft: T,
|
||||
topRight: T,
|
||||
bottomLeft: T,
|
||||
moduleSize: f32,
|
||||
) -> Result<u32> {
|
||||
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 tltrCentersDimension =
|
||||
(Point::distance(topLeft.into(), topRight.into()) / moduleSize).round() as i32;
|
||||
let tlblCentersDimension =
|
||||
(Point::distance(topLeft.into(), bottomLeft.into()) / moduleSize).round() as i32;
|
||||
let mut dimension = ((tltrCentersDimension + tlblCentersDimension) / 2) + 7;
|
||||
match dimension & 0x03 {
|
||||
0 => dimension += 1,
|
||||
@@ -261,11 +260,11 @@ impl<'a> Detector<'_> {
|
||||
* @param bottomLeft detected bottom-left finder pattern center
|
||||
* @return estimated module size
|
||||
*/
|
||||
pub fn calculateModuleSize<T: ResultPoint>(
|
||||
pub fn calculateModuleSize<T: Into<Point>>(
|
||||
&self,
|
||||
topLeft: &T,
|
||||
topRight: &T,
|
||||
bottomLeft: &T,
|
||||
topLeft: T,
|
||||
topRight: T,
|
||||
bottomLeft: T,
|
||||
) -> f32 {
|
||||
// Take the average
|
||||
(self.calculateModuleSizeOneWay(topLeft, topRight)
|
||||
@@ -278,7 +277,10 @@ impl<'a> Detector<'_> {
|
||||
* {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
|
||||
* width of each, measuring along the axis between their centers.</p>
|
||||
*/
|
||||
fn calculateModuleSizeOneWay<T: ResultPoint>(&self, pattern: &T, otherPattern: &T) -> f32 {
|
||||
fn calculateModuleSizeOneWay<T: Into<Point>>(&self, pattern: T, otherPattern: T) -> f32 {
|
||||
let pattern: Point = pattern.into();
|
||||
let otherPattern: Point = otherPattern.into();
|
||||
|
||||
let moduleSizeEst1 = self.sizeOfBlackWhiteBlackRunBothWays(
|
||||
pattern.getX().floor() as u32,
|
||||
pattern.getY().floor() as u32,
|
||||
|
||||
Reference in New Issue
Block a user