From dbc6ca4e55131ece8596cf3934eadb7b12fa8c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Stepanovi=C4=87?= Date: Thu, 16 Feb 2023 08:25:32 +0000 Subject: [PATCH] wip: Search & replace RXingResultPoint with Point Build fails because the OneDReader proc macro expects that a RXingResultPoint type exists. --- src/aztec/DecoderTest.rs | 6 +- src/aztec/DetectorTest.rs | 10 +- src/aztec/EncoderTest.rs | 4 +- src/aztec/aztec_detector_result.rs | 10 +- src/aztec/detector.rs | 112 +++++++++--------- src/common/bit_matrix.rs | 6 +- .../detector/monochrome_rectangle_detector.rs | 22 ++-- .../detector/white_rectangle_detector.rs | 46 +++---- src/common/mod.rs | 8 +- src/datamatrix/data_matrix_reader.rs | 2 +- .../detector/datamatrix_detector.rs | 34 +++--- src/datamatrix/detector/datamatrix_result.rs | 8 +- .../zxing_cpp_detector/bitmatrix_cursor.rs | 28 ++--- .../zxing_cpp_detector/cpp_new_detector.rs | 34 +++--- .../zxing_cpp_detector/dm_regression_line.rs | 54 ++++----- .../zxing_cpp_detector/edge_tracer.rs | 68 +++++------ .../detector/zxing_cpp_detector/quad.rs | 60 +++++----- .../zxing_cpp_detector/regression_line.rs | 28 ++--- .../detector/zxing_cpp_detector/util.rs | 6 +- src/decode_hints.rs | 12 +- src/lib.rs | 2 +- src/maxicode/detector.rs | 28 ++--- src/multi/by_quadrant_reader.rs | 18 +-- src/multi/generic_multiple_barcode_reader.rs | 26 ++-- .../detector/multi_finder_pattern_finder.rs | 4 +- src/oned/coda_bar_reader.rs | 4 +- src/oned/code_128_reader.rs | 4 +- src/oned/code_39_reader.rs | 4 +- src/oned/code_93_reader.rs | 4 +- src/oned/itf_reader.rs | 4 +- src/oned/multi_format_one_d_reader.rs | 4 +- src/oned/multi_format_upc_ean_reader.rs | 6 +- src/oned/one_d_reader.rs | 8 +- src/oned/rss/expanded/rss_expanded_reader.rs | 8 +- src/oned/rss/finder_pattern.rs | 10 +- src/oned/rss/rss_14_reader.rs | 12 +- src/oned/upc_a_reader.rs | 2 +- src/oned/upc_ean_extension_2_support.rs | 6 +- src/oned/upc_ean_extension_5_support.rs | 6 +- src/oned/upc_ean_reader.rs | 14 +-- src/pdf417/decoder/bounding_box.rs | 38 +++--- .../decoder/pdf_417_scanning_decoder.rs | 12 +- src/pdf417/detector/pdf_417_detector.rs | 26 ++-- .../detector/pdf_417_detector_result.rs | 10 +- src/pdf417/pdf_417_reader.rs | 10 +- .../decoder/qr_code_decoder_meta_data.rs | 4 +- src/qrcode/detector/alignment_pattern.rs | 8 +- .../detector/alignment_pattern_finder.rs | 6 +- src/qrcode/detector/finder_pattern.rs | 6 +- src/qrcode/detector/finder_pattern_finder.rs | 6 +- src/qrcode/detector/qrcode_detector.rs | 6 +- src/qrcode/detector/qrcode_detector_result.rs | 8 +- src/qrcode/qr_code_reader.rs | 6 +- src/result_point.rs | 4 +- src/result_point_utils.rs | 4 +- src/rxing_result.rs | 18 +-- src/rxing_result_point.rs | 48 ++++---- 57 files changed, 476 insertions(+), 476 deletions(-) diff --git a/src/aztec/DecoderTest.rs b/src/aztec/DecoderTest.rs index c7deae2..0a68af8 100644 --- a/src/aztec/DecoderTest.rs +++ b/src/aztec/DecoderTest.rs @@ -18,7 +18,7 @@ // import com.google.zxing.aztec.encoder.EncoderTest; // 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.common.BitArray; // import com.google.zxing.common.BitMatrix; @@ -29,7 +29,7 @@ use crate::{ aztec::shared_test_methods::{stripSpace, toBitArray, toBooleanArray}, common::BitMatrix, - RXingResultPoint, + Point, }; use super::{aztec_detector_result::AztecDetectorRXingResult, decoder}; @@ -38,7 +38,7 @@ use super::{aztec_detector_result::AztecDetectorRXingResult, 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] fn test_high_level_decode() { diff --git a/src/aztec/DetectorTest.rs b/src/aztec/DetectorTest.rs index 5c9cc50..d88f1e9 100644 --- a/src/aztec/DetectorTest.rs +++ b/src/aztec/DetectorTest.rs @@ -39,7 +39,7 @@ use rand::Rng; use crate::{aztec::decoder, common::BitMatrix, exceptions::Exceptions}; use super::{ - detector::{self, Detector, Point}, + detector::{self, Detector, AztecPoint}, encoder::{self, AztecCode}, }; @@ -261,7 +261,7 @@ fn clone(input: &BitMatrix) -> BitMatrix { result } -fn get_orientation_points(code: &AztecCode) -> Vec { +fn get_orientation_points(code: &AztecCode) -> Vec { let center = code.getMatrix().getWidth() as i32 / 2; let offset = if code.isCompact() { 5 } else { 7 }; let mut result = Vec::new(); @@ -271,12 +271,12 @@ fn get_orientation_points(code: &AztecCode) -> Vec { let mut ySign: i32 = -1; while ySign <= 1 { // for (int ySign = -1; ySign <= 1; ySign += 2) { - result.push(Point::new(center + xSign * offset, center + ySign * offset)); - result.push(Point::new( + result.push(AztecPoint::new(center + xSign * offset, center + ySign * offset)); + result.push(AztecPoint::new( center + xSign * (offset - 1), center + ySign * offset, )); - result.push(Point::new( + result.push(AztecPoint::new( center + xSign * offset, center + ySign * (offset - 1), )); diff --git a/src/aztec/EncoderTest.rs b/src/aztec/EncoderTest.rs index af45797..bf7be82 100644 --- a/src/aztec/EncoderTest.rs +++ b/src/aztec/EncoderTest.rs @@ -25,7 +25,7 @@ use crate::{ encoder::HighLevelEncoder, shared_test_methods::{stripSpace, toBitArray, toBooleanArray}, }, - BarcodeFormat, EncodeHintType, EncodeHintValue, RXingResultPoint, + BarcodeFormat, EncodeHintType, EncodeHintValue, Point, }; 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 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 diff --git a/src/aztec/aztec_detector_result.rs b/src/aztec/aztec_detector_result.rs index 8579347..7a7ab6c 100644 --- a/src/aztec/aztec_detector_result.rs +++ b/src/aztec/aztec_detector_result.rs @@ -16,13 +16,13 @@ // 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.DetectorRXingResult; use crate::{ common::{BitMatrix, DetectorRXingResult}, - RXingResultPoint, + Point, }; /** @@ -33,7 +33,7 @@ use crate::{ */ pub struct AztecDetectorRXingResult { bits: BitMatrix, - points: [RXingResultPoint; 4], + points: [Point; 4], compact: bool, nbDatablocks: u32, nbLayers: u32, @@ -44,7 +44,7 @@ impl DetectorRXingResult for AztecDetectorRXingResult { &self.bits } - fn getPoints(&self) -> &[RXingResultPoint] { + fn getPoints(&self) -> &[Point] { &self.points } } @@ -52,7 +52,7 @@ impl DetectorRXingResult for AztecDetectorRXingResult { impl AztecDetectorRXingResult { pub fn new( bits: BitMatrix, - points: [RXingResultPoint; 4], + points: [Point; 4], compact: bool, nbDatablocks: u32, nbLayers: u32, diff --git a/src/aztec/detector.rs b/src/aztec/detector.rs index ff987d1..2ad79ef 100644 --- a/src/aztec/detector.rs +++ b/src/aztec/detector.rs @@ -23,7 +23,7 @@ use crate::{ BitMatrix, DefaultGridSampler, GridSampler, Result, }, exceptions::Exceptions, - RXingResultPoint, ResultPoint, + Point, ResultPoint, }; use super::aztec_detector_result::AztecDetectorRXingResult; @@ -118,7 +118,7 @@ impl<'a> Detector<'_> { * @param bullsEyeCorners the array of bull's eye corners * @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]) || !self.is_valid(bulls_eye_corners[1]) || !self.is_valid(bulls_eye_corners[2]) @@ -266,7 +266,7 @@ impl<'a> Detector<'_> { * @return The corners of the bull-eye * @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 pinb = 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 // between the white square and the black square 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 = - 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 = - 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 = - 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 // just outside the bull's eye. @@ -348,11 +348,11 @@ impl<'a> Detector<'_> { * * @return the center point */ - fn get_matrix_center(&self) -> Point { - let mut point_a = RXingResultPoint::default(); - let mut point_b = RXingResultPoint::default(); - let mut point_c = RXingResultPoint::default(); - let mut point_d = RXingResultPoint::default(); + fn get_matrix_center(&self) -> AztecPoint { + let mut point_a = Point::default(); + let mut point_b = Point::default(); + let mut point_c = Point::default(); + let mut point_d = Point::default(); let mut fnd = false; @@ -373,16 +373,16 @@ impl<'a> Detector<'_> { let cx: i32 = (self.image.getWidth() / 2) as i32; let cy: i32 = (self.image.getHeight() / 2) as i32; 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(); 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(); 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(); 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(); } // try { @@ -399,10 +399,10 @@ impl<'a> Detector<'_> { // // In that case, surely in the bull's eye, we try to expand the rectangle. // int cx = image.getWidth() / 2; // int cy = image.getHeight() / 2; - // pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toRXingResultPoint(); - // pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toRXingResultPoint(); - // pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toRXingResultPoint(); - // pointD = 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).toPoint(); + // pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toPoint(); + // 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. if !fnd { 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(); 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(); 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(); 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(); } // try { - // RXingResultPoint[] cornerPoints = new WhiteRectangleDetector(image, 15, cx, cy).detect(); + // Point[] cornerPoints = new WhiteRectangleDetector(image, 15, cx, cy).detect(); // pointA = cornerPoints[0]; // pointB = cornerPoints[1]; // pointC = cornerPoints[2]; @@ -452,10 +452,10 @@ impl<'a> Detector<'_> { // } catch (NotFoundException e) { // // This exception can be in case the initial rectangle is white // // In that case we try to expand the rectangle. - // pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toRXingResultPoint(); - // pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toRXingResultPoint(); - // pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toRXingResultPoint(); - // pointD = 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).toPoint(); + // pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toPoint(); + // pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toPoint(); // } // 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::new(cx, cy) + AztecPoint::new(cx, cy) } /** @@ -477,8 +477,8 @@ impl<'a> Detector<'_> { */ fn get_matrix_corner_points( &self, - bulls_eye_corners: &[RXingResultPoint], - ) -> [RXingResultPoint; 4] { + bulls_eye_corners: &[Point], + ) -> [Point; 4] { Self::expand_square( bulls_eye_corners, 2 * self.nb_center_layers, @@ -494,10 +494,10 @@ impl<'a> Detector<'_> { fn sample_grid( &self, image: &BitMatrix, - top_left: RXingResultPoint, - top_right: RXingResultPoint, - bottom_right: RXingResultPoint, - bottom_left: RXingResultPoint, + top_left: Point, + top_right: Point, + bottom_right: Point, + bottom_left: Point, ) -> Result { let sampler = DefaultGridSampler::default(); let dimension = self.get_dimension(); @@ -536,7 +536,7 @@ impl<'a> Detector<'_> { * @param size number of bits * @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 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 * 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 p1 = Point::new( + let p1 = AztecPoint::new( 0.max(p1.get_x() - 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 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 p3 = Point::new( + let p3 = AztecPoint::new( (self.image.getWidth() as i32 - 1).min(p3.get_x() + 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), // 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.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 */ - 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); if d == 0.0f32 { return 0; @@ -657,7 +657,7 @@ impl<'a> Detector<'_> { /** * 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 y = init.get_y() + dy; @@ -679,7 +679,7 @@ impl<'a> Detector<'_> { } y -= dy; - Point::new(x, y) + AztecPoint::new(x, y) } /** @@ -691,10 +691,10 @@ impl<'a> Detector<'_> { * @return the corners of the expanded square */ fn expand_square( - corner_points: &[RXingResultPoint], + corner_points: &[Point], old_side: u32, new_side: u32, - ) -> [RXingResultPoint; 4] { + ) -> [Point; 4] { let ratio = new_side as f32 / (2.0f32 * old_side as f32); 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 } - fn is_valid(&self, point: RXingResultPoint) -> bool { + fn is_valid(&self, point: Point) -> bool { let x = MathUtils::round(point.getX()); let y = MathUtils::round(point.getY()); 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()) } - fn distance(a: RXingResultPoint, b: RXingResultPoint) -> f32 { + fn distance(a: Point, b: Point) -> f32 { MathUtils::distance(a.getX(), a.getY(), b.getX(), b.getY()) } @@ -738,12 +738,12 @@ impl<'a> Detector<'_> { } #[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub struct Point { +pub struct AztecPoint { x: i32, y: i32, } -impl Point { +impl AztecPoint { pub fn new(x: i32, y: i32) -> Self { Self { x, y } } @@ -757,13 +757,13 @@ impl Point { } } -impl From for RXingResultPoint { - fn from(value: Point) -> Self { - RXingResultPoint::new(value.x as f32, value.y as f32) +impl From for Point { + fn from(value: AztecPoint) -> Self { + 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 { write!(f, "<{} {}>", &self.x, &self.y) } diff --git a/src/common/bit_matrix.rs b/src/common/bit_matrix.rs index c3e0b20..1b8fa9f 100644 --- a/src/common/bit_matrix.rs +++ b/src/common/bit_matrix.rs @@ -21,7 +21,7 @@ use std::fmt; use crate::common::Result; -use crate::{Exceptions, RXingResultPoint}; +use crate::{Exceptions, Point}; use super::BitArray; @@ -213,7 +213,7 @@ impl BitMatrix { ((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) // let offset = self.get_offset(point.y as u32, point.x as u32); // ((self.bits[offset] >> (x & 0x1f)) & 1) != 0 @@ -695,7 +695,7 @@ impl BitMatrix { 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 && p.x < self.getWidth() as f32 - b as f32 && b as f32 <= p.y diff --git a/src/common/detector/monochrome_rectangle_detector.rs b/src/common/detector/monochrome_rectangle_detector.rs index 16d297d..31a1e44 100644 --- a/src/common/detector/monochrome_rectangle_detector.rs +++ b/src/common/detector/monochrome_rectangle_detector.rs @@ -19,7 +19,7 @@ use crate::{ common::{BitMatrix, Result}, - Exceptions, RXingResultPoint, ResultPoint, + Exceptions, Point, ResultPoint, }; /** @@ -45,13 +45,13 @@ impl<'a> MonochromeRectangleDetector<'_> { *

Detects a rectangular region of black and white -- mostly black -- with a region of mostly * white, in an image.

* - * @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 * the topmost point and the last, the bottommost. The second point will be leftmost and the * third, the rightmost * @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 width = self.image.getWidth() as i32; let halfHeight = height / 2; @@ -143,7 +143,7 @@ impl<'a> MonochromeRectangleDetector<'_> { * @param bottom maximum value of y * @param maxWhiteRun maximum run of white pixels that can still be considered to be within * 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 */ #[allow(clippy::too_many_arguments)] @@ -158,7 +158,7 @@ impl<'a> MonochromeRectangleDetector<'_> { top: i32, bottom: i32, maxWhiteRun: i32, - ) -> Result { + ) -> Result { let mut lastRange_z: Option<[i32; 2]> = None; let mut y: i32 = centerY; let mut x: i32 = centerX; @@ -178,27 +178,27 @@ impl<'a> MonochromeRectangleDetector<'_> { if lastRange[0] < centerX { if lastRange[1] > centerX { // straddle, choose one or the other based on direction - return Ok(RXingResultPoint::new( + return Ok(Point::new( lastRange[usize::from(deltaY <= 0)] 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 { - return Ok(RXingResultPoint::new(lastRange[1] as f32, lastY as f32)); + return Ok(Point::new(lastRange[1] as f32, lastY as f32)); } } else { let lastX = x - deltaX; if lastRange[0] < centerY { if lastRange[1] > centerY { - return Ok(RXingResultPoint::new( + return Ok(Point::new( lastX 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 { - return Ok(RXingResultPoint::new(lastX as f32, lastRange[1] as f32)); + return Ok(Point::new(lastX as f32, lastRange[1] as f32)); } } } diff --git a/src/common/detector/white_rectangle_detector.rs b/src/common/detector/white_rectangle_detector.rs index c52b937..5033874 100644 --- a/src/common/detector/white_rectangle_detector.rs +++ b/src/common/detector/white_rectangle_detector.rs @@ -18,7 +18,7 @@ use crate::{ common::{BitMatrix, Result}, - Exceptions, RXingResultPoint, ResultPoint, + Exceptions, Point, ResultPoint, }; use super::MathUtils; @@ -101,14 +101,14 @@ impl<'a> WhiteRectangleDetector<'_> { * region until it finds a white rectangular region. *

* - * @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 * 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 third, the rightmost * @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 right: i32 = self.rightInit; let mut up: i32 = self.upInit; @@ -212,7 +212,7 @@ impl<'a> WhiteRectangleDetector<'_> { if !size_exceeded { let max_size = right - left; - let mut z: Option = None; + let mut z: Option = None; let mut i = 1; while z.is_none() && i < max_size { //for (int i = 1; z == null && i < maxSize; i++) { @@ -229,7 +229,7 @@ impl<'a> WhiteRectangleDetector<'_> { return Err(Exceptions::NotFoundException(None)); } - let mut t: Option = None; + let mut t: Option = None; //go down right let mut i = 1; while t.is_none() && i < max_size { @@ -247,7 +247,7 @@ impl<'a> WhiteRectangleDetector<'_> { return Err(Exceptions::NotFoundException(None)); } - let mut x: Option = None; + let mut x: Option = None; //go down left let mut i = 1; while x.is_none() && i < max_size { @@ -265,7 +265,7 @@ impl<'a> WhiteRectangleDetector<'_> { return Err(Exceptions::NotFoundException(None)); } - let mut y: Option = None; + let mut y: Option = None; //go up left let mut i = 1; while y.is_none() && i < max_size { @@ -295,7 +295,7 @@ impl<'a> WhiteRectangleDetector<'_> { a_y: f32, b_x: f32, b_y: f32, - ) -> Option { + ) -> Option { 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 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 y = MathUtils::round(a_y + i as f32 * y_step); 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 @@ -317,7 +317,7 @@ impl<'a> WhiteRectangleDetector<'_> { * @param z left most point * @param x right 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 * are the second and third. The first point will be the topmost * point and the last, the bottommost. The second point will be @@ -325,11 +325,11 @@ impl<'a> WhiteRectangleDetector<'_> { */ fn center_edges( &self, - y: RXingResultPoint, - z: RXingResultPoint, - x: RXingResultPoint, - t: RXingResultPoint, - ) -> [RXingResultPoint; 4] { + y: Point, + z: Point, + x: Point, + t: Point, + ) -> [Point; 4] { // // t t // z x @@ -348,17 +348,17 @@ impl<'a> WhiteRectangleDetector<'_> { if yi < self.width as f32 / 2.0f32 { [ - RXingResultPoint::new(ti - CORR as f32, tj + CORR as f32), - RXingResultPoint::new(zi + CORR as f32, zj + CORR as f32), - RXingResultPoint::new(xi - CORR as f32, xj - CORR as f32), - RXingResultPoint::new(yi + CORR as f32, yj - CORR as f32), + Point::new(ti - CORR as f32, tj + CORR as f32), + Point::new(zi + CORR as f32, zj + CORR as f32), + Point::new(xi - CORR as f32, xj - CORR as f32), + Point::new(yi + CORR as f32, yj - CORR as f32), ] } else { [ - RXingResultPoint::new(ti + CORR as f32, tj + CORR as f32), - RXingResultPoint::new(zi + CORR as f32, zj - CORR as f32), - RXingResultPoint::new(xi - CORR as f32, xj + CORR as f32), - RXingResultPoint::new(yi - CORR as f32, yj - CORR as f32), + Point::new(ti + CORR as f32, tj + CORR as f32), + Point::new(zi + CORR as f32, zj - CORR as f32), + Point::new(xi - CORR as f32, xj + CORR as f32), + Point::new(yi - CORR as f32, yj - CORR as f32), ] } } diff --git a/src/common/mod.rs b/src/common/mod.rs index 4b3b080..257e8a6 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,7 +1,7 @@ pub mod detector; pub mod reedsolomon; -use crate::RXingResultPoint; +use crate::Point; #[cfg(test)] mod StringUtilsTestCase; @@ -44,7 +44,7 @@ pub type Result = std::result::Result; // package com.google.zxing.common; -// import com.google.zxing.RXingResultPoint; +// import com.google.zxing.Point; /** *

Encapsulates the result of detecting a barcode in an image. This includes the raw @@ -56,12 +56,12 @@ pub type Result = std::result::Result; pub trait DetectorRXingResult { fn getBits(&self) -> &BitMatrix; - fn getPoints(&self) -> &[RXingResultPoint]; + fn getPoints(&self) -> &[Point]; } // pub struct DetectorRXingResult { // bits: BitMatrix, -// points: Vec, +// points: Vec, // } mod bit_matrix; diff --git a/src/datamatrix/data_matrix_reader.rs b/src/datamatrix/data_matrix_reader.rs index 9a9adf2..40ebb6e 100644 --- a/src/datamatrix/data_matrix_reader.rs +++ b/src/datamatrix/data_matrix_reader.rs @@ -39,7 +39,7 @@ static DECODER: Lazy = Lazy::new(Decoder::new); #[derive(Default)] 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(); diff --git a/src/datamatrix/detector/datamatrix_detector.rs b/src/datamatrix/detector/datamatrix_detector.rs index 71fedd8..0ec28cd 100644 --- a/src/datamatrix/detector/datamatrix_detector.rs +++ b/src/datamatrix/detector/datamatrix_detector.rs @@ -18,7 +18,7 @@ use crate::{ common::{ detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result, }, - Exceptions, RXingResultPoint, ResultPoint, + Exceptions, Point, ResultPoint, }; 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 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 y = point.getY(); @@ -123,13 +123,13 @@ impl<'a> Detector<'_> { y += 1.0; } - RXingResultPoint::new(x, y) + Point::new(x, y) } /** * 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 // 1 3 let pointA = cornerPoints[0]; @@ -174,7 +174,7 @@ impl<'a> Detector<'_> { /** * 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 // : : // B--C @@ -214,7 +214,7 @@ impl<'a> Detector<'_> { /** * Calculates the corner position of the white top right module. */ - fn correctTopRight(&self, points: &[RXingResultPoint; 4]) -> Option { + fn correctTopRight(&self, points: &[Point; 4]) -> Option { // A..D // | : // B--C @@ -232,11 +232,11 @@ impl<'a> Detector<'_> { trTop = self.transitionsBetween(pointAs, 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.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.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. */ - fn shiftToModuleCenter(&self, points: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] { + fn shiftToModuleCenter(&self, points: [Point; 4]) -> [Point; 4] { // A..D // | : // B--C @@ -318,7 +318,7 @@ impl<'a> Detector<'_> { [pointAs, pointBs, pointCs, pointDs] } - fn isValid(&self, p: RXingResultPoint) -> bool { + fn isValid(&self, p: Point) -> bool { p.getX() >= 0.0 && p.getX() <= self.image.getWidth() as f32 - 1.0 && p.getY() > 0.0 @@ -327,10 +327,10 @@ impl<'a> Detector<'_> { fn sampleGrid( image: &BitMatrix, - topLeft: RXingResultPoint, - bottomLeft: RXingResultPoint, - bottomRight: RXingResultPoint, - topRight: RXingResultPoint, + topLeft: Point, + bottomLeft: Point, + bottomRight: Point, + topRight: Point, dimensionX: u32, dimensionY: u32, ) -> Result { @@ -362,7 +362,7 @@ impl<'a> Detector<'_> { /** * 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() let mut fromX = from.getX().floor() as i32; let mut fromY = from.getY().floor() as i32; diff --git a/src/datamatrix/detector/datamatrix_result.rs b/src/datamatrix/detector/datamatrix_result.rs index 40811e5..bd2634b 100644 --- a/src/datamatrix/detector/datamatrix_result.rs +++ b/src/datamatrix/detector/datamatrix_result.rs @@ -1,12 +1,12 @@ use crate::{ common::{BitMatrix, DetectorRXingResult}, - RXingResultPoint, + Point, }; -pub struct DatamatrixDetectorResult(BitMatrix, Vec); +pub struct DatamatrixDetectorResult(BitMatrix, Vec); impl DatamatrixDetectorResult { - pub fn new(bits: BitMatrix, points: Vec) -> Self { + pub fn new(bits: BitMatrix, points: Vec) -> Self { Self(bits, points) } } @@ -16,7 +16,7 @@ impl DetectorRXingResult for DatamatrixDetectorResult { &self.0 } - fn getPoints(&self) -> &[RXingResultPoint] { + fn getPoints(&self) -> &[Point] { &self.1 } } diff --git a/src/datamatrix/detector/zxing_cpp_detector/bitmatrix_cursor.rs b/src/datamatrix/detector/zxing_cpp_detector/bitmatrix_cursor.rs index 74db446..4bd9505 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/bitmatrix_cursor.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/bitmatrix_cursor.rs @@ -1,4 +1,4 @@ -use crate::RXingResultPoint; +use crate::Point; 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); } - fn testAt(&self, p: RXingResultPoint) -> Value; //const + fn testAt(&self, p: Point) -> Value; //const // { // 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() } - fn whiteAt(&self, pos: RXingResultPoint) -> bool { + fn whiteAt(&self, pos: Point) -> bool { 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 isBlack(&self) -> bool; // { return blackAt(p); } fn isWhite(&self) -> bool; // { return whiteAt(p); } - fn front(&self) -> &RXingResultPoint; //{ return d; } - fn back(&self) -> RXingResultPoint; // { return {-d.x, -d.y}; } - fn left(&self) -> RXingResultPoint; //{ return {d.y, -d.x}; } - fn right(&self) -> RXingResultPoint; //{ return {-d.y, d.x}; } - fn direction(&self, dir: Direction) -> RXingResultPoint { + fn front(&self) -> &Point; //{ return d; } + fn back(&self) -> Point; // { return {-d.x, -d.y}; } + fn left(&self) -> Point; //{ return {d.y, -d.x}; } + fn right(&self) -> Point; //{ return {-d.y, d.x}; } + fn direction(&self, dir: Direction) -> Point { self.right() * Into::::into(dir) } @@ -46,7 +46,7 @@ pub trait BitMatrixCursor { fn turnRight(&mut self); //noexcept { d = right(); } 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); // return testAt(p + d) != v ? v : Value(); @@ -68,8 +68,8 @@ pub trait BitMatrixCursor { self.edgeAt_point(self.direction(dir)) } - fn setDirection(&mut self, dir: RXingResultPoint); // { d = bresenhamDirection(dir); } - // fn setDirection(&self, dir: RXingResultPoint);// { d = dir; } + fn setDirection(&mut self, dir: Point); // { d = bresenhamDirection(dir); } + // fn setDirection(&self, dir: Point);// { d = dir; } fn step(&mut self, s: Option) -> bool; // DEF to 1 // { @@ -77,7 +77,7 @@ pub trait BitMatrixCursor { // return isIn(p); // } - fn movedBy(self, d: RXingResultPoint) -> Self; + fn movedBy(self, d: Point) -> Self; // { // auto res = *this; // res.p += d; diff --git a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs index 2287dff..83d449b 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs @@ -21,7 +21,7 @@ use crate::{ }, qrcode::encoder::ByteMatrix, result_point_utils::distance, - Exceptions, RXingResultPoint, ResultPoint, + Exceptions, Point, ResultPoint, }; use super::{DMRegressionLine, EdgeTracer}; @@ -46,10 +46,10 @@ fn Scan( continue; } - let mut tl = RXingResultPoint::default(); - let mut bl = RXingResultPoint::default(); - let mut br = RXingResultPoint::default(); - let mut tr = RXingResultPoint::default(); + let mut tl = Point::default(); + let mut bl = Point::default(); + let mut br = Point::default(); + let mut tr = Point::default(); for l in lines.iter_mut() { l.reset(); @@ -197,13 +197,13 @@ fn Scan( CHECK!((10..=144).contains(&dimT) && (8..=144).contains(&dimR)); - let movedTowardsBy = |a: RXingResultPoint, - b1: RXingResultPoint, - b2: RXingResultPoint, + let movedTowardsBy = |a: Point, + b1: Point, + b2: Point, d: f32| - -> RXingResultPoint { - a + d * RXingResultPoint::normalized( - RXingResultPoint::normalized(b1 - a) + RXingResultPoint::normalized(b2 - a), + -> Point { + a + d * Point::normalized( + 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 for dir in [ - RXingResultPoint { x: -1.0, y: 0.0 }, - RXingResultPoint { x: 1.0, y: 0.0 }, - RXingResultPoint { x: 0.0, y: -1.0 }, - RXingResultPoint { x: 0.0, y: 1.0 }, + Point { x: -1.0, y: 0.0 }, + Point { x: 1.0, y: 0.0 }, + Point { 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)}) { - let center = RXingResultPoint { + let center = Point { x: (image.getWidth() / 2) as f32, y: (image.getHeight() / 2) as f32, }; //PointF(image.width() / 2, image.height() / 2); 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 { history.borrow_mut().clear(0); diff --git a/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs b/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs index 6cd6a0d..0edf347 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/dm_regression_line.rs @@ -1,5 +1,5 @@ use crate::common::Result; -use crate::{Exceptions, RXingResultPoint}; +use crate::{Exceptions, Point}; use super::{ util::{float_max, float_min}, @@ -8,8 +8,8 @@ use super::{ #[derive(Clone)] pub struct DMRegressionLine { - points: Vec, - direction_inward: RXingResultPoint, + points: Vec, + direction_inward: Point, pub(super) a: f32, pub(super) b: f32, pub(super) c: f32, @@ -31,13 +31,13 @@ impl Default for DMRegressionLine { } impl RegressionLine for DMRegressionLine { - fn points(&self) -> &[RXingResultPoint] { + fn points(&self) -> &[Point] { &self.points } fn length(&self) -> u32 { 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 } else { 0 @@ -48,9 +48,9 @@ impl RegressionLine for DMRegressionLine { !self.a.is_nan() } - fn normal(&self) -> RXingResultPoint { + fn normal(&self) -> Point { if self.isValid() { - RXingResultPoint { + Point { x: self.a, y: self.b, } @@ -59,29 +59,29 @@ impl RegressionLine for DMRegressionLine { } } - fn signedDistance(&self, p: RXingResultPoint) -> f32 { - RXingResultPoint::dot(self.normal(), p) - self.c + fn signedDistance(&self, p: Point) -> f32 { + 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() } fn reset(&mut self) { 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.b = f32::NAN; self.c = f32::NAN; } - fn add(&mut self, p: RXingResultPoint) -> Result<()> { - if self.direction_inward == RXingResultPoint::default() { + fn add(&mut self, p: Point) -> Result<()> { + if self.direction_inward == Point::default() { return Err(Exceptions::IllegalStateException(None)); } self.points.push(p); if self.points.len() == 1 { - self.c = RXingResultPoint::dot(self.normal(), p); + self.c = Point::dot(self.normal(), p); } Ok(()) } @@ -90,8 +90,8 @@ impl RegressionLine for DMRegressionLine { self.points.pop(); } - fn setDirectionInward(&mut self, d: RXingResultPoint) { - self.direction_inward = RXingResultPoint::normalized(d); + fn setDirectionInward(&mut self, d: Point) { + self.direction_inward = Point::normalized(d); } fn evaluate_max_distance( @@ -149,8 +149,8 @@ impl RegressionLine for DMRegressionLine { steps > 2.0 || len > 50.0 } - fn evaluate(&mut self, points: &[RXingResultPoint]) -> bool { - let mean = points.iter().sum::() / points.len() as f32; + fn evaluate(&mut self, points: &[Point]) -> bool { + let mean = points.iter().sum::() / points.len() as f32; let mut sumXX = 0.0; let mut sumYY = 0.0; @@ -171,18 +171,18 @@ impl RegressionLine for DMRegressionLine { self.a = sumXY / 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) { self.a = -self.a; self.b = -self.b; } - self.c = RXingResultPoint::dot(self.normal(), mean); // (a*mean.x + b*mean.y); - RXingResultPoint::dot(self.direction_inward, self.normal()) > 0.5 + self.c = Point::dot(self.normal(), mean); // (a*mean.x + b*mean.y); + Point::dot(self.direction_inward, self.normal()) > 0.5 // angle between original and new direction is at most 60 degree } fn evaluateSelf(&mut self) -> bool { - let mean = self.points.iter().sum::() / self.points.len() as f32; + let mean = self.points.iter().sum::() / self.points.len() as f32; let mut sumXX = 0.0; let mut sumYY = 0.0; @@ -203,13 +203,13 @@ impl RegressionLine for DMRegressionLine { self.a = sumXY / 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) { self.a = -self.a; self.b = -self.b; } - self.c = RXingResultPoint::dot(self.normal(), mean); // (a*mean.x + b*mean.y); - RXingResultPoint::dot(self.direction_inward, self.normal()) > 0.5 + self.c = Point::dot(self.normal(), mean); // (a*mean.x + b*mean.y); + Point::dot(self.direction_inward, self.normal()) > 0.5 // angle between original and new direction is at most 60 degree } } @@ -236,7 +236,7 @@ impl DMRegressionLine { self.points.reverse(); } - pub fn modules(&mut self, beg: RXingResultPoint, end: RXingResultPoint) -> Result { + pub fn modules(&mut self, beg: Point, end: Point) -> Result { if self.points.len() <= 3 { return Err(Exceptions::IllegalStateException(None)); } @@ -260,7 +260,7 @@ impl DMRegressionLine { } // calculate the (expected average) distance of two adjacent pixels - let unitPixelDist = RXingResultPoint::length(RXingResultPoint::bresenhamDirection( + let unitPixelDist = Point::length(Point::bresenhamDirection( self.points .last() .copied() diff --git a/src/datamatrix/detector/zxing_cpp_detector/edge_tracer.rs b/src/datamatrix/detector/zxing_cpp_detector/edge_tracer.rs index f84c53a..1787985 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/edge_tracer.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/edge_tracer.rs @@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc}; use crate::{ common::{BitMatrix, Result}, qrcode::encoder::ByteMatrix, - Exceptions, RXingResultPoint, + Exceptions, Point, }; use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value}; @@ -12,8 +12,8 @@ use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value}; pub struct EdgeTracer<'a> { pub(super) img: &'a BitMatrix, - pub(super) p: RXingResultPoint, // current position - d: RXingResultPoint, // current direction + pub(super) p: Point, // current position + d: Point, // current direction // pub history: Option<&'a mut ByteMatrix>, // = nullptr; pub history: Option>>, @@ -35,7 +35,7 @@ pub struct EdgeTracer<'a> { // } impl BitMatrixCursor for EdgeTracer<'_> { - fn testAt(&self, p: RXingResultPoint) -> Value { + fn testAt(&self, p: Point) -> Value { if self.img.isIn(p, 0) { Value::from(self.img.get_point(p)) } 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) } @@ -59,26 +59,26 @@ impl BitMatrixCursor for EdgeTracer<'_> { self.whiteAt(self.p) } - fn front(&self) -> &RXingResultPoint { + fn front(&self) -> &Point { &self.d } - fn back(&self) -> RXingResultPoint { - RXingResultPoint { + fn back(&self) -> Point { + Point { x: -self.d.x, y: -self.d.y, } } - fn left(&self) -> RXingResultPoint { - RXingResultPoint { + fn left(&self) -> Point { + Point { x: self.d.y, y: -self.d.x, } } - fn right(&self) -> RXingResultPoint { - RXingResultPoint { + fn right(&self) -> Point { + Point { x: -self.d.y, y: self.d.x, } @@ -100,7 +100,7 @@ impl BitMatrixCursor for EdgeTracer<'_> { 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); if self.testAt(self.p + d) != 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(); } @@ -119,7 +119,7 @@ impl BitMatrixCursor for EdgeTracer<'_> { self.isIn(self.p) } - fn movedBy(self, d: RXingResultPoint) -> Self { + fn movedBy(self, d: Point) -> Self { let mut res = self; res.p += d; @@ -158,7 +158,7 @@ impl BitMatrixCursor for 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); } EdgeTracer { img: image, @@ -171,11 +171,11 @@ impl<'a> EdgeTracer<'_> { fn traceStep( &mut self, - dEdge: RXingResultPoint, + dEdge: Point, maxStepSize: i32, goodDirection: bool, ) -> Result { - let dEdge = RXingResultPoint::mainDirection(dEdge); + let dEdge = Point::mainDirection(dEdge); for breadth in 1..=(if maxStepSize == 1 { 2 } else if goodDirection { @@ -243,28 +243,28 @@ impl<'a> EdgeTracer<'_> { Ok(StepResult::OpenEnd) } - pub fn updateDirectionFromOrigin(&mut self, origin: RXingResultPoint) -> bool { + pub fn updateDirectionFromOrigin(&mut self, origin: Point) -> bool { let old_d = self.d; self.setDirection(self.p - origin); // 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; } // make sure d stays in the same quadrant to prevent an infinite loop if (self.d.x).abs() == (self.d.y).abs() { - self.d = RXingResultPoint::mainDirection(old_d) - + 0.99 * (self.d - RXingResultPoint::mainDirection(old_d)); - } else if RXingResultPoint::mainDirection(self.d) != RXingResultPoint::mainDirection(old_d) + self.d = Point::mainDirection(old_d) + + 0.99 * (self.d - Point::mainDirection(old_d)); + } else if Point::mainDirection(self.d) != Point::mainDirection(old_d) { - self.d = RXingResultPoint::mainDirection(old_d) - + 0.99 * RXingResultPoint::mainDirection(self.d); + self.d = Point::mainDirection(old_d) + + 0.99 * Point::mainDirection(self.d); } true } pub fn traceLine( &mut self, - dEdge: RXingResultPoint, + dEdge: Point, line: &mut T, ) -> Result { line.setDirectionInward(dEdge); @@ -295,7 +295,7 @@ impl<'a> EdgeTracer<'_> { pub fn traceGaps( &mut self, - dEdge: RXingResultPoint, + dEdge: Point, line: &mut T, maxStepSize: i32, 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 // 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. - if (RXingResultPoint::dot(RXingResultPoint::normalized(self.d), line.normal())) + if (Point::dot(Point::normalized(self.d), line.normal())) .abs() > 0.7 // 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 // 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 - while RXingResultPoint::distance( + while Point::distance( np, line.project( line.points() @@ -373,13 +373,13 @@ impl<'a> EdgeTracer<'_> { { np += self.d; } - self.p = RXingResultPoint::centered(np); + self.p = Point::centered(np); } else { let stepLengthInMainDir = if line.points().is_empty() { 0.0 } else { - RXingResultPoint::dot( - RXingResultPoint::mainDirection(self.d), + Point::dot( + Point::mainDirection(self.d), self.p - line .points() @@ -441,8 +441,8 @@ impl<'a> EdgeTracer<'_> { pub fn traceCorner( &mut self, - dir: &mut RXingResultPoint, - corner: &mut RXingResultPoint, + dir: &mut Point, + corner: &mut Point, ) -> Result { self.step(None); // log(p); diff --git a/src/datamatrix/detector/zxing_cpp_detector/quad.rs b/src/datamatrix/detector/zxing_cpp_detector/quad.rs index 672d9d5..26f75f4 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/quad.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/quad.rs @@ -1,7 +1,7 @@ -use crate::RXingResultPoint; +use crate::Point; #[derive(Clone, Debug)] -pub struct Quadrilateral([RXingResultPoint; 4]); +pub struct Quadrilateral([Point; 4]); impl Quadrilateral { // using Base = std::array; @@ -11,31 +11,31 @@ impl Quadrilateral { #[allow(dead_code)] 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 { // Self([tl, tr,br, bl ]) // } pub fn with_points( - tl: RXingResultPoint, - tr: RXingResultPoint, - br: RXingResultPoint, - bl: RXingResultPoint, + tl: Point, + tr: Point, + br: Point, + bl: Point, ) -> Self { Self([tl, tr, br, bl]) } - pub fn topLeft(&self) -> &RXingResultPoint { + pub fn topLeft(&self) -> &Point { &self.0[0] } //const noexcept { return at(0); } - pub fn topRight(&self) -> &RXingResultPoint { + pub fn topRight(&self) -> &Point { &self.0[1] } //const noexcept { return at(1); } - pub fn bottomRight(&self) -> &RXingResultPoint { + pub fn bottomRight(&self) -> &Point { &self.0[2] } //const noexcept { return at(2); } - pub fn bottomLeft(&self) -> &RXingResultPoint { + pub fn bottomLeft(&self) -> &Point { &self.0[3] } //const noexcept { return at(3); } @@ -43,13 +43,13 @@ impl Quadrilateral { pub fn orientation(&self) -> f64 { let centerLine = (*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; } - let centerLineF = RXingResultPoint::normalized(centerLine); + let centerLineF = Point::normalized(centerLine); f32::atan2(centerLineF.y, centerLineF.x).into() } - pub fn points(&self) -> &[RXingResultPoint] { + pub fn points(&self) -> &[Point] { &self.0 } } @@ -59,19 +59,19 @@ pub fn Rectangle(width: i32, height: i32, margin: Option) -> Quadrilateral let margin = if let Some(m) = margin { m } else { 0 }; Quadrilateral([ - RXingResultPoint { + Point { x: margin as f32, y: margin as f32, }, - RXingResultPoint { + Point { x: width as f32 - margin as f32, y: margin as f32, }, - RXingResultPoint { + Point { x: width as f32 - margin as f32, y: height as f32 - margin as f32, }, - RXingResultPoint { + Point { x: margin as f32, y: height as f32 - margin as f32, }, @@ -82,10 +82,10 @@ pub fn Rectangle(width: i32, height: i32, margin: Option) -> Quadrilateral pub fn CenteredSquare(size: i32) -> Quadrilateral { Scale( &Quadrilateral([ - RXingResultPoint { x: -1.0, y: -1.0 }, - RXingResultPoint { x: 1.0, y: -1.0 }, - RXingResultPoint { x: 1.0, y: 1.0 }, - RXingResultPoint { x: -1.0, y: 1.0 }, + Point { x: -1.0, y: -1.0 }, + Point { x: 1.0, y: -1.0 }, + Point { x: 1.0, y: 1.0 }, + Point { x: -1.0, y: 1.0 }, ]), size / 2, ) @@ -94,19 +94,19 @@ pub fn CenteredSquare(size: i32) -> Quadrilateral { #[allow(dead_code)] pub fn Line(y: i32, xStart: i32, xStop: i32) -> Quadrilateral { Quadrilateral([ - RXingResultPoint { + Point { x: xStart as f32, y: y as f32, }, - RXingResultPoint { + Point { x: xStop as f32, y: y as f32, }, - RXingResultPoint { + Point { x: xStop as f32, y: y as f32, }, - RXingResultPoint { + Point { x: xStart as f32, y: y as f32, }, @@ -162,8 +162,8 @@ pub fn Scale(q: &Quadrilateral, factor: i32) -> Quadrilateral { } #[allow(dead_code)] -pub fn Center(q: &Quadrilateral) -> RXingResultPoint { - let reduced: RXingResultPoint = q.0.iter().sum(); +pub fn Center(q: &Quadrilateral) -> Point { + let reduced: Point = q.0.iter().sum(); let size = q.0.len() as f32; reduced / size // return Reduce(q) / Size(q); @@ -186,14 +186,14 @@ pub fn RotatedCorners(q: &Quadrilateral, n: Option, mirror: Option) - } #[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 let mut pos = 0; let mut neg = 0; for i in 0..q.0.len() // 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; } else { pos += 1; diff --git a/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs b/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs index a93bc57..a788d6d 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/regression_line.rs @@ -1,9 +1,9 @@ use crate::common::Result; -use crate::RXingResultPoint; +use crate::Point; pub trait RegressionLine { - // points: Vec, - // direction_inward: RXingResultPoint, + // points: Vec, + // direction_inward: Point, // } // impl RegressionLine { @@ -12,9 +12,9 @@ pub trait RegressionLine { // PointF::value_t a = NAN, b = NAN, c = NAN; // fn intersect(&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); // 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 // } - 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 distance(&self, a: RXingResultPoint, b: RXingResultPoint) -> f32 { + fn distance(&self, a: Point, b: Point) -> f32 { crate::result_point_utils::distance(&a, &b) } @@ -60,13 +60,13 @@ pub trait RegressionLine { // 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 isValid(&self) -> bool; //const { return !std::isnan(a); } - fn normal(&self) -> RXingResultPoint; //const { return isValid() ? PointF(a, b) : _directionInward; } - fn signedDistance(&self, p: RXingResultPoint) -> f32; //const { return dot(normal(), p) - c; } - fn distance_single(&self, p: RXingResultPoint) -> f32; //const { return std::abs(signedDistance(PointF(p))); } - fn project(&self, p: RXingResultPoint) -> RXingResultPoint { + fn normal(&self) -> Point; //const { return isValid() ? PointF(a, b) : _directionInward; } + fn signedDistance(&self, p: Point) -> f32; //const { return dot(normal(), p) - c; } + fn distance_single(&self, p: Point) -> f32; //const { return std::abs(signedDistance(PointF(p))); } + fn project(&self, p: Point) -> Point { p - self.normal() * self.signedDistance(p) } @@ -77,7 +77,7 @@ pub trait RegressionLine { // a = b = c = NAN; // } - fn add(&mut self, p: RXingResultPoint) -> Result<()>; //{ + fn add(&mut self, p: Point) -> Result<()>; //{ // assert(_directionInward != PointF()); // _points.push_back(p); // if (_points.size() == 1) @@ -86,7 +86,7 @@ pub trait RegressionLine { 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_max_distance( diff --git a/src/datamatrix/detector/zxing_cpp_detector/util.rs b/src/datamatrix/detector/zxing_cpp_detector/util.rs index 0df0f36..22d87f9 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/util.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/util.rs @@ -1,5 +1,5 @@ use crate::common::Result; -use crate::{Exceptions, RXingResultPoint}; +use crate::{Exceptions, Point}; use super::{DMRegressionLine, Direction, RegressionLine}; @@ -22,14 +22,14 @@ pub fn float_max(a: T, b: T) -> T { } #[inline(always)] -pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result { +pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result { if !(l1.isValid() && l2.isValid()) { return Err(Exceptions::IllegalStateException(None)); } let d = l1.a * l2.b - l1.b * l2.a; let x = (l1.c * l2.b - l1.b * l2.c) / d; let y = (l1.a * l2.c - l1.c * l2.a) / d; - Ok(RXingResultPoint { x, y }) + Ok(Point { x, y }) } #[allow(dead_code)] diff --git a/src/decode_hints.rs b/src/decode_hints.rs index 53649a4..dbc2885 100644 --- a/src/decode_hints.rs +++ b/src/decode_hints.rs @@ -18,7 +18,7 @@ use std::collections::HashSet; -use crate::{BarcodeFormat, RXingResultPointCallback}; +use crate::{BarcodeFormat, PointCallback}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -89,8 +89,8 @@ pub enum DecodeHintType { RETURN_CODABAR_START_END, /** - * The caller needs to be notified via callback when a possible {@link RXingResultPoint} - * is found. Maps to a {@link RXingResultPointCallback}. + * The caller needs to be notified via callback when a possible {@link Point} + * is found. Maps to a {@link PointCallback}. */ NEED_RESULT_POINT_CALLBACK, @@ -198,11 +198,11 @@ pub enum DecodeHintValue { ReturnCodabarStartEnd(bool), /** - * The caller needs to be notified via callback when a possible {@link RXingResultPoint} - * is found. Maps to a {@link RXingResultPointCallback}. + * The caller needs to be notified via callback when a possible {@link Point} + * is found. Maps to a {@link PointCallback}. */ #[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. diff --git a/src/lib.rs b/src/lib.rs index c2b5cf4..06bdab0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ pub use encode_hints::*; /// Callback which is invoked when a possible result point (significant /// point in the barcode image such as a corner) is found. -pub type RXingResultPointCallback = Rc; +pub type PointCallback = Rc; mod decode_hints; pub use decode_hints::*; diff --git a/src/maxicode/detector.rs b/src/maxicode/detector.rs index 37391a4..e19dd44 100644 --- a/src/maxicode/detector.rs +++ b/src/maxicode/detector.rs @@ -6,7 +6,7 @@ use crate::{ detector::MathUtils, BitMatrix, DefaultGridSampler, DetectorRXingResult, GridSampler, Result, }, - Exceptions, RXingResultPoint, + Exceptions, Point, }; use super::MaxiCodeReader; @@ -16,7 +16,7 @@ const ROW_SCAN_SKIP: u32 = 2; #[derive(Debug)] pub struct MaxicodeDetectionResult { bits: BitMatrix, - points: Vec, + points: Vec, rotation: f32, } @@ -31,7 +31,7 @@ impl DetectorRXingResult for MaxicodeDetectionResult { &self.bits } - fn getPoints(&self) -> &[RXingResultPoint] { + fn getPoints(&self) -> &[Point] { &self.points } } @@ -387,7 +387,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result Result<([(f32, f32); 4] calculate_simple_boundary(circle, Some(image), None, false); let naive_box = [ - RXingResultPoint::new(left_boundary as f32, bottom_boundary as f32), - RXingResultPoint::new(left_boundary as f32, top_boundary as f32), - RXingResultPoint::new(right_boundary as f32, bottom_boundary as f32), - RXingResultPoint::new(right_boundary as f32, top_boundary as f32), + Point::new(left_boundary as f32, bottom_boundary as f32), + Point::new(left_boundary as f32, top_boundary as f32), + Point::new(right_boundary as f32, bottom_boundary as f32), + Point::new(right_boundary as f32, top_boundary as f32), ]; #[allow(unused_mut)] @@ -807,9 +807,9 @@ const BOTTOM_RIGHT_ORIENTATION_POS: ((u32, u32), (u32, u32), (u32, u32)) = fn attempt_rotation_box( image: &BitMatrix, circle: &mut Circle, - naive_box: &[RXingResultPoint; 4], + naive_box: &[Point; 4], center_scale: f64, -) -> Option<([RXingResultPoint; 4], f32)> { +) -> Option<([Point; 4], f32)> { // update our circle with a more accurate center point circle.calculate_high_accuracy_center(); @@ -955,10 +955,10 @@ fn attempt_rotation_box( Some(( [ - RXingResultPoint::new(new_1.0, new_1.1), - RXingResultPoint::new(new_2.0, new_2.1), - RXingResultPoint::new(new_3.0, new_3.1), - RXingResultPoint::new(new_4.0, new_4.1), + Point::new(new_1.0, new_1.1), + Point::new(new_2.0, new_2.1), + Point::new(new_3.0, new_3.1), + Point::new(new_4.0, new_4.1), ], final_rotation, )) diff --git a/src/multi/by_quadrant_reader.rs b/src/multi/by_quadrant_reader.rs index 571a79a..4d199af 100644 --- a/src/multi/by_quadrant_reader.rs +++ b/src/multi/by_quadrant_reader.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; 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, @@ -61,7 +61,7 @@ impl Reader for ByQuadrantReader { // This is a match because only NotFoundExceptions should be ignored match result { 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)); } Err(Exceptions::NotFoundException(_)) => {} @@ -74,7 +74,7 @@ impl Reader for ByQuadrantReader { // This is a match because only NotFoundExceptions should be ignored match result { 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)); } Err(Exceptions::NotFoundException(_)) => {} @@ -89,7 +89,7 @@ impl Reader for ByQuadrantReader { match result { Ok(res) => { let points = Self::makeAbsolute( - res.getRXingResultPoints(), + res.getPoints(), halfWidth as f32, halfHeight as f32, ); @@ -105,7 +105,7 @@ impl Reader for ByQuadrantReader { let result = self.0.decode_with_hints(&mut center, hints)?; let points = Self::makeAbsolute( - result.getRXingResultPoints(), + result.getPoints(), quarterWidth as f32, quarterHeight as f32, ); @@ -123,15 +123,15 @@ impl ByQuadrantReader { } fn makeAbsolute( - points: &[RXingResultPoint], + points: &[Point], leftOffset: f32, topOffset: f32, - ) -> Vec { + ) -> Vec { // let mut result = Vec::new(); // if !points.is_empty() { // // for relative in points { - // // result.push(RXingResultPoint::new( + // // result.push(Point::new( // // relative.getX() + leftOffset, // // relative.getY() + topOffset, // // )); @@ -141,7 +141,7 @@ impl ByQuadrantReader { points .iter() .map(|relative| { - RXingResultPoint::new(relative.getX() + leftOffset, relative.getY() + topOffset) + Point::new(relative.getX() + leftOffset, relative.getY() + topOffset) }) .collect() } diff --git a/src/multi/generic_multiple_barcode_reader.rs b/src/multi/generic_multiple_barcode_reader.rs index 2574dd7..acdbd89 100644 --- a/src/multi/generic_multiple_barcode_reader.rs +++ b/src/multi/generic_multiple_barcode_reader.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use crate::{ common::Result, BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResult, - RXingResultPoint, Reader, ResultPoint, + Point, Reader, ResultPoint, }; use super::MultipleBarcodeReader; @@ -26,7 +26,7 @@ use super::MultipleBarcodeReader; /** *

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 - * {@link RXingResultPoint}s are scanned, recursively.

+ * {@link Point}s are scanned, recursively.

* *

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 @@ -95,10 +95,10 @@ impl GenericMultipleBarcodeReader { } } - let resultPoints = result.getRXingResultPoints().clone(); + let resultPoints = result.getPoints().clone(); if !alreadyFound { - results.push(Self::translateRXingResultPoints(result, xOffset, yOffset)); + results.push(Self::translatePoints(result, xOffset, yOffset)); } if resultPoints.is_empty() { @@ -177,25 +177,25 @@ impl GenericMultipleBarcodeReader { } } - fn translateRXingResultPoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult { - let oldRXingResultPoints = result.getRXingResultPoints(); - if oldRXingResultPoints.is_empty() { + fn translatePoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult { + let oldPoints = result.getPoints(); + if oldPoints.is_empty() { return result; } - let newRXingResultPoints: Vec = oldRXingResultPoints + let newPoints: Vec = oldPoints .iter() .map(|oldPoint| { - RXingResultPoint::new( + Point::new( oldPoint.getX() + xOffset as f32, oldPoint.getY() + yOffset as f32, ) }) .collect(); - // let mut newRXingResultPoints = Vec::with_capacity(oldRXingResultPoints.len()); - // for oldPoint in oldRXingResultPoints { - // newRXingResultPoints.push(RXingResultPoint::new( + // let mut newPoints = Vec::with_capacity(oldPoints.len()); + // for oldPoint in oldPoints { + // newPoints.push(Point::new( // oldPoint.getX() + xOffset as f32, // oldPoint.getY() + yOffset as f32, // )); @@ -204,7 +204,7 @@ impl GenericMultipleBarcodeReader { result.getText(), result.getRawBytes().clone(), result.getNumBits(), - newRXingResultPoints, + newPoints, *result.getBarcodeFormat(), result.getTimestamp(), ); diff --git a/src/multi/qrcode/detector/multi_finder_pattern_finder.rs b/src/multi/qrcode/detector/multi_finder_pattern_finder.rs index d313714..5d83532 100644 --- a/src/multi/qrcode/detector/multi_finder_pattern_finder.rs +++ b/src/multi/qrcode/detector/multi_finder_pattern_finder.rs @@ -20,7 +20,7 @@ use crate::{ common::{BitMatrix, Result}, qrcode::detector::{FinderPattern, FinderPatternFinder, FinderPatternInfo}, result_point_utils, DecodeHintType, DecodingHintDictionary, Exceptions, - RXingResultPointCallback, + PointCallback, }; // max. legal count of modules per QR code edge (177) @@ -68,7 +68,7 @@ impl<'a> MultiFinderPatternFinder<'_> { pub fn new( image: &'a BitMatrix, - resultPointCallback: Option, + resultPointCallback: Option, ) -> MultiFinderPatternFinder<'a> { MultiFinderPatternFinder(FinderPatternFinder::with_callback( image, diff --git a/src/oned/coda_bar_reader.rs b/src/oned/coda_bar_reader.rs index c154e52..eed8a89 100644 --- a/src/oned/coda_bar_reader.rs +++ b/src/oned/coda_bar_reader.rs @@ -171,8 +171,8 @@ impl OneDReader for CodaBarReader { &self.decodeRowRXingResult, Vec::new(), vec![ - RXingResultPoint::new(left, rowNumber as f32), - RXingResultPoint::new(right, rowNumber as f32), + Point::new(left, rowNumber as f32), + Point::new(right, rowNumber as f32), ], BarcodeFormat::CODABAR, ); diff --git a/src/oned/code_128_reader.rs b/src/oned/code_128_reader.rs index 9898a56..2978606 100644 --- a/src/oned/code_128_reader.rs +++ b/src/oned/code_128_reader.rs @@ -342,8 +342,8 @@ impl OneDReader for Code128Reader { &result, rawBytes, vec![ - RXingResultPoint::new(left, rowNumber as f32), - RXingResultPoint::new(right, rowNumber as f32), + Point::new(left, rowNumber as f32), + Point::new(right, rowNumber as f32), ], BarcodeFormat::CODE_128, ); diff --git a/src/oned/code_39_reader.rs b/src/oned/code_39_reader.rs index 56060bd..04b9aaa 100644 --- a/src/oned/code_39_reader.rs +++ b/src/oned/code_39_reader.rs @@ -134,8 +134,8 @@ impl OneDReader for Code39Reader { &resultString, Vec::new(), vec![ - RXingResultPoint::new(left, rowNumber as f32), - RXingResultPoint::new(right, rowNumber as f32), + Point::new(left, rowNumber as f32), + Point::new(right, rowNumber as f32), ], BarcodeFormat::CODE_39, ); diff --git a/src/oned/code_93_reader.rs b/src/oned/code_93_reader.rs index 415cb80..d2e890c 100644 --- a/src/oned/code_93_reader.rs +++ b/src/oned/code_93_reader.rs @@ -117,8 +117,8 @@ impl OneDReader for Code93Reader { &resultString, Vec::new(), vec![ - RXingResultPoint::new(left, rowNumber as f32), - RXingResultPoint::new(right, rowNumber as f32), + Point::new(left, rowNumber as f32), + Point::new(right, rowNumber as f32), ], BarcodeFormat::CODE_93, ); diff --git a/src/oned/itf_reader.rs b/src/oned/itf_reader.rs index 41de313..fb54549 100644 --- a/src/oned/itf_reader.rs +++ b/src/oned/itf_reader.rs @@ -150,8 +150,8 @@ impl OneDReader for ITFReader { &resultString, Vec::new(), // no natural byte representation for these barcodes vec![ - RXingResultPoint::new(startRange[1] as f32, rowNumber as f32), - RXingResultPoint::new(endRange[0] as f32, rowNumber as f32), + Point::new(startRange[1] as f32, rowNumber as f32), + Point::new(endRange[0] as f32, rowNumber as f32), ], BarcodeFormat::ITF, ); diff --git a/src/oned/multi_format_one_d_reader.rs b/src/oned/multi_format_one_d_reader.rs index b0c7eb4..d621c8b 100644 --- a/src/oned/multi_format_one_d_reader.rs +++ b/src/oned/multi_format_one_d_reader.rs @@ -157,8 +157,8 @@ impl Reader for MultiFormatOneDReader { ); // Update result points let height = rotatedImage.getHeight(); - let total_points = result.getRXingResultPoints().len(); - let points = result.getRXingResultPointsMut(); + let total_points = result.getPoints().len(); + let points = result.getPointsMut(); for point in points.iter_mut().take(total_points) { std::mem::swap(&mut point.x, &mut point.y); point.x = height as f32 - point.x - 1.0; diff --git a/src/oned/multi_format_upc_ean_reader.rs b/src/oned/multi_format_upc_ean_reader.rs index fb8b817..31ef40a 100644 --- a/src/oned/multi_format_upc_ean_reader.rs +++ b/src/oned/multi_format_upc_ean_reader.rs @@ -105,7 +105,7 @@ impl MultiFormatUPCEANReader { let mut resultUPCA = RXingResult::new( &result.getText()[1..], result.getRawBytes().clone(), - result.getRXingResultPoints().clone(), + result.getPoints().clone(), BarcodeFormat::UPC_A, ); resultUPCA.putAllMetadata(result.getRXingResultMetadata().clone()); @@ -189,8 +189,8 @@ impl Reader for MultiFormatUPCEANReader { ); // Update result points let height = rotatedImage.getHeight(); - let total_points = result.getRXingResultPoints().len(); - let points = result.getRXingResultPointsMut(); + let total_points = result.getPoints().len(); + let points = result.getPointsMut(); for point in points.iter_mut().take(total_points) { std::mem::swap(&mut point.x, &mut point.y); point.x = height as f32 - point.x - 1.0; diff --git a/src/oned/one_d_reader.rs b/src/oned/one_d_reader.rs index 091ed1a..9dab307 100644 --- a/src/oned/one_d_reader.rs +++ b/src/oned/one_d_reader.rs @@ -17,7 +17,7 @@ use crate::{ common::{BitArray, Result}, 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), ); // And remember to flip the result points horizontally. - let points = result.getRXingResultPointsMut(); + let points = result.getPointsMut(); if !points.is_empty() && points.len() >= 2 { - points[0] = RXingResultPoint::new( + points[0] = Point::new( width as f32 - points[0].getX() - 1.0, points[0].getY(), ); - points[1] = RXingResultPoint::new( + points[1] = Point::new( width as f32 - points[1].getX() - 1.0, points[1].getY(), ); diff --git a/src/oned/rss/expanded/rss_expanded_reader.rs b/src/oned/rss/expanded/rss_expanded_reader.rs index 62a94a3..2307343 100644 --- a/src/oned/rss/expanded/rss_expanded_reader.rs +++ b/src/oned/rss/expanded/rss_expanded_reader.rs @@ -215,8 +215,8 @@ impl Reader for RSSExpandedReader { // Update result points let height = rotatedImage.getHeight(); - let total_points = result.getRXingResultPoints().len(); - let points = result.getRXingResultPointsMut(); + let total_points = result.getPoints().len(); + let points = result.getPointsMut(); for point in points.iter_mut().take(total_points) { std::mem::swap(&mut point.x, &mut point.y); point.x = height as f32 - point.x - 1.0; @@ -545,14 +545,14 @@ impl RSSExpandedReader { .getFinderPattern() .as_ref() .ok_or(Exceptions::IllegalStateException(None))? - .getRXingResultPoints(); + .getPoints(); let lastPoints = pairs .last() .ok_or(Exceptions::IndexOutOfBoundsException(None))? .getFinderPattern() .as_ref() .ok_or(Exceptions::IllegalStateException(None))? - .getRXingResultPoints(); + .getPoints(); let mut result = RXingResult::new( &resultingString, diff --git a/src/oned/rss/finder_pattern.rs b/src/oned/rss/finder_pattern.rs index 6578e95..1854fe7 100644 --- a/src/oned/rss/finder_pattern.rs +++ b/src/oned/rss/finder_pattern.rs @@ -16,7 +16,7 @@ use std::hash::Hash; -use crate::RXingResultPoint; +use crate::Point; /** * Encapsulates an RSS barcode finder pattern, including its start/end position and row. @@ -25,7 +25,7 @@ use crate::RXingResultPoint; pub struct FinderPattern { value: u32, startEnd: [usize; 2], - resultPoints: Vec, + resultPoints: Vec, } impl FinderPattern { @@ -34,8 +34,8 @@ impl FinderPattern { value, startEnd, resultPoints: vec![ - RXingResultPoint::new(start as f32, rowNumber as f32), - RXingResultPoint::new(end as f32, rowNumber as f32), + Point::new(start as f32, rowNumber as f32), + Point::new(end as f32, rowNumber as f32), ], } } @@ -53,7 +53,7 @@ impl FinderPattern { &mut self.startEnd } - pub fn getRXingResultPoints(&self) -> &[RXingResultPoint] { + pub fn getPoints(&self) -> &[Point] { &self.resultPoints } } diff --git a/src/oned/rss/rss_14_reader.rs b/src/oned/rss/rss_14_reader.rs index 520a32c..f5048ce 100644 --- a/src/oned/rss/rss_14_reader.rs +++ b/src/oned/rss/rss_14_reader.rs @@ -20,7 +20,7 @@ use crate::{ common::{BitArray, Result}, oned::{one_d_reader, OneDReader}, BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, - RXingResult, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, + RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Point, Reader, }; use super::{ @@ -114,8 +114,8 @@ impl Reader for RSS14Reader { ); // Update result points let height = rotatedImage.getHeight(); - let total_points = result.getRXingResultPoints().len(); - let points = result.getRXingResultPointsMut(); + let total_points = result.getPoints().len(); + let points = result.getPointsMut(); for point in points.iter_mut().take(total_points) { std::mem::swap(&mut point.x, &mut point.y); point.x = height as f32 - point.x - 1.0 @@ -209,8 +209,8 @@ impl RSS14Reader { } buffer.push_str(&checkDigit.to_string()); - let leftPoints = leftPair.getFinderPattern().getRXingResultPoints(); - let rightPoints = rightPair.getFinderPattern().getRXingResultPoints(); + let leftPoints = leftPair.getFinderPattern().getPoints(); + let rightPoints = rightPair.getFinderPattern().getPoints(); let mut result = RXingResult::new( &buffer, Vec::new(), @@ -259,7 +259,7 @@ impl RSS14Reader { // row is actually reversed 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)?; diff --git a/src/oned/upc_a_reader.rs b/src/oned/upc_a_reader.rs index 58d0eb1..4f5eefa 100644 --- a/src/oned/upc_a_reader.rs +++ b/src/oned/upc_a_reader.rs @@ -94,7 +94,7 @@ impl UPCAReader { let mut upcaRXingResult = RXingResult::new( stripped_text, Vec::new(), - result.getRXingResultPoints().to_vec(), + result.getPoints().to_vec(), BarcodeFormat::UPC_A, ); upcaRXingResult.putAllMetadata(result.getRXingResultMetadata().clone()); diff --git a/src/oned/upc_ean_extension_2_support.rs b/src/oned/upc_ean_extension_2_support.rs index 6dd85d0..f3ed755 100644 --- a/src/oned/upc_ean_extension_2_support.rs +++ b/src/oned/upc_ean_extension_2_support.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use crate::{ common::{BitArray, Result}, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, - RXingResultPoint, + Point, }; use super::{upc_ean_reader, UPCEANReader, STAND_IN}; @@ -49,11 +49,11 @@ impl UPCEANExtension2Support { &resultString, Vec::new(), vec![ - RXingResultPoint::new( + Point::new( (extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0, rowNumber as f32, ), - RXingResultPoint::new(end as f32, rowNumber as f32), + Point::new(end as f32, rowNumber as f32), ], BarcodeFormat::UPC_EAN_EXTENSION, ); diff --git a/src/oned/upc_ean_extension_5_support.rs b/src/oned/upc_ean_extension_5_support.rs index db147fb..16b732c 100644 --- a/src/oned/upc_ean_extension_5_support.rs +++ b/src/oned/upc_ean_extension_5_support.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use crate::{ common::{BitArray, Result}, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, - RXingResultPoint, + Point, }; use super::{upc_ean_reader, UPCEANReader, STAND_IN}; @@ -51,11 +51,11 @@ impl UPCEANExtension5Support { &resultString, Vec::new(), vec![ - RXingResultPoint::new( + Point::new( (extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0, rowNumber as f32, ), - RXingResultPoint::new(end as f32, rowNumber as f32), + Point::new(end as f32, rowNumber as f32), ], BarcodeFormat::UPC_EAN_EXTENSION, ); diff --git a/src/oned/upc_ean_reader.rs b/src/oned/upc_ean_reader.rs index 2fca4bc..1a641b4 100644 --- a/src/oned/upc_ean_reader.rs +++ b/src/oned/upc_ean_reader.rs @@ -17,7 +17,7 @@ use crate::{ common::{BitArray, Result}, BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult, - RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, + RXingResultMetadataType, RXingResultMetadataValue, Point, Reader, }; use super::{one_d_reader, EANManufacturerOrgSupport, OneDReader, UPCEANExtensionSupport}; @@ -156,7 +156,7 @@ pub trait UPCEANReader: OneDReader { let mut symbologyIdentifier = 0; if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { - cb(&RXingResultPoint::new( + cb(&Point::new( (startGuardRange[0] + startGuardRange[1]) as f32 / 2.0, rowNumber as f32, )); @@ -166,13 +166,13 @@ pub trait UPCEANReader: OneDReader { let endStart = self.decodeMiddle(row, startGuardRange, &mut result)?; 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)?; if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { - cb(&RXingResultPoint::new( + cb(&Point::new( (endRange[0] + endRange[1]) as f32 / 2.0, rowNumber as f32, )); @@ -204,8 +204,8 @@ pub trait UPCEANReader: OneDReader { &resultString, Vec::new(), // no natural byte representation for these barcodes vec![ - RXingResultPoint::new(left, rowNumber as f32), - RXingResultPoint::new(right, rowNumber as f32), + Point::new(left, rowNumber as f32), + Point::new(right, rowNumber as f32), ], format, ); @@ -224,7 +224,7 @@ pub trait UPCEANReader: OneDReader { ); decodeRXingResult.putAllMetadata(extensionRXingResult.getRXingResultMetadata().clone()); decodeRXingResult - .addRXingResultPoints(&mut extensionRXingResult.getRXingResultPoints().clone()); + .addPoints(&mut extensionRXingResult.getPoints().clone()); extensionLength = extensionRXingResult.getText().chars().count(); Ok(()) }; diff --git a/src/pdf417/decoder/bounding_box.rs b/src/pdf417/decoder/bounding_box.rs index 19bc668..8eef760 100644 --- a/src/pdf417/decoder/bounding_box.rs +++ b/src/pdf417/decoder/bounding_box.rs @@ -18,7 +18,7 @@ use std::rc::Rc; use crate::{ common::{BitMatrix, Result}, - Exceptions, RXingResultPoint, ResultPoint, + Exceptions, Point, ResultPoint, }; /** @@ -27,10 +27,10 @@ use crate::{ #[derive(Clone)] pub struct BoundingBox { image: Rc, - topLeft: RXingResultPoint, - bottomLeft: RXingResultPoint, - topRight: RXingResultPoint, - bottomRight: RXingResultPoint, + topLeft: Point, + bottomLeft: Point, + topRight: Point, + bottomRight: Point, minX: u32, maxX: u32, minY: u32, @@ -39,10 +39,10 @@ pub struct BoundingBox { impl BoundingBox { pub fn new( image: Rc, - topLeft: Option, - bottomLeft: Option, - topRight: Option, - bottomRight: Option, + topLeft: Option, + bottomLeft: Option, + topRight: Option, + bottomRight: Option, ) -> Result { let leftUnspecified = topLeft.is_none() || bottomLeft.is_none(); let rightUnspecified = topRight.is_none() || bottomRight.is_none(); @@ -58,14 +58,14 @@ impl BoundingBox { if leftUnspecified { newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?; - newTopLeft = RXingResultPoint::new(0.0, newTopRight.getY()); - newBottomLeft = RXingResultPoint::new(0.0, newBottomRight.getY()); + newTopLeft = Point::new(0.0, newTopRight.getY()); + newBottomLeft = Point::new(0.0, newBottomRight.getY()); } else if rightUnspecified { newTopLeft = topLeft.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 = - RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY()); + Point::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY()); } else { newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?; newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; @@ -145,7 +145,7 @@ impl BoundingBox { if newMinY < 0.0 { newMinY = 0.0; } - let newTop = RXingResultPoint::new(top.getX(), newMinY); + let newTop = Point::new(top.getX(), newMinY); if isLeft { newTopLeft = newTop; } else { @@ -163,7 +163,7 @@ impl BoundingBox { if newMaxY >= self.image.getHeight() { 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 { newBottomLeft = newBottom; } else { @@ -196,19 +196,19 @@ impl BoundingBox { self.maxY } - pub fn getTopLeft(&self) -> &RXingResultPoint { + pub fn getTopLeft(&self) -> &Point { &self.topLeft } - pub fn getTopRight(&self) -> &RXingResultPoint { + pub fn getTopRight(&self) -> &Point { &self.topRight } - pub fn getBottomLeft(&self) -> &RXingResultPoint { + pub fn getBottomLeft(&self) -> &Point { &self.bottomLeft } - pub fn getBottomRight(&self) -> &RXingResultPoint { + pub fn getBottomRight(&self) -> &Point { &self.bottomRight } } diff --git a/src/pdf417/decoder/pdf_417_scanning_decoder.rs b/src/pdf417/decoder/pdf_417_scanning_decoder.rs index 971ea14..b808a8d 100644 --- a/src/pdf417/decoder/pdf_417_scanning_decoder.rs +++ b/src/pdf417/decoder/pdf_417_scanning_decoder.rs @@ -19,7 +19,7 @@ use std::rc::Rc; use crate::{ common::{BitMatrix, DecoderRXingResult, Result}, pdf417::pdf_417_common, - Exceptions, RXingResultPoint, ResultPoint, + Exceptions, Point, ResultPoint, }; 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. pub fn decode( image: &BitMatrix, - imageTopLeft: Option, - imageBottomLeft: Option, - imageTopRight: Option, - imageBottomRight: Option, + imageTopLeft: Option, + imageBottomLeft: Option, + imageTopRight: Option, + imageBottomRight: Option, minCodewordWidth: u32, maxCodewordWidth: u32, ) -> Result { @@ -358,7 +358,7 @@ fn getBarcodeMetadata( fn getRowIndicatorColumn<'a>( image: &BitMatrix, boundingBox: Rc, - startPoint: RXingResultPoint, + startPoint: Point, leftToRight: bool, minCodewordWidth: u32, maxCodewordWidth: u32, diff --git a/src/pdf417/detector/pdf_417_detector.rs b/src/pdf417/detector/pdf_417_detector.rs index 0e007c0..501fc15 100644 --- a/src/pdf417/detector/pdf_417_detector.rs +++ b/src/pdf417/detector/pdf_417_detector.rs @@ -16,7 +16,7 @@ use crate::{ common::{BitMatrix, Result}, - BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResultPoint, ResultPoint, + BinaryBitmap, DecodingHintDictionary, Exceptions, Point, ResultPoint, }; use std::borrow::Cow; @@ -116,10 +116,10 @@ fn applyRotation(matrix: &BitMatrix, rotation: u32) -> Result> { * @param multiple if true, then the image is searched for multiple codes. If false, then at most one code will * be found and returned * @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; 8]>> { - let mut barcodeCoordinates: Vec<[Option; 8]> = Vec::new(); +pub fn detect(multiple: bool, bitMatrix: &BitMatrix) -> Option; 8]>> { + let mut barcodeCoordinates: Vec<[Option; 8]> = Vec::new(); let mut row = 0; let mut column = 0; let mut foundBarcodeInRow = false; @@ -183,13 +183,13 @@ fn findVertices( matrix: &BitMatrix, startRow: u32, startColumn: u32, -) -> Option<[Option; 8]> { +) -> Option<[Option; 8]> { let height = matrix.getHeight(); let width = matrix.getWidth(); let mut startRow = startRow; let mut startColumn = startColumn; - let mut result = [None::; 8]; //RXingResultPoint[8]; + let mut result = [None::; 8]; //Point[8]; copyToRXingResult( &mut result, &findRowsWithPattern(matrix, height, width, startRow, startColumn, &START_PATTERN)?, @@ -210,8 +210,8 @@ fn findVertices( } fn copyToRXingResult( - result: &mut [Option], - tmpRXingResult: &[Option], + result: &mut [Option], + tmpRXingResult: &[Option], destinationIndexes: &[u32], ) { for i in 0..destinationIndexes.len() { @@ -226,7 +226,7 @@ fn findRowsWithPattern( startRow: u32, startColumn: u32, pattern: &[u32], -) -> Option<[Option; 4]> { +) -> Option<[Option; 4]> { let mut startRow = startRow; let mut result = [None; 4]; let mut found = false; @@ -249,11 +249,11 @@ fn findRowsWithPattern( break; } } - result[0] = Some(RXingResultPoint::new( + result[0] = Some(Point::new( loc_store.as_ref()?[0] as f32, startRow as f32, )); - result[1] = Some(RXingResultPoint::new( + result[1] = Some(Point::new( loc_store.as_ref()?[1] as f32, startRow as f32, )); @@ -304,11 +304,11 @@ fn findRowsWithPattern( stopRow += 1; } stopRow -= skippedRowCount + 1; - result[2] = Some(RXingResultPoint::new( + result[2] = Some(Point::new( previousRowLoc[0] as f32, stopRow as f32, )); - result[3] = Some(RXingResultPoint::new( + result[3] = Some(Point::new( previousRowLoc[1] as f32, stopRow as f32, )); diff --git a/src/pdf417/detector/pdf_417_detector_result.rs b/src/pdf417/detector/pdf_417_detector_result.rs index b3f67ad..2d4ee2c 100644 --- a/src/pdf417/detector/pdf_417_detector_result.rs +++ b/src/pdf417/detector/pdf_417_detector_result.rs @@ -14,21 +14,21 @@ * limitations under the License. */ -use crate::{common::BitMatrix, RXingResultPoint}; +use crate::{common::BitMatrix, Point}; /** * @author Guenther Grau */ pub struct PDF417DetectorRXingResult { bits: BitMatrix, - points: Vec<[Option; 8]>, + points: Vec<[Option; 8]>, rotation: u32, } impl PDF417DetectorRXingResult { pub fn with_rotation( bits: BitMatrix, - points: Vec<[Option; 8]>, + points: Vec<[Option; 8]>, rotation: u32, ) -> Self { Self { @@ -38,7 +38,7 @@ impl PDF417DetectorRXingResult { } } - pub fn new(bits: BitMatrix, points: Vec<[Option; 8]>) -> Self { + pub fn new(bits: BitMatrix, points: Vec<[Option; 8]>) -> Self { Self::with_rotation(bits, points, 0) } @@ -46,7 +46,7 @@ impl PDF417DetectorRXingResult { &self.bits } - pub fn getPoints(&self) -> &Vec<[Option; 8]> { + pub fn getPoints(&self) -> &Vec<[Option; 8]> { &self.points } diff --git a/src/pdf417/pdf_417_reader.rs b/src/pdf417/pdf_417_reader.rs index b99280d..8ad3d91 100644 --- a/src/pdf417/pdf_417_reader.rs +++ b/src/pdf417/pdf_417_reader.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use crate::{ common::Result, multi::MultipleBarcodeReader, BarcodeFormat, BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResult, RXingResultMetadataType, - RXingResultMetadataValue, RXingResultPoint, Reader, ResultPoint, + RXingResultMetadataValue, Point, Reader, ResultPoint, }; use super::{ @@ -151,7 +151,7 @@ impl PDF417Reader { Ok(results) } - fn getMaxWidth(p1: &Option, p2: &Option) -> u64 { + fn getMaxWidth(p1: &Option, p2: &Option) -> u64 { if let (Some(p1), Some(p2)) = (p1, p2) { (p1.getX() - p2.getX()).abs() as u64 } else { @@ -159,7 +159,7 @@ impl PDF417Reader { } } - fn getMinWidth(p1: &Option, p2: &Option) -> u64 { + fn getMinWidth(p1: &Option, p2: &Option) -> u64 { if let (Some(p1), Some(p2)) = (p1, p2) { (p1.getX() - p2.getX()).abs() as u64 } else { @@ -167,7 +167,7 @@ impl PDF417Reader { } } - fn getMaxCodewordWidth(p: &[Option]) -> u32 { + fn getMaxCodewordWidth(p: &[Option]) -> u32 { Self::getMaxWidth(&p[0], &p[4]) .max( Self::getMaxWidth(&p[6], &p[2]) * pdf_417_common::MODULES_IN_CODEWORD as u64 @@ -179,7 +179,7 @@ impl PDF417Reader { )) as u32 } - fn getMinCodewordWidth(p: &[Option]) -> u32 { + fn getMinCodewordWidth(p: &[Option]) -> u32 { Self::getMinWidth(&p[0], &p[4]) .min( Self::getMinWidth(&p[6], &p[2]) * pdf_417_common::MODULES_IN_CODEWORD as u64 diff --git a/src/qrcode/decoder/qr_code_decoder_meta_data.rs b/src/qrcode/decoder/qr_code_decoder_meta_data.rs index 503fd84..1bc853d 100644 --- a/src/qrcode/decoder/qr_code_decoder_meta_data.rs +++ b/src/qrcode/decoder/qr_code_decoder_meta_data.rs @@ -14,7 +14,7 @@ * 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 @@ -41,7 +41,7 @@ impl QRCodeDecoderMetaData { * * @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 { return; } diff --git a/src/qrcode/detector/alignment_pattern.rs b/src/qrcode/detector/alignment_pattern.rs index 91934a5..5f937e7 100644 --- a/src/qrcode/detector/alignment_pattern.rs +++ b/src/qrcode/detector/alignment_pattern.rs @@ -14,9 +14,9 @@ * limitations under the License. */ -//RXingResultPoint +//Point -use crate::{RXingResultPoint, ResultPoint}; +use crate::{Point, ResultPoint}; /** *

Encapsulates an alignment pattern, which are the smaller square patterns found in @@ -39,8 +39,8 @@ impl ResultPoint for AlignmentPattern { self.point.1 } - fn into_rxing_result_point(self) -> RXingResultPoint { - RXingResultPoint { + fn into_rxing_result_point(self) -> Point { + Point { x: self.point.0, y: self.point.1, } diff --git a/src/qrcode/detector/alignment_pattern_finder.rs b/src/qrcode/detector/alignment_pattern_finder.rs index c10700e..8982dc3 100644 --- a/src/qrcode/detector/alignment_pattern_finder.rs +++ b/src/qrcode/detector/alignment_pattern_finder.rs @@ -16,7 +16,7 @@ use crate::{ common::{BitMatrix, Result}, - Exceptions, RXingResultPointCallback, + Exceptions, PointCallback, }; use super::AlignmentPattern; @@ -44,7 +44,7 @@ pub struct AlignmentPatternFinder { height: u32, moduleSize: f32, crossCheckStateCount: [u32; 3], - resultPointCallback: Option, + resultPointCallback: Option, } impl AlignmentPatternFinder { @@ -65,7 +65,7 @@ impl AlignmentPatternFinder { width: u32, height: u32, moduleSize: f32, - resultPointCallback: Option, + resultPointCallback: Option, ) -> Self { Self { image, diff --git a/src/qrcode/detector/finder_pattern.rs b/src/qrcode/detector/finder_pattern.rs index 3d931e9..447ee48 100644 --- a/src/qrcode/detector/finder_pattern.rs +++ b/src/qrcode/detector/finder_pattern.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use crate::{RXingResultPoint, ResultPoint}; +use crate::{Point, ResultPoint}; /** *

Encapsulates a finder pattern, which are the three square patterns found in @@ -39,8 +39,8 @@ impl ResultPoint for FinderPattern { self.point.1 } - fn into_rxing_result_point(self) -> RXingResultPoint { - RXingResultPoint { + fn into_rxing_result_point(self) -> Point { + Point { x: self.point.0, y: self.point.1, } diff --git a/src/qrcode/detector/finder_pattern_finder.rs b/src/qrcode/detector/finder_pattern_finder.rs index c8ba971..1f1801d 100755 --- a/src/qrcode/detector/finder_pattern_finder.rs +++ b/src/qrcode/detector/finder_pattern_finder.rs @@ -17,7 +17,7 @@ use crate::{ common::{BitMatrix, Result}, result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, - RXingResultPointCallback, ResultPoint, + PointCallback, ResultPoint, }; use super::{FinderPattern, FinderPatternInfo}; @@ -35,7 +35,7 @@ pub struct FinderPatternFinder<'a> { possibleCenters: Vec, hasSkipped: bool, crossCheckStateCount: [u32; 5], - resultPointCallback: Option, + resultPointCallback: Option, } impl<'a> FinderPatternFinder<'_> { pub const CENTER_QUORUM: usize = 2; @@ -53,7 +53,7 @@ impl<'a> FinderPatternFinder<'_> { pub fn with_callback( image: &'a BitMatrix, - resultPointCallback: Option, + resultPointCallback: Option, ) -> FinderPatternFinder<'a> { FinderPatternFinder { image, diff --git a/src/qrcode/detector/qrcode_detector.rs b/src/qrcode/detector/qrcode_detector.rs index 3985426..ccfc746 100644 --- a/src/qrcode/detector/qrcode_detector.rs +++ b/src/qrcode/detector/qrcode_detector.rs @@ -23,7 +23,7 @@ use crate::{ }, qrcode::decoder::Version, result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, - RXingResultPointCallback, ResultPoint, + PointCallback, ResultPoint, }; use super::{ @@ -39,7 +39,7 @@ use super::{ */ pub struct Detector<'a> { image: &'a BitMatrix, - resultPointCallback: Option, + resultPointCallback: Option, } impl<'a> Detector<'_> { @@ -54,7 +54,7 @@ impl<'a> Detector<'_> { self.image } - pub fn getRXingResultPointCallback(&self) -> &Option { + pub fn getPointCallback(&self) -> &Option { &self.resultPointCallback } diff --git a/src/qrcode/detector/qrcode_detector_result.rs b/src/qrcode/detector/qrcode_detector_result.rs index fa9070f..f3c3f30 100644 --- a/src/qrcode/detector/qrcode_detector_result.rs +++ b/src/qrcode/detector/qrcode_detector_result.rs @@ -1,15 +1,15 @@ use crate::{ common::{BitMatrix, DetectorRXingResult}, - RXingResultPoint, + Point, }; pub struct QRCodeDetectorResult { bit_source: BitMatrix, - result_points: Vec, + result_points: Vec, } impl QRCodeDetectorResult { - pub fn new(bit_source: BitMatrix, result_points: Vec) -> Self { + pub fn new(bit_source: BitMatrix, result_points: Vec) -> Self { Self { bit_source, result_points, @@ -22,7 +22,7 @@ impl DetectorRXingResult for QRCodeDetectorResult { &self.bit_source } - fn getPoints(&self) -> &[crate::RXingResultPoint] { + fn getPoints(&self) -> &[crate::Point] { &self.result_points } } diff --git a/src/qrcode/qr_code_reader.rs b/src/qrcode/qr_code_reader.rs index 2e9e5a9..f213d62 100644 --- a/src/qrcode/qr_code_reader.rs +++ b/src/qrcode/qr_code_reader.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use crate::{ common::{BitMatrix, DecoderRXingResult, DetectorRXingResult, Result}, BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult, - RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, + RXingResultMetadataType, RXingResultMetadataValue, Point, Reader, }; use super::{ @@ -36,7 +36,7 @@ use super::{ 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 { @@ -58,7 +58,7 @@ impl Reader for QRCodeReader { hints: &crate::DecodingHintDictionary, ) -> Result { let decoderRXingResult: DecoderRXingResult; - let mut points: Vec; + let mut points: Vec; if matches!( hints.get(&DecodeHintType::PURE_BARCODE), Some(DecodeHintValue::PureBarcode(true)) diff --git a/src/result_point.rs b/src/result_point.rs index 256a6e5..2a3700a 100644 --- a/src/result_point.rs +++ b/src/result_point.rs @@ -16,10 +16,10 @@ //package com.google.zxing; -use crate::RXingResultPoint; +use crate::Point; pub trait ResultPoint { fn getX(&self) -> f32; fn getY(&self) -> f32; - fn into_rxing_result_point(self) -> RXingResultPoint; + fn into_rxing_result_point(self) -> Point; } diff --git a/src/result_point_utils.rs b/src/result_point_utils.rs index 39d7755..909b566 100644 --- a/src/result_point_utils.rs +++ b/src/result_point_utils.rs @@ -1,10 +1,10 @@ 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. * - * @param patterns array of three {@code RXingResultPoint} to order + * @param patterns array of three {@code Point} to order */ pub fn orderBestPatterns(patterns: &mut [T; 3]) { // Find distances between pattern centers diff --git a/src/rxing_result.rs b/src/rxing_result.rs index 5a72a84..7fde804 100644 --- a/src/rxing_result.rs +++ b/src/rxing_result.rs @@ -16,7 +16,7 @@ use std::{collections::HashMap, fmt}; -use crate::{BarcodeFormat, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint}; +use crate::{BarcodeFormat, RXingResultMetadataType, RXingResultMetadataValue, Point}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -32,7 +32,7 @@ pub struct RXingResult { text: String, rawBytes: Vec, numBits: usize, - resultPoints: Vec, + resultPoints: Vec, format: BarcodeFormat, resultMetadata: HashMap, timestamp: u128, @@ -41,7 +41,7 @@ impl RXingResult { pub fn new( text: &str, rawBytes: Vec, - resultPoints: Vec, + resultPoints: Vec, format: BarcodeFormat, ) -> Self { Self::new_timestamp( @@ -56,7 +56,7 @@ impl RXingResult { pub fn new_timestamp( text: &str, rawBytes: Vec, - resultPoints: Vec, + resultPoints: Vec, format: BarcodeFormat, timestamp: u128, ) -> Self { @@ -68,7 +68,7 @@ impl RXingResult { text: &str, rawBytes: Vec, numBits: usize, - resultPoints: Vec, + resultPoints: Vec, format: BarcodeFormat, timestamp: u128, ) -> Self { @@ -83,7 +83,7 @@ impl RXingResult { } } - pub fn new_from_existing_result(prev: Self, points: Vec) -> Self { + pub fn new_from_existing_result(prev: Self, points: Vec) -> Self { Self { text: prev.text, rawBytes: prev.rawBytes, @@ -122,11 +122,11 @@ impl RXingResult { * identifying finder patterns or the corners of the barcode. The exact meaning is * specific to the type of barcode that was decoded. */ - pub fn getRXingResultPoints(&self) -> &Vec { + pub fn getPoints(&self) -> &Vec { &self.resultPoints } - pub fn getRXingResultPointsMut(&mut self) -> &mut Vec { + pub fn getPointsMut(&mut self) -> &mut Vec { &mut self.resultPoints } @@ -169,7 +169,7 @@ impl RXingResult { } } - pub fn addRXingResultPoints(&mut self, newPoints: &mut Vec) { + pub fn addPoints(&mut self, newPoints: &mut Vec) { if !newPoints.is_empty() { self.resultPoints.append(newPoints); } diff --git a/src/rxing_result_point.rs b/src/rxing_result_point.rs index 7948c8c..70bb447 100644 --- a/src/rxing_result_point.rs +++ b/src/rxing_result_point.rs @@ -14,26 +14,26 @@ use serde::{Deserialize, Serialize}; */ #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, Copy, Default)] -pub struct RXingResultPoint { +pub struct Point { pub(crate) x: f32, pub(crate) y: f32, } -impl Hash for RXingResultPoint { +impl Hash for Point { fn hash(&self, state: &mut H) { self.x.to_string().hash(state); self.y.to_string().hash(state); } } -impl PartialEq for RXingResultPoint { +impl PartialEq for Point { fn eq(&self, other: &Self) -> bool { 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 { 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) { self.x = self.x + rhs.x; self.y = self.y + rhs.y; } } -impl<'a> Sum<&'a RXingResultPoint> for RXingResultPoint { +impl<'a> Sum<&'a Point> for Point { fn sum>(iter: I) -> Self { iter.fold(Self::default(), |acc, &p| acc + p) } } -impl ResultPoint for RXingResultPoint { +impl ResultPoint for Point { fn getX(&self) -> f32 { 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 { write!(f, "({},{})", self.x, self.y) } } -impl std::ops::Sub for RXingResultPoint { +impl std::ops::Sub for Point { type Output = Self; 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; 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; 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; fn mul(self, rhs: Self) -> Self::Output { @@ -108,7 +108,7 @@ impl std::ops::Mul for RXingResultPoint { } } -impl std::ops::Mul for RXingResultPoint { +impl std::ops::Mul for Point { type Output = Self; fn mul(self, rhs: f32) -> Self::Output { @@ -116,7 +116,7 @@ impl std::ops::Mul for RXingResultPoint { } } -impl std::ops::Mul for RXingResultPoint { +impl std::ops::Mul for Point { type Output = Self; fn mul(self, rhs: i32) -> Self::Output { @@ -124,31 +124,31 @@ impl std::ops::Mul for RXingResultPoint { } } -impl std::ops::Mul for i32 { - type Output = RXingResultPoint; +impl std::ops::Mul for i32 { + 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) } } -impl std::ops::Mul for f32 { - type Output = RXingResultPoint; +impl std::ops::Mul for f32 { + 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) } } -impl std::ops::Div for RXingResultPoint { - type Output = RXingResultPoint; +impl std::ops::Div for Point { + type Output = Point; fn div(self, rhs: f32) -> Self::Output { Self::Output::new(self.x / rhs, self.y / rhs) } } -impl RXingResultPoint { +impl Point { pub fn dot(self, p: Self) -> f32 { self.x * p.x + self.y * p.y }