Skip to content

feat(core): a route model and writer for OpenSCENARIO (p8-s3) (#247) - #541

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

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

Conversation

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

First of four PRs for #247 (lane-anchored routes): the model and the writer. The reader, the resolver + edit factories, and the editor Route tool follow.

What lands

<RoutingAction> gains its AssignRouteAction arm, carrying an inline <Route> of <Waypoint>s. Waypoints hold the same osc::Position variant a teleport does, so a route RoadMaker authors names lanes rather than points in space — which is what makes it follow the roads beneath it (GW-6 step 7) instead of staying behind where it was drawn.

Spec basis: OpenSCENARIO XML 1.4.0 §7.7 — Route (@name and @closed both use="required", ParameterDeclarations? then Waypoint{2,}), Waypoint (@routeStrategy required, Position 1..1), AssignRouteAction (Route XOR CatalogReference), RoutingAction (five-way choice).

★ The struct is RouteWaypoint, never Waypoint

roadmaker::Waypoint is the road-authoring node type (road/authoring.hpp). An unqualified Waypoint declared inside roadmaker::osc would shadow it in exactly the translation unit that needs both — the resolver in PR 3, which walks a route across a network whose roads are shaped by authoring waypoints.

That is the third name this header's surrounding tree has already taken, after signals (a Qt macro, which stops the struct declaration parsing in any editor TU) and RoadNetwork (the kernel's most central type). The rule those two established: the element keeps its schema name, the struct gets an unambiguous one.

Design calls

The inline route is an optional arm. An <AssignRouteAction> whose content is a <CatalogReference> keeps it on the preserved tier and no empty <Route> is invented — that would replace a legal document with an invalid one.

Waypoint positions go through the same check_road_relative_position an init teleport does. A route cannot smuggle past it a reference the placement layer would have refused. Shared, not re-implemented.

Route names are unique document-wide, not per entity: they are siblings once flattened, and a simulator resolves a route by name.

A <WorldPosition> waypoint warns and does not block, citing asam.net:xosc:1.0.0:routing.ambiguous_route_waypoints. It is legal; it merely fails to say which lane the route takes where several meet, so the same file routes differently in two simulators. RoadMaker never authors one — this fires on foreign input.

routing.route_waypoints_locations is deliberately NOT declared yet. "Route waypoints should not be located in junctions" is not reachable from validate_scenario at all: whether a road belongs to a junction is a fact about the .xodr, and a Scenario holds only the roadId string (ADR-0014 §5). It arrives with the network-aware checker in PR 3. Declaring it early would make it exactly the decoration rules.hpp's own header rules out — and XoscRules.EveryRuleConstantIsCitedBySomeFinding would have failed on it.

Verification

  • cmake --build --preset ci-macos clean; 3107/3107 ctest --preset ci-macos pass.
  • 12 new writer tests. Every assertion slices its parent element rather than searching the document, per this file's standing rule — RoutingAction > AssignRouteAction > Route > Waypoint > Position > LanePosition, each sliced inside the last.
  • Six sabotages, six caught: reordering <ParameterDeclarations> after the waypoints, always emitting the wrapper, always emitting a <Route>, dropping the two-waypoint minimum, skipping the shared position check, and nesting the routing arm inside the teleport's <PrivateAction>.
  • One sabotage initially caught nothing, and the test was wrong rather than the code: the own-element test built three separate PrivateActions, which produce three elements no matter what the writer does with the arms. Rebuilt around ONE action carrying all three (a shape unreachable from parsing, so this writer test is its only guard), it fails as it should.
  • One assertion was also wrong on first run — find("<Waypoint ", 1) re-finds the first waypoint, so the ordering check would have passed on a document holding only one. Fixed to search from the first waypoint's close tag.
  • git ls-files '*.cpp' '*.hpp' | xargs clang-format --dry-run --Werror clean.

Refs #247.

The first of four PRs for lane-anchored routes: the model and the writer.
The reader, the resolver and the editor tool follow.

<RoutingAction> gains its AssignRouteAction arm, carrying an inline <Route>
of <Waypoint>s. Waypoints hold the same osc::Position variant a teleport
does, so a route RoadMaker authors names lanes rather than points in space —
which is what makes it follow the roads beneath it (GW-6 step 7) instead of
staying behind where it was drawn.

★ The struct is RouteWaypoint, never Waypoint. roadmaker::Waypoint is the
road-authoring node type, and an unqualified Waypoint declared inside
roadmaker::osc would shadow it in exactly the translation unit that needs
both — the resolver, which walks a route across a network whose roads are
shaped by authoring waypoints. Third name this header's surrounding tree has
already taken, after `signals` (a Qt macro) and RoadNetwork; the rule those
established is that the element keeps its schema name and the struct gets an
unambiguous one.

The inline route is an OPTIONAL arm. An <AssignRouteAction> whose content is
a <CatalogReference> keeps it on the preserved tier, and no empty <Route> is
invented — that would replace a legal document with an invalid one.

Refusals mirror the schema: fewer than two waypoints, a nameless route, a
duplicate route name (uniqueness is document-wide, since routes are siblings
once flattened and a simulator resolves one by name), a waypoint with no
routeStrategy. Waypoint positions go through the SAME
check_road_relative_position an init teleport does, so a route cannot smuggle
past it a reference the placement layer would have refused.

A <WorldPosition> waypoint warns, citing routing.ambiguous_route_waypoints,
and does not block the write. It is legal; it merely fails to say which lane
the route takes where several meet.

routing.route_waypoints_locations is deliberately NOT declared yet. Whether a
road belongs to a junction is a fact about the .xodr, and a Scenario holds
only the roadId string — so it belongs with the network-aware checker in the
next PR. Declaring it early would make it the decoration rules.hpp's own
header rules out, which EveryRuleConstantIsCitedBySomeFinding enforces.

Twelve new writer tests, all six sabotages caught. One of them was
incoherent first: the routing arm's own-element test built three separate
PrivateActions, which produce three elements no matter what the writer does
with the arms. Rebuilt around ONE action carrying all three, it fails as it
should.

Refs #247.
@JArmandoAnaya
JArmandoAnaya force-pushed the feat/p8-s3-route-model branch from 2afc9c7 to 75b676d Compare August 1, 2026 01:07
@JArmandoAnaya
JArmandoAnaya merged commit f1189b8 into main Aug 1, 2026
16 checks passed
@JArmandoAnaya
JArmandoAnaya deleted the feat/p8-s3-route-model branch August 1, 2026 01:32
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