Extract shared RoutePolylineReconciler for both map flavors (#1906)#1918
Merged
Conversation
The route-polyline reconcile/width algorithm was duplicated verbatim across GoogleMapRenderer and MapLibreRenderer: the identity/equality early-exit, the reconcileEqualItems diff, per-index width comparison against the stored widths, the native width patch, the three-field state update, and the camera-settle width resync. A single bug fix had to be applied by hand to both copies. Move that flavor-neutral bookkeeping into a new RoutePolylineReconciler<NativeLine> in the render module, parameterized by the four genuinely platform-specific operations over the opaque native line type: width resolution, line creation, batch removal, and width patch. Each renderer now supplies those and calls reconcile()/resyncWidths()/clear(), dropping ~60 lines of duplicated logic and its three private state fields. Add RoutePolylineReconcilerTest covering retain-equal, remove-gone, create-new, patch-changed-width, the same-list O(1) no-op, resync, and clear via a fake native line. Behavior is unchanged on both flavors; both compile clean under -PwarningsAsErrors and the render test suite passes on obaGoogle and obaMaplibre. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #1906.
Problem
The route-polyline reconcile/width algorithm (~60 lines) was duplicated verbatim across
GoogleMapRendererandMapLibreRenderer: the identity/equality early-exit, thereconcileEqualItemsdiff, per-index width comparison against the stored widths, the native width patch, the three-field state update, and the camera-settle width resync. As the issue notes, a single bug fix had recently had to be applied by hand to both copies — the maintenance hazard this refactor removes.Change
Introduce
RoutePolylineReconciler<NativeLine>in the existingmap/rendermodule. It owns all the flavor-neutral bookkeeping and is parameterized by the four genuinely platform-specific operations over the opaque native-line type:widthOf(polyline, zoom)— resolve a line's pixel width (gms scales by density; maplibre doesn't)createLine(polyline, width)— mint a native lineremoveLines(lines)— batch removal (gmsremove()per line; maplibreremoveAnnotations)setWidth(line, width)— patch a live line's widthEach renderer now holds a
RoutePolylineReconciler<Polyline>supplying those, andrenderRoutePolylines/onCameraSettled/disposecollapse to single delegations (reconcile/resyncWidths/clear). Three private state fields and thereconcileEqualItemsimport drop out of each renderer.Behavior is unchanged — a pure extraction. The MapLibre dispose keeps its exact prior semantics (route lines cleared before the mass
removeAnnotations()).Tests
New
RoutePolylineReconcilerTest(11 cases) drives the shared logic through a fake native line: retain-equal, remove-gone, create-new, patch-changed-width, patch-skipped-when-unchanged, the same-list O(1) no-op,resyncWidths, andclear.Verification
-PwarningsAsErrors=true(the CI gate).obaGoogleandobaMaplibre.main(Cleanup: small-exhaust sweep from the 2026-07-16 debt review #1915); main's concurrent renderer edits were comment/constant drift outside the reconcile path, so the merge was clean.🤖 Generated with Claude Code