chore: cargo fmt

This commit is contained in:
Henry Schimke
2024-01-13 18:12:23 -06:00
parent c9e10ea9ca
commit 6faf506398
6 changed files with 71 additions and 56 deletions

View File

@@ -104,10 +104,7 @@ impl FormatInformation {
//FormatInformation fi;
let mut fi = if formatInfoBits2 != 0 {
Self::FindBestFormatInfoRMQR(
&[formatInfoBits1],
&[formatInfoBits2],
)
Self::FindBestFormatInfoRMQR(&[formatInfoBits1], &[formatInfoBits2])
} else {
// TODO probably remove if `sampleRMQR()` done properly
Self::FindBestFormatInfoRMQR(&[formatInfoBits1], &[])

View File

@@ -216,7 +216,8 @@ impl Version {
fn IndexOf(_points: &[PointI], search: PointI) -> i32 {
RMQR_SIZES
.iter()
.position(|p| *p == search).map(|x| x as i32)
.position(|p| *p == search)
.map(|x| x as i32)
.unwrap_or(-1)
}

View File

@@ -5,16 +5,15 @@ use crate::{
},
DefaultGridSampler, GridSampler, Result, SamplerControl,
},
point_i,
point, point_i,
qrcode::{
decoder::{FormatInformation, Version, VersionRef},
detector::QRCodeDetectorResult,
},
Exceptions, point,
Exceptions,
};
use multimap::MultiMap;
use crate::{
common::{
cpp_essentials::{
@@ -988,37 +987,43 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
return Err(Exceptions::NOT_FOUND);
}
let fpWidth = (diagonal).into_iter().sum::<u16>();
let moduleSize = (fpWidth as f32) / 7.0;
let dimW = (width as f32 / moduleSize as f32).floor() as u32;
let dimH = (height as f32 / moduleSize as f32).floor() as u32;
if !Version::IsValidSize(point(dimW as i32, dimH as i32), Type::RectMicro)
{return Err(Exceptions::NOT_FOUND);}
if !Version::IsValidSize(point(dimW as i32, dimH as i32), Type::RectMicro) {
return Err(Exceptions::NOT_FOUND);
}
// Finder sub pattern
let subdiagonal : SubPattern = EdgeTracer::new(image, br, point_i(-1, -1)).readPatternFromBlack(1,None).ok_or(Exceptions::ILLEGAL_STATE)?;
let subdiagonal: SubPattern = EdgeTracer::new(image, br, point_i(-1, -1))
.readPatternFromBlack(1, None)
.ok_or(Exceptions::ILLEGAL_STATE)?;
let subdiagonal_hld = subdiagonal.to_vec().into();
let view = PatternView::new(&subdiagonal_hld);
if IsPattern::<E2E, 4, 4, false>(&view, &SUBPATTERN, None, 0.0, 0.0) != 0.0
{return Err(Exceptions::NOT_FOUND);}
if IsPattern::<E2E, 4, 4, false>(&view, &SUBPATTERN, None, 0.0, 0.0) != 0.0 {
return Err(Exceptions::NOT_FOUND);
}
// Vertical corner finder patterns
// Horizontal timing patterns
for (p, d) in [(tr, point(-1, 0)), (bl, point(1, 0)), (tl, point(1, 0)), (br, point(-1, 0))] {
for (p, d) in [
(tr, point(-1, 0)),
(bl, point(1, 0)),
(tl, point(1, 0)),
(br, point(-1, 0)),
] {
let mut cur = EdgeTracer::new(image, p, d.into());
// skip corner / finder / sub pattern edge
cur.stepToEdge(Some(2 + i32::from(cur.isWhite())), None, None);
let timing: TimingPattern = cur.readPattern(None).ok_or(Exceptions::ILLEGAL_STATE)?;
let timing_hld = timing.to_vec().into();
let view = PatternView::new(&timing_hld);
if !(IsPattern::<E2E, 10,10, false>(&view, &TIMINGPATTERN, None, 0.0, 0.0) != 0.0)
{return Err(Exceptions::NOT_FOUND);}
if !(IsPattern::<E2E, 10, 10, false>(&view, &TIMINGPATTERN, None, 0.0, 0.0) != 0.0) {
return Err(Exceptions::NOT_FOUND);
}
}
// #ifdef PRINT_DEBUG
// LogMatrix log;
@@ -1162,10 +1167,24 @@ pub fn SampleRMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDete
let FORMAT_INFO_EDGE_COORDS: [Point; 4] =
[point_i(8, 0), point_i(9, 0), point_i(10, 0), point_i(11, 0)];
let FORMAT_INFO_COORDS: [Point; 18] = [
point_i(11, 3), point_i(11, 2), point_i(11, 1),
point_i(10, 5), point_i(10, 4), point_i(10, 3), point_i(10, 2), point_i(10, 1),
point_i( 9, 5), point_i( 9, 4), point_i( 9, 3), point_i( 9, 2), point_i( 9, 1),
point_i( 8, 5), point_i( 8, 4), point_i( 8, 3), point_i( 8, 2), point_i( 8, 1),
point_i(11, 3),
point_i(11, 2),
point_i(11, 1),
point_i(10, 5),
point_i(10, 4),
point_i(10, 3),
point_i(10, 2),
point_i(10, 1),
point_i(9, 5),
point_i(9, 4),
point_i(9, 3),
point_i(9, 2),
point_i(9, 1),
point_i(8, 5),
point_i(8, 4),
point_i(8, 3),
point_i(8, 2),
point_i(8, 1),
];
let mut bestFI: FormatInformation = FormatInformation::default();

View File

@@ -6,7 +6,10 @@
use crate::{
common::BitMatrix,
qrcode::{decoder::{Version, VersionRef}, cpp_port::Type},
qrcode::{
cpp_port::Type,
decoder::{Version, VersionRef},
},
};
fn CheckVersion(version: VersionRef, number: u32, dimension: u32) {

View File

@@ -228,12 +228,7 @@ impl Version {
bitMatrix.setRegion(11, 1, 1, 3)?;
// Bottom right finder subpattern
bitMatrix.setRegion(
(size.x - 5) as u32,
(size.y - 5) as u32,
5 - 1,
5 - 1,
)?;
bitMatrix.setRegion((size.x - 5) as u32, (size.y - 5) as u32, 5 - 1, 5 - 1)?;
// Bottom right format
bitMatrix.setRegion((size.x - 8) as u32, (size.y - 6) as u32, 3, 5)?;
bitMatrix.setRegion((size.x - 5) as u32, (size.y - 6) as u32, 3, 1)?;