cargo fmt

This commit is contained in:
Henry Schimke
2022-12-19 17:49:52 -06:00
parent 9580f542d6
commit eaacf31923
7 changed files with 418 additions and 394 deletions

View File

@@ -18,7 +18,6 @@
* @author Guenther Grau
*/
pub struct BarcodeMetadata {
columnCount: u32,
errorCorrectionLevel: u32,
rowCountUpperPart: u32,
@@ -26,8 +25,12 @@ pub struct BarcodeMetadata {
rowCount: u32,
}
impl BarcodeMetadata {
pub fn new( columnCount:u32, rowCountUpperPart:u32, rowCountLowerPart:u32, errorCorrectionLevel:u32) -> Self{
pub fn new(
columnCount: u32,
rowCountUpperPart: u32,
rowCountLowerPart: u32,
errorCorrectionLevel: u32,
) -> Self {
Self {
columnCount,
errorCorrectionLevel,
@@ -56,5 +59,4 @@ impl BarcodeMetadata {
pub fn getRowCountLowerPart(&self) -> u32 {
self.rowCountLowerPart
}
}

View File

@@ -68,7 +68,6 @@ pub fn new() -> Self {
0
}
}
}
impl Default for BarcodeValue {

View File

@@ -14,14 +14,13 @@
* limitations under the License.
*/
use crate::{common::BitMatrix, RXingResultPoint, Exceptions, ResultPoint};
use crate::{common::BitMatrix, Exceptions, RXingResultPoint, ResultPoint};
/**
* @author Guenther Grau
*/
#[derive(Clone)]
pub struct BoundingBox<'a> {
image: &'a BitMatrix,
topLeft: RXingResultPoint,
bottomLeft: RXingResultPoint,
@@ -33,16 +32,17 @@ pub struct BoundingBox<'a> {
maxY: u32,
}
impl<'a> BoundingBox<'_> {
pub fn new( image:&'a BitMatrix,
pub fn new(
image: &'a BitMatrix,
topLeft: Option<RXingResultPoint>,
bottomLeft: Option<RXingResultPoint>,
topRight: Option<RXingResultPoint>,
bottomRight:Option<RXingResultPoint>) -> Result<BoundingBox<'a>,Exceptions> {
bottomRight: Option<RXingResultPoint>,
) -> Result<BoundingBox<'a>, Exceptions> {
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
let rightUnspecified = topRight.is_none() || bottomRight.is_none();
if leftUnspecified && rightUnspecified {
return Err(Exceptions::NotFoundException("".to_owned()))
return Err(Exceptions::NotFoundException("".to_owned()));
}
let newTopLeft;
@@ -59,7 +59,8 @@ impl<'a> BoundingBox<'_> {
newTopLeft = topLeft.unwrap();
newBottomLeft = bottomLeft.unwrap();
newTopRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newTopLeft.getY());
newBottomRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
newBottomRight =
RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
} else {
newTopLeft = topLeft.unwrap();
newTopRight = topRight.unwrap();
@@ -94,20 +95,34 @@ impl<'a> BoundingBox<'_> {
}
}
pub fn merge( leftBox:Option<&'a BoundingBox>, rightBox:Option<&'a BoundingBox>) -> Result<BoundingBox<'a>,Exceptions> {
pub fn merge(
leftBox: Option<&'a BoundingBox>,
rightBox: Option<&'a BoundingBox>,
) -> Result<BoundingBox<'a>, Exceptions> {
if leftBox.is_none() {
return Ok(rightBox.unwrap().clone())
return Ok(rightBox.unwrap().clone());
}
if rightBox.is_none() {
return Ok(leftBox.unwrap().clone())
return Ok(leftBox.unwrap().clone());
}
let leftBox = leftBox.unwrap();
let rightBox = rightBox.unwrap();
BoundingBox::new(leftBox.image, Some(leftBox.topLeft), Some(leftBox.bottomLeft), Some(rightBox.topRight), Some(rightBox.bottomRight))
BoundingBox::new(
leftBox.image,
Some(leftBox.topLeft),
Some(leftBox.bottomLeft),
Some(rightBox.topRight),
Some(rightBox.bottomRight),
)
}
pub fn addMissingRows(&self, missingStartRows:u32, missingEndRows:u32, isLeft:bool) -> Result<BoundingBox,Exceptions> {
pub fn addMissingRows(
&self,
missingStartRows: u32,
missingEndRows: u32,
isLeft: bool,
) -> Result<BoundingBox, Exceptions> {
let mut newTopLeft = self.topLeft;
let mut newBottomLeft = self.bottomLeft;
let mut newTopRight = self.topRight;
@@ -128,7 +143,11 @@ impl<'a> BoundingBox<'_> {
}
if missingEndRows > 0 {
let bottom = if isLeft { self.bottomLeft} else {self.bottomRight};
let bottom = if isLeft {
self.bottomLeft
} else {
self.bottomRight
};
let mut newMaxY = bottom.getY() as u32 + missingEndRows;
if newMaxY >= self.image.getHeight() {
newMaxY = self.image.getHeight() - 1;
@@ -141,7 +160,13 @@ impl<'a> BoundingBox<'_> {
}
}
BoundingBox::new(self.image, Some(newTopLeft), Some(newBottomLeft), Some(newTopRight), Some(newBottomRight))
BoundingBox::new(
self.image,
Some(newTopLeft),
Some(newBottomLeft),
Some(newTopRight),
Some(newBottomRight),
)
}
pub fn getMinX(&self) -> u32 {
@@ -175,5 +200,4 @@ impl<'a> BoundingBox<'_> {
pub fn getBottomRight(&self) -> &RXingResultPoint {
&self.bottomRight
}
}

View File

@@ -23,7 +23,6 @@ use std::fmt::Display;
*/
#[derive(Clone, Copy)]
pub struct Codeword {
startX: u32,
endX: u32,
bucket: u32,
@@ -32,7 +31,6 @@ pub struct Codeword {
}
impl Codeword {
pub fn new(startX: u32, endX: u32, bucket: u32, value: u32) -> Self {
Self {
startX,
@@ -82,7 +80,6 @@ impl Codeword {
pub fn setRowNumber(&mut self, rowNumber: i32) {
self.rowNumber = rowNumber;
}
}
impl Display for Codeword {

View File

@@ -29,7 +29,6 @@ pub struct DetectionRXingResultColumn<'a> {
}
impl<'a> DetectionRXingResultColumn<'_> {
pub fn new(boundingBox: &'a BoundingBox) -> DetectionRXingResultColumn<'a> {
DetectionRXingResultColumn {
boundingBox: BoundingBox::from_other(boundingBox),
@@ -84,9 +83,6 @@ impl<'a> DetectionRXingResultColumn<'_> {
pub fn getCodewords(&self) -> &[Option<Codeword>] {
&self.codewords
}
}
impl Display for DetectionRXingResultColumn<'_> {

View File

@@ -25,7 +25,8 @@ use crate::pdf417::pdf_417_common;
// [[0.0;pdf_417_common::SYMBOL_TABLE.len()];pdf_417_common::BARS_IN_MODULE];
const RATIOS_TABLE: [[f64; pdf_417_common::BARS_IN_MODULE as usize]; 2787] = {
let mut table = [[0.0;pdf_417_common::BARS_IN_MODULE as usize];pdf_417_common::SYMBOL_TABLE.len()];
let mut table =
[[0.0; pdf_417_common::BARS_IN_MODULE as usize]; pdf_417_common::SYMBOL_TABLE.len()];
// Pre-computes the symbol ratio table.
let mut i = 0_usize;
while i < pdf_417_common::SYMBOL_TABLE.len() {
@@ -41,7 +42,8 @@ use crate::pdf417::pdf_417_common;
currentSymbol >>= 1;
}
currentBit = currentSymbol & 0x1;
table[i][pdf_417_common::BARS_IN_MODULE as usize - j - 1] = size / pdf_417_common::MODULES_IN_CODEWORD as f64;
table[i][pdf_417_common::BARS_IN_MODULE as usize - j - 1] =
size / pdf_417_common::MODULES_IN_CODEWORD as f64;
j += 1;
}
@@ -67,9 +69,9 @@ use crate::pdf417::pdf_417_common;
let mut sumPreviousBits = 0;
for i in 0..pdf_417_common::MODULES_IN_CODEWORD {
// for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
let sampleIndex:f32 =
bitCountSum as f32/ (2 * pdf_417_common::MODULES_IN_CODEWORD) as f32 +
(i * bitCountSum) as f32 / pdf_417_common::MODULES_IN_CODEWORD as f32;
let sampleIndex: f32 = bitCountSum as f32
/ (2 * pdf_417_common::MODULES_IN_CODEWORD) as f32
+ (i * bitCountSum) as f32 / pdf_417_common::MODULES_IN_CODEWORD as f32;
if sumPreviousBits as f32 + moduleBitCount[bitCountIndex] as f32 <= sampleIndex {
sumPreviousBits += moduleBitCount[bitCountIndex];
bitCountIndex += 1;
@@ -81,7 +83,11 @@ use crate::pdf417::pdf_417_common;
fn getDecodedCodewordValue(moduleBitCount: &[u32]) -> i32 {
let decodedValue = getBitValue(moduleBitCount);
if pdf_417_common::getCodeword(decodedValue as u32) == -1 {-1} else {decodedValue}
if pdf_417_common::getCodeword(decodedValue as u32) == -1 {
-1
} else {
decodedValue
}
}
fn getBitValue(moduleBitCount: &[u32]) -> i32 {