Skip to content

Compute grid node index from grid indices only (#1318) - #1495

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

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

Conversation

@blessedefe4real

@blessedefe4real blessedefe4real commented Nov 5, 2026 •

Copy link
Copy Markdown

Reference issue

Fixes #1318

What does this implement/fix?

calc_index / calc_grid_index computed (node.y - self.min_y) * self.x_width + (node.x - self.min_x), but node.x / node.y are already grid indices while min_x / min_y are map coordinates in meters, so the units were mixed and indices could fall outside [0, x_width * y_width) when the map does not start at the origin.

This uses node.y * self.x_width + node.x in:

  • PathPlanning/Dijkstra/dijkstra.py
  • PathPlanning/AStar/a_star.py
  • PathPlanning/ThetaStar/theta_star.py
  • PathPlanning/BidirectionalAStar/bidirectional_a_star.py
  • PathPlanning/BidirectionalBreadthFirstSearch/bidirectional_breadth_first_search.py

Planned paths from all five planners' main() are identical before and after.

Additional information

As requested in the review of #1360, the tests use a non-zero map origin and a resolution of 0.5, and check that the first cell maps to index 0 and the last to x_width * y_width - 1 (Dijkstra and A*), and that every Dijkstra index is unique and in range. They fail on master and pass with this change.

#1461 fixes the same line in Dijkstra only; this PR covers the other four planners that copied it.

CheckList

  • Did you add an unittest for your new example or defect fix?
  • Did you add documents for your new example? (not applicable: defect fix)
  • All CIs are green? (You can check it after submitting) (full suite pytest tests -Werror passes locally; CI awaiting workflow approval)

calc_index/calc_grid_index subtracted min_x/min_y (meters) from
node.x/node.y, which are already grid indices. Because the offset is
constant the mapping stayed unique, but the units were mixed and the
resulting keys could fall outside [0, x_width * y_width).

Use node.y * x_width + node.x in Dijkstra, A*, Theta*, bidirectional
A* and bidirectional BFS. Planned paths are unchanged. Add a
regression test for the index range.
Check that the first cell maps to index 0 and the last cell to
x_width * y_width - 1 when the map origin is not (0, 0) and the
resolution is 0.5, for Dijkstra and A*. Both tests fail with the
previous formula.

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