mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
cargo clippy --fix
This commit is contained in:
@@ -334,6 +334,7 @@ fn testVCardTypes() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn doTest(
|
fn doTest(
|
||||||
contents: &str,
|
contents: &str,
|
||||||
title: &str,
|
title: &str,
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ fn doTestShort(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn doTest(
|
fn doTest(
|
||||||
contents: &str,
|
contents: &str,
|
||||||
description: &str,
|
description: &str,
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ fn test_vin() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn do_test(
|
fn do_test(
|
||||||
contents: &str,
|
contents: &str,
|
||||||
wmi: &str,
|
wmi: &str,
|
||||||
|
|||||||
@@ -429,8 +429,8 @@ impl Into<Vec<bool>> for BitArray {
|
|||||||
fn into(self) -> Vec<bool> {
|
fn into(self) -> Vec<bool> {
|
||||||
let mut array = vec![false; self.size];
|
let mut array = vec![false; self.size];
|
||||||
|
|
||||||
for pixel in 0..self.size {
|
for (pixel, element) in array.iter_mut().enumerate().take(self.size) {
|
||||||
array[pixel] = self.get(pixel);
|
*element = self.get(pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
array
|
array
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ impl BitSource {
|
|||||||
num_bits -= toRead;
|
num_bits -= toRead;
|
||||||
bit_offset += toRead;
|
bit_offset += toRead;
|
||||||
if bit_offset == 8 {
|
if bit_offset == 8 {
|
||||||
bit_offset = 0;
|
//bit_offset = 0;
|
||||||
byte_offset += 1;
|
byte_offset += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,12 +100,12 @@ impl FormatInformation {
|
|||||||
// Some QR codes apparently do not apply the XOR mask. Try without and with additional masking.
|
// Some QR codes apparently do not apply the XOR mask. Try without and with additional masking.
|
||||||
for mask in [0, mask] {
|
for mask in [0, mask] {
|
||||||
// for (auto mask : {0, mask})
|
// for (auto mask : {0, mask})
|
||||||
for bitsIndex in 0..bits.len() {
|
for (bitsIndex, bit_set) in bits.iter().enumerate() {
|
||||||
// for (int bitsIndex = 0; bitsIndex < Size(bits); ++bitsIndex)
|
// for (int bitsIndex = 0; bitsIndex < Size(bits); ++bitsIndex)
|
||||||
for [pattern, index] in lookup {
|
for [pattern, index] in lookup {
|
||||||
// for (const auto& [pattern, index] : lookup) {
|
// for (const auto& [pattern, index] : lookup) {
|
||||||
// Find the int in lookup with fewest bits differing
|
// Find the int in lookup with fewest bits differing
|
||||||
let hammingDist = ((bits[bitsIndex] ^ mask) ^ pattern).count_ones();
|
let hammingDist = ((bit_set ^ mask) ^ pattern).count_ones();
|
||||||
if hammingDist < fi.hammingDistance {
|
if hammingDist < fi.hammingDistance {
|
||||||
// if (int hammingDist = BitHacks::CountBitsSet((bits[bitsIndex] ^ mask) ^ pattern); hammingDist < fi.hammingDistance) {
|
// if (int hammingDist = BitHacks::CountBitsSet((bits[bitsIndex] ^ mask) ^ pattern); hammingDist < fi.hammingDistance) {
|
||||||
fi.index = index as u8;
|
fi.index = index as u8;
|
||||||
|
|||||||
@@ -63,12 +63,11 @@ impl Version {
|
|||||||
pub fn DecodeVersionInformation(versionBitsA: i32, versionBitsB: i32) -> Result<VersionRef> {
|
pub fn DecodeVersionInformation(versionBitsA: i32, versionBitsB: i32) -> Result<VersionRef> {
|
||||||
let mut bestDifference = u32::MAX;
|
let mut bestDifference = u32::MAX;
|
||||||
let mut bestVersion = 0;
|
let mut bestVersion = 0;
|
||||||
let mut i = 0;
|
for (i, targetVersion) in VERSION_DECODE_INFO.into_iter().enumerate() {
|
||||||
for targetVersion in VERSION_DECODE_INFO {
|
|
||||||
// for (int targetVersion : VERSION_DECODE_INFO) {
|
// for (int targetVersion : VERSION_DECODE_INFO) {
|
||||||
// Do the version info bits match exactly? done.
|
// Do the version info bits match exactly? done.
|
||||||
if targetVersion == versionBitsA as u32 || targetVersion == versionBitsB as u32 {
|
if targetVersion == versionBitsA as u32 || targetVersion == versionBitsB as u32 {
|
||||||
return Self::getVersionForNumber(i + 7);
|
return Self::getVersionForNumber(i as u32 + 7);
|
||||||
}
|
}
|
||||||
// Otherwise see if this is the closest to a real version info bit string
|
// Otherwise see if this is the closest to a real version info bit string
|
||||||
// we have seen so far
|
// we have seen so far
|
||||||
@@ -80,12 +79,11 @@ impl Version {
|
|||||||
bestDifference = bitsDifference;
|
bestDifference = bitsDifference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
// We can tolerate up to 3 bits of error since no two version info codewords will
|
// We can tolerate up to 3 bits of error since no two version info codewords will
|
||||||
// differ in less than 8 bits.
|
// differ in less than 8 bits.
|
||||||
if bestDifference <= 3 {
|
if bestDifference <= 3 {
|
||||||
return Self::getVersionForNumber(bestVersion);
|
return Self::getVersionForNumber(bestVersion as u32);
|
||||||
}
|
}
|
||||||
// If we didn't find a close enough match, fail
|
// If we didn't find a close enough match, fail
|
||||||
Err(Exceptions::ILLEGAL_STATE)
|
Err(Exceptions::ILLEGAL_STATE)
|
||||||
|
|||||||
@@ -49,10 +49,10 @@ where
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self {
|
pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self {
|
||||||
let mut new_self = Self::default();
|
DecoderResult::<T> {
|
||||||
new_self.content = src;
|
content: src,
|
||||||
|
..Default::default()
|
||||||
new_self
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isValid(&self) -> bool {
|
pub fn isValid(&self) -> bool {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ pub struct PatternViewIterator<'a> {
|
|||||||
current_position: usize,
|
current_position: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for PatternViewIterator<'_> {
|
impl Iterator for PatternViewIterator<'_> {
|
||||||
type Item = PatternType;
|
type Item = PatternType;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
@@ -243,7 +243,7 @@ impl<'a> PatternView<'a> {
|
|||||||
|
|
||||||
pub fn shift(&mut self, n: usize) -> bool {
|
pub fn shift(&mut self, n: usize) -> bool {
|
||||||
self.current += n;
|
self.current += n;
|
||||||
!self.data.0.is_empty() && self.start + self.count <= (self.start + self.count)
|
!self.data.0.is_empty() //&& self.start + self.count <= (self.start + self.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn skipPair(&mut self) -> bool {
|
pub fn skipPair(&mut self) -> bool {
|
||||||
@@ -278,7 +278,7 @@ impl<'a> PatternView<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> std::ops::Index<isize> for PatternView<'_> {
|
impl std::ops::Index<isize> for PatternView<'_> {
|
||||||
type Output = PatternType;
|
type Output = PatternType;
|
||||||
|
|
||||||
fn index(&self, index: isize) -> &Self::Output {
|
fn index(&self, index: isize) -> &Self::Output {
|
||||||
@@ -301,7 +301,7 @@ impl<'a> std::ops::Index<isize> for PatternView<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> std::ops::Index<usize> for PatternView<'_> {
|
impl std::ops::Index<usize> for PatternView<'_> {
|
||||||
type Output = PatternType;
|
type Output = PatternType;
|
||||||
|
|
||||||
fn index(&self, index: usize) -> &Self::Output {
|
fn index(&self, index: usize) -> &Self::Output {
|
||||||
@@ -316,7 +316,7 @@ impl<'a> std::ops::Index<usize> for PatternView<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> std::ops::Index<i32> for PatternView<'_> {
|
impl std::ops::Index<i32> for PatternView<'_> {
|
||||||
type Output = PatternType;
|
type Output = PatternType;
|
||||||
|
|
||||||
fn index(&self, index: i32) -> &Self::Output {
|
fn index(&self, index: i32) -> &Self::Output {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ impl GridSampler for DefaultGridSampler {
|
|||||||
dimensionY: u32,
|
dimensionY: u32,
|
||||||
controls: &[SamplerControl],
|
controls: &[SamplerControl],
|
||||||
) -> Result<(BitMatrix, [Point; 4])> {
|
) -> Result<(BitMatrix, [Point; 4])> {
|
||||||
if dimensionX <= 0 || dimensionY <= 0 {
|
if dimensionX == 0 || dimensionY == 0 {
|
||||||
return Err(Exceptions::NOT_FOUND);
|
return Err(Exceptions::NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -417,9 +417,10 @@ fn test_encode_decode_random(field: GenericGFRef, dataSize: usize, ecSize: usize
|
|||||||
for _i in 0..iterations {
|
for _i in 0..iterations {
|
||||||
//for (int i = 0; i < iterations; i++) {
|
//for (int i = 0; i < iterations; i++) {
|
||||||
// generate random data
|
// generate random data
|
||||||
for k in 0..dataSize {
|
for data in dataWords.iter_mut().take(dataSize) {
|
||||||
|
// for k in 0..dataSize {
|
||||||
//for (int k = 0; k < dataSize; k++) {
|
//for (int k = 0; k < dataSize; k++) {
|
||||||
dataWords[k] = random.gen_range(0..field.getSize().try_into().unwrap());
|
*data = random.gen_range(0..field.getSize().try_into().unwrap());
|
||||||
}
|
}
|
||||||
// generate ECC words
|
// generate ECC words
|
||||||
message[0..dataWords.len()].clone_from_slice(&dataWords[..]);
|
message[0..dataWords.len()].clone_from_slice(&dataWords[..]);
|
||||||
|
|||||||
@@ -116,12 +116,12 @@ mod BitArrayBuilderTest {
|
|||||||
checkBinary(&pairValues, expected);
|
checkBinary(&pairValues, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkBinary(pairValues: &Vec<Vec<u32>>, expected: &str) {
|
fn checkBinary(pairValues: &[Vec<u32>], expected: &str) {
|
||||||
let binary = buildBitArray(pairValues);
|
let binary = buildBitArray(pairValues);
|
||||||
assert_eq!(expected, binary.to_string());
|
assert_eq!(expected, binary.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buildBitArray(pairValues: &Vec<Vec<u32>>) -> BitArray {
|
fn buildBitArray(pairValues: &[Vec<u32>]) -> BitArray {
|
||||||
let mut pairs = Vec::new(); //new ArrayList<>();
|
let mut pairs = Vec::new(); //new ArrayList<>();
|
||||||
for (i, pair) in pairValues.iter().enumerate() {
|
for (i, pair) in pairValues.iter().enumerate() {
|
||||||
// for (int i = 0; i < pairValues.length; ++i) {
|
// for (int i = 0; i < pairValues.length; ++i) {
|
||||||
|
|||||||
@@ -137,8 +137,8 @@ pub fn DecodeByteSegment(
|
|||||||
pub fn ToAlphaNumericChar(value: u32) -> Result<char> {
|
pub fn ToAlphaNumericChar(value: u32) -> Result<char> {
|
||||||
let value = value as usize;
|
let value = value as usize;
|
||||||
/**
|
/**
|
||||||
* See ISO 18004:2006, 6.4.4 Table 5
|
* See ISO 18004:2006, 6.4.4 Table 5
|
||||||
*/
|
*/
|
||||||
const ALPHANUMERIC_CHARS: [char; 45] = [
|
const ALPHANUMERIC_CHARS: [char; 45] = [
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||||
@@ -301,15 +301,14 @@ pub fn DecodeBitStream(
|
|||||||
|
|
||||||
let res = (|| {
|
let res = (|| {
|
||||||
while !IsEndOfStream(&mut bits, version)? {
|
while !IsEndOfStream(&mut bits, version)? {
|
||||||
let mode: Mode;
|
let mode: Mode = if modeBitLength == 0 {
|
||||||
if modeBitLength == 0 {
|
Mode::NUMERIC // MicroQRCode version 1 is always NUMERIC and modeBitLength is 0
|
||||||
mode = Mode::NUMERIC; // MicroQRCode version 1 is always NUMERIC and modeBitLength is 0
|
|
||||||
} else {
|
} else {
|
||||||
mode = Mode::CodecModeForBits(
|
Mode::CodecModeForBits(
|
||||||
bits.readBits(modeBitLength as usize)?,
|
bits.readBits(modeBitLength as usize)?,
|
||||||
Some(version.isMicroQRCode()),
|
Some(version.isMicroQRCode()),
|
||||||
)?;
|
)?
|
||||||
}
|
};
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
Mode::FNC1_FIRST_POSITION => {
|
Mode::FNC1_FIRST_POSITION => {
|
||||||
|
|||||||
@@ -99,10 +99,9 @@ pub fn FindFinderPatterns(image: &BitMatrix, tryHarder: bool) -> FinderPatterns
|
|||||||
);
|
);
|
||||||
|
|
||||||
// make sure p is not 'inside' an already found pattern area
|
// make sure p is not 'inside' an already found pattern area
|
||||||
if res
|
if !res
|
||||||
.iter()
|
.iter()
|
||||||
.find(|old| Point::distance(p, old.p) < (old.size as f32) / 2.0)
|
.any(|old| Point::distance(p, old.p) < (old.size as f32) / 2.0)
|
||||||
.is_none()
|
|
||||||
{
|
{
|
||||||
// if (FindIf(res, [p](const auto& old) { return distance(p, old) < old.size / 2; }) == res.end()) {
|
// if (FindIf(res, [p](const auto& old) { return distance(p, old) < old.size / 2; }) == res.end()) {
|
||||||
let pattern = LocateConcentricPattern::<E2E, 5, 7>(
|
let pattern = LocateConcentricPattern::<E2E, 5, 7>(
|
||||||
@@ -149,8 +148,8 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern
|
|||||||
* (((b).size as f64) / ((a).size as f64)).powi(2) //std::pow(double(b.size) / a.size, 2)
|
* (((b).size as f64) / ((a).size as f64)).powi(2) //std::pow(double(b.size) / a.size, 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
let cosUpper: f64 = (45.0_f64 / 180.0 * 3.1415).cos(); // TODO: use c++20 std::numbers::pi_v
|
let cosUpper: f64 = (45.0_f64 / 180.0 * std::f64::consts::PI).cos(); // TODO: use c++20 std::numbers::pi_v
|
||||||
let cosLower: f64 = (135.0_f64 / 180.0 * 3.1415).cos();
|
let cosLower: f64 = (135.0_f64 / 180.0 * std::f64::consts::PI).cos();
|
||||||
|
|
||||||
let nbPatterns = (patterns).len();
|
let nbPatterns = (patterns).len();
|
||||||
|
|
||||||
@@ -1014,12 +1013,13 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDetec
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut formatInfoBits = 0;
|
let mut formatInfoBits = 0;
|
||||||
for i in 1..=15
|
for info_coord in FORMAT_INFO_COORDS.iter().take(15 + 1).skip(1)
|
||||||
|
// for i in 1..=15
|
||||||
// for (int i = 1; i <= 15; ++i)
|
// for (int i = 1; i <= 15; ++i)
|
||||||
{
|
{
|
||||||
AppendBit(
|
AppendBit(
|
||||||
&mut formatInfoBits,
|
&mut formatInfoBits,
|
||||||
image.get_point(mod2Pix.transform_point(Point::centered(FORMAT_INFO_COORDS[i]))),
|
image.get_point(mod2Pix.transform_point(Point::centered(*info_coord))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ fn testApplyMaskPenaltyRule4() {
|
|||||||
assert_eq!(30, mask_util::applyMaskPenaltyRule4(&matrix));
|
assert_eq!(30, mask_util::applyMaskPenaltyRule4(&matrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testGetDataMaskBitInternal(maskPattern: u32, expected: &Vec<Vec<u32>>) -> bool {
|
fn testGetDataMaskBitInternal(maskPattern: u32, expected: &[Vec<u32>]) -> bool {
|
||||||
for x in 0..6 {
|
for x in 0..6 {
|
||||||
// for (int x = 0; x < 6; ++x) {
|
// for (int x = 0; x < 6; ++x) {
|
||||||
for y in 0..6 {
|
for y in 0..6 {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use std::{fmt, iter::Sum};
|
use std::{fmt, iter::Sum};
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
@@ -31,20 +30,20 @@ pub type PointF = PointT<f32>;
|
|||||||
pub type PointI = PointT<u32>;
|
pub type PointI = PointT<u32>;
|
||||||
pub type Point = PointF;
|
pub type Point = PointF;
|
||||||
|
|
||||||
impl Into<PointI> for Point {
|
impl From<Point> for PointI {
|
||||||
fn into(self) -> PointI {
|
fn from(val: Point) -> Self {
|
||||||
PointI {
|
PointI {
|
||||||
x: self.x.floor() as u32,
|
x: val.x.floor() as u32,
|
||||||
y: self.y.floor() as u32,
|
y: val.y.floor() as u32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Point> for PointI {
|
impl From<PointI> for Point {
|
||||||
fn into(self) -> Point {
|
fn from(val: PointI) -> Self {
|
||||||
Point {
|
Point {
|
||||||
x: self.x as f32,
|
x: val.x as f32,
|
||||||
y: self.y as f32,
|
y: val.y as f32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +80,7 @@ where
|
|||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
pub const fn new(x: T, y: T) -> PointT<T> {
|
pub const fn new(x: T, y: T) -> PointT<T> {
|
||||||
PointT { x: x, y: y }
|
PointT { x, y }
|
||||||
}
|
}
|
||||||
pub const fn with_single(x: T) -> Self {
|
pub const fn with_single(x: T) -> Self {
|
||||||
Self { x, y: x }
|
Self { x, y: x }
|
||||||
|
|||||||
Reference in New Issue
Block a user