Fix 2d Perlin noise implementation to handle boundary cases #103
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.
Summary
At the boundaries of the pre-computed 2d gradient array the noise values produced would be far outside of 0->1, producing interesting bugs like this one:

The bug was caused by large
dxanddyvalues being calculated and used in the dot products with the 4 gradient vectors.In the case where
xwas 63,x0would be 0 anddxwould bex - x0(63).This is now resolved by making sure that
dxanddyrespect the boundary ofPERLIN_NOISE_2D, thatx1andy1(the bottom and right edges of the cell in the Perlin unit space) will properly wrap, and that the dot products are calculated usingdy - 1anddx - 1rather thany - y1etc to prevent these out of bounds issues.