DrawingPoint (persisted source of truth) and Waypoint (derived view-model) serve distinct roles. Merging them is not recommended.
CurrentRouteState.points is [DrawingPoint]. Whenever points is set, waypoints is automatically rebuilt via a didSet:
var points: [DrawingPoint] = [] {
didSet {
waypoints = BuildWaypoints.call(routePoints: points)
isSaved = false
objectWillChange.send()
}
}| Property | DrawingPoint | Waypoint |
|---|---|---|
id / drawingPointID |
✅ | ✅ (mirrors DrawingPoint id) |
coordinate |
✅ | ✅ (copied) |
name |
✅ | ✅ (copied) |
index |
✅ | ❌ |
kind (start/turn/end) |
❌ | ✅ (derived from position) |
pinLabel ("A", "B") |
❌ | ✅ (derived from index) |
pinDescription |
❌ | ✅ (derived from name + kind) |
pinColor |
❌ | ✅ (currently always .track) |
Codable |
✅ | ❌ |
-
DrawingPointisCodableand persisted — saved to the database and to JSON. Adding derived display properties would mean either making themCodabletoo (wasteful) or adding custom coding logic. -
DrawingPointis shared with tracks —DrawingusesDrawingPointfor both routes and tracks. TheWaypointconcept (start/turn/end, pin labels) is route-specific. Merging would pollute the track model. -
Waypointis used as anEquatablechange trigger —.onChange(of: currentRouteState.waypoints)inMapViewMainMapViewfiresHandleWaypointsChangedto rebuild routes. This works because waypoints are rebuilt as new value types on everypointschange. Computed properties would break this change-detection mechanism. -
14+ consumers read waypoints for display — carousel, table, map pins, navigation logic all expect the
Waypointtype.
navigableLine is derived from segments (via BuildNavigableLine) and was not being rebuilt when CurrentRouteState.restore() loaded persisted data. This caused ShowOnMap.flyAndZoomToCurrentRoute to silently fail after app restart because navigableCoordinates returned [].
Fix: Call rebuildNavigableLine() at the end of restore() to reconstruct the LineString from the already-persisted segments.
The two-type split is the right design. DrawingPoint is the persisted, shared, mutable data model. Waypoint is a route-specific, derived, immutable view-model. The didSet derivation pattern is non-obvious but correct — the key is ensuring all derived state (like navigableLine) is also rebuilt on restore.