Repository navigation
Fix mixed coordinate units in Dijkstra grid indexing - #1461
huxiaoyi-ovo wants to merge 2 commits into
Conversation
|
Automated Codex-assisted supporting check; no human review or approval is claimed. The index normalization also fixes a path-reconstruction failure, so the description's claim that planned paths are unchanged has an exception: from PathPlanning.Dijkstra import dijkstra
dijkstra.show_animation = False
planner = dijkstra.DijkstraPlanner(
[1.0, 5.0, 1.0, 5.0], [1.0, 1.0, 5.0, 5.0], 1.0, 0.0
)
rx, ry = planner.planning(1.0, 2.0, 1.0, 3.0)
print(list(zip(rx, ry)))With Python 3.13.5 and the repository-pinned NumPy 2.5.3 / Matplotlib 3.11.2, both endpoints pass
The old formula assigns start grid cell This would be a useful end-to-end regression alongside the key-value tests. Only this matched case was run against the complete, unmodified module at each immutable revision, not the full suite or CI. Matplotlib emitted Fontconfig cache diagnostics; both runs completed normally. |
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) fromNode.xandNode.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.5and2.0m/cell), including:(0, 0)and index0;y * width + x;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:PathPlanning/Dijkstra/dijkstra.pyandtests/test_dijkstra.py, with no new dependencies.CheckList
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.