Crop assists and compare panel (#36) #85

Merged
crowmaki merged 4 commits from issue-36-crop-assists into main 2026-10-08 03:30:54 +00:00
Owner

Closes #36. Part of #24.

What

  • studio-core (crop_assist.rs), all on the sheet's original pixels and writing nothing:
    • analyze_source_sheet finds the figures: blobs of pixels that differ from the background (estimated from the sheet's edge; handles light, dark, noisy and transparent backgrounds). Dust is dropped and pieces that nearly touch (a head apart from its body) join into one figure.
    • Figures come back in reading order (rows from the top, left to right inside a row). The four largest are mapped to face, front, side, back. With fewer than four figures auto_fit is empty, so the Tiles stay unboxed. The other figures are the snap targets.
    • shrink_to_content shrinks a box to the content inside it; an empty box is returned as it is.
  • src-tauri: analyze_source_sheet and shrink_to_content commands (run off the async runtime) with DTOs. bindings.ts regenerated.
  • Crop session UI:
    • On open, the four largest figures box the unboxed turnaround Tiles. Other figures show as faint dashed snap targets.
    • Toolbar: Auto-fit, 1x4, 2x2 (four Tiles only), Shrink to content, Padding (px). Padding applies to auto-fit and shrink, and changing it redoes the last of those. Presets are the full grid cells and are not padded.
    • Boxes snap to figure edges while dragging or resizing (assist.ts: snapMove, snapResize); hold Alt to turn it off.
    • New ComparePanel side panel: per Tile, the current version beside the new crop in the 4:9 cell with sizes, the new / changed / unchanged status from Rust, and an Include checkbox to skip Tiles before commit.
  • Presets, padding and snapping are pure box geometry in assist.ts, since they need no pixels. Finding figures and shrinking read pixels, so they are in Rust (ADR-0003).
  • No migration. Only changed crops make versions, as before.

Tests

  • crates/studio-core/tests/crop_assist.rs (16 tests): reading order on 2x2 and 1x4 layouts, a short face staying in its row, auto-fit roles, the four largest with extra figures left as snap targets, fewer than four leaving Tiles unboxed, a blank sheet, fragment merging, noisy / transparent / dark backgrounds, an unknown sheet, shrink cases, and re-committing an auto-fit making versions only for the crops that moved.
  • src/lib/references/assist.test.ts (16 tests): presets, padding, snap targets, snapping on resize and move.
  • src-tauri/tests/source_sheets.rs: the two commands through the adapter.

Checks

  • cargo test --workspace --all-features, bun run test and bun run check pass. cargo clippy --workspace --all-targets --all-features -- -D warnings passes except a type_complexity lint on Hooks::open_window that is already on main.
  • The Svelte UI is type-checked only. It has not been run in the app, so the stage, snapping and the new panel in the webview are untested.

Open questions

  • The background is estimated from the sheet's edge, so gradient backgrounds or figures touching the edge may merge or be missed.
  • The Auto-fit button overwrites every box, including dragged ones.
  • Reading-order rows are led by the topmost figure, so a staggered layout may order oddly.
Closes #36. Part of #24. ## What - `studio-core` (`crop_assist.rs`), all on the sheet's original pixels and writing nothing: - `analyze_source_sheet` finds the figures: blobs of pixels that differ from the background (estimated from the sheet's edge; handles light, dark, noisy and transparent backgrounds). Dust is dropped and pieces that nearly touch (a head apart from its body) join into one figure. - Figures come back in reading order (rows from the top, left to right inside a row). The four largest are mapped to face, front, side, back. With fewer than four figures `auto_fit` is empty, so the Tiles stay unboxed. The other figures are the snap targets. - `shrink_to_content` shrinks a box to the content inside it; an empty box is returned as it is. - `src-tauri`: `analyze_source_sheet` and `shrink_to_content` commands (run off the async runtime) with DTOs. `bindings.ts` regenerated. - Crop session UI: - On open, the four largest figures box the unboxed turnaround Tiles. Other figures show as faint dashed snap targets. - Toolbar: Auto-fit, 1x4, 2x2 (four Tiles only), Shrink to content, Padding (px). Padding applies to auto-fit and shrink, and changing it redoes the last of those. Presets are the full grid cells and are not padded. - Boxes snap to figure edges while dragging or resizing (`assist.ts`: `snapMove`, `snapResize`); hold Alt to turn it off. - New `ComparePanel` side panel: per Tile, the current version beside the new crop in the 4:9 cell with sizes, the new / changed / unchanged status from Rust, and an Include checkbox to skip Tiles before commit. - Presets, padding and snapping are pure box geometry in `assist.ts`, since they need no pixels. Finding figures and shrinking read pixels, so they are in Rust (ADR-0003). - No migration. Only changed crops make versions, as before. ## Tests - `crates/studio-core/tests/crop_assist.rs` (16 tests): reading order on 2x2 and 1x4 layouts, a short face staying in its row, auto-fit roles, the four largest with extra figures left as snap targets, fewer than four leaving Tiles unboxed, a blank sheet, fragment merging, noisy / transparent / dark backgrounds, an unknown sheet, shrink cases, and re-committing an auto-fit making versions only for the crops that moved. - `src/lib/references/assist.test.ts` (16 tests): presets, padding, snap targets, snapping on resize and move. - `src-tauri/tests/source_sheets.rs`: the two commands through the adapter. ## Checks - `cargo test --workspace --all-features`, `bun run test` and `bun run check` pass. `cargo clippy --workspace --all-targets --all-features -- -D warnings` passes except a `type_complexity` lint on `Hooks::open_window` that is already on main. - The Svelte UI is type-checked only. It has not been run in the app, so the stage, snapping and the new panel in the webview are untested. ## Open questions - The background is estimated from the sheet's edge, so gradient backgrounds or figures touching the edge may merge or be missed. - The Auto-fit button overwrites every box, including dragged ones. - Reading-order rows are led by the topmost figure, so a staggered layout may order oddly.
crowmaki deleted branch issue-36-crop-assists 2026-10-08 03:30:54 +00:00
Sign in to join this conversation.
No description provided.