reorganize some impl blocks

This commit is contained in:
Henry Schimke
2023-03-20 15:33:01 -05:00
parent 0df86d4fd4
commit 372bb454c0
6 changed files with 53 additions and 46 deletions

View File

@@ -0,0 +1,3 @@
mod bitmatrix;
mod qr_formatinformation;
mod qrcode_version;

View File

@@ -0,0 +1,47 @@
use crate::common::Result;
use crate::qrcode::decoder::{Version, VersionRef, VERSION_DECODE_INFO};
use crate::Exceptions;
impl Version {
pub fn DimensionOfVersion(version: u32, is_micro: bool) -> u32 {
Self::DimensionOffset(is_micro) + Self::DimensionStep(is_micro) * version
}
pub fn DimensionOffset(is_micro: bool) -> u32 {
unimplemented!()
}
pub fn DimensionStep(is_micro: bool) -> u32 {
unimplemented!()
}
pub fn DecodeVersionInformation(versionBitsA: i32, versionBitsB: i32) -> Result<VersionRef> {
let mut bestDifference = u32::MAX;
let mut bestVersion = 0;
let mut i = 0;
for targetVersion in VERSION_DECODE_INFO {
// for (int targetVersion : VERSION_DECODE_INFO) {
// Do the version info bits match exactly? done.
if targetVersion == versionBitsA as u32 || targetVersion == versionBitsB as u32 {
return Self::getVersionForNumber(i + 7);
}
// Otherwise see if this is the closest to a real version info bit string
// we have seen so far
for bits in [versionBitsA, versionBitsB] {
// for (int bits : {versionBitsA, versionBitsB}) {
let bitsDifference = ((bits as u32) ^ targetVersion).count_ones(); //BitHacks::CountBitsSet(bits ^ targetVersion);
if bitsDifference < bestDifference {
bestVersion = i + 7;
bestDifference = bitsDifference;
}
}
i += 1;
}
// We can tolerate up to 3 bits of error since no two version info codewords will
// differ in less than 8 bits.
if bestDifference <= 3 {
return Self::getVersionForNumber(bestVersion);
}
// If we didn't find a close enough match, fail
return Err(Exceptions::ILLEGAL_STATE);
}
}

View File

@@ -1,4 +1,5 @@
mod bitmatrix;
mod base_extentions;
pub mod bitmatrix_cursor;
pub mod bitmatrix_cursor_trait;
pub mod concentric_finder;
@@ -8,7 +9,6 @@ pub mod edge_tracer;
pub mod fast_edge_to_edge_counter;
pub mod matrix;
pub mod pattern;
mod qr_formatinformation;
pub mod regression_line;
pub mod regression_line_trait;
pub mod step_result;