Conversation
The edge iterator, and the dense walks of GridIterator and GridIntoIterator, step x along a row and move to the next row when x comes back to width. With a width of zero x never does, so y never advances and the walk never ends. A grid without columns has no vertices, so all three now yield nothing. Fixes evenfurther#842
| if self.y == self.grid.height { | ||
| // With no columns, `x` would never come back to `width` and the walk would | ||
| // never move on to the next row. | ||
| if self.y == self.grid.height || self.grid.width == 0 { |
Member
There was a problem hiding this comment.
Isn't it a bit strange to redo the self.grid.width == 0 at every iteration of the loop instead of once at the beginning?
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #842.
Iterating a
Gridwithout columns never returned:Grid::new(0, 5).edges()in any state, anditer()/into_iter()once such a grid is dense, for instance afterfill()or after shrinking a full grid withresize(0, h).All three walks step
xalong a row and move to the next row whenxcomes back towidth. With a width of zero that never happens, soynever advances and they == heightexit is never reached. They now stop straight away when there are no columns, since such a grid has no vertices and no edges.Test
a_grid_without_columns_iterates_to_nothingintests/grid.rscoversedges(),iter()andinto_iter(), both onGrid::new(0, 5)afterfill()and on a full 3x3 grid shrunk to 0x3, and checksvertices_len()along the way. It hangs on currentmainand passes with this change.I also checked the rest of
Gridagainst a plain set of vertices through a few thousand randomadd_vertex,remove_vertex,add_borders,resize,fillandclearoperations, in both diagonal modes, comparing vertices, edges and neighbours after each step. Everything else agreed, so this is limited to the zero-width case.