@@ -59,7 +59,10 @@ const grad4 = new Float32Array([0, 1, 1, 1, 0, 1, 1, -1, 0, 1, -1, 1, 0, 1, -1,
5959 1 , 1 , 1 , 0 , 1 , 1 , - 1 , 0 , 1 , - 1 , 1 , 0 , 1 , - 1 , - 1 , 0 ,
6060 - 1 , 1 , 1 , 0 , - 1 , 1 , - 1 , 0 , - 1 , - 1 , 1 , 0 , - 1 , - 1 , - 1 , 0 ] ) ;
6161
62- type RandomFn = ( ) => number ;
62+ /**
63+ * A random() function, must return a numer in the interval [0,1), just like Math.random().
64+ */
65+ export type RandomFn = ( ) => number ;
6366
6467/** Deterministic simplex noise generator suitable for 2D, 3D and 4D spaces. */
6568export class SimplexNoise {
@@ -68,7 +71,7 @@ export class SimplexNoise {
6871 private permMod12 : Uint8Array ;
6972 /**
7073 * Creates a new `SimplexNoise` instance.
71- * This involves some setup costs so should preferably only be called once .
74+ * This involves some setup. You can save a few cpu cycles by reusing the same instance .
7275 * @param randomOrSeed A random number generator or a seed (string|number).
7376 * Defaults to Math.random (random irreproducible initialization).
7477 */
@@ -83,6 +86,12 @@ export class SimplexNoise {
8386 }
8487 }
8588
89+ /**
90+ * Samples the noise field in 2 dimensions
91+ * @param x
92+ * @param y
93+ * @returns a number in the interval [-1, 1]
94+ */
8695 noise2D ( x : number , y : number ) : number {
8796 const permMod12 = this . permMod12 ;
8897 const perm = this . perm ;
@@ -142,7 +151,14 @@ export class SimplexNoise {
142151 // The result is scaled to return values in the interval [-1,1].
143152 return 70.0 * ( n0 + n1 + n2 ) ;
144153 }
145- // 3D simplex noise
154+
155+ /**
156+ * Samples the noise field in 3 dimensions
157+ * @param x
158+ * @param y
159+ * @param z
160+ * @returns a number in the interval [-1, 1]
161+ */
146162 noise3D ( x :number , y :number , z :number ) : number {
147163 const permMod12 = this . permMod12 ;
148164 const perm = this . perm ;
@@ -265,7 +281,14 @@ export class SimplexNoise {
265281 // The result is scaled to stay just inside [-1,1]
266282 return 32.0 * ( n0 + n1 + n2 + n3 ) ;
267283 }
268- // 4D simplex noise, better simplex rank ordering method 2012-03-09
284+
285+ /**
286+ * Samples the noise field in 4 dimensions
287+ * @param x
288+ * @param y
289+ * @param z
290+ * @returns a number in the interval [-1, 1]
291+ */
269292 noise4D ( x :number , y :number , z :number , w :number ) : number {
270293 const perm = this . perm ;
271294
@@ -395,6 +418,9 @@ export class SimplexNoise {
395418export default SimplexNoise ;
396419
397420/**
421+ * Builds a random permutation table.
422+ * This is exported only for (internal) testing purposes.
423+ * Do not rely on this export.
398424 * @private
399425 */
400426export function buildPermutationTable ( random : RandomFn ) : Uint8Array {
0 commit comments