Repository navigation
Draw HexGrid agents at their hexagon in legacy draw_hex_grid - #4043
AshNicolus wants to merge 4 commits into
Conversation
draw_hex_grid applied hex spacing to agent.cell.position, which is already in pixels, so agents drifted away from their hexagons and many left the plot. Start from cell.coordinate instead and keep the existing even-r conversion, which matches the hexagons from _get_hexmesh. Fixes mesa#4042
|
Performance benchmarks:
|
|
Can you add a before after? Once I have seen that, I will go ahead and merge this. |
|
Thanks @AshNicolus for the before/after screenshots and the row-layout explanation. @quaquel, should this land with the coordinate conversion, or should #3959 land first so the author can use Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot. |
|
@EwoutH saw the note in #4130. i checked whether this is still needed on 3.5.x: on |
|
Thanks @AshNicolus for checking whether 3.5.x needs this fix. @EwoutH, should this still merge before #4130, or wait for the legacy API removal? I recommend waiting for removal: the author reports that 3.5.x already draws these agents correctly, so there is no backport benefit. Please confirm which path to take. Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot. |
|
I would I just merged #4130, so I think this can be closed. |
|
closing, since #4130 removed the legacy drawing API from main, and 3.5.x already draws hex agents on their hexagons. thanks for the reviews! |


Pre-PR Checklist
Summary
The legacy
draw_space/draw_hex_griddrewHexGridagents away from their hexagons, many of them off the plot. Agents are now drawn at the centre of their own hexagon.Bug / Issue
Fixes #4042.
collect_agent_datagivesagent.cell.position, which since #3268 is already in pixels.draw_hex_gridthen applied hex spacing to it a second time, the same double conversion #3952 fixes forSpaceRenderer.flowchart LR P["cell.position<br/>already the hexagon centre (even-r since #3959)"] -->|main: spacing applied again| X["agent off its hexagon"] P -->|this PR: used as it is| H["agent at its hexagon centre"] M["_get_hexmesh<br/>even rows shifted"] --> HOn a 6x6 grid:
Implementation
draw_hex_gridno longer converts the positions it gets fromcollect_agent_data. Since #3959,cell.positionuses the same even-r layout as_get_hexmesh, so it is already the centre of the drawn hexagon. The conversion is removed, as @quaquel suggested.Testing
test_draw_hex_grid_agents_at_hexagon_centre, which compares each drawn agent with the centre of its cell's hexagon from_get_hexmesh. It fails onmainand passes here.pytest tests/ -Werror -Wdefault::PendingDeprecationWarning(1127 passed). Pre-commit passes.Additional Notes
Only the legacy matplotlib path is touched.
SpaceRendereris handled by #3952.