Refactor: reusable preview module, geometry tests, App decomposition (#5) - #6
Merged
Conversation
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>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 modulePreviewCanvas.tsx(~690 lines) split into focused pieces (~85 lines avg):useViewport(zoom/pan + rAF),useCanvasSize(ResizeObserver/DPR),useSpatialIndex(RBush hit-test + box query),usePointerInteraction(click/box-select/pan),useWheelZoom(native{passive:false})transform(world↔screen),renderScene(board/holes/OTL/partitions/selection box),colors(theme colors cached per theme)PreviewCanvasorchestrator +ZoomControlsFolded-in perf: theme colors read once per theme instead of
getComputedStyleevery 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), andcomputeTubeStats(active counts, heat-transfer area with custom diameters, partition/edge conflicts).3.
App.tsxdecomposition615 → 115 lines of composition:
useHoleEditing— selection (single/toggle/box + symmetry) and per-hole editsuseSession— DXF/STEP/JSON export-import with progress/error stateExportPanel/PropertiesPanel— presentational panelscore/tube-stats(purecomputeTubeStats, tested) +core/modified-holeVerification
pnpm typecheck✅ ·pnpm test(55) ✅ ·pnpm build✅🤖 Generated with Claude Code