From af626afc151902080178930dd292f1eb46e77500 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Wed, 29 Mar 2023 14:30:19 -0500 Subject: [PATCH] removed todo!() from qrcode_version.rs --- .../base_extentions/qr_formatinformation.rs | 6 ++-- .../base_extentions/qrcode_version.rs | 31 ++++++++++++++----- src/qrcode/decoder/version.rs | 4 +-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs index 720abcb..414cfa2 100644 --- a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs +++ b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs @@ -2,9 +2,9 @@ use crate::qrcode::decoder::FormatInformation; impl FormatInformation { /** - * @param formatInfoBits1 format info indicator, with mask still applied - * @param formatInfoBits2 second copy of same info; both are checked at the same time to establish best match - */ + * @param formatInfoBits1 format info indicator, with mask still applied + * @param formatInfoBits2 second copy of same info; both are checked at the same time to establish best match + */ pub fn DecodeQR(formatInfoBits1: u32, formatInfoBits2: u32) -> Self { todo!() // // maks out the 'Dark Module' for mirrored and non-mirrored case (see Figure 25 in ISO/IEC 18004:2015) diff --git a/src/common/cpp_essentials/base_extentions/qrcode_version.rs b/src/common/cpp_essentials/base_extentions/qrcode_version.rs index a61fb44..4e1ba46 100644 --- a/src/common/cpp_essentials/base_extentions/qrcode_version.rs +++ b/src/common/cpp_essentials/base_extentions/qrcode_version.rs @@ -1,5 +1,5 @@ use crate::common::Result; -use crate::qrcode::decoder::{Version, VersionRef, VERSION_DECODE_INFO}; +use crate::qrcode::decoder::{Version, VersionRef, MICRO_VERSIONS, VERSIONS, VERSION_DECODE_INFO}; use crate::Exceptions; // const Version* Version::AllMicroVersions() @@ -17,13 +17,28 @@ use crate::Exceptions; impl Version { pub fn FromDimension(dimension: u32) -> Result { - todo!() - // bool isMicro = dimension < 21; - // if (dimension % DimensionStep(isMicro) != 1) { - // //throw std::invalid_argument("Unexpected dimension"); - // return nullptr; - // } - // return FromNumber((dimension - DimensionOffset(isMicro)) / DimensionStep(isMicro), isMicro); + let isMicro = dimension < 21; + if (dimension % Self::DimensionStep(isMicro) != 1) { + //throw std::invalid_argument("Unexpected dimension"); + return Err(Exceptions::ILLEGAL_ARGUMENT); + } + return Self::FromNumber( + (dimension - Self::DimensionOffset(isMicro)) / Self::DimensionStep(isMicro), + isMicro, + ); + } + + pub fn FromNumber(versionNumber: u32, is_micro: bool) -> Result { + if (versionNumber < 1 || versionNumber > (if is_micro { 4 } else { 40 })) { + //throw std::invalid_argument("Version should be in range [1-40]."); + return Err(Exceptions::ILLEGAL_ARGUMENT); + } + + Ok(if is_micro { + &MICRO_VERSIONS[versionNumber as usize - 1] + } else { + &VERSIONS[versionNumber as usize - 1] + }) } pub fn DimensionOfVersion(version: u32, is_micro: bool) -> u32 { diff --git a/src/qrcode/decoder/version.rs b/src/qrcode/decoder/version.rs index d39e360..98a1ab2 100755 --- a/src/qrcode/decoder/version.rs +++ b/src/qrcode/decoder/version.rs @@ -27,8 +27,8 @@ use once_cell::sync::Lazy; pub type VersionRef = &'static Version; -static VERSIONS: Lazy> = Lazy::new(Version::buildVersions); -static MICRO_VERSIONS: Lazy> = Lazy::new(Version::build_micro_versions); +pub static VERSIONS: Lazy> = Lazy::new(Version::buildVersions); +pub static MICRO_VERSIONS: Lazy> = Lazy::new(Version::build_micro_versions); /** * See ISO 18004:2006 Annex D.