Update SimplexNoiseOctave.java

This commit is contained in:
Libin Yang 2019-03-22 18:36:07 +08:00 committed by GitHub
parent 1093a496b9
commit e5b07ebc3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,10 +9,10 @@ public class SimplexNoiseOctave {
private static final Gradient[] GRADIENTS = { private static final Gradient[] GRADIENTS = {
new Gradient( 1, 1, 0), new Gradient(-1, 1, 0), new Gradient( 1, -1, 0), new Gradient(1, 1, 0), new Gradient(-1, 1, 0), new Gradient(1, -1, 0),
new Gradient(-1, -1, 0), new Gradient( 1, 0, 1), new Gradient(-1, 0, 1), new Gradient(-1, -1, 0), new Gradient(1, 0, 1), new Gradient(-1, 0, 1),
new Gradient( 1, 0, -1), new Gradient(-1, 0, -1), new Gradient( 0, 1, 1), new Gradient(1, 0, -1), new Gradient(-1, 0, -1), new Gradient(0, 1, 1),
new Gradient( 0, -1, 1), new Gradient( 0, 1, -1), new Gradient( 0, -1, -1) new Gradient(0, -1, 1), new Gradient(0, 1, -1), new Gradient(0, -1, -1)
}; };
private static final short P_SUPPLY[] = { private static final short P_SUPPLY[] = {
@ -51,7 +51,7 @@ public class SimplexNoiseOctave {
Random random = new Random(seed); Random random = new Random(seed);
for(int index = 0; index < SWAP_COUNT; index++) { for (int index = 0; index < SWAP_COUNT; index++) {
int swapFrom = random.nextInt(this.p.length); int swapFrom = random.nextInt(this.p.length);
int swapTo = random.nextInt(this.p.length); int swapTo = random.nextInt(this.p.length);
@ -61,27 +61,29 @@ public class SimplexNoiseOctave {
this.p[swapTo] = temp; this.p[swapTo] = temp;
} }
for(int index = 0; index < LENGTH; index++) { for (int index = 0; index < LENGTH; index++) {
this.perm[index] = this.p[index & 255]; this.perm[index] = this.p[index & 255];
this.permMod12[index] = (short)(this.perm[index] % 12); this.permMod12[index] = (short) (this.perm[index] % 12);
} }
} }
/** /**
* A method with the functionality of {@link Math#floor(double)} but it is faster. * A method with the functionality of {@link Math#floor(double)} but it is faster.
*
* @param x the value * @param x the value
* @return the result * @return the result
* @see Math#floor(double) * @see Math#floor(double)
*/ */
private static final int fastfloor(double x) { private static final int fastfloor(double x) {
int xAsInt = (int)x; int xAsInt = (int) x;
return x < xAsInt ? xAsInt - 1 : xAsInt; return x < xAsInt ? xAsInt - 1 : xAsInt;
} }
/** /**
* Dot function for a gradient. * Dot function for a gradient.
*
* @param gradient the gradient * @param gradient the gradient
* @param x X * @param x X
* @param y Y * @param y Y
@ -94,6 +96,7 @@ public class SimplexNoiseOctave {
/** /**
* Dot function for a gradient. * Dot function for a gradient.
*
* @param gradient the gradient * @param gradient the gradient
* @param x X * @param x X
* @param y Y * @param y Y
@ -107,6 +110,7 @@ public class SimplexNoiseOctave {
/** /**
* Makes a two dimensional noise. * Makes a two dimensional noise.
*
* @param x X * @param x X
* @param y Y * @param y Y
* @return the noise * @return the noise
@ -133,7 +137,7 @@ public class SimplexNoiseOctave {
int i1; int i1;
int j1; int j1;
if(x0 > y0) { if (x0 > y0) {
i1 = 1; i1 = 1;
j1 = 0; j1 = 0;
@ -158,7 +162,7 @@ public class SimplexNoiseOctave {
double t0 = 0.5D - x0 * x0 - y0 * y0; double t0 = 0.5D - x0 * x0 - y0 * y0;
if(t0 < 0) { if (t0 < 0) {
n0 = 0.0; n0 = 0.0;
@ -170,7 +174,7 @@ public class SimplexNoiseOctave {
double t1 = 0.5D - x1 * x1 - y1 * y1; double t1 = 0.5D - x1 * x1 - y1 * y1;
if(t1 < 0.0D) { if (t1 < 0.0D) {
n1 = 0.0; n1 = 0.0;
@ -182,7 +186,7 @@ public class SimplexNoiseOctave {
double t2 = 0.5D - x2 * x2 - y2 * y2; double t2 = 0.5D - x2 * x2 - y2 * y2;
if(t2 < 0.0D) { if (t2 < 0.0D) {
n2 = 0.0D; n2 = 0.0D;
@ -197,6 +201,7 @@ public class SimplexNoiseOctave {
/** /**
* Makes a three dimensional noise. * Makes a three dimensional noise.
*
* @param x X * @param x X
* @param y Y * @param y Y
* @param z Z * @param z Z
@ -232,9 +237,9 @@ public class SimplexNoiseOctave {
int j2; int j2;
int k2; int k2;
if(x0 >= y0) { if (x0 >= y0) {
if(y0 >= z0) { if (y0 >= z0) {
i1 = 1; i1 = 1;
j1 = 0; j1 = 0;
@ -243,7 +248,7 @@ public class SimplexNoiseOctave {
j2 = 1; j2 = 1;
k2 = 0; k2 = 0;
} else if(x0 >= z0) { } else if (x0 >= z0) {
i1 = 1; i1 = 1;
j1 = 0; j1 = 0;
@ -264,7 +269,7 @@ public class SimplexNoiseOctave {
} else { } else {
if(y0 < z0) { if (y0 < z0) {
i1 = 0; i1 = 0;
j1 = 0; j1 = 0;
@ -273,7 +278,7 @@ public class SimplexNoiseOctave {
j2 = 1; j2 = 1;
k2 = 1; k2 = 1;
} else if(x0 < z0) { } else if (x0 < z0) {
i1 = 0; i1 = 0;
j1 = 1; j1 = 1;
@ -316,7 +321,7 @@ public class SimplexNoiseOctave {
double t0 = 0.6D - x0 * x0 - y0 * y0 - z0 * z0; double t0 = 0.6D - x0 * x0 - y0 * y0 - z0 * z0;
if(t0 < 0) { if (t0 < 0) {
n0 = 0.0D; n0 = 0.0D;
@ -328,7 +333,7 @@ public class SimplexNoiseOctave {
double t1 = 0.6D - x1 * x1 - y1 * y1 - z1 * z1; double t1 = 0.6D - x1 * x1 - y1 * y1 - z1 * z1;
if(t1 < 0) { if (t1 < 0) {
n1 = 0.0D; n1 = 0.0D;
@ -340,7 +345,7 @@ public class SimplexNoiseOctave {
double t2 = 0.6D - x2 * x2 - y2 * y2 - z2 * z2; double t2 = 0.6D - x2 * x2 - y2 * y2 - z2 * z2;
if(t2 < 0) { if (t2 < 0) {
n2 = 0.0D; n2 = 0.0D;
@ -352,7 +357,7 @@ public class SimplexNoiseOctave {
double t3 = 0.6D - x3 * x3 - y3 * y3 - z3 * z3; double t3 = 0.6D - x3 * x3 - y3 * y3 - z3 * z3;
if(t3 < 0) { if (t3 < 0) {
n3 = 0.0D; n3 = 0.0D;