Skip to content

Conversation

@cl445
Copy link
Owner

@cl445 cl445 commented Jan 11, 2026

Summary

  • Extract settings management into dedicated HapticSettings and LayoutSettings classes
  • Create HapticFeedbackManager to separate haptic feedback concern
  • Add Vector2D type for type-safe geometric calculations
  • Extract gesture calculation helpers into GestureCalculations enum
  • Introduce KeyBuilder fluent API for MessagEase key definitions
  • Centralize CGPoint/CGSize/CGRect extensions in GeometryUtils
  • Replace force unwraps with optional binding in GesturePreprocessor
  • Document magic numbers in KeyboardLayout

New Files

File Purpose
KeyboardSettings.swift Settings classes with persistence and clamping
HapticFeedbackManager.swift Clean haptic feedback API
Vector2D.swift 2D vector math operations
GestureFeatureCalculations.swift Extracted gesture analysis helpers
KeyBuilder.swift Fluent builder for key definitions
GeometryUtils.swift Centralized geometry extensions

Test Coverage

Added 5 new test files with 50+ test cases covering all new components:

  • Vector2DTests.swift
  • GestureCalculationsTests.swift
  • KeyboardSettingsTests.swift
  • KeyBuilderTests.swift
  • GeometryUtilsTests.swift

Test plan

  • All 160+ unit tests pass
  • Build succeeds on iOS Simulator
  • Manual testing of keyboard in simulator

cl445 added 4 commits January 11, 2026 22:34
- Extract KeyboardSettings and HapticSettings from KeyboardViewModel
  - Eliminates duplicate didSet handlers for haptic intensity properties
  - Centralizes settings persistence logic
  - Adds SettingsKey enum for type-safe UserDefaults keys

- Extract HapticFeedbackManager from KeyboardViewModel
  - Separates haptic feedback concern from keyboard state management
  - Cleaner API: tap(), modifier(), drag() methods

- Add Vector2D type for geometric calculations
  - Type-safe 2D vector operations (dot, cross, angle, etc.)
  - Improves code readability in gesture processing

- Add GestureFeatureCalculations helper functions
  - Extracted from GestureFeatures.extract() for better testability
  - Pure functions for pathLength, centroid, circularity, etc.

- Add KeyBuilder pattern for MessagEase key definitions
  - Fluent API for building key configurations
  - Reduces boilerplate in KeyboardLayout.swift
  - Example: KeyBuilder("a").swipe(.up, "ä").build(locale: de)

- Fix force unwraps in GesturePreprocessor
  - Replace force unwraps with optional binding
  - Safer handling of edge cases

- Document magic numbers in KeyboardConstants
  - Added documentation explaining purpose of each constant
  - e.g., minSwipeLength: 30pt ≈ 55% of key height
- Refactor GestureFeatures.extract() to use GestureCalculations
  - Reduces method from ~165 lines to ~55 lines
  - All calculations now delegated to testable helper functions

- Add GeometryUtils.swift for centralized CGPoint extensions
  - distance(to:), magnitude(), asVector, vector(to:)
  - Removes duplicate definitions from KeyboardLayout.swift and Vector2D.swift

- GestureCalculations now properly uses Vector2D
  - angularSpan() and turnConsistency() use Vector2D for cleaner math
Tests for Vector2D, GestureCalculations, KeyboardSettings,
KeyBuilder, and GeometryUtils - all 160+ tests passing.
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.

2 participants