Skip to content

Commit

Permalink
swap point_f and point functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hschimke committed May 4, 2023
1 parent 80f06ec commit 3fc068f
Show file tree
Hide file tree
Showing 38 changed files with 210 additions and 217 deletions.
18 changes: 9 additions & 9 deletions src/aztec/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
BitMatrix, DefaultGridSampler, GridSampler, Quadrilateral, Result,
},
exceptions::Exceptions,
point, Point,
point_f, Point,
};

use super::aztec_detector_result::AztecDetectorRXingResult;
Expand Down Expand Up @@ -320,10 +320,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(pina.x + 0.5, pina.y - 0.5);
let pinbx = point(pinb.x + 0.5, pinb.y + 0.5);
let pincx = point(pinc.x - 0.5, pinc.y + 0.5);
let pindx = point(pind.x - 0.5, pind.y - 0.5);
let pinax = point_f(pina.x + 0.5, pina.y - 0.5);
let pinbx = point_f(pinb.x + 0.5, pinb.y + 0.5);
let pincx = point_f(pinc.x - 0.5, pinc.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
// just outside the bull's eye.
Expand Down Expand Up @@ -463,10 +463,10 @@ impl<'a> Detector<'_> {
let high = dimension as f32 / 2.0 + self.nb_center_layers as f32;

let dst = Quadrilateral::new(
point(low, low),
point(high, low),
point(high, high),
point(low, high),
point_f(low, low),
point_f(high, low),
point_f(high, high),
point_f(low, high),
);

let (res, _) = sampler.sample_grid_detailed(image, dimension, dimension, dst, quad)?;
Expand Down
28 changes: 14 additions & 14 deletions src/common/PerspectiveTransformTestCase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// import org.junit.Assert;
// import org.junit.Test;

use crate::point;
use crate::point_f;

/**
* @author Sean Owen
Expand All @@ -32,10 +32,10 @@ static EPSILON: f32 = 1.0E-4_f32;
#[test]
fn test_square_to_quadrilateral() {
let square = Quadrilateral::new(
point(2.0, 3.0),
point(10.0, 3.0),
point(16.0, 15.0),
point(4.0, 9.0),
point_f(2.0, 3.0),
point_f(10.0, 3.0),
point_f(16.0, 15.0),
point_f(4.0, 9.0),
);
let pt = PerspectiveTransform::squareToQuadrilateral(square);
assert_point_equals(2.0, 3.0, 0.0, 0.0, &pt);
Expand All @@ -49,16 +49,16 @@ fn test_square_to_quadrilateral() {
#[test]
fn test_quadrilateral_to_quadrilateral() {
let quad1 = Quadrilateral::new(
point(2.0, 3.0),
point(10.0, 4.0),
point(16.0, 15.0),
point(4.0, 9.0),
point_f(2.0, 3.0),
point_f(10.0, 4.0),
point_f(16.0, 15.0),
point_f(4.0, 9.0),
);
let quad2 = Quadrilateral::new(
point(103.0, 110.0),
point(300.0, 120.0),
point(290.0, 270.0),
point(150.0, 280.0),
point_f(103.0, 110.0),
point_f(300.0, 120.0),
point_f(290.0, 270.0),
point_f(150.0, 280.0),
);
let pt = PerspectiveTransform::quadrilateralToQuadrilateral(quad1, quad2).expect("transform");

Expand All @@ -77,7 +77,7 @@ fn assert_point_equals(
source_y: f32,
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);
assert!(
(expected_x - points[0].x < EPSILON || points[0].x - expected_x < EPSILON),
Expand Down
6 changes: 3 additions & 3 deletions src/common/bit_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use std::fmt;

use crate::common::Result;
use crate::{point, point_i, Exceptions, Point};
use crate::{point_f, point_i, Exceptions, Point};

use super::BitArray;

Expand Down Expand Up @@ -604,7 +604,7 @@ impl BitMatrix {
bit += 1;
}
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> {
Expand All @@ -626,7 +626,7 @@ impl BitMatrix {
}
x += bit;

Some(point(x as f32, y as f32))
Some(point_f(x as f32, y as f32))
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/common/bit_matrix_test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// */
// public final class BitMatrixTestCase extends Assert {

use crate::point;
use crate::point_f;

use super::BitMatrix;

Expand Down Expand Up @@ -89,14 +89,14 @@ fn test_on_bit() {
assert!(matrix.getTopLeftOnBit().is_none());
assert!(matrix.getBottomRightOnBit().is_none());
matrix.setRegion(1, 1, 1, 1).expect("must set");
assert_eq!(point(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.getTopLeftOnBit().unwrap());
assert_eq!(point_f(1.0, 1.0), matrix.getBottomRightOnBit().unwrap());
matrix.setRegion(1, 1, 3, 2).expect("must set");
assert_eq!(point(1.0, 1.0), matrix.getTopLeftOnBit().unwrap());
assert_eq!(point(3.0, 2.0), matrix.getBottomRightOnBit().unwrap());
assert_eq!(point_f(1.0, 1.0), matrix.getTopLeftOnBit().unwrap());
assert_eq!(point_f(3.0, 2.0), matrix.getBottomRightOnBit().unwrap());
matrix.setRegion(0, 0, 5, 5).expect("must set");
assert_eq!(point(0.0, 0.0), matrix.getTopLeftOnBit().unwrap());
assert_eq!(point(4.0, 4.0), matrix.getBottomRightOnBit().unwrap());
assert_eq!(point_f(0.0, 0.0), matrix.getTopLeftOnBit().unwrap());
assert_eq!(point_f(4.0, 4.0), matrix.getBottomRightOnBit().unwrap());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/common/cpp_essentials/base_extentions/bitmatrix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::BitMatrix;
use crate::common::Result;
use crate::point;
use crate::point_f;
use crate::Point;

impl BitMatrix {
Expand All @@ -19,7 +19,7 @@ impl BitMatrix {
let yOffset = top + y as f32 * subSampling;
for x in 0..result.width() {
// 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);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/common/cpp_essentials/concentric_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
},
BitMatrix, Quadrilateral,
},
point, Point,
point_f, Point,
};

use super::{
Expand Down Expand Up @@ -172,10 +172,10 @@ pub fn CenterOfDoubleCross(
let mut sum = Point::default();

for d in [
point(0.0, 1.0),
point(1.0, 0.0),
point(1.0, 1.0),
point(1.0, -1.0),
point_f(0.0, 1.0),
point_f(1.0, 0.0),
point_f(1.0, 1.0),
point_f(1.0, -1.0),
] {
// for (auto d : {PointI{0, 1}, {1, 0}, {1, 1}, {1, -1}}) {
let avr1 = AverageEdgePixels(&mut EdgeTracer::new(image, center, d), range, numOfEdges)?;
Expand All @@ -199,7 +199,7 @@ pub fn CenterOfRing(
let inner = nth < 0;
let nth = nth.abs();
// 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 {
return None;
}
Expand All @@ -224,7 +224,7 @@ pub fn CenterOfRing(
<< (4.0
+ Point::dot(
Point::floor(Point::bresenhamDirection(cur.p() - center)),
point(1.0, 3.0),
point_f(1.0, 3.0),
)) as u32;

if !cur.stepAlongEdge(edgeDir, None) {
Expand Down Expand Up @@ -288,7 +288,7 @@ pub fn CollectRingPoints(
) -> Vec<Point> {
let centerI = center.floor();
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 {
return Vec::default();
}
Expand All @@ -312,7 +312,7 @@ pub fn CollectRingPoints(
<< (4.0
+ Point::dot(
Point::round(Point::bresenhamDirection(cur.p - centerI)),
point(1.0, 3.0),
point_f(1.0, 3.0),
)) as u32;

if !cur.stepAlongEdge(edgeDir, None) {
Expand Down Expand Up @@ -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
// finder patterns, but it sutantially increases the runtime (approx. 20% slower for the falsepositive images).
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}}) {
cur.setDirection(d); // THIS COULD POSSIBLY BE WRONG, WE MIGHT MEAN TO CLONE cur EACH RUN?

Expand All @@ -573,7 +573,7 @@ pub fn LocateConcentricPattern<const E2E: bool, const LEN: usize, const SUM: usi
}

//#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}}) {
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);
Expand Down
4 changes: 2 additions & 2 deletions src/common/cpp_essentials/regression_line_trait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::common::Result;
use crate::{point, Point};
use crate::{point_f, Point};

pub trait RegressionLineTrait {
// points: Vec<Point>,
Expand All @@ -23,7 +23,7 @@ pub trait RegressionLineTrait {
let x = (l1.c() * l2.b() - l1.b() * l2.c()) / 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;// {
Expand Down
8 changes: 4 additions & 4 deletions src/common/default_grid_sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// import com.google.zxing.NotFoundException;

use crate::common::Result;
use crate::{point, Exceptions, Point};
use crate::{point_f, Exceptions, Point};

use super::{BitMatrix, GridSampler, SamplerControl};

Expand Down Expand Up @@ -49,13 +49,13 @@ impl GridSampler for DefaultGridSampler {
|p: Point| -> bool { image.is_in(transform.transform_point(p.centered())) };
for y in (p0.y as i32)..(p1.y as i32) {
// 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);
}
}
for x in (p0.x as i32)..(p1.x as i32) {
// 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);
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ impl GridSampler for DefaultGridSampler {
let projectCorner = |p: Point| -> Point {
for SamplerControl { p0, p1, transform } in controls {
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()
Expand Down
14 changes: 7 additions & 7 deletions src/common/detector/monochrome_rectangle_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use crate::{
common::{BitMatrix, Result},
point, Exceptions, Point,
point_f, Exceptions, Point,
};

/**
Expand Down Expand Up @@ -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(
return Ok(point_f(
lastRange[usize::from(deltaY <= 0)] 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 {
return Ok(point(lastRange[1] as f32, lastY as f32));
return Ok(point_f(lastRange[1] as f32, lastY as f32));
}
} else {
let lastX = x - deltaX;
if lastRange[0] < centerY {
if lastRange[1] > centerY {
return Ok(point(
return Ok(point_f(
lastX 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 {
return Ok(point(lastX as f32, lastRange[1] as f32));
return Ok(point_f(lastX as f32, lastRange[1] as f32));
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/common/detector/white_rectangle_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::{
common::{BitMatrix, Result},
point, Exceptions, Point,
point_f, Exceptions, Point,
};

/**
Expand Down Expand Up @@ -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> {
let a = point(a_x, a_y);
let b = point(b_x, b_y);
let a = point_f(a_x, a_y);
let b = point_f(b_x, b_y);

let dist = a.distance(b).round() as i32;
let x_step: f32 = (b_x - a_x) / dist as f32;
Expand All @@ -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(x as f32, y as f32));
return Some(point_f(x as f32, y as f32));
}
}
None
Expand Down Expand Up @@ -337,17 +337,17 @@ impl<'a> WhiteRectangleDetector<'_> {

if yi < self.width as f32 / 2.0 {
[
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),
point_f(ti - CORR as f32, tj + CORR as f32),
point_f(zi + CORR as f32, zj + CORR as f32),
point_f(xi - CORR as f32, xj - CORR as f32),
point_f(yi + CORR as f32, yj - CORR as f32),
]
} else {
[
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),
point_f(ti + CORR as f32, tj + CORR as f32),
point_f(zi + CORR as f32, zj - CORR as f32),
point_f(xi - CORR as f32, xj + CORR as f32),
point_f(yi - CORR as f32, yj - CORR as f32),
]
}
}
Expand Down
Loading

0 comments on commit 3fc068f

Please sign in to comment.