From 302a83f84f58357e6e8e61895d9216da215abb94 Mon Sep 17 00:00:00 2001 From: Sachin Iyer Date: Fri, 6 Mar 2026 03:30:10 -0800 Subject: [PATCH 1/4] fix(satisfying-sort): remove incorrect pixel-center offset in logo mask sampling The +0.5 offset in mask_region_at was intended for continuous pixel-center sampling but is incorrect for discrete pixel-to-pixel coordinate mapping. It caused the viewport corner (0,0) to map to logo pixel (2,5) instead of (0,0), shifting/cropping the logo and misclassifying 7-12% of pixels. Fixes #125 Detail bug: bug_8f5a6e86-4467-41d4-af7c-0c168357e204 Co-Authored-By: Claude Opus 4.6 --- src/commands/satisfying_sort/logo_math.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/satisfying_sort/logo_math.rs b/src/commands/satisfying_sort/logo_math.rs index 6c25401..9d78fda 100644 --- a/src/commands/satisfying_sort/logo_math.rs +++ b/src/commands/satisfying_sort/logo_math.rs @@ -139,10 +139,10 @@ fn mask_region_at( } let x = floor_f32_to_usize( - ((usize_to_f32(local_x) + 0.5) * usize_to_f32(logo.width)) / usize_to_f32(viewport_width), + (usize_to_f32(local_x) * usize_to_f32(logo.width)) / usize_to_f32(viewport_width), ); let y = floor_f32_to_usize( - ((usize_to_f32(local_y) + 0.5) * usize_to_f32(logo.height)) / usize_to_f32(viewport_height), + (usize_to_f32(local_y) * usize_to_f32(logo.height)) / usize_to_f32(viewport_height), ); logo.regions[y.min(logo.height - 1) * logo.width + x.min(logo.width - 1)] } From ab484edd28bd891bf9741df9a0e99d90c96be280 Mon Sep 17 00:00:00 2001 From: Sachin Iyer Date: Fri, 6 Mar 2026 15:03:08 -0800 Subject: [PATCH 2/4] fix(satisfying-sort): use endpoint-to-endpoint mapping for logo mask sampling Map [0, viewport-1] to [0, logo-1] so both corners of the logo are correctly represented. The previous fix removed the +0.5 offset but still used a ratio-of-sizes mapping that couldn't reach the last logo pixel, breaking the square symmetry. Co-Authored-By: Claude Opus 4.6 --- src/commands/satisfying_sort/logo_math.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/satisfying_sort/logo_math.rs b/src/commands/satisfying_sort/logo_math.rs index 9d78fda..1f6610e 100644 --- a/src/commands/satisfying_sort/logo_math.rs +++ b/src/commands/satisfying_sort/logo_math.rs @@ -138,11 +138,13 @@ fn mask_region_at( return LogoRegion::Empty; } - let x = floor_f32_to_usize( - (usize_to_f32(local_x) * usize_to_f32(logo.width)) / usize_to_f32(viewport_width), + let max_vx = usize_to_f32(viewport_width.saturating_sub(1).max(1)); + let max_vy = usize_to_f32(viewport_height.saturating_sub(1).max(1)); + let x = round_f32_to_usize( + usize_to_f32(local_x) / max_vx * usize_to_f32(logo.width - 1), ); - let y = floor_f32_to_usize( - (usize_to_f32(local_y) * usize_to_f32(logo.height)) / usize_to_f32(viewport_height), + let y = round_f32_to_usize( + usize_to_f32(local_y) / max_vy * usize_to_f32(logo.height - 1), ); logo.regions[y.min(logo.height - 1) * logo.width + x.min(logo.width - 1)] } From dc60628c04e5acb0af4a733b9e765f727ed019e8 Mon Sep 17 00:00:00 2001 From: Sachin Iyer Date: Fri, 6 Mar 2026 15:29:22 -0800 Subject: [PATCH 3/4] chore(lint): deny `as` casts via clippy lint Prefer `try_into`/`into`/`From` over `as` casts to prevent silent truncation and lossy conversions. Co-Authored-By: Claude Opus 4.6 --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 97169a9..6ada186 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,9 @@ regress = "0.10.5" clap-markdown = "0.1" # The profile that 'dist' will build with +[lints.clippy] +as_conversions = "deny" + [profile.dist] inherits = "release" lto = "thin" From 5156919bafd7bdfe8f41364989794b8288f59c44 Mon Sep 17 00:00:00 2001 From: Sachin Iyer Date: Fri, 6 Mar 2026 15:33:12 -0800 Subject: [PATCH 4/4] style: fix rustfmt formatting in logo_math.rs Co-Authored-By: Claude Opus 4.6 --- src/commands/satisfying_sort/logo_math.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/commands/satisfying_sort/logo_math.rs b/src/commands/satisfying_sort/logo_math.rs index 1f6610e..aa05504 100644 --- a/src/commands/satisfying_sort/logo_math.rs +++ b/src/commands/satisfying_sort/logo_math.rs @@ -140,12 +140,8 @@ fn mask_region_at( let max_vx = usize_to_f32(viewport_width.saturating_sub(1).max(1)); let max_vy = usize_to_f32(viewport_height.saturating_sub(1).max(1)); - let x = round_f32_to_usize( - usize_to_f32(local_x) / max_vx * usize_to_f32(logo.width - 1), - ); - let y = round_f32_to_usize( - usize_to_f32(local_y) / max_vy * usize_to_f32(logo.height - 1), - ); + let x = round_f32_to_usize(usize_to_f32(local_x) / max_vx * usize_to_f32(logo.width - 1)); + let y = round_f32_to_usize(usize_to_f32(local_y) / max_vy * usize_to_f32(logo.height - 1)); logo.regions[y.min(logo.height - 1) * logo.width + x.min(logo.width - 1)] }