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.
This commit is contained in:
Vukašin Stepanović
2023-02-16 15:54:07 +00:00
parent 9889555b02
commit 0992e85e6c
16 changed files with 137 additions and 147 deletions

View File

@@ -23,7 +23,7 @@ use crate::{
BitMatrix, DefaultGridSampler, GridSampler, Result, BitMatrix, DefaultGridSampler, GridSampler, Result,
}, },
exceptions::Exceptions, exceptions::Exceptions,
point, Point, ResultPoint, point, Point,
}; };
use super::aztec_detector_result::AztecDetectorRXingResult; use super::aztec_detector_result::AztecDetectorRXingResult;
@@ -403,10 +403,8 @@ impl<'a> Detector<'_> {
// } // }
//Compute the center of the rectangle //Compute the center of the rectangle
let mut cx = ((point_a.getX() + point_d.getX() + point_b.getX() + point_c.getX()) / 4.0) let mut cx = ((point_a.x + point_d.x + point_b.x + point_c.x) / 4.0).round() as i32;
.round() as i32; let mut cy = ((point_a.y + point_d.y + point_b.y + point_c.y) / 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;
// Redetermine the white rectangle starting from previously computed center. // 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 // 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 // Recompute the center of the rectangle
cx = ((point_a.getX() + point_d.getX() + point_b.getX() + point_c.getX()) / 4.0).round() cx = ((point_a.x + point_d.x + point_b.x + point_c.x) / 4.0).round() as i32;
as i32; cy = ((point_a.y + point_d.y + point_b.y + point_c.y) / 4.0).round() as i32;
cy = ((point_a.getY() + point_d.getY() + point_b.getY() + point_c.getY()) / 4.0).round()
as i32;
AztecPoint::new(cx, cy) AztecPoint::new(cx, cy)
} }
@@ -506,14 +502,14 @@ impl<'a> Detector<'_> {
high, // bottomright high, // bottomright
low, low,
high, // bottomleft high, // bottomleft
top_left.getX(), top_left.x,
top_left.getY(), top_left.y,
top_right.getX(), top_right.x,
top_right.getY(), top_right.y,
bottom_right.getX(), bottom_right.x,
bottom_right.getY(), bottom_right.y,
bottom_left.getX(), bottom_left.x,
bottom_left.getY(), bottom_left.y,
) )
} }
@@ -530,10 +526,10 @@ impl<'a> Detector<'_> {
let d = Self::distance(p1, p2); let d = Self::distance(p1, p2);
let module_size = d / size as f32; let module_size = d / size as f32;
let px = p1.getX(); let px = p1.x;
let py = p1.getY(); let py = p1.y;
let dx = module_size * (p2.getX() - p1.getX()) / d; let dx = module_size * (p2.x - p1.x) / d;
let dy = module_size * (p2.getY() - p1.getY()) / d; let dy = module_size * (p2.y - p1.y) / d;
for i in 0..size { for i in 0..size {
// for (int i = 0; i < size; i++) { // for (int i = 0; i < size; i++) {
if self.image.get( if self.image.get(
@@ -702,8 +698,8 @@ impl<'a> Detector<'_> {
} }
fn is_valid(&self, point: Point) -> bool { fn is_valid(&self, point: Point) -> bool {
let x = point.getX().round() as i32; let x = point.x.round() as i32;
let y = point.getY().round() as i32; let y = point.y.round() as i32;
self.is_valid_points(x, y) self.is_valid_points(x, y)
} }

View File

@@ -19,7 +19,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, Exceptions, Point, ResultPoint, point, Exceptions, Point,
}; };
/** /**
@@ -74,7 +74,7 @@ impl<'a> MonochromeRectangleDetector<'_> {
bottom, bottom,
halfWidth / 2, halfWidth / 2,
)?; )?;
top = (pointA.getY() - 1f32) as i32; top = (pointA.y - 1f32) as i32;
let pointB = self.findCornerFromCenter( let pointB = self.findCornerFromCenter(
halfWidth, halfWidth,
-deltaX, -deltaX,
@@ -86,7 +86,7 @@ impl<'a> MonochromeRectangleDetector<'_> {
bottom, bottom,
halfHeight / 2, halfHeight / 2,
)?; )?;
left = (pointB.getX() - 1f32) as i32; left = (pointB.x - 1f32) as i32;
let pointC = self.findCornerFromCenter( let pointC = self.findCornerFromCenter(
halfWidth, halfWidth,
deltaX, deltaX,
@@ -98,7 +98,7 @@ impl<'a> MonochromeRectangleDetector<'_> {
bottom, bottom,
halfHeight / 2, halfHeight / 2,
)?; )?;
right = (pointC.getX() + 1f32) as i32; right = (pointC.x + 1f32) as i32;
let pointD = self.findCornerFromCenter( let pointD = self.findCornerFromCenter(
halfWidth, halfWidth,
0, 0,
@@ -110,7 +110,7 @@ impl<'a> MonochromeRectangleDetector<'_> {
bottom, bottom,
halfWidth / 2, 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. // Go try to find point A again with better information -- might have been off at first.
pointA = self.findCornerFromCenter( pointA = self.findCornerFromCenter(

View File

@@ -18,7 +18,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, Exceptions, Point, ResultPoint, point, Exceptions, Point,
}; };
/** /**
@@ -326,14 +326,14 @@ impl<'a> WhiteRectangleDetector<'_> {
// y y // y y
// //
let yi = y.getX(); let yi = y.x;
let yj = y.getY(); let yj = y.y;
let zi = z.getX(); let zi = z.x;
let zj = z.getY(); let zj = z.y;
let xi = x.getX(); let xi = x.x;
let xj = x.getY(); let xj = x.y;
let ti = t.getX(); let ti = t.x;
let tj = t.getY(); let tj = t.y;
if yi < self.width as f32 / 2.0f32 { if yi < self.width as f32 / 2.0f32 {
[ [

View File

@@ -18,7 +18,7 @@ use crate::{
common::{ common::{
detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result, detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result,
}, },
point, Exceptions, Point, ResultPoint, point, Exceptions, Point,
}; };
use super::DatamatrixDetectorResult; use super::DatamatrixDetectorResult;
@@ -102,14 +102,14 @@ impl<'a> Detector<'_> {
} }
fn shiftPoint(p: Point, to: Point, div: u32) -> Point { fn shiftPoint(p: Point, to: Point, div: u32) -> Point {
let x = (to.getX() - p.getX()) / (div as f32 + 1.0); let x = (to.x - p.x) / (div as f32 + 1.0);
let y = (to.getY() - p.getY()) / (div as f32 + 1.0); let y = (to.y - p.y) / (div as f32 + 1.0);
point(p.getX() + x, p.getY() + y) point(p.x + x, p.y + y)
} }
fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point { fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point {
let mut x = p.getX(); let mut x = p.x;
let mut y = p.getY(); let mut y = p.y;
if x < fromX { if x < fromX {
x -= 1.0; x -= 1.0;
@@ -233,12 +233,12 @@ impl<'a> Detector<'_> {
trRight = self.transitionsBetween(pointCs, pointD); trRight = self.transitionsBetween(pointCs, pointD);
let candidate1 = point( let candidate1 = point(
pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop as f32 + 1.0), pointD.x + (pointC.x - pointB.x) / (trTop as f32 + 1.0),
pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop as f32 + 1.0), pointD.y + (pointC.y - pointB.y) / (trTop as f32 + 1.0),
); );
let candidate2 = point( let candidate2 = point(
pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight as f32 + 1.0), pointD.x + (pointA.x - pointB.x) / (trRight as f32 + 1.0),
pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight as f32 + 1.0), pointD.y + (pointA.y - pointB.y) / (trRight as f32 + 1.0),
); );
if !self.isValid(candidate1) { if !self.isValid(candidate1) {
@@ -295,8 +295,8 @@ impl<'a> Detector<'_> {
// WhiteRectangleDetector returns points inside of the rectangle. // WhiteRectangleDetector returns points inside of the rectangle.
// I want points on the edges. // I want points on the edges.
let centerX = (pointA.getX() + pointB.getX() + pointC.getX() + pointD.getX()) / 4.0; let centerX = (pointA.x + pointB.x + pointC.x + pointD.x) / 4.0;
let centerY = (pointA.getY() + pointB.getY() + pointC.getY() + pointD.getY()) / 4.0; let centerY = (pointA.y + pointB.y + pointC.y + pointD.y) / 4.0;
pointA = Self::moveAway(pointA, centerX, centerY); pointA = Self::moveAway(pointA, centerX, centerY);
pointB = Self::moveAway(pointB, centerX, centerY); pointB = Self::moveAway(pointB, centerX, centerY);
pointC = Self::moveAway(pointC, centerX, centerY); pointC = Self::moveAway(pointC, centerX, centerY);
@@ -319,10 +319,10 @@ impl<'a> Detector<'_> {
} }
fn isValid(&self, p: Point) -> bool { fn isValid(&self, p: Point) -> bool {
p.getX() >= 0.0 p.x >= 0.0
&& p.getX() <= self.image.getWidth() as f32 - 1.0 && p.x <= self.image.getWidth() as f32 - 1.0
&& p.getY() > 0.0 && p.y > 0.0
&& p.getY() <= self.image.getHeight() as f32 - 1.0 && p.y <= self.image.getHeight() as f32 - 1.0
} }
fn sampleGrid( fn sampleGrid(
@@ -348,14 +348,14 @@ impl<'a> Detector<'_> {
dimensionY as f32 - 0.5, dimensionY as f32 - 0.5,
0.5, 0.5,
dimensionY as f32 - 0.5, dimensionY as f32 - 0.5,
topLeft.getX(), topLeft.x,
topLeft.getY(), topLeft.y,
topRight.getX(), topRight.x,
topRight.getY(), topRight.y,
bottomRight.getX(), bottomRight.x,
bottomRight.getY(), bottomRight.y,
bottomLeft.getX(), bottomLeft.x,
bottomLeft.getY(), bottomLeft.y,
) )
} }
@@ -364,10 +364,10 @@ impl<'a> Detector<'_> {
*/ */
fn transitionsBetween(&self, from: Point, to: Point) -> u32 { fn transitionsBetween(&self, from: Point, to: Point) -> u32 {
// See QR Code Detector, sizeOfBlackWhiteBlackRun() // See QR Code Detector, sizeOfBlackWhiteBlackRun()
let mut fromX = from.getX().floor() as i32; let mut fromX = from.x.floor() as i32;
let mut fromY = from.getY().floor() as i32; let mut fromY = from.y.floor() as i32;
let mut toX = to.getX().floor() as i32; let mut toX = to.x.floor() as i32;
let mut toY = (self.image.getHeight() - 1).min(to.getY().floor() as u32) 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(); let steep = (toY - fromY).abs() > (toX - fromX).abs();
if steep { if steep {

View File

@@ -20,7 +20,7 @@ use crate::{
DatamatrixDetectorResult, DatamatrixDetectorResult,
}, },
qrcode::encoder::ByteMatrix, qrcode::encoder::ByteMatrix,
Exceptions, Point, ResultPoint, Exceptions, Point,
}; };
use super::{DMRegressionLine, EdgeTracer}; use super::{DMRegressionLine, EdgeTracer};
@@ -225,14 +225,14 @@ fn Scan(
dimR as f32, dimR as f32,
0.0, 0.0,
dimR as f32, dimR as f32,
sourcePoints.topLeft().getX(), sourcePoints.topLeft().x,
sourcePoints.topLeft().getY(), sourcePoints.topLeft().y,
sourcePoints.topRight().getX(), sourcePoints.topRight().x,
sourcePoints.topRight().getY(), sourcePoints.topRight().y,
sourcePoints.bottomRight().getX(), sourcePoints.bottomRight().x,
sourcePoints.bottomRight().getY(), sourcePoints.bottomRight().y,
sourcePoints.bottomLeft().getX(), sourcePoints.bottomLeft().x,
sourcePoints.bottomLeft().getY(), sourcePoints.bottomLeft().y,
); );
// let res = grid_sampler.sample_grid(startTracer.img, dimT as u32, dimR as u32, &transform); // let res = grid_sampler.sample_grid(startTracer.img, dimT as u32, dimR as u32, &transform);

View File

@@ -17,7 +17,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::common::Result; 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, * This class attempts to decode a barcode from an image, not by scanning the whole image,
@@ -133,7 +133,7 @@ impl<T: Reader> ByQuadrantReader<T> {
// result // result
points points
.iter() .iter()
.map(|relative| point(relative.getX() + leftOffset, relative.getY() + topOffset)) .map(|relative| point(relative.x + leftOffset, relative.y + topOffset))
.collect() .collect()
} }
} }

View File

@@ -18,7 +18,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::Result, point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, RXingResult, common::Result, point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, RXingResult,
Reader, ResultPoint, Reader,
}; };
use super::MultipleBarcodeReader; use super::MultipleBarcodeReader;
@@ -115,8 +115,8 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
// if (point == null) { // if (point == null) {
// continue; // continue;
// } // }
let x = point.getX(); let x = point.x;
let y = point.getY(); let y = point.y;
if x < minX { if x < minX {
minX = x; minX = x;
} }
@@ -185,12 +185,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
let newPoints: Vec<Point> = oldPoints let newPoints: Vec<Point> = oldPoints
.iter() .iter()
.map(|oldPoint| { .map(|oldPoint| point(oldPoint.x + xOffset as f32, oldPoint.y + yOffset as f32))
point(
oldPoint.getX() + xOffset as f32,
oldPoint.getY() + yOffset as f32,
)
})
.collect(); .collect();
// let mut newPoints = Vec::with_capacity(oldPoints.len()); // let mut newPoints = Vec::with_capacity(oldPoints.len());

View File

@@ -17,7 +17,7 @@
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
point, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, 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. // And remember to flip the result points horizontally.
let points = result.getPointsMut(); let points = result.getPointsMut();
if !points.is_empty() && points.len() >= 2 { if !points.is_empty() && points.len() >= 2 {
points[0] = point(width as f32 - points[0].getX() - 1.0, points[0].getY()); points[0] = point(width as f32 - points[0].x - 1.0, points[0].y);
points[1] = point(width as f32 - points[1].getX() - 1.0, points[1].getY()); points[1] = point(width as f32 - points[1].x - 1.0, points[1].y);
} }
} }
return Ok(result); return Ok(result);

View File

@@ -18,7 +18,7 @@ use std::rc::Rc;
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, Exceptions, Point, ResultPoint, point, Exceptions, Point,
}; };
/** /**
@@ -58,13 +58,13 @@ impl BoundingBox {
if leftUnspecified { if leftUnspecified {
newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?;
newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?; newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?;
newTopLeft = point(0.0, newTopRight.getY()); newTopLeft = point(0.0, newTopRight.y);
newBottomLeft = point(0.0, newBottomRight.getY()); newBottomLeft = point(0.0, newBottomRight.y);
} else if rightUnspecified { } else if rightUnspecified {
newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?; newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?;
newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?; newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?;
newTopRight = point(image.getWidth() as f32 - 1.0, newTopLeft.getY()); newTopRight = point(image.getWidth() as f32 - 1.0, newTopLeft.y);
newBottomRight = point(image.getWidth() as f32 - 1.0, newBottomLeft.getY()); newBottomRight = point(image.getWidth() as f32 - 1.0, newBottomLeft.y);
} else { } else {
newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?; newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?;
newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?;
@@ -74,10 +74,10 @@ impl BoundingBox {
Ok(BoundingBox { Ok(BoundingBox {
image, image,
minX: newTopLeft.getX().min(newBottomLeft.getX()) as u32, minX: newTopLeft.x.min(newBottomLeft.x) as u32,
maxX: newTopRight.getX().max(newBottomRight.getX()) as u32, maxX: newTopRight.x.max(newBottomRight.x) as u32,
minY: newTopLeft.getY().min(newTopRight.getY()) as u32, minY: newTopLeft.y.min(newTopRight.y) as u32,
maxY: newBottomLeft.getY().max(newBottomRight.getY()) as u32, maxY: newBottomLeft.y.max(newBottomRight.y) as u32,
topLeft: newTopLeft, topLeft: newTopLeft,
bottomLeft: newBottomLeft, bottomLeft: newBottomLeft,
topRight: newTopRight, topRight: newTopRight,
@@ -140,11 +140,11 @@ impl BoundingBox {
if missingStartRows > 0 { if missingStartRows > 0 {
let top = if isLeft { self.topLeft } else { self.topRight }; 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 { if newMinY < 0.0 {
newMinY = 0.0; newMinY = 0.0;
} }
let newTop = point(top.getX(), newMinY); let newTop = point(top.x, newMinY);
if isLeft { if isLeft {
newTopLeft = newTop; newTopLeft = newTop;
} else { } else {
@@ -158,11 +158,11 @@ impl BoundingBox {
} else { } else {
self.bottomRight self.bottomRight
}; };
let mut newMaxY = bottom.getY() as u32 + missingEndRows; let mut newMaxY = bottom.y as u32 + missingEndRows;
if newMaxY >= self.image.getHeight() { if newMaxY >= self.image.getHeight() {
newMaxY = self.image.getHeight() - 1; newMaxY = self.image.getHeight() - 1;
} }
let newBottom = point(bottom.getX(), newMaxY as f32); let newBottom = point(bottom.x, newMaxY as f32);
if isLeft { if isLeft {
newBottomLeft = newBottom; newBottomLeft = newBottom;
} else { } else {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::{pdf417::pdf_417_common, ResultPoint}; use crate::pdf417::pdf_417_common;
use super::{ use super::{
BarcodeMetadata, BarcodeValue, Codeword, DetectionRXingResultColumn, BarcodeMetadata, BarcodeValue, Codeword, DetectionRXingResultColumn,
@@ -63,8 +63,8 @@ impl DetectionRXingResultRowIndicatorColumn for DetectionRXingResultColumn {
boundingBox.getBottomRight() boundingBox.getBottomRight()
}; };
let firstRow = self.imageRowToCodewordIndex(top.getY() as u32); let firstRow = self.imageRowToCodewordIndex(top.y as u32);
let lastRow = self.imageRowToCodewordIndex(bottom.getY() 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 // We need to be careful using the average row height. Barcode could be skewed so that we have smaller and
// taller rows // taller rows
let averageRowHeight: f64 = let averageRowHeight: f64 =
@@ -263,8 +263,8 @@ fn adjustIncompleteIndicatorColumnRowNumbers(
} else { } else {
boundingBox.getBottomRight() boundingBox.getBottomRight()
}; };
let firstRow = col.imageRowToCodewordIndex(top.getY() as u32); let firstRow = col.imageRowToCodewordIndex(top.y as u32);
let lastRow = col.imageRowToCodewordIndex(bottom.getY() as u32); let lastRow = col.imageRowToCodewordIndex(bottom.y as u32);
let averageRowHeight: f64 = let averageRowHeight: f64 =
(lastRow as f64 - firstRow as f64) / barcodeMetadata.getRowCount() as f64; (lastRow as f64 - firstRow as f64) / barcodeMetadata.getRowCount() as f64;
let codewords = col.getCodewordsMut(); let codewords = col.getCodewordsMut();

View File

@@ -19,7 +19,7 @@ use std::rc::Rc;
use crate::{ use crate::{
common::{BitMatrix, DecoderRXingResult, Result}, common::{BitMatrix, DecoderRXingResult, Result},
pdf417::pdf_417_common, pdf417::pdf_417_common,
Exceptions, Point, ResultPoint, Exceptions, Point,
}; };
use super::{ use super::{
@@ -368,8 +368,8 @@ fn getRowIndicatorColumn<'a>(
for i in 0..2 { for i in 0..2 {
// for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
let increment: i32 = if i == 0 { 1 } else { -1 }; let increment: i32 = if i == 0 { 1 } else { -1 };
let mut startColumn: u32 = startPoint.getX() as u32; let mut startColumn: u32 = startPoint.x as u32;
let mut imageRow: i32 = startPoint.getY() as i32; let mut imageRow: i32 = startPoint.y as i32;
while imageRow <= boundingBox.getMaxY() as i32 && imageRow >= boundingBox.getMinY() as i32 { while imageRow <= boundingBox.getMaxY() as i32 && imageRow >= boundingBox.getMinY() as i32 {
// for (int imageRow = (int) startPoint.getY(); imageRow <= boundingBox.getMaxY() && // for (int imageRow = (int) startPoint.getY(); imageRow <= boundingBox.getMaxY() &&
// imageRow >= boundingBox.getMinY(); imageRow += increment) { // imageRow >= boundingBox.getMinY(); imageRow += increment) {

View File

@@ -16,7 +16,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, ResultPoint, point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point,
}; };
use std::borrow::Cow; use std::borrow::Cow;
@@ -137,10 +137,10 @@ pub fn detect(multiple: bool, bitMatrix: &BitMatrix) -> Option<Vec<[Option<Point
column = 0; column = 0;
for barcodeCoordinate in &barcodeCoordinates { for barcodeCoordinate in &barcodeCoordinates {
if let Some(coord_1) = barcodeCoordinate[1] { if let Some(coord_1) = barcodeCoordinate[1] {
row = row.max(coord_1.getY() as u32); row = row.max(coord_1.y as u32);
} }
if let Some(coord_3) = barcodeCoordinate[3] { if let Some(coord_3) = barcodeCoordinate[3] {
row = row.max(coord_3.getY() as u32); row = row.max(coord_3.y as u32);
} }
} }
row += ROW_STEP; row += ROW_STEP;
@@ -154,11 +154,11 @@ pub fn detect(multiple: bool, bitMatrix: &BitMatrix) -> Option<Vec<[Option<Point
// if we didn't find a right row indicator column, then continue the search for the next barcode after the // if we didn't find a right row indicator column, then continue the search for the next barcode after the
// start pattern of the barcode just found. // start pattern of the barcode just found.
if let Some(vert_2) = vertices[2] { if let Some(vert_2) = vertices[2] {
column = vert_2.getX() as u32; column = vert_2.x as u32;
row = vert_2.getY() as u32; row = vert_2.y as u32;
} else { } else {
column = vertices[4].as_ref().unwrap().getX() as u32; column = vertices[4].as_ref().unwrap().x as u32;
row = vertices[4].as_ref().unwrap().getY() as u32; row = vertices[4].as_ref().unwrap().y as u32;
} }
} }
Some(barcodeCoordinates) Some(barcodeCoordinates)
@@ -193,8 +193,8 @@ fn findVertices(matrix: &BitMatrix, startRow: u32, startColumn: u32) -> Option<[
); );
if let Some(result_4) = result[4] { if let Some(result_4) = result[4] {
startColumn = result_4.getX() as u32; startColumn = result_4.x as u32;
startRow = result_4.getY() as u32; startRow = result_4.y as u32;
} }
copyToRXingResult( copyToRXingResult(
&mut result, &mut result,
@@ -258,10 +258,7 @@ fn findRowsWithPattern(
// Last row of the current symbol that contains pattern // Last row of the current symbol that contains pattern
if found { if found {
let mut skippedRowCount = 0; let mut skippedRowCount = 0;
let mut previousRowLoc = [ let mut previousRowLoc = [result[0].as_ref()?.x as u32, result[1].as_ref()?.x as u32];
result[0].as_ref()?.getX() as u32,
result[1].as_ref()?.getX() as u32,
];
while stopRow < height { while stopRow < height {
if let Some(loc) = findGuardPattern( if let Some(loc) = findGuardPattern(
matrix, matrix,

View File

@@ -19,7 +19,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::Result, multi::MultipleBarcodeReader, BarcodeFormat, BinaryBitmap, common::Result, multi::MultipleBarcodeReader, BarcodeFormat, BinaryBitmap,
DecodingHintDictionary, Exceptions, Point, RXingResult, RXingResultMetadataType, DecodingHintDictionary, Exceptions, Point, RXingResult, RXingResultMetadataType,
RXingResultMetadataValue, Reader, ResultPoint, RXingResultMetadataValue, Reader,
}; };
use super::{ use super::{
@@ -153,7 +153,7 @@ impl PDF417Reader {
fn getMaxWidth(p1: &Option<Point>, p2: &Option<Point>) -> u64 { fn getMaxWidth(p1: &Option<Point>, p2: &Option<Point>) -> u64 {
if let (Some(p1), Some(p2)) = (p1, p2) { if let (Some(p1), Some(p2)) = (p1, p2) {
(p1.getX() - p2.getX()).abs() as u64 (p1.x - p2.x).abs() as u64
} else { } else {
0 0
} }
@@ -161,7 +161,7 @@ impl PDF417Reader {
fn getMinWidth(p1: &Option<Point>, p2: &Option<Point>) -> u64 { fn getMinWidth(p1: &Option<Point>, p2: &Option<Point>) -> u64 {
if let (Some(p1), Some(p2)) = (p1, p2) { if let (Some(p1), Some(p2)) = (p1, p2) {
(p1.getX() - p2.getX()).abs() as u64 (p1.x - p2.x).abs() as u64
} else { } else {
u32::MAX as u64 u32::MAX as u64
} }

View File

@@ -186,14 +186,14 @@ impl<'a> Detector<'_> {
let sourceBottomRightY: f32; let sourceBottomRightY: f32;
if alignmentPattern.is_some() { if alignmentPattern.is_some() {
let alignmentPattern = alignmentPattern?; let alignmentPattern = alignmentPattern?;
bottomRightX = alignmentPattern.getX(); bottomRightX = alignmentPattern.x;
bottomRightY = alignmentPattern.getY(); bottomRightY = alignmentPattern.y;
sourceBottomRightX = dimMinusThree - 3.0; sourceBottomRightX = dimMinusThree - 3.0;
sourceBottomRightY = sourceBottomRightX; sourceBottomRightY = sourceBottomRightX;
} else { } else {
// Don't have an alignment pattern, just make up the bottom-right point // Don't have an alignment pattern, just make up the bottom-right point
bottomRightX = (topRight.getX() - topLeft.getX()) + bottomLeft.getX(); bottomRightX = (topRight.x - topLeft.x) + bottomLeft.x;
bottomRightY = (topRight.getY() - topLeft.getY()) + bottomLeft.getY(); bottomRightY = (topRight.y - topLeft.y) + bottomLeft.y;
sourceBottomRightX = dimMinusThree; sourceBottomRightX = dimMinusThree;
sourceBottomRightY = dimMinusThree; sourceBottomRightY = dimMinusThree;
} }
@@ -207,14 +207,14 @@ impl<'a> Detector<'_> {
sourceBottomRightY, sourceBottomRightY,
3.5, 3.5,
dimMinusThree, dimMinusThree,
topLeft.getX(), topLeft.x,
topLeft.getY(), topLeft.y,
topRight.getX(), topRight.x,
topRight.getY(), topRight.y,
bottomRightX, bottomRightX,
bottomRightY, bottomRightY,
bottomLeft.getX(), bottomLeft.x,
bottomLeft.getY(), bottomLeft.y,
)) ))
} }
@@ -231,7 +231,7 @@ impl<'a> Detector<'_> {
* <p>Computes the dimension (number of modules on a size) of the QR Code based on the position * <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> * of the finder patterns and estimated module size.</p>
*/ */
fn computeDimension<T: Into<Point>>( fn computeDimension<T: Into<Point> + Copy>(
topLeft: T, topLeft: T,
topRight: T, topRight: T,
bottomLeft: T, bottomLeft: T,
@@ -260,7 +260,7 @@ impl<'a> Detector<'_> {
* @param bottomLeft detected bottom-left finder pattern center * @param bottomLeft detected bottom-left finder pattern center
* @return estimated module size * @return estimated module size
*/ */
pub fn calculateModuleSize<T: Into<Point>>( pub fn calculateModuleSize<T: Into<Point> + Copy>(
&self, &self,
topLeft: T, topLeft: T,
topRight: T, topRight: T,
@@ -282,16 +282,16 @@ impl<'a> Detector<'_> {
let otherPattern: Point = otherPattern.into(); let otherPattern: Point = otherPattern.into();
let moduleSizeEst1 = self.sizeOfBlackWhiteBlackRunBothWays( let moduleSizeEst1 = self.sizeOfBlackWhiteBlackRunBothWays(
pattern.getX().floor() as u32, pattern.x.floor() as u32,
pattern.getY().floor() as u32, pattern.y.floor() as u32,
otherPattern.getX().floor() as u32, otherPattern.x.floor() as u32,
otherPattern.getY().floor() as u32, otherPattern.y.floor() as u32,
); );
let moduleSizeEst2 = self.sizeOfBlackWhiteBlackRunBothWays( let moduleSizeEst2 = self.sizeOfBlackWhiteBlackRunBothWays(
otherPattern.getX().floor() as u32, otherPattern.x.floor() as u32,
otherPattern.getY().floor() as u32, otherPattern.y.floor() as u32,
pattern.getX().floor() as u32, pattern.x.floor() as u32,
pattern.getY().floor() as u32, pattern.y.floor() as u32,
); );
if moduleSizeEst1.is_nan() { if moduleSizeEst1.is_nan() {
return moduleSizeEst2 / 7.0; return moduleSizeEst2 / 7.0;

View File

@@ -6,7 +6,7 @@ use crate::Point;
* *
* @param patterns array of three {@code Point} to order * @param patterns array of three {@code Point} to order
*/ */
pub fn orderBestPatterns<T: Into<Point>>(patterns: &mut [T; 3]) { pub fn orderBestPatterns<T: Into<Point> + Copy>(patterns: &mut [T; 3]) {
// Find distances between pattern centers // Find distances between pattern centers
let zeroOneDistance = Point::distance(patterns[0].into(), patterns[1].into()); let zeroOneDistance = Point::distance(patterns[0].into(), patterns[1].into());
let oneTwoDistance = Point::distance(patterns[1].into(), patterns[2].into()); let oneTwoDistance = Point::distance(patterns[1].into(), patterns[2].into());

View File

@@ -1,11 +1,12 @@
use std::{fmt, iter::Sum}; use std::{fmt, iter::Sum};
use crate::ResultPoint;
use std::hash::Hash; use std::hash::Hash;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::ResultPoint;
/** /**
* <p>Encapsulates a point of interest in an image containing a barcode. Typically, this * <p>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.</p> * would be the location of a finder pattern or the corner of the barcode, for example.</p>
@@ -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 { impl ResultPoint for Point {
fn getX(&self) -> f32 { fn getX(&self) -> f32 {
self.x self.x