Fixed hex-space draw function to avoid overlaps#2609
Conversation
|
Thanks for this! I quickly scanned the code, and it made sense. I want to take a closer look, hopefully soon, to see if stuff can be simplified a bit. In the meantime, could you add a before and after of, say, a 20x20 grid next to what you already provided (which looks great, btw)? |
|
Thank you for your response! I’ve added grid images with a 10x10 layout (as the 20x20 grid didn’t look as clean in the screenshot) while keeping the same line-dot pattern for better clarity. |
quaquel
left a comment
There was a problem hiding this comment.
Again, thanks a lot for this PR. It's great to see how you solved the problem!
I have left a variety of suggestions for improving the code of this PR. If you have any questions, don't hesitate to ask.
|
There is still one issue unresolved regarding the alignment of hexes. Make the change shown below: loc[:, 0] = loc[:, 0] * x_spacing + ((loc[:, 1]-1) % 2) * (x_spacing / 2) |
|
@quaquel I don't know if you were able to see the review I started, in which I clearly attached images of your suggestion not working, so just to make sure I am attaching one image again, your suggestion offsets the placement of agents. I don't know if this is the intended behavior, if it is I shall change the code. |
|
I had missed that reply. Sorry. I'll try to take a closer look myself later this week. |
|
Finally had time to look at this again. My suggestion only changed the agent location, but the same correction evidently also needs to be made to the hex centers: so However, while figuring this out, I discovered 2 other bugs (which are also present in the current code).
This is most definitely not right and seems to be related to mixing up row and column indexing. I'll try to figure this out asap. |
|
I have added the reviewed changes, including the new empty |
Yes this issue predates your PR. See #2632 |
I suggest we first merge #2632 so I can fully visually check this PR. |
|
I have merged the bugfix and updated this PR by rebasing. |
|
@quaquel If there are no issues with the current approach, I would really appreciate it if this PR could be merged. |
|
I hope to have time for some final checks later this afternoon CET time. |
|
Ok, I checked stuff visually, and it looks all ok now. Merging this. Thanks again! |


Summary
This PR fixes the overlapping of hex-tiles.
Before:
After:
Grid
Before:
After:
Bug / Issue
fixes #2438
Implementation
The old code used
RegularPolygonto gather hexagon shapes and assemble them usingPatchCollection. In the new implementation, all six vertices are calculated using simple math and the origin coordinates, then combined at the end usingLineCollectionto avoid duplicate edges.No breaking changes have been made to the API.
Testing
Tested using building a custom model, found no errors.