Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/math

Package Overview
Dependencies
Maintainers
1
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/math - npm Package Compare versions

Comparing version 2.0.4 to 2.1.0

3

abs.d.ts

@@ -1,3 +0,4 @@

export declare const absDiff: (x: number, y: number) => number;
import type { FnN2 } from "@thi.ng/api";
export declare const absDiff: FnN2;
export declare const sign: (x: number, eps?: number) => 1 | 0 | -1;
//# sourceMappingURL=abs.d.ts.map

@@ -0,1 +1,2 @@

import type { FnN, FnN2, FnN3 } from "@thi.ng/api";
/**

@@ -20,4 +21,4 @@ * Returns vector of `[sin(theta)*n, cos(theta)*n]`.

*/
export declare const absTheta: (theta: number) => number;
export declare const absInnerAngle: (theta: number) => number;
export declare const absTheta: FnN;
export declare const absInnerAngle: FnN;
/**

@@ -30,3 +31,3 @@ * Returns smallest absolute angle difference between `a` and `b`.

*/
export declare const angleDist: (a: number, b: number) => number;
export declare const angleDist: FnN2;
/**

@@ -38,3 +39,3 @@ * Like `Math.atan2`, but always returns angle in [0 .. TAU) interval.

*/
export declare const atan2Abs: (y: number, x: number) => number;
export declare const atan2Abs: FnN2;
/**

@@ -45,3 +46,3 @@ * Returns quadrant ID (0-3) of given angle (in radians).

*/
export declare const quadrant: (theta: number) => number;
export declare const quadrant: FnN;
/**

@@ -52,3 +53,3 @@ * Converts angle to degrees.

*/
export declare const deg: (theta: number) => number;
export declare const deg: FnN;
/**

@@ -59,3 +60,3 @@ * Converts angle to radians.

*/
export declare const rad: (theta: number) => number;
export declare const rad: FnN;
/**

@@ -66,3 +67,3 @@ * Cosecant. Approaches `±Infinity` for `theta` near multiples of π.

*/
export declare const csc: (theta: number) => number;
export declare const csc: FnN;
/**

@@ -73,3 +74,3 @@ * Secant. Approaches `±Infinity` for `theta` near π/2 ± nπ

*/
export declare const sec: (theta: number) => number;
export declare const sec: FnN;
/**

@@ -80,3 +81,3 @@ * Cotangent. Approaches `±Infinity` for `theta` near multiples of π.

*/
export declare const cot: (theta: number) => number;
export declare const cot: FnN;
/**

@@ -90,3 +91,3 @@ * Law of Cosines. Takes length of two sides of a triangle and the inner

*/
export declare const loc: (a: number, b: number, gamma: number) => number;
export declare const loc: FnN3;
/**

@@ -97,3 +98,3 @@ * Approximates cos(xπ) for x in [-1,1]

*/
export declare const normCos: (x: number) => number;
export declare const normCos: FnN;
/**

@@ -107,3 +108,3 @@ * Fast cosine approximation using {@link normCos} (polynomial). Max. error

*/
export declare const fastCos: (theta: number) => number;
export declare const fastCos: FnN;
/**

@@ -114,3 +115,3 @@ * {@link fastCos}

*/
export declare const fastSin: (theta: number) => number;
export declare const fastSin: FnN;
//# sourceMappingURL=angle.d.ts.map

@@ -6,2 +6,13 @@ # Change Log

# [2.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.0.4...@thi.ng/math@2.1.0) (2020-09-13)
### Features
* **math:** add lens(), invCircular() interpolators ([56dce17](https://github.com/thi-ng/umbrella/commit/56dce1779ee314179771fa14f31d0f36e1ec6a12))
## [2.0.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.0.3...@thi.ng/math@2.0.4) (2020-08-28)

@@ -8,0 +19,0 @@

@@ -0,1 +1,2 @@

import type { FnU4 } from "@thi.ng/api";
import { Crossing } from "./api";

@@ -18,3 +19,3 @@ /**

*/
export declare const isCrossOver: (a1: number, a2: number, b1: number, b2: number) => boolean;
export declare const isCrossOver: FnU4<number, boolean>;
/**

@@ -36,3 +37,3 @@ * Returns true if line A rises up over B.

*/
export declare const isCrossUnder: (a1: number, a2: number, b1: number, b2: number) => boolean;
export declare const isCrossUnder: FnU4<number, boolean>;
/**

@@ -39,0 +40,0 @@ * Returns {@link Crossing} classifier indicating the relationship of line A

@@ -0,1 +1,2 @@

import type { FnU3 } from "@thi.ng/api";
/**

@@ -8,3 +9,3 @@ * Returns true if `b` is a local minima, i.e. iff a > b and b < c.

*/
export declare const isMinima: (a: number, b: number, c: number) => boolean;
export declare const isMinima: FnU3<number, boolean>;
/**

@@ -17,3 +18,3 @@ * Returns true if `b` is a local maxima, i.e. iff a < b and b > c.

*/
export declare const isMaxima: (a: number, b: number, c: number) => boolean;
export declare const isMaxima: FnU3<number, boolean>;
/**

@@ -20,0 +21,0 @@ * Returns index of the first local & internal minima found in given

@@ -0,1 +1,2 @@

import type { FnN3, FnN5 } from "@thi.ng/api";
/**

@@ -9,8 +10,8 @@ * Returns normalized value of `x` WRT to interval `a .. b`. If `a`

*/
export declare const norm: (x: number, a: number, b: number) => number;
export declare const fit: (x: number, a: number, b: number, c: number, d: number) => number;
export declare const fitClamped: (x: number, a: number, b: number, c: number, d: number) => number;
export declare const fit01: (x: number, a: number, b: number) => number;
export declare const fit10: (x: number, a: number, b: number) => number;
export declare const fit11: (x: number, a: number, b: number) => number;
export declare const norm: FnN3;
export declare const fit: FnN5;
export declare const fitClamped: FnN5;
export declare const fit01: FnN3;
export declare const fit10: FnN3;
export declare const fit11: FnN3;
//# sourceMappingURL=fit.d.ts.map

@@ -10,3 +10,3 @@ import { clamp01, clamp11 } from "./interval";

*/
export const norm = (x, a, b) => b !== a ? (x - a) / (b - a) : 0;
export const norm = (x, a, b) => (b !== a ? (x - a) / (b - a) : 0);
export const fit = (x, a, b, c, d) => c + (d - c) * norm(x, a, b);

@@ -13,0 +13,0 @@ export const fitClamped = (x, a, b, c, d) => c + (d - c) * clamp01(norm(x, a, b));

@@ -1,63 +0,64 @@

export declare const signExtend8: (a: number) => number;
export declare const signExtend16: (a: number) => number;
export declare const addi8: (a: number, b: number) => number;
export declare const divi8: (a: number, b: number) => number;
export declare const muli8: (a: number, b: number) => number;
export declare const subi8: (a: number, b: number) => number;
export declare const andi8: (a: number, b: number) => number;
export declare const ori8: (a: number, b: number) => number;
export declare const xori8: (a: number, b: number) => number;
export declare const noti8: (a: number) => number;
export declare const lshifti8: (a: number, b: number) => number;
export declare const rshifti8: (a: number, b: number) => number;
export declare const addi16: (a: number, b: number) => number;
export declare const divi16: (a: number, b: number) => number;
export declare const muli16: (a: number, b: number) => number;
export declare const subi16: (a: number, b: number) => number;
export declare const andi16: (a: number, b: number) => number;
export declare const ori16: (a: number, b: number) => number;
export declare const xori16: (a: number, b: number) => number;
export declare const noti16: (a: number) => number;
export declare const lshifti16: (a: number, b: number) => number;
export declare const rshifti16: (a: number, b: number) => number;
export declare const addi32: (a: number, b: number) => number;
export declare const divi32: (a: number, b: number) => number;
export declare const muli32: (a: number, b: number) => number;
export declare const subi32: (a: number, b: number) => number;
export declare const andi32: (a: number, b: number) => number;
export declare const ori32: (a: number, b: number) => number;
export declare const xori32: (a: number, b: number) => number;
export declare const lshifti32: (a: number, b: number) => number;
export declare const rshifti32: (a: number, b: number) => number;
export declare const noti32: (a: number) => number;
export declare const addu8: (a: number, b: number) => number;
export declare const divu8: (a: number, b: number) => number;
export declare const mulu8: (a: number, b: number) => number;
export declare const subu8: (a: number, b: number) => number;
export declare const andu8: (a: number, b: number) => number;
export declare const oru8: (a: number, b: number) => number;
export declare const xoru8: (a: number, b: number) => number;
export declare const notu8: (a: number) => number;
export declare const lshiftu8: (a: number, b: number) => number;
export declare const rshiftu8: (a: number, b: number) => number;
export declare const addu16: (a: number, b: number) => number;
export declare const divu16: (a: number, b: number) => number;
export declare const mulu16: (a: number, b: number) => number;
export declare const subu16: (a: number, b: number) => number;
export declare const andu16: (a: number, b: number) => number;
export declare const oru16: (a: number, b: number) => number;
export declare const xoru16: (a: number, b: number) => number;
export declare const notu16: (a: number) => number;
export declare const lshiftu16: (a: number, b: number) => number;
export declare const rshiftu16: (a: number, b: number) => number;
export declare const addu32: (a: number, b: number) => number;
export declare const divu32: (a: number, b: number) => number;
export declare const mulu32: (a: number, b: number) => number;
export declare const subu32: (a: number, b: number) => number;
export declare const andu32: (a: number, b: number) => number;
export declare const oru32: (a: number, b: number) => number;
export declare const xoru32: (a: number, b: number) => number;
export declare const notu32: (a: number) => number;
export declare const lshiftu32: (a: number, b: number) => number;
export declare const rshiftu32: (a: number, b: number) => number;
import type { FnN, FnN2 } from "@thi.ng/api";
export declare const signExtend8: FnN;
export declare const signExtend16: FnN;
export declare const addi8: FnN2;
export declare const divi8: FnN2;
export declare const muli8: FnN2;
export declare const subi8: FnN2;
export declare const andi8: FnN2;
export declare const ori8: FnN2;
export declare const xori8: FnN2;
export declare const noti8: FnN;
export declare const lshifti8: FnN2;
export declare const rshifti8: FnN2;
export declare const addi16: FnN2;
export declare const divi16: FnN2;
export declare const muli16: FnN2;
export declare const subi16: FnN2;
export declare const andi16: FnN2;
export declare const ori16: FnN2;
export declare const xori16: FnN2;
export declare const noti16: FnN;
export declare const lshifti16: FnN2;
export declare const rshifti16: FnN2;
export declare const addi32: FnN2;
export declare const divi32: FnN2;
export declare const muli32: FnN2;
export declare const subi32: FnN2;
export declare const andi32: FnN2;
export declare const ori32: FnN2;
export declare const xori32: FnN2;
export declare const lshifti32: FnN2;
export declare const rshifti32: FnN2;
export declare const noti32: FnN;
export declare const addu8: FnN2;
export declare const divu8: FnN2;
export declare const mulu8: FnN2;
export declare const subu8: FnN2;
export declare const andu8: FnN2;
export declare const oru8: FnN2;
export declare const xoru8: FnN2;
export declare const notu8: FnN;
export declare const lshiftu8: FnN2;
export declare const rshiftu8: FnN2;
export declare const addu16: FnN2;
export declare const divu16: FnN2;
export declare const mulu16: FnN2;
export declare const subu16: FnN2;
export declare const andu16: FnN2;
export declare const oru16: FnN2;
export declare const xoru16: FnN2;
export declare const notu16: FnN;
export declare const lshiftu16: FnN2;
export declare const rshiftu16: FnN2;
export declare const addu32: FnN2;
export declare const divu32: FnN2;
export declare const mulu32: FnN2;
export declare const subu32: FnN2;
export declare const andu32: FnN2;
export declare const oru32: FnN2;
export declare const xoru32: FnN2;
export declare const notu32: FnN;
export declare const lshiftu32: FnN2;
export declare const rshiftu32: FnN2;
//# sourceMappingURL=int.d.ts.map

@@ -13,5 +13,3 @@ const M8 = 0xff;

export const noti8 = (a) => signExtend8(~a);
// prettier-ignore
export const lshifti8 = (a, b) => signExtend8((a | 0) << (b | 0));
// prettier-ignore
export const rshifti8 = (a, b) => signExtend8((a | 0) >> (b | 0));

@@ -26,5 +24,3 @@ export const addi16 = (a, b) => signExtend16((a | 0) + (b | 0));

export const noti16 = (a) => signExtend16(~a);
// prettier-ignore
export const lshifti16 = (a, b) => signExtend16((a | 0) << (b | 0));
// prettier-ignore
export const rshifti16 = (a, b) => signExtend16((a | 0) >> (b | 0));

@@ -41,15 +37,8 @@ export const addi32 = (a, b) => ((a | 0) + (b | 0)) | 0;

export const noti32 = (a) => ~a;
// prettier-ignore
export const addu8 = (a, b) => ((a & M8) + (b & M8)) & M8;
// prettier-ignore
export const divu8 = (a, b) => ((a & M8) / (b & M8)) & M8;
// prettier-ignore
export const mulu8 = (a, b) => ((a & M8) * (b & M8)) & M8;
// prettier-ignore
export const subu8 = (a, b) => ((a & M8) - (b & M8)) & M8;
// prettier-ignore
export const andu8 = (a, b) => ((a & M8) & (b & M8)) & M8;
// prettier-ignore
export const andu8 = (a, b) => a & M8 & (b & M8) & M8;
export const oru8 = (a, b) => ((a & M8) | (b & M8)) & M8;
// prettier-ignore
export const xoru8 = (a, b) => ((a & M8) ^ (b & M8)) & M8;

@@ -59,20 +48,11 @@ export const notu8 = (a) => ~a & M8;

export const rshiftu8 = (a, b) => ((a & M8) >>> (b & M8)) & M8;
// prettier-ignore
export const addu16 = (a, b) => ((a & M16) + (b & M16)) & M16;
// prettier-ignore
export const divu16 = (a, b) => ((a & M16) / (b & M16)) & M16;
// prettier-ignore
export const mulu16 = (a, b) => ((a & M16) * (b & M16)) & M16;
// prettier-ignore
export const subu16 = (a, b) => ((a & M16) - (b & M16)) & M16;
// prettier-ignore
export const andu16 = (a, b) => ((a & M16) & (b & M16)) & M16;
// prettier-ignore
export const andu16 = (a, b) => a & M16 & (b & M16) & M16;
export const oru16 = (a, b) => ((a & M16) | (b & M16)) & M16;
// prettier-ignore
export const xoru16 = (a, b) => ((a & M16) ^ (b & M16)) & M16;
export const notu16 = (a) => ~a & M16;
// prettier-ignore
export const lshiftu16 = (a, b) => ((a & M16) << (b & M16)) & M16;
// prettier-ignore
export const rshiftu16 = (a, b) => ((a & M16) >>> (b & M16)) & M16;

@@ -87,5 +67,3 @@ export const addu32 = (a, b) => ((a >>> 0) + (b >>> 0)) >>> 0;

export const notu32 = (a) => ~a >>> 0;
// prettier-ignore
export const lshiftu32 = (a, b) => ((a >>> 0) << (b >>> 0)) >>> 0;
// prettier-ignore
export const rshiftu32 = (a, b) => ((a >>> 0) >>> (b >>> 0)) >>> 0;

@@ -0,1 +1,2 @@

import type { FnN, FnN2, FnN3, FnN4, FnU3 } from "@thi.ng/api";
/**

@@ -8,3 +9,3 @@ * Clamps value `x` to given closed interval.

*/
export declare const clamp: (x: number, min: number, max: number) => number;
export declare const clamp: FnN3;
/**

@@ -15,3 +16,3 @@ * Clamps value `x` to closed [0 .. 1] interval.

*/
export declare const clamp01: (x: number) => number;
export declare const clamp01: FnN;
/**

@@ -22,3 +23,3 @@ * Clamps value `x` to closed [-1 .. 1] interval.

*/
export declare const clamp11: (x: number) => number;
export declare const clamp11: FnN;
/**

@@ -29,3 +30,3 @@ * Clamps value `x` to closed [0 .. 0.5] interval.

*/
export declare const clamp05: (x: number) => number;
export declare const clamp05: FnN;
/**

@@ -39,3 +40,3 @@ * Folds `x` back inside closed [min..max] interval. Also see

*/
export declare const wrap: (x: number, min: number, max: number) => number;
export declare const wrap: FnN3;
/**

@@ -50,3 +51,3 @@ * Like {@link wrap}, but optimized for cases where `x` is guaranteed to

*/
export declare const wrapOnce: (x: number, min: number, max: number) => number;
export declare const wrapOnce: FnN3;
/**

@@ -57,3 +58,3 @@ * Similar to {@link wrapOnce} for [0..1] interval.

*/
export declare const wrap01: (x: number) => number;
export declare const wrap01: FnN;
/**

@@ -64,9 +65,9 @@ * Similar to {@link wrapOnce} for [-1..1] interval.

*/
export declare const wrap11: (x: number) => number;
export declare const min2id: (a: number, b: number) => 1 | 0;
export declare const min3id: (a: number, b: number, c: number) => 1 | 2 | 0;
export declare const min4id: (a: number, b: number, c: number, d: number) => 1 | 2 | 3 | 0;
export declare const max2id: (a: number, b: number) => 1 | 0;
export declare const max3id: (a: number, b: number, c: number) => 1 | 2 | 0;
export declare const max4id: (a: number, b: number, c: number, d: number) => 1 | 2 | 3 | 0;
export declare const wrap11: FnN;
export declare const min2id: FnN2;
export declare const min3id: FnN3;
export declare const min4id: FnN4;
export declare const max2id: FnN2;
export declare const max3id: FnN3;
export declare const max4id: FnN4;
/**

@@ -78,3 +79,3 @@ * Returns the non-zero minimum value of the given `a`, `b` args.

*/
export declare const minNonZero2: (a: number, b: number) => number;
export declare const minNonZero2: FnN2;
/**

@@ -87,3 +88,3 @@ * Returns the non-zero minimum value of the given `a`, `b`, `c` args.

*/
export declare const minNonZero3: (a: number, b: number, c: number) => number;
export declare const minNonZero3: FnN3;
/**

@@ -96,3 +97,3 @@ * See `smax()`.

*/
export declare const smin: (a: number, b: number, k: number) => number;
export declare const smin: FnN3;
/**

@@ -109,3 +110,3 @@ * Smooth maximum. Note: Result values will be slightly larger than max

*/
export declare const smax: (a: number, b: number, k: number) => number;
export declare const smax: FnN3;
/**

@@ -119,5 +120,5 @@ * Same as `smin(smax(x, min, k), max, k)`.

*/
export declare const sclamp: (x: number, min: number, max: number, k: number) => number;
export declare const absMin: (a: number, b: number) => number;
export declare const absMax: (a: number, b: number) => number;
export declare const sclamp: FnN4;
export declare const absMin: FnN2;
export declare const absMax: FnN2;
/**

@@ -135,3 +136,3 @@ * If `abs(x) > abs(e)`, recursively mirrors `x` back into `[-e .. +e]`

*/
export declare const foldback: (e: number, x: number) => number;
export declare const foldback: FnN2;
/**

@@ -144,3 +145,3 @@ * Returns true iff `x` is in closed interval `[min .. max]`

*/
export declare const inRange: (x: number, min: number, max: number) => boolean;
export declare const inRange: FnU3<number, boolean>;
/**

@@ -153,3 +154,3 @@ * Returns true iff `x` is in open interval `(min .. max)`

*/
export declare const inOpenRange: (x: number, min: number, max: number) => boolean;
export declare const inOpenRange: FnU3<number, boolean>;
//# sourceMappingURL=interval.d.ts.map

@@ -8,3 +8,3 @@ /**

*/
export const clamp = (x, min, max) => x < min ? min : x > max ? max : x;
export const clamp = (x, min, max) => (x < min ? min : x > max ? max : x);
/**

@@ -157,4 +157,4 @@ * Clamps value `x` to closed [0 .. 1] interval.

export const sclamp = (x, min, max, k) => smin(smax(x, min, k), max, k);
export const absMin = (a, b) => Math.abs(a) < Math.abs(b) ? a : b;
export const absMax = (a, b) => Math.abs(a) > Math.abs(b) ? a : b;
export const absMin = (a, b) => (Math.abs(a) < Math.abs(b) ? a : b);
export const absMax = (a, b) => (Math.abs(a) > Math.abs(b) ? a : b);
/**

@@ -161,0 +161,0 @@ * If `abs(x) > abs(e)`, recursively mirrors `x` back into `[-e .. +e]`

@@ -126,3 +126,3 @@ 'use strict';

const clamp = (x, min, max) => x < min ? min : x > max ? max : x;
const clamp = (x, min, max) => (x < min ? min : x > max ? max : x);
const clamp01 = (x) => (x < 0 ? 0 : x > 1 ? 1 : x);

@@ -194,4 +194,4 @@ const clamp11 = (x) => (x < -1 ? -1 : x > 1 ? 1 : x);

const sclamp = (x, min, max, k) => smin(smax(x, min, k), max, k);
const absMin = (a, b) => Math.abs(a) < Math.abs(b) ? a : b;
const absMax = (a, b) => Math.abs(a) > Math.abs(b) ? a : b;
const absMin = (a, b) => (Math.abs(a) < Math.abs(b) ? a : b);
const absMax = (a, b) => (Math.abs(a) > Math.abs(b) ? a : b);
const foldback = (e, x) => x < -e || x > e ? Math.abs(Math.abs((x - e) % (4 * e)) - 2 * e) - e : x;

@@ -201,3 +201,3 @@ const inRange = (x, min, max) => x >= min && x <= max;

const norm = (x, a, b) => b !== a ? (x - a) / (b - a) : 0;
const norm = (x, a, b) => (b !== a ? (x - a) / (b - a) : 0);
const fit = (x, a, b, c, d) => c + (d - c) * norm(x, a, b);

@@ -247,3 +247,3 @@ const fitClamped = (x, a, b, c, d) => c + (d - c) * clamp01(norm(x, a, b));

const subu8 = (a, b) => ((a & M8) - (b & M8)) & M8;
const andu8 = (a, b) => ((a & M8) & (b & M8)) & M8;
const andu8 = (a, b) => a & M8 & (b & M8) & M8;
const oru8 = (a, b) => ((a & M8) | (b & M8)) & M8;

@@ -258,3 +258,3 @@ const xoru8 = (a, b) => ((a & M8) ^ (b & M8)) & M8;

const subu16 = (a, b) => ((a & M16) - (b & M16)) & M16;
const andu16 = (a, b) => ((a & M16) & (b & M16)) & M16;
const andu16 = (a, b) => a & M16 & (b & M16) & M16;
const oru16 = (a, b) => ((a & M16) | (b & M16)) & M16;

@@ -329,2 +329,9 @@ const xoru16 = (a, b) => ((a & M16) ^ (b & M16)) & M16;

};
const invCircular = (t) => 1 - circular(1 - t);
const lens = (pos, strength, t) => {
const impl = strength > 0 ? invCircular : circular;
const tp = 1 - pos;
const tl = t <= pos ? impl(t / pos) * pos : 1 - impl((1 - t) / tp) * tp;
return mix(t, tl, Math.abs(strength));
};
const cosine = (t) => 1 - (Math.cos(t * PI) * 0.5 + 0.5);

@@ -386,3 +393,3 @@ const decimated = (n, t) => Math.floor(t * n) / n;

const derivative = (f, eps = EPS) => (x) => (f(x + eps) - f(x)) / eps;
const solveLinear = (a, b) => -b / a;
const solveLinear = (a, b) => safeDiv(-b, a);
const solveQuadratic = (a, b, c, eps = 1e-9) => {

@@ -522,2 +529,3 @@ const d = 2 * a;

exports.inRange = inRange;
exports.invCircular = invCircular;
exports.isCrossOver = isCrossOver;

@@ -527,2 +535,3 @@ exports.isCrossUnder = isCrossUnder;

exports.isMinima = isMinima;
exports.lens = lens;
exports.loc = loc;

@@ -529,0 +538,0 @@ exports.lshifti16 = lshifti16;

@@ -1,1 +0,1 @@

!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i(((t="undefined"!=typeof globalThis?globalThis:t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.math={}))}(this,(function(t){"use strict";const i=Math.PI,a=2*i,n=i/2,s=i/3,r=i/4,e=i/6,o=1/i,h=1/a,u=1/n,c=i/180,M=180/i,d=(1+Math.sqrt(5))/2,f=Math.SQRT2,l=Math.sqrt(3),m=f/2,b=l/2;let p=1e-6;var x;(x=t.Crossing||(t.Crossing={}))[x.EQUAL=0]="EQUAL",x[x.FLAT=1]="FLAT",x[x.UNDER=2]="UNDER",x[x.OVER=3]="OVER",x[x.OTHER=4]="OTHER";const g=t=>(t%=a)<0?a+t:t,R=t=>(t=Math.abs(t))>i?a-t:t,T=t=>{const i=t*t;return.99940307+i*(.03679168*i-.49558072)},I=t=>{switch((t%=a)<0&&(t=-t),t*u|0){case 0:return T(t);case 1:return-T(i-t);case 2:return-T(t-i);default:return T(a-t)}},E=Math.abs,C=Math.max,D=(t,i,a=p)=>E(t-i)<=a,v=D,A=(t,i,a,n)=>t<a&&i>n,q=(t,i,a,n)=>t>a&&i<n,H=(t,i,a)=>t>i&&i<a,P=(t,i,a)=>t<i&&i>a,S=(t,i,a=0,n=i.length)=>{n--;for(let s=a+1;s<n;s++)if(t(i[s-1],i[s],i[s+1]))return s;return-1},_=(t,i=0,a=t.length)=>S(H,t,i,a);function*w(t,i,a=0,n=i.length){for(;a<n;){const s=t(i,a,n);if(s<0)return;yield s,a=s+1}}const O=t=>t<0?0:t>1?1:t,Q=t=>t<-1?-1:t>1?1:t,U=(t,i)=>0!==t?0!==i?Math.min(t,i):t:i,L=(t,i,a)=>y(t,i,-a),y=(t,i,a)=>{const n=Math.exp(t*a),s=Math.exp(i*a);return(t*n+i*s)/(n+s)},N=(t,i,a)=>a!==i?(t-i)/(a-i):0,F=255,V=65535,j=t=>128&(t&=F)?t|~F:t,G=t=>32768&(t&=V)?t|~V:t,X=(t,i,a,n=16,s=8,r=0,e=1,o=p)=>{if(s<=0)return(r+e)/2;const h=(e-r)/n;let u=r,c=1/0;for(let s=0;s<=n;s++){const n=r+s*h,e=i(a,t(n));if(e<c){if(e<=o)return n;c=e,u=n}}return X(t,i,a,n,s-1,Math.max(u-h,0),Math.min(u+h,1))},Z=(t,i,a)=>t+(i-t)*a,k=t=>t-Math.floor(t);t.DEG2RAD=c,t.EPS=p,t.HALF_PI=n,t.INV_HALF_PI=u,t.INV_PI=o,t.INV_TAU=h,t.PHI=d,t.PI=i,t.QUARTER_PI=r,t.RAD2DEG=M,t.SIXTH=1/6,t.SIXTH_PI=e,t.SQRT2=f,t.SQRT2_2=m,t.SQRT2_3=b,t.SQRT3=l,t.TAU=a,t.THIRD=1/3,t.THIRD_PI=s,t.TWO_THIRD=2/3,t.absDiff=(t,i)=>Math.abs(t-i),t.absInnerAngle=R,t.absMax=(t,i)=>Math.abs(t)>Math.abs(i)?t:i,t.absMin=(t,i)=>Math.abs(t)<Math.abs(i)?t:i,t.absTheta=g,t.addi16=(t,i)=>G((0|t)+(0|i)),t.addi32=(t,i)=>(0|t)+(0|i)|0,t.addi8=(t,i)=>j((0|t)+(0|i)),t.addu16=(t,i)=>(t&V)+(i&V)&V,t.addu32=(t,i)=>(t>>>0)+(i>>>0)>>>0,t.addu8=(t,i)=>(t&F)+(i&F)&F,t.andi16=(t,i)=>G((0|t)&(0|i)),t.andi32=(t,i)=>(0|t)&(0|i),t.andi8=(t,i)=>j((0|t)&(0|i)),t.andu16=(t,i)=>t&V&i&V&V,t.andu32=(t,i)=>(t>>>0&i>>>0)>>>0,t.andu8=(t,i)=>t&F&i&F&F,t.angleDist=(t,i)=>R(g(i%a-t%a)),t.atan2Abs=(t,i)=>g(Math.atan2(t,i)),t.bounce=(t,i,a)=>{const s=a*t;return 1-i*Math.sin(s)/s*Math.cos(a*n)},t.circular=t=>(t=1-t,Math.sqrt(1-t*t)),t.clamp=(t,i,a)=>t<i?i:t>a?a:t,t.clamp01=O,t.clamp05=t=>t<0?0:t>.5?.5:t,t.clamp11=Q,t.classifyCrossing=(i,a,n,s,r=p)=>A(i,a,n,s)?t.Crossing.OVER:q(i,a,n,s)?t.Crossing.UNDER:D(i,n,r)&&D(a,s,r)?D(i,s,r)?t.Crossing.FLAT:t.Crossing.EQUAL:t.Crossing.OTHER,t.cosine=t=>1-(.5*Math.cos(t*i)+.5),t.cossin=(t,i=1)=>[Math.cos(t)*i,Math.sin(t)*i],t.cot=t=>1/Math.tan(t),t.csc=t=>1/Math.sin(t),t.cubicPulse=(t,i,a)=>(a=Math.abs(a-i))>t?0:1-(a/=t)*a*(3-2*a),t.decimated=(t,i)=>Math.floor(i*t)/t,t.deg=t=>t*M,t.derivative=(t,i=p)=>a=>(t(a+i)-t(a))/i,t.divi16=(t,i)=>G((0|t)/(0|i)),t.divi32=(t,i)=>(0|t)/(0|i)|0,t.divi8=(t,i)=>j((0|t)/(0|i)),t.divu16=(t,i)=>(t&V)/(i&V)&V,t.divu32=(t,i)=>(t>>>0)/(i>>>0)>>>0,t.divu8=(t,i)=>(t&F)/(i&F)&F,t.ease=(t,i)=>Math.pow(i,t),t.eqDelta=D,t.eqDeltaFixed=v,t.eqDeltaScaled=(t,i,a=p)=>E(t-i)<=a*C(1,E(t),E(i)),t.expFactor=(t,i,a)=>(i/t)**(1/a),t.expStep=(t,i,a)=>1-Math.exp(-t*Math.pow(a,i)),t.fastCos=I,t.fastSin=t=>I(n-t),t.fit=(t,i,a,n,s)=>n+(s-n)*N(t,i,a),t.fit01=(t,i,a)=>i+(a-i)*O(t),t.fit10=(t,i,a)=>a+(i-a)*O(t),t.fit11=(t,i,a)=>i+(a-i)*(.5+.5*Q(t)),t.fitClamped=(t,i,a,n,s)=>n+(s-n)*O(N(t,i,a)),t.fmod=(t,i)=>t-i*Math.floor(t/i),t.foldback=(t,i)=>i<-t||i>t?Math.abs(Math.abs((i-t)%(4*t))-2*t)-t:i,t.fract=k,t.gain=(t,i)=>i<.5?.5*Math.pow(2*i,t):1-.5*Math.pow(2-2*i,t),t.impulse=(t,i)=>{const a=t*i;return a*Math.exp(1-a)},t.inOpenRange=(t,i,a)=>t>i&&t<a,t.inRange=(t,i,a)=>t>=i&&t<=a,t.isCrossOver=A,t.isCrossUnder=q,t.isMaxima=P,t.isMinima=H,t.loc=(t,i,a)=>Math.sqrt(t*t+i*i-2*t*i*Math.cos(a)),t.lshifti16=(t,i)=>G((0|t)<<(0|i)),t.lshifti32=(t,i)=>(0|t)<<(0|i),t.lshifti8=(t,i)=>j((0|t)<<(0|i)),t.lshiftu16=(t,i)=>(t&V)<<(i&V)&V,t.lshiftu32=(t,i)=>t>>>0<<(i>>>0)>>>0,t.lshiftu8=(t,i)=>(t&F)<<(i&F)&F,t.max2id=(t,i)=>t>=i?0:1,t.max3id=(t,i,a)=>t>=i?t>=a?0:2:i>=a?1:2,t.max4id=(t,i,a,n)=>t>=i?t>=a?t>=n?0:3:a>=n?2:3:i>=a?i>=n?1:3:a>=n?2:3,t.maximaIndex=(t,i=0,a=t.length)=>S(P,t,i,a),t.maximaIndices=(t,i=0,a=t.length)=>w(_,t,i,a),t.min2id=(t,i)=>t<=i?0:1,t.min3id=(t,i,a)=>t<=i?t<=a?0:2:i<=a?1:2,t.min4id=(t,i,a,n)=>t<=i?t<=a?t<=n?0:3:a<=n?2:3:i<=a?i<=n?1:3:a<=n?2:3,t.minError=X,t.minNonZero2=U,t.minNonZero3=(t,i,a)=>U(U(t,i),a),t.minimaIndex=_,t.minimaIndices=(t,i=0,a=t.length)=>w(_,t,i,a),t.mix=Z,t.mixBilinear=(t,i,a,n,s,r)=>Z(Z(t,i,s),Z(a,n,s),r),t.mixCubic=(t,i,a,n,s)=>{const r=s*s,e=1-s,o=e*e;return t*o*e+3*i*o*s+3*a*r*e+n*r*s},t.mixCubicHermite=(t,i,a,n,s)=>{const r=s-1,e=s*s,o=r*r;return(1+2*s)*o*t+s*o*i+e*(3-2*s)*a+e*r*n},t.mixHermite=(t,i,a,n,s)=>{const r=.5*(a-t),e=1.5*(i-a)+.5*(n-t);return((e*s+t-i+r-e)*s+r)*s+i},t.mixQuadratic=(t,i,a,n)=>{const s=1-n;return t*s*s+2*i*s*n+a*n*n},t.muli16=(t,i)=>G((0|t)*(0|i)),t.muli32=(t,i)=>(0|t)*(0|i)|0,t.muli8=(t,i)=>j((0|t)*(0|i)),t.mulu16=(t,i)=>(t&V)*(i&V)&V,t.mulu32=(t,i)=>(t>>>0)*(i>>>0)>>>0,t.mulu8=(t,i)=>(t&F)*(i&F)&F,t.norm=N,t.normCos=t=>{const i=t*t;return 1+i*(2*i-4)},t.noti16=t=>G(~t),t.noti32=t=>~t,t.noti8=t=>j(~t),t.notu16=t=>~t&V,t.notu32=t=>~t>>>0,t.notu8=t=>~t&F,t.ori16=(t,i)=>G(0|t|i),t.ori32=(t,i)=>0|t|i,t.ori8=(t,i)=>j(0|t|i),t.oru16=(t,i)=>(t&V|i&V)&V,t.oru32=(t,i)=>(t>>>0|i>>>0)>>>0,t.oru8=(t,i)=>(t&F|i&F)&F,t.parabola=(t,i)=>Math.pow(4*i*(1-i),t),t.quadrant=t=>g(t)*u|0,t.rad=t=>t*c,t.roundEps=(t,i=p)=>{const a=k(t);return a<=i||a>=1-i?Math.round(t):t},t.roundTo=(t,i=1)=>Math.round(t/i)*i,t.rshifti16=(t,i)=>G((0|t)>>(0|i)),t.rshifti32=(t,i)=>(0|t)>>(0|i),t.rshifti8=(t,i)=>j((0|t)>>(0|i)),t.rshiftu16=(t,i)=>(t&V)>>>(i&V)&V,t.rshiftu32=(t,i)=>t>>>0>>>(i>>>0)>>>0,t.rshiftu8=(t,i)=>(t&F)>>>(i&F)&F,t.safeDiv=(t,i)=>0!==i?t/i:0,t.sclamp=(t,i,a,n)=>L(y(t,i,n),a,n),t.sec=t=>1/Math.cos(t),t.sigmoid=(t,i)=>1/(1+Math.exp(-t*(2*i-1))),t.sigmoid11=(t,i)=>1/(1+Math.exp(-t*i)),t.sign=(t,i=p)=>t>i?1:t<-i?-1:0,t.signExtend16=G,t.signExtend8=j,t.simplifyRatio=(t,i)=>{let a=Math.abs(t),n=Math.abs(i);for(;;){if(a<n){const t=a;a=n,n=t}const s=a%n;if(!s)return[t/n,i/n];a=s}},t.sinc=(t,a)=>(a=i*(t*a-1),Math.sin(a)/a),t.sincos=(t,i=1)=>[Math.sin(t)*i,Math.cos(t)*i],t.smax=y,t.smin=L,t.smoothStep=(t,i,a)=>(3-2*(a=O((a-t)/(i-t))))*a*a,t.smootherStep=(t,i,a)=>(a=O((a-t)/(i-t)))*a*a*(a*(6*a-15)+10),t.solveCubic=(t,i,a,n,s=1e-9)=>{const r=t*t,e=i*i,o=i/(3*t),h=(3*t*a-e)/(3*r),u=(2*e*i-9*t*i*a+27*r*n)/(27*r*t);if(Math.abs(h)<s)return[Math.cbrt(-u)-o];if(Math.abs(u)<s)return h<0?[-Math.sqrt(-h)-o,-o,Math.sqrt(-h)-o]:[-o];{const t=u*u/4+h*h*h/27;if(Math.abs(t)<s)return[-1.5*u/h-o,3*u/h-o];if(t>0){const i=Math.cbrt(-u/2-Math.sqrt(t));return[i-h/(3*i)-o]}{const t=2*Math.sqrt(-h/3),i=Math.acos(3*u/h/t)/3,a=2*Math.PI/3;return[t*Math.cos(i)-o,t*Math.cos(i-a)-o,t*Math.cos(i-2*a)-o]}}},t.solveLinear=(t,i)=>-i/t,t.solveQuadratic=(t,i,a,n=1e-9)=>{const s=2*t;let r=i*i-4*t*a;return r<0?[]:r<n?[-i/s]:(r=Math.sqrt(r),[(-i-r)/s,(-i+r)/s])},t.step=(t,i)=>i<t?0:1,t.subi16=(t,i)=>G((0|t)-(0|i)),t.subi32=(t,i)=>(0|t)-(0|i)|0,t.subi8=(t,i)=>j((0|t)-(0|i)),t.subu16=(t,i)=>(t&V)-(i&V)&V,t.subu32=(t,i)=>(t>>>0)-(i>>>0)>>>0,t.subu8=(t,i)=>(t&F)-(i&F)&F,t.tangentCardinal=(t,i,a=.5,n=0,s=2)=>a*((i-t)/(s-n)),t.tangentDiff3=(t,i,a,n=0,s=1,r=2)=>.5*((a-i)/(r-s)+(i-t)/(s-n)),t.trunc=t=>t<0?Math.ceil(t):Math.floor(t),t.tween=(t,i,a)=>n=>Z(i,a,t(n)),t.wrap=(t,i,a)=>{if(i===a)return i;if(t>a){const n=a-i;(t-=n)>a&&(t-=n*((t-i)/n|0))}else if(t<i){const n=a-i;(t+=n)<i&&(t+=n*((i-t)/n+1|0))}return t},t.wrap01=t=>t<0?t+1:t>1?t-1:t,t.wrap11=t=>t<-1?t+2:t>1?t-2:t,t.wrapOnce=(t,i,a)=>t<i?t-i+a:t>a?t-a+i:t,t.xori16=(t,i)=>G((0|t)^(0|i)),t.xori32=(t,i)=>(0|t)^(0|i),t.xori8=(t,i)=>j((0|t)^(0|i)),t.xoru16=(t,i)=>(t&V^i&V)&V,t.xoru32=(t,i)=>(t>>>0^i>>>0)>>>0,t.xoru8=(t,i)=>(t&F^i&F)&F,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a(((t="undefined"!=typeof globalThis?globalThis:t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.math={}))}(this,(function(t){"use strict";const a=Math.PI,i=2*a,n=a/2,s=a/3,r=a/4,e=a/6,o=1/a,h=1/i,u=1/n,c=a/180,M=180/a,d=(1+Math.sqrt(5))/2,f=Math.SQRT2,l=Math.sqrt(3),m=f/2,b=l/2;let p=1e-6;var x;(x=t.Crossing||(t.Crossing={}))[x.EQUAL=0]="EQUAL",x[x.FLAT=1]="FLAT",x[x.UNDER=2]="UNDER",x[x.OVER=3]="OVER",x[x.OTHER=4]="OTHER";const g=t=>(t%=i)<0?i+t:t,R=t=>(t=Math.abs(t))>a?i-t:t,T=t=>{const a=t*t;return.99940307+a*(.03679168*a-.49558072)},I=t=>{switch((t%=i)<0&&(t=-t),t*u|0){case 0:return T(t);case 1:return-T(a-t);case 2:return-T(t-a);default:return T(i-t)}},E=Math.abs,C=Math.max,D=(t,a,i=p)=>E(t-a)<=i,v=D,A=(t,a,i,n)=>t<i&&a>n,q=(t,a,i,n)=>t>i&&a<n,H=(t,a,i)=>t>a&&a<i,P=(t,a,i)=>t<a&&a>i,S=(t,a,i=0,n=a.length)=>{n--;for(let s=i+1;s<n;s++)if(t(a[s-1],a[s],a[s+1]))return s;return-1},_=(t,a=0,i=t.length)=>S(H,t,a,i);function*w(t,a,i=0,n=a.length){for(;i<n;){const s=t(a,i,n);if(s<0)return;yield s,i=s+1}}const O=t=>t<0?0:t>1?1:t,Q=t=>t<-1?-1:t>1?1:t,U=(t,a)=>0!==t?0!==a?Math.min(t,a):t:a,L=(t,a,i)=>y(t,a,-i),y=(t,a,i)=>{const n=Math.exp(t*i),s=Math.exp(a*i);return(t*n+a*s)/(n+s)},N=(t,a,i)=>i!==a?(t-a)/(i-a):0,F=255,V=65535,j=t=>128&(t&=F)?t|~F:t,G=t=>32768&(t&=V)?t|~V:t,X=(t,a,i,n=16,s=8,r=0,e=1,o=p)=>{if(s<=0)return(r+e)/2;const h=(e-r)/n;let u=r,c=1/0;for(let s=0;s<=n;s++){const n=r+s*h,e=a(i,t(n));if(e<c){if(e<=o)return n;c=e,u=n}}return X(t,a,i,n,s-1,Math.max(u-h,0),Math.min(u+h,1))},Z=(t,a,i)=>t+(a-t)*i,k=t=>(t=1-t,Math.sqrt(1-t*t)),B=t=>1-k(1-t),W=t=>t-Math.floor(t),z=(t,a)=>0!==a?t/a:0;t.DEG2RAD=c,t.EPS=p,t.HALF_PI=n,t.INV_HALF_PI=u,t.INV_PI=o,t.INV_TAU=h,t.PHI=d,t.PI=a,t.QUARTER_PI=r,t.RAD2DEG=M,t.SIXTH=1/6,t.SIXTH_PI=e,t.SQRT2=f,t.SQRT2_2=m,t.SQRT2_3=b,t.SQRT3=l,t.TAU=i,t.THIRD=1/3,t.THIRD_PI=s,t.TWO_THIRD=2/3,t.absDiff=(t,a)=>Math.abs(t-a),t.absInnerAngle=R,t.absMax=(t,a)=>Math.abs(t)>Math.abs(a)?t:a,t.absMin=(t,a)=>Math.abs(t)<Math.abs(a)?t:a,t.absTheta=g,t.addi16=(t,a)=>G((0|t)+(0|a)),t.addi32=(t,a)=>(0|t)+(0|a)|0,t.addi8=(t,a)=>j((0|t)+(0|a)),t.addu16=(t,a)=>(t&V)+(a&V)&V,t.addu32=(t,a)=>(t>>>0)+(a>>>0)>>>0,t.addu8=(t,a)=>(t&F)+(a&F)&F,t.andi16=(t,a)=>G((0|t)&(0|a)),t.andi32=(t,a)=>(0|t)&(0|a),t.andi8=(t,a)=>j((0|t)&(0|a)),t.andu16=(t,a)=>t&V&a&V&V,t.andu32=(t,a)=>(t>>>0&a>>>0)>>>0,t.andu8=(t,a)=>t&F&a&F&F,t.angleDist=(t,a)=>R(g(a%i-t%i)),t.atan2Abs=(t,a)=>g(Math.atan2(t,a)),t.bounce=(t,a,i)=>{const s=i*t;return 1-a*Math.sin(s)/s*Math.cos(i*n)},t.circular=k,t.clamp=(t,a,i)=>t<a?a:t>i?i:t,t.clamp01=O,t.clamp05=t=>t<0?0:t>.5?.5:t,t.clamp11=Q,t.classifyCrossing=(a,i,n,s,r=p)=>A(a,i,n,s)?t.Crossing.OVER:q(a,i,n,s)?t.Crossing.UNDER:D(a,n,r)&&D(i,s,r)?D(a,s,r)?t.Crossing.FLAT:t.Crossing.EQUAL:t.Crossing.OTHER,t.cosine=t=>1-(.5*Math.cos(t*a)+.5),t.cossin=(t,a=1)=>[Math.cos(t)*a,Math.sin(t)*a],t.cot=t=>1/Math.tan(t),t.csc=t=>1/Math.sin(t),t.cubicPulse=(t,a,i)=>(i=Math.abs(i-a))>t?0:1-(i/=t)*i*(3-2*i),t.decimated=(t,a)=>Math.floor(a*t)/t,t.deg=t=>t*M,t.derivative=(t,a=p)=>i=>(t(i+a)-t(i))/a,t.divi16=(t,a)=>G((0|t)/(0|a)),t.divi32=(t,a)=>(0|t)/(0|a)|0,t.divi8=(t,a)=>j((0|t)/(0|a)),t.divu16=(t,a)=>(t&V)/(a&V)&V,t.divu32=(t,a)=>(t>>>0)/(a>>>0)>>>0,t.divu8=(t,a)=>(t&F)/(a&F)&F,t.ease=(t,a)=>Math.pow(a,t),t.eqDelta=D,t.eqDeltaFixed=v,t.eqDeltaScaled=(t,a,i=p)=>E(t-a)<=i*C(1,E(t),E(a)),t.expFactor=(t,a,i)=>(a/t)**(1/i),t.expStep=(t,a,i)=>1-Math.exp(-t*Math.pow(i,a)),t.fastCos=I,t.fastSin=t=>I(n-t),t.fit=(t,a,i,n,s)=>n+(s-n)*N(t,a,i),t.fit01=(t,a,i)=>a+(i-a)*O(t),t.fit10=(t,a,i)=>i+(a-i)*O(t),t.fit11=(t,a,i)=>a+(i-a)*(.5+.5*Q(t)),t.fitClamped=(t,a,i,n,s)=>n+(s-n)*O(N(t,a,i)),t.fmod=(t,a)=>t-a*Math.floor(t/a),t.foldback=(t,a)=>a<-t||a>t?Math.abs(Math.abs((a-t)%(4*t))-2*t)-t:a,t.fract=W,t.gain=(t,a)=>a<.5?.5*Math.pow(2*a,t):1-.5*Math.pow(2-2*a,t),t.impulse=(t,a)=>{const i=t*a;return i*Math.exp(1-i)},t.inOpenRange=(t,a,i)=>t>a&&t<i,t.inRange=(t,a,i)=>t>=a&&t<=i,t.invCircular=B,t.isCrossOver=A,t.isCrossUnder=q,t.isMaxima=P,t.isMinima=H,t.lens=(t,a,i)=>{const n=a>0?B:k,s=1-t,r=i<=t?n(i/t)*t:1-n((1-i)/s)*s;return Z(i,r,Math.abs(a))},t.loc=(t,a,i)=>Math.sqrt(t*t+a*a-2*t*a*Math.cos(i)),t.lshifti16=(t,a)=>G((0|t)<<(0|a)),t.lshifti32=(t,a)=>(0|t)<<(0|a),t.lshifti8=(t,a)=>j((0|t)<<(0|a)),t.lshiftu16=(t,a)=>(t&V)<<(a&V)&V,t.lshiftu32=(t,a)=>t>>>0<<(a>>>0)>>>0,t.lshiftu8=(t,a)=>(t&F)<<(a&F)&F,t.max2id=(t,a)=>t>=a?0:1,t.max3id=(t,a,i)=>t>=a?t>=i?0:2:a>=i?1:2,t.max4id=(t,a,i,n)=>t>=a?t>=i?t>=n?0:3:i>=n?2:3:a>=i?a>=n?1:3:i>=n?2:3,t.maximaIndex=(t,a=0,i=t.length)=>S(P,t,a,i),t.maximaIndices=(t,a=0,i=t.length)=>w(_,t,a,i),t.min2id=(t,a)=>t<=a?0:1,t.min3id=(t,a,i)=>t<=a?t<=i?0:2:a<=i?1:2,t.min4id=(t,a,i,n)=>t<=a?t<=i?t<=n?0:3:i<=n?2:3:a<=i?a<=n?1:3:i<=n?2:3,t.minError=X,t.minNonZero2=U,t.minNonZero3=(t,a,i)=>U(U(t,a),i),t.minimaIndex=_,t.minimaIndices=(t,a=0,i=t.length)=>w(_,t,a,i),t.mix=Z,t.mixBilinear=(t,a,i,n,s,r)=>Z(Z(t,a,s),Z(i,n,s),r),t.mixCubic=(t,a,i,n,s)=>{const r=s*s,e=1-s,o=e*e;return t*o*e+3*a*o*s+3*i*r*e+n*r*s},t.mixCubicHermite=(t,a,i,n,s)=>{const r=s-1,e=s*s,o=r*r;return(1+2*s)*o*t+s*o*a+e*(3-2*s)*i+e*r*n},t.mixHermite=(t,a,i,n,s)=>{const r=.5*(i-t),e=1.5*(a-i)+.5*(n-t);return((e*s+t-a+r-e)*s+r)*s+a},t.mixQuadratic=(t,a,i,n)=>{const s=1-n;return t*s*s+2*a*s*n+i*n*n},t.muli16=(t,a)=>G((0|t)*(0|a)),t.muli32=(t,a)=>(0|t)*(0|a)|0,t.muli8=(t,a)=>j((0|t)*(0|a)),t.mulu16=(t,a)=>(t&V)*(a&V)&V,t.mulu32=(t,a)=>(t>>>0)*(a>>>0)>>>0,t.mulu8=(t,a)=>(t&F)*(a&F)&F,t.norm=N,t.normCos=t=>{const a=t*t;return 1+a*(2*a-4)},t.noti16=t=>G(~t),t.noti32=t=>~t,t.noti8=t=>j(~t),t.notu16=t=>~t&V,t.notu32=t=>~t>>>0,t.notu8=t=>~t&F,t.ori16=(t,a)=>G(0|t|a),t.ori32=(t,a)=>0|t|a,t.ori8=(t,a)=>j(0|t|a),t.oru16=(t,a)=>(t&V|a&V)&V,t.oru32=(t,a)=>(t>>>0|a>>>0)>>>0,t.oru8=(t,a)=>(t&F|a&F)&F,t.parabola=(t,a)=>Math.pow(4*a*(1-a),t),t.quadrant=t=>g(t)*u|0,t.rad=t=>t*c,t.roundEps=(t,a=p)=>{const i=W(t);return i<=a||i>=1-a?Math.round(t):t},t.roundTo=(t,a=1)=>Math.round(t/a)*a,t.rshifti16=(t,a)=>G((0|t)>>(0|a)),t.rshifti32=(t,a)=>(0|t)>>(0|a),t.rshifti8=(t,a)=>j((0|t)>>(0|a)),t.rshiftu16=(t,a)=>(t&V)>>>(a&V)&V,t.rshiftu32=(t,a)=>t>>>0>>>(a>>>0)>>>0,t.rshiftu8=(t,a)=>(t&F)>>>(a&F)&F,t.safeDiv=z,t.sclamp=(t,a,i,n)=>L(y(t,a,n),i,n),t.sec=t=>1/Math.cos(t),t.sigmoid=(t,a)=>1/(1+Math.exp(-t*(2*a-1))),t.sigmoid11=(t,a)=>1/(1+Math.exp(-t*a)),t.sign=(t,a=p)=>t>a?1:t<-a?-1:0,t.signExtend16=G,t.signExtend8=j,t.simplifyRatio=(t,a)=>{let i=Math.abs(t),n=Math.abs(a);for(;;){if(i<n){const t=i;i=n,n=t}const s=i%n;if(!s)return[t/n,a/n];i=s}},t.sinc=(t,i)=>(i=a*(t*i-1),Math.sin(i)/i),t.sincos=(t,a=1)=>[Math.sin(t)*a,Math.cos(t)*a],t.smax=y,t.smin=L,t.smoothStep=(t,a,i)=>(3-2*(i=O((i-t)/(a-t))))*i*i,t.smootherStep=(t,a,i)=>(i=O((i-t)/(a-t)))*i*i*(i*(6*i-15)+10),t.solveCubic=(t,a,i,n,s=1e-9)=>{const r=t*t,e=a*a,o=a/(3*t),h=(3*t*i-e)/(3*r),u=(2*e*a-9*t*a*i+27*r*n)/(27*r*t);if(Math.abs(h)<s)return[Math.cbrt(-u)-o];if(Math.abs(u)<s)return h<0?[-Math.sqrt(-h)-o,-o,Math.sqrt(-h)-o]:[-o];{const t=u*u/4+h*h*h/27;if(Math.abs(t)<s)return[-1.5*u/h-o,3*u/h-o];if(t>0){const a=Math.cbrt(-u/2-Math.sqrt(t));return[a-h/(3*a)-o]}{const t=2*Math.sqrt(-h/3),a=Math.acos(3*u/h/t)/3,i=2*Math.PI/3;return[t*Math.cos(a)-o,t*Math.cos(a-i)-o,t*Math.cos(a-2*i)-o]}}},t.solveLinear=(t,a)=>z(-a,t),t.solveQuadratic=(t,a,i,n=1e-9)=>{const s=2*t;let r=a*a-4*t*i;return r<0?[]:r<n?[-a/s]:(r=Math.sqrt(r),[(-a-r)/s,(-a+r)/s])},t.step=(t,a)=>a<t?0:1,t.subi16=(t,a)=>G((0|t)-(0|a)),t.subi32=(t,a)=>(0|t)-(0|a)|0,t.subi8=(t,a)=>j((0|t)-(0|a)),t.subu16=(t,a)=>(t&V)-(a&V)&V,t.subu32=(t,a)=>(t>>>0)-(a>>>0)>>>0,t.subu8=(t,a)=>(t&F)-(a&F)&F,t.tangentCardinal=(t,a,i=.5,n=0,s=2)=>i*((a-t)/(s-n)),t.tangentDiff3=(t,a,i,n=0,s=1,r=2)=>.5*((i-a)/(r-s)+(a-t)/(s-n)),t.trunc=t=>t<0?Math.ceil(t):Math.floor(t),t.tween=(t,a,i)=>n=>Z(a,i,t(n)),t.wrap=(t,a,i)=>{if(a===i)return a;if(t>i){const n=i-a;(t-=n)>i&&(t-=n*((t-a)/n|0))}else if(t<a){const n=i-a;(t+=n)<a&&(t+=n*((a-t)/n+1|0))}return t},t.wrap01=t=>t<0?t+1:t>1?t-1:t,t.wrap11=t=>t<-1?t+2:t>1?t-2:t,t.wrapOnce=(t,a,i)=>t<a?t-a+i:t>i?t-i+a:t,t.xori16=(t,a)=>G((0|t)^(0|a)),t.xori32=(t,a)=>(0|t)^(0|a),t.xori8=(t,a)=>j((0|t)^(0|a)),t.xoru16=(t,a)=>(t&V^a&V)&V,t.xoru32=(t,a)=>(t>>>0^a>>>0)>>>0,t.xoru8=(t,a)=>(t&F^a&F)&F,Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -1,2 +0,3 @@

export declare const mix: (a: number, b: number, t: number) => number;
import type { FnN, FnN2, FnN3, FnN4, FnN5, FnN6 } from "@thi.ng/api";
export declare const mix: FnN3;
/**

@@ -19,5 +20,5 @@ * @example

*/
export declare const mixBilinear: (a: number, b: number, c: number, d: number, u: number, v: number) => number;
export declare const mixQuadratic: (a: number, b: number, c: number, t: number) => number;
export declare const mixCubic: (a: number, b: number, c: number, d: number, t: number) => number;
export declare const mixBilinear: FnN6;
export declare const mixQuadratic: FnN4;
export declare const mixCubic: FnN5;
/**

@@ -48,3 +49,3 @@ * Returns hermite interpolation of `a, b, c, d` at normalized position

*/
export declare const mixHermite: (a: number, b: number, c: number, d: number, t: number) => number;
export declare const mixHermite: FnN5;
/**

@@ -66,3 +67,3 @@ * Computes cubic-hermite interpolation between `a` / `b` at normalized

*/
export declare const mixCubicHermite: (a: number, ta: number, b: number, tb: number, t: number) => number;
export declare const mixCubicHermite: FnN5;
/**

@@ -116,13 +117,49 @@ * Helper function for {@link mixCubicHermite}. Computes cardinal tangents

/**
* Circular interpolation: `sqrt(1 - (1 - t)^2)`
* Circular interpolation (ease out): `sqrt(1 - (1 - t)^2)`
*
* @param t - interpolation factor (0.0 .. 1.0)
* Reference: https://www.desmos.com/calculator/tisoiazdrw
*
* @param t - interpolation factor [0..1]
*/
export declare const circular: (t: number) => number;
export declare const cosine: (t: number) => number;
export declare const decimated: (n: number, t: number) => number;
export declare const bounce: (k: number, amp: number, t: number) => number;
export declare const circular: FnN;
/**
* HOF exponential easing.
* Inverse/flipped version of {@link circular} (ease in).
*
* Reference: https://www.desmos.com/calculator/tisoiazdrw
*
* @param t - interpolation factor [0..1]
*/
export declare const invCircular: FnN;
/**
* Zoomlens interpolation with customizable lens position, behavior and
* strength.
*
* @remarks
* Lens position must be given in (0..1) interval. Lens strength must be in
* [-1,1] range. If negative, the lens will be bundling values near `pos`, if
* positive the lens has dilating characteristics and will spread values near
* `pos` towards the edges.
*
* @example
* ```ts
* // interpolated position in [100..400] interval for given `t`
* y = mix(100, 400, lens(0.5, 1, t));
*
* // or build tween function via `tween()`
* f = tween(partial(lens, 0.5, 1), 100, 400);
*
* f(t)
* ```
*
* @param pos - lens pos
* @param strength - lens strength
* @param t - interpolation factor [0..1]
*/
export declare const lens: FnN3;
export declare const cosine: FnN;
export declare const decimated: FnN2;
export declare const bounce: FnN3;
/**
* Exponential easing.
*
* - `ease = 1` -> linear

@@ -135,13 +172,13 @@ * - `ease > 1` -> ease in

*/
export declare const ease: (ease: number, t: number) => number;
export declare const ease: FnN2;
/**
* HOF impulse generator. Peaks at `t=1/k`
* Impulse generator. Peaks at `t = 1/k`
*
* @param k - impulse width (higher values => shorter impulse)
*/
export declare const impulse: (k: number, t: number) => number;
export declare const gain: (k: number, t: number) => number;
export declare const parabola: (k: number, t: number) => number;
export declare const cubicPulse: (w: number, c: number, t: number) => number;
export declare const sinc: (k: number, t: number) => number;
export declare const impulse: FnN2;
export declare const gain: FnN2;
export declare const parabola: FnN2;
export declare const cubicPulse: FnN3;
export declare const sinc: FnN2;
/**

@@ -153,3 +190,3 @@ * Sigmoid function for inputs in [0..1] interval.

*/
export declare const sigmoid: (k: number, t: number) => number;
export declare const sigmoid: FnN2;
/**

@@ -161,3 +198,3 @@ * Sigmoid function for inputs in [-1..+1] interval.

*/
export declare const sigmoid11: (k: number, t: number) => number;
export declare const sigmoid11: FnN2;
/**

@@ -172,3 +209,3 @@ * Computes exponential factor to interpolate from `a` to `b` over

*/
export declare const expFactor: (a: number, b: number, num: number) => number;
export declare const expFactor: FnN3;
//# sourceMappingURL=mix.d.ts.map

@@ -135,5 +135,7 @@ import { HALF_PI, PI } from "./api";

/**
* Circular interpolation: `sqrt(1 - (1 - t)^2)`
* Circular interpolation (ease out): `sqrt(1 - (1 - t)^2)`
*
* @param t - interpolation factor (0.0 .. 1.0)
* Reference: https://www.desmos.com/calculator/tisoiazdrw
*
* @param t - interpolation factor [0..1]
*/

@@ -144,2 +146,41 @@ export const circular = (t) => {

};
/**
* Inverse/flipped version of {@link circular} (ease in).
*
* Reference: https://www.desmos.com/calculator/tisoiazdrw
*
* @param t - interpolation factor [0..1]
*/
export const invCircular = (t) => 1 - circular(1 - t);
/**
* Zoomlens interpolation with customizable lens position, behavior and
* strength.
*
* @remarks
* Lens position must be given in (0..1) interval. Lens strength must be in
* [-1,1] range. If negative, the lens will be bundling values near `pos`, if
* positive the lens has dilating characteristics and will spread values near
* `pos` towards the edges.
*
* @example
* ```ts
* // interpolated position in [100..400] interval for given `t`
* y = mix(100, 400, lens(0.5, 1, t));
*
* // or build tween function via `tween()`
* f = tween(partial(lens, 0.5, 1), 100, 400);
*
* f(t)
* ```
*
* @param pos - lens pos
* @param strength - lens strength
* @param t - interpolation factor [0..1]
*/
export const lens = (pos, strength, t) => {
const impl = strength > 0 ? invCircular : circular;
const tp = 1 - pos;
const tl = t <= pos ? impl(t / pos) * pos : 1 - impl((1 - t) / tp) * tp;
return mix(t, tl, Math.abs(strength));
};
export const cosine = (t) => 1 - (Math.cos(t * PI) * 0.5 + 0.5);

@@ -152,3 +193,3 @@ export const decimated = (n, t) => Math.floor(t * n) / n;

/**
* HOF exponential easing.
* Exponential easing.
*

@@ -164,3 +205,3 @@ * - `ease = 1` -> linear

/**
* HOF impulse generator. Peaks at `t=1/k`
* Impulse generator. Peaks at `t = 1/k`
*

@@ -167,0 +208,0 @@ * @param k - impulse width (higher values => shorter impulse)

{
"name": "@thi.ng/math",
"version": "2.0.4",
"version": "2.1.0",
"description": "Assorted common math functions & utilities",

@@ -34,3 +34,3 @@ "module": "./index.js",

"cover": "nyc mocha test && nyc report --reporter=lcov",
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib",
"clean": "rimraf *.js *.d.ts *.map .nyc_output build coverage doc lib",
"doc:readme": "ts-node -P ../../tools/tsconfig.json ../../tools/src/readme.ts",

@@ -52,2 +52,5 @@ "doc": "node_modules/.bin/typedoc --mode modules --out doc --theme ../../tools/doc/typedoc-theme src",

},
"dependencies": {
"@thi.ng/api": "^6.13.0"
},
"files": [

@@ -59,9 +62,13 @@ "*.js",

"keywords": [
"ES6",
"es6",
"cubic",
"hermite",
"interpolation",
"interval",
"math",
"quadratic",
"smooth",
"solver",
"typescript",
"utilities"
"trigonometry",
"typescript"
],

@@ -72,6 +79,3 @@ "publishConfig": {

"sideEffects": false,
"dependencies": {
"tslib": "^2.0.1"
},
"gitHead": "3a55c0df86c5be9c56a1e1a4c0cfcaa2809a160a"
"gitHead": "83a0206aae59aa1b1b4bcb01c2b34bbe3db4844c"
}

@@ -0,1 +1,2 @@

import type { FnN, FnN2 } from "@thi.ng/api";
/**

@@ -7,5 +8,5 @@ * Returns `a - b * floor(a/b)`

*/
export declare const fmod: (a: number, b: number) => number;
export declare const fract: (x: number) => number;
export declare const trunc: (x: number) => number;
export declare const fmod: FnN2;
export declare const fract: FnN;
export declare const trunc: FnN;
export declare const roundTo: (x: number, prec?: number) => number;

@@ -12,0 +13,0 @@ /**

@@ -49,7 +49,7 @@ <!-- This file is generated - DO NOT EDIT! -->

Package sizes (gzipped, pre-treeshake): ESM: 3.49 KB / CJS: 4.04 KB / UMD: 3.33 KB
Package sizes (gzipped, pre-treeshake): ESM: 3.56 KB / CJS: 4.12 KB / UMD: 3.40 KB
## Dependencies
- [tslib](https://github.com/thi-ng/umbrella/tree/develop/packages/undefined)
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)

@@ -56,0 +56,0 @@ ## Usage examples

@@ -0,1 +1,2 @@

import type { FnN2 } from "@thi.ng/api";
/**

@@ -7,3 +8,3 @@ * Returns `a` divided by `b` or zero if `b = 0`.

*/
export declare const safeDiv: (a: number, b: number) => number;
export declare const safeDiv: FnN2;
//# sourceMappingURL=safe-div.d.ts.map

@@ -0,1 +1,2 @@

import type { FnN2 } from "@thi.ng/api";
/**

@@ -21,3 +22,3 @@ * Produces a new function which computes derivative of the given

*
* Note: `a` MUST NOT be zero.
* Note: Returns 0 iff `a == 0`
*

@@ -27,3 +28,3 @@ * @param a - slope

*/
export declare const solveLinear: (a: number, b: number) => number;
export declare const solveLinear: FnN2;
/**

@@ -30,0 +31,0 @@ * Computes solutions for quadratic equation: `ax^2 + bx + c = 0`.

import { EPS } from "./api";
import { safeDiv } from "./safe-div";
/**

@@ -22,3 +23,3 @@ * Produces a new function which computes derivative of the given

*
* Note: `a` MUST NOT be zero.
* Note: Returns 0 iff `a == 0`
*

@@ -28,3 +29,3 @@ * @param a - slope

*/
export const solveLinear = (a, b) => -b / a;
export const solveLinear = (a, b) => safeDiv(-b, a);
/**

@@ -31,0 +32,0 @@ * Computes solutions for quadratic equation: `ax^2 + bx + c = 0`.

@@ -0,1 +1,2 @@

import type { FnN2, FnN3 } from "@thi.ng/api";
/**

@@ -8,3 +9,3 @@ * Step/threshold function.

*/
export declare const step: (edge: number, x: number) => 1 | 0;
export declare const step: FnN2;
/**

@@ -18,3 +19,3 @@ * GLSL-style smoothStep threshold function.

*/
export declare const smoothStep: (edge: number, edge2: number, x: number) => number;
export declare const smoothStep: FnN3;
/**

@@ -27,3 +28,3 @@ * Similar to {@link smoothStep} but using different polynomial.

*/
export declare const smootherStep: (edge: number, edge2: number, x: number) => number;
export declare const smootherStep: FnN3;
/**

@@ -41,3 +42,3 @@ * Exponential ramp with variable shape, e.g.

*/
export declare const expStep: (k: number, n: number, x: number) => number;
export declare const expStep: FnN3;
//# sourceMappingURL=step.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc