WardBenjamin / SimplexNoise

C# Simplex Noise (1D, 2D, 3D). Supports arbitrary sizes and scales.
BSD 3-Clause "New" or "Revised" License
160 stars 38 forks source link

Broken for negative inputs in 2D #3

Closed GoogleCodeExporter closed 6 years ago

GoogleCodeExporter commented 9 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 9 years ago
Correction: There is no problem in 3D, only 2D.

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

WardBenjamin commented 6 years ago

Related to #1. Weird. I'm not sure how that got past me.