From 39b4866e4769ab11c968b5aa5b98e0d6428972dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Stepanovi=C4=87?= Date: Thu, 16 Feb 2023 11:20:03 +0000 Subject: [PATCH] add point(x: f32, y: f32) function Shorter than writing `Point::new` --- src/aztec/detector.rs | 20 ++++++++-------- .../detector/monochrome_rectangle_detector.rs | 14 +++++------ .../detector/white_rectangle_detector.rs | 24 +++++++++---------- .../detector/datamatrix_detector.rs | 22 ++++++++--------- src/maxicode/detector.rs | 18 +++++++------- src/multi/by_quadrant_reader.rs | 6 ++--- src/multi/generic_multiple_barcode_reader.rs | 8 +++---- src/oned/coda_bar_reader.rs | 6 ++--- src/oned/code_128_reader.rs | 6 ++--- src/oned/code_39_reader.rs | 6 ++--- src/oned/code_93_reader.rs | 6 ++--- src/oned/itf_reader.rs | 6 ++--- src/oned/one_d_reader.rs | 8 +++---- src/oned/rss/finder_pattern.rs | 6 ++--- src/oned/rss/rss_14_reader.rs | 4 ++-- src/oned/upc_ean_extension_2_support.rs | 6 ++--- src/oned/upc_ean_extension_5_support.rs | 6 ++--- src/oned/upc_ean_reader.rs | 12 +++++----- src/pdf417/decoder/bounding_box.rs | 14 +++++------ src/pdf417/detector/pdf_417_detector.rs | 10 ++++---- src/qrcode/detector/qrcode_detector.rs | 9 +++---- src/rxing_result_point.rs | 5 ++++ 22 files changed, 113 insertions(+), 109 deletions(-) diff --git a/src/aztec/detector.rs b/src/aztec/detector.rs index 6d44eea..4e3037f 100644 --- a/src/aztec/detector.rs +++ b/src/aztec/detector.rs @@ -23,7 +23,7 @@ use crate::{ BitMatrix, DefaultGridSampler, GridSampler, Result, }, exceptions::Exceptions, - Point, ResultPoint, + point, Point, ResultPoint, }; use super::aztec_detector_result::AztecDetectorRXingResult; @@ -325,10 +325,10 @@ 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 = Point::new(pina.get_x() as f32 + 0.5f32, pina.get_y() as f32 - 0.5f32); - let pinbx = Point::new(pinb.get_x() as f32 + 0.5f32, pinb.get_y() as f32 + 0.5f32); - let pincx = Point::new(pinc.get_x() as f32 - 0.5f32, pinc.get_y() as f32 + 0.5f32); - let pindx = Point::new(pind.get_x() as f32 - 0.5f32, pind.get_y() as f32 - 0.5f32); + let pinax = point(pina.get_x() as f32 + 0.5f32, pina.get_y() as f32 - 0.5f32); + let pinbx = point(pinb.get_x() as f32 + 0.5f32, pinb.get_y() as f32 + 0.5f32); + let pincx = point(pinc.get_x() as f32 - 0.5f32, pinc.get_y() as f32 + 0.5f32); + let pindx = point(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. @@ -563,20 +563,20 @@ impl<'a> Detector<'_> { 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 p1 = point(Math.max(0, p1.getX() - corr), Math.min(image.getHeight() - 1, p1.getY() + corr)); let p2 = AztecPoint::new(0.max(p2.get_x() - corr), 0.max(p2.get_y() - corr)); - // let p2 = Point::new(Math.max(0, p2.getX() - corr), Math.max(0, p2.getY() - corr)); + // let p2 = point(Math.max(0, p2.getX() - corr), Math.max(0, p2.getY() - corr)); 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), + // let p3 = point(Math.min(image.getWidth() - 1, p3.getX() + corr), // Math.max(0, Math.min(image.getHeight() - 1, p3.getY() - corr))); 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), ); - // let p4 = Point::new(Math.min(image.getWidth() - 1, p4.getX() + corr), + // let p4 = point(Math.min(image.getWidth() - 1, p4.getX() + corr), // Math.min(image.getHeight() - 1, p4.getY() + corr)); let c_init = self.get_color(p4, p1); @@ -746,7 +746,7 @@ impl AztecPoint { impl From for Point { fn from(value: AztecPoint) -> Self { - Point::new(value.x as f32, value.y as f32) + point(value.x as f32, value.y as f32) } } diff --git a/src/common/detector/monochrome_rectangle_detector.rs b/src/common/detector/monochrome_rectangle_detector.rs index 31a1e44..6f99fe1 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, Point, ResultPoint, + point, Exceptions, Point, ResultPoint, }; /** @@ -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(Point::new( + return Ok(point( lastRange[usize::from(deltaY <= 0)] as f32, lastY as f32, )); } - return Ok(Point::new(lastRange[0] as f32, lastY as f32)); + return Ok(point(lastRange[0] as f32, lastY as f32)); } else { - return Ok(Point::new(lastRange[1] as f32, lastY as f32)); + return Ok(point(lastRange[1] as f32, lastY as f32)); } } else { let lastX = x - deltaX; if lastRange[0] < centerY { if lastRange[1] > centerY { - return Ok(Point::new( + return Ok(point( lastX as f32, lastRange[usize::from(deltaX >= 0)] as f32, )); } - return Ok(Point::new(lastX as f32, lastRange[0] as f32)); + return Ok(point(lastX as f32, lastRange[0] as f32)); } else { - return Ok(Point::new(lastX as f32, lastRange[1] as f32)); + return Ok(point(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 cb8df39..9b48db0 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, Point, ResultPoint, + point, Exceptions, Point, ResultPoint, }; /** @@ -288,8 +288,8 @@ impl<'a> WhiteRectangleDetector<'_> { } fn get_black_point_on_segment(&self, a_x: f32, a_y: f32, b_x: f32, b_y: f32) -> Option { - let a = Point::new(a_x, a_y); - let b = Point::new(b_x, b_y); + let a = point(a_x, a_y); + let b = point(b_x, b_y); let dist = a.distance(b).round() as i32; let x_step: f32 = (b_x - a_x) / dist as f32; @@ -299,7 +299,7 @@ impl<'a> WhiteRectangleDetector<'_> { let x = (a_x + i as f32 * x_step).round() as i32; let y = (a_y + i as f32 * y_step).round() as i32; if self.image.get(x as u32, y as u32) { - return Some(Point::new(x as f32, y as f32)); + return Some(point(x as f32, y as f32)); } } None @@ -337,17 +337,17 @@ impl<'a> WhiteRectangleDetector<'_> { if yi < self.width as f32 / 2.0f32 { [ - 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), + point(ti - CORR as f32, tj + CORR as f32), + point(zi + CORR as f32, zj + CORR as f32), + point(xi - CORR as f32, xj - CORR as f32), + point(yi + CORR as f32, yj - CORR as f32), ] } else { [ - 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), + point(ti + CORR as f32, tj + CORR as f32), + point(zi + CORR as f32, zj - CORR as f32), + point(xi - CORR as f32, xj + CORR as f32), + point(yi - CORR as f32, yj - CORR as f32), ] } } diff --git a/src/datamatrix/detector/datamatrix_detector.rs b/src/datamatrix/detector/datamatrix_detector.rs index 0ec28cd..a91ec73 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, Point, ResultPoint, + point, Exceptions, Point, ResultPoint, }; use super::DatamatrixDetectorResult; @@ -101,15 +101,15 @@ impl<'a> Detector<'_> { )) } - 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); - Point::new(point.getX() + x, point.getY() + y) + fn shiftPoint(p: Point, to: Point, div: u32) -> Point { + let x = (to.getX() - p.getX()) / (div as f32 + 1.0); + let y = (to.getY() - p.getY()) / (div as f32 + 1.0); + point(p.getX() + x, p.getY() + y) } - fn moveAway(point: Point, fromX: f32, fromY: f32) -> Point { - let mut x = point.getX(); - let mut y = point.getY(); + fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point { + let mut x = p.getX(); + let mut y = p.getY(); if x < fromX { x -= 1.0; @@ -123,7 +123,7 @@ impl<'a> Detector<'_> { y += 1.0; } - Point::new(x, y) + point(x, y) } /** @@ -232,11 +232,11 @@ impl<'a> Detector<'_> { trTop = self.transitionsBetween(pointAs, pointD); trRight = self.transitionsBetween(pointCs, pointD); - let candidate1 = Point::new( + let candidate1 = point( pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop as f32 + 1.0), pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop as f32 + 1.0), ); - let candidate2 = Point::new( + let candidate2 = point( pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight as f32 + 1.0), pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight as f32 + 1.0), ); diff --git a/src/maxicode/detector.rs b/src/maxicode/detector.rs index d2a846c..de1a0d7 100644 --- a/src/maxicode/detector.rs +++ b/src/maxicode/detector.rs @@ -3,7 +3,7 @@ use num::integer::Roots; use crate::{ common::{BitMatrix, DefaultGridSampler, DetectorRXingResult, GridSampler, Result}, - Exceptions, Point, + point, Exceptions, Point, }; use super::MaxiCodeReader; @@ -714,10 +714,10 @@ fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4] calculate_simple_boundary(circle, Some(image), None, false); let naive_box = [ - 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), + point(left_boundary as f32, bottom_boundary as f32), + point(left_boundary as f32, top_boundary as f32), + point(right_boundary as f32, bottom_boundary as f32), + point(right_boundary as f32, top_boundary as f32), ]; #[allow(unused_mut)] @@ -952,10 +952,10 @@ fn attempt_rotation_box( Some(( [ - 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), + point(new_1.0, new_1.1), + point(new_2.0, new_2.1), + point(new_3.0, new_3.1), + point(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 f43dc8e..bb23fa7 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, Point, RXingResult, Reader, ResultPoint}; +use crate::{point, Exceptions, Point, RXingResult, Reader, ResultPoint}; /** * This class attempts to decode a barcode from an image, not by scanning the whole image, @@ -124,7 +124,7 @@ impl ByQuadrantReader { // if !points.is_empty() { // // for relative in points { - // // result.push(Point::new( + // // result.push(point( // // relative.getX() + leftOffset, // // relative.getY() + topOffset, // // )); @@ -133,7 +133,7 @@ impl ByQuadrantReader { // result points .iter() - .map(|relative| Point::new(relative.getX() + leftOffset, relative.getY() + topOffset)) + .map(|relative| point(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 26c3d59..3d2487d 100644 --- a/src/multi/generic_multiple_barcode_reader.rs +++ b/src/multi/generic_multiple_barcode_reader.rs @@ -17,8 +17,8 @@ use std::collections::HashMap; use crate::{ - common::Result, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, RXingResult, Reader, - ResultPoint, + common::Result, point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, RXingResult, + Reader, ResultPoint, }; use super::MultipleBarcodeReader; @@ -186,7 +186,7 @@ impl GenericMultipleBarcodeReader { let newPoints: Vec = oldPoints .iter() .map(|oldPoint| { - Point::new( + point( oldPoint.getX() + xOffset as f32, oldPoint.getY() + yOffset as f32, ) @@ -195,7 +195,7 @@ impl GenericMultipleBarcodeReader { // let mut newPoints = Vec::with_capacity(oldPoints.len()); // for oldPoint in oldPoints { - // newPoints.push(Point::new( + // newPoints.push(point( // oldPoint.getX() + xOffset as f32, // oldPoint.getY() + yOffset as f32, // )); diff --git a/src/oned/coda_bar_reader.rs b/src/oned/coda_bar_reader.rs index 1acaf8f..dccb79b 100644 --- a/src/oned/coda_bar_reader.rs +++ b/src/oned/coda_bar_reader.rs @@ -20,7 +20,7 @@ use crate::common::{BitArray, Result}; use crate::DecodeHintValue; use crate::Exceptions; use crate::RXingResult; -use crate::{BarcodeFormat, Point}; +use crate::{point, BarcodeFormat}; use super::OneDReader; @@ -171,8 +171,8 @@ impl OneDReader for CodaBarReader { &self.decodeRowRXingResult, Vec::new(), vec![ - Point::new(left, rowNumber as f32), - Point::new(right, rowNumber as f32), + point(left, rowNumber as f32), + point(right, rowNumber as f32), ], BarcodeFormat::CODABAR, ); diff --git a/src/oned/code_128_reader.rs b/src/oned/code_128_reader.rs index a282de4..f5cd128 100644 --- a/src/oned/code_128_reader.rs +++ b/src/oned/code_128_reader.rs @@ -18,7 +18,7 @@ use rxing_one_d_proc_derive::OneDReader; use crate::{ common::{BitArray, Result}, - BarcodeFormat, Exceptions, Point, RXingResult, + point, BarcodeFormat, Exceptions, RXingResult, }; use super::{one_d_reader, OneDReader}; @@ -342,8 +342,8 @@ impl OneDReader for Code128Reader { &result, rawBytes, vec![ - Point::new(left, rowNumber as f32), - Point::new(right, rowNumber as f32), + point(left, rowNumber as f32), + point(right, rowNumber as f32), ], BarcodeFormat::CODE_128, ); diff --git a/src/oned/code_39_reader.rs b/src/oned/code_39_reader.rs index f5d5a73..4e30bd8 100644 --- a/src/oned/code_39_reader.rs +++ b/src/oned/code_39_reader.rs @@ -17,7 +17,7 @@ use rxing_one_d_proc_derive::OneDReader; use crate::common::{BitArray, Result}; -use crate::{BarcodeFormat, Exceptions, Point, RXingResult}; +use crate::{point, BarcodeFormat, Exceptions, RXingResult}; use super::{one_d_reader, OneDReader}; @@ -134,8 +134,8 @@ impl OneDReader for Code39Reader { &resultString, Vec::new(), vec![ - Point::new(left, rowNumber as f32), - Point::new(right, rowNumber as f32), + point(left, rowNumber as f32), + point(right, rowNumber as f32), ], BarcodeFormat::CODE_39, ); diff --git a/src/oned/code_93_reader.rs b/src/oned/code_93_reader.rs index a0d9178..4b275f8 100644 --- a/src/oned/code_93_reader.rs +++ b/src/oned/code_93_reader.rs @@ -18,7 +18,7 @@ use rxing_one_d_proc_derive::OneDReader; use crate::{ common::{BitArray, Result}, - BarcodeFormat, Exceptions, Point, RXingResult, + point, BarcodeFormat, Exceptions, RXingResult, }; use super::{one_d_reader, OneDReader}; @@ -117,8 +117,8 @@ impl OneDReader for Code93Reader { &resultString, Vec::new(), vec![ - Point::new(left, rowNumber as f32), - Point::new(right, rowNumber as f32), + point(left, rowNumber as f32), + point(right, rowNumber as f32), ], BarcodeFormat::CODE_93, ); diff --git a/src/oned/itf_reader.rs b/src/oned/itf_reader.rs index 491501c..2db7bbd 100644 --- a/src/oned/itf_reader.rs +++ b/src/oned/itf_reader.rs @@ -18,7 +18,7 @@ use rxing_one_d_proc_derive::OneDReader; use crate::{ common::{BitArray, Result}, - BarcodeFormat, DecodeHintValue, Exceptions, Point, RXingResult, + point, BarcodeFormat, DecodeHintValue, Exceptions, RXingResult, }; use super::{one_d_reader, OneDReader}; @@ -150,8 +150,8 @@ impl OneDReader for ITFReader { &resultString, Vec::new(), // no natural byte representation for these barcodes vec![ - Point::new(startRange[1] as f32, rowNumber as f32), - Point::new(endRange[0] as f32, rowNumber as f32), + point(startRange[1] as f32, rowNumber as f32), + point(endRange[0] as f32, rowNumber as f32), ], BarcodeFormat::ITF, ); diff --git a/src/oned/one_d_reader.rs b/src/oned/one_d_reader.rs index 641da7a..e7e7f43 100644 --- a/src/oned/one_d_reader.rs +++ b/src/oned/one_d_reader.rs @@ -16,7 +16,7 @@ use crate::{ common::{BitArray, Result}, - BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, + point, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, ResultPoint, }; @@ -117,10 +117,8 @@ pub trait OneDReader: Reader { // And remember to flip the result points horizontally. let points = result.getPointsMut(); if !points.is_empty() && points.len() >= 2 { - points[0] = - Point::new(width as f32 - points[0].getX() - 1.0, points[0].getY()); - points[1] = - Point::new(width as f32 - points[1].getX() - 1.0, points[1].getY()); + points[0] = point(width as f32 - points[0].getX() - 1.0, points[0].getY()); + points[1] = point(width as f32 - points[1].getX() - 1.0, points[1].getY()); } } return Ok(result); diff --git a/src/oned/rss/finder_pattern.rs b/src/oned/rss/finder_pattern.rs index 1854fe7..775e38f 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::Point; +use crate::{point, Point}; /** * Encapsulates an RSS barcode finder pattern, including its start/end position and row. @@ -34,8 +34,8 @@ impl FinderPattern { value, startEnd, resultPoints: vec![ - Point::new(start as f32, rowNumber as f32), - Point::new(end as f32, rowNumber as f32), + point(start as f32, rowNumber as f32), + point(end as f32, rowNumber as f32), ], } } diff --git a/src/oned/rss/rss_14_reader.rs b/src/oned/rss/rss_14_reader.rs index 3e6fe5c..0f23616 100644 --- a/src/oned/rss/rss_14_reader.rs +++ b/src/oned/rss/rss_14_reader.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use crate::{ common::{BitArray, Result}, oned::{one_d_reader, OneDReader}, - BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, + point, BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, }; @@ -259,7 +259,7 @@ impl RSS14Reader { // row is actually reversed center = row.getSize() as f32 - 1.0 - center; } - cb(&Point::new(center, rowNumber as f32)); + cb(&point(center, rowNumber as f32)); } let outside = self.decodeDataCharacter(row, &pattern, true)?; diff --git a/src/oned/upc_ean_extension_2_support.rs b/src/oned/upc_ean_extension_2_support.rs index 604d4a6..4e79d82 100644 --- a/src/oned/upc_ean_extension_2_support.rs +++ b/src/oned/upc_ean_extension_2_support.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use crate::{ common::{BitArray, Result}, - BarcodeFormat, Exceptions, Point, RXingResult, RXingResultMetadataType, + point, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, }; @@ -49,11 +49,11 @@ impl UPCEANExtension2Support { &resultString, Vec::new(), vec![ - Point::new( + point( (extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0, rowNumber as f32, ), - Point::new(end as f32, rowNumber as f32), + point(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 3e2bc4b..30518f7 100644 --- a/src/oned/upc_ean_extension_5_support.rs +++ b/src/oned/upc_ean_extension_5_support.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use crate::{ common::{BitArray, Result}, - BarcodeFormat, Exceptions, Point, RXingResult, RXingResultMetadataType, + point, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, }; @@ -51,11 +51,11 @@ impl UPCEANExtension5Support { &resultString, Vec::new(), vec![ - Point::new( + point( (extensionStartRange[0] + extensionStartRange[1]) as f32 / 2.0, rowNumber as f32, ), - Point::new(end as f32, rowNumber as f32), + point(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 3c39bfe..346c90f 100644 --- a/src/oned/upc_ean_reader.rs +++ b/src/oned/upc_ean_reader.rs @@ -16,7 +16,7 @@ use crate::{ common::{BitArray, Result}, - BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, Point, RXingResult, + point, BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, }; @@ -156,7 +156,7 @@ pub trait UPCEANReader: OneDReader { let mut symbologyIdentifier = 0; if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { - cb(&Point::new( + cb(&point( (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(&Point::new(endStart as f32, rowNumber as f32)); + cb(&point(endStart as f32, rowNumber as f32)); } let endRange = self.decodeEnd(row, endStart)?; if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { - cb(&Point::new( + cb(&point( (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![ - Point::new(left, rowNumber as f32), - Point::new(right, rowNumber as f32), + point(left, rowNumber as f32), + point(right, rowNumber as f32), ], format, ); diff --git a/src/pdf417/decoder/bounding_box.rs b/src/pdf417/decoder/bounding_box.rs index f30e340..8adb723 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, Point, ResultPoint, + point, Exceptions, Point, ResultPoint, }; /** @@ -58,13 +58,13 @@ impl BoundingBox { if leftUnspecified { newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?; - newTopLeft = Point::new(0.0, newTopRight.getY()); - newBottomLeft = Point::new(0.0, newBottomRight.getY()); + newTopLeft = point(0.0, newTopRight.getY()); + newBottomLeft = point(0.0, newBottomRight.getY()); } else if rightUnspecified { newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?; newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?; - newTopRight = Point::new(image.getWidth() as f32 - 1.0, newTopLeft.getY()); - newBottomRight = Point::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY()); + newTopRight = point(image.getWidth() as f32 - 1.0, newTopLeft.getY()); + newBottomRight = point(image.getWidth() as f32 - 1.0, newBottomLeft.getY()); } else { newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?; newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?; @@ -144,7 +144,7 @@ impl BoundingBox { if newMinY < 0.0 { newMinY = 0.0; } - let newTop = Point::new(top.getX(), newMinY); + let newTop = point(top.getX(), newMinY); if isLeft { newTopLeft = newTop; } else { @@ -162,7 +162,7 @@ impl BoundingBox { if newMaxY >= self.image.getHeight() { newMaxY = self.image.getHeight() - 1; } - let newBottom = Point::new(bottom.getX(), newMaxY as f32); + let newBottom = point(bottom.getX(), newMaxY as f32); if isLeft { newBottomLeft = newBottom; } else { diff --git a/src/pdf417/detector/pdf_417_detector.rs b/src/pdf417/detector/pdf_417_detector.rs index 9a62ae0..836e2bc 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, Point, ResultPoint, + point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, ResultPoint, }; use std::borrow::Cow; @@ -245,8 +245,8 @@ fn findRowsWithPattern( break; } } - result[0] = Some(Point::new(loc_store.as_ref()?[0] as f32, startRow as f32)); - result[1] = Some(Point::new(loc_store.as_ref()?[1] as f32, startRow as f32)); + result[0] = Some(point(loc_store.as_ref()?[0] as f32, startRow as f32)); + result[1] = Some(point(loc_store.as_ref()?[1] as f32, startRow as f32)); found = true; break; } @@ -294,8 +294,8 @@ fn findRowsWithPattern( stopRow += 1; } stopRow -= skippedRowCount + 1; - result[2] = Some(Point::new(previousRowLoc[0] as f32, stopRow as f32)); - result[3] = Some(Point::new(previousRowLoc[1] as f32, stopRow as f32)); + result[2] = Some(point(previousRowLoc[0] as f32, stopRow as f32)); + result[3] = Some(point(previousRowLoc[1] as f32, stopRow as f32)); } if stopRow - startRow < BARCODE_MIN_HEIGHT { result.fill(None); diff --git a/src/qrcode/detector/qrcode_detector.rs b/src/qrcode/detector/qrcode_detector.rs index eda48de..fc23759 100644 --- a/src/qrcode/detector/qrcode_detector.rs +++ b/src/qrcode/detector/qrcode_detector.rs @@ -18,6 +18,7 @@ use std::collections::HashMap; use crate::{ common::{BitMatrix, DefaultGridSampler, GridSampler, PerspectiveTransform, Result}, + point, qrcode::decoder::Version, result_point_utils, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, PointCallback, ResultPoint, @@ -377,8 +378,8 @@ impl<'a> Detector<'_> { if (state == 1) == self.image.get(realX as u32, realY as u32) { if state == 2 { return Point::distance( - Point::new(x as f32, y as f32), - Point::new(fromX as f32, fromY as f32), + point(x as f32, y as f32), + point(fromX as f32, fromY as f32), ); } state += 1; @@ -400,8 +401,8 @@ impl<'a> Detector<'_> { // small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this. if state == 2 { return Point::distance( - Point::new((toX as i32 + xstep) as f32, toY as f32), - Point::new(fromX as f32, fromY as f32), + point((toX as i32 + xstep) as f32, toY as f32), + point(fromX as f32, fromY as f32), ); } // else we didn't find even black-white-black; no estimate is really possible diff --git a/src/rxing_result_point.rs b/src/rxing_result_point.rs index e0ed881..a48e6e8 100644 --- a/src/rxing_result_point.rs +++ b/src/rxing_result_point.rs @@ -19,6 +19,11 @@ pub struct Point { pub(crate) y: f32, } +/** An alias for `Point::new`. */ +pub fn point(x: f32, y: f32) -> Point { + Point::new(x, y) +} + /** Currently necessary because the external OneDReader proc macro uses it. */ pub type RXingResultPoint = Point;