Skip to content

refactor: separate UI from calibration logic in DoubleCalibrationRecord.vue (#112)#117

Open
harsshks wants to merge 5 commits intoruxailab:mainfrom
harsshks:refactor/issue-112-separate-ui-logic
Open

refactor: separate UI from calibration logic in DoubleCalibrationRecord.vue (#112)#117
harsshks wants to merge 5 commits intoruxailab:mainfrom
harsshks:refactor/issue-112-separate-ui-logic

Conversation

@harsshks
Copy link
Copy Markdown

@harsshks harsshks commented Mar 6, 2026

Summary

Resolves #112

Refactors DoubleCalibrationRecord.vue by extracting calibration math and webcam handling into dedicated modules, reducing the component by ~245 lines and improving separation of concerns.

Changes

New Files

  • src/services/CalibrationCalculator.js — Pure utility functions (no Vue dependencies):

    • generateCalibrationPattern() — generates point patterns for 1–9 calibration points
    • generateRuntimePattern() — dynamic pattern based on screen size and store config
    • calculateDistance() — Euclidean distance for eye-blink detection
  • src/mixins/CameraMixin.js — Reusable Vue mixin for webcam/MediaRecorder:

    • startWebCamCapture() — camera access with fallback constraints
    • detectFace() — face-landmark detection with auto-retry
    • stopRecord() / stopWebCamCapture() — cleanup

Modified Files

  • src/views/DoubleCalibrationRecord.vue — imports and delegates to the new service and mixin instead of inline implementations

Why This Matters

  • Testability: CalibrationCalculator.js is pure functions — easy to unit test without mocking Vue
  • Reusability: CameraMixin.js can be used by other components that need camera access (e.g., CameraConfiguration.vue)
  • Maintainability: Component focuses on UI orchestration, not implementation details

Testing

  • ✅ Build compiles successfully (npx vue-cli-service build)
  • ⬜ Manual testing with webcam (requires camera + backend)

Dependencies

This PR is based on feat/fullscreen-calibration (PR #103). It should be merged after #103.

- Enter fullscreen during training and validation
- Exit fullscreen on completion or route leave
- Fix camera preview being clipped by stepper container
- Allow natural scrolling during calibration

Fixes ruxailab#100
- Add calibration mode selection (multi-point vs single-point)
- Update store with calibrationMode state and mutations
- Add single-point pattern generation (center screen)
- Update DoubleCalibrationRecord.vue to support single-point mode
- Add calibration mode selector in CameraConfiguration.vue
- Dynamic stepper content based on calibration mode
- Maintain backward compatibility with existing multi-point mode

Features:
- Quick single-point calibration for faster setup
- Lower accuracy trade-off for speed
- Center screen point positioning
- Dynamic UI based on selected mode
- Proper state management integration

Addresses ruxailab#99
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 DoubleCalibrationRecord.vue to separate UI from logic

1 participant