From 58e6827e89b9cc1d54fecfe570bbeacfc8c5f6e1 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Fri, 27 Jan 2023 15:14:01 -0600 Subject: [PATCH] cargo fmt --- src/common/bit_matrix.rs | 8 +- src/maxicode/detector.rs | 156 +++++++++---------- tests/common/abstract_black_box_test_case.rs | 5 +- 3 files changed, 86 insertions(+), 83 deletions(-) diff --git a/src/common/bit_matrix.rs b/src/common/bit_matrix.rs index 9bfdfb2..7d12cc0 100644 --- a/src/common/bit_matrix.rs +++ b/src/common/bit_matrix.rs @@ -231,7 +231,7 @@ impl BitMatrix { let start_x = x - box_size / 2; let end_x = x + box_size / 2; let start_y = y - box_size / 2; - let end_y = y+ box_size / 2; + let end_y = y + box_size / 2; for get_x in start_x..=end_x { for get_y in start_y..=end_y { @@ -239,10 +239,10 @@ impl BitMatrix { } } - let total_set = matrix.iter().filter(|bit| **bit ).count(); - if (total_set as f32 / matrix.len() as f32) >=0.5 { + let total_set = matrix.iter().filter(|bit| **bit).count(); + if (total_set as f32 / matrix.len() as f32) >= 0.5 { Some(true) - }else { + } else { Some(false) } } diff --git a/src/maxicode/detector.rs b/src/maxicode/detector.rs index 2b18599..007de57 100644 --- a/src/maxicode/detector.rs +++ b/src/maxicode/detector.rs @@ -819,91 +819,91 @@ fn attempt_rotation_box( for int_rotation in 0..175 { let rotation = (int_rotation * 2) as f32; - // look for top left - // * * - // * - let p1_rot = get_point(circle.center, topl_p1, rotation); - let p2_rot = get_point(circle.center, topl_p2, rotation); - let p3_rot = get_point(circle.center, topl_p3, rotation); - let found_tl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32,3)? - && image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32,3)? - && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32,3)?; - if !found_tl { - continue; - } + // look for top left + // * * + // * + let p1_rot = get_point(circle.center, topl_p1, rotation); + let p2_rot = get_point(circle.center, topl_p2, rotation); + let p3_rot = get_point(circle.center, topl_p3, rotation); + let found_tl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)? + && image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)? + && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?; + if !found_tl { + continue; + } - // look for top right - // /\ - // __ - let p1_rot = get_point(circle.center, topr_p1, rotation); - let p2_rot = get_point(circle.center, topr_p2, rotation); - let p3_rot = get_point(circle.center, topr_p3, rotation); - let found_tr = !image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32,3)? - && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32,3)? - && !image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32,3)?; - if !found_tr { - continue; - } + // look for top right + // /\ + // __ + let p1_rot = get_point(circle.center, topr_p1, rotation); + let p2_rot = get_point(circle.center, topr_p2, rotation); + let p3_rot = get_point(circle.center, topr_p3, rotation); + let found_tr = !image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)? + && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)? + && !image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?; + if !found_tr { + continue; + } - // look for left - // * - // * - let p1_rot = get_point(circle.center, l_p1, rotation); - let p2_rot = get_point(circle.center, l_p2, rotation); - let p3_rot = get_point(circle.center, l_p3, rotation); - let found_l = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32,3)? - && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32,3)? - && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32,3)?; - if !found_l { - continue; - } + // look for left + // * + // * + let p1_rot = get_point(circle.center, l_p1, rotation); + let p2_rot = get_point(circle.center, l_p2, rotation); + let p3_rot = get_point(circle.center, l_p3, rotation); + let found_l = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)? + && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)? + && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?; + if !found_l { + continue; + } - // look for right - // * - // * - let p1_rot = get_point(circle.center, r_p1, rotation); - let p2_rot = get_point(circle.center, r_p2, rotation); - let p3_rot = get_point(circle.center, r_p3, rotation); - let found_r = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32,3)? - && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32,3)? - && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32,3)?; - if !found_r { - continue; - } + // look for right + // * + // * + let p1_rot = get_point(circle.center, r_p1, rotation); + let p2_rot = get_point(circle.center, r_p2, rotation); + let p3_rot = get_point(circle.center, r_p3, rotation); + let found_r = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)? + && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)? + && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?; + if !found_r { + continue; + } - // look for bottom left - // * - // * - let p1_rot = get_point(circle.center, bottoml_p1, rotation); - let p2_rot = get_point(circle.center, bottoml_p2, rotation); - let p3_rot = get_point(circle.center, bottoml_p3, rotation); - let found_bl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32,3)? - && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32,3)? - && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32,3)?; - if !found_bl { - continue; - } + // look for bottom left + // * + // * + let p1_rot = get_point(circle.center, bottoml_p1, rotation); + let p2_rot = get_point(circle.center, bottoml_p2, rotation); + let p3_rot = get_point(circle.center, bottoml_p3, rotation); + let found_bl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)? + && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)? + && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?; + if !found_bl { + continue; + } - // look for bottom right - // * - // * - let p1_rot = get_point(circle.center, bottomr_p1, rotation); - let p2_rot = get_point(circle.center, bottomr_p2, rotation); - let p3_rot = get_point(circle.center, bottomr_p3, rotation); - let found_br = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32,3)? - && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32,3)? - && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32,3)?; - if !found_br { - continue; - } + // look for bottom right + // * + // * + let p1_rot = get_point(circle.center, bottomr_p1, rotation); + let p2_rot = get_point(circle.center, bottomr_p2, rotation); + let p3_rot = get_point(circle.center, bottomr_p3, rotation); + let found_br = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)? + && !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)? + && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?; + if !found_br { + continue; + } - // did we find it? - found = found_tl && found_tr && found_l && found_r && found_bl && found_br; + // did we find it? + found = found_tl && found_tr && found_l && found_r && found_bl && found_br; - if found { - final_rotation = rotation; - break; - } + if found { + final_rotation = rotation; + break; + } } if found { diff --git a/tests/common/abstract_black_box_test_case.rs b/tests/common/abstract_black_box_test_case.rs index 1ed84ee..9b4900e 100644 --- a/tests/common/abstract_black_box_test_case.rs +++ b/tests/common/abstract_black_box_test_case.rs @@ -124,7 +124,10 @@ impl AbstractBlackBoxTestCase { .filter(|r| r.is_ok()) // Get rid of Err variants for Result .map(|r| r.unwrap().path()) // This is safe, since we only have the Ok variants .filter(|r| r.is_file()) // Filter out non-folders - .filter(|r| r.extension().is_some() && POSSIBLE_EXTENSIONS.contains(r.extension().unwrap().to_str().unwrap())) + .filter(|r| { + r.extension().is_some() + && POSSIBLE_EXTENSIONS.contains(r.extension().unwrap().to_str().unwrap()) + }) // .map(|r| r.into_boxed_path()) .collect::>();