feat(06-01): point-to-edge GPS-fix snapping with memoized grid index (GREEN)

- snapToGraph: bbox+margin guard first (honest null = router-pending,
  D-03), then 3x3 coarse-grid neighborhood (0.002 deg cells, WeakMap
  memo per RoadGraph — LAW 1 lazy memoize, O(local) not O(n))
- projection in cos(lat)-scaled degree space (Pitfall 8); returned
  distance is haversineM; result carries the best segment's nameId
  (null for the unnamed sentinel) for plan 07's cron street-hop
- oneway-reverse edges stay snap-visible (direction is A*'s law);
  gridBuildCount() instrumentation kept internal to the workspace
This commit is contained in:
araharah-executor
2026-10-24 12:10:46 +08:00
parent 72703d26ec
commit 2e73068af5
2 changed files with 173 additions and 1 deletions
+1 -1
View File
@@ -133,7 +133,7 @@ test("S4 bbox margin — outside bbox + SNAP_BBOX_MARGIN_DEG -> null; just outsi
// bbox maxLat = 3.152; +0.008 above it is inside the margin AND near row-4 roads.
const justOutside = snapToGraph(g, { lat: 3.1528, lng: nodeLng(1) });
assert.ok(justOutside, "a fix just outside the bbox but near roads still snaps");
assert.ok(justOutside.node >= 10 && justOutside.node <= 14, "snaps to a row-4 node");
assert.ok(justOutside.node >= 20 && justOutside.node <= 24, "snaps to a row-4 node (ids 20..24)");
// 0.011 deg above the bbox top -> outside bbox + margin -> honest null.
assert.equal(
snapToGraph(g, { lat: 3.163, lng: nodeLng(1) }),