bsimser / simplexnoise

Implementation of the Perlin simplex noise, an improved Perlin noise algorithm.
MIT License
0 stars 0 forks source link

Broken for negative inputs in 2D #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Attempt to generate any noise given negative inputs (in 2D and 3D)

What is the expected output? What do you see instead?
Noise is expected, an out of bounds exception is thrown instead.

What version of the product are you using? On what operating system?
1.01, Windows 7

Please provide any additional information below.
It's simply because of line 107 and 108, just replace:

int ii = i % 256;
int jj = j % 256;

with 

int ii = i & 0xff;
int jj = j & 0xff;

or

int ii = Mod(i, 256);
int jj = Mod(j, 256);

and it works as expected. This is because of this: 
http://stackoverflow.com/questions/11720656/modulo-operation-with-negative-numbe
rs

It's done correctly in 3 dimensions, however. (it uses the Mod function already 
in the code that addresses the issue in the above link)

Original issue reported on code.google.com by danip...@gmail.com on 26 Apr 2014 at 3:06

GoogleCodeExporter commented 8 years ago
Correction: There is no problem in 3D, only 2D.

Original comment by danip...@gmail.com on 26 Apr 2014 at 3:07