-
Notifications
You must be signed in to change notification settings - Fork 928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed hex-space draw function to avoid overlaps #2609
base: main
Are you sure you want to change the base?
Fixed hex-space draw function to avoid overlaps #2609
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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. |
loc[:, 0][logical] += 0.5 | ||
loc[:, 1] *= offset | ||
# Calculate hexagon centers | ||
loc[:, 0] = loc[:, 0] * x_spacing + (loc[:, 1] % 2) * (x_spacing / 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think something is not right. Look at the top row in both figures. You'll see that they are differently aligned. This means that the neigborhood of a given cell as shown in the grid is not the same as in the underlying data. You can also check this by placing an agent in the very first cell.
This is due to this line of code: loc[:, 1] % 2
. Note how in the original code, I check for 0, rather than 1.
loc[:, 0] = loc[:, 0] * x_spacing + (loc[:, 1] % 2) * (x_spacing / 2) | |
loc[:, 0] = loc[:, 0] * x_spacing + ((loc[:, 1]-1) % 2) * (x_spacing / 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue is still not resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
for more information, see https://pre-commit.ci
…hhoker/mesa into fix-hex-tile-overlapping
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. |
Summary
This PR fixes the overlapping of hex-tiles.
Before:
After:
Grid
Before:
After:
Bug / Issue
fixes #2438
Implementation
The old code used
RegularPolygon
to 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 usingLineCollection
to avoid duplicate edges.No breaking changes have been made to the API.
Testing
Tested using building a custom model, found no errors.