Smart waypoint insertion + route-editor fixes #17

Open
jmz wants to merge 4 commits from feat/smart-insertion into main
Owner

Local PR tracking the smart-insertion feature + the route-editor fixes found while testing.

Commits

  • min-detour waypoint insertion index chooser (M1.2, #11) — chooseInsertionIndex + 8 vitest cases.
  • insert clicked waypoints at the least-detour position (M1.3, #12) — wires it into the map click; fixes insertIntoRoute index-0.
  • route-editor: clear track on anchor removal, correct undo, tidy totals (#16) — removeAnchor clearing, undo anchor-sync, insertAnchorSplit, deleteFromRoute totals.

Deployed and validated at wanderer.ziefle.org (svelte-check clean, unit tests green).

Note: when upstreaming, this will be split into atomic PRs (smart-insertion feature vs. the independent route-editor bug fixes). Kept together here because commit 3 also touches addAnchorSmart. Closes nothing yet — tracking #2, #11, #12, #16.

Local PR tracking the smart-insertion feature + the route-editor fixes found while testing. **Commits** - `min-detour waypoint insertion index chooser` (M1.2, #11) — `chooseInsertionIndex` + 8 vitest cases. - `insert clicked waypoints at the least-detour position` (M1.3, #12) — wires it into the map click; fixes `insertIntoRoute` index-0. - `route-editor: clear track on anchor removal, correct undo, tidy totals` (#16) — removeAnchor clearing, undo anchor-sync, `insertAnchorSplit`, deleteFromRoute totals. Deployed and validated at wanderer.ziefle.org (`svelte-check` clean, unit tests green). **Note:** when upstreaming, this will be split into atomic PRs (smart-insertion feature vs. the independent route-editor bug fixes). Kept together here because commit 3 also touches `addAnchorSmart`. Closes nothing yet — tracking #2, #11, #12, #16.
Adds chooseInsertionIndex(anchors, point): scores prepend / each interior
gap / append by route-length increase and returns the least-detour anchor
index, so a clicked point that belongs mid-route is inserted there instead
of always appended. Pure + unit-tested (8 vitest cases); reuses
haversineDistance. Wiring into the map click handler follows separately.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Wire chooseInsertionIndex into the route editor's map-click handler so a
clicked point is placed where it grows total route length the least: a
point that belongs mid-route is inserted between its neighbouring anchors
(re-routing both halves, mirroring the segment-drag path) instead of always
being appended. Points that extend the route still append; k=0 prepends.

Also fixes insertIntoRoute() to splice at index 0 — the `if (index)` guard
treated 0 as falsy and appended; prepend relies on splicing at 0. No
existing caller passes 0.

svelte-check clean (0 errors); route_insertion unit tests green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
fix(route-editor): clear track on anchor removal, correct undo, tidy totals
Some checks failed
Web CI / test (pull_request) Failing after 9s
5e20f77394
- removeAnchor: clear the track when <2 anchors remain (was leaving a
  dangling segment / stale route line); drop the gpx_data gate that skipped
  the map refresh while drawing; rebuild via setRoute when removing the end
  anchor so the last segment can't dangle.
- Tag anchorsBefore/anchorsAfter on add actions so undo/redo restores the
  anchor list instead of rebuilding from the emptied route (fixes: add two
  points then undo removes both).
- addAnchorSmart: mid-insert uses a single insertAnchorSplit change so undo
  reverts the whole insertion in one step; prepend routes new->start.
- deleteFromRoute: compute totals from the reduced snapshot, not the
  pre-delete route.

svelte-check clean; unit tests green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
fix(route-editor): undo/redo marker sync + undoable first anchor
Some checks failed
Web CI / test (pull_request) Failing after 2s
597185c4a7
- applyAnchorSnapshot(): on undo/redo, remove markers for anchors no longer
  present and (re-)add markers for restored ones. Fixes: the added point's
  marker stayed on the map after undo even though it left the anchor list.
- Placing the first anchor now records an anchor-only undo entry
  (pushAnchorOnlyChange) so it is undoable (undo was greyed / a no-op).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Some checks failed
Web CI / test (pull_request) Failing after 2s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/smart-insertion:feat/smart-insertion
git switch feat/smart-insertion

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff feat/smart-insertion
git switch feat/smart-insertion
git rebase main
git switch main
git merge --ff-only feat/smart-insertion
git switch feat/smart-insertion
git rebase main
git switch main
git merge --no-ff feat/smart-insertion
git switch main
git merge --squash feat/smart-insertion
git switch main
git merge --ff-only feat/smart-insertion
git switch main
git merge feat/smart-insertion
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer!17
No description provided.