镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Build the state path in one place - #153

Open
FrogAi wants to merge 1 commit into
pfeiferj:mainfrom
FrogAi:build-state-path-once
Open

FrogAi wants to merge 1 commit into
pfeiferj:mainfrom
FrogAi:build-state-path-once

Conversation

@FrogAi

@FrogAi FrogAi commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

"GetStateCurvatures" and "ExtendedState.setPath" both turn the current way and the next ways into one list of positions in travel order, and each has its own copy of the same index loop to do it. This moves that into "GetStatePath", which reverses each way that's driven backward and appends each next way without its first node, since that's the junction already in the list. "GetStateCurvatures" now finds its merge and split junctions from the way lengths instead of tracking them inside the loop, and "setPath" just copies the positions out.

The output doesn't change, and it's 46 fewer lines.

Audit report

Why the output is identical

"Nodes.Slice()" returns a fresh copy, so reversing it and appending to it never touches a way's stored nodes. The old loop read each way forward or backward and skipped the first node of every next way, which is the same list "GetStatePath" builds. The junction before each next way is the last node of everything before it, so its index is the current way's length minus one, plus each earlier next way's length minus one. That's the index the old loop recorded when it moved on to the next way.

Testing

  • On the PC, I replayed all 214 real drive segments from a comma 3X through the real "GetCurrentWay", "NextWays", "GetStateCurvatures" and "GetTargetVelocities" on every GPS fix, then called the real "setPath" and hashed every curvature, target velocity and published path point at full precision. That covered 12,488 GPS fixes, 445,805 curvatures, 493,455 path points, 12,648 flattened merges or splits, 13,289 next ways driven backward and 1,972 empty next ways. The code before and after this change gave byte-identical output.
  • To check that the replay would catch a mistake here, I shifted the junction index by one in a copy, and the replay panicked.
  • "go build ./...", "go vet ./..." and "go test ./..." pass in "golang:1.26.2-bookworm".

Not covered

The only inputs where the two differ are a current way with no nodes and a one-node next way in the middle of the chain, where the old loop indexed past the end and panicked. Neither came up in the replay.

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