Skip to content

feat(compare): paper-based detection, auto alignment, page pairing and change report (#465) - #784

Open
oscar981-op wants to merge 1 commit into
OpenAEC-Foundation:mainfrom
oscar981-op:feat/compare-improvements-465
Open

oscar981-op wants to merge 1 commit into
OpenAEC-Foundation:mainfrom
oscar981-op:feat/compare-improvements-465

Conversation

@oscar981-op

Copy link
Copy Markdown
Contributor

Fixes #465.

Per gap

  1. Detection resolution:
    • About 0.2 mm/px derived from the paper size, shared by both sides (40 Mpx cap per side).
    • Tiled rendering (≤ 4096 px and 32 MB per tile); each side is kept as a 1 byte/px mask (25 MB for A0).
    • Worker detection row by row, with tolerance, minimum size and merge distance in mm.
    • Tests: a 2 mm change is found on A3, A1 and A0, and identical pages give zero changes.
  2. Sensitivity:
    • presets for line drawing, scan and text document
    • the paper colour is estimated from a preview, so black CAD backgrounds and grey scans are handled
  3. Automatic alignment:
    • A coarse search over scales and rotations (including the ratio of the two measuring scales), then a fine fit of shift, rotation and scale. Confidence badge; Auto per pair (on by default); manual dx/dy in mm, rotation and scale % override it.
    • Tests: a 1 mm / −0.6 mm / 0.3° offset is recovered to within 0.1 mm and 0.03°; A1 against an A3 plot gives scale 0.4994 without input, after which a 2 mm change is found.
  4. Page pairing:
    • pages are matched on title-block sheet number, then page label, then content (words or a thumbnail), then page order
    • a "Pages" tab with a dropdown per pair and markers for pages only in old or only in new
    • tests for inserted, removed and swapped sheets
  5. Text diff: an added/removed/modified filter.
  6. Change report:
    • CSV, or a PDF summary with old and new crops per change (up to 150)
    • ticked changes can be placed as clouds with a comment on the new document
  7. Off the main thread: detection, alignment and vector diff run in workers. Tile rendering and masking (which need pdf.js) yield between tiles.
  8. Vector comparison (investigation): an opt-in "Vector" mode compares path segments; other pages fall back to pixels. Limit: a line split into two pieces in the next revision shows as added, so pixels stay the default.
  9. Second side from disk: a Browse button, or the version of an open tab from before its last save. The Compare button now needs only one open document.

About 70 strings in all 40 locales. The PDF report uses the standard PDF font, so its headings are in English for non-Latin languages; the CSV keeps every language.

A0 timing (measured locally, Ryzen 7 3700U)

Step Time
Mask build, per side ~105 ms
Detection, known alignment 66–71 ms
Detection, alignment applied ~190 ms
Auto-alignment, once per pair ~760 ms

About 0.4 s with a known alignment and about 1.2 s on the first visit. pdf.js tile rendering is not included; it can only be measured in the app.

Behaviour changes

  • dx/dy are now millimetres on paper (before: zoom-dependent screen pixels).
  • splitOldTransform is no longer used.
  • Outside Compare: rememberPreviousPdfBytes (loader.js, saver.js) and the Compare ribbon button.

Tests

75 Compare tests (detection, alignment, pairing, report, vector, i18n). Full suite: 0 failures. vite build is clean.

Not yet checked in the running app

  • pdf.js tile rendering and its speed.
  • The toolbar layout (it now wraps to more lines), the Pages tab and the report dialogs with crops.
  • The Tauri file dialog, and placing clouds including undo.
  • Real title blocks and real CAD vector diffs.

🤖 Generated with Claude Code

… pairing and change report (OpenAEC-Foundation#465)

Detection
- Resolution derived from the paper size (about 0.2 mm per pixel on any
  sheet), pages rendered in bounded tiles into 1-byte ink masks, a per-side
  pixel budget for oversized sheets.
- Streaming mask comparison in the worker: tolerance dilation, run-based
  connected components, merge and minimum size expressed in mm on paper.
- Background colour estimated from the page instead of assuming white.
- Sensitivity presets (line drawing, scan, text document) that set
  threshold, tolerance, minimum size and merge distance together.
- Optional vector comparison of path segments for pages recognised as
  vector drawings, with the pixel comparison as fallback.

Alignment
- "Align automatically": coarse phase correlation over candidate scales
  and rotations, then patch-based similarity refinement; confidence shown,
  measuring-scale ratio used as candidate and fallback.
- Manual dx/dy (mm), rotation and scale stay available and override the
  automatic result per page pair; old-page highlights and the split line
  use the same transform as the detection.

Pairing, text and report
- Automatic page pairing on sheet number, page label or content
  fingerprint, shown as an editable list with "only in old/new" pages.
- Filter for added/removed/modified in the text tab.
- Change report as CSV and as a PDF summary with crops, and selected
  changes placed as clouds with a comment on the new document.
- The second side can be a file on disk or the version before the last
  save.

Translations for all 40 languages; unit tests for detection on A0/A1/A3,
tiling bounds, alignment, pairing, report and vector diff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Compare: detection resolution, automatic alignment, page pairing and a change report

1 participant