cargo fmt

This commit is contained in:
Henry Schimke
2023-01-27 15:14:01 -06:00
parent d2728e0414
commit 58e6827e89
3 changed files with 86 additions and 83 deletions

View File

@@ -231,7 +231,7 @@ impl BitMatrix {
let start_x = x - box_size / 2; let start_x = x - box_size / 2;
let end_x = x + box_size / 2; let end_x = x + box_size / 2;
let start_y = y - 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_x in start_x..=end_x {
for get_y in start_y..=end_y { for get_y in start_y..=end_y {
@@ -239,10 +239,10 @@ impl BitMatrix {
} }
} }
let total_set = matrix.iter().filter(|bit| **bit ).count(); let total_set = matrix.iter().filter(|bit| **bit).count();
if (total_set as f32 / matrix.len() as f32) >=0.5 { if (total_set as f32 / matrix.len() as f32) >= 0.5 {
Some(true) Some(true)
}else { } else {
Some(false) Some(false)
} }
} }

View File

@@ -819,91 +819,91 @@ fn attempt_rotation_box(
for int_rotation in 0..175 { for int_rotation in 0..175 {
let rotation = (int_rotation * 2) as f32; let rotation = (int_rotation * 2) as f32;
// look for top left // look for top left
// * * // * *
// * // *
let p1_rot = get_point(circle.center, topl_p1, rotation); let p1_rot = get_point(circle.center, topl_p1, rotation);
let p2_rot = get_point(circle.center, topl_p2, rotation); let p2_rot = get_point(circle.center, topl_p2, rotation);
let p3_rot = get_point(circle.center, topl_p3, 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)? 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(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)?; && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
if !found_tl { if !found_tl {
continue; continue;
} }
// look for top right // look for top right
// /\ // /\
// __ // __
let p1_rot = get_point(circle.center, topr_p1, rotation); let p1_rot = get_point(circle.center, topr_p1, rotation);
let p2_rot = get_point(circle.center, topr_p2, rotation); let p2_rot = get_point(circle.center, topr_p2, rotation);
let p3_rot = get_point(circle.center, topr_p3, 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)? 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(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)?; && !image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
if !found_tr { if !found_tr {
continue; continue;
} }
// look for left // look for left
// * // *
// * // *
let p1_rot = get_point(circle.center, l_p1, rotation); let p1_rot = get_point(circle.center, l_p1, rotation);
let p2_rot = get_point(circle.center, l_p2, rotation); let p2_rot = get_point(circle.center, l_p2, rotation);
let p3_rot = get_point(circle.center, l_p3, 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)? 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(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)?; && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
if !found_l { if !found_l {
continue; continue;
} }
// look for right // look for right
// * // *
// * // *
let p1_rot = get_point(circle.center, r_p1, rotation); let p1_rot = get_point(circle.center, r_p1, rotation);
let p2_rot = get_point(circle.center, r_p2, rotation); let p2_rot = get_point(circle.center, r_p2, rotation);
let p3_rot = get_point(circle.center, r_p3, 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)? 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(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)?; && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
if !found_r { if !found_r {
continue; continue;
} }
// look for bottom left // look for bottom left
// * // *
// * // *
let p1_rot = get_point(circle.center, bottoml_p1, rotation); let p1_rot = get_point(circle.center, bottoml_p1, rotation);
let p2_rot = get_point(circle.center, bottoml_p2, rotation); let p2_rot = get_point(circle.center, bottoml_p2, rotation);
let p3_rot = get_point(circle.center, bottoml_p3, 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)? 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(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)?; && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
if !found_bl { if !found_bl {
continue; continue;
} }
// look for bottom right // look for bottom right
// * // *
// * // *
let p1_rot = get_point(circle.center, bottomr_p1, rotation); let p1_rot = get_point(circle.center, bottomr_p1, rotation);
let p2_rot = get_point(circle.center, bottomr_p2, rotation); let p2_rot = get_point(circle.center, bottomr_p2, rotation);
let p3_rot = get_point(circle.center, bottomr_p3, 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)? 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(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)?; && image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
if !found_br { if !found_br {
continue; continue;
} }
// did we find it? // did we find it?
found = found_tl && found_tr && found_l && found_r && found_bl && found_br; found = found_tl && found_tr && found_l && found_r && found_bl && found_br;
if found { if found {
final_rotation = rotation; final_rotation = rotation;
break; break;
} }
} }
if found { if found {

View File

@@ -124,7 +124,10 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
.filter(|r| r.is_ok()) // Get rid of Err variants for Result<DirEntry> .filter(|r| r.is_ok()) // Get rid of Err variants for Result<DirEntry>
.map(|r| r.unwrap().path()) // This is safe, since we only have the Ok variants .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.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()) // .map(|r| r.into_boxed_path())
.collect::<Vec<PathBuf>>(); .collect::<Vec<PathBuf>>();