@tsparticles/simplex-noise 4.0.5 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,25 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
2
  const half = 0.5;
3
3
  export class SimplexNoise2D {
4
- _NORM_2D;
5
- _SQUISH_2D;
6
- _STRETCH_2D;
7
- _base2D;
8
- _gradients2D;
9
- _lookup;
10
- _lookupPairs2D;
11
- _p2D;
12
- _perm;
13
- _perm2D;
4
+ #NORM_2D;
5
+ #SQUISH_2D;
6
+ #STRETCH_2D;
7
+ #base2D;
8
+ #gradients2D;
9
+ #lookup;
10
+ #lookupPairs2D;
11
+ #p2D;
12
+ #perm;
13
+ #perm2D;
14
14
  constructor() {
15
- this._NORM_2D = 1 / 47;
16
- this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) * half;
17
- this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) * half;
18
- this._base2D = [
15
+ this.#NORM_2D = 1 / 47;
16
+ this.#SQUISH_2D = (Math.sqrt(2 + 1) - 1) * half;
17
+ this.#STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) * half;
18
+ this.#base2D = [
19
19
  [1, 1, 0, 1, 0, 1, 0, 0, 0],
20
20
  [1, 1, 0, 1, 0, 1, 2, 1, 1],
21
21
  ];
22
- this._gradients2D = [
22
+ this.#gradients2D = [
23
23
  5,
24
24
  2,
25
25
  2,
@@ -37,8 +37,8 @@ export class SimplexNoise2D {
37
37
  -2,
38
38
  -5,
39
39
  ];
40
- this._lookup = [];
41
- this._lookupPairs2D = [
40
+ this.#lookup = [];
41
+ this.#lookupPairs2D = [
42
42
  0,
43
43
  1,
44
44
  1,
@@ -64,7 +64,7 @@ export class SimplexNoise2D {
64
64
  43,
65
65
  3,
66
66
  ];
67
- this._p2D = [
67
+ this.#p2D = [
68
68
  0,
69
69
  0,
70
70
  1,
@@ -90,29 +90,29 @@ export class SimplexNoise2D {
90
90
  0,
91
91
  0,
92
92
  ];
93
- this._perm = new Uint8Array(256);
94
- this._perm2D = new Uint8Array(256);
93
+ this.#perm = new Uint8Array(256);
94
+ this.#perm2D = new Uint8Array(256);
95
95
  }
96
96
  noise(x, y) {
97
- const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this, stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
97
+ const gradients2D = this.#gradients2D, NORM_2D = this.#NORM_2D, SQUISH_2D = this.#SQUISH_2D, STRETCH_2D = this.#STRETCH_2D, lookup = this.#lookup, perm = this.#perm, perm2D = this.#perm2D, stretchOffset = (x + y) * STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
98
98
  let value = 0;
99
- for (let c = _lookup[hash]; c !== undefined; c = c.next) {
99
+ for (let c = lookup[hash]; c !== undefined; c = c.next) {
100
100
  const dx = dx0 + c.dx, dy = dy0 + c.dy, attn = 2 - dx * dx - dy * dy;
101
101
  if (attn <= 0) {
102
102
  continue;
103
103
  }
104
- const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
104
+ const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = perm[px & 0xff], index = perm2D[(indexPartA + py) & 0xff], valuePart = gradients2D[index] * dx + gradients2D[index + 1] * dy;
105
105
  value += attn * attn * attn * attn * valuePart;
106
106
  }
107
- return value * _NORM_2D;
107
+ return value * NORM_2D;
108
108
  }
109
109
  seed(clientSeed) {
110
- const { _p2D, _base2D, _lookupPairs2D } = this, contributions = [];
111
- for (let i = 0; i < _p2D.length; i += 4) {
112
- const baseSet = _base2D[_p2D[i]];
110
+ const p2D = this.#p2D, base2D = this.#base2D, lookupPairs2D = this.#lookupPairs2D, contributions = [];
111
+ for (let i = 0; i < p2D.length; i += 4) {
112
+ const baseSet = base2D[p2D[i]];
113
113
  let previous = null, current = null;
114
114
  for (let k = 0; k < baseSet.length; k += 3) {
115
- current = this._contribution2D(baseSet[k], baseSet[k + 1], baseSet[k + 2]);
115
+ current = this.#contribution2D(baseSet[k], baseSet[k + 1], baseSet[k + 2]);
116
116
  if (previous === null) {
117
117
  contributions[i / 4] = current;
118
118
  }
@@ -122,15 +122,15 @@ export class SimplexNoise2D {
122
122
  previous = current;
123
123
  }
124
124
  if (current) {
125
- current.next = this._contribution2D(_p2D[i + 1], _p2D[i + 2], _p2D[i + 3]);
125
+ current.next = this.#contribution2D(p2D[i + 1], p2D[i + 2], p2D[i + 3]);
126
126
  }
127
127
  }
128
- this._lookup = [];
129
- for (let i = 0; i < _lookupPairs2D.length; i += 2) {
130
- this._lookup[_lookupPairs2D[i]] = contributions[_lookupPairs2D[i + 1]];
128
+ this.#lookup = [];
129
+ for (let i = 0; i < lookupPairs2D.length; i += 2) {
130
+ this.#lookup[lookupPairs2D[i]] = contributions[lookupPairs2D[i + 1]];
131
131
  }
132
- this._perm = new Uint8Array(256);
133
- this._perm2D = new Uint8Array(256);
132
+ this.#perm = new Uint8Array(256);
133
+ this.#perm2D = new Uint8Array(256);
134
134
  const source = new Uint8Array(256);
135
135
  for (let i = 0; i < 256; i++) {
136
136
  source[i] = i;
@@ -145,16 +145,16 @@ export class SimplexNoise2D {
145
145
  if (r[0] < 0) {
146
146
  r[0] += i + 1;
147
147
  }
148
- this._perm[i] = source[r[0]];
149
- this._perm2D[i] = this._perm[i] & 0x0e;
148
+ this.#perm[i] = source[r[0]];
149
+ this.#perm2D[i] = this.#perm[i] & 0x0e;
150
150
  source[r[0]] = source[i];
151
151
  }
152
152
  }
153
- _contribution2D(multiplier, xsb, ysb) {
154
- const { _SQUISH_2D } = this;
153
+ #contribution2D(multiplier, xsb, ysb) {
154
+ const SQUISH_2D = this.#SQUISH_2D;
155
155
  return {
156
- dx: -xsb - multiplier * _SQUISH_2D,
157
- dy: -ysb - multiplier * _SQUISH_2D,
156
+ dx: -xsb - multiplier * SQUISH_2D,
157
+ dy: -ysb - multiplier * SQUISH_2D,
158
158
  xsb,
159
159
  ysb,
160
160
  };
@@ -1,26 +1,26 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
2
  const third = 1 / 3;
3
3
  export class SimplexNoise3D {
4
- _NORM_3D;
5
- _SQUISH_3D;
6
- _STRETCH_3D;
7
- _base3D;
8
- _gradients3D;
9
- _lookup;
10
- _lookupPairs3D;
11
- _p3D;
12
- _perm;
13
- _perm3D;
4
+ #NORM_3D;
5
+ #SQUISH_3D;
6
+ #STRETCH_3D;
7
+ #base3D;
8
+ #gradients3D;
9
+ #lookup;
10
+ #lookupPairs3D;
11
+ #p3D;
12
+ #perm;
13
+ #perm3D;
14
14
  constructor() {
15
- this._NORM_3D = 1 / 103;
16
- this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) * third;
17
- this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) * third;
18
- this._base3D = [
15
+ this.#NORM_3D = 1 / 103;
16
+ this.#SQUISH_3D = (Math.sqrt(3 + 1) - 1) * third;
17
+ this.#STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) * third;
18
+ this.#base3D = [
19
19
  [0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1],
20
20
  [2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 3, 1, 1, 1],
21
21
  [1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1],
22
22
  ];
23
- this._gradients3D = [
23
+ this.#gradients3D = [
24
24
  -11,
25
25
  4,
26
26
  4,
@@ -94,8 +94,8 @@ export class SimplexNoise3D {
94
94
  -4,
95
95
  -11,
96
96
  ];
97
- this._lookup = [];
98
- this._lookupPairs3D = [
97
+ this.#lookup = [];
98
+ this.#lookupPairs3D = [
99
99
  0,
100
100
  2,
101
101
  1,
@@ -241,7 +241,7 @@ export class SimplexNoise3D {
241
241
  2039,
242
242
  6,
243
243
  ];
244
- this._p3D = [
244
+ this.#p3D = [
245
245
  0,
246
246
  0,
247
247
  1,
@@ -459,11 +459,11 @@ export class SimplexNoise3D {
459
459
  2,
460
460
  0,
461
461
  ];
462
- this._perm = new Uint8Array(256);
463
- this._perm3D = new Uint8Array(256);
462
+ this.#perm = new Uint8Array(256);
463
+ this.#perm3D = new Uint8Array(256);
464
464
  }
465
465
  noise(x, y, z) {
466
- const { _STRETCH_3D, _NORM_3D, _SQUISH_3D, _lookup, _perm, _perm3D, _gradients3D } = this, stretchOffset = (x + y + z) * _STRETCH_3D, xs = x + stretchOffset, ys = y + stretchOffset, zs = z + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), zsb = Math.floor(zs), squishOffset = (xsb + ysb + zsb) * _SQUISH_3D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), dz0 = z - (zsb + squishOffset), xins = xs - xsb, yins = ys - ysb, zins = zs - zsb, inSum = xins + yins + zins, hash = (yins - zins + 1) |
466
+ const STRETCH_3D = this.#STRETCH_3D, NORM_3D = this.#NORM_3D, SQUISH_3D = this.#SQUISH_3D, lookup = this.#lookup, perm = this.#perm, perm3D = this.#perm3D, gradients3D = this.#gradients3D, stretchOffset = (x + y + z) * STRETCH_3D, xs = x + stretchOffset, ys = y + stretchOffset, zs = z + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), zsb = Math.floor(zs), squishOffset = (xsb + ysb + zsb) * SQUISH_3D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), dz0 = z - (zsb + squishOffset), xins = xs - xsb, yins = ys - ysb, zins = zs - zsb, inSum = xins + yins + zins, hash = (yins - zins + 1) |
467
467
  ((xins - yins + 1) << 1) |
468
468
  ((xins - zins + 1) << 2) |
469
469
  (inSum << 3) |
@@ -471,22 +471,22 @@ export class SimplexNoise3D {
471
471
  ((inSum + yins) << 7) |
472
472
  ((inSum + xins) << 9);
473
473
  let value = 0;
474
- for (let c = _lookup[hash]; c !== undefined; c = c.next) {
474
+ for (let c = lookup[hash]; c !== undefined; c = c.next) {
475
475
  const dx = dx0 + c.dx, dy = dy0 + c.dy, dz = dz0 + c.dz, attn = 2 - dx * dx - dy * dy - dz * dz;
476
476
  if (attn > 0) {
477
- const px = xsb + c.xsb, py = ysb + c.ysb, pz = zsb + c.zsb, indexPartA = _perm[px & 0xff], indexPartB = _perm[(indexPartA + py) & 0xff], index = _perm3D[(indexPartB + pz) & 0xff], valuePart = _gradients3D[index] * dx + _gradients3D[index + 1] * dy + _gradients3D[index + 2] * dz;
477
+ const px = xsb + c.xsb, py = ysb + c.ysb, pz = zsb + c.zsb, indexPartA = perm[px & 0xff], indexPartB = perm[(indexPartA + py) & 0xff], index = perm3D[(indexPartB + pz) & 0xff], valuePart = gradients3D[index] * dx + gradients3D[index + 1] * dy + gradients3D[index + 2] * dz;
478
478
  value += attn * attn * attn * attn * valuePart;
479
479
  }
480
480
  }
481
- return value * _NORM_3D;
481
+ return value * NORM_3D;
482
482
  }
483
483
  seed(clientSeed) {
484
- const { _base3D, _lookupPairs3D, _p3D } = this, contributions = [];
485
- for (let i = 0; i < _p3D.length; i += 9) {
486
- const baseSet = _base3D[_p3D[i]];
484
+ const base3D = this.#base3D, lookupPairs3D = this.#lookupPairs3D, p3D = this.#p3D, contributions = [];
485
+ for (let i = 0; i < p3D.length; i += 9) {
486
+ const baseSet = base3D[p3D[i]];
487
487
  let previous = null, current = null;
488
488
  for (let k = 0; k < baseSet.length; k += 4) {
489
- current = this._contribution3D(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3]);
489
+ current = this.#contribution3D(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3]);
490
490
  if (previous === null) {
491
491
  contributions[i / 9] = current;
492
492
  }
@@ -496,16 +496,16 @@ export class SimplexNoise3D {
496
496
  previous = current;
497
497
  }
498
498
  if (current) {
499
- current.next = this._contribution3D(_p3D[i + 1], _p3D[i + 2], _p3D[i + 3], _p3D[i + 4]);
500
- current.next.next = this._contribution3D(_p3D[i + 5], _p3D[i + 6], _p3D[i + 7], _p3D[i + 8]);
499
+ current.next = this.#contribution3D(p3D[i + 1], p3D[i + 2], p3D[i + 3], p3D[i + 4]);
500
+ current.next.next = this.#contribution3D(p3D[i + 5], p3D[i + 6], p3D[i + 7], p3D[i + 8]);
501
501
  }
502
502
  }
503
- this._lookup = [];
504
- for (let i = 0; i < _lookupPairs3D.length; i += 2) {
505
- this._lookup[_lookupPairs3D[i]] = contributions[_lookupPairs3D[i + 1]];
503
+ this.#lookup = [];
504
+ for (let i = 0; i < lookupPairs3D.length; i += 2) {
505
+ this.#lookup[lookupPairs3D[i]] = contributions[lookupPairs3D[i + 1]];
506
506
  }
507
- this._perm = new Uint8Array(256);
508
- this._perm3D = new Uint8Array(256);
507
+ this.#perm = new Uint8Array(256);
508
+ this.#perm3D = new Uint8Array(256);
509
509
  const source = new Uint8Array(256);
510
510
  for (let i = 0; i < 256; i++) {
511
511
  source[i] = i;
@@ -520,17 +520,17 @@ export class SimplexNoise3D {
520
520
  if (r[0] < 0) {
521
521
  r[0] += i + 1;
522
522
  }
523
- this._perm[i] = source[r[0]];
524
- this._perm3D[i] = (this._perm[i] % 24) * 3;
523
+ this.#perm[i] = source[r[0]];
524
+ this.#perm3D[i] = (this.#perm[i] % 24) * 3;
525
525
  source[r[0]] = source[i];
526
526
  }
527
527
  }
528
- _contribution3D(multiplier, xsb, ysb, zsb) {
529
- const { _SQUISH_3D } = this;
528
+ #contribution3D(multiplier, xsb, ysb, zsb) {
529
+ const SQUISH_3D = this.#SQUISH_3D;
530
530
  return {
531
- dx: -xsb - multiplier * _SQUISH_3D,
532
- dy: -ysb - multiplier * _SQUISH_3D,
533
- dz: -zsb - multiplier * _SQUISH_3D,
531
+ dx: -xsb - multiplier * SQUISH_3D,
532
+ dy: -ysb - multiplier * SQUISH_3D,
533
+ dz: -zsb - multiplier * SQUISH_3D,
534
534
  xsb,
535
535
  ysb,
536
536
  zsb,
@@ -1,24 +1,24 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
2
  const quarter = 0.25;
3
3
  export class SimplexNoise4D {
4
- _NORM_4D;
5
- _SQUISH_4D;
6
- _STRETCH_4D;
7
- _base4D;
8
- _gradients4D;
9
- _lookup;
10
- _lookupPairs4D;
11
- _p4D;
12
- _perm;
13
- _perm4D;
4
+ #NORM_4D;
5
+ #SQUISH_4D;
6
+ #STRETCH_4D;
7
+ #base4D;
8
+ #gradients4D;
9
+ #lookup;
10
+ #lookupPairs4D;
11
+ #p4D;
12
+ #perm;
13
+ #perm4D;
14
14
  constructor() {
15
- this._NORM_4D = 1 / 30;
16
- this._SQUISH_4D = (Math.sqrt(4 + 1) - 1) * quarter;
17
- this._STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) * quarter;
18
- this._lookup = [];
19
- this._perm = new Uint8Array(0);
20
- this._perm4D = new Uint8Array(0);
21
- this._base4D = [
15
+ this.#NORM_4D = 1 / 30;
16
+ this.#SQUISH_4D = (Math.sqrt(4 + 1) - 1) * quarter;
17
+ this.#STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) * quarter;
18
+ this.#lookup = [];
19
+ this.#perm = new Uint8Array(0);
20
+ this.#perm4D = new Uint8Array(0);
21
+ this.#base4D = [
22
22
  [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1],
23
23
  [3, 1, 1, 1, 0, 3, 1, 1, 0, 1, 3, 1, 0, 1, 1, 3, 0, 1, 1, 1, 4, 1, 1, 1, 1],
24
24
  [
@@ -126,7 +126,7 @@ export class SimplexNoise4D {
126
126
  1,
127
127
  ],
128
128
  ];
129
- this._gradients4D = [
129
+ this.#gradients4D = [
130
130
  3,
131
131
  1,
132
132
  1,
@@ -384,7 +384,7 @@ export class SimplexNoise4D {
384
384
  -1,
385
385
  -3,
386
386
  ];
387
- this._lookupPairs4D = [
387
+ this.#lookupPairs4D = [
388
388
  0,
389
389
  3,
390
390
  1,
@@ -1506,7 +1506,7 @@ export class SimplexNoise4D {
1506
1506
  599295,
1507
1507
  10,
1508
1508
  ];
1509
- this._p4D = [
1509
+ this.#p4D = [
1510
1510
  0,
1511
1511
  0,
1512
1512
  1,
@@ -2790,7 +2790,7 @@ export class SimplexNoise4D {
2790
2790
  ];
2791
2791
  }
2792
2792
  noise(x, y, z, w) {
2793
- const { _perm, _perm4D, _lookup, _STRETCH_4D, _SQUISH_4D, _gradients4D, _NORM_4D } = this, stretchOffset = (x + y + z + w) * _STRETCH_4D, xs = x + stretchOffset, ys = y + stretchOffset, zs = z + stretchOffset, ws = w + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), zsb = Math.floor(zs), wsb = Math.floor(ws), squishOffset = (xsb + ysb + zsb + wsb) * _SQUISH_4D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), dz0 = z - (zsb + squishOffset), dw0 = w - (wsb + squishOffset), xins = xs - xsb, yins = ys - ysb, zins = zs - zsb, wins = ws - wsb, inSum = xins + yins + zins + wins, hash = (zins - wins + 1) |
2793
+ const perm = this.#perm, perm4D = this.#perm4D, lookup = this.#lookup, STRETCH_4D = this.#STRETCH_4D, SQUISH_4D = this.#SQUISH_4D, gradients4D = this.#gradients4D, NORM_4D = this.#NORM_4D, stretchOffset = (x + y + z + w) * STRETCH_4D, xs = x + stretchOffset, ys = y + stretchOffset, zs = z + stretchOffset, ws = w + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), zsb = Math.floor(zs), wsb = Math.floor(ws), squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_4D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), dz0 = z - (zsb + squishOffset), dw0 = w - (wsb + squishOffset), xins = xs - xsb, yins = ys - ysb, zins = zs - zsb, wins = ws - wsb, inSum = xins + yins + zins + wins, hash = (zins - wins + 1) |
2794
2794
  ((yins - zins + 1) << 1) |
2795
2795
  ((yins - wins + 1) << 2) |
2796
2796
  ((xins - yins + 1) << 3) |
@@ -2802,25 +2802,25 @@ export class SimplexNoise4D {
2802
2802
  ((inSum + yins) << 14) |
2803
2803
  ((inSum + xins) << 17);
2804
2804
  let value = 0;
2805
- for (let c = _lookup[hash]; c !== undefined; c = c.next) {
2805
+ for (let c = lookup[hash]; c !== undefined; c = c.next) {
2806
2806
  const dx = dx0 + c.dx, dy = dy0 + c.dy, dz = dz0 + c.dz, dw = dw0 + c.dw, attn = 2 - dx * dx - dy * dy - dz * dz - dw * dw;
2807
2807
  if (attn > 0) {
2808
- const px = xsb + c.xsb, py = ysb + c.ysb, pz = zsb + c.zsb, pw = wsb + c.wsb, indexPartA = _perm[px & 0xff], indexPartB = _perm[(indexPartA + py) & 0xff], indexPartC = _perm[(indexPartB + pz) & 0xff], index = _perm4D[(indexPartC + pw) & 0xff], valuePart = _gradients4D[index] * dx +
2809
- _gradients4D[index + 1] * dy +
2810
- _gradients4D[index + 2] * dz +
2811
- _gradients4D[index + 3] * dw;
2808
+ const px = xsb + c.xsb, py = ysb + c.ysb, pz = zsb + c.zsb, pw = wsb + c.wsb, indexPartA = perm[px & 0xff], indexPartB = perm[(indexPartA + py) & 0xff], indexPartC = perm[(indexPartB + pz) & 0xff], index = perm4D[(indexPartC + pw) & 0xff], valuePart = gradients4D[index] * dx +
2809
+ gradients4D[index + 1] * dy +
2810
+ gradients4D[index + 2] * dz +
2811
+ gradients4D[index + 3] * dw;
2812
2812
  value += attn * attn * attn * attn * valuePart;
2813
2813
  }
2814
2814
  }
2815
- return value * _NORM_4D;
2815
+ return value * NORM_4D;
2816
2816
  }
2817
2817
  seed(clientSeed) {
2818
- const { _p4D, _base4D, _lookupPairs4D } = this, contributions = [];
2819
- for (let i = 0; i < _p4D.length; i += 16) {
2820
- const baseSet = _base4D[_p4D[i]];
2818
+ const p4D = this.#p4D, base4D = this.#base4D, lookupPairs4D = this.#lookupPairs4D, contributions = [];
2819
+ for (let i = 0; i < p4D.length; i += 16) {
2820
+ const baseSet = base4D[p4D[i]];
2821
2821
  let previous = null, current = null;
2822
2822
  for (let k = 0; k < baseSet.length; k += 5) {
2823
- current = this._contribution4D(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3], baseSet[k + 4]);
2823
+ current = this.#contribution4D(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3], baseSet[k + 4]);
2824
2824
  if (previous === null) {
2825
2825
  contributions[i / 16] = current;
2826
2826
  }
@@ -2830,17 +2830,17 @@ export class SimplexNoise4D {
2830
2830
  previous = current;
2831
2831
  }
2832
2832
  if (current) {
2833
- current.next = this._contribution4D(_p4D[i + 1], _p4D[i + 2], _p4D[i + 3], _p4D[i + 4], _p4D[i + 5]);
2834
- current.next.next = this._contribution4D(_p4D[i + 6], _p4D[i + 7], _p4D[i + 8], _p4D[i + 9], _p4D[i + 10]);
2835
- current.next.next.next = this._contribution4D(_p4D[i + 11], _p4D[i + 12], _p4D[i + 13], _p4D[i + 14], _p4D[i + 15]);
2833
+ current.next = this.#contribution4D(p4D[i + 1], p4D[i + 2], p4D[i + 3], p4D[i + 4], p4D[i + 5]);
2834
+ current.next.next = this.#contribution4D(p4D[i + 6], p4D[i + 7], p4D[i + 8], p4D[i + 9], p4D[i + 10]);
2835
+ current.next.next.next = this.#contribution4D(p4D[i + 11], p4D[i + 12], p4D[i + 13], p4D[i + 14], p4D[i + 15]);
2836
2836
  }
2837
2837
  }
2838
- this._lookup = [];
2839
- for (let i = 0; i < _lookupPairs4D.length; i += 2) {
2840
- this._lookup[_lookupPairs4D[i]] = contributions[_lookupPairs4D[i + 1]];
2838
+ this.#lookup = [];
2839
+ for (let i = 0; i < lookupPairs4D.length; i += 2) {
2840
+ this.#lookup[lookupPairs4D[i]] = contributions[lookupPairs4D[i + 1]];
2841
2841
  }
2842
- this._perm = new Uint8Array(256);
2843
- this._perm4D = new Uint8Array(256);
2842
+ this.#perm = new Uint8Array(256);
2843
+ this.#perm4D = new Uint8Array(256);
2844
2844
  const source = new Uint8Array(256);
2845
2845
  for (let i = 0; i < 256; i++) {
2846
2846
  source[i] = i;
@@ -2855,18 +2855,18 @@ export class SimplexNoise4D {
2855
2855
  if (r[0] < 0) {
2856
2856
  r[0] += i + 1;
2857
2857
  }
2858
- this._perm[i] = source[r[0]];
2859
- this._perm4D[i] = this._perm[i] & 0xfc;
2858
+ this.#perm[i] = source[r[0]];
2859
+ this.#perm4D[i] = this.#perm[i] & 0xfc;
2860
2860
  source[r[0]] = source[i];
2861
2861
  }
2862
2862
  }
2863
- _contribution4D(multiplier, xsb, ysb, zsb, wsb) {
2864
- const { _SQUISH_4D } = this;
2863
+ #contribution4D(multiplier, xsb, ysb, zsb, wsb) {
2864
+ const SQUISH_4D = this.#SQUISH_4D;
2865
2865
  return {
2866
- dx: -xsb - multiplier * _SQUISH_4D,
2867
- dy: -ysb - multiplier * _SQUISH_4D,
2868
- dz: -zsb - multiplier * _SQUISH_4D,
2869
- dw: -wsb - multiplier * _SQUISH_4D,
2866
+ dx: -xsb - multiplier * SQUISH_4D,
2867
+ dy: -ysb - multiplier * SQUISH_4D,
2868
+ dz: -zsb - multiplier * SQUISH_4D,
2869
+ dw: -wsb - multiplier * SQUISH_4D,
2870
2870
  xsb,
2871
2871
  ysb,
2872
2872
  zsb,
@@ -1,25 +1,25 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
2
  const half = 0.5;
3
3
  export class SimplexNoise2D {
4
- _NORM_2D;
5
- _SQUISH_2D;
6
- _STRETCH_2D;
7
- _base2D;
8
- _gradients2D;
9
- _lookup;
10
- _lookupPairs2D;
11
- _p2D;
12
- _perm;
13
- _perm2D;
4
+ #NORM_2D;
5
+ #SQUISH_2D;
6
+ #STRETCH_2D;
7
+ #base2D;
8
+ #gradients2D;
9
+ #lookup;
10
+ #lookupPairs2D;
11
+ #p2D;
12
+ #perm;
13
+ #perm2D;
14
14
  constructor() {
15
- this._NORM_2D = 1 / 47;
16
- this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) * half;
17
- this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) * half;
18
- this._base2D = [
15
+ this.#NORM_2D = 1 / 47;
16
+ this.#SQUISH_2D = (Math.sqrt(2 + 1) - 1) * half;
17
+ this.#STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) * half;
18
+ this.#base2D = [
19
19
  [1, 1, 0, 1, 0, 1, 0, 0, 0],
20
20
  [1, 1, 0, 1, 0, 1, 2, 1, 1],
21
21
  ];
22
- this._gradients2D = [
22
+ this.#gradients2D = [
23
23
  5,
24
24
  2,
25
25
  2,
@@ -37,8 +37,8 @@ export class SimplexNoise2D {
37
37
  -2,
38
38
  -5,
39
39
  ];
40
- this._lookup = [];
41
- this._lookupPairs2D = [
40
+ this.#lookup = [];
41
+ this.#lookupPairs2D = [
42
42
  0,
43
43
  1,
44
44
  1,
@@ -64,7 +64,7 @@ export class SimplexNoise2D {
64
64
  43,
65
65
  3,
66
66
  ];
67
- this._p2D = [
67
+ this.#p2D = [
68
68
  0,
69
69
  0,
70
70
  1,
@@ -90,29 +90,29 @@ export class SimplexNoise2D {
90
90
  0,
91
91
  0,
92
92
  ];
93
- this._perm = new Uint8Array(256);
94
- this._perm2D = new Uint8Array(256);
93
+ this.#perm = new Uint8Array(256);
94
+ this.#perm2D = new Uint8Array(256);
95
95
  }
96
96
  noise(x, y) {
97
- const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this, stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
97
+ const gradients2D = this.#gradients2D, NORM_2D = this.#NORM_2D, SQUISH_2D = this.#SQUISH_2D, STRETCH_2D = this.#STRETCH_2D, lookup = this.#lookup, perm = this.#perm, perm2D = this.#perm2D, stretchOffset = (x + y) * STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
98
98
  let value = 0;
99
- for (let c = _lookup[hash]; c !== undefined; c = c.next) {
99
+ for (let c = lookup[hash]; c !== undefined; c = c.next) {
100
100
  const dx = dx0 + c.dx, dy = dy0 + c.dy, attn = 2 - dx * dx - dy * dy;
101
101
  if (attn <= 0) {
102
102
  continue;
103
103
  }
104
- const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
104
+ const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = perm[px & 0xff], index = perm2D[(indexPartA + py) & 0xff], valuePart = gradients2D[index] * dx + gradients2D[index + 1] * dy;
105
105
  value += attn * attn * attn * attn * valuePart;
106
106
  }
107
- return value * _NORM_2D;
107
+ return value * NORM_2D;
108
108
  }
109
109
  seed(clientSeed) {
110
- const { _p2D, _base2D, _lookupPairs2D } = this, contributions = [];
111
- for (let i = 0; i < _p2D.length; i += 4) {
112
- const baseSet = _base2D[_p2D[i]];
110
+ const p2D = this.#p2D, base2D = this.#base2D, lookupPairs2D = this.#lookupPairs2D, contributions = [];
111
+ for (let i = 0; i < p2D.length; i += 4) {
112
+ const baseSet = base2D[p2D[i]];
113
113
  let previous = null, current = null;
114
114
  for (let k = 0; k < baseSet.length; k += 3) {
115
- current = this._contribution2D(baseSet[k], baseSet[k + 1], baseSet[k + 2]);
115
+ current = this.#contribution2D(baseSet[k], baseSet[k + 1], baseSet[k + 2]);
116
116
  if (previous === null) {
117
117
  contributions[i / 4] = current;
118
118
  }
@@ -122,15 +122,15 @@ export class SimplexNoise2D {
122
122
  previous = current;
123
123
  }
124
124
  if (current) {
125
- current.next = this._contribution2D(_p2D[i + 1], _p2D[i + 2], _p2D[i + 3]);
125
+ current.next = this.#contribution2D(p2D[i + 1], p2D[i + 2], p2D[i + 3]);
126
126
  }
127
127
  }
128
- this._lookup = [];
129
- for (let i = 0; i < _lookupPairs2D.length; i += 2) {
130
- this._lookup[_lookupPairs2D[i]] = contributions[_lookupPairs2D[i + 1]];
128
+ this.#lookup = [];
129
+ for (let i = 0; i < lookupPairs2D.length; i += 2) {
130
+ this.#lookup[lookupPairs2D[i]] = contributions[lookupPairs2D[i + 1]];
131
131
  }
132
- this._perm = new Uint8Array(256);
133
- this._perm2D = new Uint8Array(256);
132
+ this.#perm = new Uint8Array(256);
133
+ this.#perm2D = new Uint8Array(256);
134
134
  const source = new Uint8Array(256);
135
135
  for (let i = 0; i < 256; i++) {
136
136
  source[i] = i;
@@ -145,16 +145,16 @@ export class SimplexNoise2D {
145
145
  if (r[0] < 0) {
146
146
  r[0] += i + 1;
147
147
  }
148
- this._perm[i] = source[r[0]];
149
- this._perm2D[i] = this._perm[i] & 0x0e;
148
+ this.#perm[i] = source[r[0]];
149
+ this.#perm2D[i] = this.#perm[i] & 0x0e;
150
150
  source[r[0]] = source[i];
151
151
  }
152
152
  }
153
- _contribution2D(multiplier, xsb, ysb) {
154
- const { _SQUISH_2D } = this;
153
+ #contribution2D(multiplier, xsb, ysb) {
154
+ const SQUISH_2D = this.#SQUISH_2D;
155
155
  return {
156
- dx: -xsb - multiplier * _SQUISH_2D,
157
- dy: -ysb - multiplier * _SQUISH_2D,
156
+ dx: -xsb - multiplier * SQUISH_2D,
157
+ dy: -ysb - multiplier * SQUISH_2D,
158
158
  xsb,
159
159
  ysb,
160
160
  };