Repository navigation
Fix mixed coordinate units in Dijkstra grid indexing - #1461
huxiaoyi-ovo wants to merge 3 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. |
|
Thanks @Afloat16, good catch. The start cell really can end up with key |
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 fix corrects the index definition. It can also change an incorrect result: a valid start cell previously assigned key-1could collide with the parent-chain sentinel and be omitted from the returned path. The search algorithm and intended path ordering remain unchanged.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.A second end-to-end regression follows Afloat16's reproduction and asserts the complete reversed path
[(1.0, 3.0), (1.0, 2.0)]instead of the old goal-only result.This also addresses the maintainer's earlier request for an offset-origin, non-unit-resolution regression test on #1360 (closed without merge).
Additional information
The original two-commit head was validated against upstream
master(cdd0cc888802b584c2d654ca85e3c5460973487d) using fork-only draft PR #2:The end-to-end test was added in commit
9e96bf4; the latest CI status should be checked separately.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.