Skip to content

Refactor: reusable preview module, geometry tests, App decomposition (#5) - #6

Merged
YurMil merged 3 commits into
mainfrom
refactor/preview-module-tests
Jul 17, 2026
Merged

Refactor: reusable preview module, geometry tests, App decomposition (#5)#6
YurMil merged 3 commits into
mainfrom
refactor/preview-module-tests

Conversation

@YurMil

@YurMil YurMil commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Closes #5.

Structural refactor of the two oversized UI files into a reusable, library-style architecture, backed by a Vitest safety net. Pure refactor — no behaviour change; verified end-to-end in the browser.

1. Reusable src/ui/preview/ canvas-viewer module

PreviewCanvas.tsx (~690 lines) split into focused pieces (~85 lines avg):

  • hooks: useViewport (zoom/pan + rAF), useCanvasSize (ResizeObserver/DPR), useSpatialIndex (RBush hit-test + box query), usePointerInteraction (click/box-select/pan), useWheelZoom (native {passive:false})
  • pure modules: transform (world↔screen), renderScene (board/holes/OTL/partitions/selection box), colors (theme colors cached per theme)
  • components: thin PreviewCanvas orchestrator + ZoomControls

Folded-in perf: theme colors read once per theme instead of getComputedStyle every frame; point keys precomputed once per points change instead of per-point-per-frame.

2. Vitest + tests

Added Vitest (runs in CI between typecheck and build). 55 tests covering layout strategies (non-empty, centre point, safe-radius containment, no duplicates, axis symmetry, expected counts), geometry-utils (validation, safe radius, point-count estimate, cutoff/partition bands, key normalisation), transform (world↔screen round-trip), and computeTubeStats (active counts, heat-transfer area with custom diameters, partition/edge conflicts).

3. App.tsx decomposition

615 → 115 lines of composition:

  • useHoleEditing — selection (single/toggle/box + symmetry) and per-hole edits
  • useSession — DXF/STEP/JSON export-import with progress/error state
  • ExportPanel / PropertiesPanel — presentational panels
  • core/tube-stats (pure computeTubeStats, tested) + core/modified-hole

Verification

  • pnpm typecheck ✅ · pnpm test (55) ✅ · pnpm build
  • In-browser: identical render, click-select, box-select (17 holes), wheel zoom (preventDefault works), tie-rod edit (metrics + area recompute), reset, session export + import round-trip (params + square hole), no error boundary.

🤖 Generated with Claude Code

YurMil and others added 3 commits July 17, 2026 19:19
Cover layout strategies (non-empty, centre point, safe-radius containment,
no duplicates, axis symmetry, expected counts) and geometry-utils (validation,
safe radius, point-count estimate, cutoff/partition bands, key normalisation).
Run them in CI between typecheck and build.

Refs #5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Split the ~690-line component into src/ui/preview/:
- hooks: useViewport, useCanvasSize, useSpatialIndex, usePointerInteraction,
  useWheelZoom
- pure modules: transform (world/screen), renderScene (board/holes/OTL/
  partitions/selection box), colors (theme colors cached per theme)
- components: thin PreviewCanvas orchestrator + ZoomControls

Behaviour is unchanged. Folded-in perf: theme colors are read once per theme
instead of via getComputedStyle every frame, and point keys are precomputed
once per points change instead of rebuilt per point per frame.

Refs #5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
App shrinks from ~615 to ~115 lines of composition:
- useHoleEditing: selection (single/toggle/box + symmetry) and per-hole edits
- useSession: DXF/STEP/JSON export-import with progress and error state
- ExportPanel / PropertiesPanel: presentational panels
- core/tube-stats: pure computeTubeStats (with unit tests) + core/modified-hole

Behaviour is unchanged. Refs #5.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@YurMil
YurMil merged commit 53a1ffa into main Jul 17, 2026
2 checks passed
@YurMil
YurMil deleted the refactor/preview-module-tests branch July 17, 2026 16:34
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.

Refactor: reusable preview module, geometry tests, App decomposition

1 participant