mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
cargo fmt
This commit is contained in:
@@ -4,4 +4,4 @@ mod monochrome_rectangle_detector;
|
||||
pub use monochrome_rectangle_detector::*;
|
||||
|
||||
mod white_rectangle_detector;
|
||||
pub use white_rectangle_detector::*;
|
||||
pub use white_rectangle_detector::*;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//package com.google.zxing.common.detector;
|
||||
|
||||
use crate::{Exceptions, RXingResultPoint, common::BitMatrix, ResultPoint};
|
||||
use crate::{common::BitMatrix, Exceptions, RXingResultPoint, ResultPoint};
|
||||
|
||||
/**
|
||||
* <p>A somewhat generic detector that looks for a barcode-like rectangular region within an image.
|
||||
@@ -34,7 +34,9 @@ pub struct MonochromeRectangleDetector {
|
||||
|
||||
impl MonochromeRectangleDetector {
|
||||
pub fn new(image: &BitMatrix) -> Self {
|
||||
Self { image: image.clone() }
|
||||
Self {
|
||||
image: image.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +52,7 @@ impl MonochromeRectangleDetector {
|
||||
pub fn detect(&self) -> Result<Vec<RXingResultPoint>, Exceptions> {
|
||||
let height = self.image.getHeight() as i32;
|
||||
let width = self.image.getWidth() as i32;
|
||||
let halfHeight= height / 2;
|
||||
let halfHeight = height / 2;
|
||||
let halfWidth = width / 2;
|
||||
let deltaY = 1.max(height as i32 / (MAX_MODULES * 8));
|
||||
let deltaX = 1.max(width as i32 / (MAX_MODULES * 8));
|
||||
@@ -168,48 +170,37 @@ impl MonochromeRectangleDetector {
|
||||
}
|
||||
if range.is_none() {
|
||||
if let Some(lastRange) = lastRange_z {
|
||||
// lastRange was found
|
||||
if deltaX == 0 {
|
||||
let lastY = y - deltaY;
|
||||
if lastRange[0] < centerX {
|
||||
if lastRange[1] > centerX {
|
||||
// straddle, choose one or the other based on direction
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastRange[if deltaY > 0 { 0 } else { 1 }] as f32,
|
||||
lastY as f32,
|
||||
));
|
||||
// lastRange was found
|
||||
if deltaX == 0 {
|
||||
let lastY = y - deltaY;
|
||||
if lastRange[0] < centerX {
|
||||
if lastRange[1] > centerX {
|
||||
// straddle, choose one or the other based on direction
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastRange[if deltaY > 0 { 0 } else { 1 }] as f32,
|
||||
lastY as f32,
|
||||
));
|
||||
}
|
||||
return Ok(RXingResultPoint::new(lastRange[0] as f32, lastY as f32));
|
||||
} else {
|
||||
return Ok(RXingResultPoint::new(lastRange[1] as f32, lastY as f32));
|
||||
}
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastRange[0] as f32,
|
||||
lastY as f32,
|
||||
));
|
||||
} else {
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastRange[1] as f32,
|
||||
lastY as f32,
|
||||
));
|
||||
}
|
||||
} else {
|
||||
let lastX = x - deltaX;
|
||||
if lastRange[0] < centerY {
|
||||
if lastRange[1] > centerY {
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastX as f32,
|
||||
lastRange[if deltaX < 0 { 0 } else { 1 }] as f32,
|
||||
));
|
||||
let lastX = x - deltaX;
|
||||
if lastRange[0] < centerY {
|
||||
if lastRange[1] > centerY {
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastX as f32,
|
||||
lastRange[if deltaX < 0 { 0 } else { 1 }] as f32,
|
||||
));
|
||||
}
|
||||
return Ok(RXingResultPoint::new(lastX as f32, lastRange[0] as f32));
|
||||
} else {
|
||||
return Ok(RXingResultPoint::new(lastX as f32, lastRange[1] as f32));
|
||||
}
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastX as f32,
|
||||
lastRange[0] as f32,
|
||||
));
|
||||
} else {
|
||||
return Ok(RXingResultPoint::new(
|
||||
lastX as f32,
|
||||
lastRange[1] as f32,
|
||||
));
|
||||
}
|
||||
}
|
||||
}}else {
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
}
|
||||
lastRange_z = range;
|
||||
@@ -309,4 +300,4 @@ impl MonochromeRectangleDetector {
|
||||
None
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//package com.google.zxing.common.detector;
|
||||
|
||||
use crate::{RXingResultPoint, Exceptions, common::BitMatrix, ResultPoint};
|
||||
use crate::{common::BitMatrix, Exceptions, RXingResultPoint, ResultPoint};
|
||||
|
||||
use super::MathUtils;
|
||||
|
||||
@@ -59,13 +59,7 @@ impl WhiteRectangleDetector {
|
||||
* @param y y position of search center
|
||||
* @throws NotFoundException if image is too small to accommodate {@code initSize}
|
||||
*/
|
||||
pub fn new(
|
||||
image: &BitMatrix,
|
||||
initSize: i32,
|
||||
x: i32,
|
||||
y: i32,
|
||||
) -> Result<Self, Exceptions> {
|
||||
|
||||
pub fn new(image: &BitMatrix, initSize: i32, x: i32, y: i32) -> Result<Self, Exceptions> {
|
||||
let halfsize = initSize / 2;
|
||||
|
||||
let leftInit = x - halfsize;
|
||||
@@ -81,7 +75,7 @@ impl WhiteRectangleDetector {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
}
|
||||
|
||||
Ok(Self{
|
||||
Ok(Self {
|
||||
image: image.clone(),
|
||||
height: image.getHeight() as i32,
|
||||
width: image.getWidth() as i32,
|
||||
@@ -126,7 +120,9 @@ impl WhiteRectangleDetector {
|
||||
// . |
|
||||
// .....
|
||||
let mut right_border_not_white = true;
|
||||
while (right_border_not_white || !at_least_one_black_point_found_on_right) && right < self.width {
|
||||
while (right_border_not_white || !at_least_one_black_point_found_on_right)
|
||||
&& right < self.width
|
||||
{
|
||||
right_border_not_white = self.contains_black_point(up, down, right, false);
|
||||
if right_border_not_white {
|
||||
right += 1;
|
||||
@@ -146,7 +142,8 @@ impl WhiteRectangleDetector {
|
||||
// . .
|
||||
// .___.
|
||||
let mut bottom_border_not_white = true;
|
||||
while (bottom_border_not_white || !at_least_one_black_point_found_on_bottom) && down < self.height
|
||||
while (bottom_border_not_white || !at_least_one_black_point_found_on_bottom)
|
||||
&& down < self.height
|
||||
{
|
||||
bottom_border_not_white = self.contains_black_point(left, right, down, true);
|
||||
if bottom_border_not_white {
|
||||
|
||||
Reference in New Issue
Block a user