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

3D Simplex Noise doesn't account for potentially negative values. #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For this part of the code:

  // Wrap the integer indices at 256, to avoid indexing perm[] out of bounds
            int ii = i % 256;
            int jj = j % 256;
            int kk = k % 256;

ii, jj, and kk all may be negative. Since they are used as array indices, they 
need to be positive or zero.

This code fixes the issue, but may not be optimal (insert directly under)

            if (ii < 0) ii *= -1;
            if (jj < 0) jj *= -1;
            if (kk < 0) kk *= -1;

Original issue reported on code.google.com by NetherPh...@gmail.com on 3 Nov 2012 at 7:08

GoogleCodeExporter commented 9 years ago
If there is any way of fixing this and still keeping a smooth generated number 
from 0 to -1 for example, that would be nice.

Original comment by nicolas....@gmail.com on 7 Jul 2013 at 12:34

GoogleCodeExporter commented 9 years ago
Fixed.
Generated noise is smooth over negative - non-negative boundary.

Original comment by heikki....@gmail.com on 22 Aug 2013 at 3:23

GoogleCodeExporter commented 9 years ago
I think the same fix is needed for 2D noise generation too.  Perhaps the test 
cases can be modified to span a range of negative & positive numbers.

Original comment by bphi...@gmail.com on 12 Jan 2014 at 9:55