code cleanup

This commit is contained in:
Henry Schimke
2023-04-29 09:58:04 -05:00
parent ef999a4eb0
commit 508f5f14c5
19 changed files with 56 additions and 154 deletions

View File

@@ -9,8 +9,7 @@ use crate::common::reedsolomon::{
get_predefined_genericgf, PredefinedGenericGF, ReedSolomonDecoder,
};
use crate::common::{
AIFlag, BitMatrix, BitSource, CharacterSet, ECIStringBuilder, Eci, Result,
SymbologyIdentifier,
AIFlag, BitMatrix, BitSource, CharacterSet, ECIStringBuilder, Eci, Result, SymbologyIdentifier,
};
use crate::qrcode::cpp_port::bitmatrix_parser::{
ReadCodewords, ReadFormatInformation, ReadVersion,

View File

@@ -4,7 +4,8 @@ use crate::{
CenterOfRing, DMRegressionLine, FindConcentricPatternCorners, FindLeftGuardBy, Matrix,
},
DefaultGridSampler, GridSampler, Result, SamplerControl,
}, point_i,
},
point_i,
qrcode::{
decoder::{FormatInformation, Version, VersionRef},
detector::QRCodeDetectorResult,
@@ -16,10 +17,9 @@ use multimap::MultiMap;
use crate::{
common::{
cpp_essentials::{
BitMatrixCursorTrait, ConcentricPattern, Direction, EdgeTracer,
FixedPattern, GetPatternRowTP, IsPattern, LocateConcentricPattern,
PatternRow, PatternType, PatternView, ReadSymmetricPattern, RegressionLine,
RegressionLineTrait,
BitMatrixCursorTrait, ConcentricPattern, Direction, EdgeTracer, FixedPattern,
GetPatternRowTP, IsPattern, LocateConcentricPattern, PatternRow, PatternType,
PatternView, ReadSymmetricPattern, RegressionLine, RegressionLineTrait,
},
BitMatrix, PerspectiveTransform, Quadrilateral,
},
@@ -502,8 +502,16 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
}
let best = if top.err == left.err {
if top.dim > left.dim { top } else { left }
} else if top.err < left.err { top } else { left };
if top.dim > left.dim {
top
} else {
left
}
} else if top.err < left.err {
top
} else {
left
};
let mut dimension = best.dim;
let moduleSize = (best.ms + 1.0) as i32;

View File

@@ -120,8 +120,8 @@
use crate::{
common::{cpp_essentials::ConcentricPattern, DetectorRXingResult},
multi::MultipleBarcodeReader,
BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary,
Exceptions, RXingResult, Reader,
BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions,
RXingResult, Reader,
};
use super::{
@@ -132,8 +132,6 @@ use super::{
},
};
#[derive(Default)]
pub struct QrReader;

View File

@@ -8,86 +8,62 @@ use crate::{common::BitMatrix, qrcode::cpp_port::data_mask::GetMaskedBit};
#[test]
fn Mask0() {
TestMaskAcrossDimensions(0, |i, j| {
(i + j) % 2 == 0
});
TestMaskAcrossDimensions(0, |i, j| (i + j) % 2 == 0);
}
#[test]
fn Mask1() {
TestMaskAcrossDimensions(1, |i, _| {
i % 2 == 0
});
TestMaskAcrossDimensions(1, |i, _| i % 2 == 0);
}
#[test]
fn Mask2() {
TestMaskAcrossDimensions(2, |_, j| {
j % 3 == 0
});
TestMaskAcrossDimensions(2, |_, j| j % 3 == 0);
}
#[test]
fn Mask3() {
TestMaskAcrossDimensions(3, |i, j| {
(i + j) % 3 == 0
});
TestMaskAcrossDimensions(3, |i, j| (i + j) % 3 == 0);
}
#[test]
fn Mask4() {
TestMaskAcrossDimensions(4, |i, j| {
(i / 2 + j / 3) % 2 == 0
});
TestMaskAcrossDimensions(4, |i, j| (i / 2 + j / 3) % 2 == 0);
}
#[test]
fn Mask5() {
TestMaskAcrossDimensions(5, |i, j| {
(i * j) % 2 + (i * j) % 3 == 0
});
TestMaskAcrossDimensions(5, |i, j| (i * j) % 2 + (i * j) % 3 == 0);
}
#[test]
fn Mask6() {
TestMaskAcrossDimensions(6, |i, j| {
((i * j) % 2 + (i * j) % 3) % 2 == 0
});
TestMaskAcrossDimensions(6, |i, j| ((i * j) % 2 + (i * j) % 3) % 2 == 0);
}
#[test]
fn Mask7() {
TestMaskAcrossDimensions(7, |i, j| {
((i + j) % 2 + (i * j) % 3) % 2 == 0
});
TestMaskAcrossDimensions(7, |i, j| ((i + j) % 2 + (i * j) % 3) % 2 == 0);
}
#[test]
fn MicroMask0() {
TestMicroMaskAcrossDimensions(0, |i, _| {
i % 2 == 0
});
TestMicroMaskAcrossDimensions(0, |i, _| i % 2 == 0);
}
#[test]
fn MicroMask1() {
TestMicroMaskAcrossDimensions(1, |i, j| {
(i / 2 + j / 3) % 2 == 0
});
TestMicroMaskAcrossDimensions(1, |i, j| (i / 2 + j / 3) % 2 == 0);
}
#[test]
fn MicroMask2() {
TestMicroMaskAcrossDimensions(2, |i, j| {
((i * j) % 2 + (i * j) % 3) % 2 == 0
});
TestMicroMaskAcrossDimensions(2, |i, j| ((i * j) % 2 + (i * j) % 3) % 2 == 0);
}
#[test]
fn MicroMask3() {
TestMicroMaskAcrossDimensions(3, |i, j| {
((i + j) % 2 + (i * j) % 3) % 2 == 0
});
TestMicroMaskAcrossDimensions(3, |i, j| ((i + j) % 2 + (i * j) % 3) % 2 == 0);
}
fn TestMaskAcrossDimensionsImpl<F>(

View File

@@ -23,10 +23,8 @@
// using namespace ZXing;
// using namespace ZXing::QRCode;
use crate::{
common::{BitArray},
common::BitArray,
qrcode::{
cpp_port::decoder::DecodeBitStream,
decoder::{ErrorCorrectionLevel, Version},

View File

@@ -43,8 +43,8 @@ fn VersionForNumber() {
fn GetProvisionalVersionForDimension() {
for i in 1..=40 {
// for (int i = 1; i <= 40; i++) {
let prov =
Version::FromDimension(4 * i + 17).unwrap_or_else(|_| panic!("version should exist for {i}"));
let prov = Version::FromDimension(4 * i + 17)
.unwrap_or_else(|_| panic!("version should exist for {i}"));
// assert_ne!(prov, nullptr);
assert_eq!(i, prov.getVersionNumber());
}