mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
swap point_f and point functions
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
// import org.junit.Assert;
|
||||
// import org.junit.Test;
|
||||
|
||||
use crate::point;
|
||||
use crate::point_f;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
@@ -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);
|
||||
@@ -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");
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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> {
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
// */
|
||||
// public final class BitMatrixTestCase extends Assert {
|
||||
|
||||
use crate::point;
|
||||
use crate::point_f;
|
||||
|
||||
use super::BitMatrix;
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::common::BitMatrix;
|
||||
use crate::common::Result;
|
||||
use crate::point;
|
||||
use crate::point_f;
|
||||
use crate::Point;
|
||||
|
||||
impl BitMatrix {
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
},
|
||||
BitMatrix, Quadrilateral,
|
||||
},
|
||||
point, Point,
|
||||
point_f, Point,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -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)?;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -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?
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::common::Result;
|
||||
use crate::{point, Point};
|
||||
use crate::{point_f, Point};
|
||||
|
||||
pub trait RegressionLineTrait {
|
||||
// points: Vec<Point>,
|
||||
@@ -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;// {
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
use crate::{
|
||||
common::{BitMatrix, Result},
|
||||
point, Exceptions, Point,
|
||||
point_f, Exceptions, Point,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use crate::{
|
||||
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> {
|
||||
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;
|
||||
@@ -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
|
||||
@@ -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),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
// import com.google.zxing.NotFoundException;
|
||||
|
||||
use crate::{common::Result, Point};
|
||||
use crate::{point, Exceptions};
|
||||
use crate::{point_f, Exceptions};
|
||||
|
||||
use super::{BitMatrix, PerspectiveTransform, Quadrilateral};
|
||||
|
||||
@@ -269,8 +269,8 @@ pub struct SamplerControl {
|
||||
impl SamplerControl {
|
||||
pub fn new(width: u32, height: u32, transform: PerspectiveTransform) -> Self {
|
||||
Self {
|
||||
p0: point(0.0, 0.0),
|
||||
p1: point(width as f32, height as f32),
|
||||
p0: point_f(0.0, 0.0),
|
||||
p1: point_f(width as f32, height as f32),
|
||||
transform,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::ops::Mul;
|
||||
|
||||
use crate::{common::Result, point, Exceptions, Point};
|
||||
use crate::{common::Result, point_f, Exceptions, Point};
|
||||
|
||||
use super::Quadrilateral;
|
||||
|
||||
@@ -122,7 +122,7 @@ impl PerspectiveTransform {
|
||||
let [p0, p1, p2, p3] = square.0;
|
||||
|
||||
let d3 = p0 - p1 + p2 - p3;
|
||||
if d3 == point(0.0, 0.0) {
|
||||
if d3 == point_f(0.0, 0.0) {
|
||||
// Affine
|
||||
PerspectiveTransform::new(
|
||||
p1.x - p0.x,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{point, Point};
|
||||
use crate::{point_f, Point};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
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 {
|
||||
let o = o.unwrap_or(0.5);
|
||||
Quadrilateral::from([
|
||||
point(x0 + o, y0 + o),
|
||||
point(x1 + o, y0 + o),
|
||||
point(x1 + o, y1 + o),
|
||||
point(x0 + o, y1 + o),
|
||||
point_f(x0 + o, y0 + o),
|
||||
point_f(x1 + o, y0 + o),
|
||||
point_f(x1 + o, y1 + o),
|
||||
point_f(x0 + o, y1 + o),
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user