Skip to content

feat(core): resolve routes against the network, and edit them undoably (p8-s3) (#247) - #544

Merged
JArmandoAnaya merged 1 commit into
mainfrom
feat/p8-s3-route-resolver
Aug 1, 2026
Merged

JArmandoAnaya merged 1 commit into
mainfrom
feat/p8-s3-route-resolver

Conversation

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

The resolver half of #247: the one place the .xosc and the .xodr are read together. #541 gave routes a model and a writer, #543 a reader; this PR makes them mean something against a live network — and editable, one gesture at a time, on the same undo stack as everything else.

What lands

  • osc::resolve_route(network, route) (core/osc/route.{hpp,cpp}) turns a route's waypoints into the ordered lane legs a car would actually drive. Consecutive waypoints are joined by a breadth-first search over lane links (§9.3), road links (§9.2) and JunctionConnection::lane_links (§12) — so a solved path runs along a junction's connecting roads, the roads its authored maneuvers shape, rather than across it. The search is directed by each lane's own direction of travel: a route that could only be driven against the traffic is reported as unreachable, not solved.
  • osc::validate_routes(network, scenario) re-checks every assigned route and is the cross-document half of validate_scenario, which structurally cannot see a network (a Scenario holds @id strings, never arena handles — ADR-0014 §5). It cites routing.route_waypoints_locations for a waypoint sitting on a junction's connecting road — the rule #245 deliberately left undeclared because nothing could check it from the .xosc alone.
  • ★ The resolver never mutates and never re-routes. A dead waypoint, an unjoinable gap — each is a Diagnostic naming the entity, the route and the waypoint index, and the legs that did resolve are still returned so a caller can draw what it knows and mark the gap. An incomplete resolution always says why; a silent complete = false is the failure mode the module exists to prevent.
  • A leg is a LANE, not a road, so it pins the cross-section too — and s_end < s_start when the lane travels against +s, which a left-hand lane always does. Pinned by its own test, because a caller assuming an ascending interval draws a left-hand route backwards.
  • Five commands — assign_route, clear_route, set_route_waypoint, insert_route_waypoint, remove_route_waypoint — with the usual contract: refuse via a non-null command, byte-identical write_xosc across undo/redo, no clamping. Removing a waypoint that would leave fewer than two is refused: that deletion would produce a document write_xosc refuses, i.e. a scenario made unsavable by an edit that appeared to succeed.
  • Python bindings for the route model, resolve_route, validate_routes, assigned_routes and the five factories, plus python/examples/scenario_routes.py — which replays GW-6 steps 7 and 8 headlessly: move a road the route runs along and it still resolves; delete a lane it traverses and the route is reported as invalidated. python/ links roadmaker::core alone, so this file is the evidence those steps can be produced without the editor.

Notes for review

  • onward_lanes falls back to same-@id lane matching across a road boundary whose <lane><link> records are absent — RoadMaker's own authoring path never emits them across a plain weld (only across section splits and inside junctions), so requiring the record would report every road-to-road route as unreachable while the roads are visibly joined. When the record is present it wins, because a foreign file may renumber across the joint. The authoring-side gap is called out in a comment as follow-up material.
  • The BFS is bounded (kMaxRouteSearchLanes = 4096): a malformed junction can make the lane graph cyclic, and a resolver intended to re-run on every topology change must not become the thing that hangs the editor.
  • routing.route_waypoints_locations is declared in rules.hpp only now, together with its citer, because XoscRules.EveryRuleConstantIsCitedBySomeFinding fails on a constant nothing cites.

Editor integration (Route tool, rendering, re-validation on topology_changed) is the sprint's next PR; #247 stays open.

Evidence

  • ctest --preset ci-macos: 3164/3164 passed locally, including 15 new XoscRoute tests and 12 new XoscEdit route-command tests.
  • pytest python/tests: green locally, including test_scenario_routes.py.
  • python python/examples/scenario_routes.py runs clean against the freshly built module.
  • CI's exact clang-format command (with the untracked files added in) reports clean.

@JArmandoAnaya
JArmandoAnaya merged commit 1a47aca into main Aug 1, 2026
16 checks passed
@JArmandoAnaya
JArmandoAnaya deleted the feat/p8-s3-route-resolver branch August 1, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant