mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
cargo fmt
This commit is contained in:
@@ -17,9 +17,9 @@ pub trait BitMatrixCursor {
|
||||
// BitMatrixCursor(const BitMatrix& image, POINT p, POINT d) : img(&image), p(p) { setDirection(d); }
|
||||
|
||||
fn testAt(&self, p: Point) -> Value; //const
|
||||
// {
|
||||
// return img->isIn(p) ? Value{img->get(p)} : Value{};
|
||||
// }
|
||||
// {
|
||||
// return img->isIn(p) ? Value{img->get(p)} : Value{};
|
||||
// }
|
||||
|
||||
fn blackAt(&self, pos: Point) -> bool {
|
||||
self.testAt(pos).isBlack()
|
||||
@@ -69,7 +69,7 @@ pub trait BitMatrixCursor {
|
||||
}
|
||||
|
||||
fn setDirection(&mut self, dir: Point); // { d = bresenhamDirection(dir); }
|
||||
// fn setDirection(&self, dir: Point);// { d = dir; }
|
||||
// fn setDirection(&self, dir: Point);// { d = dir; }
|
||||
|
||||
fn step(&mut self, s: Option<f32>) -> bool; // DEF to 1
|
||||
// {
|
||||
|
||||
@@ -197,14 +197,8 @@ fn Scan(
|
||||
|
||||
CHECK!((10..=144).contains(&dimT) && (8..=144).contains(&dimR));
|
||||
|
||||
let movedTowardsBy = |a: Point,
|
||||
b1: Point,
|
||||
b2: Point,
|
||||
d: f32|
|
||||
-> Point {
|
||||
a + d * Point::normalized(
|
||||
Point::normalized(b1 - a) + Point::normalized(b2 - a),
|
||||
)
|
||||
let movedTowardsBy = |a: Point, b1: Point, b2: Point, d: f32| -> Point {
|
||||
a + d * Point::normalized(Point::normalized(b1 - a) + Point::normalized(b2 - a))
|
||||
};
|
||||
|
||||
// shrink shape by half a pixel to go from center of white pixel outside of code to the edge between white and black
|
||||
@@ -302,8 +296,7 @@ pub fn detect(
|
||||
x: (image.getWidth() / 2) as f32,
|
||||
y: (image.getHeight() / 2) as f32,
|
||||
}; //PointF(image.width() / 2, image.height() / 2);
|
||||
let startPos =
|
||||
Point::centered(center - center * dir + MIN_SYMBOL_SIZE as i32 / 2 * dir);
|
||||
let startPos = Point::centered(center - center * dir + MIN_SYMBOL_SIZE as i32 / 2 * dir);
|
||||
|
||||
if let Some(history) = &mut history {
|
||||
history.borrow_mut().clear(0);
|
||||
|
||||
@@ -37,8 +37,7 @@ impl RegressionLine for DMRegressionLine {
|
||||
|
||||
fn length(&self) -> u32 {
|
||||
if self.points.len() >= 2 {
|
||||
Point::distance(*self.points.first().unwrap(), *self.points.last().unwrap())
|
||||
as u32
|
||||
Point::distance(*self.points.first().unwrap(), *self.points.last().unwrap()) as u32
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
||||
@@ -252,21 +252,14 @@ impl<'a> EdgeTracer<'_> {
|
||||
}
|
||||
// make sure d stays in the same quadrant to prevent an infinite loop
|
||||
if (self.d.x).abs() == (self.d.y).abs() {
|
||||
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 = Point::mainDirection(old_d)
|
||||
+ 0.99 * Point::mainDirection(self.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 = Point::mainDirection(old_d) + 0.99 * Point::mainDirection(self.d);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn traceLine<T: RegressionLine>(
|
||||
&mut self,
|
||||
dEdge: Point,
|
||||
line: &mut T,
|
||||
) -> Result<bool> {
|
||||
pub fn traceLine<T: RegressionLine>(&mut self, dEdge: Point, line: &mut T) -> Result<bool> {
|
||||
line.setDirectionInward(dEdge);
|
||||
loop {
|
||||
// log(self.p);
|
||||
@@ -341,9 +334,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 (Point::dot(Point::normalized(self.d), line.normal()))
|
||||
.abs()
|
||||
> 0.7
|
||||
if (Point::dot(Point::normalized(self.d), line.normal())).abs() > 0.7
|
||||
// thresh is approx. sin(45 deg)
|
||||
{
|
||||
return Ok(false);
|
||||
@@ -439,11 +430,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
} //while (true);
|
||||
}
|
||||
|
||||
pub fn traceCorner(
|
||||
&mut self,
|
||||
dir: &mut Point,
|
||||
corner: &mut Point,
|
||||
) -> Result<bool> {
|
||||
pub fn traceCorner(&mut self, dir: &mut Point, corner: &mut Point) -> Result<bool> {
|
||||
self.step(None);
|
||||
// log(p);
|
||||
*corner = self.p;
|
||||
|
||||
@@ -17,12 +17,7 @@ impl Quadrilateral {
|
||||
// Self([tl, tr,br, bl ])
|
||||
// }
|
||||
|
||||
pub fn with_points(
|
||||
tl: Point,
|
||||
tr: Point,
|
||||
br: Point,
|
||||
bl: Point,
|
||||
) -> Self {
|
||||
pub fn with_points(tl: Point, tr: Point, br: Point, bl: Point) -> Self {
|
||||
Self([tl, tr, br, bl])
|
||||
}
|
||||
|
||||
|
||||
@@ -78,11 +78,11 @@ pub trait RegressionLine {
|
||||
// }
|
||||
|
||||
fn add(&mut self, p: Point) -> Result<()>; //{
|
||||
// assert(_directionInward != PointF());
|
||||
// _points.push_back(p);
|
||||
// if (_points.size() == 1)
|
||||
// c = dot(normal(), p);
|
||||
// }
|
||||
// assert(_directionInward != PointF());
|
||||
// _points.push_back(p);
|
||||
// if (_points.size() == 1)
|
||||
// c = dot(normal(), p);
|
||||
// }
|
||||
|
||||
fn pop_back(&mut self); // { _points.pop_back(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user