diff --git a/.trellis/tasks/09-23-complex-junction-interior-line/check.jsonl b/.trellis/tasks/09-23-complex-junction-interior-line/check.jsonl new file mode 100644 index 0000000..658cb74 --- /dev/null +++ b/.trellis/tasks/09-23-complex-junction-interior-line/check.jsonl @@ -0,0 +1,2 @@ +{"file":".trellis/tasks/09-23-complex-junction-interior-line/prd.md","reason":"Acceptance criteria cover the white-line screenshot regression and ordinary-marking compatibility."} +{"file":".trellis/tasks/09-23-complex-junction-interior-line/design.md","reason":"Provides the data-flow and compatibility checks for review."} diff --git a/.trellis/tasks/09-23-complex-junction-interior-line/design.md b/.trellis/tasks/09-23-complex-junction-interior-line/design.md new file mode 100644 index 0000000..0a3cbed --- /dev/null +++ b/.trellis/tasks/09-23-complex-junction-interior-line/design.md @@ -0,0 +1,41 @@ +# Design + +## Boundary + +The compiler must publish complex-junction white road markings only on the +approach side of the first generated crosswalk or stop line. The central +junction pavement and zebra crossing remain free of those markings. + +## Data Flow + +1. Complex junction templates produce approach lane preview lines and control + polygons (`crosswalks` and `stopLines`). +2. `compileComplexLaneSeparators` derives white lane-separator geometry from + preview lanes. This is the layer shown by the screenshot. +3. `compileCenterLines` derives center-line marking geometry from the trimmed + bidirectional approach line. +4. Both paths use `trimLineBeforeFirstControl`; complex lines must first be + oriented from the exterior toward the cluster center, then restored to their + published direction. + +## Implementation Shape + +Reuse the existing center-aware `trimLaneOutsideControls` behavior (or extract +its orientation step into a small shared helper) for complex preview and center +lines. For complex lane separators, also trim against the stable published +approach/core boundary so a control polygon that ends short of the core cannot +leave an interior tail. Ordinary roads keep the existing behavior. All cutoffs +remain driven by published geometry, with no cluster-specific coordinates. + +## Compatibility + +- Preserve feature identities, styles, source road IDs, and signal layers. +- Do not change connector or lane-solving coordinates; only published marking + geometry is clipped. +- Ordinary-junction trimming remains unchanged. + +## Risks + +If the first control polygon is malformed or absent, the existing full-line +fallback remains in place. Tests must cover both line orientations so a future +OSM way direction cannot reintroduce the bug. diff --git a/.trellis/tasks/09-23-complex-junction-interior-line/implement.jsonl b/.trellis/tasks/09-23-complex-junction-interior-line/implement.jsonl new file mode 100644 index 0000000..8b3ee80 --- /dev/null +++ b/.trellis/tasks/09-23-complex-junction-interior-line/implement.jsonl @@ -0,0 +1,2 @@ +{"file":".trellis/tasks/09-23-complex-junction-interior-line/design.md","reason":"Defines the center-aware clipping contract for complex white markings."} +{"file":".trellis/tasks/09-23-complex-junction-interior-line/implement.md","reason":"Lists the ordered implementation and validation work."} diff --git a/.trellis/tasks/09-23-complex-junction-interior-line/implement.md b/.trellis/tasks/09-23-complex-junction-interior-line/implement.md new file mode 100644 index 0000000..50240a1 --- /dev/null +++ b/.trellis/tasks/09-23-complex-junction-interior-line/implement.md @@ -0,0 +1,27 @@ +# Implementation Plan + +1. Add a focused geometry regression for the `8005332807` complex cluster that + identifies white marking features and asserts their published geometry does + not overlap generated crosswalk/stop-line controls or the interior side of + the approach boundary. +2. Update complex center-line and preview lane-separator trimming to orient by + cluster center before applying the first-control cutoff. +3. Add an opposite-direction synthetic/control assertion proving ordinary + junction markings retain their current behavior. +4. Run focused junction marking tests, then the full test suite and diff checks. + +## Validation + +- `node test/junction-corridor-markings.js` +- `node test/junction-marking-containment.js` +- `node test/junction-layer-seams.js` +- `npm test` +- `git diff --check` + +## Risky Files + +- `src/compile/native-road.js` +- `test/junction-corridor-markings.js` or the closest existing geometry test + +Do not update fixture baselines unless the final behavior change is reviewed +and explicitly intended. diff --git a/.trellis/tasks/09-23-complex-junction-interior-line/prd.md b/.trellis/tasks/09-23-complex-junction-interior-line/prd.md new file mode 100644 index 0000000..13d798e --- /dev/null +++ b/.trellis/tasks/09-23-complex-junction-interior-line/prd.md @@ -0,0 +1,64 @@ +# Fix Complex Junction Interior Line for cluster-8005332807 + +## Goal + +Prevent a white lane marking from crossing the zebra crossing and extending into +the interior of a complex junction. The visible result must match the user's +screenshot for `cluster-8005332807` and must not regress ordinary-junction +markings. + +## Confirmed Facts + +- The reported line is white in the workbench screenshot, so it is a road + marking layer rather than the dark/magenta signal or connector overlays. +- The affected geometry is in the complex-junction cluster containing node + `8005332807`; the screenshot shows the marking continuing inward past a + zebra crossing toward the central pavement region. +- Complex lane separators are generated separately from ordinary road + separators in `src/compile/native-road.js` and are expected to stop at + complex-junction controls and boundaries. +- `trimLineBeforeFirstControl` assumes its input starts at the exterior and + proceeds toward the junction. Complex preview/center lines can be supplied + in the opposite direction, so the current code can preserve the interior + segment instead of the approach segment. +- The screenshot's white line is specifically published as + `native-road-complex-lane-separator/v1` by `compileComplexLaneSeparators`, + not as a signal or center-line overlay. That path clips against controls but + does not independently enforce the complex core boundary. +- Existing worktree changes are unrelated user work and must be preserved. + +## Requirements + +- R1. In a complex-junction view, the affected white lane marking must stop + before it crosses the zebra crossing or enters the configured junction + interior region. +- R2. The fix must be derived from the actual complex-junction geometry, + crossing controls, or their stable published boundary, not from a + cluster-specific coordinate or screenshot-only special case. +- R3. Lane markings outside the affected complex-junction segment, including + ordinary-junction markings, must remain unchanged. +- R4. Add a regression covering `cluster-8005332807` and a control case proving + ordinary-junction marking generation remains unchanged. + +## Technical Decision + +Orient complex marking lines by distance from the cluster center before +applying the existing first-control trim, then enforce the published complex +approach/core boundary before restoring their original direction. This keeps +the fix geometry-driven and leaves ordinary road trimming untouched. + +## Acceptance Criteria + +- [ ] The reported white marking no longer crosses the zebra crossing or + enters the complex-junction interior in the workbench image. +- [ ] No affected white marking segment published for the complex cluster lies + inside its configured crossing/interior boundary; geometry remains finite + and stable. +- [ ] Existing signal, marking, and complex-junction behavior remains intact, + including the affected real OSM fixture. + +## Scope Boundary + +- In scope: complex-junction white lane-marking geometry and its regression. +- Out of scope: traffic-signal phase logic, OSM source editing, free signal + creation/deletion, vehicle simulation, and unrelated road or island geometry. diff --git a/.trellis/tasks/09-23-complex-junction-interior-line/task.json b/.trellis/tasks/09-23-complex-junction-interior-line/task.json new file mode 100644 index 0000000..c2fbbdc --- /dev/null +++ b/.trellis/tasks/09-23-complex-junction-interior-line/task.json @@ -0,0 +1,26 @@ +{ + "id": "complex-junction-interior-line", + "name": "complex-junction-interior-line", + "title": "Fix complex junction interior line for cluster-8005332807", + "description": "", + "status": "in_progress", + "dev_type": null, + "scope": null, + "package": null, + "priority": "P2", + "creator": "dingkang", + "assignee": "dingkang", + "createdAt": "2026-09-23", + "completedAt": null, + "branch": null, + "base_branch": "main", + "worktree_path": null, + "commit": null, + "pr_url": null, + "subtasks": [], + "children": [], + "parent": null, + "relatedFiles": [], + "notes": "", + "meta": {} +} \ No newline at end of file diff --git a/src/compile/native-road.js b/src/compile/native-road.js index 83721ee..67ccf8d 100644 --- a/src/compile/native-road.js +++ b/src/compile/native-road.js @@ -863,7 +863,16 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) { ); const markings = compileLaneMarkings(model, overrides, lanes, diagnostics, junctionPlans, allControls, options); markings.separators.push( - ...compileComplexLaneSeparators(lanes.features, [...allControls.crosswalks, ...allControls.stopLines]), + ...compileComplexLaneSeparators( + lanes.features, + [...allControls.crosswalks, ...allControls.stopLines], + complexClusterCenters, + new Map( + activeClusters + .filter((cluster) => cluster.template === 'complex-junction-v1') + .map((cluster) => [cluster.id, complexJunctionMetrics(cluster).coreRadius]), + ), + ), ); markings.directionArrows.push(...compileComplexPreviewArrows(lanes.features, generatedComplexStopLines)); // Complex crosswalks are generated from native approach tangents; do not @@ -1128,7 +1137,7 @@ function compileComplexPreviewArrows(features, stopLines) { return result; } -function compileComplexLaneSeparators(features, controls = []) { +function compileComplexLaneSeparators(features, controls = [], clusterCenters = new Map(), clusterCoreRadii = new Map()) { const groups = new Map(); for (const feature of features) { if (!feature.properties?.cluster_preview || !feature.properties.road_id) continue; @@ -1153,7 +1162,14 @@ function compileComplexLaneSeparators(features, controls = []) { // near the core and make the separator disappear entirely. const roadControls = controls.filter((control) => String(control.properties?.road_id || '') === String(roadId)); const visibleLine = trimLineBeforeFirstControl(line, roadControls, 0.12); - const ring = visibleLine ? roadRing(visibleLine, 0.12) : null; + const clusterId = lanes[0].properties.cluster_id; + const center = clusterCenters.get(clusterId); + const coreRadius = clusterCoreRadii.get(clusterId); + const coreClippedLine = + visibleLine && center && Number.isFinite(coreRadius) + ? trimLineOutsideRadius(visibleLine, center, coreRadius) + : visibleLine; + const ring = coreClippedLine ? roadRing(coreClippedLine, 0.12) : null; if (!ring) continue; result.push({ type: 'Feature', @@ -1175,6 +1191,33 @@ function compileComplexLaneSeparators(features, controls = []) { return result; } +// Complex preview lanes are radial approach geometry. Keep only the exterior +// portion of a separator; the core pavement owns everything at or inside the +// cluster's calibrated core radius. +function trimLineOutsideRadius(line, center, radius) { + if (!Array.isArray(line) || line.length < 2 || !center || !Number.isFinite(radius) || radius <= 0) return line; + const outwardFirst = distanceMeters(line[0], center) >= distanceMeters(line.at(-1), center); + const oriented = outwardFirst ? line : [...line].reverse(); + const outside = (point) => distanceMeters(point, center) >= radius; + if (!outside(oriented[0])) return null; + for (let index = 1; index < oriented.length; index += 1) { + if (outside(oriented[index])) continue; + const start = oriented[index - 1]; + const end = oriented[index]; + let low = 0; + let high = 1; + for (let iteration = 0; iteration < 24; iteration += 1) { + const middle = (low + high) / 2; + const point = interpolate(start, end, middle); + if (outside(point)) low = middle; + else high = middle; + } + const clipped = [...oriented.slice(0, index), interpolate(start, end, low)]; + return outwardFirst ? clipped : clipped.reverse(); + } + return line; +} + function trimLineBeforeFirstControl(line, controls, width) { // Build once per line; preserve the exact polygon overlap predicate. const indexed = controls diff --git a/test/junction-corridor-markings.js b/test/junction-corridor-markings.js index de69a31..d0b4956 100644 --- a/test/junction-corridor-markings.js +++ b/test/junction-corridor-markings.js @@ -38,6 +38,20 @@ for (const ordered of [clusters, [...clusters].reverse()]) { const complexSeparators = geometry.laneSeparators.features.filter( (f) => f.properties.road_id === roadId && f.properties.provenance === 'native-road-complex-lane-separator/v1', ); + if (roadId === 'road:way/858770823:segment/2:forward') { + const core = geometry.roadSurface.features.find( + (feature) => feature.properties?.kind === 'complex-core' && feature.properties?.cluster_id === 'west', + ); + if (core) { + const clusterCenter = core.properties.center; + const coreRadius = Number(core.properties.radius_m); + for (const separator of complexSeparators) + assert.ok( + separator.geometry.coordinates[0].every((point) => meters(point, clusterCenter) >= coreRadius - 0.05), + 'complex separator must stop outside the calibrated west-cluster core', + ); + } + } for (const separator of complexSeparators) { assert.ok( separator.geometry.coordinates[0].every((p) => meters(p, midpoint) > 180),