mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
clippy fix
This commit is contained in:
@@ -24,9 +24,9 @@ pub fn getBit(bitMatrix: &BitMatrix, x: u32, y: u32, mirrored: Option<bool>) ->
|
||||
pub fn hasValidDimension(bitMatrix: &BitMatrix, isMicro: bool) -> bool {
|
||||
let dimension = bitMatrix.height();
|
||||
if isMicro {
|
||||
dimension >= 11 && dimension <= 17 && (dimension % 2) == 1
|
||||
(11..=17).contains(&dimension) && (dimension % 2) == 1
|
||||
} else {
|
||||
dimension >= 21 && dimension <= 177 && (dimension % 4) == 1
|
||||
(21..=177).contains(&dimension) && (dimension % 4) == 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ pub fn ReadVersion(bitMatrix: &BitMatrix) -> Result<VersionRef> {
|
||||
}
|
||||
}
|
||||
|
||||
return Err(Exceptions::FORMAT);
|
||||
Err(Exceptions::FORMAT)
|
||||
}
|
||||
|
||||
pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result<FormatInformation> {
|
||||
@@ -110,10 +110,10 @@ pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result<For
|
||||
AppendBit(&mut formatInfoBits2, getBit(bitMatrix, x, 8, None));
|
||||
}
|
||||
|
||||
return Ok(FormatInformation::DecodeQR(
|
||||
Ok(FormatInformation::DecodeQR(
|
||||
formatInfoBits1 as u32,
|
||||
formatInfoBits2 as u32,
|
||||
));
|
||||
))
|
||||
}
|
||||
|
||||
pub fn ReadQRCodewords(
|
||||
@@ -184,12 +184,10 @@ pub fn ReadMQRCodewords(
|
||||
let hasD4mBlock = version.getVersionNumber() % 2 == 1;
|
||||
let d4mBlockIndex = if version.getVersionNumber() == 1 {
|
||||
3
|
||||
} else if formatInfo.error_correction_level == ErrorCorrectionLevel::L {
|
||||
11
|
||||
} else {
|
||||
if formatInfo.error_correction_level == ErrorCorrectionLevel::L {
|
||||
11
|
||||
} else {
|
||||
9
|
||||
}
|
||||
9
|
||||
};
|
||||
|
||||
let mut result = Vec::new();
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn GetDataMaskBit(maskIndex: u32, x: u32, y: u32, isMicro: Option<bool>) ->
|
||||
let isMicro = isMicro.unwrap_or(false);
|
||||
let mut maskIndex = maskIndex;
|
||||
if isMicro {
|
||||
if maskIndex < 0 || maskIndex >= 4 {
|
||||
if !(0..4).contains(&maskIndex) {
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"QRCode maskIndex out of range",
|
||||
));
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn CorrectErrors(codewordBytes: &mut [u8], numDataCodewords: u32) -> Result<
|
||||
// We don't care about errors in the error-correction codewords
|
||||
codewordBytes[..numDataCodewords as usize].copy_from_slice(
|
||||
&codewordsInts[..numDataCodewords as usize]
|
||||
.into_iter()
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|i| i as u8)
|
||||
.collect::<Vec<u8>>(),
|
||||
@@ -332,7 +332,7 @@ pub fn DecodeBitStream(
|
||||
{
|
||||
result +=
|
||||
crate::common::cpp_essentials::util::ToString(appInd as usize, 2)?;
|
||||
} else if (appInd >= 165 && appInd <= 190) || (appInd >= 197 && appInd <= 222)
|
||||
} else if (165..=190).contains(&appInd) || (197..=222).contains(&appInd)
|
||||
// "A-Za-z"
|
||||
{
|
||||
result += (appInd - 100) as u8;
|
||||
@@ -403,14 +403,14 @@ pub fn Decode(bits: &BitMatrix) -> Result<DecoderResult<bool>> {
|
||||
};
|
||||
|
||||
// Read codewords
|
||||
let codewords = ReadCodewords(bits, &version, &formatInfo)?;
|
||||
let codewords = ReadCodewords(bits, version, &formatInfo)?;
|
||||
if codewords.is_empty() {
|
||||
return Err(Exceptions::format_with("Failed to read codewords"));
|
||||
}
|
||||
|
||||
// Separate into data blocks
|
||||
let dataBlocks: Vec<DataBlock> =
|
||||
DataBlock::getDataBlocks(&codewords, &version, formatInfo.error_correction_level)?;
|
||||
DataBlock::getDataBlocks(&codewords, version, formatInfo.error_correction_level)?;
|
||||
if dataBlocks.is_empty() {
|
||||
return Err(Exceptions::format_with("Failed to get data blocks"));
|
||||
}
|
||||
@@ -438,7 +438,7 @@ pub fn Decode(bits: &BitMatrix) -> Result<DecoderResult<bool>> {
|
||||
|
||||
// Decode the contents of that stream of bytes
|
||||
Ok(
|
||||
DecodeBitStream(&resultBytes, &version, formatInfo.error_correction_level)?
|
||||
DecodeBitStream(&resultBytes, version, formatInfo.error_correction_level)?
|
||||
.withIsMirrored(formatInfo.isMirrored),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ const SUM: usize = 7;
|
||||
const PATTERN: FixedPattern<LEN, SUM, false> = FixedPattern::new([1, 1, 3, 1, 1]);
|
||||
const E2E: bool = true;
|
||||
|
||||
fn FindPattern<'a>(view: PatternView<'a>) -> Result<PatternView<'a>> {
|
||||
fn FindPattern(view: PatternView<'_>) -> Result<PatternView<'_>> {
|
||||
FindLeftGuardBy::<LEN, _>(
|
||||
view,
|
||||
LEN,
|
||||
@@ -162,7 +162,7 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern
|
||||
// for (int i = 0; i < nbPatterns - 2; i++) {
|
||||
for j in (i + 1)..(nbPatterns - 1) {
|
||||
// for (int j = i + 1; j < nbPatterns - 1; j++) {
|
||||
for k in (j + 1)..(nbPatterns - 0) {
|
||||
for k in (j + 1)..nbPatterns {
|
||||
// for (int k = j + 1; k < nbPatterns - 0; k++) {
|
||||
let mut a = &patterns[i];
|
||||
let mut b = &patterns[j];
|
||||
@@ -201,7 +201,7 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern
|
||||
let moduleCount = (distAB + distBC)
|
||||
/ (2.0 * (a.size + b.size + c.size) as f64 / (3.0 * 7.0))
|
||||
+ 7.0;
|
||||
if moduleCount < 21.0 * 0.9 || moduleCount > 177.0 * 1.5
|
||||
if !(21.0 * 0.9..=177.0 * 1.5).contains(&moduleCount)
|
||||
// moduleCount may be overestimated, see above
|
||||
{
|
||||
continue;
|
||||
@@ -399,7 +399,7 @@ pub fn Mod2Pix(
|
||||
) -> Result<PerspectiveTransform> {
|
||||
let mut quad = Quadrilateral::rectangle(dimension, dimension, Some(3.5));
|
||||
// let quad = Rectangle(dimension, dimension, 3.5);
|
||||
quad[2] = quad[2] - brOffset;
|
||||
quad[2] -= brOffset;
|
||||
|
||||
PerspectiveTransform::quadrilateralToQuadrilateral(quad, pix)
|
||||
// return {quad, pix};
|
||||
@@ -497,15 +497,13 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
let top = EstimateDimension(image, fp.tl, fp.tr);
|
||||
let left = EstimateDimension(image, fp.tl, fp.bl);
|
||||
|
||||
if !(top.dim != 0) && !(left.dim != 0) {
|
||||
if top.dim == 0 && left.dim == 0 {
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
}
|
||||
|
||||
let best = if top.err == left.err {
|
||||
if top.dim > left.dim { top } else { left }
|
||||
} else {
|
||||
if top.err < left.err { 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;
|
||||
|
||||
@@ -563,10 +561,10 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
)?;
|
||||
|
||||
if dimension >= Version::DimensionOfVersion(7, false) as i32 {
|
||||
let version = ReadVersion(image, dimension as u32, mod2Pix.clone());
|
||||
let version = ReadVersion(image, dimension as u32, mod2Pix);
|
||||
|
||||
// if the version bits are garbage -> discard the detection
|
||||
if !version.is_ok()
|
||||
if version.is_err()
|
||||
|| (version.as_ref().unwrap().getDimensionForVersion() as i32 - dimension).abs() > 8
|
||||
{
|
||||
/*return DetectorResult();*/
|
||||
@@ -609,7 +607,7 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
{
|
||||
return p;
|
||||
}
|
||||
return projectM2P(x, y, &mod2Pix);
|
||||
projectM2P(x, y, &mod2Pix)
|
||||
};
|
||||
|
||||
for y in 0..=N {
|
||||
@@ -847,7 +845,7 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
|
||||
if dimension < MIN_MODULES as i32
|
||||
|| dimension > MAX_MODULES as i32
|
||||
|| !image.is_in(point(
|
||||
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize as f32,
|
||||
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
))
|
||||
{
|
||||
@@ -899,7 +897,7 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
|
||||
let bottom = top + height - 1;
|
||||
|
||||
// allow corners be moved one pixel inside to accommodate for possible aliasing artifacts
|
||||
let diagonal: Pattern = EdgeTracer::new(&image, point_i(left, top), point_i(1, 1))
|
||||
let diagonal: Pattern = EdgeTracer::new(image, point_i(left, top), point_i(1, 1))
|
||||
.readPatternFromBlack(1, None)
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?;
|
||||
let diag_hld = diagonal.to_vec().into();
|
||||
@@ -915,8 +913,8 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
|
||||
if dimension < MIN_MODULES
|
||||
|| dimension > MAX_MODULES
|
||||
|| !image.is_in(point(
|
||||
left as f32 + moduleSize as f32 / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
top as f32 + moduleSize as f32 / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
))
|
||||
{
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
@@ -997,7 +995,7 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDetec
|
||||
|
||||
let check = |i, checkOne: bool| {
|
||||
let p = mod2Pix.transform_point(Point::centered(FORMAT_INFO_COORDS[i]));
|
||||
return image.is_in(p) && (!checkOne || image.get_point(p));
|
||||
image.is_in(p) && (!checkOne || image.get_point(p))
|
||||
};
|
||||
|
||||
// check that we see both innermost timing pattern modules
|
||||
@@ -1048,7 +1046,7 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDetec
|
||||
dim,
|
||||
dim,
|
||||
&[SamplerControl {
|
||||
p1: point_i(dim as u32, dim as u32),
|
||||
p1: point_i(dim, dim),
|
||||
p0: point_i(0, 0),
|
||||
transform: bestPT,
|
||||
}],
|
||||
|
||||
@@ -374,6 +374,6 @@ impl QrReader {
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(results);
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,84 +9,84 @@ use crate::{common::BitMatrix, qrcode::cpp_port::data_mask::GetMaskedBit};
|
||||
#[test]
|
||||
fn Mask0() {
|
||||
TestMaskAcrossDimensions(0, |i, j| {
|
||||
return (i + j) % 2 == 0;
|
||||
(i + j) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask1() {
|
||||
TestMaskAcrossDimensions(1, |i, _| {
|
||||
return i % 2 == 0;
|
||||
i % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask2() {
|
||||
TestMaskAcrossDimensions(2, |_, j| {
|
||||
return j % 3 == 0;
|
||||
j % 3 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask3() {
|
||||
TestMaskAcrossDimensions(3, |i, j| {
|
||||
return (i + j) % 3 == 0;
|
||||
(i + j) % 3 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask4() {
|
||||
TestMaskAcrossDimensions(4, |i, j| {
|
||||
return (i / 2 + j / 3) % 2 == 0;
|
||||
(i / 2 + j / 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask5() {
|
||||
TestMaskAcrossDimensions(5, |i, j| {
|
||||
return (i * j) % 2 + (i * j) % 3 == 0;
|
||||
(i * j) % 2 + (i * j) % 3 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask6() {
|
||||
TestMaskAcrossDimensions(6, |i, j| {
|
||||
return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i * j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask7() {
|
||||
TestMaskAcrossDimensions(7, |i, j| {
|
||||
return ((i + j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i + j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask0() {
|
||||
TestMicroMaskAcrossDimensions(0, |i, _| {
|
||||
return i % 2 == 0;
|
||||
i % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask1() {
|
||||
TestMicroMaskAcrossDimensions(1, |i, j| {
|
||||
return (i / 2 + j / 3) % 2 == 0;
|
||||
(i / 2 + j / 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask2() {
|
||||
TestMicroMaskAcrossDimensions(2, |i, j| {
|
||||
return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i * j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask3() {
|
||||
TestMicroMaskAcrossDimensions(3, |i, j| {
|
||||
return ((i + j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i + j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ fn GetProvisionalVersionForDimension() {
|
||||
for i in 1..=40 {
|
||||
// for (int i = 1; i <= 40; i++) {
|
||||
let prov =
|
||||
Version::FromDimension(4 * i + 17).expect(&format!("version should exist for {i}"));
|
||||
Version::FromDimension(4 * i + 17).unwrap_or_else(|_| panic!("version should exist for {i}"));
|
||||
// assert_ne!(prov, nullptr);
|
||||
assert_eq!(i, prov.getVersionNumber());
|
||||
}
|
||||
@@ -69,7 +69,7 @@ fn MicroVersionForNumber() {
|
||||
for i in 1..=4 {
|
||||
// for (int i = 1; i <= 4; i++) {
|
||||
CheckVersion(
|
||||
Version::FromNumber(i, true).expect(&format!("version for {i} should exist")),
|
||||
Version::FromNumber(i, true).unwrap_or_else(|_| panic!("version for {i} should exist")),
|
||||
i,
|
||||
2 * i + 9,
|
||||
);
|
||||
@@ -81,7 +81,7 @@ fn GetProvisionalMicroVersionForDimension() {
|
||||
for i in 1..=4 {
|
||||
// for (int i = 1; i <= 4; i++) {
|
||||
let prov = Version::FromDimension(2 * i + 9)
|
||||
.expect(&format!("version for micro {i} should exist"));
|
||||
.unwrap_or_else(|_| panic!("version for micro {i} should exist"));
|
||||
// assert_ne!(prov, nullptr);
|
||||
assert_eq!(i, prov.getVersionNumber());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user