M1.2 Insertion-index algorithm + unit tests #11
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
public/wanderer#11
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Given the polyline anchors and a clicked point, compute the segment that minimizes added detour and the index to splice at. Pure function + unit tests, independent of the map UI.
Code complete (validation gated on CI toolchain).
Wrote
web/src/lib/util/route_insertion.ts→chooseInsertionIndex(anchors, point).Design: score prepend / every interior gap / append by route-length increase (ends = raw leg to the endpoint; mid = detour
d(prev,p)+d(p,next)−d(prev,next)); minimum wins, ties → append. This makes the endpoint guard automatic — no distance threshold — and matches the agreed min-detour behavior. ReuseshaversineDistancefromgpx/utils.ts.Tests:
route_insertion.test.ts— 8 vitest cases (empty, single anchor, append-beyond-end, prepend-before-start, insert gap-1, insert gap-2 = the reported bug, off-line mid-insert, symmetric tie→append). Logic validated 8/8 via a standalone node runner. Formalvitestrun is gated on the dev toolchain — tracked under M0.2 (#7). Leaving open until it runs green in CI.Landed in the fork. Commit
cfeb45dconfeat/smart-insertion(web/src/lib/util/route_insertion.ts+route_insertion.test.ts). PR compare: https://git.mirus-tech.com/oss/wanderer/compare/main...feat/smart-insertion . Runningvitestagainst the full clone now to replace the standalone-validation caveat.✅ vitest green —
2 test files, 11 tests passed(my 8route_insertioncases + the 3 existingtrailtests) run from the full fork clone, resolving the real$libhaversine import. Standalone-validation caveat lifted. Algorithm + unit tests complete; closing. Wiring tracked in #12.