Skip to content

Fix mixed coordinate units in Dijkstra grid indexing - #1461

Open
huxiaoyi-ovo wants to merge 2 commits into
AtsushiSakai:masterfrom
huxiaoyi-ovo:fix/dijkstra-grid-index-units-1318
Open

huxiaoyi-ovo wants to merge 2 commits into
AtsushiSakai:masterfrom
huxiaoyi-ovo:fix/dijkstra-grid-index-units-1318

Conversation

@huxiaoyi-ovo

Copy link
Copy Markdown

Reference issue

Fixes #1318.

What does this implement/fix?

DijkstraPlanner.calc_index() previously subtracted the map's world-coordinate origin (min_x, min_y, in metres) from Node.x and Node.y, even though these node coordinates are already zero-based grid indices (in cells). This mixes units and produces an incorrect nonzero index for the grid-origin cell whenever the world origin is offset.

Use the direct row-major index node.y * self.x_width + node.x. The previous offset was constant for a map, so the fix corrects the index definition without changing Dijkstra's search ordering or planned paths.

A focused regression test checks two maps with different nonzero world origins and non-unit resolutions (0.5 and 2.0 m/cell), including:

  • mapping the world origin to grid cell (0, 0) and index 0;
  • mapping an interior cell to y * width + x;
  • mapping the final grid cell to width * height - 1.

This also addresses the maintainer's earlier request for an offset-origin, non-unit-resolution regression test on #1360 (closed without merge).

Additional information

Validated against current upstream master (cdd0cc888802b584c2d654ca85e3c5460973487d) using fork-only draft PR #2:

  • Linux Python 3.14 full CI — passed.
  • Windows Python 3.14 full CI — passed.
  • macOS Python 3.14 full CI — passed.
  • CodeQL code scanning — passed.
  • Diff: only PathPlanning/Dijkstra/dijkstra.py and tests/test_dijkstra.py, with no new dependencies.

CheckList

  • Did you add an unittest for your new example or defect fix?
  • Did you add documents for your new example? (Not applicable: corrects an internal grid-index formula; no public API or algorithm documentation changes.)
  • All CIs are green? (Fork CI: Linux, Windows, macOS, CodeQL; upstream checks will run separately.)

AI assistance was used to review the issue history and prepare the minimal fix and regression test; the final branch was checked against upstream, and the full fork CI passed.

This branch has not been deployed

No deployments
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.

the implement Dijkstra maybe have issue

1 participant