flocc 0.5.18 → 0.5.21

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,9 +1,15 @@
1
1
  /**
2
2
  * Given a mean and standard deviation,
3
3
  * returns a value from a normal/Gaussian distribution.
4
- * @param {number} mean
5
- * @param {number} sd
6
- * @returns {number}
4
+ *
5
+ * ```js
6
+ * // returns values mostly between 5 and 15 (but sometimes lower or higher)
7
+ * gaussian(10, 5);
8
+ *
9
+ * // no parameters defaults to mean = 0, std. dev. = 1
10
+ * gaussian(); // mostly values between -1 and 1
11
+ * ```
12
+ *
7
13
  * @since 0.0.8
8
14
  */
9
15
  export default function gaussian(mean?: number, sd?: number): number;
@@ -1,4 +1,12 @@
1
1
  /**
2
+ * Finds the {@link https://en.wikipedia.org/wiki/Greatest_common_divisor | greatest common divisor} of `a` and `b`.
3
+ *
4
+ * ```js
5
+ * gcd(7, 13); // returns 1
6
+ * gcd(9, 15); // returns 3
7
+ * gcd(12, 24); // returns 12
8
+ * ```
9
+ *
2
10
  * @since 0.4.5
3
11
  */
4
12
  export default function gcd(a: number, b: number): number;
@@ -2,7 +2,7 @@
2
2
  * Copies the values of `source` to `arr`
3
3
  * or to a new Array.
4
4
  *
5
- * @private
5
+ * @hidden
6
6
  * @param {Array} source The Array to copy values from.
7
7
  * @param {Array} [arr=[]] The Array to copy values to.
8
8
  * @returns {Array}
@@ -1,8 +1,17 @@
1
1
  /**
2
- * Linearly interpolate between two values.
3
- * @param x {number} - The first value.
4
- * @param y {number} - The second value.
5
- * @param t {number} - The amount by which to interpolate (0 returns x, 1 returns y).
2
+ * Linearly interpolates between `x` and `y`. The third parameter `t` (usually
3
+ * a value between `0` and `1`) is the amount by which to interpolate — a value of `0`
4
+ * returns the `x` value and `1` returns the `y` value.
5
+ *
6
+ * ```js
7
+ * lerp(5, 10, 0.5); // returns 7.5
8
+ * lerp(0, 100, 0.1); // returns 10
9
+ * lerp(22, 79, 1); // returns 79
10
+ * ```
11
+ *
12
+ * @param x The first value.
13
+ * @param y The second value.
14
+ * @param t The amount by which to interpolate (0 returns x, 1 returns y).
6
15
  * @since 0.2.4
7
16
  */
8
17
  export default function lerp(x: number, y: number, t: number): number;
@@ -1,13 +1,21 @@
1
1
  /// <reference path="../src/types/Point.d.ts" />
2
2
  import { Agent } from "../agents/Agent";
3
3
  /**
4
- * Finds the Manhattan distance between `p1` and `p2`.
5
- * The inputs may be plain objects
6
- * with `x`, `y`, and/or `z` keys, or Agent-like objects who have
7
- * `x`, `y`, and/or `z` data.
8
- * @param {Point|Agent} p1
9
- * @param {Point|Agent} p2
10
- * @return {number} The Manhattan distance between p1 and p2.
4
+ * Finds the {@link https://en.wikipedia.org/wiki/Taxicab_geometry | Manhattan distance} between `p1` and `p2`.
5
+ *
6
+ * The inputs may be plain objects with `x`, `y`, and/or `z` keys, {@linkcode Vector}s,
7
+ * or {@linkcode Agent}s with `x`, `y`, and/or `z` data.
8
+ *
9
+ * ```js
10
+ * const a1 = new Agent();
11
+ * const a2 = new Agent({ x: 3, y: 4 });
12
+ * manhattanDistance(a1, a2); // returns 7 (defaults to x = 0 and y = 0 for a1)
13
+ *
14
+ * const p1 = { x: 3, y: 2 };
15
+ * const p2 = { x: 0, y: 4 };
16
+ * manhattanDistance(p1, p2); // returns 5
17
+ * ```
18
+ *
11
19
  * @since 0.0.12
12
20
  */
13
21
  export default function manhattanDistance(p1: Point | Agent, p2: Point | Agent): number;
@@ -1,4 +1,13 @@
1
1
  /**
2
+ * Return the maximum value from an array of numbers.
3
+ *
4
+ * ```js
5
+ * max([1, 2, 3]); // returns 3
6
+ * max([10]); // returns 10
7
+ *
8
+ * max([]); // returns null for empty arrays
9
+ * ```
10
+ *
2
11
  * @since 0.2.0
3
12
  */
4
13
  export default function max(arr: Array<number>): number;
@@ -1,7 +1,13 @@
1
1
  /**
2
- * Find the mean value of an Array of numbers.
3
- * @param {Array<number>} arr
4
- * @returns {number}
2
+ * Return the mean value from an array of numbers.
3
+ *
4
+ * ```js
5
+ * mean([1, 2, 3]); // returns 2
6
+ * mean([10]); // returns 10
7
+ *
8
+ * mean([]); // returns null for empty arrays
9
+ * ```
10
+ *
5
11
  * @since 0.0.16
6
12
  */
7
13
  declare function mean(arr: Array<number>): number;
@@ -1,6 +1,14 @@
1
1
  /**
2
- * Find the median value of an array of numbers. If there are an even number
3
- * of elements in the array, takes the mean of the two values closest to the median.
2
+ * Return the mean value from an array of numbers.
3
+ *
4
+ * ```js
5
+ * median([1, 2, 3]); // returns 2
6
+ * median([10]); // returns 10
7
+ * median([1, 2, 3, 4]); // returns 2.5 (the mean of the two median values)
8
+ *
9
+ * median([]); // returns null for empty arrays
10
+ * ```
11
+ *
4
12
  * @param {number[]} arr
5
13
  * @since 0.2.0
6
14
  */
@@ -1,4 +1,12 @@
1
1
  /**
2
+ * Return the minimum value from an array of numbers.
3
+ *
4
+ * ```js
5
+ * min([1, 2, 3]); // returns 1
6
+ * min([10]); // returns 10
7
+ *
8
+ * min([]); // returns null for empty arrays
9
+ * ```
2
10
  * @since 0.2.0
3
11
  */
4
12
  export default function min(arr: Array<number>): number;
@@ -4,6 +4,8 @@ interface SampleFunc {
4
4
  interface MultipleSampleFunc {
5
5
  <T>(array: T[], weights?: number[]): T[];
6
6
  }
7
+ export declare function isSampleFunc(f: Function): f is SampleFunc;
8
+ export declare function isMultipleSampleFunc(f: Function): f is MultipleSampleFunc;
7
9
  declare let sample: SampleFunc;
8
10
  export default sample;
9
11
  /**
package/dist/version.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ /**
2
+ * The current version of the Flocc library.
3
+ */
1
4
  declare const version: string;
2
5
  export default version;
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "flocc",
3
- "version": "0.5.18",
3
+ "version": "0.5.21",
4
4
  "description": "Agent-based modeling in JavaScript in the browser or server.",
5
5
  "main": "dist/flocc.js",
6
6
  "module": "dist/flocc.es.js",
7
7
  "typings": "dist/main.d.ts",
8
8
  "scripts": {
9
9
  "build": "rollup -c && node replace-version",
10
+ "docs": "typedoc src/main.ts --watch --out docs/$npm_package_version",
11
+ "docs-build": "typedoc src/main.ts --out docs/$npm_package_version",
12
+ "docs-redirect": "cat _redirects > docs/_redirects && sed -i \"s/{{ VERSION }}/$npm_package_version/g\" docs/_redirects",
10
13
  "watch": "rollup -cw",
11
14
  "dev": "concurrently 'npm run watch' 'node client/app.js' 'browser-sync start --watch dist/flocc.js'",
12
15
  "format": "prettier --write src",
@@ -18,7 +21,7 @@
18
21
  "devDependencies": {
19
22
  "@rollup/plugin-json": "^4.1.0",
20
23
  "@types/node": "^14.0.19",
21
- "browser-sync": "^2.26.13",
24
+ "browser-sync": "^2.26.14",
22
25
  "concurrently": "5.1.0",
23
26
  "ejs": "^3.0.2",
24
27
  "express": "^4.17.1",
@@ -30,7 +33,8 @@
30
33
  "puppeteer": "^2.1.1",
31
34
  "rollup": "2.1.0",
32
35
  "rollup-plugin-typescript2": "0.26.0",
33
- "typescript": "3.8.3",
36
+ "typedoc": "^0.20.28",
37
+ "typescript": "4.1.3",
34
38
  "yargs": "^15.3.1"
35
39
  },
36
40
  "files": [
@@ -1,5 +0,0 @@
1
- declare class Data {
2
- [key: string]: any;
3
- constructor();
4
- }
5
- export default Data;
@@ -1 +0,0 @@
1
- export default function torusNormalize(value: number, max: number): number;