mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
wip: Search & replace RXingResultPoint with Point
Build fails because the OneDReader proc macro expects that a RXingResultPoint type exists.
This commit is contained in:
@@ -39,7 +39,7 @@ static DECODER: Lazy<Decoder> = Lazy::new(Decoder::new);
|
||||
#[derive(Default)]
|
||||
pub struct DataMatrixReader;
|
||||
|
||||
// private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0];
|
||||
// private static final Point[] NO_POINTS = new Point[0];
|
||||
|
||||
// private final Decoder decoder = new Decoder();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
common::{
|
||||
detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result,
|
||||
},
|
||||
Exceptions, RXingResultPoint, ResultPoint,
|
||||
Exceptions, Point, ResultPoint,
|
||||
};
|
||||
|
||||
use super::DatamatrixDetectorResult;
|
||||
@@ -101,13 +101,13 @@ impl<'a> Detector<'_> {
|
||||
))
|
||||
}
|
||||
|
||||
fn shiftPoint(point: RXingResultPoint, to: RXingResultPoint, div: u32) -> RXingResultPoint {
|
||||
fn shiftPoint(point: Point, to: Point, div: u32) -> Point {
|
||||
let x = (to.getX() - point.getX()) / (div as f32 + 1.0);
|
||||
let y = (to.getY() - point.getY()) / (div as f32 + 1.0);
|
||||
RXingResultPoint::new(point.getX() + x, point.getY() + y)
|
||||
Point::new(point.getX() + x, point.getY() + y)
|
||||
}
|
||||
|
||||
fn moveAway(point: RXingResultPoint, fromX: f32, fromY: f32) -> RXingResultPoint {
|
||||
fn moveAway(point: Point, fromX: f32, fromY: f32) -> Point {
|
||||
let mut x = point.getX();
|
||||
let mut y = point.getY();
|
||||
|
||||
@@ -123,13 +123,13 @@ impl<'a> Detector<'_> {
|
||||
y += 1.0;
|
||||
}
|
||||
|
||||
RXingResultPoint::new(x, y)
|
||||
Point::new(x, y)
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect a solid side which has minimum transition.
|
||||
*/
|
||||
fn detectSolid1(&self, cornerPoints: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] {
|
||||
fn detectSolid1(&self, cornerPoints: [Point; 4]) -> [Point; 4] {
|
||||
// 0 2
|
||||
// 1 3
|
||||
let pointA = cornerPoints[0];
|
||||
@@ -174,7 +174,7 @@ impl<'a> Detector<'_> {
|
||||
/**
|
||||
* Detect a second solid side next to first solid side.
|
||||
*/
|
||||
fn detectSolid2(&self, points: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] {
|
||||
fn detectSolid2(&self, points: [Point; 4]) -> [Point; 4] {
|
||||
// A..D
|
||||
// : :
|
||||
// B--C
|
||||
@@ -214,7 +214,7 @@ impl<'a> Detector<'_> {
|
||||
/**
|
||||
* Calculates the corner position of the white top right module.
|
||||
*/
|
||||
fn correctTopRight(&self, points: &[RXingResultPoint; 4]) -> Option<RXingResultPoint> {
|
||||
fn correctTopRight(&self, points: &[Point; 4]) -> Option<Point> {
|
||||
// A..D
|
||||
// | :
|
||||
// B--C
|
||||
@@ -232,11 +232,11 @@ impl<'a> Detector<'_> {
|
||||
trTop = self.transitionsBetween(pointAs, pointD);
|
||||
trRight = self.transitionsBetween(pointCs, pointD);
|
||||
|
||||
let candidate1 = RXingResultPoint::new(
|
||||
let candidate1 = Point::new(
|
||||
pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop as f32 + 1.0),
|
||||
pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop as f32 + 1.0),
|
||||
);
|
||||
let candidate2 = RXingResultPoint::new(
|
||||
let candidate2 = Point::new(
|
||||
pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight as f32 + 1.0),
|
||||
pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight as f32 + 1.0),
|
||||
);
|
||||
@@ -266,7 +266,7 @@ impl<'a> Detector<'_> {
|
||||
/**
|
||||
* Shift the edge points to the module center.
|
||||
*/
|
||||
fn shiftToModuleCenter(&self, points: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] {
|
||||
fn shiftToModuleCenter(&self, points: [Point; 4]) -> [Point; 4] {
|
||||
// A..D
|
||||
// | :
|
||||
// B--C
|
||||
@@ -318,7 +318,7 @@ impl<'a> Detector<'_> {
|
||||
[pointAs, pointBs, pointCs, pointDs]
|
||||
}
|
||||
|
||||
fn isValid(&self, p: RXingResultPoint) -> bool {
|
||||
fn isValid(&self, p: Point) -> bool {
|
||||
p.getX() >= 0.0
|
||||
&& p.getX() <= self.image.getWidth() as f32 - 1.0
|
||||
&& p.getY() > 0.0
|
||||
@@ -327,10 +327,10 @@ impl<'a> Detector<'_> {
|
||||
|
||||
fn sampleGrid(
|
||||
image: &BitMatrix,
|
||||
topLeft: RXingResultPoint,
|
||||
bottomLeft: RXingResultPoint,
|
||||
bottomRight: RXingResultPoint,
|
||||
topRight: RXingResultPoint,
|
||||
topLeft: Point,
|
||||
bottomLeft: Point,
|
||||
bottomRight: Point,
|
||||
topRight: Point,
|
||||
dimensionX: u32,
|
||||
dimensionY: u32,
|
||||
) -> Result<BitMatrix> {
|
||||
@@ -362,7 +362,7 @@ impl<'a> Detector<'_> {
|
||||
/**
|
||||
* Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.
|
||||
*/
|
||||
fn transitionsBetween(&self, from: RXingResultPoint, to: RXingResultPoint) -> u32 {
|
||||
fn transitionsBetween(&self, from: Point, to: Point) -> u32 {
|
||||
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
|
||||
let mut fromX = from.getX().floor() as i32;
|
||||
let mut fromY = from.getY().floor() as i32;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::{
|
||||
common::{BitMatrix, DetectorRXingResult},
|
||||
RXingResultPoint,
|
||||
Point,
|
||||
};
|
||||
|
||||
pub struct DatamatrixDetectorResult(BitMatrix, Vec<RXingResultPoint>);
|
||||
pub struct DatamatrixDetectorResult(BitMatrix, Vec<Point>);
|
||||
|
||||
impl DatamatrixDetectorResult {
|
||||
pub fn new(bits: BitMatrix, points: Vec<RXingResultPoint>) -> Self {
|
||||
pub fn new(bits: BitMatrix, points: Vec<Point>) -> Self {
|
||||
Self(bits, points)
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ impl DetectorRXingResult for DatamatrixDetectorResult {
|
||||
&self.0
|
||||
}
|
||||
|
||||
fn getPoints(&self) -> &[RXingResultPoint] {
|
||||
fn getPoints(&self) -> &[Point] {
|
||||
&self.1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::RXingResultPoint;
|
||||
use crate::Point;
|
||||
|
||||
use super::{util::opposite, Direction, Value};
|
||||
|
||||
@@ -16,28 +16,28 @@ pub trait BitMatrixCursor {
|
||||
|
||||
// BitMatrixCursor(const BitMatrix& image, POINT p, POINT d) : img(&image), p(p) { setDirection(d); }
|
||||
|
||||
fn testAt(&self, p: RXingResultPoint) -> Value; //const
|
||||
fn testAt(&self, p: Point) -> Value; //const
|
||||
// {
|
||||
// return img->isIn(p) ? Value{img->get(p)} : Value{};
|
||||
// }
|
||||
|
||||
fn blackAt(&self, pos: RXingResultPoint) -> bool {
|
||||
fn blackAt(&self, pos: Point) -> bool {
|
||||
self.testAt(pos).isBlack()
|
||||
}
|
||||
fn whiteAt(&self, pos: RXingResultPoint) -> bool {
|
||||
fn whiteAt(&self, pos: Point) -> bool {
|
||||
self.testAt(pos).isWhite()
|
||||
}
|
||||
|
||||
fn isIn(&self, p: RXingResultPoint) -> bool; // { return img->isIn(p); }
|
||||
fn isIn(&self, p: Point) -> bool; // { return img->isIn(p); }
|
||||
fn isInSelf(&self) -> bool; // { return self.isIn(p); }
|
||||
fn isBlack(&self) -> bool; // { return blackAt(p); }
|
||||
fn isWhite(&self) -> bool; // { return whiteAt(p); }
|
||||
|
||||
fn front(&self) -> &RXingResultPoint; //{ return d; }
|
||||
fn back(&self) -> RXingResultPoint; // { return {-d.x, -d.y}; }
|
||||
fn left(&self) -> RXingResultPoint; //{ return {d.y, -d.x}; }
|
||||
fn right(&self) -> RXingResultPoint; //{ return {-d.y, d.x}; }
|
||||
fn direction(&self, dir: Direction) -> RXingResultPoint {
|
||||
fn front(&self) -> &Point; //{ return d; }
|
||||
fn back(&self) -> Point; // { return {-d.x, -d.y}; }
|
||||
fn left(&self) -> Point; //{ return {d.y, -d.x}; }
|
||||
fn right(&self) -> Point; //{ return {-d.y, d.x}; }
|
||||
fn direction(&self, dir: Direction) -> Point {
|
||||
self.right() * Into::<i32>::into(dir)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub trait BitMatrixCursor {
|
||||
fn turnRight(&mut self); //noexcept { d = right(); }
|
||||
fn turn(&mut self, dir: Direction); //noexcept { d = direction(dir); }
|
||||
|
||||
fn edgeAt_point(&self, d: RXingResultPoint) -> Value;
|
||||
fn edgeAt_point(&self, d: Point) -> Value;
|
||||
// {
|
||||
// Value v = testAt(p);
|
||||
// return testAt(p + d) != v ? v : Value();
|
||||
@@ -68,8 +68,8 @@ pub trait BitMatrixCursor {
|
||||
self.edgeAt_point(self.direction(dir))
|
||||
}
|
||||
|
||||
fn setDirection(&mut self, dir: RXingResultPoint); // { d = bresenhamDirection(dir); }
|
||||
// fn setDirection(&self, dir: RXingResultPoint);// { d = dir; }
|
||||
fn setDirection(&mut self, dir: Point); // { d = bresenhamDirection(dir); }
|
||||
// fn setDirection(&self, dir: Point);// { d = dir; }
|
||||
|
||||
fn step(&mut self, s: Option<f32>) -> bool; // DEF to 1
|
||||
// {
|
||||
@@ -77,7 +77,7 @@ pub trait BitMatrixCursor {
|
||||
// return isIn(p);
|
||||
// }
|
||||
|
||||
fn movedBy<T: BitMatrixCursor>(self, d: RXingResultPoint) -> Self;
|
||||
fn movedBy<T: BitMatrixCursor>(self, d: Point) -> Self;
|
||||
// {
|
||||
// auto res = *this;
|
||||
// res.p += d;
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::{
|
||||
},
|
||||
qrcode::encoder::ByteMatrix,
|
||||
result_point_utils::distance,
|
||||
Exceptions, RXingResultPoint, ResultPoint,
|
||||
Exceptions, Point, ResultPoint,
|
||||
};
|
||||
|
||||
use super::{DMRegressionLine, EdgeTracer};
|
||||
@@ -46,10 +46,10 @@ fn Scan(
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut tl = RXingResultPoint::default();
|
||||
let mut bl = RXingResultPoint::default();
|
||||
let mut br = RXingResultPoint::default();
|
||||
let mut tr = RXingResultPoint::default();
|
||||
let mut tl = Point::default();
|
||||
let mut bl = Point::default();
|
||||
let mut br = Point::default();
|
||||
let mut tr = Point::default();
|
||||
|
||||
for l in lines.iter_mut() {
|
||||
l.reset();
|
||||
@@ -197,13 +197,13 @@ fn Scan(
|
||||
|
||||
CHECK!((10..=144).contains(&dimT) && (8..=144).contains(&dimR));
|
||||
|
||||
let movedTowardsBy = |a: RXingResultPoint,
|
||||
b1: RXingResultPoint,
|
||||
b2: RXingResultPoint,
|
||||
let movedTowardsBy = |a: Point,
|
||||
b1: Point,
|
||||
b2: Point,
|
||||
d: f32|
|
||||
-> RXingResultPoint {
|
||||
a + d * RXingResultPoint::normalized(
|
||||
RXingResultPoint::normalized(b1 - a) + RXingResultPoint::normalized(b2 - a),
|
||||
-> Point {
|
||||
a + d * Point::normalized(
|
||||
Point::normalized(b1 - a) + Point::normalized(b2 - a),
|
||||
)
|
||||
};
|
||||
|
||||
@@ -292,18 +292,18 @@ pub fn detect(
|
||||
const MIN_SYMBOL_SIZE: u32 = 8 * 2; // minimum realistic size in pixel: 8 modules x 2 pixels per module
|
||||
|
||||
for dir in [
|
||||
RXingResultPoint { x: -1.0, y: 0.0 },
|
||||
RXingResultPoint { x: 1.0, y: 0.0 },
|
||||
RXingResultPoint { x: 0.0, y: -1.0 },
|
||||
RXingResultPoint { x: 0.0, y: 1.0 },
|
||||
Point { x: -1.0, y: 0.0 },
|
||||
Point { x: 1.0, y: 0.0 },
|
||||
Point { x: 0.0, y: -1.0 },
|
||||
Point { x: 0.0, y: 1.0 },
|
||||
] {
|
||||
// for (auto dir : {PointF(-1, 0), PointF(1, 0), PointF(0, -1), PointF(0, 1)}) {
|
||||
let center = RXingResultPoint {
|
||||
let center = Point {
|
||||
x: (image.getWidth() / 2) as f32,
|
||||
y: (image.getHeight() / 2) as f32,
|
||||
}; //PointF(image.width() / 2, image.height() / 2);
|
||||
let startPos =
|
||||
RXingResultPoint::centered(center - center * dir + MIN_SYMBOL_SIZE as i32 / 2 * dir);
|
||||
Point::centered(center - center * dir + MIN_SYMBOL_SIZE as i32 / 2 * dir);
|
||||
|
||||
if let Some(history) = &mut history {
|
||||
history.borrow_mut().clear(0);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::common::Result;
|
||||
use crate::{Exceptions, RXingResultPoint};
|
||||
use crate::{Exceptions, Point};
|
||||
|
||||
use super::{
|
||||
util::{float_max, float_min},
|
||||
@@ -8,8 +8,8 @@ use super::{
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DMRegressionLine {
|
||||
points: Vec<RXingResultPoint>,
|
||||
direction_inward: RXingResultPoint,
|
||||
points: Vec<Point>,
|
||||
direction_inward: Point,
|
||||
pub(super) a: f32,
|
||||
pub(super) b: f32,
|
||||
pub(super) c: f32,
|
||||
@@ -31,13 +31,13 @@ impl Default for DMRegressionLine {
|
||||
}
|
||||
|
||||
impl RegressionLine for DMRegressionLine {
|
||||
fn points(&self) -> &[RXingResultPoint] {
|
||||
fn points(&self) -> &[Point] {
|
||||
&self.points
|
||||
}
|
||||
|
||||
fn length(&self) -> u32 {
|
||||
if self.points.len() >= 2 {
|
||||
RXingResultPoint::distance(*self.points.first().unwrap(), *self.points.last().unwrap())
|
||||
Point::distance(*self.points.first().unwrap(), *self.points.last().unwrap())
|
||||
as u32
|
||||
} else {
|
||||
0
|
||||
@@ -48,9 +48,9 @@ impl RegressionLine for DMRegressionLine {
|
||||
!self.a.is_nan()
|
||||
}
|
||||
|
||||
fn normal(&self) -> RXingResultPoint {
|
||||
fn normal(&self) -> Point {
|
||||
if self.isValid() {
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: self.a,
|
||||
y: self.b,
|
||||
}
|
||||
@@ -59,29 +59,29 @@ impl RegressionLine for DMRegressionLine {
|
||||
}
|
||||
}
|
||||
|
||||
fn signedDistance(&self, p: RXingResultPoint) -> f32 {
|
||||
RXingResultPoint::dot(self.normal(), p) - self.c
|
||||
fn signedDistance(&self, p: Point) -> f32 {
|
||||
Point::dot(self.normal(), p) - self.c
|
||||
}
|
||||
|
||||
fn distance_single(&self, p: RXingResultPoint) -> f32 {
|
||||
fn distance_single(&self, p: Point) -> f32 {
|
||||
(self.signedDistance(p)).abs()
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
self.points.clear();
|
||||
self.direction_inward = RXingResultPoint { x: 0.0, y: 0.0 };
|
||||
self.direction_inward = Point { x: 0.0, y: 0.0 };
|
||||
self.a = f32::NAN;
|
||||
self.b = f32::NAN;
|
||||
self.c = f32::NAN;
|
||||
}
|
||||
|
||||
fn add(&mut self, p: RXingResultPoint) -> Result<()> {
|
||||
if self.direction_inward == RXingResultPoint::default() {
|
||||
fn add(&mut self, p: Point) -> Result<()> {
|
||||
if self.direction_inward == Point::default() {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
}
|
||||
self.points.push(p);
|
||||
if self.points.len() == 1 {
|
||||
self.c = RXingResultPoint::dot(self.normal(), p);
|
||||
self.c = Point::dot(self.normal(), p);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -90,8 +90,8 @@ impl RegressionLine for DMRegressionLine {
|
||||
self.points.pop();
|
||||
}
|
||||
|
||||
fn setDirectionInward(&mut self, d: RXingResultPoint) {
|
||||
self.direction_inward = RXingResultPoint::normalized(d);
|
||||
fn setDirectionInward(&mut self, d: Point) {
|
||||
self.direction_inward = Point::normalized(d);
|
||||
}
|
||||
|
||||
fn evaluate_max_distance(
|
||||
@@ -149,8 +149,8 @@ impl RegressionLine for DMRegressionLine {
|
||||
steps > 2.0 || len > 50.0
|
||||
}
|
||||
|
||||
fn evaluate(&mut self, points: &[RXingResultPoint]) -> bool {
|
||||
let mean = points.iter().sum::<RXingResultPoint>() / points.len() as f32;
|
||||
fn evaluate(&mut self, points: &[Point]) -> bool {
|
||||
let mean = points.iter().sum::<Point>() / points.len() as f32;
|
||||
|
||||
let mut sumXX = 0.0;
|
||||
let mut sumYY = 0.0;
|
||||
@@ -171,18 +171,18 @@ impl RegressionLine for DMRegressionLine {
|
||||
self.a = sumXY / l;
|
||||
self.b = -sumXX / l;
|
||||
}
|
||||
if RXingResultPoint::dot(self.direction_inward, self.normal()) < 0.0 {
|
||||
if Point::dot(self.direction_inward, self.normal()) < 0.0 {
|
||||
// if (dot(_directionInward, normal()) < 0) {
|
||||
self.a = -self.a;
|
||||
self.b = -self.b;
|
||||
}
|
||||
self.c = RXingResultPoint::dot(self.normal(), mean); // (a*mean.x + b*mean.y);
|
||||
RXingResultPoint::dot(self.direction_inward, self.normal()) > 0.5
|
||||
self.c = Point::dot(self.normal(), mean); // (a*mean.x + b*mean.y);
|
||||
Point::dot(self.direction_inward, self.normal()) > 0.5
|
||||
// angle between original and new direction is at most 60 degree
|
||||
}
|
||||
|
||||
fn evaluateSelf(&mut self) -> bool {
|
||||
let mean = self.points.iter().sum::<RXingResultPoint>() / self.points.len() as f32;
|
||||
let mean = self.points.iter().sum::<Point>() / self.points.len() as f32;
|
||||
|
||||
let mut sumXX = 0.0;
|
||||
let mut sumYY = 0.0;
|
||||
@@ -203,13 +203,13 @@ impl RegressionLine for DMRegressionLine {
|
||||
self.a = sumXY / l;
|
||||
self.b = -sumXX / l;
|
||||
}
|
||||
if RXingResultPoint::dot(self.direction_inward, self.normal()) < 0.0 {
|
||||
if Point::dot(self.direction_inward, self.normal()) < 0.0 {
|
||||
// if (dot(_directionInward, normal()) < 0) {
|
||||
self.a = -self.a;
|
||||
self.b = -self.b;
|
||||
}
|
||||
self.c = RXingResultPoint::dot(self.normal(), mean); // (a*mean.x + b*mean.y);
|
||||
RXingResultPoint::dot(self.direction_inward, self.normal()) > 0.5
|
||||
self.c = Point::dot(self.normal(), mean); // (a*mean.x + b*mean.y);
|
||||
Point::dot(self.direction_inward, self.normal()) > 0.5
|
||||
// angle between original and new direction is at most 60 degree
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,7 @@ impl DMRegressionLine {
|
||||
self.points.reverse();
|
||||
}
|
||||
|
||||
pub fn modules(&mut self, beg: RXingResultPoint, end: RXingResultPoint) -> Result<f64> {
|
||||
pub fn modules(&mut self, beg: Point, end: Point) -> Result<f64> {
|
||||
if self.points.len() <= 3 {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
}
|
||||
@@ -260,7 +260,7 @@ impl DMRegressionLine {
|
||||
}
|
||||
|
||||
// calculate the (expected average) distance of two adjacent pixels
|
||||
let unitPixelDist = RXingResultPoint::length(RXingResultPoint::bresenhamDirection(
|
||||
let unitPixelDist = Point::length(Point::bresenhamDirection(
|
||||
self.points
|
||||
.last()
|
||||
.copied()
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
|
||||
use crate::{
|
||||
common::{BitMatrix, Result},
|
||||
qrcode::encoder::ByteMatrix,
|
||||
Exceptions, RXingResultPoint,
|
||||
Exceptions, Point,
|
||||
};
|
||||
|
||||
use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value};
|
||||
@@ -12,8 +12,8 @@ use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value};
|
||||
pub struct EdgeTracer<'a> {
|
||||
pub(super) img: &'a BitMatrix,
|
||||
|
||||
pub(super) p: RXingResultPoint, // current position
|
||||
d: RXingResultPoint, // current direction
|
||||
pub(super) p: Point, // current position
|
||||
d: Point, // current direction
|
||||
|
||||
// pub history: Option<&'a mut ByteMatrix>, // = nullptr;
|
||||
pub history: Option<Rc<RefCell<ByteMatrix>>>,
|
||||
@@ -35,7 +35,7 @@ pub struct EdgeTracer<'a> {
|
||||
// }
|
||||
|
||||
impl BitMatrixCursor for EdgeTracer<'_> {
|
||||
fn testAt(&self, p: RXingResultPoint) -> Value {
|
||||
fn testAt(&self, p: Point) -> Value {
|
||||
if self.img.isIn(p, 0) {
|
||||
Value::from(self.img.get_point(p))
|
||||
} else {
|
||||
@@ -43,7 +43,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn isIn(&self, p: RXingResultPoint) -> bool {
|
||||
fn isIn(&self, p: Point) -> bool {
|
||||
self.img.isIn(p, 0)
|
||||
}
|
||||
|
||||
@@ -59,26 +59,26 @@ impl BitMatrixCursor for EdgeTracer<'_> {
|
||||
self.whiteAt(self.p)
|
||||
}
|
||||
|
||||
fn front(&self) -> &RXingResultPoint {
|
||||
fn front(&self) -> &Point {
|
||||
&self.d
|
||||
}
|
||||
|
||||
fn back(&self) -> RXingResultPoint {
|
||||
RXingResultPoint {
|
||||
fn back(&self) -> Point {
|
||||
Point {
|
||||
x: -self.d.x,
|
||||
y: -self.d.y,
|
||||
}
|
||||
}
|
||||
|
||||
fn left(&self) -> RXingResultPoint {
|
||||
RXingResultPoint {
|
||||
fn left(&self) -> Point {
|
||||
Point {
|
||||
x: self.d.y,
|
||||
y: -self.d.x,
|
||||
}
|
||||
}
|
||||
|
||||
fn right(&self) -> RXingResultPoint {
|
||||
RXingResultPoint {
|
||||
fn right(&self) -> Point {
|
||||
Point {
|
||||
x: -self.d.y,
|
||||
y: self.d.x,
|
||||
}
|
||||
@@ -100,7 +100,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
|
||||
self.d = self.direction(dir)
|
||||
}
|
||||
|
||||
fn edgeAt_point(&self, d: RXingResultPoint) -> Value {
|
||||
fn edgeAt_point(&self, d: Point) -> Value {
|
||||
let v = self.testAt(self.p);
|
||||
if self.testAt(self.p + d) != v {
|
||||
v
|
||||
@@ -109,7 +109,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn setDirection(&mut self, dir: RXingResultPoint) {
|
||||
fn setDirection(&mut self, dir: Point) {
|
||||
self.d = dir.bresenhamDirection();
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
|
||||
self.isIn(self.p)
|
||||
}
|
||||
|
||||
fn movedBy<T: BitMatrixCursor>(self, d: RXingResultPoint) -> Self {
|
||||
fn movedBy<T: BitMatrixCursor>(self, d: Point) -> Self {
|
||||
let mut res = self;
|
||||
res.p += d;
|
||||
|
||||
@@ -158,7 +158,7 @@ impl BitMatrixCursor for EdgeTracer<'_> {
|
||||
}
|
||||
|
||||
impl<'a> EdgeTracer<'_> {
|
||||
pub fn new(image: &'a BitMatrix, p: RXingResultPoint, d: RXingResultPoint) -> EdgeTracer<'a> {
|
||||
pub fn new(image: &'a BitMatrix, p: Point, d: Point) -> EdgeTracer<'a> {
|
||||
// : img(&image), p(p) { setDirection(d); }
|
||||
EdgeTracer {
|
||||
img: image,
|
||||
@@ -171,11 +171,11 @@ impl<'a> EdgeTracer<'_> {
|
||||
|
||||
fn traceStep(
|
||||
&mut self,
|
||||
dEdge: RXingResultPoint,
|
||||
dEdge: Point,
|
||||
maxStepSize: i32,
|
||||
goodDirection: bool,
|
||||
) -> Result<StepResult> {
|
||||
let dEdge = RXingResultPoint::mainDirection(dEdge);
|
||||
let dEdge = Point::mainDirection(dEdge);
|
||||
for breadth in 1..=(if maxStepSize == 1 {
|
||||
2
|
||||
} else if goodDirection {
|
||||
@@ -243,28 +243,28 @@ impl<'a> EdgeTracer<'_> {
|
||||
Ok(StepResult::OpenEnd)
|
||||
}
|
||||
|
||||
pub fn updateDirectionFromOrigin(&mut self, origin: RXingResultPoint) -> bool {
|
||||
pub fn updateDirectionFromOrigin(&mut self, origin: Point) -> bool {
|
||||
let old_d = self.d;
|
||||
self.setDirection(self.p - origin);
|
||||
// if the new direction is pointing "backward", i.e. angle(new, old) > 90 deg -> break
|
||||
if RXingResultPoint::dot(self.d, old_d) < 0.0 {
|
||||
if Point::dot(self.d, old_d) < 0.0 {
|
||||
return false;
|
||||
}
|
||||
// make sure d stays in the same quadrant to prevent an infinite loop
|
||||
if (self.d.x).abs() == (self.d.y).abs() {
|
||||
self.d = RXingResultPoint::mainDirection(old_d)
|
||||
+ 0.99 * (self.d - RXingResultPoint::mainDirection(old_d));
|
||||
} else if RXingResultPoint::mainDirection(self.d) != RXingResultPoint::mainDirection(old_d)
|
||||
self.d = Point::mainDirection(old_d)
|
||||
+ 0.99 * (self.d - Point::mainDirection(old_d));
|
||||
} else if Point::mainDirection(self.d) != Point::mainDirection(old_d)
|
||||
{
|
||||
self.d = RXingResultPoint::mainDirection(old_d)
|
||||
+ 0.99 * RXingResultPoint::mainDirection(self.d);
|
||||
self.d = Point::mainDirection(old_d)
|
||||
+ 0.99 * Point::mainDirection(self.d);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn traceLine<T: RegressionLine>(
|
||||
&mut self,
|
||||
dEdge: RXingResultPoint,
|
||||
dEdge: Point,
|
||||
line: &mut T,
|
||||
) -> Result<bool> {
|
||||
line.setDirectionInward(dEdge);
|
||||
@@ -295,7 +295,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
|
||||
pub fn traceGaps<T: RegressionLine>(
|
||||
&mut self,
|
||||
dEdge: RXingResultPoint,
|
||||
dEdge: Point,
|
||||
line: &mut T,
|
||||
maxStepSize: i32,
|
||||
finishLine: &mut T,
|
||||
@@ -341,7 +341,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
// In case the 'go outward' step in traceStep lead us astray, we might end up with a line
|
||||
// that is almost perpendicular to d. Then the back-projection below can result in an
|
||||
// endless loop. Break if the angle between d and line is greater than 45 deg.
|
||||
if (RXingResultPoint::dot(RXingResultPoint::normalized(self.d), line.normal()))
|
||||
if (Point::dot(Point::normalized(self.d), line.normal()))
|
||||
.abs()
|
||||
> 0.7
|
||||
// thresh is approx. sin(45 deg)
|
||||
@@ -361,7 +361,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
// The 'while' instead of 'if' was introduced to fix the issue with #245. It turns out that
|
||||
// np can actually be behind the projection of the last line point and we need 2 steps in d
|
||||
// to prevent a dead lock. see #245.png
|
||||
while RXingResultPoint::distance(
|
||||
while Point::distance(
|
||||
np,
|
||||
line.project(
|
||||
line.points()
|
||||
@@ -373,13 +373,13 @@ impl<'a> EdgeTracer<'_> {
|
||||
{
|
||||
np += self.d;
|
||||
}
|
||||
self.p = RXingResultPoint::centered(np);
|
||||
self.p = Point::centered(np);
|
||||
} else {
|
||||
let stepLengthInMainDir = if line.points().is_empty() {
|
||||
0.0
|
||||
} else {
|
||||
RXingResultPoint::dot(
|
||||
RXingResultPoint::mainDirection(self.d),
|
||||
Point::dot(
|
||||
Point::mainDirection(self.d),
|
||||
self.p
|
||||
- line
|
||||
.points()
|
||||
@@ -441,8 +441,8 @@ impl<'a> EdgeTracer<'_> {
|
||||
|
||||
pub fn traceCorner(
|
||||
&mut self,
|
||||
dir: &mut RXingResultPoint,
|
||||
corner: &mut RXingResultPoint,
|
||||
dir: &mut Point,
|
||||
corner: &mut Point,
|
||||
) -> Result<bool> {
|
||||
self.step(None);
|
||||
// log(p);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::RXingResultPoint;
|
||||
use crate::Point;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Quadrilateral([RXingResultPoint; 4]);
|
||||
pub struct Quadrilateral([Point; 4]);
|
||||
|
||||
impl Quadrilateral {
|
||||
// using Base = std::array<T, 4>;
|
||||
@@ -11,31 +11,31 @@ impl Quadrilateral {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn new() -> Self {
|
||||
Self([RXingResultPoint { x: 0.0, y: 0.0 }; 4])
|
||||
Self([Point { x: 0.0, y: 0.0 }; 4])
|
||||
}
|
||||
// pub fn with_f32( tl:f32, tr:f32, br:f32, bl:f32) -> Self {
|
||||
// Self([tl, tr,br, bl ])
|
||||
// }
|
||||
|
||||
pub fn with_points(
|
||||
tl: RXingResultPoint,
|
||||
tr: RXingResultPoint,
|
||||
br: RXingResultPoint,
|
||||
bl: RXingResultPoint,
|
||||
tl: Point,
|
||||
tr: Point,
|
||||
br: Point,
|
||||
bl: Point,
|
||||
) -> Self {
|
||||
Self([tl, tr, br, bl])
|
||||
}
|
||||
|
||||
pub fn topLeft(&self) -> &RXingResultPoint {
|
||||
pub fn topLeft(&self) -> &Point {
|
||||
&self.0[0]
|
||||
} //const noexcept { return at(0); }
|
||||
pub fn topRight(&self) -> &RXingResultPoint {
|
||||
pub fn topRight(&self) -> &Point {
|
||||
&self.0[1]
|
||||
} //const noexcept { return at(1); }
|
||||
pub fn bottomRight(&self) -> &RXingResultPoint {
|
||||
pub fn bottomRight(&self) -> &Point {
|
||||
&self.0[2]
|
||||
} //const noexcept { return at(2); }
|
||||
pub fn bottomLeft(&self) -> &RXingResultPoint {
|
||||
pub fn bottomLeft(&self) -> &Point {
|
||||
&self.0[3]
|
||||
} //const noexcept { return at(3); }
|
||||
|
||||
@@ -43,13 +43,13 @@ impl Quadrilateral {
|
||||
pub fn orientation(&self) -> f64 {
|
||||
let centerLine =
|
||||
(*self.topRight() + *self.bottomRight()) - (*self.topLeft() + *self.bottomLeft());
|
||||
if (centerLine == RXingResultPoint { x: 0.0, y: 0.0 }) {
|
||||
if (centerLine == Point { x: 0.0, y: 0.0 }) {
|
||||
return 0.0;
|
||||
}
|
||||
let centerLineF = RXingResultPoint::normalized(centerLine);
|
||||
let centerLineF = Point::normalized(centerLine);
|
||||
f32::atan2(centerLineF.y, centerLineF.x).into()
|
||||
}
|
||||
pub fn points(&self) -> &[RXingResultPoint] {
|
||||
pub fn points(&self) -> &[Point] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
@@ -59,19 +59,19 @@ pub fn Rectangle(width: i32, height: i32, margin: Option<i32>) -> Quadrilateral
|
||||
let margin = if let Some(m) = margin { m } else { 0 };
|
||||
|
||||
Quadrilateral([
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: margin as f32,
|
||||
y: margin as f32,
|
||||
},
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: width as f32 - margin as f32,
|
||||
y: margin as f32,
|
||||
},
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: width as f32 - margin as f32,
|
||||
y: height as f32 - margin as f32,
|
||||
},
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: margin as f32,
|
||||
y: height as f32 - margin as f32,
|
||||
},
|
||||
@@ -82,10 +82,10 @@ pub fn Rectangle(width: i32, height: i32, margin: Option<i32>) -> Quadrilateral
|
||||
pub fn CenteredSquare(size: i32) -> Quadrilateral {
|
||||
Scale(
|
||||
&Quadrilateral([
|
||||
RXingResultPoint { x: -1.0, y: -1.0 },
|
||||
RXingResultPoint { x: 1.0, y: -1.0 },
|
||||
RXingResultPoint { x: 1.0, y: 1.0 },
|
||||
RXingResultPoint { x: -1.0, y: 1.0 },
|
||||
Point { x: -1.0, y: -1.0 },
|
||||
Point { x: 1.0, y: -1.0 },
|
||||
Point { x: 1.0, y: 1.0 },
|
||||
Point { x: -1.0, y: 1.0 },
|
||||
]),
|
||||
size / 2,
|
||||
)
|
||||
@@ -94,19 +94,19 @@ pub fn CenteredSquare(size: i32) -> Quadrilateral {
|
||||
#[allow(dead_code)]
|
||||
pub fn Line(y: i32, xStart: i32, xStop: i32) -> Quadrilateral {
|
||||
Quadrilateral([
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: xStart as f32,
|
||||
y: y as f32,
|
||||
},
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: xStop as f32,
|
||||
y: y as f32,
|
||||
},
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: xStop as f32,
|
||||
y: y as f32,
|
||||
},
|
||||
RXingResultPoint {
|
||||
Point {
|
||||
x: xStart as f32,
|
||||
y: y as f32,
|
||||
},
|
||||
@@ -162,8 +162,8 @@ pub fn Scale(q: &Quadrilateral, factor: i32) -> Quadrilateral {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn Center(q: &Quadrilateral) -> RXingResultPoint {
|
||||
let reduced: RXingResultPoint = q.0.iter().sum();
|
||||
pub fn Center(q: &Quadrilateral) -> Point {
|
||||
let reduced: Point = q.0.iter().sum();
|
||||
let size = q.0.len() as f32;
|
||||
reduced / size
|
||||
// return Reduce(q) / Size(q);
|
||||
@@ -186,14 +186,14 @@ pub fn RotatedCorners(q: &Quadrilateral, n: Option<i32>, mirror: Option<bool>) -
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn IsInside(p: RXingResultPoint, q: &Quadrilateral) -> bool {
|
||||
pub fn IsInside(p: Point, q: &Quadrilateral) -> bool {
|
||||
// Test if p is on the same side (right or left) of all polygon segments
|
||||
let mut pos = 0;
|
||||
let mut neg = 0;
|
||||
for i in 0..q.0.len()
|
||||
// for (int i = 0; i < Size(q); ++i)
|
||||
{
|
||||
if RXingResultPoint::cross(p - q.0[i], q.0[(i + 1) % q.0.len()] - q.0[i]) < 0.0 {
|
||||
if Point::cross(p - q.0[i], q.0[(i + 1) % q.0.len()] - q.0[i]) < 0.0 {
|
||||
neg += 1;
|
||||
} else {
|
||||
pos += 1;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::common::Result;
|
||||
use crate::RXingResultPoint;
|
||||
use crate::Point;
|
||||
|
||||
pub trait RegressionLine {
|
||||
// points: Vec<RXingResultPoint>,
|
||||
// direction_inward: RXingResultPoint,
|
||||
// points: Vec<Point>,
|
||||
// direction_inward: Point,
|
||||
|
||||
// }
|
||||
// impl RegressionLine {
|
||||
@@ -12,9 +12,9 @@ pub trait RegressionLine {
|
||||
// PointF::value_t a = NAN, b = NAN, c = NAN;
|
||||
|
||||
// fn intersect<T: RegressionLine, T2: RegressionLine>(&self, l1: &T, l2: &T2)
|
||||
// -> RXingResultPoint;
|
||||
// -> Point;
|
||||
|
||||
// fn evaluate_begin_end(&self, begin: RXingResultPoint, end: RXingResultPoint) -> bool;// {
|
||||
// fn evaluate_begin_end(&self, begin: Point, end: Point) -> bool;// {
|
||||
// {
|
||||
// let mean = std::accumulate(begin, end, PointF()) / std::distance(begin, end);
|
||||
// PointF::value_t sumXX = 0, sumYY = 0, sumXY = 0;
|
||||
@@ -41,10 +41,10 @@ pub trait RegressionLine {
|
||||
// return dot(_directionInward, normal()) > 0.5f; // angle between original and new direction is at most 60 degree
|
||||
// }
|
||||
|
||||
fn evaluate(&mut self, points: &[RXingResultPoint]) -> bool; // { return self.evaluate_begin_end(&points.front(), &points.back() + 1); }
|
||||
fn evaluate(&mut self, points: &[Point]) -> bool; // { return self.evaluate_begin_end(&points.front(), &points.back() + 1); }
|
||||
fn evaluateSelf(&mut self) -> bool;
|
||||
|
||||
fn distance(&self, a: RXingResultPoint, b: RXingResultPoint) -> f32 {
|
||||
fn distance(&self, a: Point, b: Point) -> f32 {
|
||||
crate::result_point_utils::distance(&a, &b)
|
||||
}
|
||||
|
||||
@@ -60,13 +60,13 @@ pub trait RegressionLine {
|
||||
// evaluate(b, e);
|
||||
// }
|
||||
|
||||
fn points(&self) -> &[RXingResultPoint]; //const { return _points; }
|
||||
fn points(&self) -> &[Point]; //const { return _points; }
|
||||
fn length(&self) -> u32; //const { return _points.size() >= 2 ? int(distance(_points.front(), _points.back())) : 0; }
|
||||
fn isValid(&self) -> bool; //const { return !std::isnan(a); }
|
||||
fn normal(&self) -> RXingResultPoint; //const { return isValid() ? PointF(a, b) : _directionInward; }
|
||||
fn signedDistance(&self, p: RXingResultPoint) -> f32; //const { return dot(normal(), p) - c; }
|
||||
fn distance_single(&self, p: RXingResultPoint) -> f32; //const { return std::abs(signedDistance(PointF(p))); }
|
||||
fn project(&self, p: RXingResultPoint) -> RXingResultPoint {
|
||||
fn normal(&self) -> Point; //const { return isValid() ? PointF(a, b) : _directionInward; }
|
||||
fn signedDistance(&self, p: Point) -> f32; //const { return dot(normal(), p) - c; }
|
||||
fn distance_single(&self, p: Point) -> f32; //const { return std::abs(signedDistance(PointF(p))); }
|
||||
fn project(&self, p: Point) -> Point {
|
||||
p - self.normal() * self.signedDistance(p)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ pub trait RegressionLine {
|
||||
// a = b = c = NAN;
|
||||
// }
|
||||
|
||||
fn add(&mut self, p: RXingResultPoint) -> Result<()>; //{
|
||||
fn add(&mut self, p: Point) -> Result<()>; //{
|
||||
// assert(_directionInward != PointF());
|
||||
// _points.push_back(p);
|
||||
// if (_points.size() == 1)
|
||||
@@ -86,7 +86,7 @@ pub trait RegressionLine {
|
||||
|
||||
fn pop_back(&mut self); // { _points.pop_back(); }
|
||||
|
||||
fn setDirectionInward(&mut self, d: RXingResultPoint); //{ _directionInward = normalized(d); }
|
||||
fn setDirectionInward(&mut self, d: Point); //{ _directionInward = normalized(d); }
|
||||
|
||||
// fn evaluate(&self, double maxSignedDist = -1, bool updatePoints = false) -> bool
|
||||
fn evaluate_max_distance(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::common::Result;
|
||||
use crate::{Exceptions, RXingResultPoint};
|
||||
use crate::{Exceptions, Point};
|
||||
|
||||
use super::{DMRegressionLine, Direction, RegressionLine};
|
||||
|
||||
@@ -22,14 +22,14 @@ pub fn float_max<T: PartialOrd>(a: T, b: T) -> T {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result<RXingResultPoint> {
|
||||
pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result<Point> {
|
||||
if !(l1.isValid() && l2.isValid()) {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
}
|
||||
let d = l1.a * l2.b - l1.b * l2.a;
|
||||
let x = (l1.c * l2.b - l1.b * l2.c) / d;
|
||||
let y = (l1.a * l2.c - l1.c * l2.a) / d;
|
||||
Ok(RXingResultPoint { x, y })
|
||||
Ok(Point { x, y })
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
Reference in New Issue
Block a user