From f9ea8b97f9b9853d0db8086734a67853b90882ae Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Thu, 13 Oct 2022 18:30:43 -0500 Subject: [PATCH] a tiny bit more precision, still fails on 90 degree rotation --- src/qrcode/detector/finder_pattern_finder.rs | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/qrcode/detector/finder_pattern_finder.rs b/src/qrcode/detector/finder_pattern_finder.rs index 0fd8fb3..f99c4b1 100755 --- a/src/qrcode/detector/finder_pattern_finder.rs +++ b/src/qrcode/detector/finder_pattern_finder.rs @@ -210,14 +210,14 @@ impl FinderPatternFinder { if totalModuleSize < 7 { return false; } - let moduleSize = totalModuleSize as f32 / 7.0; - let maxVariance = moduleSize as f32 / 2.0; + let moduleSize = totalModuleSize as f64 / 7.0; + let maxVariance = moduleSize as f64 / 2.0; // Allow less than 50% variance from 1-1-3-1-1 proportions - return ((moduleSize - stateCount[0] as f32).abs()) < maxVariance - && ((moduleSize - stateCount[1] as f32).abs()) < maxVariance - && ((3.0 * moduleSize - stateCount[2] as f32).abs()) < 3.0 * maxVariance - && (moduleSize - stateCount[3] as f32).abs() < maxVariance - && (moduleSize - stateCount[4] as f32).abs() < maxVariance; + return ((moduleSize - stateCount[0] as f64).abs()) < maxVariance + && ((moduleSize - stateCount[1] as f64).abs()) < maxVariance + && ((3.0 * moduleSize - stateCount[2] as f64).abs()) < 3.0 * maxVariance + && (moduleSize - stateCount[3] as f64).abs() < maxVariance + && (moduleSize - stateCount[4] as f64).abs() < maxVariance; } /** @@ -238,14 +238,14 @@ impl FinderPatternFinder { if totalModuleSize < 7 { return false; } - let moduleSize = totalModuleSize as f32 / 7.0; + let moduleSize = totalModuleSize as f64 / 7.0; let maxVariance = moduleSize / 1.333; // Allow less than 75% variance from 1-1-3-1-1 proportions - return (moduleSize - stateCount[0] as f32).abs() < maxVariance - && (moduleSize - stateCount[1] as f32).abs() < maxVariance - && (3.0 * moduleSize - stateCount[2] as f32).abs() < 3.0 * maxVariance - && (moduleSize - stateCount[3] as f32).abs() < maxVariance - && (moduleSize - stateCount[4] as f32).abs() < maxVariance; + return (moduleSize - stateCount[0] as f64).abs() < maxVariance + && (moduleSize - stateCount[1] as f64).abs() < maxVariance + && (3.0 * moduleSize - stateCount[2] as f64).abs() < 3.0 * maxVariance + && (moduleSize - stateCount[3] as f64).abs() < maxVariance + && (moduleSize - stateCount[4] as f64).abs() < maxVariance; } fn getCrossCheckStateCount(&mut self) -> &[u32; 5] {