wip: Search & replace RXingResultPoint with Point

Build fails because the OneDReader proc macro expects
that a RXingResultPoint type exists.
This commit is contained in:
Vukašin Stepanović
2023-02-16 08:25:32 +00:00
parent 15280d5f98
commit dbc6ca4e55
57 changed files with 476 additions and 476 deletions

View File

@@ -18,7 +18,7 @@
// import com.google.zxing.aztec.encoder.EncoderTest; // import com.google.zxing.aztec.encoder.EncoderTest;
// import com.google.zxing.FormatException; // import com.google.zxing.FormatException;
// import com.google.zxing.RXingResultPoint; // import com.google.zxing.Point;
// import com.google.zxing.aztec.AztecDetectorRXingResult; // import com.google.zxing.aztec.AztecDetectorRXingResult;
// import com.google.zxing.common.BitArray; // import com.google.zxing.common.BitArray;
// import com.google.zxing.common.BitMatrix; // import com.google.zxing.common.BitMatrix;
@@ -29,7 +29,7 @@
use crate::{ use crate::{
aztec::shared_test_methods::{stripSpace, toBitArray, toBooleanArray}, aztec::shared_test_methods::{stripSpace, toBitArray, toBooleanArray},
common::BitMatrix, common::BitMatrix,
RXingResultPoint, Point,
}; };
use super::{aztec_detector_result::AztecDetectorRXingResult, decoder}; use super::{aztec_detector_result::AztecDetectorRXingResult, decoder};
@@ -38,7 +38,7 @@ use super::{aztec_detector_result::AztecDetectorRXingResult, decoder};
* Tests {@link Decoder}. * Tests {@link Decoder}.
*/ */
const NO_POINTS: [RXingResultPoint; 4] = [RXingResultPoint { x: 0.0, y: 0.0 }; 4]; const NO_POINTS: [Point; 4] = [Point { x: 0.0, y: 0.0 }; 4];
#[test] #[test]
fn test_high_level_decode() { fn test_high_level_decode() {

View File

@@ -39,7 +39,7 @@ use rand::Rng;
use crate::{aztec::decoder, common::BitMatrix, exceptions::Exceptions}; use crate::{aztec::decoder, common::BitMatrix, exceptions::Exceptions};
use super::{ use super::{
detector::{self, Detector, Point}, detector::{self, Detector, AztecPoint},
encoder::{self, AztecCode}, encoder::{self, AztecCode},
}; };
@@ -261,7 +261,7 @@ fn clone(input: &BitMatrix) -> BitMatrix {
result result
} }
fn get_orientation_points(code: &AztecCode) -> Vec<Point> { fn get_orientation_points(code: &AztecCode) -> Vec<AztecPoint> {
let center = code.getMatrix().getWidth() as i32 / 2; let center = code.getMatrix().getWidth() as i32 / 2;
let offset = if code.isCompact() { 5 } else { 7 }; let offset = if code.isCompact() { 5 } else { 7 };
let mut result = Vec::new(); let mut result = Vec::new();
@@ -271,12 +271,12 @@ fn get_orientation_points(code: &AztecCode) -> Vec<Point> {
let mut ySign: i32 = -1; let mut ySign: i32 = -1;
while ySign <= 1 { while ySign <= 1 {
// for (int ySign = -1; ySign <= 1; ySign += 2) { // for (int ySign = -1; ySign <= 1; ySign += 2) {
result.push(Point::new(center + xSign * offset, center + ySign * offset)); result.push(AztecPoint::new(center + xSign * offset, center + ySign * offset));
result.push(Point::new( result.push(AztecPoint::new(
center + xSign * (offset - 1), center + xSign * (offset - 1),
center + ySign * offset, center + ySign * offset,
)); ));
result.push(Point::new( result.push(AztecPoint::new(
center + xSign * offset, center + xSign * offset,
center + ySign * (offset - 1), center + ySign * (offset - 1),
)); ));

View File

@@ -25,7 +25,7 @@ use crate::{
encoder::HighLevelEncoder, encoder::HighLevelEncoder,
shared_test_methods::{stripSpace, toBitArray, toBooleanArray}, shared_test_methods::{stripSpace, toBitArray, toBooleanArray},
}, },
BarcodeFormat, EncodeHintType, EncodeHintValue, RXingResultPoint, BarcodeFormat, EncodeHintType, EncodeHintValue, Point,
}; };
use super::{encoder::aztec_encoder, AztecWriter}; use super::{encoder::aztec_encoder, AztecWriter};
@@ -50,7 +50,7 @@ const WINDOWS_1252: EncodingRef = encoding::all::WINDOWS_1252; //Charset.forName
// const DOTX: &str = "[^.X]"; // const DOTX: &str = "[^.X]";
// const SPACES: &str = "\\s+"; // const SPACES: &str = "\\s+";
const NO_POINTS: [RXingResultPoint; 4] = [RXingResultPoint { x: 0.0, y: 0.0 }; 4]; const NO_POINTS: [Point; 4] = [Point { x: 0.0, y: 0.0 }; 4];
// real life tests // real life tests

View File

@@ -16,13 +16,13 @@
// package com.google.zxing.aztec; // package com.google.zxing.aztec;
// import com.google.zxing.RXingResultPoint; // import com.google.zxing.Point;
// import com.google.zxing.common.BitMatrix; // import com.google.zxing.common.BitMatrix;
// import com.google.zxing.common.DetectorRXingResult; // import com.google.zxing.common.DetectorRXingResult;
use crate::{ use crate::{
common::{BitMatrix, DetectorRXingResult}, common::{BitMatrix, DetectorRXingResult},
RXingResultPoint, Point,
}; };
/** /**
@@ -33,7 +33,7 @@ use crate::{
*/ */
pub struct AztecDetectorRXingResult { pub struct AztecDetectorRXingResult {
bits: BitMatrix, bits: BitMatrix,
points: [RXingResultPoint; 4], points: [Point; 4],
compact: bool, compact: bool,
nbDatablocks: u32, nbDatablocks: u32,
nbLayers: u32, nbLayers: u32,
@@ -44,7 +44,7 @@ impl DetectorRXingResult for AztecDetectorRXingResult {
&self.bits &self.bits
} }
fn getPoints(&self) -> &[RXingResultPoint] { fn getPoints(&self) -> &[Point] {
&self.points &self.points
} }
} }
@@ -52,7 +52,7 @@ impl DetectorRXingResult for AztecDetectorRXingResult {
impl AztecDetectorRXingResult { impl AztecDetectorRXingResult {
pub fn new( pub fn new(
bits: BitMatrix, bits: BitMatrix,
points: [RXingResultPoint; 4], points: [Point; 4],
compact: bool, compact: bool,
nbDatablocks: u32, nbDatablocks: u32,
nbLayers: u32, nbLayers: u32,

View File

@@ -23,7 +23,7 @@ use crate::{
BitMatrix, DefaultGridSampler, GridSampler, Result, BitMatrix, DefaultGridSampler, GridSampler, Result,
}, },
exceptions::Exceptions, exceptions::Exceptions,
RXingResultPoint, ResultPoint, Point, ResultPoint,
}; };
use super::aztec_detector_result::AztecDetectorRXingResult; use super::aztec_detector_result::AztecDetectorRXingResult;
@@ -118,7 +118,7 @@ impl<'a> Detector<'_> {
* @param bullsEyeCorners the array of bull's eye corners * @param bullsEyeCorners the array of bull's eye corners
* @throws NotFoundException in case of too many errors or invalid parameters * @throws NotFoundException in case of too many errors or invalid parameters
*/ */
fn extractParameters(&mut self, bulls_eye_corners: &[RXingResultPoint]) -> Result<()> { fn extractParameters(&mut self, bulls_eye_corners: &[Point]) -> Result<()> {
if !self.is_valid(bulls_eye_corners[0]) if !self.is_valid(bulls_eye_corners[0])
|| !self.is_valid(bulls_eye_corners[1]) || !self.is_valid(bulls_eye_corners[1])
|| !self.is_valid(bulls_eye_corners[2]) || !self.is_valid(bulls_eye_corners[2])
@@ -266,7 +266,7 @@ impl<'a> Detector<'_> {
* @return The corners of the bull-eye * @return The corners of the bull-eye
* @throws NotFoundException If no valid bull-eye can be found * @throws NotFoundException If no valid bull-eye can be found
*/ */
fn get_bulls_eye_corners(&mut self, pCenter: Point) -> Result<[RXingResultPoint; 4]> { fn get_bulls_eye_corners(&mut self, pCenter: AztecPoint) -> Result<[Point; 4]> {
let mut pina = pCenter; let mut pina = pCenter;
let mut pinb = pCenter; let mut pinb = pCenter;
let mut pinc = pCenter; let mut pinc = pCenter;
@@ -326,13 +326,13 @@ impl<'a> Detector<'_> {
// Expand the square by .5 pixel in each direction so that we're on the border // Expand the square by .5 pixel in each direction so that we're on the border
// between the white square and the black square // between the white square and the black square
let pinax = let pinax =
RXingResultPoint::new(pina.get_x() as f32 + 0.5f32, pina.get_y() as f32 - 0.5f32); Point::new(pina.get_x() as f32 + 0.5f32, pina.get_y() as f32 - 0.5f32);
let pinbx = let pinbx =
RXingResultPoint::new(pinb.get_x() as f32 + 0.5f32, pinb.get_y() as f32 + 0.5f32); Point::new(pinb.get_x() as f32 + 0.5f32, pinb.get_y() as f32 + 0.5f32);
let pincx = let pincx =
RXingResultPoint::new(pinc.get_x() as f32 - 0.5f32, pinc.get_y() as f32 + 0.5f32); Point::new(pinc.get_x() as f32 - 0.5f32, pinc.get_y() as f32 + 0.5f32);
let pindx = let pindx =
RXingResultPoint::new(pind.get_x() as f32 - 0.5f32, pind.get_y() as f32 - 0.5f32); Point::new(pind.get_x() as f32 - 0.5f32, pind.get_y() as f32 - 0.5f32);
// Expand the square so that its corners are the centers of the points // Expand the square so that its corners are the centers of the points
// just outside the bull's eye. // just outside the bull's eye.
@@ -348,11 +348,11 @@ impl<'a> Detector<'_> {
* *
* @return the center point * @return the center point
*/ */
fn get_matrix_center(&self) -> Point { fn get_matrix_center(&self) -> AztecPoint {
let mut point_a = RXingResultPoint::default(); let mut point_a = Point::default();
let mut point_b = RXingResultPoint::default(); let mut point_b = Point::default();
let mut point_c = RXingResultPoint::default(); let mut point_c = Point::default();
let mut point_d = RXingResultPoint::default(); let mut point_d = Point::default();
let mut fnd = false; let mut fnd = false;
@@ -373,16 +373,16 @@ impl<'a> Detector<'_> {
let cx: i32 = (self.image.getWidth() / 2) as i32; let cx: i32 = (self.image.getWidth() / 2) as i32;
let cy: i32 = (self.image.getHeight() / 2) as i32; let cy: i32 = (self.image.getHeight() / 2) as i32;
point_a = self point_a = self
.get_first_different(&Point::new(cx + 7, cy - 7), false, 1, -1) .get_first_different(&AztecPoint::new(cx + 7, cy - 7), false, 1, -1)
.into(); .into();
point_b = self point_b = self
.get_first_different(&Point::new(cx + 7, cy + 7), false, 1, 1) .get_first_different(&AztecPoint::new(cx + 7, cy + 7), false, 1, 1)
.into(); .into();
point_c = self point_c = self
.get_first_different(&Point::new(cx - 7, cy + 7), false, -1, 1) .get_first_different(&AztecPoint::new(cx - 7, cy + 7), false, -1, 1)
.into(); .into();
point_d = self point_d = self
.get_first_different(&Point::new(cx - 7, cy - 7), false, -1, -1) .get_first_different(&AztecPoint::new(cx - 7, cy - 7), false, -1, -1)
.into(); .into();
} }
// try { // try {
@@ -399,10 +399,10 @@ impl<'a> Detector<'_> {
// // In that case, surely in the bull's eye, we try to expand the rectangle. // // In that case, surely in the bull's eye, we try to expand the rectangle.
// int cx = image.getWidth() / 2; // int cx = image.getWidth() / 2;
// int cy = image.getHeight() / 2; // int cy = image.getHeight() / 2;
// pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toRXingResultPoint(); // pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toPoint();
// pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toRXingResultPoint(); // pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toPoint();
// pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toRXingResultPoint(); // pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toPoint();
// pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toRXingResultPoint(); // pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toPoint();
// } // }
@@ -431,20 +431,20 @@ impl<'a> Detector<'_> {
// In that case we try to expand the rectangle. // In that case we try to expand the rectangle.
if !fnd { if !fnd {
point_a = self point_a = self
.get_first_different(&Point::new(cx + 7, cy - 7), false, 1, -1) .get_first_different(&AztecPoint::new(cx + 7, cy - 7), false, 1, -1)
.into(); .into();
point_b = self point_b = self
.get_first_different(&Point::new(cx + 7, cy + 7), false, 1, 1) .get_first_different(&AztecPoint::new(cx + 7, cy + 7), false, 1, 1)
.into(); .into();
point_c = self point_c = self
.get_first_different(&Point::new(cx - 7, cy + 7), false, -1, 1) .get_first_different(&AztecPoint::new(cx - 7, cy + 7), false, -1, 1)
.into(); .into();
point_d = self point_d = self
.get_first_different(&Point::new(cx - 7, cy - 7), false, -1, -1) .get_first_different(&AztecPoint::new(cx - 7, cy - 7), false, -1, -1)
.into(); .into();
} }
// try { // try {
// RXingResultPoint[] cornerPoints = new WhiteRectangleDetector(image, 15, cx, cy).detect(); // Point[] cornerPoints = new WhiteRectangleDetector(image, 15, cx, cy).detect();
// pointA = cornerPoints[0]; // pointA = cornerPoints[0];
// pointB = cornerPoints[1]; // pointB = cornerPoints[1];
// pointC = cornerPoints[2]; // pointC = cornerPoints[2];
@@ -452,10 +452,10 @@ impl<'a> Detector<'_> {
// } catch (NotFoundException e) { // } catch (NotFoundException e) {
// // This exception can be in case the initial rectangle is white // // This exception can be in case the initial rectangle is white
// // In that case we try to expand the rectangle. // // In that case we try to expand the rectangle.
// pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toRXingResultPoint(); // pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toPoint();
// pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toRXingResultPoint(); // pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toPoint();
// pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toRXingResultPoint(); // pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toPoint();
// pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toRXingResultPoint(); // pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toPoint();
// } // }
// Recompute the center of the rectangle // Recompute the center of the rectangle
@@ -466,7 +466,7 @@ impl<'a> Detector<'_> {
(point_a.getY() + point_d.getY() + point_b.getY() + point_c.getY()) / 4.0f32, (point_a.getY() + point_d.getY() + point_b.getY() + point_c.getY()) / 4.0f32,
); );
Point::new(cx, cy) AztecPoint::new(cx, cy)
} }
/** /**
@@ -477,8 +477,8 @@ impl<'a> Detector<'_> {
*/ */
fn get_matrix_corner_points( fn get_matrix_corner_points(
&self, &self,
bulls_eye_corners: &[RXingResultPoint], bulls_eye_corners: &[Point],
) -> [RXingResultPoint; 4] { ) -> [Point; 4] {
Self::expand_square( Self::expand_square(
bulls_eye_corners, bulls_eye_corners,
2 * self.nb_center_layers, 2 * self.nb_center_layers,
@@ -494,10 +494,10 @@ impl<'a> Detector<'_> {
fn sample_grid( fn sample_grid(
&self, &self,
image: &BitMatrix, image: &BitMatrix,
top_left: RXingResultPoint, top_left: Point,
top_right: RXingResultPoint, top_right: Point,
bottom_right: RXingResultPoint, bottom_right: Point,
bottom_left: RXingResultPoint, bottom_left: Point,
) -> Result<BitMatrix> { ) -> Result<BitMatrix> {
let sampler = DefaultGridSampler::default(); let sampler = DefaultGridSampler::default();
let dimension = self.get_dimension(); let dimension = self.get_dimension();
@@ -536,7 +536,7 @@ impl<'a> Detector<'_> {
* @param size number of bits * @param size number of bits
* @return the array of bits as an int (first bit is high-order bit of result) * @return the array of bits as an int (first bit is high-order bit of result)
*/ */
fn sample_line(&self, p1: RXingResultPoint, p2: RXingResultPoint, size: u32) -> u32 { fn sample_line(&self, p1: Point, p2: Point, size: u32) -> u32 {
let mut result = 0; let mut result = 0;
let d = Self::distance(p1, p2); let d = Self::distance(p1, p2);
@@ -561,23 +561,23 @@ impl<'a> Detector<'_> {
* @return true if the border of the rectangle passed in parameter is compound of white points only * @return true if the border of the rectangle passed in parameter is compound of white points only
* or black points only * or black points only
*/ */
fn is_white_or_black_rectangle(&self, p1: &Point, p2: &Point, p3: &Point, p4: &Point) -> bool { fn is_white_or_black_rectangle(&self, p1: &AztecPoint, p2: &AztecPoint, p3: &AztecPoint, p4: &AztecPoint) -> bool {
let corr = 3; let corr = 3;
let p1 = Point::new( let p1 = AztecPoint::new(
0.max(p1.get_x() - corr), 0.max(p1.get_x() - corr),
(self.image.getHeight() as i32 - 1).min(p1.get_y() + corr), (self.image.getHeight() as i32 - 1).min(p1.get_y() + corr),
); );
// let p1 = Point::new(Math.max(0, p1.getX() - corr), Math.min(image.getHeight() - 1, p1.getY() + corr)); // let p1 = Point::new(Math.max(0, p1.getX() - corr), Math.min(image.getHeight() - 1, p1.getY() + corr));
let p2 = Point::new(0.max(p2.get_x() - corr), 0.max(p2.get_y() - corr)); let p2 = AztecPoint::new(0.max(p2.get_x() - corr), 0.max(p2.get_y() - corr));
// let p2 = Point::new(Math.max(0, p2.getX() - corr), Math.max(0, p2.getY() - corr)); // let p2 = Point::new(Math.max(0, p2.getX() - corr), Math.max(0, p2.getY() - corr));
let p3 = Point::new( let p3 = AztecPoint::new(
(self.image.getWidth() as i32 - 1).min(p3.get_x() + corr), (self.image.getWidth() as i32 - 1).min(p3.get_x() + corr),
0.max((self.image.getHeight() as i32 - 1).min(p3.get_y() - corr)), 0.max((self.image.getHeight() as i32 - 1).min(p3.get_y() - corr)),
); );
// let p3 = Point::new(Math.min(image.getWidth() - 1, p3.getX() + corr), // let p3 = Point::new(Math.min(image.getWidth() - 1, p3.getX() + corr),
// Math.max(0, Math.min(image.getHeight() - 1, p3.getY() - corr))); // Math.max(0, Math.min(image.getHeight() - 1, p3.getY() - corr)));
let p4 = Point::new( let p4 = AztecPoint::new(
(self.image.getWidth() as i32 - 1).min(p4.get_x() + corr), (self.image.getWidth() as i32 - 1).min(p4.get_x() + corr),
(self.image.getHeight() as i32 - 1).min(p4.get_y() + corr), (self.image.getHeight() as i32 - 1).min(p4.get_y() + corr),
); );
@@ -612,7 +612,7 @@ impl<'a> Detector<'_> {
* *
* @return 1 if segment more than 90% black, -1 if segment is more than 90% white, 0 else * @return 1 if segment more than 90% black, -1 if segment is more than 90% white, 0 else
*/ */
fn get_color(&self, p1: &Point, p2: &Point) -> i32 { fn get_color(&self, p1: &AztecPoint, p2: &AztecPoint) -> i32 {
let d = Self::distance_points(p1, p2); let d = Self::distance_points(p1, p2);
if d == 0.0f32 { if d == 0.0f32 {
return 0; return 0;
@@ -657,7 +657,7 @@ impl<'a> Detector<'_> {
/** /**
* Gets the coordinate of the first point with a different color in the given direction * Gets the coordinate of the first point with a different color in the given direction
*/ */
fn get_first_different(&self, init: &Point, color: bool, dx: i32, dy: i32) -> Point { fn get_first_different(&self, init: &AztecPoint, color: bool, dx: i32, dy: i32) -> AztecPoint {
let mut x = init.get_x() + dx; let mut x = init.get_x() + dx;
let mut y = init.get_y() + dy; let mut y = init.get_y() + dy;
@@ -679,7 +679,7 @@ impl<'a> Detector<'_> {
} }
y -= dy; y -= dy;
Point::new(x, y) AztecPoint::new(x, y)
} }
/** /**
@@ -691,10 +691,10 @@ impl<'a> Detector<'_> {
* @return the corners of the expanded square * @return the corners of the expanded square
*/ */
fn expand_square( fn expand_square(
corner_points: &[RXingResultPoint], corner_points: &[Point],
old_side: u32, old_side: u32,
new_side: u32, new_side: u32,
) -> [RXingResultPoint; 4] { ) -> [Point; 4] {
let ratio = new_side as f32 / (2.0f32 * old_side as f32); let ratio = new_side as f32 / (2.0f32 * old_side as f32);
let d = corner_points[0] - corner_points[2]; let d = corner_points[0] - corner_points[2];
@@ -714,17 +714,17 @@ impl<'a> Detector<'_> {
x >= 0 && x < self.image.getWidth() as i32 && y >= 0 && y < self.image.getHeight() as i32 x >= 0 && x < self.image.getWidth() as i32 && y >= 0 && y < self.image.getHeight() as i32
} }
fn is_valid(&self, point: RXingResultPoint) -> bool { fn is_valid(&self, point: Point) -> bool {
let x = MathUtils::round(point.getX()); let x = MathUtils::round(point.getX());
let y = MathUtils::round(point.getY()); let y = MathUtils::round(point.getY());
self.is_valid_points(x, y) self.is_valid_points(x, y)
} }
fn distance_points(a: &Point, b: &Point) -> f32 { fn distance_points(a: &AztecPoint, b: &AztecPoint) -> f32 {
MathUtils::distance(a.get_x(), a.get_y(), b.get_x(), b.get_y()) MathUtils::distance(a.get_x(), a.get_y(), b.get_x(), b.get_y())
} }
fn distance(a: RXingResultPoint, b: RXingResultPoint) -> f32 { fn distance(a: Point, b: Point) -> f32 {
MathUtils::distance(a.getX(), a.getY(), b.getX(), b.getY()) MathUtils::distance(a.getX(), a.getY(), b.getX(), b.getY())
} }
@@ -738,12 +738,12 @@ impl<'a> Detector<'_> {
} }
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Point { pub struct AztecPoint {
x: i32, x: i32,
y: i32, y: i32,
} }
impl Point { impl AztecPoint {
pub fn new(x: i32, y: i32) -> Self { pub fn new(x: i32, y: i32) -> Self {
Self { x, y } Self { x, y }
} }
@@ -757,13 +757,13 @@ impl Point {
} }
} }
impl From<Point> for RXingResultPoint { impl From<AztecPoint> for Point {
fn from(value: Point) -> Self { fn from(value: AztecPoint) -> Self {
RXingResultPoint::new(value.x as f32, value.y as f32) Point::new(value.x as f32, value.y as f32)
} }
} }
impl fmt::Display for Point { impl fmt::Display for AztecPoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<{} {}>", &self.x, &self.y) write!(f, "<{} {}>", &self.x, &self.y)
} }

View File

@@ -21,7 +21,7 @@
use std::fmt; use std::fmt;
use crate::common::Result; use crate::common::Result;
use crate::{Exceptions, RXingResultPoint}; use crate::{Exceptions, Point};
use super::BitArray; use super::BitArray;
@@ -213,7 +213,7 @@ impl BitMatrix {
((self.bits[offset] >> (x & 0x1f)) & 1) != 0 ((self.bits[offset] >> (x & 0x1f)) & 1) != 0
} }
pub fn get_point(&self, point: RXingResultPoint) -> bool { pub fn get_point(&self, point: Point) -> bool {
self.get(point.x as u32, point.y as u32) self.get(point.x as u32, point.y as u32)
// let offset = self.get_offset(point.y as u32, point.x as u32); // let offset = self.get_offset(point.y as u32, point.x as u32);
// ((self.bits[offset] >> (x & 0x1f)) & 1) != 0 // ((self.bits[offset] >> (x & 0x1f)) & 1) != 0
@@ -695,7 +695,7 @@ impl BitMatrix {
new_bm new_bm
} }
pub fn isIn(&self, p: RXingResultPoint, b: i32) -> bool { pub fn isIn(&self, p: Point, b: i32) -> bool {
b as f32 <= p.x b as f32 <= p.x
&& p.x < self.getWidth() as f32 - b as f32 && p.x < self.getWidth() as f32 - b as f32
&& b as f32 <= p.y && b as f32 <= p.y

View File

@@ -19,7 +19,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
Exceptions, RXingResultPoint, ResultPoint, Exceptions, Point, ResultPoint,
}; };
/** /**
@@ -45,13 +45,13 @@ impl<'a> MonochromeRectangleDetector<'_> {
* <p>Detects a rectangular region of black and white -- mostly black -- with a region of mostly * <p>Detects a rectangular region of black and white -- mostly black -- with a region of mostly
* white, in an image.</p> * white, in an image.</p>
* *
* @return {@link RXingResultPoint}[] describing the corners of the rectangular region. The first and * @return {@link Point}[] describing the corners of the rectangular region. The first and
* last points are opposed on the diagonal, as are the second and third. The first point will be * last points are opposed on the diagonal, as are the second and third. The first point will be
* the topmost point and the last, the bottommost. The second point will be leftmost and the * the topmost point and the last, the bottommost. The second point will be leftmost and the
* third, the rightmost * third, the rightmost
* @throws NotFoundException if no Data Matrix Code can be found * @throws NotFoundException if no Data Matrix Code can be found
*/ */
pub fn detect(&self) -> Result<[RXingResultPoint; 4]> { pub fn detect(&self) -> Result<[Point; 4]> {
let height = self.image.getHeight() as i32; let height = self.image.getHeight() as i32;
let width = self.image.getWidth() as i32; let width = self.image.getWidth() as i32;
let halfHeight = height / 2; let halfHeight = height / 2;
@@ -143,7 +143,7 @@ impl<'a> MonochromeRectangleDetector<'_> {
* @param bottom maximum value of y * @param bottom maximum value of y
* @param maxWhiteRun maximum run of white pixels that can still be considered to be within * @param maxWhiteRun maximum run of white pixels that can still be considered to be within
* the barcode * the barcode
* @return a {@link RXingResultPoint} encapsulating the corner that was found * @return a {@link Point} encapsulating the corner that was found
* @throws NotFoundException if such a point cannot be found * @throws NotFoundException if such a point cannot be found
*/ */
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@@ -158,7 +158,7 @@ impl<'a> MonochromeRectangleDetector<'_> {
top: i32, top: i32,
bottom: i32, bottom: i32,
maxWhiteRun: i32, maxWhiteRun: i32,
) -> Result<RXingResultPoint> { ) -> Result<Point> {
let mut lastRange_z: Option<[i32; 2]> = None; let mut lastRange_z: Option<[i32; 2]> = None;
let mut y: i32 = centerY; let mut y: i32 = centerY;
let mut x: i32 = centerX; let mut x: i32 = centerX;
@@ -178,27 +178,27 @@ impl<'a> MonochromeRectangleDetector<'_> {
if lastRange[0] < centerX { if lastRange[0] < centerX {
if lastRange[1] > centerX { if lastRange[1] > centerX {
// straddle, choose one or the other based on direction // straddle, choose one or the other based on direction
return Ok(RXingResultPoint::new( return Ok(Point::new(
lastRange[usize::from(deltaY <= 0)] as f32, lastRange[usize::from(deltaY <= 0)] as f32,
lastY as f32, lastY as f32,
)); ));
} }
return Ok(RXingResultPoint::new(lastRange[0] as f32, lastY as f32)); return Ok(Point::new(lastRange[0] as f32, lastY as f32));
} else { } else {
return Ok(RXingResultPoint::new(lastRange[1] as f32, lastY as f32)); return Ok(Point::new(lastRange[1] as f32, lastY as f32));
} }
} else { } else {
let lastX = x - deltaX; let lastX = x - deltaX;
if lastRange[0] < centerY { if lastRange[0] < centerY {
if lastRange[1] > centerY { if lastRange[1] > centerY {
return Ok(RXingResultPoint::new( return Ok(Point::new(
lastX as f32, lastX as f32,
lastRange[usize::from(deltaX >= 0)] as f32, lastRange[usize::from(deltaX >= 0)] as f32,
)); ));
} }
return Ok(RXingResultPoint::new(lastX as f32, lastRange[0] as f32)); return Ok(Point::new(lastX as f32, lastRange[0] as f32));
} else { } else {
return Ok(RXingResultPoint::new(lastX as f32, lastRange[1] as f32)); return Ok(Point::new(lastX as f32, lastRange[1] as f32));
} }
} }
} }

View File

@@ -18,7 +18,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
Exceptions, RXingResultPoint, ResultPoint, Exceptions, Point, ResultPoint,
}; };
use super::MathUtils; use super::MathUtils;
@@ -101,14 +101,14 @@ impl<'a> WhiteRectangleDetector<'_> {
* region until it finds a white rectangular region. * region until it finds a white rectangular region.
* </p> * </p>
* *
* @return {@link RXingResultPoint}[] describing the corners of the rectangular * @return {@link Point}[] describing the corners of the rectangular
* region. The first and last points are opposed on the diagonal, as * region. The first and last points are opposed on the diagonal, as
* are the second and third. The first point will be the topmost * are the second and third. The first point will be the topmost
* point and the last, the bottommost. The second point will be * point and the last, the bottommost. The second point will be
* leftmost and the third, the rightmost * leftmost and the third, the rightmost
* @throws NotFoundException if no Data Matrix Code can be found * @throws NotFoundException if no Data Matrix Code can be found
*/ */
pub fn detect(&self) -> Result<[RXingResultPoint; 4]> { pub fn detect(&self) -> Result<[Point; 4]> {
let mut left: i32 = self.leftInit; let mut left: i32 = self.leftInit;
let mut right: i32 = self.rightInit; let mut right: i32 = self.rightInit;
let mut up: i32 = self.upInit; let mut up: i32 = self.upInit;
@@ -212,7 +212,7 @@ impl<'a> WhiteRectangleDetector<'_> {
if !size_exceeded { if !size_exceeded {
let max_size = right - left; let max_size = right - left;
let mut z: Option<RXingResultPoint> = None; let mut z: Option<Point> = None;
let mut i = 1; let mut i = 1;
while z.is_none() && i < max_size { while z.is_none() && i < max_size {
//for (int i = 1; z == null && i < maxSize; i++) { //for (int i = 1; z == null && i < maxSize; i++) {
@@ -229,7 +229,7 @@ impl<'a> WhiteRectangleDetector<'_> {
return Err(Exceptions::NotFoundException(None)); return Err(Exceptions::NotFoundException(None));
} }
let mut t: Option<RXingResultPoint> = None; let mut t: Option<Point> = None;
//go down right //go down right
let mut i = 1; let mut i = 1;
while t.is_none() && i < max_size { while t.is_none() && i < max_size {
@@ -247,7 +247,7 @@ impl<'a> WhiteRectangleDetector<'_> {
return Err(Exceptions::NotFoundException(None)); return Err(Exceptions::NotFoundException(None));
} }
let mut x: Option<RXingResultPoint> = None; let mut x: Option<Point> = None;
//go down left //go down left
let mut i = 1; let mut i = 1;
while x.is_none() && i < max_size { while x.is_none() && i < max_size {
@@ -265,7 +265,7 @@ impl<'a> WhiteRectangleDetector<'_> {
return Err(Exceptions::NotFoundException(None)); return Err(Exceptions::NotFoundException(None));
} }
let mut y: Option<RXingResultPoint> = None; let mut y: Option<Point> = None;
//go up left //go up left
let mut i = 1; let mut i = 1;
while y.is_none() && i < max_size { while y.is_none() && i < max_size {
@@ -295,7 +295,7 @@ impl<'a> WhiteRectangleDetector<'_> {
a_y: f32, a_y: f32,
b_x: f32, b_x: f32,
b_y: f32, b_y: f32,
) -> Option<RXingResultPoint> { ) -> Option<Point> {
let dist = MathUtils::round(MathUtils::distance(a_x, a_y, b_x, b_y)); let dist = MathUtils::round(MathUtils::distance(a_x, a_y, b_x, b_y));
let x_step: f32 = (b_x - a_x) / dist as f32; let x_step: f32 = (b_x - a_x) / dist as f32;
let y_step: f32 = (b_y - a_y) / dist as f32; let y_step: f32 = (b_y - a_y) / dist as f32;
@@ -304,7 +304,7 @@ impl<'a> WhiteRectangleDetector<'_> {
let x = MathUtils::round(a_x + i as f32 * x_step); let x = MathUtils::round(a_x + i as f32 * x_step);
let y = MathUtils::round(a_y + i as f32 * y_step); let y = MathUtils::round(a_y + i as f32 * y_step);
if self.image.get(x as u32, y as u32) { if self.image.get(x as u32, y as u32) {
return Some(RXingResultPoint::new(x as f32, y as f32)); return Some(Point::new(x as f32, y as f32));
} }
} }
None None
@@ -317,7 +317,7 @@ impl<'a> WhiteRectangleDetector<'_> {
* @param z left most point * @param z left most point
* @param x right most point * @param x right most point
* @param t top most point * @param t top most point
* @return {@link RXingResultPoint}[] describing the corners of the rectangular * @return {@link Point}[] describing the corners of the rectangular
* region. The first and last points are opposed on the diagonal, as * region. The first and last points are opposed on the diagonal, as
* are the second and third. The first point will be the topmost * are the second and third. The first point will be the topmost
* point and the last, the bottommost. The second point will be * point and the last, the bottommost. The second point will be
@@ -325,11 +325,11 @@ impl<'a> WhiteRectangleDetector<'_> {
*/ */
fn center_edges( fn center_edges(
&self, &self,
y: RXingResultPoint, y: Point,
z: RXingResultPoint, z: Point,
x: RXingResultPoint, x: Point,
t: RXingResultPoint, t: Point,
) -> [RXingResultPoint; 4] { ) -> [Point; 4] {
// //
// t t // t t
// z x // z x
@@ -348,17 +348,17 @@ impl<'a> WhiteRectangleDetector<'_> {
if yi < self.width as f32 / 2.0f32 { if yi < self.width as f32 / 2.0f32 {
[ [
RXingResultPoint::new(ti - CORR as f32, tj + CORR as f32), Point::new(ti - CORR as f32, tj + CORR as f32),
RXingResultPoint::new(zi + CORR as f32, zj + CORR as f32), Point::new(zi + CORR as f32, zj + CORR as f32),
RXingResultPoint::new(xi - CORR as f32, xj - CORR as f32), Point::new(xi - CORR as f32, xj - CORR as f32),
RXingResultPoint::new(yi + CORR as f32, yj - CORR as f32), Point::new(yi + CORR as f32, yj - CORR as f32),
] ]
} else { } else {
[ [
RXingResultPoint::new(ti + CORR as f32, tj + CORR as f32), Point::new(ti + CORR as f32, tj + CORR as f32),
RXingResultPoint::new(zi + CORR as f32, zj - CORR as f32), Point::new(zi + CORR as f32, zj - CORR as f32),
RXingResultPoint::new(xi - CORR as f32, xj + CORR as f32), Point::new(xi - CORR as f32, xj + CORR as f32),
RXingResultPoint::new(yi - CORR as f32, yj - CORR as f32), Point::new(yi - CORR as f32, yj - CORR as f32),
] ]
} }
} }

View File

@@ -1,7 +1,7 @@
pub mod detector; pub mod detector;
pub mod reedsolomon; pub mod reedsolomon;
use crate::RXingResultPoint; use crate::Point;
#[cfg(test)] #[cfg(test)]
mod StringUtilsTestCase; mod StringUtilsTestCase;
@@ -44,7 +44,7 @@ pub type Result<T, E = crate::Exceptions> = std::result::Result<T, E>;
// package com.google.zxing.common; // package com.google.zxing.common;
// import com.google.zxing.RXingResultPoint; // import com.google.zxing.Point;
/** /**
* <p>Encapsulates the result of detecting a barcode in an image. This includes the raw * <p>Encapsulates the result of detecting a barcode in an image. This includes the raw
@@ -56,12 +56,12 @@ pub type Result<T, E = crate::Exceptions> = std::result::Result<T, E>;
pub trait DetectorRXingResult { pub trait DetectorRXingResult {
fn getBits(&self) -> &BitMatrix; fn getBits(&self) -> &BitMatrix;
fn getPoints(&self) -> &[RXingResultPoint]; fn getPoints(&self) -> &[Point];
} }
// pub struct DetectorRXingResult { // pub struct DetectorRXingResult {
// bits: BitMatrix, // bits: BitMatrix,
// points: Vec<RXingResultPoint>, // points: Vec<Point>,
// } // }
mod bit_matrix; mod bit_matrix;

View File

@@ -39,7 +39,7 @@ static DECODER: Lazy<Decoder> = Lazy::new(Decoder::new);
#[derive(Default)] #[derive(Default)]
pub struct DataMatrixReader; pub struct DataMatrixReader;
// private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0]; // private static final Point[] NO_POINTS = new Point[0];
// private final Decoder decoder = new Decoder(); // private final Decoder decoder = new Decoder();

View File

@@ -18,7 +18,7 @@ use crate::{
common::{ common::{
detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result, detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result,
}, },
Exceptions, RXingResultPoint, ResultPoint, Exceptions, Point, ResultPoint,
}; };
use super::DatamatrixDetectorResult; use super::DatamatrixDetectorResult;
@@ -101,13 +101,13 @@ impl<'a> Detector<'_> {
)) ))
} }
fn shiftPoint(point: RXingResultPoint, to: RXingResultPoint, div: u32) -> RXingResultPoint { fn shiftPoint(point: Point, to: Point, div: u32) -> Point {
let x = (to.getX() - point.getX()) / (div as f32 + 1.0); let x = (to.getX() - point.getX()) / (div as f32 + 1.0);
let y = (to.getY() - point.getY()) / (div as f32 + 1.0); let y = (to.getY() - point.getY()) / (div as f32 + 1.0);
RXingResultPoint::new(point.getX() + x, point.getY() + y) Point::new(point.getX() + x, point.getY() + y)
} }
fn moveAway(point: RXingResultPoint, fromX: f32, fromY: f32) -> RXingResultPoint { fn moveAway(point: Point, fromX: f32, fromY: f32) -> Point {
let mut x = point.getX(); let mut x = point.getX();
let mut y = point.getY(); let mut y = point.getY();
@@ -123,13 +123,13 @@ impl<'a> Detector<'_> {
y += 1.0; y += 1.0;
} }
RXingResultPoint::new(x, y) Point::new(x, y)
} }
/** /**
* Detect a solid side which has minimum transition. * Detect a solid side which has minimum transition.
*/ */
fn detectSolid1(&self, cornerPoints: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] { fn detectSolid1(&self, cornerPoints: [Point; 4]) -> [Point; 4] {
// 0 2 // 0 2
// 1 3 // 1 3
let pointA = cornerPoints[0]; let pointA = cornerPoints[0];
@@ -174,7 +174,7 @@ impl<'a> Detector<'_> {
/** /**
* Detect a second solid side next to first solid side. * Detect a second solid side next to first solid side.
*/ */
fn detectSolid2(&self, points: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] { fn detectSolid2(&self, points: [Point; 4]) -> [Point; 4] {
// A..D // A..D
// : : // : :
// B--C // B--C
@@ -214,7 +214,7 @@ impl<'a> Detector<'_> {
/** /**
* Calculates the corner position of the white top right module. * Calculates the corner position of the white top right module.
*/ */
fn correctTopRight(&self, points: &[RXingResultPoint; 4]) -> Option<RXingResultPoint> { fn correctTopRight(&self, points: &[Point; 4]) -> Option<Point> {
// A..D // A..D
// | : // | :
// B--C // B--C
@@ -232,11 +232,11 @@ impl<'a> Detector<'_> {
trTop = self.transitionsBetween(pointAs, pointD); trTop = self.transitionsBetween(pointAs, pointD);
trRight = self.transitionsBetween(pointCs, pointD); trRight = self.transitionsBetween(pointCs, pointD);
let candidate1 = RXingResultPoint::new( let candidate1 = Point::new(
pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop as f32 + 1.0), pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop as f32 + 1.0),
pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop as f32 + 1.0), pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop as f32 + 1.0),
); );
let candidate2 = RXingResultPoint::new( let candidate2 = Point::new(
pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight as f32 + 1.0), pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight as f32 + 1.0),
pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight as f32 + 1.0), pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight as f32 + 1.0),
); );
@@ -266,7 +266,7 @@ impl<'a> Detector<'_> {
/** /**
* Shift the edge points to the module center. * Shift the edge points to the module center.
*/ */
fn shiftToModuleCenter(&self, points: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] { fn shiftToModuleCenter(&self, points: [Point; 4]) -> [Point; 4] {
// A..D // A..D
// | : // | :
// B--C // B--C
@@ -318,7 +318,7 @@ impl<'a> Detector<'_> {
[pointAs, pointBs, pointCs, pointDs] [pointAs, pointBs, pointCs, pointDs]
} }
fn isValid(&self, p: RXingResultPoint) -> bool { fn isValid(&self, p: Point) -> bool {
p.getX() >= 0.0 p.getX() >= 0.0
&& p.getX() <= self.image.getWidth() as f32 - 1.0 && p.getX() <= self.image.getWidth() as f32 - 1.0
&& p.getY() > 0.0 && p.getY() > 0.0
@@ -327,10 +327,10 @@ impl<'a> Detector<'_> {
fn sampleGrid( fn sampleGrid(
image: &BitMatrix, image: &BitMatrix,
topLeft: RXingResultPoint, topLeft: Point,
bottomLeft: RXingResultPoint, bottomLeft: Point,
bottomRight: RXingResultPoint, bottomRight: Point,
topRight: RXingResultPoint, topRight: Point,
dimensionX: u32, dimensionX: u32,
dimensionY: u32, dimensionY: u32,
) -> Result<BitMatrix> { ) -> Result<BitMatrix> {
@@ -362,7 +362,7 @@ impl<'a> Detector<'_> {
/** /**
* Counts the number of black/white transitions between two points, using something like Bresenham's algorithm. * Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.
*/ */
fn transitionsBetween(&self, from: RXingResultPoint, to: RXingResultPoint) -> 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.getX().floor() as i32;
let mut fromY = from.getY().floor() as i32; let mut fromY = from.getY().floor() as i32;

View File

@@ -1,12 +1,12 @@
use crate::{ use crate::{
common::{BitMatrix, DetectorRXingResult}, common::{BitMatrix, DetectorRXingResult},
RXingResultPoint, Point,
}; };
pub struct DatamatrixDetectorResult(BitMatrix, Vec<RXingResultPoint>); pub struct DatamatrixDetectorResult(BitMatrix, Vec<Point>);
impl DatamatrixDetectorResult { impl DatamatrixDetectorResult {
pub fn new(bits: BitMatrix, points: Vec<RXingResultPoint>) -> Self { pub fn new(bits: BitMatrix, points: Vec<Point>) -> Self {
Self(bits, points) Self(bits, points)
} }
} }
@@ -16,7 +16,7 @@ impl DetectorRXingResult for DatamatrixDetectorResult {
&self.0 &self.0
} }
fn getPoints(&self) -> &[RXingResultPoint] { fn getPoints(&self) -> &[Point] {
&self.1 &self.1
} }
} }

View File

@@ -1,4 +1,4 @@
use crate::RXingResultPoint; use crate::Point;
use super::{util::opposite, Direction, Value}; use super::{util::opposite, Direction, Value};
@@ -16,28 +16,28 @@ pub trait BitMatrixCursor {
// BitMatrixCursor(const BitMatrix& image, POINT p, POINT d) : img(&image), p(p) { setDirection(d); } // BitMatrixCursor(const BitMatrix& image, POINT p, POINT d) : img(&image), p(p) { setDirection(d); }
fn testAt(&self, p: RXingResultPoint) -> Value; //const fn testAt(&self, p: Point) -> Value; //const
// { // {
// return img->isIn(p) ? Value{img->get(p)} : Value{}; // return img->isIn(p) ? Value{img->get(p)} : Value{};
// } // }
fn blackAt(&self, pos: RXingResultPoint) -> bool { fn blackAt(&self, pos: Point) -> bool {
self.testAt(pos).isBlack() self.testAt(pos).isBlack()
} }
fn whiteAt(&self, pos: RXingResultPoint) -> bool { fn whiteAt(&self, pos: Point) -> bool {
self.testAt(pos).isWhite() self.testAt(pos).isWhite()
} }
fn isIn(&self, p: RXingResultPoint) -> bool; // { return img->isIn(p); } fn isIn(&self, p: Point) -> bool; // { return img->isIn(p); }
fn isInSelf(&self) -> bool; // { return self.isIn(p); } fn isInSelf(&self) -> bool; // { return self.isIn(p); }
fn isBlack(&self) -> bool; // { return blackAt(p); } fn isBlack(&self) -> bool; // { return blackAt(p); }
fn isWhite(&self) -> bool; // { return whiteAt(p); } fn isWhite(&self) -> bool; // { return whiteAt(p); }
fn front(&self) -> &RXingResultPoint; //{ return d; } fn front(&self) -> &Point; //{ return d; }
fn back(&self) -> RXingResultPoint; // { return {-d.x, -d.y}; } fn back(&self) -> Point; // { return {-d.x, -d.y}; }
fn left(&self) -> RXingResultPoint; //{ return {d.y, -d.x}; } fn left(&self) -> Point; //{ return {d.y, -d.x}; }
fn right(&self) -> RXingResultPoint; //{ return {-d.y, d.x}; } fn right(&self) -> Point; //{ return {-d.y, d.x}; }
fn direction(&self, dir: Direction) -> RXingResultPoint { fn direction(&self, dir: Direction) -> Point {
self.right() * Into::<i32>::into(dir) self.right() * Into::<i32>::into(dir)
} }
@@ -46,7 +46,7 @@ pub trait BitMatrixCursor {
fn turnRight(&mut self); //noexcept { d = right(); } fn turnRight(&mut self); //noexcept { d = right(); }
fn turn(&mut self, dir: Direction); //noexcept { d = direction(dir); } fn turn(&mut self, dir: Direction); //noexcept { d = direction(dir); }
fn edgeAt_point(&self, d: RXingResultPoint) -> Value; fn edgeAt_point(&self, d: Point) -> Value;
// { // {
// Value v = testAt(p); // Value v = testAt(p);
// return testAt(p + d) != v ? v : Value(); // return testAt(p + d) != v ? v : Value();
@@ -68,8 +68,8 @@ pub trait BitMatrixCursor {
self.edgeAt_point(self.direction(dir)) self.edgeAt_point(self.direction(dir))
} }
fn setDirection(&mut self, dir: RXingResultPoint); // { d = bresenhamDirection(dir); } fn setDirection(&mut self, dir: Point); // { d = bresenhamDirection(dir); }
// fn setDirection(&self, dir: RXingResultPoint);// { d = dir; } // fn setDirection(&self, dir: Point);// { d = dir; }
fn step(&mut self, s: Option<f32>) -> bool; // DEF to 1 fn step(&mut self, s: Option<f32>) -> bool; // DEF to 1
// { // {
@@ -77,7 +77,7 @@ pub trait BitMatrixCursor {
// return isIn(p); // return isIn(p);
// } // }
fn movedBy<T: BitMatrixCursor>(self, d: RXingResultPoint) -> Self; fn movedBy<T: BitMatrixCursor>(self, d: Point) -> Self;
// { // {
// auto res = *this; // auto res = *this;
// res.p += d; // res.p += d;

View File

@@ -21,7 +21,7 @@ use crate::{
}, },
qrcode::encoder::ByteMatrix, qrcode::encoder::ByteMatrix,
result_point_utils::distance, result_point_utils::distance,
Exceptions, RXingResultPoint, ResultPoint, Exceptions, Point, ResultPoint,
}; };
use super::{DMRegressionLine, EdgeTracer}; use super::{DMRegressionLine, EdgeTracer};
@@ -46,10 +46,10 @@ fn Scan(
continue; continue;
} }
let mut tl = RXingResultPoint::default(); let mut tl = Point::default();
let mut bl = RXingResultPoint::default(); let mut bl = Point::default();
let mut br = RXingResultPoint::default(); let mut br = Point::default();
let mut tr = RXingResultPoint::default(); let mut tr = Point::default();
for l in lines.iter_mut() { for l in lines.iter_mut() {
l.reset(); l.reset();
@@ -197,13 +197,13 @@ fn Scan(
CHECK!((10..=144).contains(&dimT) && (8..=144).contains(&dimR)); CHECK!((10..=144).contains(&dimT) && (8..=144).contains(&dimR));
let movedTowardsBy = |a: RXingResultPoint, let movedTowardsBy = |a: Point,
b1: RXingResultPoint, b1: Point,
b2: RXingResultPoint, b2: Point,
d: f32| d: f32|
-> RXingResultPoint { -> Point {
a + d * RXingResultPoint::normalized( a + d * Point::normalized(
RXingResultPoint::normalized(b1 - a) + RXingResultPoint::normalized(b2 - a), Point::normalized(b1 - a) + Point::normalized(b2 - a),
) )
}; };
@@ -292,18 +292,18 @@ pub fn detect(
const MIN_SYMBOL_SIZE: u32 = 8 * 2; // minimum realistic size in pixel: 8 modules x 2 pixels per module const MIN_SYMBOL_SIZE: u32 = 8 * 2; // minimum realistic size in pixel: 8 modules x 2 pixels per module
for dir in [ for dir in [
RXingResultPoint { x: -1.0, y: 0.0 }, Point { x: -1.0, y: 0.0 },
RXingResultPoint { x: 1.0, y: 0.0 }, Point { x: 1.0, y: 0.0 },
RXingResultPoint { x: 0.0, y: -1.0 }, Point { x: 0.0, y: -1.0 },
RXingResultPoint { x: 0.0, y: 1.0 }, Point { x: 0.0, y: 1.0 },
] { ] {
// for (auto dir : {PointF(-1, 0), PointF(1, 0), PointF(0, -1), PointF(0, 1)}) { // for (auto dir : {PointF(-1, 0), PointF(1, 0), PointF(0, -1), PointF(0, 1)}) {
let center = RXingResultPoint { let center = Point {
x: (image.getWidth() / 2) as f32, x: (image.getWidth() / 2) as f32,
y: (image.getHeight() / 2) as f32, y: (image.getHeight() / 2) as f32,
}; //PointF(image.width() / 2, image.height() / 2); }; //PointF(image.width() / 2, image.height() / 2);
let startPos = let startPos =
RXingResultPoint::centered(center - center * dir + MIN_SYMBOL_SIZE as i32 / 2 * dir); Point::centered(center - center * dir + MIN_SYMBOL_SIZE as i32 / 2 * dir);
if let Some(history) = &mut history { if let Some(history) = &mut history {
history.borrow_mut().clear(0); history.borrow_mut().clear(0);

View File

@@ -1,5 +1,5 @@
use crate::common::Result; use crate::common::Result;
use crate::{Exceptions, RXingResultPoint}; use crate::{Exceptions, Point};
use super::{ use super::{
util::{float_max, float_min}, util::{float_max, float_min},
@@ -8,8 +8,8 @@ use super::{
#[derive(Clone)] #[derive(Clone)]
pub struct DMRegressionLine { pub struct DMRegressionLine {
points: Vec<RXingResultPoint>, points: Vec<Point>,
direction_inward: RXingResultPoint, direction_inward: Point,
pub(super) a: f32, pub(super) a: f32,
pub(super) b: f32, pub(super) b: f32,
pub(super) c: f32, pub(super) c: f32,
@@ -31,13 +31,13 @@ impl Default for DMRegressionLine {
} }
impl RegressionLine for DMRegressionLine { impl RegressionLine for DMRegressionLine {
fn points(&self) -> &[RXingResultPoint] { fn points(&self) -> &[Point] {
&self.points &self.points
} }
fn length(&self) -> u32 { fn length(&self) -> u32 {
if self.points.len() >= 2 { if self.points.len() >= 2 {
RXingResultPoint::distance(*self.points.first().unwrap(), *self.points.last().unwrap()) Point::distance(*self.points.first().unwrap(), *self.points.last().unwrap())
as u32 as u32
} else { } else {
0 0
@@ -48,9 +48,9 @@ impl RegressionLine for DMRegressionLine {
!self.a.is_nan() !self.a.is_nan()
} }
fn normal(&self) -> RXingResultPoint { fn normal(&self) -> Point {
if self.isValid() { if self.isValid() {
RXingResultPoint { Point {
x: self.a, x: self.a,
y: self.b, y: self.b,
} }
@@ -59,29 +59,29 @@ impl RegressionLine for DMRegressionLine {
} }
} }
fn signedDistance(&self, p: RXingResultPoint) -> f32 { fn signedDistance(&self, p: Point) -> f32 {
RXingResultPoint::dot(self.normal(), p) - self.c Point::dot(self.normal(), p) - self.c
} }
fn distance_single(&self, p: RXingResultPoint) -> f32 { fn distance_single(&self, p: Point) -> f32 {
(self.signedDistance(p)).abs() (self.signedDistance(p)).abs()
} }
fn reset(&mut self) { fn reset(&mut self) {
self.points.clear(); self.points.clear();
self.direction_inward = RXingResultPoint { x: 0.0, y: 0.0 }; self.direction_inward = Point { x: 0.0, y: 0.0 };
self.a = f32::NAN; self.a = f32::NAN;
self.b = f32::NAN; self.b = f32::NAN;
self.c = f32::NAN; self.c = f32::NAN;
} }
fn add(&mut self, p: RXingResultPoint) -> Result<()> { fn add(&mut self, p: Point) -> Result<()> {
if self.direction_inward == RXingResultPoint::default() { if self.direction_inward == Point::default() {
return Err(Exceptions::IllegalStateException(None)); return Err(Exceptions::IllegalStateException(None));
} }
self.points.push(p); self.points.push(p);
if self.points.len() == 1 { if self.points.len() == 1 {
self.c = RXingResultPoint::dot(self.normal(), p); self.c = Point::dot(self.normal(), p);
} }
Ok(()) Ok(())
} }
@@ -90,8 +90,8 @@ impl RegressionLine for DMRegressionLine {
self.points.pop(); self.points.pop();
} }
fn setDirectionInward(&mut self, d: RXingResultPoint) { fn setDirectionInward(&mut self, d: Point) {
self.direction_inward = RXingResultPoint::normalized(d); self.direction_inward = Point::normalized(d);
} }
fn evaluate_max_distance( fn evaluate_max_distance(
@@ -149,8 +149,8 @@ impl RegressionLine for DMRegressionLine {
steps > 2.0 || len > 50.0 steps > 2.0 || len > 50.0
} }
fn evaluate(&mut self, points: &[RXingResultPoint]) -> bool { fn evaluate(&mut self, points: &[Point]) -> bool {
let mean = points.iter().sum::<RXingResultPoint>() / points.len() as f32; let mean = points.iter().sum::<Point>() / points.len() as f32;
let mut sumXX = 0.0; let mut sumXX = 0.0;
let mut sumYY = 0.0; let mut sumYY = 0.0;
@@ -171,18 +171,18 @@ impl RegressionLine for DMRegressionLine {
self.a = sumXY / l; self.a = sumXY / l;
self.b = -sumXX / l; self.b = -sumXX / l;
} }
if RXingResultPoint::dot(self.direction_inward, self.normal()) < 0.0 { if Point::dot(self.direction_inward, self.normal()) < 0.0 {
// if (dot(_directionInward, normal()) < 0) { // if (dot(_directionInward, normal()) < 0) {
self.a = -self.a; self.a = -self.a;
self.b = -self.b; self.b = -self.b;
} }
self.c = RXingResultPoint::dot(self.normal(), mean); // (a*mean.x + b*mean.y); self.c = Point::dot(self.normal(), mean); // (a*mean.x + b*mean.y);
RXingResultPoint::dot(self.direction_inward, self.normal()) > 0.5 Point::dot(self.direction_inward, self.normal()) > 0.5
// angle between original and new direction is at most 60 degree // angle between original and new direction is at most 60 degree
} }
fn evaluateSelf(&mut self) -> bool { fn evaluateSelf(&mut self) -> bool {
let mean = self.points.iter().sum::<RXingResultPoint>() / self.points.len() as f32; let mean = self.points.iter().sum::<Point>() / self.points.len() as f32;
let mut sumXX = 0.0; let mut sumXX = 0.0;
let mut sumYY = 0.0; let mut sumYY = 0.0;
@@ -203,13 +203,13 @@ impl RegressionLine for DMRegressionLine {
self.a = sumXY / l; self.a = sumXY / l;
self.b = -sumXX / l; self.b = -sumXX / l;
} }
if RXingResultPoint::dot(self.direction_inward, self.normal()) < 0.0 { if Point::dot(self.direction_inward, self.normal()) < 0.0 {
// if (dot(_directionInward, normal()) < 0) { // if (dot(_directionInward, normal()) < 0) {
self.a = -self.a; self.a = -self.a;
self.b = -self.b; self.b = -self.b;
} }
self.c = RXingResultPoint::dot(self.normal(), mean); // (a*mean.x + b*mean.y); self.c = Point::dot(self.normal(), mean); // (a*mean.x + b*mean.y);
RXingResultPoint::dot(self.direction_inward, self.normal()) > 0.5 Point::dot(self.direction_inward, self.normal()) > 0.5
// angle between original and new direction is at most 60 degree // angle between original and new direction is at most 60 degree
} }
} }
@@ -236,7 +236,7 @@ impl DMRegressionLine {
self.points.reverse(); self.points.reverse();
} }
pub fn modules(&mut self, beg: RXingResultPoint, end: RXingResultPoint) -> Result<f64> { pub fn modules(&mut self, beg: Point, end: Point) -> Result<f64> {
if self.points.len() <= 3 { if self.points.len() <= 3 {
return Err(Exceptions::IllegalStateException(None)); return Err(Exceptions::IllegalStateException(None));
} }
@@ -260,7 +260,7 @@ impl DMRegressionLine {
} }
// calculate the (expected average) distance of two adjacent pixels // calculate the (expected average) distance of two adjacent pixels
let unitPixelDist = RXingResultPoint::length(RXingResultPoint::bresenhamDirection( let unitPixelDist = Point::length(Point::bresenhamDirection(
self.points self.points
.last() .last()
.copied() .copied()

View File

@@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
qrcode::encoder::ByteMatrix, qrcode::encoder::ByteMatrix,
Exceptions, RXingResultPoint, Exceptions, Point,
}; };
use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value}; use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value};
@@ -12,8 +12,8 @@ use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value};
pub struct EdgeTracer<'a> { pub struct EdgeTracer<'a> {
pub(super) img: &'a BitMatrix, pub(super) img: &'a BitMatrix,
pub(super) p: RXingResultPoint, // current position pub(super) p: Point, // current position
d: RXingResultPoint, // current direction d: Point, // current direction
// pub history: Option<&'a mut ByteMatrix>, // = nullptr; // pub history: Option<&'a mut ByteMatrix>, // = nullptr;
pub history: Option<Rc<RefCell<ByteMatrix>>>, pub history: Option<Rc<RefCell<ByteMatrix>>>,
@@ -35,7 +35,7 @@ pub struct EdgeTracer<'a> {
// } // }
impl BitMatrixCursor for EdgeTracer<'_> { impl BitMatrixCursor for EdgeTracer<'_> {
fn testAt(&self, p: RXingResultPoint) -> Value { fn testAt(&self, p: Point) -> Value {
if self.img.isIn(p, 0) { if self.img.isIn(p, 0) {
Value::from(self.img.get_point(p)) Value::from(self.img.get_point(p))
} else { } else {
@@ -43,7 +43,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
} }
} }
fn isIn(&self, p: RXingResultPoint) -> bool { fn isIn(&self, p: Point) -> bool {
self.img.isIn(p, 0) self.img.isIn(p, 0)
} }
@@ -59,26 +59,26 @@ impl BitMatrixCursor for EdgeTracer<'_> {
self.whiteAt(self.p) self.whiteAt(self.p)
} }
fn front(&self) -> &RXingResultPoint { fn front(&self) -> &Point {
&self.d &self.d
} }
fn back(&self) -> RXingResultPoint { fn back(&self) -> Point {
RXingResultPoint { Point {
x: -self.d.x, x: -self.d.x,
y: -self.d.y, y: -self.d.y,
} }
} }
fn left(&self) -> RXingResultPoint { fn left(&self) -> Point {
RXingResultPoint { Point {
x: self.d.y, x: self.d.y,
y: -self.d.x, y: -self.d.x,
} }
} }
fn right(&self) -> RXingResultPoint { fn right(&self) -> Point {
RXingResultPoint { Point {
x: -self.d.y, x: -self.d.y,
y: self.d.x, y: self.d.x,
} }
@@ -100,7 +100,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
self.d = self.direction(dir) self.d = self.direction(dir)
} }
fn edgeAt_point(&self, d: RXingResultPoint) -> Value { fn edgeAt_point(&self, d: Point) -> Value {
let v = self.testAt(self.p); let v = self.testAt(self.p);
if self.testAt(self.p + d) != v { if self.testAt(self.p + d) != v {
v v
@@ -109,7 +109,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
} }
} }
fn setDirection(&mut self, dir: RXingResultPoint) { fn setDirection(&mut self, dir: Point) {
self.d = dir.bresenhamDirection(); self.d = dir.bresenhamDirection();
} }
@@ -119,7 +119,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
self.isIn(self.p) self.isIn(self.p)
} }
fn movedBy<T: BitMatrixCursor>(self, d: RXingResultPoint) -> Self { fn movedBy<T: BitMatrixCursor>(self, d: Point) -> Self {
let mut res = self; let mut res = self;
res.p += d; res.p += d;
@@ -158,7 +158,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
} }
impl<'a> EdgeTracer<'_> { impl<'a> EdgeTracer<'_> {
pub fn new(image: &'a BitMatrix, p: RXingResultPoint, d: RXingResultPoint) -> EdgeTracer<'a> { pub fn new(image: &'a BitMatrix, p: Point, d: Point) -> EdgeTracer<'a> {
// : img(&image), p(p) { setDirection(d); } // : img(&image), p(p) { setDirection(d); }
EdgeTracer { EdgeTracer {
img: image, img: image,
@@ -171,11 +171,11 @@ impl<'a> EdgeTracer<'_> {
fn traceStep( fn traceStep(
&mut self, &mut self,
dEdge: RXingResultPoint, dEdge: Point,
maxStepSize: i32, maxStepSize: i32,
goodDirection: bool, goodDirection: bool,
) -> Result<StepResult> { ) -> Result<StepResult> {
let dEdge = RXingResultPoint::mainDirection(dEdge); let dEdge = Point::mainDirection(dEdge);
for breadth in 1..=(if maxStepSize == 1 { for breadth in 1..=(if maxStepSize == 1 {
2 2
} else if goodDirection { } else if goodDirection {
@@ -243,28 +243,28 @@ impl<'a> EdgeTracer<'_> {
Ok(StepResult::OpenEnd) Ok(StepResult::OpenEnd)
} }
pub fn updateDirectionFromOrigin(&mut self, origin: RXingResultPoint) -> bool { pub fn updateDirectionFromOrigin(&mut self, origin: Point) -> bool {
let old_d = self.d; let old_d = self.d;
self.setDirection(self.p - origin); self.setDirection(self.p - origin);
// if the new direction is pointing "backward", i.e. angle(new, old) > 90 deg -> break // if the new direction is pointing "backward", i.e. angle(new, old) > 90 deg -> break
if RXingResultPoint::dot(self.d, old_d) < 0.0 { if Point::dot(self.d, old_d) < 0.0 {
return false; return false;
} }
// make sure d stays in the same quadrant to prevent an infinite loop // make sure d stays in the same quadrant to prevent an infinite loop
if (self.d.x).abs() == (self.d.y).abs() { if (self.d.x).abs() == (self.d.y).abs() {
self.d = RXingResultPoint::mainDirection(old_d) self.d = Point::mainDirection(old_d)
+ 0.99 * (self.d - RXingResultPoint::mainDirection(old_d)); + 0.99 * (self.d - Point::mainDirection(old_d));
} else if RXingResultPoint::mainDirection(self.d) != RXingResultPoint::mainDirection(old_d) } else if Point::mainDirection(self.d) != Point::mainDirection(old_d)
{ {
self.d = RXingResultPoint::mainDirection(old_d) self.d = Point::mainDirection(old_d)
+ 0.99 * RXingResultPoint::mainDirection(self.d); + 0.99 * Point::mainDirection(self.d);
} }
true true
} }
pub fn traceLine<T: RegressionLine>( pub fn traceLine<T: RegressionLine>(
&mut self, &mut self,
dEdge: RXingResultPoint, dEdge: Point,
line: &mut T, line: &mut T,
) -> Result<bool> { ) -> Result<bool> {
line.setDirectionInward(dEdge); line.setDirectionInward(dEdge);
@@ -295,7 +295,7 @@ impl<'a> EdgeTracer<'_> {
pub fn traceGaps<T: RegressionLine>( pub fn traceGaps<T: RegressionLine>(
&mut self, &mut self,
dEdge: RXingResultPoint, dEdge: Point,
line: &mut T, line: &mut T,
maxStepSize: i32, maxStepSize: i32,
finishLine: &mut T, finishLine: &mut T,
@@ -341,7 +341,7 @@ impl<'a> EdgeTracer<'_> {
// In case the 'go outward' step in traceStep lead us astray, we might end up with a line // In case the 'go outward' step in traceStep lead us astray, we might end up with a line
// that is almost perpendicular to d. Then the back-projection below can result in an // that is almost perpendicular to d. Then the back-projection below can result in an
// endless loop. Break if the angle between d and line is greater than 45 deg. // endless loop. Break if the angle between d and line is greater than 45 deg.
if (RXingResultPoint::dot(RXingResultPoint::normalized(self.d), line.normal())) if (Point::dot(Point::normalized(self.d), line.normal()))
.abs() .abs()
> 0.7 > 0.7
// thresh is approx. sin(45 deg) // thresh is approx. sin(45 deg)
@@ -361,7 +361,7 @@ impl<'a> EdgeTracer<'_> {
// The 'while' instead of 'if' was introduced to fix the issue with #245. It turns out that // The 'while' instead of 'if' was introduced to fix the issue with #245. It turns out that
// np can actually be behind the projection of the last line point and we need 2 steps in d // np can actually be behind the projection of the last line point and we need 2 steps in d
// to prevent a dead lock. see #245.png // to prevent a dead lock. see #245.png
while RXingResultPoint::distance( while Point::distance(
np, np,
line.project( line.project(
line.points() line.points()
@@ -373,13 +373,13 @@ impl<'a> EdgeTracer<'_> {
{ {
np += self.d; np += self.d;
} }
self.p = RXingResultPoint::centered(np); self.p = Point::centered(np);
} else { } else {
let stepLengthInMainDir = if line.points().is_empty() { let stepLengthInMainDir = if line.points().is_empty() {
0.0 0.0
} else { } else {
RXingResultPoint::dot( Point::dot(
RXingResultPoint::mainDirection(self.d), Point::mainDirection(self.d),
self.p self.p
- line - line
.points() .points()
@@ -441,8 +441,8 @@ impl<'a> EdgeTracer<'_> {
pub fn traceCorner( pub fn traceCorner(
&mut self, &mut self,
dir: &mut RXingResultPoint, dir: &mut Point,
corner: &mut RXingResultPoint, corner: &mut Point,
) -> Result<bool> { ) -> Result<bool> {
self.step(None); self.step(None);
// log(p); // log(p);

View File

@@ -1,7 +1,7 @@
use crate::RXingResultPoint; use crate::Point;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Quadrilateral([RXingResultPoint; 4]); pub struct Quadrilateral([Point; 4]);
impl Quadrilateral { impl Quadrilateral {
// using Base = std::array<T, 4>; // using Base = std::array<T, 4>;
@@ -11,31 +11,31 @@ impl Quadrilateral {
#[allow(dead_code)] #[allow(dead_code)]
pub fn new() -> Self { pub fn new() -> Self {
Self([RXingResultPoint { x: 0.0, y: 0.0 }; 4]) Self([Point { x: 0.0, y: 0.0 }; 4])
} }
// pub fn with_f32( tl:f32, tr:f32, br:f32, bl:f32) -> Self { // pub fn with_f32( tl:f32, tr:f32, br:f32, bl:f32) -> Self {
// Self([tl, tr,br, bl ]) // Self([tl, tr,br, bl ])
// } // }
pub fn with_points( pub fn with_points(
tl: RXingResultPoint, tl: Point,
tr: RXingResultPoint, tr: Point,
br: RXingResultPoint, br: Point,
bl: RXingResultPoint, bl: Point,
) -> Self { ) -> Self {
Self([tl, tr, br, bl]) Self([tl, tr, br, bl])
} }
pub fn topLeft(&self) -> &RXingResultPoint { pub fn topLeft(&self) -> &Point {
&self.0[0] &self.0[0]
} //const noexcept { return at(0); } } //const noexcept { return at(0); }
pub fn topRight(&self) -> &RXingResultPoint { pub fn topRight(&self) -> &Point {
&self.0[1] &self.0[1]
} //const noexcept { return at(1); } } //const noexcept { return at(1); }
pub fn bottomRight(&self) -> &RXingResultPoint { pub fn bottomRight(&self) -> &Point {
&self.0[2] &self.0[2]
} //const noexcept { return at(2); } } //const noexcept { return at(2); }
pub fn bottomLeft(&self) -> &RXingResultPoint { pub fn bottomLeft(&self) -> &Point {
&self.0[3] &self.0[3]
} //const noexcept { return at(3); } } //const noexcept { return at(3); }
@@ -43,13 +43,13 @@ impl Quadrilateral {
pub fn orientation(&self) -> f64 { pub fn orientation(&self) -> f64 {
let centerLine = let centerLine =
(*self.topRight() + *self.bottomRight()) - (*self.topLeft() + *self.bottomLeft()); (*self.topRight() + *self.bottomRight()) - (*self.topLeft() + *self.bottomLeft());
if (centerLine == RXingResultPoint { x: 0.0, y: 0.0 }) { if (centerLine == Point { x: 0.0, y: 0.0 }) {
return 0.0; return 0.0;
} }
let centerLineF = RXingResultPoint::normalized(centerLine); let centerLineF = Point::normalized(centerLine);
f32::atan2(centerLineF.y, centerLineF.x).into() f32::atan2(centerLineF.y, centerLineF.x).into()
} }
pub fn points(&self) -> &[RXingResultPoint] { pub fn points(&self) -> &[Point] {
&self.0 &self.0
} }
} }
@@ -59,19 +59,19 @@ pub fn Rectangle(width: i32, height: i32, margin: Option<i32>) -> Quadrilateral
let margin = if let Some(m) = margin { m } else { 0 }; let margin = if let Some(m) = margin { m } else { 0 };
Quadrilateral([ Quadrilateral([
RXingResultPoint { Point {
x: margin as f32, x: margin as f32,
y: margin as f32, y: margin as f32,
}, },
RXingResultPoint { Point {
x: width as f32 - margin as f32, x: width as f32 - margin as f32,
y: margin as f32, y: margin as f32,
}, },
RXingResultPoint { Point {
x: width as f32 - margin as f32, x: width as f32 - margin as f32,
y: height as f32 - margin as f32, y: height as f32 - margin as f32,
}, },
RXingResultPoint { Point {
x: margin as f32, x: margin as f32,
y: height as f32 - margin as f32, y: height as f32 - margin as f32,
}, },
@@ -82,10 +82,10 @@ pub fn Rectangle(width: i32, height: i32, margin: Option<i32>) -> Quadrilateral
pub fn CenteredSquare(size: i32) -> Quadrilateral { pub fn CenteredSquare(size: i32) -> Quadrilateral {
Scale( Scale(
&Quadrilateral([ &Quadrilateral([
RXingResultPoint { x: -1.0, y: -1.0 }, Point { x: -1.0, y: -1.0 },
RXingResultPoint { x: 1.0, y: -1.0 }, Point { x: 1.0, y: -1.0 },
RXingResultPoint { x: 1.0, y: 1.0 }, Point { x: 1.0, y: 1.0 },
RXingResultPoint { x: -1.0, y: 1.0 }, Point { x: -1.0, y: 1.0 },
]), ]),
size / 2, size / 2,
) )
@@ -94,19 +94,19 @@ pub fn CenteredSquare(size: i32) -> Quadrilateral {
#[allow(dead_code)] #[allow(dead_code)]
pub fn Line(y: i32, xStart: i32, xStop: i32) -> Quadrilateral { pub fn Line(y: i32, xStart: i32, xStop: i32) -> Quadrilateral {
Quadrilateral([ Quadrilateral([
RXingResultPoint { Point {
x: xStart as f32, x: xStart as f32,
y: y as f32, y: y as f32,
}, },
RXingResultPoint { Point {
x: xStop as f32, x: xStop as f32,
y: y as f32, y: y as f32,
}, },
RXingResultPoint { Point {
x: xStop as f32, x: xStop as f32,
y: y as f32, y: y as f32,
}, },
RXingResultPoint { Point {
x: xStart as f32, x: xStart as f32,
y: y as f32, y: y as f32,
}, },
@@ -162,8 +162,8 @@ pub fn Scale(q: &Quadrilateral, factor: i32) -> Quadrilateral {
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn Center(q: &Quadrilateral) -> RXingResultPoint { pub fn Center(q: &Quadrilateral) -> Point {
let reduced: RXingResultPoint = q.0.iter().sum(); let reduced: Point = q.0.iter().sum();
let size = q.0.len() as f32; let size = q.0.len() as f32;
reduced / size reduced / size
// return Reduce(q) / Size(q); // return Reduce(q) / Size(q);
@@ -186,14 +186,14 @@ pub fn RotatedCorners(q: &Quadrilateral, n: Option<i32>, mirror: Option<bool>) -
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn IsInside(p: RXingResultPoint, q: &Quadrilateral) -> bool { pub fn IsInside(p: Point, q: &Quadrilateral) -> bool {
// Test if p is on the same side (right or left) of all polygon segments // Test if p is on the same side (right or left) of all polygon segments
let mut pos = 0; let mut pos = 0;
let mut neg = 0; let mut neg = 0;
for i in 0..q.0.len() for i in 0..q.0.len()
// for (int i = 0; i < Size(q); ++i) // for (int i = 0; i < Size(q); ++i)
{ {
if RXingResultPoint::cross(p - q.0[i], q.0[(i + 1) % q.0.len()] - q.0[i]) < 0.0 { if Point::cross(p - q.0[i], q.0[(i + 1) % q.0.len()] - q.0[i]) < 0.0 {
neg += 1; neg += 1;
} else { } else {
pos += 1; pos += 1;

View File

@@ -1,9 +1,9 @@
use crate::common::Result; use crate::common::Result;
use crate::RXingResultPoint; use crate::Point;
pub trait RegressionLine { pub trait RegressionLine {
// points: Vec<RXingResultPoint>, // points: Vec<Point>,
// direction_inward: RXingResultPoint, // direction_inward: Point,
// } // }
// impl RegressionLine { // impl RegressionLine {
@@ -12,9 +12,9 @@ pub trait RegressionLine {
// PointF::value_t a = NAN, b = NAN, c = NAN; // PointF::value_t a = NAN, b = NAN, c = NAN;
// fn intersect<T: RegressionLine, T2: RegressionLine>(&self, l1: &T, l2: &T2) // fn intersect<T: RegressionLine, T2: RegressionLine>(&self, l1: &T, l2: &T2)
// -> RXingResultPoint; // -> Point;
// fn evaluate_begin_end(&self, begin: RXingResultPoint, end: RXingResultPoint) -> bool;// { // fn evaluate_begin_end(&self, begin: Point, end: Point) -> bool;// {
// { // {
// let mean = std::accumulate(begin, end, PointF()) / std::distance(begin, end); // let mean = std::accumulate(begin, end, PointF()) / std::distance(begin, end);
// PointF::value_t sumXX = 0, sumYY = 0, sumXY = 0; // PointF::value_t sumXX = 0, sumYY = 0, sumXY = 0;
@@ -41,10 +41,10 @@ pub trait RegressionLine {
// return dot(_directionInward, normal()) > 0.5f; // angle between original and new direction is at most 60 degree // return dot(_directionInward, normal()) > 0.5f; // angle between original and new direction is at most 60 degree
// } // }
fn evaluate(&mut self, points: &[RXingResultPoint]) -> 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: RXingResultPoint, b: RXingResultPoint) -> f32 { fn distance(&self, a: Point, b: Point) -> f32 {
crate::result_point_utils::distance(&a, &b) crate::result_point_utils::distance(&a, &b)
} }
@@ -60,13 +60,13 @@ pub trait RegressionLine {
// evaluate(b, e); // evaluate(b, e);
// } // }
fn points(&self) -> &[RXingResultPoint]; //const { return _points; } fn points(&self) -> &[Point]; //const { return _points; }
fn length(&self) -> u32; //const { return _points.size() >= 2 ? int(distance(_points.front(), _points.back())) : 0; } fn length(&self) -> u32; //const { return _points.size() >= 2 ? int(distance(_points.front(), _points.back())) : 0; }
fn isValid(&self) -> bool; //const { return !std::isnan(a); } fn isValid(&self) -> bool; //const { return !std::isnan(a); }
fn normal(&self) -> RXingResultPoint; //const { return isValid() ? PointF(a, b) : _directionInward; } fn normal(&self) -> Point; //const { return isValid() ? PointF(a, b) : _directionInward; }
fn signedDistance(&self, p: RXingResultPoint) -> f32; //const { return dot(normal(), p) - c; } fn signedDistance(&self, p: Point) -> f32; //const { return dot(normal(), p) - c; }
fn distance_single(&self, p: RXingResultPoint) -> f32; //const { return std::abs(signedDistance(PointF(p))); } fn distance_single(&self, p: Point) -> f32; //const { return std::abs(signedDistance(PointF(p))); }
fn project(&self, p: RXingResultPoint) -> RXingResultPoint { fn project(&self, p: Point) -> Point {
p - self.normal() * self.signedDistance(p) p - self.normal() * self.signedDistance(p)
} }
@@ -77,7 +77,7 @@ pub trait RegressionLine {
// a = b = c = NAN; // a = b = c = NAN;
// } // }
fn add(&mut self, p: RXingResultPoint) -> Result<()>; //{ fn add(&mut self, p: Point) -> Result<()>; //{
// assert(_directionInward != PointF()); // assert(_directionInward != PointF());
// _points.push_back(p); // _points.push_back(p);
// if (_points.size() == 1) // if (_points.size() == 1)
@@ -86,7 +86,7 @@ pub trait RegressionLine {
fn pop_back(&mut self); // { _points.pop_back(); } fn pop_back(&mut self); // { _points.pop_back(); }
fn setDirectionInward(&mut self, d: RXingResultPoint); //{ _directionInward = normalized(d); } fn setDirectionInward(&mut self, d: Point); //{ _directionInward = normalized(d); }
// fn evaluate(&self, double maxSignedDist = -1, bool updatePoints = false) -> bool // fn evaluate(&self, double maxSignedDist = -1, bool updatePoints = false) -> bool
fn evaluate_max_distance( fn evaluate_max_distance(

View File

@@ -1,5 +1,5 @@
use crate::common::Result; use crate::common::Result;
use crate::{Exceptions, RXingResultPoint}; use crate::{Exceptions, Point};
use super::{DMRegressionLine, Direction, RegressionLine}; use super::{DMRegressionLine, Direction, RegressionLine};
@@ -22,14 +22,14 @@ pub fn float_max<T: PartialOrd>(a: T, b: T) -> T {
} }
#[inline(always)] #[inline(always)]
pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result<RXingResultPoint> { pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result<Point> {
if !(l1.isValid() && l2.isValid()) { if !(l1.isValid() && l2.isValid()) {
return Err(Exceptions::IllegalStateException(None)); return Err(Exceptions::IllegalStateException(None));
} }
let d = l1.a * l2.b - l1.b * l2.a; let d = l1.a * l2.b - l1.b * l2.a;
let x = (l1.c * l2.b - l1.b * l2.c) / d; let x = (l1.c * l2.b - l1.b * l2.c) / d;
let y = (l1.a * l2.c - l1.c * l2.a) / d; let y = (l1.a * l2.c - l1.c * l2.a) / d;
Ok(RXingResultPoint { x, y }) Ok(Point { x, y })
} }
#[allow(dead_code)] #[allow(dead_code)]

View File

@@ -18,7 +18,7 @@
use std::collections::HashSet; use std::collections::HashSet;
use crate::{BarcodeFormat, RXingResultPointCallback}; use crate::{BarcodeFormat, PointCallback};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -89,8 +89,8 @@ pub enum DecodeHintType {
RETURN_CODABAR_START_END, RETURN_CODABAR_START_END,
/** /**
* The caller needs to be notified via callback when a possible {@link RXingResultPoint} * The caller needs to be notified via callback when a possible {@link Point}
* is found. Maps to a {@link RXingResultPointCallback}. * is found. Maps to a {@link PointCallback}.
*/ */
NEED_RESULT_POINT_CALLBACK, NEED_RESULT_POINT_CALLBACK,
@@ -198,11 +198,11 @@ pub enum DecodeHintValue {
ReturnCodabarStartEnd(bool), ReturnCodabarStartEnd(bool),
/** /**
* The caller needs to be notified via callback when a possible {@link RXingResultPoint} * The caller needs to be notified via callback when a possible {@link Point}
* is found. Maps to a {@link RXingResultPointCallback}. * is found. Maps to a {@link PointCallback}.
*/ */
#[cfg_attr(feature = "serde", serde(skip_serializing, skip_deserializing))] #[cfg_attr(feature = "serde", serde(skip_serializing, skip_deserializing))]
NeedResultPointCallback(RXingResultPointCallback), NeedResultPointCallback(PointCallback),
/** /**
* Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this. * Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.

View File

@@ -36,7 +36,7 @@ pub use encode_hints::*;
/// Callback which is invoked when a possible result point (significant /// Callback which is invoked when a possible result point (significant
/// point in the barcode image such as a corner) is found. /// point in the barcode image such as a corner) is found.
pub type RXingResultPointCallback = Rc<dyn Fn(&dyn ResultPoint)>; pub type PointCallback = Rc<dyn Fn(&dyn ResultPoint)>;
mod decode_hints; mod decode_hints;
pub use decode_hints::*; pub use decode_hints::*;

View File

@@ -6,7 +6,7 @@ use crate::{
detector::MathUtils, BitMatrix, DefaultGridSampler, DetectorRXingResult, GridSampler, detector::MathUtils, BitMatrix, DefaultGridSampler, DetectorRXingResult, GridSampler,
Result, Result,
}, },
Exceptions, RXingResultPoint, Exceptions, Point,
}; };
use super::MaxiCodeReader; use super::MaxiCodeReader;
@@ -16,7 +16,7 @@ const ROW_SCAN_SKIP: u32 = 2;
#[derive(Debug)] #[derive(Debug)]
pub struct MaxicodeDetectionResult { pub struct MaxicodeDetectionResult {
bits: BitMatrix, bits: BitMatrix,
points: Vec<RXingResultPoint>, points: Vec<Point>,
rotation: f32, rotation: f32,
} }
@@ -31,7 +31,7 @@ impl DetectorRXingResult for MaxicodeDetectionResult {
&self.bits &self.bits
} }
fn getPoints(&self) -> &[RXingResultPoint] { fn getPoints(&self) -> &[Point] {
&self.points &self.points
} }
} }
@@ -387,7 +387,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
points: symbol_box points: symbol_box
.0 .0
.iter() .iter()
.map(|p| RXingResultPoint { x: p.0, y: p.1 }) .map(|p| Point { x: p.0, y: p.1 })
.collect(), .collect(),
rotation: symbol_box.1, rotation: symbol_box.1,
}); });
@@ -717,10 +717,10 @@ fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4]
calculate_simple_boundary(circle, Some(image), None, false); calculate_simple_boundary(circle, Some(image), None, false);
let naive_box = [ let naive_box = [
RXingResultPoint::new(left_boundary as f32, bottom_boundary as f32), Point::new(left_boundary as f32, bottom_boundary as f32),
RXingResultPoint::new(left_boundary as f32, top_boundary as f32), Point::new(left_boundary as f32, top_boundary as f32),
RXingResultPoint::new(right_boundary as f32, bottom_boundary as f32), Point::new(right_boundary as f32, bottom_boundary as f32),
RXingResultPoint::new(right_boundary as f32, top_boundary as f32), Point::new(right_boundary as f32, top_boundary as f32),
]; ];
#[allow(unused_mut)] #[allow(unused_mut)]
@@ -807,9 +807,9 @@ const BOTTOM_RIGHT_ORIENTATION_POS: ((u32, u32), (u32, u32), (u32, u32)) =
fn attempt_rotation_box( fn attempt_rotation_box(
image: &BitMatrix, image: &BitMatrix,
circle: &mut Circle, circle: &mut Circle,
naive_box: &[RXingResultPoint; 4], naive_box: &[Point; 4],
center_scale: f64, center_scale: f64,
) -> Option<([RXingResultPoint; 4], f32)> { ) -> Option<([Point; 4], f32)> {
// update our circle with a more accurate center point // update our circle with a more accurate center point
circle.calculate_high_accuracy_center(); circle.calculate_high_accuracy_center();
@@ -955,10 +955,10 @@ fn attempt_rotation_box(
Some(( Some((
[ [
RXingResultPoint::new(new_1.0, new_1.1), Point::new(new_1.0, new_1.1),
RXingResultPoint::new(new_2.0, new_2.1), Point::new(new_2.0, new_2.1),
RXingResultPoint::new(new_3.0, new_3.1), Point::new(new_3.0, new_3.1),
RXingResultPoint::new(new_4.0, new_4.1), Point::new(new_4.0, new_4.1),
], ],
final_rotation, final_rotation,
)) ))

View File

@@ -17,7 +17,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::common::Result; use crate::common::Result;
use crate::{Exceptions, RXingResult, RXingResultPoint, Reader, ResultPoint}; use crate::{Exceptions, RXingResult, Point, Reader, ResultPoint};
/** /**
* 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,
@@ -61,7 +61,7 @@ impl<T: Reader> Reader for ByQuadrantReader<T> {
// This is a match because only NotFoundExceptions should be ignored // This is a match because only NotFoundExceptions should be ignored
match result { match result {
Ok(res) => { Ok(res) => {
let points = Self::makeAbsolute(res.getRXingResultPoints(), halfWidth as f32, 0.0); let points = Self::makeAbsolute(res.getPoints(), halfWidth as f32, 0.0);
return Ok(RXingResult::new_from_existing_result(res, points)); return Ok(RXingResult::new_from_existing_result(res, points));
} }
Err(Exceptions::NotFoundException(_)) => {} Err(Exceptions::NotFoundException(_)) => {}
@@ -74,7 +74,7 @@ impl<T: Reader> Reader for ByQuadrantReader<T> {
// This is a match because only NotFoundExceptions should be ignored // This is a match because only NotFoundExceptions should be ignored
match result { match result {
Ok(res) => { Ok(res) => {
let points = Self::makeAbsolute(res.getRXingResultPoints(), 0.0, halfHeight as f32); let points = Self::makeAbsolute(res.getPoints(), 0.0, halfHeight as f32);
return Ok(RXingResult::new_from_existing_result(res, points)); return Ok(RXingResult::new_from_existing_result(res, points));
} }
Err(Exceptions::NotFoundException(_)) => {} Err(Exceptions::NotFoundException(_)) => {}
@@ -89,7 +89,7 @@ impl<T: Reader> Reader for ByQuadrantReader<T> {
match result { match result {
Ok(res) => { Ok(res) => {
let points = Self::makeAbsolute( let points = Self::makeAbsolute(
res.getRXingResultPoints(), res.getPoints(),
halfWidth as f32, halfWidth as f32,
halfHeight as f32, halfHeight as f32,
); );
@@ -105,7 +105,7 @@ impl<T: Reader> Reader for ByQuadrantReader<T> {
let result = self.0.decode_with_hints(&mut center, hints)?; let result = self.0.decode_with_hints(&mut center, hints)?;
let points = Self::makeAbsolute( let points = Self::makeAbsolute(
result.getRXingResultPoints(), result.getPoints(),
quarterWidth as f32, quarterWidth as f32,
quarterHeight as f32, quarterHeight as f32,
); );
@@ -123,15 +123,15 @@ impl<T: Reader> ByQuadrantReader<T> {
} }
fn makeAbsolute( fn makeAbsolute(
points: &[RXingResultPoint], points: &[Point],
leftOffset: f32, leftOffset: f32,
topOffset: f32, topOffset: f32,
) -> Vec<RXingResultPoint> { ) -> Vec<Point> {
// let mut result = Vec::new(); // let mut result = Vec::new();
// if !points.is_empty() { // if !points.is_empty() {
// // for relative in points { // // for relative in points {
// // result.push(RXingResultPoint::new( // // result.push(Point::new(
// // relative.getX() + leftOffset, // // relative.getX() + leftOffset,
// // relative.getY() + topOffset, // // relative.getY() + topOffset,
// // )); // // ));
@@ -141,7 +141,7 @@ impl<T: Reader> ByQuadrantReader<T> {
points points
.iter() .iter()
.map(|relative| { .map(|relative| {
RXingResultPoint::new(relative.getX() + leftOffset, relative.getY() + topOffset) Point::new(relative.getX() + leftOffset, relative.getY() + topOffset)
}) })
.collect() .collect()
} }

View File

@@ -18,7 +18,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::Result, BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResult, common::Result, BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResult,
RXingResultPoint, Reader, ResultPoint, Point, Reader, ResultPoint,
}; };
use super::MultipleBarcodeReader; use super::MultipleBarcodeReader;
@@ -26,7 +26,7 @@ use super::MultipleBarcodeReader;
/** /**
* <p>Attempts to locate multiple barcodes in an image by repeatedly decoding portion of the image. * <p>Attempts to locate multiple barcodes in an image by repeatedly decoding portion of the image.
* After one barcode is found, the areas left, above, right and below the barcode's * After one barcode is found, the areas left, above, right and below the barcode's
* {@link RXingResultPoint}s are scanned, recursively.</p> * {@link Point}s are scanned, recursively.</p>
* *
* <p>A caller may want to also employ {@link ByQuadrantReader} when attempting to find multiple * <p>A caller may want to also employ {@link ByQuadrantReader} when attempting to find multiple
* 2D barcodes, like QR Codes, in an image, where the presence of multiple barcodes might prevent * 2D barcodes, like QR Codes, in an image, where the presence of multiple barcodes might prevent
@@ -95,10 +95,10 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
} }
} }
let resultPoints = result.getRXingResultPoints().clone(); let resultPoints = result.getPoints().clone();
if !alreadyFound { if !alreadyFound {
results.push(Self::translateRXingResultPoints(result, xOffset, yOffset)); results.push(Self::translatePoints(result, xOffset, yOffset));
} }
if resultPoints.is_empty() { if resultPoints.is_empty() {
@@ -177,25 +177,25 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
} }
} }
fn translateRXingResultPoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult { fn translatePoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult {
let oldRXingResultPoints = result.getRXingResultPoints(); let oldPoints = result.getPoints();
if oldRXingResultPoints.is_empty() { if oldPoints.is_empty() {
return result; return result;
} }
let newRXingResultPoints: Vec<RXingResultPoint> = oldRXingResultPoints let newPoints: Vec<Point> = oldPoints
.iter() .iter()
.map(|oldPoint| { .map(|oldPoint| {
RXingResultPoint::new( Point::new(
oldPoint.getX() + xOffset as f32, oldPoint.getX() + xOffset as f32,
oldPoint.getY() + yOffset as f32, oldPoint.getY() + yOffset as f32,
) )
}) })
.collect(); .collect();
// let mut newRXingResultPoints = Vec::with_capacity(oldRXingResultPoints.len()); // let mut newPoints = Vec::with_capacity(oldPoints.len());
// for oldPoint in oldRXingResultPoints { // for oldPoint in oldPoints {
// newRXingResultPoints.push(RXingResultPoint::new( // newPoints.push(Point::new(
// oldPoint.getX() + xOffset as f32, // oldPoint.getX() + xOffset as f32,
// oldPoint.getY() + yOffset as f32, // oldPoint.getY() + yOffset as f32,
// )); // ));
@@ -204,7 +204,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
result.getText(), result.getText(),
result.getRawBytes().clone(), result.getRawBytes().clone(),
result.getNumBits(), result.getNumBits(),
newRXingResultPoints, newPoints,
*result.getBarcodeFormat(), *result.getBarcodeFormat(),
result.getTimestamp(), result.getTimestamp(),
); );

View File

@@ -20,7 +20,7 @@ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
qrcode::detector::{FinderPattern, FinderPatternFinder, FinderPatternInfo}, qrcode::detector::{FinderPattern, FinderPatternFinder, FinderPatternInfo},
result_point_utils, DecodeHintType, DecodingHintDictionary, Exceptions, result_point_utils, DecodeHintType, DecodingHintDictionary, Exceptions,
RXingResultPointCallback, PointCallback,
}; };
// max. legal count of modules per QR code edge (177) // max. legal count of modules per QR code edge (177)
@@ -68,7 +68,7 @@ impl<'a> MultiFinderPatternFinder<'_> {
pub fn new( pub fn new(
image: &'a BitMatrix, image: &'a BitMatrix,
resultPointCallback: Option<RXingResultPointCallback>, resultPointCallback: Option<PointCallback>,
) -> MultiFinderPatternFinder<'a> { ) -> MultiFinderPatternFinder<'a> {
MultiFinderPatternFinder(FinderPatternFinder::with_callback( MultiFinderPatternFinder(FinderPatternFinder::with_callback(
image, image,

View File

@@ -171,8 +171,8 @@ impl OneDReader for CodaBarReader {
&self.decodeRowRXingResult, &self.decodeRowRXingResult,
Vec::new(), Vec::new(),
vec![ vec![
RXingResultPoint::new(left, rowNumber as f32), Point::new(left, rowNumber as f32),
RXingResultPoint::new(right, rowNumber as f32), Point::new(right, rowNumber as f32),
], ],
BarcodeFormat::CODABAR, BarcodeFormat::CODABAR,
); );

View File

@@ -342,8 +342,8 @@ impl OneDReader for Code128Reader {
&result, &result,
rawBytes, rawBytes,
vec![ vec![
RXingResultPoint::new(left, rowNumber as f32), Point::new(left, rowNumber as f32),
RXingResultPoint::new(right, rowNumber as f32), Point::new(right, rowNumber as f32),
], ],
BarcodeFormat::CODE_128, BarcodeFormat::CODE_128,
); );

View File

@@ -134,8 +134,8 @@ impl OneDReader for Code39Reader {
&resultString, &resultString,
Vec::new(), Vec::new(),
vec![ vec![
RXingResultPoint::new(left, rowNumber as f32), Point::new(left, rowNumber as f32),
RXingResultPoint::new(right, rowNumber as f32), Point::new(right, rowNumber as f32),
], ],
BarcodeFormat::CODE_39, BarcodeFormat::CODE_39,
); );

View File

@@ -117,8 +117,8 @@ impl OneDReader for Code93Reader {
&resultString, &resultString,
Vec::new(), Vec::new(),
vec![ vec![
RXingResultPoint::new(left, rowNumber as f32), Point::new(left, rowNumber as f32),
RXingResultPoint::new(right, rowNumber as f32), Point::new(right, rowNumber as f32),
], ],
BarcodeFormat::CODE_93, BarcodeFormat::CODE_93,
); );

View File

@@ -150,8 +150,8 @@ impl OneDReader for ITFReader {
&resultString, &resultString,
Vec::new(), // no natural byte representation for these barcodes Vec::new(), // no natural byte representation for these barcodes
vec![ vec![
RXingResultPoint::new(startRange[1] as f32, rowNumber as f32), Point::new(startRange[1] as f32, rowNumber as f32),
RXingResultPoint::new(endRange[0] as f32, rowNumber as f32), Point::new(endRange[0] as f32, rowNumber as f32),
], ],
BarcodeFormat::ITF, BarcodeFormat::ITF,
); );

View File

@@ -157,8 +157,8 @@ impl Reader for MultiFormatOneDReader {
); );
// Update result points // Update result points
let height = rotatedImage.getHeight(); let height = rotatedImage.getHeight();
let total_points = result.getRXingResultPoints().len(); let total_points = result.getPoints().len();
let points = result.getRXingResultPointsMut(); let points = result.getPointsMut();
for point in points.iter_mut().take(total_points) { for point in points.iter_mut().take(total_points) {
std::mem::swap(&mut point.x, &mut point.y); std::mem::swap(&mut point.x, &mut point.y);
point.x = height as f32 - point.x - 1.0; point.x = height as f32 - point.x - 1.0;

View File

@@ -105,7 +105,7 @@ impl MultiFormatUPCEANReader {
let mut resultUPCA = RXingResult::new( let mut resultUPCA = RXingResult::new(
&result.getText()[1..], &result.getText()[1..],
result.getRawBytes().clone(), result.getRawBytes().clone(),
result.getRXingResultPoints().clone(), result.getPoints().clone(),
BarcodeFormat::UPC_A, BarcodeFormat::UPC_A,
); );
resultUPCA.putAllMetadata(result.getRXingResultMetadata().clone()); resultUPCA.putAllMetadata(result.getRXingResultMetadata().clone());
@@ -189,8 +189,8 @@ impl Reader for MultiFormatUPCEANReader {
); );
// Update result points // Update result points
let height = rotatedImage.getHeight(); let height = rotatedImage.getHeight();
let total_points = result.getRXingResultPoints().len(); let total_points = result.getPoints().len();
let points = result.getRXingResultPointsMut(); let points = result.getPointsMut();
for point in points.iter_mut().take(total_points) { for point in points.iter_mut().take(total_points) {
std::mem::swap(&mut point.x, &mut point.y); std::mem::swap(&mut point.x, &mut point.y);
point.x = height as f32 - point.x - 1.0; point.x = height as f32 - point.x - 1.0;

View File

@@ -17,7 +17,7 @@
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult,
RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, ResultPoint, RXingResultMetadataType, RXingResultMetadataValue, Point, Reader, ResultPoint,
}; };
/** /**
@@ -115,13 +115,13 @@ pub trait OneDReader: Reader {
RXingResultMetadataValue::Orientation(180), RXingResultMetadataValue::Orientation(180),
); );
// And remember to flip the result points horizontally. // And remember to flip the result points horizontally.
let points = result.getRXingResultPointsMut(); let points = result.getPointsMut();
if !points.is_empty() && points.len() >= 2 { if !points.is_empty() && points.len() >= 2 {
points[0] = RXingResultPoint::new( points[0] = Point::new(
width as f32 - points[0].getX() - 1.0, width as f32 - points[0].getX() - 1.0,
points[0].getY(), points[0].getY(),
); );
points[1] = RXingResultPoint::new( points[1] = Point::new(
width as f32 - points[1].getX() - 1.0, width as f32 - points[1].getX() - 1.0,
points[1].getY(), points[1].getY(),
); );

View File

@@ -215,8 +215,8 @@ impl Reader for RSSExpandedReader {
// Update result points // Update result points
let height = rotatedImage.getHeight(); let height = rotatedImage.getHeight();
let total_points = result.getRXingResultPoints().len(); let total_points = result.getPoints().len();
let points = result.getRXingResultPointsMut(); let points = result.getPointsMut();
for point in points.iter_mut().take(total_points) { for point in points.iter_mut().take(total_points) {
std::mem::swap(&mut point.x, &mut point.y); std::mem::swap(&mut point.x, &mut point.y);
point.x = height as f32 - point.x - 1.0; point.x = height as f32 - point.x - 1.0;
@@ -545,14 +545,14 @@ impl RSSExpandedReader {
.getFinderPattern() .getFinderPattern()
.as_ref() .as_ref()
.ok_or(Exceptions::IllegalStateException(None))? .ok_or(Exceptions::IllegalStateException(None))?
.getRXingResultPoints(); .getPoints();
let lastPoints = pairs let lastPoints = pairs
.last() .last()
.ok_or(Exceptions::IndexOutOfBoundsException(None))? .ok_or(Exceptions::IndexOutOfBoundsException(None))?
.getFinderPattern() .getFinderPattern()
.as_ref() .as_ref()
.ok_or(Exceptions::IllegalStateException(None))? .ok_or(Exceptions::IllegalStateException(None))?
.getRXingResultPoints(); .getPoints();
let mut result = RXingResult::new( let mut result = RXingResult::new(
&resultingString, &resultingString,

View File

@@ -16,7 +16,7 @@
use std::hash::Hash; use std::hash::Hash;
use crate::RXingResultPoint; use crate::Point;
/** /**
* Encapsulates an RSS barcode finder pattern, including its start/end position and row. * Encapsulates an RSS barcode finder pattern, including its start/end position and row.
@@ -25,7 +25,7 @@ use crate::RXingResultPoint;
pub struct FinderPattern { pub struct FinderPattern {
value: u32, value: u32,
startEnd: [usize; 2], startEnd: [usize; 2],
resultPoints: Vec<RXingResultPoint>, resultPoints: Vec<Point>,
} }
impl FinderPattern { impl FinderPattern {
@@ -34,8 +34,8 @@ impl FinderPattern {
value, value,
startEnd, startEnd,
resultPoints: vec![ resultPoints: vec![
RXingResultPoint::new(start as f32, rowNumber as f32), Point::new(start as f32, rowNumber as f32),
RXingResultPoint::new(end as f32, rowNumber as f32), Point::new(end as f32, rowNumber as f32),
], ],
} }
} }
@@ -53,7 +53,7 @@ impl FinderPattern {
&mut self.startEnd &mut self.startEnd
} }
pub fn getRXingResultPoints(&self) -> &[RXingResultPoint] { pub fn getPoints(&self) -> &[Point] {
&self.resultPoints &self.resultPoints
} }
} }

View File

@@ -20,7 +20,7 @@ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
oned::{one_d_reader, OneDReader}, oned::{one_d_reader, OneDReader},
BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions,
RXingResult, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Point, Reader,
}; };
use super::{ use super::{
@@ -114,8 +114,8 @@ impl Reader for RSS14Reader {
); );
// Update result points // Update result points
let height = rotatedImage.getHeight(); let height = rotatedImage.getHeight();
let total_points = result.getRXingResultPoints().len(); let total_points = result.getPoints().len();
let points = result.getRXingResultPointsMut(); let points = result.getPointsMut();
for point in points.iter_mut().take(total_points) { for point in points.iter_mut().take(total_points) {
std::mem::swap(&mut point.x, &mut point.y); std::mem::swap(&mut point.x, &mut point.y);
point.x = height as f32 - point.x - 1.0 point.x = height as f32 - point.x - 1.0
@@ -209,8 +209,8 @@ impl RSS14Reader {
} }
buffer.push_str(&checkDigit.to_string()); buffer.push_str(&checkDigit.to_string());
let leftPoints = leftPair.getFinderPattern().getRXingResultPoints(); let leftPoints = leftPair.getFinderPattern().getPoints();
let rightPoints = rightPair.getFinderPattern().getRXingResultPoints(); let rightPoints = rightPair.getFinderPattern().getPoints();
let mut result = RXingResult::new( let mut result = RXingResult::new(
&buffer, &buffer,
Vec::new(), Vec::new(),
@@ -259,7 +259,7 @@ impl RSS14Reader {
// row is actually reversed // row is actually reversed
center = row.getSize() as f32 - 1.0 - center; center = row.getSize() as f32 - 1.0 - center;
} }
cb(&RXingResultPoint::new(center, rowNumber as f32)); cb(&Point::new(center, rowNumber as f32));
} }
let outside = self.decodeDataCharacter(row, &pattern, true)?; let outside = self.decodeDataCharacter(row, &pattern, true)?;

View File

@@ -94,7 +94,7 @@ impl UPCAReader {
let mut upcaRXingResult = RXingResult::new( let mut upcaRXingResult = RXingResult::new(
stripped_text, stripped_text,
Vec::new(), Vec::new(),
result.getRXingResultPoints().to_vec(), result.getPoints().to_vec(),
BarcodeFormat::UPC_A, BarcodeFormat::UPC_A,
); );
upcaRXingResult.putAllMetadata(result.getRXingResultMetadata().clone()); upcaRXingResult.putAllMetadata(result.getRXingResultMetadata().clone());

View File

@@ -19,7 +19,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue,
RXingResultPoint, Point,
}; };
use super::{upc_ean_reader, UPCEANReader, STAND_IN}; use super::{upc_ean_reader, UPCEANReader, STAND_IN};
@@ -49,11 +49,11 @@ impl UPCEANExtension2Support {
&resultString, &resultString,
Vec::new(), Vec::new(),
vec![ vec![
RXingResultPoint::new( Point::new(
(extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0, (extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0,
rowNumber as f32, rowNumber as f32,
), ),
RXingResultPoint::new(end as f32, rowNumber as f32), Point::new(end as f32, rowNumber as f32),
], ],
BarcodeFormat::UPC_EAN_EXTENSION, BarcodeFormat::UPC_EAN_EXTENSION,
); );

View File

@@ -19,7 +19,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue,
RXingResultPoint, Point,
}; };
use super::{upc_ean_reader, UPCEANReader, STAND_IN}; use super::{upc_ean_reader, UPCEANReader, STAND_IN};
@@ -51,11 +51,11 @@ impl UPCEANExtension5Support {
&resultString, &resultString,
Vec::new(), Vec::new(),
vec![ vec![
RXingResultPoint::new( Point::new(
(extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0, (extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0,
rowNumber as f32, rowNumber as f32,
), ),
RXingResultPoint::new(end as f32, rowNumber as f32), Point::new(end as f32, rowNumber as f32),
], ],
BarcodeFormat::UPC_EAN_EXTENSION, BarcodeFormat::UPC_EAN_EXTENSION,
); );

View File

@@ -17,7 +17,7 @@
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult, BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult,
RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, RXingResultMetadataType, RXingResultMetadataValue, Point, Reader,
}; };
use super::{one_d_reader, EANManufacturerOrgSupport, OneDReader, UPCEANExtensionSupport}; use super::{one_d_reader, EANManufacturerOrgSupport, OneDReader, UPCEANExtensionSupport};
@@ -156,7 +156,7 @@ pub trait UPCEANReader: OneDReader {
let mut symbologyIdentifier = 0; let mut symbologyIdentifier = 0;
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback {
cb(&RXingResultPoint::new( cb(&Point::new(
(startGuardRange[0] + startGuardRange[1]) as f32 / 2.0, (startGuardRange[0] + startGuardRange[1]) as f32 / 2.0,
rowNumber as f32, rowNumber as f32,
)); ));
@@ -166,13 +166,13 @@ pub trait UPCEANReader: OneDReader {
let endStart = self.decodeMiddle(row, startGuardRange, &mut result)?; let endStart = self.decodeMiddle(row, startGuardRange, &mut result)?;
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback {
cb(&RXingResultPoint::new(endStart as f32, rowNumber as f32)); cb(&Point::new(endStart as f32, rowNumber as f32));
} }
let endRange = self.decodeEnd(row, endStart)?; let endRange = self.decodeEnd(row, endStart)?;
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback {
cb(&RXingResultPoint::new( cb(&Point::new(
(endRange[0] + endRange[1]) as f32 / 2.0, (endRange[0] + endRange[1]) as f32 / 2.0,
rowNumber as f32, rowNumber as f32,
)); ));
@@ -204,8 +204,8 @@ pub trait UPCEANReader: OneDReader {
&resultString, &resultString,
Vec::new(), // no natural byte representation for these barcodes Vec::new(), // no natural byte representation for these barcodes
vec![ vec![
RXingResultPoint::new(left, rowNumber as f32), Point::new(left, rowNumber as f32),
RXingResultPoint::new(right, rowNumber as f32), Point::new(right, rowNumber as f32),
], ],
format, format,
); );
@@ -224,7 +224,7 @@ pub trait UPCEANReader: OneDReader {
); );
decodeRXingResult.putAllMetadata(extensionRXingResult.getRXingResultMetadata().clone()); decodeRXingResult.putAllMetadata(extensionRXingResult.getRXingResultMetadata().clone());
decodeRXingResult decodeRXingResult
.addRXingResultPoints(&mut extensionRXingResult.getRXingResultPoints().clone()); .addPoints(&mut extensionRXingResult.getPoints().clone());
extensionLength = extensionRXingResult.getText().chars().count(); extensionLength = extensionRXingResult.getText().chars().count();
Ok(()) Ok(())
}; };

View File

@@ -18,7 +18,7 @@ use std::rc::Rc;
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
Exceptions, RXingResultPoint, ResultPoint, Exceptions, Point, ResultPoint,
}; };
/** /**
@@ -27,10 +27,10 @@ use crate::{
#[derive(Clone)] #[derive(Clone)]
pub struct BoundingBox { pub struct BoundingBox {
image: Rc<BitMatrix>, image: Rc<BitMatrix>,
topLeft: RXingResultPoint, topLeft: Point,
bottomLeft: RXingResultPoint, bottomLeft: Point,
topRight: RXingResultPoint, topRight: Point,
bottomRight: RXingResultPoint, bottomRight: Point,
minX: u32, minX: u32,
maxX: u32, maxX: u32,
minY: u32, minY: u32,
@@ -39,10 +39,10 @@ pub struct BoundingBox {
impl BoundingBox { impl BoundingBox {
pub fn new( pub fn new(
image: Rc<BitMatrix>, image: Rc<BitMatrix>,
topLeft: Option<RXingResultPoint>, topLeft: Option<Point>,
bottomLeft: Option<RXingResultPoint>, bottomLeft: Option<Point>,
topRight: Option<RXingResultPoint>, topRight: Option<Point>,
bottomRight: Option<RXingResultPoint>, bottomRight: Option<Point>,
) -> Result<BoundingBox> { ) -> Result<BoundingBox> {
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none(); let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
let rightUnspecified = topRight.is_none() || bottomRight.is_none(); let rightUnspecified = topRight.is_none() || bottomRight.is_none();
@@ -58,14 +58,14 @@ 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 = RXingResultPoint::new(0.0, newTopRight.getY()); newTopLeft = Point::new(0.0, newTopRight.getY());
newBottomLeft = RXingResultPoint::new(0.0, newBottomRight.getY()); newBottomLeft = Point::new(0.0, newBottomRight.getY());
} 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 = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newTopLeft.getY()); newTopRight = Point::new(image.getWidth() as f32 - 1.0, newTopLeft.getY());
newBottomRight = newBottomRight =
RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY()); Point::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
} 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))?;
@@ -145,7 +145,7 @@ impl BoundingBox {
if newMinY < 0.0 { if newMinY < 0.0 {
newMinY = 0.0; newMinY = 0.0;
} }
let newTop = RXingResultPoint::new(top.getX(), newMinY); let newTop = Point::new(top.getX(), newMinY);
if isLeft { if isLeft {
newTopLeft = newTop; newTopLeft = newTop;
} else { } else {
@@ -163,7 +163,7 @@ impl BoundingBox {
if newMaxY >= self.image.getHeight() { if newMaxY >= self.image.getHeight() {
newMaxY = self.image.getHeight() - 1; newMaxY = self.image.getHeight() - 1;
} }
let newBottom = RXingResultPoint::new(bottom.getX(), newMaxY as f32); let newBottom = Point::new(bottom.getX(), newMaxY as f32);
if isLeft { if isLeft {
newBottomLeft = newBottom; newBottomLeft = newBottom;
} else { } else {
@@ -196,19 +196,19 @@ impl BoundingBox {
self.maxY self.maxY
} }
pub fn getTopLeft(&self) -> &RXingResultPoint { pub fn getTopLeft(&self) -> &Point {
&self.topLeft &self.topLeft
} }
pub fn getTopRight(&self) -> &RXingResultPoint { pub fn getTopRight(&self) -> &Point {
&self.topRight &self.topRight
} }
pub fn getBottomLeft(&self) -> &RXingResultPoint { pub fn getBottomLeft(&self) -> &Point {
&self.bottomLeft &self.bottomLeft
} }
pub fn getBottomRight(&self) -> &RXingResultPoint { pub fn getBottomRight(&self) -> &Point {
&self.bottomRight &self.bottomRight
} }
} }

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, RXingResultPoint, ResultPoint, Exceptions, Point, ResultPoint,
}; };
use super::{ use super::{
@@ -44,10 +44,10 @@ const MAX_EC_CODEWORDS: u32 = 512;
// than it should be. This can happen if the scanner used a bad blackpoint. // than it should be. This can happen if the scanner used a bad blackpoint.
pub fn decode( pub fn decode(
image: &BitMatrix, image: &BitMatrix,
imageTopLeft: Option<RXingResultPoint>, imageTopLeft: Option<Point>,
imageBottomLeft: Option<RXingResultPoint>, imageBottomLeft: Option<Point>,
imageTopRight: Option<RXingResultPoint>, imageTopRight: Option<Point>,
imageBottomRight: Option<RXingResultPoint>, imageBottomRight: Option<Point>,
minCodewordWidth: u32, minCodewordWidth: u32,
maxCodewordWidth: u32, maxCodewordWidth: u32,
) -> Result<DecoderRXingResult> { ) -> Result<DecoderRXingResult> {
@@ -358,7 +358,7 @@ fn getBarcodeMetadata<T: DetectionRXingResultRowIndicatorColumn>(
fn getRowIndicatorColumn<'a>( fn getRowIndicatorColumn<'a>(
image: &BitMatrix, image: &BitMatrix,
boundingBox: Rc<BoundingBox>, boundingBox: Rc<BoundingBox>,
startPoint: RXingResultPoint, startPoint: Point,
leftToRight: bool, leftToRight: bool,
minCodewordWidth: u32, minCodewordWidth: u32,
maxCodewordWidth: u32, maxCodewordWidth: u32,

View File

@@ -16,7 +16,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResultPoint, ResultPoint, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, ResultPoint,
}; };
use std::borrow::Cow; use std::borrow::Cow;
@@ -116,10 +116,10 @@ fn applyRotation(matrix: &BitMatrix, rotation: u32) -> Result<Cow<BitMatrix>> {
* @param multiple if true, then the image is searched for multiple codes. If false, then at most one code will * @param multiple if true, then the image is searched for multiple codes. If false, then at most one code will
* be found and returned * be found and returned
* @param bitMatrix bit matrix to detect barcodes in * @param bitMatrix bit matrix to detect barcodes in
* @return List of RXingResultPoint arrays containing the coordinates of found barcodes * @return List of Point arrays containing the coordinates of found barcodes
*/ */
pub fn detect(multiple: bool, bitMatrix: &BitMatrix) -> Option<Vec<[Option<RXingResultPoint>; 8]>> { pub fn detect(multiple: bool, bitMatrix: &BitMatrix) -> Option<Vec<[Option<Point>; 8]>> {
let mut barcodeCoordinates: Vec<[Option<RXingResultPoint>; 8]> = Vec::new(); let mut barcodeCoordinates: Vec<[Option<Point>; 8]> = Vec::new();
let mut row = 0; let mut row = 0;
let mut column = 0; let mut column = 0;
let mut foundBarcodeInRow = false; let mut foundBarcodeInRow = false;
@@ -183,13 +183,13 @@ fn findVertices(
matrix: &BitMatrix, matrix: &BitMatrix,
startRow: u32, startRow: u32,
startColumn: u32, startColumn: u32,
) -> Option<[Option<RXingResultPoint>; 8]> { ) -> Option<[Option<Point>; 8]> {
let height = matrix.getHeight(); let height = matrix.getHeight();
let width = matrix.getWidth(); let width = matrix.getWidth();
let mut startRow = startRow; let mut startRow = startRow;
let mut startColumn = startColumn; let mut startColumn = startColumn;
let mut result = [None::<RXingResultPoint>; 8]; //RXingResultPoint[8]; let mut result = [None::<Point>; 8]; //Point[8];
copyToRXingResult( copyToRXingResult(
&mut result, &mut result,
&findRowsWithPattern(matrix, height, width, startRow, startColumn, &START_PATTERN)?, &findRowsWithPattern(matrix, height, width, startRow, startColumn, &START_PATTERN)?,
@@ -210,8 +210,8 @@ fn findVertices(
} }
fn copyToRXingResult( fn copyToRXingResult(
result: &mut [Option<RXingResultPoint>], result: &mut [Option<Point>],
tmpRXingResult: &[Option<RXingResultPoint>], tmpRXingResult: &[Option<Point>],
destinationIndexes: &[u32], destinationIndexes: &[u32],
) { ) {
for i in 0..destinationIndexes.len() { for i in 0..destinationIndexes.len() {
@@ -226,7 +226,7 @@ fn findRowsWithPattern(
startRow: u32, startRow: u32,
startColumn: u32, startColumn: u32,
pattern: &[u32], pattern: &[u32],
) -> Option<[Option<RXingResultPoint>; 4]> { ) -> Option<[Option<Point>; 4]> {
let mut startRow = startRow; let mut startRow = startRow;
let mut result = [None; 4]; let mut result = [None; 4];
let mut found = false; let mut found = false;
@@ -249,11 +249,11 @@ fn findRowsWithPattern(
break; break;
} }
} }
result[0] = Some(RXingResultPoint::new( result[0] = Some(Point::new(
loc_store.as_ref()?[0] as f32, loc_store.as_ref()?[0] as f32,
startRow as f32, startRow as f32,
)); ));
result[1] = Some(RXingResultPoint::new( result[1] = Some(Point::new(
loc_store.as_ref()?[1] as f32, loc_store.as_ref()?[1] as f32,
startRow as f32, startRow as f32,
)); ));
@@ -304,11 +304,11 @@ fn findRowsWithPattern(
stopRow += 1; stopRow += 1;
} }
stopRow -= skippedRowCount + 1; stopRow -= skippedRowCount + 1;
result[2] = Some(RXingResultPoint::new( result[2] = Some(Point::new(
previousRowLoc[0] as f32, previousRowLoc[0] as f32,
stopRow as f32, stopRow as f32,
)); ));
result[3] = Some(RXingResultPoint::new( result[3] = Some(Point::new(
previousRowLoc[1] as f32, previousRowLoc[1] as f32,
stopRow as f32, stopRow as f32,
)); ));

View File

@@ -14,21 +14,21 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::{common::BitMatrix, RXingResultPoint}; use crate::{common::BitMatrix, Point};
/** /**
* @author Guenther Grau * @author Guenther Grau
*/ */
pub struct PDF417DetectorRXingResult { pub struct PDF417DetectorRXingResult {
bits: BitMatrix, bits: BitMatrix,
points: Vec<[Option<RXingResultPoint>; 8]>, points: Vec<[Option<Point>; 8]>,
rotation: u32, rotation: u32,
} }
impl PDF417DetectorRXingResult { impl PDF417DetectorRXingResult {
pub fn with_rotation( pub fn with_rotation(
bits: BitMatrix, bits: BitMatrix,
points: Vec<[Option<RXingResultPoint>; 8]>, points: Vec<[Option<Point>; 8]>,
rotation: u32, rotation: u32,
) -> Self { ) -> Self {
Self { Self {
@@ -38,7 +38,7 @@ impl PDF417DetectorRXingResult {
} }
} }
pub fn new(bits: BitMatrix, points: Vec<[Option<RXingResultPoint>; 8]>) -> Self { pub fn new(bits: BitMatrix, points: Vec<[Option<Point>; 8]>) -> Self {
Self::with_rotation(bits, points, 0) Self::with_rotation(bits, points, 0)
} }
@@ -46,7 +46,7 @@ impl PDF417DetectorRXingResult {
&self.bits &self.bits
} }
pub fn getPoints(&self) -> &Vec<[Option<RXingResultPoint>; 8]> { pub fn getPoints(&self) -> &Vec<[Option<Point>; 8]> {
&self.points &self.points
} }

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, RXingResult, RXingResultMetadataType, DecodingHintDictionary, Exceptions, RXingResult, RXingResultMetadataType,
RXingResultMetadataValue, RXingResultPoint, Reader, ResultPoint, RXingResultMetadataValue, Point, Reader, ResultPoint,
}; };
use super::{ use super::{
@@ -151,7 +151,7 @@ impl PDF417Reader {
Ok(results) Ok(results)
} }
fn getMaxWidth(p1: &Option<RXingResultPoint>, p2: &Option<RXingResultPoint>) -> 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.getX() - p2.getX()).abs() as u64
} else { } else {
@@ -159,7 +159,7 @@ impl PDF417Reader {
} }
} }
fn getMinWidth(p1: &Option<RXingResultPoint>, p2: &Option<RXingResultPoint>) -> 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.getX() - p2.getX()).abs() as u64
} else { } else {
@@ -167,7 +167,7 @@ impl PDF417Reader {
} }
} }
fn getMaxCodewordWidth(p: &[Option<RXingResultPoint>]) -> u32 { fn getMaxCodewordWidth(p: &[Option<Point>]) -> u32 {
Self::getMaxWidth(&p[0], &p[4]) Self::getMaxWidth(&p[0], &p[4])
.max( .max(
Self::getMaxWidth(&p[6], &p[2]) * pdf_417_common::MODULES_IN_CODEWORD as u64 Self::getMaxWidth(&p[6], &p[2]) * pdf_417_common::MODULES_IN_CODEWORD as u64
@@ -179,7 +179,7 @@ impl PDF417Reader {
)) as u32 )) as u32
} }
fn getMinCodewordWidth(p: &[Option<RXingResultPoint>]) -> u32 { fn getMinCodewordWidth(p: &[Option<Point>]) -> u32 {
Self::getMinWidth(&p[0], &p[4]) Self::getMinWidth(&p[0], &p[4])
.min( .min(
Self::getMinWidth(&p[6], &p[2]) * pdf_417_common::MODULES_IN_CODEWORD as u64 Self::getMinWidth(&p[6], &p[2]) * pdf_417_common::MODULES_IN_CODEWORD as u64

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::RXingResultPoint; use crate::Point;
/** /**
* Meta-data container for QR Code decoding. Instances of this class may be used to convey information back to the * Meta-data container for QR Code decoding. Instances of this class may be used to convey information back to the
@@ -41,7 +41,7 @@ impl QRCodeDecoderMetaData {
* *
* @param points Array of points to apply mirror correction to. * @param points Array of points to apply mirror correction to.
*/ */
pub fn applyMirroredCorrection(&self, points: &mut [RXingResultPoint]) { pub fn applyMirroredCorrection(&self, points: &mut [Point]) {
if !self.0 || points.is_empty() || points.len() < 3 { if !self.0 || points.is_empty() || points.len() < 3 {
return; return;
} }

View File

@@ -14,9 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
//RXingResultPoint //Point
use crate::{RXingResultPoint, ResultPoint}; use crate::{Point, ResultPoint};
/** /**
* <p>Encapsulates an alignment pattern, which are the smaller square patterns found in * <p>Encapsulates an alignment pattern, which are the smaller square patterns found in
@@ -39,8 +39,8 @@ impl ResultPoint for AlignmentPattern {
self.point.1 self.point.1
} }
fn into_rxing_result_point(self) -> RXingResultPoint { fn into_rxing_result_point(self) -> Point {
RXingResultPoint { Point {
x: self.point.0, x: self.point.0,
y: self.point.1, y: self.point.1,
} }

View File

@@ -16,7 +16,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
Exceptions, RXingResultPointCallback, Exceptions, PointCallback,
}; };
use super::AlignmentPattern; use super::AlignmentPattern;
@@ -44,7 +44,7 @@ pub struct AlignmentPatternFinder {
height: u32, height: u32,
moduleSize: f32, moduleSize: f32,
crossCheckStateCount: [u32; 3], crossCheckStateCount: [u32; 3],
resultPointCallback: Option<RXingResultPointCallback>, resultPointCallback: Option<PointCallback>,
} }
impl AlignmentPatternFinder { impl AlignmentPatternFinder {
@@ -65,7 +65,7 @@ impl AlignmentPatternFinder {
width: u32, width: u32,
height: u32, height: u32,
moduleSize: f32, moduleSize: f32,
resultPointCallback: Option<RXingResultPointCallback>, resultPointCallback: Option<PointCallback>,
) -> Self { ) -> Self {
Self { Self {
image, image,

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::{RXingResultPoint, ResultPoint}; use crate::{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
@@ -39,8 +39,8 @@ impl ResultPoint for FinderPattern {
self.point.1 self.point.1
} }
fn into_rxing_result_point(self) -> RXingResultPoint { fn into_rxing_result_point(self) -> Point {
RXingResultPoint { Point {
x: self.point.0, x: self.point.0,
y: self.point.1, y: self.point.1,
} }

View File

@@ -17,7 +17,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions,
RXingResultPointCallback, ResultPoint, PointCallback, ResultPoint,
}; };
use super::{FinderPattern, FinderPatternInfo}; use super::{FinderPattern, FinderPatternInfo};
@@ -35,7 +35,7 @@ pub struct FinderPatternFinder<'a> {
possibleCenters: Vec<FinderPattern>, possibleCenters: Vec<FinderPattern>,
hasSkipped: bool, hasSkipped: bool,
crossCheckStateCount: [u32; 5], crossCheckStateCount: [u32; 5],
resultPointCallback: Option<RXingResultPointCallback>, resultPointCallback: Option<PointCallback>,
} }
impl<'a> FinderPatternFinder<'_> { impl<'a> FinderPatternFinder<'_> {
pub const CENTER_QUORUM: usize = 2; pub const CENTER_QUORUM: usize = 2;
@@ -53,7 +53,7 @@ impl<'a> FinderPatternFinder<'_> {
pub fn with_callback( pub fn with_callback(
image: &'a BitMatrix, image: &'a BitMatrix,
resultPointCallback: Option<RXingResultPointCallback>, resultPointCallback: Option<PointCallback>,
) -> FinderPatternFinder<'a> { ) -> FinderPatternFinder<'a> {
FinderPatternFinder { FinderPatternFinder {
image, image,

View File

@@ -23,7 +23,7 @@ use crate::{
}, },
qrcode::decoder::Version, qrcode::decoder::Version,
result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions,
RXingResultPointCallback, ResultPoint, PointCallback, ResultPoint,
}; };
use super::{ use super::{
@@ -39,7 +39,7 @@ use super::{
*/ */
pub struct Detector<'a> { pub struct Detector<'a> {
image: &'a BitMatrix, image: &'a BitMatrix,
resultPointCallback: Option<RXingResultPointCallback>, resultPointCallback: Option<PointCallback>,
} }
impl<'a> Detector<'_> { impl<'a> Detector<'_> {
@@ -54,7 +54,7 @@ impl<'a> Detector<'_> {
self.image self.image
} }
pub fn getRXingResultPointCallback(&self) -> &Option<RXingResultPointCallback> { pub fn getPointCallback(&self) -> &Option<PointCallback> {
&self.resultPointCallback &self.resultPointCallback
} }

View File

@@ -1,15 +1,15 @@
use crate::{ use crate::{
common::{BitMatrix, DetectorRXingResult}, common::{BitMatrix, DetectorRXingResult},
RXingResultPoint, Point,
}; };
pub struct QRCodeDetectorResult { pub struct QRCodeDetectorResult {
bit_source: BitMatrix, bit_source: BitMatrix,
result_points: Vec<RXingResultPoint>, result_points: Vec<Point>,
} }
impl QRCodeDetectorResult { impl QRCodeDetectorResult {
pub fn new(bit_source: BitMatrix, result_points: Vec<RXingResultPoint>) -> Self { pub fn new(bit_source: BitMatrix, result_points: Vec<Point>) -> Self {
Self { Self {
bit_source, bit_source,
result_points, result_points,
@@ -22,7 +22,7 @@ impl DetectorRXingResult for QRCodeDetectorResult {
&self.bit_source &self.bit_source
} }
fn getPoints(&self) -> &[crate::RXingResultPoint] { fn getPoints(&self) -> &[crate::Point] {
&self.result_points &self.result_points
} }
} }

View File

@@ -19,7 +19,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::{BitMatrix, DecoderRXingResult, DetectorRXingResult, Result}, common::{BitMatrix, DecoderRXingResult, DetectorRXingResult, Result},
BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult, BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult,
RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, RXingResultMetadataType, RXingResultMetadataValue, Point, Reader,
}; };
use super::{ use super::{
@@ -36,7 +36,7 @@ use super::{
pub struct QRCodeReader; pub struct QRCodeReader;
// pub struct QRCodeReader; { // pub struct QRCodeReader; {
// // private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0]; // // private static final Point[] NO_POINTS = new Point[0];
// } // }
impl Reader for QRCodeReader { impl Reader for QRCodeReader {
@@ -58,7 +58,7 @@ impl Reader for QRCodeReader {
hints: &crate::DecodingHintDictionary, hints: &crate::DecodingHintDictionary,
) -> Result<crate::RXingResult> { ) -> Result<crate::RXingResult> {
let decoderRXingResult: DecoderRXingResult; let decoderRXingResult: DecoderRXingResult;
let mut points: Vec<RXingResultPoint>; let mut points: Vec<Point>;
if matches!( if matches!(
hints.get(&DecodeHintType::PURE_BARCODE), hints.get(&DecodeHintType::PURE_BARCODE),
Some(DecodeHintValue::PureBarcode(true)) Some(DecodeHintValue::PureBarcode(true))

View File

@@ -16,10 +16,10 @@
//package com.google.zxing; //package com.google.zxing;
use crate::RXingResultPoint; use crate::Point;
pub trait ResultPoint { pub trait ResultPoint {
fn getX(&self) -> f32; fn getX(&self) -> f32;
fn getY(&self) -> f32; fn getY(&self) -> f32;
fn into_rxing_result_point(self) -> RXingResultPoint; fn into_rxing_result_point(self) -> Point;
} }

View File

@@ -1,10 +1,10 @@
use crate::{common::detector::MathUtils, ResultPoint}; use crate::{common::detector::MathUtils, ResultPoint};
/** /**
* Orders an array of three RXingResultPoints in an order [A,B,C] such that AB is less than AC * Orders an array of three Points in an order [A,B,C] such that AB is less than AC
* and BC is less than AC, and the angle between BC and BA is less than 180 degrees. * and BC is less than AC, and the angle between BC and BA is less than 180 degrees.
* *
* @param patterns array of three {@code RXingResultPoint} to order * @param patterns array of three {@code Point} to order
*/ */
pub fn orderBestPatterns<T: ResultPoint + Copy + Clone>(patterns: &mut [T; 3]) { pub fn orderBestPatterns<T: ResultPoint + Copy + Clone>(patterns: &mut [T; 3]) {
// Find distances between pattern centers // Find distances between pattern centers

View File

@@ -16,7 +16,7 @@
use std::{collections::HashMap, fmt}; use std::{collections::HashMap, fmt};
use crate::{BarcodeFormat, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint}; use crate::{BarcodeFormat, RXingResultMetadataType, RXingResultMetadataValue, Point};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -32,7 +32,7 @@ pub struct RXingResult {
text: String, text: String,
rawBytes: Vec<u8>, rawBytes: Vec<u8>,
numBits: usize, numBits: usize,
resultPoints: Vec<RXingResultPoint>, resultPoints: Vec<Point>,
format: BarcodeFormat, format: BarcodeFormat,
resultMetadata: HashMap<RXingResultMetadataType, RXingResultMetadataValue>, resultMetadata: HashMap<RXingResultMetadataType, RXingResultMetadataValue>,
timestamp: u128, timestamp: u128,
@@ -41,7 +41,7 @@ impl RXingResult {
pub fn new( pub fn new(
text: &str, text: &str,
rawBytes: Vec<u8>, rawBytes: Vec<u8>,
resultPoints: Vec<RXingResultPoint>, resultPoints: Vec<Point>,
format: BarcodeFormat, format: BarcodeFormat,
) -> Self { ) -> Self {
Self::new_timestamp( Self::new_timestamp(
@@ -56,7 +56,7 @@ impl RXingResult {
pub fn new_timestamp( pub fn new_timestamp(
text: &str, text: &str,
rawBytes: Vec<u8>, rawBytes: Vec<u8>,
resultPoints: Vec<RXingResultPoint>, resultPoints: Vec<Point>,
format: BarcodeFormat, format: BarcodeFormat,
timestamp: u128, timestamp: u128,
) -> Self { ) -> Self {
@@ -68,7 +68,7 @@ impl RXingResult {
text: &str, text: &str,
rawBytes: Vec<u8>, rawBytes: Vec<u8>,
numBits: usize, numBits: usize,
resultPoints: Vec<RXingResultPoint>, resultPoints: Vec<Point>,
format: BarcodeFormat, format: BarcodeFormat,
timestamp: u128, timestamp: u128,
) -> Self { ) -> Self {
@@ -83,7 +83,7 @@ impl RXingResult {
} }
} }
pub fn new_from_existing_result(prev: Self, points: Vec<RXingResultPoint>) -> Self { pub fn new_from_existing_result(prev: Self, points: Vec<Point>) -> Self {
Self { Self {
text: prev.text, text: prev.text,
rawBytes: prev.rawBytes, rawBytes: prev.rawBytes,
@@ -122,11 +122,11 @@ impl RXingResult {
* identifying finder patterns or the corners of the barcode. The exact meaning is * identifying finder patterns or the corners of the barcode. The exact meaning is
* specific to the type of barcode that was decoded. * specific to the type of barcode that was decoded.
*/ */
pub fn getRXingResultPoints(&self) -> &Vec<RXingResultPoint> { pub fn getPoints(&self) -> &Vec<Point> {
&self.resultPoints &self.resultPoints
} }
pub fn getRXingResultPointsMut(&mut self) -> &mut Vec<RXingResultPoint> { pub fn getPointsMut(&mut self) -> &mut Vec<Point> {
&mut self.resultPoints &mut self.resultPoints
} }
@@ -169,7 +169,7 @@ impl RXingResult {
} }
} }
pub fn addRXingResultPoints(&mut self, newPoints: &mut Vec<RXingResultPoint>) { pub fn addPoints(&mut self, newPoints: &mut Vec<Point>) {
if !newPoints.is_empty() { if !newPoints.is_empty() {
self.resultPoints.append(newPoints); self.resultPoints.append(newPoints);
} }

View File

@@ -14,26 +14,26 @@ use serde::{Deserialize, Serialize};
*/ */
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct RXingResultPoint { pub struct Point {
pub(crate) x: f32, pub(crate) x: f32,
pub(crate) y: f32, pub(crate) y: f32,
} }
impl Hash for RXingResultPoint { impl Hash for Point {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.x.to_string().hash(state); self.x.to_string().hash(state);
self.y.to_string().hash(state); self.y.to_string().hash(state);
} }
} }
impl PartialEq for RXingResultPoint { impl PartialEq for Point {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y self.x == other.x && self.y == other.y
} }
} }
impl Eq for RXingResultPoint {} impl Eq for Point {}
impl RXingResultPoint { impl Point {
pub const fn new(x: f32, y: f32) -> Self { pub const fn new(x: f32, y: f32) -> Self {
Self { x, y } Self { x, y }
} }
@@ -43,20 +43,20 @@ impl RXingResultPoint {
} }
} }
impl std::ops::AddAssign for RXingResultPoint { impl std::ops::AddAssign for Point {
fn add_assign(&mut self, rhs: Self) { fn add_assign(&mut self, rhs: Self) {
self.x = self.x + rhs.x; self.x = self.x + rhs.x;
self.y = self.y + rhs.y; self.y = self.y + rhs.y;
} }
} }
impl<'a> Sum<&'a RXingResultPoint> for RXingResultPoint { impl<'a> Sum<&'a Point> for Point {
fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self { fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
iter.fold(Self::default(), |acc, &p| acc + p) iter.fold(Self::default(), |acc, &p| acc + p)
} }
} }
impl ResultPoint for RXingResultPoint { impl ResultPoint for Point {
fn getX(&self) -> f32 { fn getX(&self) -> f32 {
self.x self.x
} }
@@ -70,13 +70,13 @@ impl ResultPoint for RXingResultPoint {
} }
} }
impl fmt::Display for RXingResultPoint { impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({},{})", self.x, self.y) write!(f, "({},{})", self.x, self.y)
} }
} }
impl std::ops::Sub for RXingResultPoint { impl std::ops::Sub for Point {
type Output = Self; type Output = Self;
fn sub(self, rhs: Self) -> Self::Output { fn sub(self, rhs: Self) -> Self::Output {
@@ -84,7 +84,7 @@ impl std::ops::Sub for RXingResultPoint {
} }
} }
impl std::ops::Neg for RXingResultPoint { impl std::ops::Neg for Point {
type Output = Self; type Output = Self;
fn neg(self) -> Self::Output { fn neg(self) -> Self::Output {
@@ -92,7 +92,7 @@ impl std::ops::Neg for RXingResultPoint {
} }
} }
impl std::ops::Add for RXingResultPoint { impl std::ops::Add for Point {
type Output = Self; type Output = Self;
fn add(self, rhs: Self) -> Self::Output { fn add(self, rhs: Self) -> Self::Output {
@@ -100,7 +100,7 @@ impl std::ops::Add for RXingResultPoint {
} }
} }
impl std::ops::Mul for RXingResultPoint { impl std::ops::Mul for Point {
type Output = Self; type Output = Self;
fn mul(self, rhs: Self) -> Self::Output { fn mul(self, rhs: Self) -> Self::Output {
@@ -108,7 +108,7 @@ impl std::ops::Mul for RXingResultPoint {
} }
} }
impl std::ops::Mul<f32> for RXingResultPoint { impl std::ops::Mul<f32> for Point {
type Output = Self; type Output = Self;
fn mul(self, rhs: f32) -> Self::Output { fn mul(self, rhs: f32) -> Self::Output {
@@ -116,7 +116,7 @@ impl std::ops::Mul<f32> for RXingResultPoint {
} }
} }
impl std::ops::Mul<i32> for RXingResultPoint { impl std::ops::Mul<i32> for Point {
type Output = Self; type Output = Self;
fn mul(self, rhs: i32) -> Self::Output { fn mul(self, rhs: i32) -> Self::Output {
@@ -124,31 +124,31 @@ impl std::ops::Mul<i32> for RXingResultPoint {
} }
} }
impl std::ops::Mul<RXingResultPoint> for i32 { impl std::ops::Mul<Point> for i32 {
type Output = RXingResultPoint; type Output = Point;
fn mul(self, rhs: RXingResultPoint) -> Self::Output { fn mul(self, rhs: Point) -> Self::Output {
Self::Output::new(rhs.x * self as f32, rhs.y * self as f32) Self::Output::new(rhs.x * self as f32, rhs.y * self as f32)
} }
} }
impl std::ops::Mul<RXingResultPoint> for f32 { impl std::ops::Mul<Point> for f32 {
type Output = RXingResultPoint; type Output = Point;
fn mul(self, rhs: RXingResultPoint) -> Self::Output { fn mul(self, rhs: Point) -> Self::Output {
Self::Output::new(rhs.x * self, rhs.y * self) Self::Output::new(rhs.x * self, rhs.y * self)
} }
} }
impl std::ops::Div<f32> for RXingResultPoint { impl std::ops::Div<f32> for Point {
type Output = RXingResultPoint; type Output = Point;
fn div(self, rhs: f32) -> Self::Output { fn div(self, rhs: f32) -> Self::Output {
Self::Output::new(self.x / rhs, self.y / rhs) Self::Output::new(self.x / rhs, self.y / rhs)
} }
} }
impl RXingResultPoint { impl Point {
pub fn dot(self, p: Self) -> f32 { pub fn dot(self, p: Self) -> f32 {
self.x * p.x + self.y * p.y self.x * p.x + self.y * p.y
} }