Skip to content

Commit

Permalink
Fix JS using double multiply instead of int for hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Aug 13, 2023
1 parent 95900f7 commit f02085e
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions JavaScript/FastNoiseLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ export default class FastNoiseLite {
* @returns {number}
*/
static _PingPong(t) {
t -= Math.trunc(t * 0.5 * 2);
t -= Math.trunc(t * 0.5) * 2;
return t < 1 ? t : 2 - t;
}

Expand All @@ -701,8 +701,8 @@ export default class FastNoiseLite {
* @returns {number}
*/
_HashR2(seed, xPrimed, yPrimed) {
let hash = Math.trunc(seed ^ xPrimed ^ yPrimed);
hash = (hash * 0x27d4eb2d) >>> 0;
let hash = seed ^ xPrimed ^ yPrimed;
hash = Math.imul(hash, 0x27d4eb2d);
return hash;
}

Expand All @@ -715,8 +715,8 @@ export default class FastNoiseLite {
* @returns {number}
*/
_HashR3(seed, xPrimed, yPrimed, zPrimed){
let hash = Math.trunc(seed ^ xPrimed ^ yPrimed ^ zPrimed);
hash = (hash * 0x27d4eb2d) >>> 0;
let hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash = Math.imul(hash, 0x27d4eb2d);
return hash;
}

Expand All @@ -730,7 +730,7 @@ export default class FastNoiseLite {
_ValCoordR2(seed, xPrimed, yPrimed) {
let hash = this._HashR2(seed, xPrimed, yPrimed);

hash *= hash;
hash = Math.imul(hash, hash);
hash ^= hash << 19;
return hash * (1 / 2147483648.0);
}
Expand All @@ -746,7 +746,7 @@ export default class FastNoiseLite {
_ValCoordR3(seed, xPrimed, yPrimed, zPrimed){
let hash = this._HashR3(seed, xPrimed, yPrimed, zPrimed);

hash *= hash;
hash = Math.imul(hash, hash);
hash ^= hash << 19;
return hash * (1 / 2147483648.0);
}
Expand Down Expand Up @@ -1065,8 +1065,8 @@ export default class FastNoiseLite {
let x0 = xi - t;
let y0 = yi - t;

i *= this._PrimeX;
j *= this._PrimeY;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);

let n0, n1, n2;

Expand Down Expand Up @@ -1133,9 +1133,9 @@ export default class FastNoiseLite {
let ax0 = xNSign * -x0;
let ay0 = yNSign * -y0;
let az0 = zNSign * -z0;
i *= this._PrimeX;
j *= this._PrimeY;
k *= this._PrimeZ;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
k = Math.imul(k, this._PrimeZ);

let value = 0;
let a = 0.6 - x0 * x0 - (y0 * y0 + z0 * z0);
Expand Down Expand Up @@ -1253,8 +1253,8 @@ export default class FastNoiseLite {
let xi = x - i;
let yi = y - j;

i *= this._PrimeX;
j *= this._PrimeY;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
let i1 = i + this._PrimeX;
let j1 = j + this._PrimeY;

Expand Down Expand Up @@ -1379,9 +1379,9 @@ export default class FastNoiseLite {
let yi = y - j;
let zi = z - k;

i *= this._PrimeX;
j *= this._PrimeY;
k *= this._PrimeZ;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
k = Math.imul(k, this._PrimeZ);
let seed2 = seed + 1293373;

let xNMask = Math.trunc(-0.5 - xi);
Expand Down Expand Up @@ -1976,8 +1976,8 @@ export default class FastNoiseLite {
let xs = FastNoiseLite._InterpQuintic(xd0);
let ys = FastNoiseLite._InterpQuintic(yd0);

x0 *= this._PrimeX;
y0 *= this._PrimeY;
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;

Expand Down Expand Up @@ -2019,9 +2019,9 @@ export default class FastNoiseLite {
let ys = FastNoiseLite._InterpQuintic(yd0);
let zs = FastNoiseLite._InterpQuintic(zd0);

x0 *= this._PrimeX;
y0 *= this._PrimeY;
z0 *= this._PrimeZ;
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
z0 = Math.imul(z0, this._PrimeZ);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let z1 = z0 + this._PrimeZ;
Expand Down Expand Up @@ -2067,8 +2067,8 @@ export default class FastNoiseLite {
let xs = x - x1;
let ys = y - y1;

x1 *= this._PrimeX;
y1 *= this._PrimeY;
x1 = Math.imul(x1, this._PrimeX);
y1 = Math.imul(y1, this._PrimeY);
let x0 = x1 - this._PrimeX;
let y0 = y1 - this._PrimeY;
let x2 = x1 + this._PrimeX;
Expand Down Expand Up @@ -2129,9 +2129,9 @@ export default class FastNoiseLite {
let ys = y - y1;
let zs = z - z1;

x1 *= this._PrimeX;
y1 *= this._PrimeY;
z1 *= this._PrimeZ;
x1 = Math.imul(x1, this._PrimeX);
y1 = Math.imul(y1, this._PrimeY);
z1 = Math.imul(z1, this._PrimeZ);

let x0 = x1 - this._PrimeX;
let y0 = y1 - this._PrimeY;
Expand Down Expand Up @@ -2289,8 +2289,8 @@ export default class FastNoiseLite {
let xs = FastNoiseLite._InterpHermite(x - x0);
let ys = FastNoiseLite._InterpHermite(y - y0);

x0 *= this._PrimeX;
y0 *= this._PrimeY;
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;

Expand All @@ -2317,9 +2317,9 @@ export default class FastNoiseLite {
let ys = FastNoiseLite._InterpHermite(y - y0);
let zs = FastNoiseLite._InterpHermite(z - z0);

x0 *= this._PrimeX;
y0 *= this._PrimeY;
z0 *= this._PrimeZ;
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
z0 = Math.imul(z0, this._PrimeZ);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let z1 = z0 + this._PrimeZ;
Expand Down Expand Up @@ -2762,8 +2762,8 @@ export default class FastNoiseLite {
let xs = FastNoiseLite._InterpHermite(xf - x0);
let ys = FastNoiseLite._InterpHermite(yf - y0);

x0 *= this._PrimeX;
y0 *= this._PrimeY;
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;

Expand Down Expand Up @@ -2806,9 +2806,9 @@ export default class FastNoiseLite {
let ys = FastNoiseLite._InterpHermite(yf - y0);
let zs = FastNoiseLite._InterpHermite(zf - z0);

x0 *= this._PrimeX;
y0 *= this._PrimeY;
z0 *= this._PrimeZ;
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
z0 = Math.imul(z0, this._PrimeZ);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let z1 = z0 + this._PrimeZ;
Expand Down Expand Up @@ -2897,8 +2897,8 @@ export default class FastNoiseLite {
let x0 = xi - t;
let y0 = yi - t;

i *= this._PrimeX;
j *= this._PrimeY;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);

let vx, vy;
vx = vy = 0;
Expand Down Expand Up @@ -3042,9 +3042,9 @@ export default class FastNoiseLite {
let ay0 = yNSign * -y0;
let az0 = zNSign * -z0;

i *= this._PrimeX;
j *= this._PrimeY;
k *= this._PrimeZ;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
k = Math.imul(k, this._PrimeZ);

let vx, vy, vz;
vx = vy = vz = 0;
Expand Down

0 comments on commit f02085e

Please sign in to comment.