swap point_f and point functions

This commit is contained in:
Henry Schimke
2023-05-04 14:50:32 -05:00
parent 80f06ecb3c
commit 3fc068f49b
38 changed files with 210 additions and 217 deletions

View File

@@ -21,7 +21,7 @@ use crate::{
BitMatrix, DefaultGridSampler, GridSampler, Quadrilateral, Result, BitMatrix, DefaultGridSampler, GridSampler, Quadrilateral, Result,
}, },
exceptions::Exceptions, exceptions::Exceptions,
point, Point, point_f, Point,
}; };
use super::aztec_detector_result::AztecDetectorRXingResult; use super::aztec_detector_result::AztecDetectorRXingResult;
@@ -320,10 +320,10 @@ impl<'a> Detector<'_> {
// Expand the square by .5 pixel in each direction so that we're on the border // Expand the square by .5 pixel in each direction so that we're on the border
// between the white square and the black square // between the white square and the black square
let pinax = point(pina.x + 0.5, pina.y - 0.5); let pinax = point_f(pina.x + 0.5, pina.y - 0.5);
let pinbx = point(pinb.x + 0.5, pinb.y + 0.5); let pinbx = point_f(pinb.x + 0.5, pinb.y + 0.5);
let pincx = point(pinc.x - 0.5, pinc.y + 0.5); let pincx = point_f(pinc.x - 0.5, pinc.y + 0.5);
let pindx = point(pind.x - 0.5, pind.y - 0.5); let pindx = point_f(pind.x - 0.5, pind.y - 0.5);
// Expand the square so that its corners are the centers of the points // Expand the square so that its corners are the centers of the points
// just outside the bull's eye. // just outside the bull's eye.
@@ -463,10 +463,10 @@ impl<'a> Detector<'_> {
let high = dimension as f32 / 2.0 + self.nb_center_layers as f32; let high = dimension as f32 / 2.0 + self.nb_center_layers as f32;
let dst = Quadrilateral::new( let dst = Quadrilateral::new(
point(low, low), point_f(low, low),
point(high, low), point_f(high, low),
point(high, high), point_f(high, high),
point(low, high), point_f(low, high),
); );
let (res, _) = sampler.sample_grid_detailed(image, dimension, dimension, dst, quad)?; let (res, _) = sampler.sample_grid_detailed(image, dimension, dimension, dst, quad)?;

View File

@@ -19,7 +19,7 @@
// import org.junit.Assert; // import org.junit.Assert;
// import org.junit.Test; // import org.junit.Test;
use crate::point; use crate::point_f;
/** /**
* @author Sean Owen * @author Sean Owen
@@ -32,10 +32,10 @@ static EPSILON: f32 = 1.0E-4_f32;
#[test] #[test]
fn test_square_to_quadrilateral() { fn test_square_to_quadrilateral() {
let square = Quadrilateral::new( let square = Quadrilateral::new(
point(2.0, 3.0), point_f(2.0, 3.0),
point(10.0, 3.0), point_f(10.0, 3.0),
point(16.0, 15.0), point_f(16.0, 15.0),
point(4.0, 9.0), point_f(4.0, 9.0),
); );
let pt = PerspectiveTransform::squareToQuadrilateral(square); let pt = PerspectiveTransform::squareToQuadrilateral(square);
assert_point_equals(2.0, 3.0, 0.0, 0.0, &pt); assert_point_equals(2.0, 3.0, 0.0, 0.0, &pt);
@@ -49,16 +49,16 @@ fn test_square_to_quadrilateral() {
#[test] #[test]
fn test_quadrilateral_to_quadrilateral() { fn test_quadrilateral_to_quadrilateral() {
let quad1 = Quadrilateral::new( let quad1 = Quadrilateral::new(
point(2.0, 3.0), point_f(2.0, 3.0),
point(10.0, 4.0), point_f(10.0, 4.0),
point(16.0, 15.0), point_f(16.0, 15.0),
point(4.0, 9.0), point_f(4.0, 9.0),
); );
let quad2 = Quadrilateral::new( let quad2 = Quadrilateral::new(
point(103.0, 110.0), point_f(103.0, 110.0),
point(300.0, 120.0), point_f(300.0, 120.0),
point(290.0, 270.0), point_f(290.0, 270.0),
point(150.0, 280.0), point_f(150.0, 280.0),
); );
let pt = PerspectiveTransform::quadrilateralToQuadrilateral(quad1, quad2).expect("transform"); let pt = PerspectiveTransform::quadrilateralToQuadrilateral(quad1, quad2).expect("transform");
@@ -77,7 +77,7 @@ fn assert_point_equals(
source_y: f32, source_y: f32,
pt: &PerspectiveTransform, pt: &PerspectiveTransform,
) { ) {
let mut points = [point(source_x, source_y)]; let mut points = [point_f(source_x, source_y)];
pt.transform_points_single(&mut points); pt.transform_points_single(&mut points);
assert!( assert!(
(expected_x - points[0].x < EPSILON || points[0].x - expected_x < EPSILON), (expected_x - points[0].x < EPSILON || points[0].x - expected_x < EPSILON),

View File

@@ -21,7 +21,7 @@
use std::fmt; use std::fmt;
use crate::common::Result; use crate::common::Result;
use crate::{point, point_i, Exceptions, Point}; use crate::{point_f, point_i, Exceptions, Point};
use super::BitArray; use super::BitArray;
@@ -604,7 +604,7 @@ impl BitMatrix {
bit += 1; bit += 1;
} }
x += bit; x += bit;
Some(point(x as f32, y as f32)) Some(point_f(x as f32, y as f32))
} }
pub fn getBottomRightOnBit(&self) -> Option<Point> { pub fn getBottomRightOnBit(&self) -> Option<Point> {
@@ -626,7 +626,7 @@ impl BitMatrix {
} }
x += bit; x += bit;
Some(point(x as f32, y as f32)) Some(point_f(x as f32, y as f32))
} }
/** /**

View File

@@ -27,7 +27,7 @@
// */ // */
// public final class BitMatrixTestCase extends Assert { // public final class BitMatrixTestCase extends Assert {
use crate::point; use crate::point_f;
use super::BitMatrix; use super::BitMatrix;
@@ -89,14 +89,14 @@ fn test_on_bit() {
assert!(matrix.getTopLeftOnBit().is_none()); assert!(matrix.getTopLeftOnBit().is_none());
assert!(matrix.getBottomRightOnBit().is_none()); assert!(matrix.getBottomRightOnBit().is_none());
matrix.setRegion(1, 1, 1, 1).expect("must set"); matrix.setRegion(1, 1, 1, 1).expect("must set");
assert_eq!(point(1.0, 1.0), matrix.getTopLeftOnBit().unwrap()); assert_eq!(point_f(1.0, 1.0), matrix.getTopLeftOnBit().unwrap());
assert_eq!(point(1.0, 1.0), matrix.getBottomRightOnBit().unwrap()); assert_eq!(point_f(1.0, 1.0), matrix.getBottomRightOnBit().unwrap());
matrix.setRegion(1, 1, 3, 2).expect("must set"); matrix.setRegion(1, 1, 3, 2).expect("must set");
assert_eq!(point(1.0, 1.0), matrix.getTopLeftOnBit().unwrap()); assert_eq!(point_f(1.0, 1.0), matrix.getTopLeftOnBit().unwrap());
assert_eq!(point(3.0, 2.0), matrix.getBottomRightOnBit().unwrap()); assert_eq!(point_f(3.0, 2.0), matrix.getBottomRightOnBit().unwrap());
matrix.setRegion(0, 0, 5, 5).expect("must set"); matrix.setRegion(0, 0, 5, 5).expect("must set");
assert_eq!(point(0.0, 0.0), matrix.getTopLeftOnBit().unwrap()); assert_eq!(point_f(0.0, 0.0), matrix.getTopLeftOnBit().unwrap());
assert_eq!(point(4.0, 4.0), matrix.getBottomRightOnBit().unwrap()); assert_eq!(point_f(4.0, 4.0), matrix.getBottomRightOnBit().unwrap());
} }
#[test] #[test]

View File

@@ -1,6 +1,6 @@
use crate::common::BitMatrix; use crate::common::BitMatrix;
use crate::common::Result; use crate::common::Result;
use crate::point; use crate::point_f;
use crate::Point; use crate::Point;
impl BitMatrix { impl BitMatrix {
@@ -19,7 +19,7 @@ impl BitMatrix {
let yOffset = top + y as f32 * subSampling; let yOffset = top + y as f32 * subSampling;
for x in 0..result.width() { for x in 0..result.width() {
// for (int x = 0; x < result.width(); x++) { // for (int x = 0; x < result.width(); x++) {
if self.get_point(point(left + x as f32 * subSampling, yOffset)) { if self.get_point(point_f(left + x as f32 * subSampling, yOffset)) {
result.set(x, y); result.set(x, y);
} }
} }

View File

@@ -5,7 +5,7 @@ use crate::{
}, },
BitMatrix, Quadrilateral, BitMatrix, Quadrilateral,
}, },
point, Point, point_f, Point,
}; };
use super::{ use super::{
@@ -172,10 +172,10 @@ pub fn CenterOfDoubleCross(
let mut sum = Point::default(); let mut sum = Point::default();
for d in [ for d in [
point(0.0, 1.0), point_f(0.0, 1.0),
point(1.0, 0.0), point_f(1.0, 0.0),
point(1.0, 1.0), point_f(1.0, 1.0),
point(1.0, -1.0), point_f(1.0, -1.0),
] { ] {
// for (auto d : {PointI{0, 1}, {1, 0}, {1, 1}, {1, -1}}) { // for (auto d : {PointI{0, 1}, {1, 0}, {1, 1}, {1, -1}}) {
let avr1 = AverageEdgePixels(&mut EdgeTracer::new(image, center, d), range, numOfEdges)?; let avr1 = AverageEdgePixels(&mut EdgeTracer::new(image, center, d), range, numOfEdges)?;
@@ -199,7 +199,7 @@ pub fn CenterOfRing(
let inner = nth < 0; let inner = nth < 0;
let nth = nth.abs(); let nth = nth.abs();
// log(center, 3); // log(center, 3);
let mut cur = EdgeTracer::new(image, center, point(0.0, 1.0)); let mut cur = EdgeTracer::new(image, center, point_f(0.0, 1.0));
if cur.stepToEdge(Some(nth), Some(radius), Some(inner)) == 0 { if cur.stepToEdge(Some(nth), Some(radius), Some(inner)) == 0 {
return None; return None;
} }
@@ -224,7 +224,7 @@ pub fn CenterOfRing(
<< (4.0 << (4.0
+ Point::dot( + Point::dot(
Point::floor(Point::bresenhamDirection(cur.p() - center)), Point::floor(Point::bresenhamDirection(cur.p() - center)),
point(1.0, 3.0), point_f(1.0, 3.0),
)) as u32; )) as u32;
if !cur.stepAlongEdge(edgeDir, None) { if !cur.stepAlongEdge(edgeDir, None) {
@@ -288,7 +288,7 @@ pub fn CollectRingPoints(
) -> Vec<Point> { ) -> Vec<Point> {
let centerI = center.floor(); let centerI = center.floor();
let radius = range; let radius = range;
let mut cur = EdgeTracer::new(image, centerI, point(0.0, 1.0)); let mut cur = EdgeTracer::new(image, centerI, point_f(0.0, 1.0));
if cur.stepToEdge(Some(edgeIndex), Some(radius), Some(backup)) == 0 { if cur.stepToEdge(Some(edgeIndex), Some(radius), Some(backup)) == 0 {
return Vec::default(); return Vec::default();
} }
@@ -312,7 +312,7 @@ pub fn CollectRingPoints(
<< (4.0 << (4.0
+ Point::dot( + Point::dot(
Point::round(Point::bresenhamDirection(cur.p - centerI)), Point::round(Point::bresenhamDirection(cur.p - centerI)),
point(1.0, 3.0), point_f(1.0, 3.0),
)) as u32; )) as u32;
if !cur.stepAlongEdge(edgeDir, None) { if !cur.stepAlongEdge(edgeDir, None) {
@@ -557,7 +557,7 @@ pub fn LocateConcentricPattern<const E2E: bool, const LEN: usize, const SUM: usi
// TODO: setting maxError to 1 can subtantially help with detecting symbols with low print quality resulting in damaged // TODO: setting maxError to 1 can subtantially help with detecting symbols with low print quality resulting in damaged
// finder patterns, but it sutantially increases the runtime (approx. 20% slower for the falsepositive images). // finder patterns, but it sutantially increases the runtime (approx. 20% slower for the falsepositive images).
let mut maxError = 0; let mut maxError = 0;
for d in [point(0.0, 1.0), point(1.0, 0.0)] { for d in [point_f(0.0, 1.0), point_f(1.0, 0.0)] {
// for (auto d : {PointI{0, 1}, {1, 0}}) { // for (auto d : {PointI{0, 1}, {1, 0}}) {
cur.setDirection(d); // THIS COULD POSSIBLY BE WRONG, WE MIGHT MEAN TO CLONE cur EACH RUN? cur.setDirection(d); // THIS COULD POSSIBLY BE WRONG, WE MIGHT MEAN TO CLONE cur EACH RUN?
@@ -573,7 +573,7 @@ pub fn LocateConcentricPattern<const E2E: bool, const LEN: usize, const SUM: usi
} }
//#if 1 //#if 1
for d in [point(1.0, 1.0), point(1.0, -1.0)] { for d in [point_f(1.0, 1.0), point_f(1.0, -1.0)] {
// for (auto d : {PointI{1, 1}, {1, -1}}) { // for (auto d : {PointI{1, 1}, {1, -1}}) {
cur.setDirection(d); // THIS COULD POSSIBLY BE WRONG, WE MIGHT MEAN TO CLONE cur EACH RUN? cur.setDirection(d); // THIS COULD POSSIBLY BE WRONG, WE MIGHT MEAN TO CLONE cur EACH RUN?
let spread = CheckSymmetricPattern::<E2E, LEN, SUM, _>(&mut cur, pattern, range * 2, false); let spread = CheckSymmetricPattern::<E2E, LEN, SUM, _>(&mut cur, pattern, range * 2, false);

View File

@@ -1,5 +1,5 @@
use crate::common::Result; use crate::common::Result;
use crate::{point, Point}; use crate::{point_f, Point};
pub trait RegressionLineTrait { pub trait RegressionLineTrait {
// points: Vec<Point>, // points: Vec<Point>,
@@ -23,7 +23,7 @@ pub trait RegressionLineTrait {
let x = (l1.c() * l2.b() - l1.b() * l2.c()) / d; let x = (l1.c() * l2.b() - l1.b() * l2.c()) / d;
let y = (l1.a() * l2.c() - l1.c() * l2.a()) / d; let y = (l1.a() * l2.c() - l1.c() * l2.a()) / d;
Some(point(x, y)) Some(point_f(x, y))
} }
// fn evaluate_begin_end(&self, begin: Point, end: Point) -> bool;// { // fn evaluate_begin_end(&self, begin: Point, end: Point) -> bool;// {

View File

@@ -19,7 +19,7 @@
// import com.google.zxing.NotFoundException; // import com.google.zxing.NotFoundException;
use crate::common::Result; use crate::common::Result;
use crate::{point, Exceptions, Point}; use crate::{point_f, Exceptions, Point};
use super::{BitMatrix, GridSampler, SamplerControl}; use super::{BitMatrix, GridSampler, SamplerControl};
@@ -49,13 +49,13 @@ impl GridSampler for DefaultGridSampler {
|p: Point| -> bool { image.is_in(transform.transform_point(p.centered())) }; |p: Point| -> bool { image.is_in(transform.transform_point(p.centered())) };
for y in (p0.y as i32)..(p1.y as i32) { for y in (p0.y as i32)..(p1.y as i32) {
// for (int y = y0; y < y1; ++y) // for (int y = y0; y < y1; ++y)
if !isInside(point(p0.x, y as f32)) || !isInside(point(p1.x - 1.0, y as f32)) { if !isInside(point_f(p0.x, y as f32)) || !isInside(point_f(p1.x - 1.0, y as f32)) {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
} }
} }
for x in (p0.x as i32)..(p1.x as i32) { for x in (p0.x as i32)..(p1.x as i32) {
// for (int x = x0; x < x1; ++x) // for (int x = x0; x < x1; ++x)
if !isInside(point(x as f32, p0.y)) || !isInside(point(x as f32, p1.y - 1.0)) { if !isInside(point_f(x as f32, p0.y)) || !isInside(point_f(x as f32, p1.y - 1.0)) {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
} }
} }
@@ -83,7 +83,7 @@ impl GridSampler for DefaultGridSampler {
let projectCorner = |p: Point| -> Point { let projectCorner = |p: Point| -> Point {
for SamplerControl { p0, p1, transform } in controls { for SamplerControl { p0, p1, transform } in controls {
if p0.x <= p.x && p.x <= p1.x && p0.y <= p.y && p.y <= p1.y { if p0.x <= p.x && p.x <= p1.x && p0.y <= p.y && p.y <= p1.y {
return transform.transform_point(p) + point(0.5, 0.5); return transform.transform_point(p) + point_f(0.5, 0.5);
} }
} }
Point::default() Point::default()

View File

@@ -19,7 +19,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, Exceptions, Point, point_f, Exceptions, Point,
}; };
/** /**
@@ -178,27 +178,27 @@ impl<'a> MonochromeRectangleDetector<'_> {
if lastRange[0] < centerX { if lastRange[0] < centerX {
if lastRange[1] > centerX { if lastRange[1] > centerX {
// straddle, choose one or the other based on direction // straddle, choose one or the other based on direction
return Ok(point( return Ok(point_f(
lastRange[usize::from(deltaY <= 0)] as f32, lastRange[usize::from(deltaY <= 0)] as f32,
lastY as f32, lastY as f32,
)); ));
} }
return Ok(point(lastRange[0] as f32, lastY as f32)); return Ok(point_f(lastRange[0] as f32, lastY as f32));
} else { } else {
return Ok(point(lastRange[1] as f32, lastY as f32)); return Ok(point_f(lastRange[1] as f32, lastY as f32));
} }
} else { } else {
let lastX = x - deltaX; let lastX = x - deltaX;
if lastRange[0] < centerY { if lastRange[0] < centerY {
if lastRange[1] > centerY { if lastRange[1] > centerY {
return Ok(point( return Ok(point_f(
lastX as f32, lastX as f32,
lastRange[usize::from(deltaX >= 0)] as f32, lastRange[usize::from(deltaX >= 0)] as f32,
)); ));
} }
return Ok(point(lastX as f32, lastRange[0] as f32)); return Ok(point_f(lastX as f32, lastRange[0] as f32));
} else { } else {
return Ok(point(lastX as f32, lastRange[1] as f32)); return Ok(point_f(lastX as f32, lastRange[1] as f32));
} }
} }
} }

View File

@@ -18,7 +18,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, Exceptions, Point, point_f, Exceptions, Point,
}; };
/** /**
@@ -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<Point> { fn get_black_point_on_segment(&self, a_x: f32, a_y: f32, b_x: f32, b_y: f32) -> Option<Point> {
let a = point(a_x, a_y); let a = point_f(a_x, a_y);
let b = point(b_x, b_y); let b = point_f(b_x, b_y);
let dist = a.distance(b).round() as i32; let dist = a.distance(b).round() as i32;
let x_step: f32 = (b_x - a_x) / dist as f32; 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 x = (a_x + i as f32 * x_step).round() as i32;
let y = (a_y + i as f32 * y_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) { if self.image.get(x as u32, y as u32) {
return Some(point(x as f32, y as f32)); return Some(point_f(x as f32, y as f32));
} }
} }
None None
@@ -337,17 +337,17 @@ impl<'a> WhiteRectangleDetector<'_> {
if yi < self.width as f32 / 2.0 { if yi < self.width as f32 / 2.0 {
[ [
point(ti - CORR as f32, tj + CORR as f32), point_f(ti - CORR as f32, tj + CORR as f32),
point(zi + CORR as f32, zj + CORR as f32), point_f(zi + CORR as f32, zj + CORR as f32),
point(xi - CORR as f32, xj - CORR as f32), point_f(xi - CORR as f32, xj - CORR as f32),
point(yi + CORR as f32, yj - CORR as f32), point_f(yi + CORR as f32, yj - CORR as f32),
] ]
} else { } else {
[ [
point(ti + CORR as f32, tj + CORR as f32), point_f(ti + CORR as f32, tj + CORR as f32),
point(zi + CORR as f32, zj - CORR as f32), point_f(zi + CORR as f32, zj - CORR as f32),
point(xi - CORR as f32, xj + CORR as f32), point_f(xi - CORR as f32, xj + CORR as f32),
point(yi - CORR as f32, yj - CORR as f32), point_f(yi - CORR as f32, yj - CORR as f32),
] ]
} }
} }

View File

@@ -19,7 +19,7 @@
// import com.google.zxing.NotFoundException; // import com.google.zxing.NotFoundException;
use crate::{common::Result, Point}; use crate::{common::Result, Point};
use crate::{point, Exceptions}; use crate::{point_f, Exceptions};
use super::{BitMatrix, PerspectiveTransform, Quadrilateral}; use super::{BitMatrix, PerspectiveTransform, Quadrilateral};
@@ -269,8 +269,8 @@ pub struct SamplerControl {
impl SamplerControl { impl SamplerControl {
pub fn new(width: u32, height: u32, transform: PerspectiveTransform) -> Self { pub fn new(width: u32, height: u32, transform: PerspectiveTransform) -> Self {
Self { Self {
p0: point(0.0, 0.0), p0: point_f(0.0, 0.0),
p1: point(width as f32, height as f32), p1: point_f(width as f32, height as f32),
transform, transform,
} }
} }

View File

@@ -18,7 +18,7 @@
use std::ops::Mul; use std::ops::Mul;
use crate::{common::Result, point, Exceptions, Point}; use crate::{common::Result, point_f, Exceptions, Point};
use super::Quadrilateral; use super::Quadrilateral;
@@ -122,7 +122,7 @@ impl PerspectiveTransform {
let [p0, p1, p2, p3] = square.0; let [p0, p1, p2, p3] = square.0;
let d3 = p0 - p1 + p2 - p3; let d3 = p0 - p1 + p2 - p3;
if d3 == point(0.0, 0.0) { if d3 == point_f(0.0, 0.0) {
// Affine // Affine
PerspectiveTransform::new( PerspectiveTransform::new(
p1.x - p0.x, p1.x - p0.x,

View File

@@ -1,4 +1,4 @@
use crate::{point, Point}; use crate::{point_f, Point};
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Quadrilateral(pub [Point; 4]); pub struct Quadrilateral(pub [Point; 4]);
@@ -77,10 +77,10 @@ impl Quadrilateral {
pub fn rectangle_from_xy(x0: f32, x1: f32, y0: f32, y1: f32, o: Option<f32>) -> Self { pub fn rectangle_from_xy(x0: f32, x1: f32, y0: f32, y1: f32, o: Option<f32>) -> Self {
let o = o.unwrap_or(0.5); let o = o.unwrap_or(0.5);
Quadrilateral::from([ Quadrilateral::from([
point(x0 + o, y0 + o), point_f(x0 + o, y0 + o),
point(x1 + o, y0 + o), point_f(x1 + o, y0 + o),
point(x1 + o, y1 + o), point_f(x1 + o, y1 + o),
point(x0 + o, y1 + o), point_f(x0 + o, y1 + o),
]) ])
} }

View File

@@ -18,7 +18,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::{BitMatrix, DecoderRXingResult, DetectorRXingResult, Result}, common::{BitMatrix, DecoderRXingResult, DetectorRXingResult, Result},
point, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, Exceptions, Point, point_f, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, Exceptions, Point,
RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader,
}; };
@@ -218,7 +218,7 @@ impl DataMatrixReader {
let iOffset = top + y as f32 * moduleSize as f32; let iOffset = top + y as f32 * moduleSize as f32;
for x in 0..matrixWidth { for x in 0..matrixWidth {
// for (int x = 0; x < matrixWidth; x++) { // for (int x = 0; x < matrixWidth; x++) {
if image.get_point(point(left + x as f32 * moduleSize as f32, iOffset)) { if image.get_point(point_f(left + x as f32 * moduleSize as f32, iOffset)) {
bits.set(x, y); bits.set(x, y);
} }
} }

View File

@@ -19,7 +19,7 @@ use crate::{
detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler,
Quadrilateral, Result, Quadrilateral, Result,
}, },
point, Exceptions, Point, point_f, Exceptions, Point,
}; };
use super::DatamatrixDetectorResult; use super::DatamatrixDetectorResult;
@@ -103,7 +103,7 @@ impl<'a> Detector<'_> {
fn shiftPoint(p: Point, to: Point, div: u32) -> Point { fn shiftPoint(p: Point, to: Point, div: u32) -> Point {
let x = (to.x - p.x) / (div as f32 + 1.0); let x = (to.x - p.x) / (div as f32 + 1.0);
let y = (to.y - p.y) / (div as f32 + 1.0); let y = (to.y - p.y) / (div as f32 + 1.0);
point(p.x + x, p.y + y) point_f(p.x + x, p.y + y)
} }
fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point { fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point {
@@ -122,7 +122,7 @@ impl<'a> Detector<'_> {
y += 1.0; y += 1.0;
} }
point(x, y) point_f(x, y)
} }
/** /**
@@ -231,11 +231,11 @@ impl<'a> Detector<'_> {
trTop = self.transitionsBetween(pointAs, pointD); trTop = self.transitionsBetween(pointAs, pointD);
trRight = self.transitionsBetween(pointCs, pointD); trRight = self.transitionsBetween(pointCs, pointD);
let candidate1 = point( let candidate1 = point_f(
pointD.x + (pointC.x - pointB.x) / (trTop as f32 + 1.0), pointD.x + (pointC.x - pointB.x) / (trTop as f32 + 1.0),
pointD.y + (pointC.y - pointB.y) / (trTop as f32 + 1.0), pointD.y + (pointC.y - pointB.y) / (trTop as f32 + 1.0),
); );
let candidate2 = point( let candidate2 = point_f(
pointD.x + (pointA.x - pointB.x) / (trRight as f32 + 1.0), pointD.x + (pointA.x - pointB.x) / (trRight as f32 + 1.0),
pointD.y + (pointA.y - pointB.y) / (trRight as f32 + 1.0), pointD.y + (pointA.y - pointB.y) / (trRight as f32 + 1.0),
); );
@@ -336,10 +336,10 @@ impl<'a> Detector<'_> {
let sampler = DefaultGridSampler::default(); let sampler = DefaultGridSampler::default();
let dst = Quadrilateral::new( let dst = Quadrilateral::new(
point(0.5, 0.5), point_f(0.5, 0.5),
point(dimensionX as f32 - 0.5, 0.5), point_f(dimensionX as f32 - 0.5, 0.5),
point(dimensionX as f32 - 0.5, dimensionY as f32 - 0.5), point_f(dimensionX as f32 - 0.5, dimensionY as f32 - 0.5),
point(0.5, dimensionY as f32 - 0.5), point_f(0.5, dimensionY as f32 - 0.5),
); );
let src = Quadrilateral::new(topRight, topLeft, bottomRight, bottomLeft); let src = Quadrilateral::new(topRight, topLeft, bottomRight, bottomLeft);

View File

@@ -22,7 +22,7 @@ use crate::{
zxing_cpp_detector::{util::intersect, BitMatrixCursorTrait}, zxing_cpp_detector::{util::intersect, BitMatrixCursorTrait},
DatamatrixDetectorResult, DatamatrixDetectorResult,
}, },
point, point_f,
qrcode::encoder::ByteMatrix, qrcode::encoder::ByteMatrix,
Exceptions, Point, Exceptions, Point,
}; };
@@ -217,10 +217,10 @@ fn Scan(
let grid_sampler = DefaultGridSampler::default(); let grid_sampler = DefaultGridSampler::default();
// let transform = PerspectiveTransform::quadrilateralToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); // let transform = PerspectiveTransform::quadrilateralToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p);
let dst = Quadrilateral::new( let dst = Quadrilateral::new(
point(0.0, 0.0), point_f(0.0, 0.0),
point(dimT as f32, 0.0), point_f(dimT as f32, 0.0),
point(dimT as f32, dimR as f32), point_f(dimT as f32, dimR as f32),
point(0.0, dimR as f32), point_f(0.0, dimR as f32),
); );
let src = sourcePoints; let src = sourcePoints;

View File

@@ -5,7 +5,7 @@ use crate::{
common::{ common::{
BitMatrix, DefaultGridSampler, DetectorRXingResult, GridSampler, Quadrilateral, Result, BitMatrix, DefaultGridSampler, DetectorRXingResult, GridSampler, Quadrilateral, Result,
}, },
point, Exceptions, Point, PointU, point, point_f, Exceptions, Point, PointU,
}; };
use super::MaxiCodeReader; use super::MaxiCodeReader;
@@ -343,10 +343,10 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
// let target_height = (br.1 - tr.1).round().abs() as u32; // let target_height = (br.1 - tr.1).round().abs() as u32;
let dst = Quadrilateral::new( let dst = Quadrilateral::new(
point(0.0, 0.0), point_f(0.0, 0.0),
point(target_width, 0.0), point_f(target_width, 0.0),
point(target_width, target_height), point_f(target_width, target_height),
point(0.0, target_height), point_f(0.0, target_height),
); );
let src = Quadrilateral::new(tl, tr, br, bl); let src = Quadrilateral::new(tl, tr, br, bl);
@@ -693,10 +693,10 @@ fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([Point; 4], f32
calculate_simple_boundary(circle, Some(image), None, false); calculate_simple_boundary(circle, Some(image), None, false);
let naive_box = [ let naive_box = [
point(left_boundary as f32, bottom_boundary as f32), point_f(left_boundary as f32, bottom_boundary as f32),
point(left_boundary as f32, top_boundary as f32), point_f(left_boundary as f32, top_boundary as f32),
point(right_boundary as f32, bottom_boundary as f32), point_f(right_boundary as f32, bottom_boundary as f32),
point(right_boundary as f32, top_boundary as f32), point_f(right_boundary as f32, top_boundary as f32),
]; ];
#[allow(unused_mut)] #[allow(unused_mut)]
@@ -771,26 +771,16 @@ fn calculate_simple_boundary(
} }
const TOP_LEFT_ORIENTATION_POS: (PointU, PointU, PointU) = const TOP_LEFT_ORIENTATION_POS: (PointU, PointU, PointU) =
(PointU::new(10, 9), PointU::new(11, 9), PointU::new(11, 10)); (point(10, 9), point(11, 9), point(11, 10));
const TOP_RIGHT_ORIENTATION_POS: (PointU, PointU, PointU) = const TOP_RIGHT_ORIENTATION_POS: (PointU, PointU, PointU) =
(PointU::new(17, 9), PointU::new(17, 10), PointU::new(18, 10)); (point(17, 9), point(17, 10), point(18, 10));
const LEFT_ORIENTATION_POS: (PointU, PointU, PointU) = const LEFT_ORIENTATION_POS: (PointU, PointU, PointU) = (point(7, 15), point(7, 16), point(8, 16));
(PointU::new(7, 15), PointU::new(7, 16), PointU::new(8, 16)); const RIGHT_ORIENTATION_POS: (PointU, PointU, PointU) =
const RIGHT_ORIENTATION_POS: (PointU, PointU, PointU) = ( (point(20, 16), point(21, 16), point(20, 17));
PointU::new(20, 16), const BOTTOM_LEFT_ORIENTATION_POS: (PointU, PointU, PointU) =
PointU::new(21, 16), (point(10, 22), point(11, 22), point(10, 23));
PointU::new(20, 17), const BOTTOM_RIGHT_ORIENTATION_POS: (PointU, PointU, PointU) =
); (point(17, 22), point(16, 23), point(17, 23));
const BOTTOM_LEFT_ORIENTATION_POS: (PointU, PointU, PointU) = (
PointU::new(10, 22),
PointU::new(11, 22),
PointU::new(10, 23),
);
const BOTTOM_RIGHT_ORIENTATION_POS: (PointU, PointU, PointU) = (
PointU::new(17, 22),
PointU::new(16, 23),
PointU::new(17, 23),
);
fn attempt_rotation_box( fn attempt_rotation_box(
image: &BitMatrix, image: &BitMatrix,
@@ -943,10 +933,10 @@ fn attempt_rotation_box(
Some(( Some((
[ [
point(new_1.x, new_1.y), point_f(new_1.x, new_1.y),
point(new_2.x, new_2.y), point_f(new_2.x, new_2.y),
point(new_3.x, new_3.y), point_f(new_3.x, new_3.y),
point(new_4.x, new_4.y), point_f(new_4.x, new_4.y),
], ],
final_rotation, final_rotation,
)) ))
@@ -997,7 +987,7 @@ fn adjust_point_alternate(point: PointU, circle: &Circle, center_scale: f64) ->
+ ((x * width + width / 2 + (y & 0x01) * width / 2) / MaxiCodeReader::MATRIX_WIDTH) + ((x * width + width / 2 + (y & 0x01) * width / 2) / MaxiCodeReader::MATRIX_WIDTH)
.min(width - 1); .min(width - 1);
PointU::new(ix, iy) crate::point(ix, iy)
} }
/// calculate a likely size for the barcode. /// calculate a likely size for the barcode.

View File

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

View File

@@ -17,7 +17,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::{ use crate::{
common::Result, point, Binarizer, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, common::Result, point_f, Binarizer, BinaryBitmap, DecodingHintDictionary, Exceptions, Point,
RXingResult, Reader, RXingResult, Reader,
}; };
@@ -185,7 +185,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
let newPoints: Vec<Point> = oldPoints let newPoints: Vec<Point> = oldPoints
.iter() .iter()
.map(|oldPoint| point(oldPoint.x + xOffset as f32, oldPoint.y + yOffset as f32)) .map(|oldPoint| point_f(oldPoint.x + xOffset as f32, oldPoint.y + yOffset as f32))
.collect(); .collect();
// let mut newPoints = Vec::with_capacity(oldPoints.len()); // let mut newPoints = Vec::with_capacity(oldPoints.len());

View File

@@ -20,7 +20,7 @@ use crate::common::{BitArray, Result};
use crate::DecodeHintValue; use crate::DecodeHintValue;
use crate::Exceptions; use crate::Exceptions;
use crate::RXingResult; use crate::RXingResult;
use crate::{point, BarcodeFormat}; use crate::{point_f, BarcodeFormat};
use super::OneDReader; use super::OneDReader;
@@ -171,8 +171,8 @@ impl OneDReader for CodaBarReader {
&self.decodeRowRXingResult, &self.decodeRowRXingResult,
Vec::new(), Vec::new(),
vec![ vec![
point(left, rowNumber as f32), point_f(left, rowNumber as f32),
point(right, rowNumber as f32), point_f(right, rowNumber as f32),
], ],
BarcodeFormat::CODABAR, BarcodeFormat::CODABAR,
); );

View File

@@ -18,7 +18,7 @@ use rxing_one_d_proc_derive::OneDReader;
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
point, BarcodeFormat, Exceptions, RXingResult, point_f, BarcodeFormat, Exceptions, RXingResult,
}; };
use super::{one_d_reader, OneDReader}; use super::{one_d_reader, OneDReader};
@@ -338,8 +338,8 @@ impl OneDReader for Code128Reader {
&result, &result,
rawBytes, rawBytes,
vec![ vec![
point(left, rowNumber as f32), point_f(left, rowNumber as f32),
point(right, rowNumber as f32), point_f(right, rowNumber as f32),
], ],
BarcodeFormat::CODE_128, BarcodeFormat::CODE_128,
); );

View File

@@ -17,7 +17,7 @@
use rxing_one_d_proc_derive::OneDReader; use rxing_one_d_proc_derive::OneDReader;
use crate::common::{BitArray, Result}; use crate::common::{BitArray, Result};
use crate::{point, BarcodeFormat, Exceptions, RXingResult}; use crate::{point_f, BarcodeFormat, Exceptions, RXingResult};
use super::{one_d_reader, OneDReader}; use super::{one_d_reader, OneDReader};
@@ -134,8 +134,8 @@ impl OneDReader for Code39Reader {
&resultString, &resultString,
Vec::new(), Vec::new(),
vec![ vec![
point(left, rowNumber as f32), point_f(left, rowNumber as f32),
point(right, rowNumber as f32), point_f(right, rowNumber as f32),
], ],
BarcodeFormat::CODE_39, BarcodeFormat::CODE_39,
); );

View File

@@ -18,7 +18,7 @@ use rxing_one_d_proc_derive::OneDReader;
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
point, BarcodeFormat, Exceptions, RXingResult, point_f, BarcodeFormat, Exceptions, RXingResult,
}; };
use super::{one_d_reader, OneDReader}; use super::{one_d_reader, OneDReader};
@@ -117,8 +117,8 @@ impl OneDReader for Code93Reader {
&resultString, &resultString,
Vec::new(), Vec::new(),
vec![ vec![
point(left, rowNumber as f32), point_f(left, rowNumber as f32),
point(right, rowNumber as f32), point_f(right, rowNumber as f32),
], ],
BarcodeFormat::CODE_93, BarcodeFormat::CODE_93,
); );

View File

@@ -18,7 +18,7 @@ use rxing_one_d_proc_derive::OneDReader;
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
point, BarcodeFormat, DecodeHintValue, Exceptions, RXingResult, point_f, BarcodeFormat, DecodeHintValue, Exceptions, RXingResult,
}; };
use super::{one_d_reader, OneDReader}; use super::{one_d_reader, OneDReader};
@@ -150,8 +150,8 @@ impl OneDReader for ITFReader {
&resultString, &resultString,
Vec::new(), // no natural byte representation for these barcodes Vec::new(), // no natural byte representation for these barcodes
vec![ vec![
point(startRange[1] as f32, rowNumber as f32), point_f(startRange[1] as f32, rowNumber as f32),
point(endRange[0] as f32, rowNumber as f32), point_f(endRange[0] as f32, rowNumber as f32),
], ],
BarcodeFormat::ITF, BarcodeFormat::ITF,
); );

View File

@@ -16,7 +16,7 @@
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
point, Binarizer, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, point_f, Binarizer, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary,
Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader,
}; };
@@ -117,8 +117,8 @@ pub trait OneDReader: Reader {
// And remember to flip the result points horizontally. // And remember to flip the result points horizontally.
let points = result.getPointsMut(); let points = result.getPointsMut();
if !points.is_empty() && points.len() >= 2 { if !points.is_empty() && points.len() >= 2 {
points[0] = point(width as f32 - points[0].x - 1.0, points[0].y); points[0] = point_f(width as f32 - points[0].x - 1.0, points[0].y);
points[1] = point(width as f32 - points[1].x - 1.0, points[1].y); points[1] = point_f(width as f32 - points[1].x - 1.0, points[1].y);
} }
} }
return Ok(result); return Ok(result);

View File

@@ -16,7 +16,7 @@
use std::hash::Hash; use std::hash::Hash;
use crate::{point, Point}; use crate::{point_f, Point};
/** /**
* Encapsulates an RSS barcode finder pattern, including its start/end position and row. * Encapsulates an RSS barcode finder pattern, including its start/end position and row.
@@ -34,8 +34,8 @@ impl FinderPattern {
value, value,
startEnd, startEnd,
resultPoints: vec![ resultPoints: vec![
point(start as f32, rowNumber as f32), point_f(start as f32, rowNumber as f32),
point(end as f32, rowNumber as f32), point_f(end as f32, rowNumber as f32),
], ],
} }
} }

View File

@@ -19,7 +19,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
oned::{one_d_reader, OneDReader}, oned::{one_d_reader, OneDReader},
point, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, DecodingHintDictionary, point_f, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, DecodingHintDictionary,
Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader,
}; };
@@ -259,7 +259,7 @@ impl RSS14Reader {
// row is actually reversed // row is actually reversed
center = row.get_size() as f32 - 1.0 - center; center = row.get_size() as f32 - 1.0 - center;
} }
cb(point(center, rowNumber as f32)); cb(point_f(center, rowNumber as f32));
} }
let outside = self.decodeDataCharacter(row, &pattern, true)?; let outside = self.decodeDataCharacter(row, &pattern, true)?;

View File

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

View File

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

View File

@@ -16,7 +16,7 @@
use crate::{ use crate::{
common::{BitArray, Result}, common::{BitArray, Result},
point, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, Exceptions, RXingResult, point_f, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, Exceptions, RXingResult,
RXingResultMetadataType, RXingResultMetadataValue, Reader, RXingResultMetadataType, RXingResultMetadataValue, Reader,
}; };
@@ -156,7 +156,7 @@ pub trait UPCEANReader: OneDReader {
let mut symbologyIdentifier = 0; let mut symbologyIdentifier = 0;
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback {
cb(point( cb(point_f(
(startGuardRange[0] + startGuardRange[1]) as f32 / 2.0, (startGuardRange[0] + startGuardRange[1]) as f32 / 2.0,
rowNumber as f32, rowNumber as f32,
)); ));
@@ -166,13 +166,13 @@ pub trait UPCEANReader: OneDReader {
let endStart = self.decodeMiddle(row, startGuardRange, &mut result)?; let endStart = self.decodeMiddle(row, startGuardRange, &mut result)?;
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback {
cb(point(endStart as f32, rowNumber as f32)); cb(point_f(endStart as f32, rowNumber as f32));
} }
let endRange = self.decodeEnd(row, endStart)?; let endRange = self.decodeEnd(row, endStart)?;
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback { if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = resultPointCallback {
cb(point( cb(point_f(
(endRange[0] + endRange[1]) as f32 / 2.0, (endRange[0] + endRange[1]) as f32 / 2.0,
rowNumber as f32, rowNumber as f32,
)); ));
@@ -204,8 +204,8 @@ pub trait UPCEANReader: OneDReader {
&resultString, &resultString,
Vec::new(), // no natural byte representation for these barcodes Vec::new(), // no natural byte representation for these barcodes
vec![ vec![
point(left, rowNumber as f32), point_f(left, rowNumber as f32),
point(right, rowNumber as f32), point_f(right, rowNumber as f32),
], ],
format, format,
); );

View File

@@ -18,7 +18,7 @@ use std::rc::Rc;
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, Exceptions, Point, point_f, Exceptions, Point,
}; };
/** /**
@@ -58,13 +58,13 @@ impl BoundingBox {
if leftUnspecified { if leftUnspecified {
newTopRight = topRight.ok_or(Exceptions::ILLEGAL_STATE)?; newTopRight = topRight.ok_or(Exceptions::ILLEGAL_STATE)?;
newBottomRight = bottomRight.ok_or(Exceptions::ILLEGAL_STATE)?; newBottomRight = bottomRight.ok_or(Exceptions::ILLEGAL_STATE)?;
newTopLeft = point(0.0, newTopRight.y); newTopLeft = point_f(0.0, newTopRight.y);
newBottomLeft = point(0.0, newBottomRight.y); newBottomLeft = point_f(0.0, newBottomRight.y);
} else if rightUnspecified { } else if rightUnspecified {
newTopLeft = topLeft.ok_or(Exceptions::ILLEGAL_STATE)?; newTopLeft = topLeft.ok_or(Exceptions::ILLEGAL_STATE)?;
newBottomLeft = bottomLeft.ok_or(Exceptions::ILLEGAL_STATE)?; newBottomLeft = bottomLeft.ok_or(Exceptions::ILLEGAL_STATE)?;
newTopRight = point(image.getWidth() as f32 - 1.0, newTopLeft.y); newTopRight = point_f(image.getWidth() as f32 - 1.0, newTopLeft.y);
newBottomRight = point(image.getWidth() as f32 - 1.0, newBottomLeft.y); newBottomRight = point_f(image.getWidth() as f32 - 1.0, newBottomLeft.y);
} else { } else {
newTopLeft = topLeft.ok_or(Exceptions::ILLEGAL_STATE)?; newTopLeft = topLeft.ok_or(Exceptions::ILLEGAL_STATE)?;
newTopRight = topRight.ok_or(Exceptions::ILLEGAL_STATE)?; newTopRight = topRight.ok_or(Exceptions::ILLEGAL_STATE)?;
@@ -138,7 +138,7 @@ impl BoundingBox {
if newMinY < 0.0 { if newMinY < 0.0 {
newMinY = 0.0; newMinY = 0.0;
} }
let newTop = point(top.x, newMinY); let newTop = point_f(top.x, newMinY);
if isLeft { if isLeft {
newTopLeft = newTop; newTopLeft = newTop;
} else { } else {
@@ -156,7 +156,7 @@ impl BoundingBox {
if newMaxY >= self.image.getHeight() { if newMaxY >= self.image.getHeight() {
newMaxY = self.image.getHeight() - 1; newMaxY = self.image.getHeight() - 1;
} }
let newBottom = point(bottom.x, newMaxY as f32); let newBottom = point_f(bottom.x, newMaxY as f32);
if isLeft { if isLeft {
newBottomLeft = newBottom; newBottomLeft = newBottom;
} else { } else {

View File

@@ -16,7 +16,7 @@
use crate::{ use crate::{
common::{BitMatrix, Result}, common::{BitMatrix, Result},
point, Binarizer, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, point_f, Binarizer, BinaryBitmap, DecodingHintDictionary, Exceptions, Point,
}; };
use std::borrow::Cow; use std::borrow::Cow;
@@ -244,8 +244,8 @@ fn findRowsWithPattern(
break; break;
} }
} }
result[0] = Some(point(loc_store.as_ref()?[0] as f32, startRow as f32)); result[0] = Some(point_f(loc_store.as_ref()?[0] as f32, startRow as f32));
result[1] = Some(point(loc_store.as_ref()?[1] as f32, startRow as f32)); result[1] = Some(point_f(loc_store.as_ref()?[1] as f32, startRow as f32));
found = true; found = true;
break; break;
} }
@@ -290,8 +290,8 @@ fn findRowsWithPattern(
stopRow += 1; stopRow += 1;
} }
stopRow -= skippedRowCount + 1; stopRow -= skippedRowCount + 1;
result[2] = Some(point(previousRowLoc[0] as f32, stopRow as f32)); result[2] = Some(point_f(previousRowLoc[0] as f32, stopRow as f32));
result[3] = Some(point(previousRowLoc[1] as f32, stopRow as f32)); result[3] = Some(point_f(previousRowLoc[1] as f32, stopRow as f32));
} }
if stopRow - startRow < BARCODE_MIN_HEIGHT { if stopRow - startRow < BARCODE_MIN_HEIGHT {
result.fill(None); result.fill(None);

View File

@@ -23,7 +23,7 @@ use crate::{
}, },
BitMatrix, PerspectiveTransform, Quadrilateral, BitMatrix, PerspectiveTransform, Quadrilateral,
}, },
point, Point, point_f, Point,
}; };
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
@@ -90,7 +90,7 @@ pub fn FindFinderPatterns(image: &BitMatrix, tryHarder: bool) -> FinderPatterns
false false
} }
} { } {
let p = point( let p = point_f(
next.pixelsInFront() as f32 next.pixelsInFront() as f32
+ next[0] as f32 + next[0] as f32
+ next[1] as f32 + next[1] as f32
@@ -412,15 +412,15 @@ pub fn LocateAlignmentPattern(
// log(estimate, 2); // log(estimate, 2);
for d in [ for d in [
point(0.0, 0.0), point_f(0.0, 0.0),
point(0.0, -1.0), point_f(0.0, -1.0),
point(0.0, 1.0), point_f(0.0, 1.0),
point(-1.0, 0.0), point_f(-1.0, 0.0),
point(1.0, 0.0), point_f(1.0, 0.0),
point(-1.0, -1.0), point_f(-1.0, -1.0),
point(1.0, -1.0), point_f(1.0, -1.0),
point(1.0, 1.0), point_f(1.0, 1.0),
point(-1.0, 1.0), point_f(-1.0, 1.0),
] { ] {
// for (auto d : {PointF{0, 0}, {0, -1}, {0, 1}, {-1, 0}, {1, 0}, {-1, -1}, {1, -1}, {1, 1}, {-1, 1}, // for (auto d : {PointF{0, 0}, {0, -1}, {0, 1}, {-1, 0}, {1, 0}, {-1, -1}, {1, -1}, {1, 1}, {-1, 1},
// #if 1 // #if 1
@@ -515,7 +515,7 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
let moduleSize = (best.ms + 1.0) as i32; let moduleSize = (best.ms + 1.0) as i32;
let mut br = ConcentricPattern { let mut br = ConcentricPattern {
p: point(-1.0, -1.0), p: point_f(-1.0, -1.0),
size: 0, size: 0,
}; };
let mut brOffset = point_i(3, 3); let mut brOffset = point_i(3, 3);
@@ -822,8 +822,8 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
// allow corners be moved one pixel inside to accommodate for possible aliasing artifacts // allow corners be moved one pixel inside to accommodate for possible aliasing artifacts
for [p, d] in [ for [p, d] in [
[tl, point_i(1, 1)], [tl, point_i(1, 1)],
[tr, point(-1.0, 1.0)], [tr, point_f(-1.0, 1.0)],
[bl, point(1.0, -1.0)], [bl, point_f(1.0, -1.0)],
] { ] {
diagonal = EdgeTracer::new(image, p, d) diagonal = EdgeTracer::new(image, p, d)
.readPatternFromBlack(1, Some((width / 3 + 1) as i32)) .readPatternFromBlack(1, Some((width / 3 + 1) as i32))
@@ -844,7 +844,7 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
size: fpWidth, size: fpWidth,
}, },
ConcentricPattern { ConcentricPattern {
p: tr + fpWidth as f32 / 2.0 * point(-1.0, 1.0), p: tr + fpWidth as f32 / 2.0 * point_f(-1.0, 1.0),
size: fpWidth, size: fpWidth,
}, },
) )
@@ -853,7 +853,7 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
let moduleSize: f32 = ((width) as f32) / dimension as f32; let moduleSize: f32 = ((width) as f32) / dimension as f32;
if dimension < MIN_MODULES as i32 if dimension < MIN_MODULES as i32
|| dimension > MAX_MODULES as i32 || dimension > MAX_MODULES as i32
|| !image.is_in(point( || !image.is_in(point_f(
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
)) ))
@@ -921,7 +921,7 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
if dimension < MIN_MODULES if dimension < MIN_MODULES
|| dimension > MAX_MODULES || dimension > MAX_MODULES
|| !image.is_in(point( || !image.is_in(point_f(
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
)) ))

View File

@@ -16,7 +16,7 @@
//Point //Point
use crate::{point, Point}; use crate::{point_f, Point};
/** /**
* <p>Encapsulates an alignment pattern, which are the smaller square patterns found in * <p>Encapsulates an alignment pattern, which are the smaller square patterns found in
@@ -46,7 +46,7 @@ impl AlignmentPattern {
pub fn new(posX: f32, posY: f32, estimatedModuleSize: f32) -> Self { pub fn new(posX: f32, posY: f32, estimatedModuleSize: f32) -> Self {
Self { Self {
estimatedModuleSize, estimatedModuleSize,
point: point(posX, posY), point: point_f(posX, posY),
} }
} }

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::{point, Point}; use crate::{point_f, Point};
/** /**
* <p>Encapsulates a finder pattern, which are the three square patterns found in * <p>Encapsulates a finder pattern, which are the three square patterns found in
@@ -51,7 +51,7 @@ impl FinderPattern {
Self { Self {
estimatedModuleSize, estimatedModuleSize,
count, count,
point: point(posX, posY), point: point_f(posX, posY),
} }
} }

View File

@@ -21,7 +21,7 @@ use crate::{
BitMatrix, DefaultGridSampler, GridSampler, PerspectiveTransform, Quadrilateral, Result, BitMatrix, DefaultGridSampler, GridSampler, PerspectiveTransform, Quadrilateral, Result,
SamplerControl, SamplerControl,
}, },
point, point_f,
qrcode::decoder::Version, qrcode::decoder::Version,
DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, PointCallback, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, Point, PointCallback,
}; };
@@ -197,15 +197,15 @@ impl<'a> Detector<'_> {
} }
let dst = Quadrilateral::new( let dst = Quadrilateral::new(
point(3.5, 3.5), point_f(3.5, 3.5),
point(dimMinusThree, 3.5), point_f(dimMinusThree, 3.5),
point(sourceBottomRightX, sourceBottomRightY), point_f(sourceBottomRightX, sourceBottomRightY),
point(3.5, dimMinusThree), point_f(3.5, dimMinusThree),
); );
let src = Quadrilateral::new( let src = Quadrilateral::new(
topLeft, topLeft,
topRight, topRight,
point(bottomRightX, bottomRightY), point_f(bottomRightX, bottomRightY),
bottomLeft, bottomLeft,
); );
@@ -386,8 +386,8 @@ impl<'a> Detector<'_> {
if (state == 1) == self.image.get(realX as u32, realY as u32) { if (state == 1) == self.image.get(realX as u32, realY as u32) {
if state == 2 { if state == 2 {
return Point::distance( return Point::distance(
point(x as f32, y as f32), point_f(x as f32, y as f32),
point(fromX as f32, fromY as f32), point_f(fromX as f32, fromY as f32),
); );
} }
state += 1; state += 1;
@@ -409,8 +409,8 @@ impl<'a> Detector<'_> {
// small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this. // small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this.
if state == 2 { if state == 2 {
return Point::distance( return Point::distance(
point((toX as i32 + xstep) as f32, toY as f32), point_f((toX as i32 + xstep) as f32, toY as f32),
point(fromX as f32, fromY as f32), point_f(fromX as f32, fromY as f32),
); );
} }
// else we didn't find even black-white-black; no estimate is really possible // else we didn't find even black-white-black; no estimate is really possible

View File

@@ -18,7 +18,7 @@ use std::collections::HashMap;
use crate::{ use crate::{
common::{BitMatrix, DecoderRXingResult, DetectorRXingResult, Result}, common::{BitMatrix, DecoderRXingResult, DetectorRXingResult, Result},
point, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, Exceptions, Point, point_f, BarcodeFormat, Binarizer, DecodeHintType, DecodeHintValue, Exceptions, Point,
RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, Reader,
}; };
@@ -237,7 +237,7 @@ impl QRCodeReader {
let mut inBlack = true; let mut inBlack = true;
let mut transitions = 0; let mut transitions = 0;
while x < width && y < height { while x < width && y < height {
if inBlack != image.get_point(point(x, y)) { if inBlack != image.get_point(point_f(x, y)) {
transitions += 1; transitions += 1;
if transitions == 5 { if transitions == 5 {
break; break;

View File

@@ -68,12 +68,15 @@ impl From<PointU> for Point {
} }
/** An alias for `Point::new`. */ /** An alias for `Point::new`. */
pub const fn point(x: f32, y: f32) -> Point { pub const fn point_f(x: f32, y: f32) -> Point {
Point::new(x, y) Point::new(x, y)
} }
pub const fn point_g<T>(x: T, y: T) -> PointT<T> { pub const fn point<T>(x: T, y: T) -> PointT<T>
PointT { x, y } where
T: Copy,
{
PointT::new(x, y)
} }
pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point { pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point {