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 1.4.1 to 1.4.2

8

CHANGELOG.md

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

## [1.4.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@1.4.1...@thi.ng/math@1.4.2) (2019-07-31)
**Note:** Version bump only for package @thi.ng/math
## [1.4.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@1.4.0...@thi.ng/math@1.4.1) (2019-07-12)

@@ -8,0 +16,0 @@

569

lib/index.umd.js

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

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory((global.thi = global.thi || {}, global.thi.ng = global.thi.ng || {}, global.thi.ng.math = {})));
}(this, function (exports) { 'use strict';
const PI = Math.PI;
const TAU = PI * 2;
const HALF_PI = PI / 2;
const THIRD_PI = PI / 3;
const QUARTER_PI = PI / 4;
const SIXTH_PI = PI / 6;
const INV_PI = 1 / PI;
const INV_TAU = 1 / TAU;
const INV_HALF_PI = 1 / HALF_PI;
const DEG2RAD = PI / 180;
const RAD2DEG = 180 / PI;
const PHI = (1 + Math.sqrt(5)) / 2;
const SQRT2 = Math.SQRT2;
const SQRT3 = Math.sqrt(3);
const SQRT2_2 = SQRT2 / 2;
const SQRT2_3 = SQRT3 / 2;
const THIRD = 1 / 3;
const TWO_THIRD = 2 / 3;
const SIXTH = 1 / 6;
let EPS = 1e-6;
(function (Crossing) {
Crossing[Crossing["EQUAL"] = 0] = "EQUAL";
Crossing[Crossing["FLAT"] = 1] = "FLAT";
Crossing[Crossing["UNDER"] = 2] = "UNDER";
Crossing[Crossing["OVER"] = 3] = "OVER";
Crossing[Crossing["OTHER"] = 4] = "OTHER";
})(exports.Crossing || (exports.Crossing = {}));
const absDiff = (x, y) => Math.abs(x - y);
const sign = (x, eps = EPS) => (x > eps ? 1 : x < -eps ? -1 : 0);
const sincos = (theta, n = 1) => [
Math.sin(theta) * n,
Math.cos(theta) * n
];
const cossin = (theta, n = 1) => [
Math.cos(theta) * n,
Math.sin(theta) * n
];
const absTheta = (theta) => ((theta %= TAU), theta < 0 ? TAU + theta : theta);
const absInnerAngle = (theta) => ((theta = Math.abs(theta)), theta > PI ? TAU - theta : theta);
const angleDist = (a, b) => absInnerAngle(absTheta((b % TAU) - (a % TAU)));
const atan2Abs = (y, x) => absTheta(Math.atan2(y, x));
const quadrant = (theta) => (absTheta(theta) * INV_HALF_PI) | 0;
const deg = (theta) => theta * RAD2DEG;
const rad = (theta) => theta * DEG2RAD;
const csc = (theta) => 1 / Math.sin(theta);
const sec = (theta) => 1 / Math.cos(theta);
const cot = (theta) => 1 / Math.tan(theta);
const loc = (a, b, gamma) => Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(gamma));
const normCos = (x) => {
const x2 = x * x;
return 1.0 + x2 * (-4 + 2 * x2);
};
const __fastCos = (x) => {
const x2 = x * x;
return 0.99940307 + x2 * (-0.49558072 + 0.03679168 * x2);
};
const fastCos = (theta) => {
theta %= TAU;
theta < 0 && (theta = -theta);
switch ((theta * INV_HALF_PI) | 0) {
case 0:
return __fastCos(theta);
case 1:
return -__fastCos(PI - theta);
case 2:
return -__fastCos(theta - PI);
default:
return __fastCos(TAU - theta);
}
};
const fastSin = (theta) => fastCos(HALF_PI - theta);
const abs = Math.abs;
const max = Math.max;
const eqDelta = (a, b, eps = EPS) => abs(a - b) <= eps * max(1, abs(a), abs(b));
const eqDeltaFixed = (a, b, eps = EPS) => abs(a - b) <= eps;
const isCrossOver = (a1, a2, b1, b2) => a1 < b1 && a2 > b2;
const isCrossUnder = (a1, a2, b1, b2) => a1 > b1 && a2 < b2;
const classifyCrossing = (a1, a2, b1, b2, eps = EPS) => {
if (isCrossOver(a1, a2, b1, b2)) {
return 3 ;
}
else if (isCrossUnder(a1, a2, b1, b2)) {
return 2 ;
}
return eqDelta(a1, b1, eps) && eqDelta(a2, b2, eps)
? eqDelta(a1, b2, eps)
? 1
: 0
: 4 ;
};
const isMinima = (a, b, c) => a > b && b < c;
const isMaxima = (a, b, c) => a < b && b > c;
const index = (pred, values, from = 0, to = values.length) => {
to--;
for (let i = from + 1; i < to; i++) {
if (pred(values[i - 1], values[i], values[i + 1])) {
return i;
}
}
return -1;
};
const minimaIndex = (values, from = 0, to = values.length) => index(isMinima, values, from, to);
const maximaIndex = (values, from = 0, to = values.length) => index(isMaxima, values, from, to);
function* indices(fn, vals, from = 0, to = vals.length) {
while (from < to) {
const i = fn(vals, from, to);
if (i < 0)
return;
yield i;
from = i + 1;
}
}
const minimaIndices = (values, from = 0, to = values.length) => indices(minimaIndex, values, from, to);
const maximaIndices = (values, from = 0, to = values.length) => indices(minimaIndex, values, from, to);
const clamp = (x, min, max) => x < min ? min : x > max ? max : x;
const clamp01 = (x) => (x < 0 ? 0 : x > 1 ? 1 : x);
const clamp11 = (x) => (x < -1 ? -1 : x > 1 ? 1 : x);
const wrap = (x, min, max) => x < min ? x - min + max : x >= max ? x - max + min : x;
const wrap01 = (x) => (x < 0 ? x + 1 : x >= 1 ? x - 1 : x);
const wrap11 = (x) => (x < -1 ? x + 2 : x >= 1 ? x - 2 : x);
const min2id = (a, b) => (a <= b ? 0 : 1);
const min3id = (a, b, c) => a <= b ? (a <= c ? 0 : 2) : b <= c ? 1 : 2;
const min4id = (a, b, c, d) => a <= b
? a <= c
? a <= d
? 0
: 3
: c <= d
? 2
: 3
: b <= c
? b <= d
? 1
: 3
: c <= d
? 2
: 3;
const max2id = (a, b) => (a >= b ? 0 : 1);
const max3id = (a, b, c) => a >= b ? (a >= c ? 0 : 2) : b >= c ? 1 : 2;
const max4id = (a, b, c, d) => a >= b
? a >= c
? a >= d
? 0
: 3
: c >= d
? 2
: 3
: b >= c
? b >= d
? 1
: 3
: c >= d
? 2
: 3;
const smin = (a, b, k) => smax(a, b, -k);
const smax = (a, b, k) => {
const ea = Math.exp(a * k);
const eb = Math.exp(b * k);
return (a * ea + b * eb) / (ea + eb);
};
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 foldback = (e, x) => x < -e || x > e ? Math.abs(Math.abs((x - e) % (4 * e)) - 2 * e) - e : x;
const inRange = (x, min, max) => x >= min && x <= max;
const inOpenRange = (x, min, max) => x > min && x < max;
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);
const fitClamped = (x, a, b, c, d) => c + (d - c) * clamp01(norm(x, a, b));
const fit01 = (x, a, b) => a + (b - a) * clamp01(x);
const fit10 = (x, a, b) => b + (a - b) * clamp01(x);
const fit11 = (x, a, b) => a + (b - a) * (0.5 + 0.5 * clamp11(x));
const M8 = 0xff;
const M16 = 0xffff;
const signExtend8 = (a) => ((a &= M8), a & 0x80 ? a | ~M8 : a);
const signExtend16 = (a) => ((a &= M16), a & 0x8000 ? a | ~M16 : a);
const addi8 = (a, b) => signExtend8((a | 0) + (b | 0));
const divi8 = (a, b) => signExtend8((a | 0) / (b | 0));
const muli8 = (a, b) => signExtend8((a | 0) * (b | 0));
const subi8 = (a, b) => signExtend8((a | 0) - (b | 0));
const andi8 = (a, b) => signExtend8((a | 0) & (b | 0));
const ori8 = (a, b) => signExtend8(a | 0 | (b | 0));
const xori8 = (a, b) => signExtend8((a | 0) ^ (b | 0));
const noti8 = (a) => signExtend8(~a);
const lshifti8 = (a, b) => signExtend8((a | 0) << (b | 0));
const rshifti8 = (a, b) => signExtend8((a | 0) >> (b | 0));
const addi16 = (a, b) => signExtend16((a | 0) + (b | 0));
const divi16 = (a, b) => signExtend16((a | 0) / (b | 0));
const muli16 = (a, b) => signExtend16((a | 0) * (b | 0));
const subi16 = (a, b) => signExtend16((a | 0) - (b | 0));
const andi16 = (a, b) => signExtend16((a | 0) & (b | 0));
const ori16 = (a, b) => signExtend16(a | 0 | (b | 0));
const xori16 = (a, b) => signExtend16((a | 0) ^ (b | 0));
const noti16 = (a) => signExtend16(~a);
const lshifti16 = (a, b) => signExtend16((a | 0) << (b | 0));
const rshifti16 = (a, b) => signExtend16((a | 0) >> (b | 0));
const addi32 = (a, b) => ((a | 0) + (b | 0)) | 0;
const divi32 = (a, b) => ((a | 0) / (b | 0)) | 0;
const muli32 = (a, b) => ((a | 0) * (b | 0)) | 0;
const subi32 = (a, b) => ((a | 0) - (b | 0)) | 0;
const andi32 = (a, b) => (a | 0) & (b | 0);
const ori32 = (a, b) => a | 0 | (b | 0);
const xori32 = (a, b) => (a | 0) ^ (b | 0);
const lshifti32 = (a, b) => (a | 0) << (b | 0);
const rshifti32 = (a, b) => (a | 0) >> (b | 0);
const noti32 = (a) => ~a;
const addu8 = (a, b) => ((a & M8) + (b & M8)) & M8;
const divu8 = (a, b) => ((a & M8) / (b & M8)) & M8;
const mulu8 = (a, b) => ((a & M8) * (b & M8)) & M8;
const subu8 = (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;
const xoru8 = (a, b) => ((a & M8) ^ (b & M8)) & M8;
const notu8 = (a) => ~a & M8;
const lshiftu8 = (a, b) => ((a & M8) << (b & M8)) & M8;
const rshiftu8 = (a, b) => ((a & M8) >>> (b & M8)) & M8;
const addu16 = (a, b) => ((a & M16) + (b & M16)) & M16;
const divu16 = (a, b) => ((a & M16) / (b & M16)) & M16;
const mulu16 = (a, b) => ((a & M16) * (b & M16)) & M16;
const subu16 = (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;
const xoru16 = (a, b) => ((a & M16) ^ (b & M16)) & M16;
const notu16 = (a) => ~a & M16;
const lshiftu16 = (a, b) => ((a & M16) << (b & M16)) & M16;
const rshiftu16 = (a, b) => ((a & M16) >>> (b & M16)) & M16;
const addu32 = (a, b) => ((a >>> 0) + (b >>> 0)) >>> 0;
const divu32 = (a, b) => ((a >>> 0) / (b >>> 0)) >>> 0;
const mulu32 = (a, b) => ((a >>> 0) * (b >>> 0)) >>> 0;
const subu32 = (a, b) => ((a >>> 0) - (b >>> 0)) >>> 0;
const andu32 = (a, b) => ((a >>> 0) & (b >>> 0)) >>> 0;
const oru32 = (a, b) => ((a >>> 0) | (b >>> 0)) >>> 0;
const xoru32 = (a, b) => ((a >>> 0) ^ (b >>> 0)) >>> 0;
const notu32 = (a) => ~a >>> 0;
const lshiftu32 = (a, b) => ((a >>> 0) << (b >>> 0)) >>> 0;
const rshiftu32 = (a, b) => ((a >>> 0) >>> (b >>> 0)) >>> 0;
const minError = (fn, error, q, res = 16, iter = 8, start = 0, end = 1, eps = EPS) => {
if (iter <= 0)
return (start + end) / 2;
const delta = (end - start) / res;
let minT = start;
let minE = Infinity;
for (let i = 0; i <= res; i++) {
const t = start + i * delta;
const e = error(q, fn(t));
if (e < minE) {
if (e <= eps)
return t;
minE = e;
minT = t;
}
}
return minError(fn, error, q, res, iter - 1, Math.max(minT - delta, 0), Math.min(minT + delta, 1));
};
const mix = (a, b, t) => a + (b - a) * t;
const mixBilinear = (a, b, c, d, u, v) => mix(mix(a, b, u), mix(c, d, u), v);
const mixQuadratic = (a, b, c, t) => {
const s = 1 - t;
return a * s * s + b * 2 * s * t + c * t * t;
};
const mixCubic = (a, b, c, d, t) => {
const t2 = t * t;
const s = 1 - t;
const s2 = s * s;
return a * s2 * s + b * 3 * s2 * t + c * 3 * t2 * s + d * t2 * t;
};
const tween = (f, from, to) => (t) => mix(from, to, f(t));
const circular = (t) => {
t = 1 - t;
return Math.sqrt(1 - t * t);
};
const cosine = (t) => 1 - (Math.cos(t * PI) * 0.5 + 0.5);
const decimated = (n, t) => Math.floor(t * n) / n;
const bounce = (k, amp, t) => {
const tk = t * k;
return 1 - ((amp * Math.sin(tk)) / tk) * Math.cos(t * HALF_PI);
};
const ease = (ease, t) => Math.pow(t, ease);
const impulse = (k, t) => {
const h = k * t;
return h * Math.exp(1 - h);
};
const gain = (k, t) => t < 0.5 ? 0.5 * Math.pow(2 * t, k) : 1 - 0.5 * Math.pow(2 - 2 * t, k);
const parabola = (k, t) => Math.pow(4.0 * t * (1.0 - t), k);
const cubicPulse = (w, c, t) => {
t = Math.abs(t - c);
return t > w ? 0 : ((t /= w), 1 - t * t * (3 - 2 * t));
};
const sinc = (k, t) => {
t = PI * (k * t - 1.0);
return Math.sin(t) / t;
};
const sigmoid = (k, t) => 1 / (1 + Math.exp(-k * (2 * t - 1)));
const sigmoid11 = (k, t) => 1 / (1 + Math.exp(-k * t));
const fmod = (a, b) => a - b * Math.floor(a / b);
const fract = (x) => x - Math.floor(x);
const trunc = (x) => (x < 0 ? Math.ceil(x) : Math.floor(x));
const roundTo = (x, prec = 1) => Math.round(x / prec) * prec;
const roundEps = (x, eps = EPS) => {
const f = fract(x);
return f <= eps || f >= 1 - eps ? Math.round(x) : x;
};
const simplifyRatio = (num, denom) => {
let e1 = Math.abs(num);
let e2 = Math.abs(denom);
while (true) {
if (e1 < e2) {
const t = e1;
e1 = e2;
e2 = t;
}
const r = e1 % e2;
if (r) {
e1 = r;
}
else {
return [num / e2, denom / e2];
}
}
};
const derivative = (f, eps = EPS) => (x) => (f(x + eps) - f(x)) / eps;
const solveLinear = (a, b) => -b / a;
const solveQuadratic = (a, b, c, eps = 1e-9) => {
const d = 2 * a;
let r = b * b - 4 * a * c;
return r < 0
? []
: r < eps
? [-b / d]
: ((r = Math.sqrt(r)), [(-b - r) / d, (-b + r) / d]);
};
const solveCubic = (a, b, c, d, eps = 1e-9) => {
const aa = a * a;
const bb = b * b;
const ba3 = b / (3 * a);
const p = (3 * a * c - bb) / (3 * aa);
const q = (2 * bb * b - 9 * a * b * c + 27 * aa * d) / (27 * aa * a);
if (Math.abs(p) < eps) {
return [Math.cbrt(-q) - ba3];
}
else if (Math.abs(q) < eps) {
return p < 0
? [-Math.sqrt(-p) - ba3, -ba3, Math.sqrt(-p) - ba3]
: [-ba3];
}
else {
const denom = (q * q) / 4 + (p * p * p) / 27;
if (Math.abs(denom) < eps) {
return [(-1.5 * q) / p - ba3, (3 * q) / p - ba3];
}
else if (denom > 0) {
const u = Math.cbrt(-q / 2 - Math.sqrt(denom));
return [u - p / (3 * u) - ba3];
}
else {
const u = 2 * Math.sqrt(-p / 3), t = Math.acos((3 * q) / p / u) / 3, k = (2 * Math.PI) / 3;
return [
u * Math.cos(t) - ba3,
u * Math.cos(t - k) - ba3,
u * Math.cos(t - 2 * k) - ba3
];
}
}
};
const step = (edge, x) => (x < edge ? 0 : 1);
const smoothStep = (edge, edge2, x) => {
x = clamp01((x - edge) / (edge2 - edge));
return (3 - 2 * x) * x * x;
};
const smootherStep = (edge, edge2, x) => {
x = clamp01((x - edge) / (edge2 - edge));
return x * x * x * (x * (x * 6 - 15) + 10);
};
const expStep = (k, n, x) => 1 - Math.exp(-k * Math.pow(x, n));
exports.DEG2RAD = DEG2RAD;
exports.EPS = EPS;
exports.HALF_PI = HALF_PI;
exports.INV_HALF_PI = INV_HALF_PI;
exports.INV_PI = INV_PI;
exports.INV_TAU = INV_TAU;
exports.PHI = PHI;
exports.PI = PI;
exports.QUARTER_PI = QUARTER_PI;
exports.RAD2DEG = RAD2DEG;
exports.SIXTH = SIXTH;
exports.SIXTH_PI = SIXTH_PI;
exports.SQRT2 = SQRT2;
exports.SQRT2_2 = SQRT2_2;
exports.SQRT2_3 = SQRT2_3;
exports.SQRT3 = SQRT3;
exports.TAU = TAU;
exports.THIRD = THIRD;
exports.THIRD_PI = THIRD_PI;
exports.TWO_THIRD = TWO_THIRD;
exports.absDiff = absDiff;
exports.absInnerAngle = absInnerAngle;
exports.absMax = absMax;
exports.absMin = absMin;
exports.absTheta = absTheta;
exports.addi16 = addi16;
exports.addi32 = addi32;
exports.addi8 = addi8;
exports.addu16 = addu16;
exports.addu32 = addu32;
exports.addu8 = addu8;
exports.andi16 = andi16;
exports.andi32 = andi32;
exports.andi8 = andi8;
exports.andu16 = andu16;
exports.andu32 = andu32;
exports.andu8 = andu8;
exports.angleDist = angleDist;
exports.atan2Abs = atan2Abs;
exports.bounce = bounce;
exports.circular = circular;
exports.clamp = clamp;
exports.clamp01 = clamp01;
exports.clamp11 = clamp11;
exports.classifyCrossing = classifyCrossing;
exports.cosine = cosine;
exports.cossin = cossin;
exports.cot = cot;
exports.csc = csc;
exports.cubicPulse = cubicPulse;
exports.decimated = decimated;
exports.deg = deg;
exports.derivative = derivative;
exports.divi16 = divi16;
exports.divi32 = divi32;
exports.divi8 = divi8;
exports.divu16 = divu16;
exports.divu32 = divu32;
exports.divu8 = divu8;
exports.ease = ease;
exports.eqDelta = eqDelta;
exports.eqDeltaFixed = eqDeltaFixed;
exports.expStep = expStep;
exports.fastCos = fastCos;
exports.fastSin = fastSin;
exports.fit = fit;
exports.fit01 = fit01;
exports.fit10 = fit10;
exports.fit11 = fit11;
exports.fitClamped = fitClamped;
exports.fmod = fmod;
exports.foldback = foldback;
exports.fract = fract;
exports.gain = gain;
exports.impulse = impulse;
exports.inOpenRange = inOpenRange;
exports.inRange = inRange;
exports.isCrossOver = isCrossOver;
exports.isCrossUnder = isCrossUnder;
exports.isMaxima = isMaxima;
exports.isMinima = isMinima;
exports.loc = loc;
exports.lshifti16 = lshifti16;
exports.lshifti32 = lshifti32;
exports.lshifti8 = lshifti8;
exports.lshiftu16 = lshiftu16;
exports.lshiftu32 = lshiftu32;
exports.lshiftu8 = lshiftu8;
exports.max2id = max2id;
exports.max3id = max3id;
exports.max4id = max4id;
exports.maximaIndex = maximaIndex;
exports.maximaIndices = maximaIndices;
exports.min2id = min2id;
exports.min3id = min3id;
exports.min4id = min4id;
exports.minError = minError;
exports.minimaIndex = minimaIndex;
exports.minimaIndices = minimaIndices;
exports.mix = mix;
exports.mixBilinear = mixBilinear;
exports.mixCubic = mixCubic;
exports.mixQuadratic = mixQuadratic;
exports.muli16 = muli16;
exports.muli32 = muli32;
exports.muli8 = muli8;
exports.mulu16 = mulu16;
exports.mulu32 = mulu32;
exports.mulu8 = mulu8;
exports.norm = norm;
exports.normCos = normCos;
exports.noti16 = noti16;
exports.noti32 = noti32;
exports.noti8 = noti8;
exports.notu16 = notu16;
exports.notu32 = notu32;
exports.notu8 = notu8;
exports.ori16 = ori16;
exports.ori32 = ori32;
exports.ori8 = ori8;
exports.oru16 = oru16;
exports.oru32 = oru32;
exports.oru8 = oru8;
exports.parabola = parabola;
exports.quadrant = quadrant;
exports.rad = rad;
exports.roundEps = roundEps;
exports.roundTo = roundTo;
exports.rshifti16 = rshifti16;
exports.rshifti32 = rshifti32;
exports.rshifti8 = rshifti8;
exports.rshiftu16 = rshiftu16;
exports.rshiftu32 = rshiftu32;
exports.rshiftu8 = rshiftu8;
exports.sclamp = sclamp;
exports.sec = sec;
exports.sigmoid = sigmoid;
exports.sigmoid11 = sigmoid11;
exports.sign = sign;
exports.signExtend16 = signExtend16;
exports.signExtend8 = signExtend8;
exports.simplifyRatio = simplifyRatio;
exports.sinc = sinc;
exports.sincos = sincos;
exports.smax = smax;
exports.smin = smin;
exports.smoothStep = smoothStep;
exports.smootherStep = smootherStep;
exports.solveCubic = solveCubic;
exports.solveLinear = solveLinear;
exports.solveQuadratic = solveQuadratic;
exports.step = step;
exports.subi16 = subi16;
exports.subi32 = subi32;
exports.subi8 = subi8;
exports.subu16 = subu16;
exports.subu32 = subu32;
exports.subu8 = subu8;
exports.trunc = trunc;
exports.tween = tween;
exports.wrap = wrap;
exports.wrap01 = wrap01;
exports.wrap11 = wrap11;
exports.xori16 = xori16;
exports.xori32 = xori32;
exports.xori8 = xori8;
exports.xoru16 = xoru16;
exports.xoru32 = xoru32;
exports.xoru8 = xoru8;
Object.defineProperty(exports, '__esModule', { value: true });
}));
!function(t,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a(((t=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,s=a/2,n=a/3,e=a/4,r=a/6,o=1/a,h=1/i,u=1/s,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;var p;(p=t.Crossing||(t.Crossing={}))[p.EQUAL=0]="EQUAL",p[p.FLAT=1]="FLAT",p[p.UNDER=2]="UNDER",p[p.OVER=3]="OVER",p[p.OTHER=4]="OTHER";const x=t=>(t%=i,t<0?i+t:t),g=t=>(t=Math.abs(t),t>a?i-t:t),I=t=>{const a=t*t;return.99940307+a*(.03679168*a-.49558072)},R=t=>{switch((t%=i)<0&&(t=-t),t*u|0){case 0:return I(t);case 1:return-I(a-t);case 2:return-I(t-a);default:return I(i-t)}},T=Math.abs,E=Math.max,v=(t,a,i=1e-6)=>T(t-a)<=i*E(1,T(t),T(a)),A=(t,a,i,s)=>t<i&&a>s,D=(t,a,i,s)=>t>i&&a<s,P=(t,a,i)=>t>a&&a<i,_=(t,a,i)=>t<a&&a>i,q=(t,a,i=0,s=a.length)=>{s--;for(let n=i+1;n<s;n++)if(t(a[n-1],a[n],a[n+1]))return n;return-1},S=(t,a=0,i=t.length)=>q(P,t,a,i);function*w(t,a,i=0,s=a.length){for(;i<s;){const n=t(a,i,s);if(n<0)return;yield n,i=n+1}}const C=t=>t<0?0:t>1?1:t,H=t=>t<-1?-1:t>1?1:t,Q=(t,a,i)=>O(t,a,-i),O=(t,a,i)=>{const s=Math.exp(t*i),n=Math.exp(a*i);return(t*s+a*n)/(s+n)},U=(t,a,i)=>i!==a?(t-a)/(i-a):0,y=255,L=65535,F=t=>(t&=y,128&t?t|~y:t),N=t=>(t&=L,32768&t?t|~L:t),V=(t,a,i,s=16,n=8,e=0,r=1,o=1e-6)=>{if(n<=0)return(e+r)/2;const h=(r-e)/s;let u=e,c=1/0;for(let n=0;n<=s;n++){const s=e+n*h,r=a(i,t(s));if(r<c){if(r<=o)return s;c=r,u=s}}return V(t,a,i,s,n-1,Math.max(u-h,0),Math.min(u+h,1))},j=(t,a,i)=>t+(a-t)*i,G=t=>t-Math.floor(t);t.DEG2RAD=c,t.EPS=1e-6,t.HALF_PI=s,t.INV_HALF_PI=u,t.INV_PI=o,t.INV_TAU=h,t.PHI=d,t.PI=a,t.QUARTER_PI=e,t.RAD2DEG=M,t.SIXTH=1/6,t.SIXTH_PI=r,t.SQRT2=f,t.SQRT2_2=m,t.SQRT2_3=b,t.SQRT3=l,t.TAU=i,t.THIRD=1/3,t.THIRD_PI=n,t.TWO_THIRD=2/3,t.absDiff=(t,a)=>Math.abs(t-a),t.absInnerAngle=g,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=x,t.addi16=(t,a)=>N((0|t)+(0|a)),t.addi32=(t,a)=>(0|t)+(0|a)|0,t.addi8=(t,a)=>F((0|t)+(0|a)),t.addu16=(t,a)=>(t&L)+(a&L)&L,t.addu32=(t,a)=>(t>>>0)+(a>>>0)>>>0,t.addu8=(t,a)=>(t&y)+(a&y)&y,t.andi16=(t,a)=>N((0|t)&(0|a)),t.andi32=(t,a)=>(0|t)&(0|a),t.andi8=(t,a)=>F((0|t)&(0|a)),t.andu16=(t,a)=>t&L&a&L&L,t.andu32=(t,a)=>(t>>>0&a>>>0)>>>0,t.andu8=(t,a)=>t&y&a&y&y,t.angleDist=(t,a)=>g(x(a%i-t%i)),t.atan2Abs=(t,a)=>x(Math.atan2(t,a)),t.bounce=(t,a,i)=>{const n=i*t;return 1-a*Math.sin(n)/n*Math.cos(i*s)},t.circular=t=>(t=1-t,Math.sqrt(1-t*t)),t.clamp=(t,a,i)=>t<a?a:t>i?i:t,t.clamp01=C,t.clamp11=H,t.classifyCrossing=(t,a,i,s,n=1e-6)=>A(t,a,i,s)?3:D(t,a,i,s)?2:v(t,i,n)&&v(a,s,n)?v(t,s,n)?1:0:4,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=1e-6)=>i=>(t(i+a)-t(i))/a,t.divi16=(t,a)=>N((0|t)/(0|a)),t.divi32=(t,a)=>(0|t)/(0|a)|0,t.divi8=(t,a)=>F((0|t)/(0|a)),t.divu16=(t,a)=>(t&L)/(a&L)&L,t.divu32=(t,a)=>(t>>>0)/(a>>>0)>>>0,t.divu8=(t,a)=>(t&y)/(a&y)&y,t.ease=(t,a)=>Math.pow(a,t),t.eqDelta=v,t.eqDeltaFixed=(t,a,i=1e-6)=>T(t-a)<=i,t.expStep=(t,a,i)=>1-Math.exp(-t*Math.pow(i,a)),t.fastCos=R,t.fastSin=t=>R(s-t),t.fit=(t,a,i,s,n)=>s+(n-s)*U(t,a,i),t.fit01=(t,a,i)=>a+(i-a)*C(t),t.fit10=(t,a,i)=>i+(a-i)*C(t),t.fit11=(t,a,i)=>a+(i-a)*(.5+.5*H(t)),t.fitClamped=(t,a,i,s,n)=>s+(n-s)*C(U(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=G,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.isCrossOver=A,t.isCrossUnder=D,t.isMaxima=_,t.isMinima=P,t.loc=(t,a,i)=>Math.sqrt(t*t+a*a-2*t*a*Math.cos(i)),t.lshifti16=(t,a)=>N((0|t)<<(0|a)),t.lshifti32=(t,a)=>(0|t)<<(0|a),t.lshifti8=(t,a)=>F((0|t)<<(0|a)),t.lshiftu16=(t,a)=>(t&L)<<(a&L)&L,t.lshiftu32=(t,a)=>t>>>0<<(a>>>0)>>>0,t.lshiftu8=(t,a)=>(t&y)<<(a&y)&y,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,s)=>t>=a?t>=i?t>=s?0:3:i>=s?2:3:a>=i?a>=s?1:3:i>=s?2:3,t.maximaIndex=(t,a=0,i=t.length)=>q(_,t,a,i),t.maximaIndices=(t,a=0,i=t.length)=>w(S,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,s)=>t<=a?t<=i?t<=s?0:3:i<=s?2:3:a<=i?a<=s?1:3:i<=s?2:3,t.minError=V,t.minimaIndex=S,t.minimaIndices=(t,a=0,i=t.length)=>w(S,t,a,i),t.mix=j,t.mixBilinear=(t,a,i,s,n,e)=>j(j(t,a,n),j(i,s,n),e),t.mixCubic=(t,a,i,s,n)=>{const e=n*n,r=1-n,o=r*r;return t*o*r+3*a*o*n+3*i*e*r+s*e*n},t.mixQuadratic=(t,a,i,s)=>{const n=1-s;return t*n*n+2*a*n*s+i*s*s},t.muli16=(t,a)=>N((0|t)*(0|a)),t.muli32=(t,a)=>(0|t)*(0|a)|0,t.muli8=(t,a)=>F((0|t)*(0|a)),t.mulu16=(t,a)=>(t&L)*(a&L)&L,t.mulu32=(t,a)=>(t>>>0)*(a>>>0)>>>0,t.mulu8=(t,a)=>(t&y)*(a&y)&y,t.norm=U,t.normCos=t=>{const a=t*t;return 1+a*(2*a-4)},t.noti16=t=>N(~t),t.noti32=t=>~t,t.noti8=t=>F(~t),t.notu16=t=>~t&L,t.notu32=t=>~t>>>0,t.notu8=t=>~t&y,t.ori16=(t,a)=>N(0|t|a),t.ori32=(t,a)=>0|t|a,t.ori8=(t,a)=>F(0|t|a),t.oru16=(t,a)=>(t&L|a&L)&L,t.oru32=(t,a)=>(t>>>0|a>>>0)>>>0,t.oru8=(t,a)=>(t&y|a&y)&y,t.parabola=(t,a)=>Math.pow(4*a*(1-a),t),t.quadrant=t=>x(t)*u|0,t.rad=t=>t*c,t.roundEps=(t,a=1e-6)=>{const i=G(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)=>N((0|t)>>(0|a)),t.rshifti32=(t,a)=>(0|t)>>(0|a),t.rshifti8=(t,a)=>F((0|t)>>(0|a)),t.rshiftu16=(t,a)=>(t&L)>>>(a&L)&L,t.rshiftu32=(t,a)=>t>>>0>>>(a>>>0)>>>0,t.rshiftu8=(t,a)=>(t&y)>>>(a&y)&y,t.sclamp=(t,a,i,s)=>Q(O(t,a,s),i,s),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=1e-6)=>t>a?1:t<-a?-1:0,t.signExtend16=N,t.signExtend8=F,t.simplifyRatio=(t,a)=>{let i=Math.abs(t),s=Math.abs(a);for(;;){if(i<s){const t=i;i=s,s=t}const n=i%s;if(!n)return[t/s,a/s];i=n}},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=O,t.smin=Q,t.smoothStep=(t,a,i)=>(3-2*(i=C((i-t)/(a-t))))*i*i,t.smootherStep=(t,a,i)=>(i=C((i-t)/(a-t)))*i*i*(i*(6*i-15)+10),t.solveCubic=(t,a,i,s,n=1e-9)=>{const e=t*t,r=a*a,o=a/(3*t),h=(3*t*i-r)/(3*e),u=(2*r*a-9*t*a*i+27*e*s)/(27*e*t);if(Math.abs(h)<n)return[Math.cbrt(-u)-o];if(Math.abs(u)<n)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)<n)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)=>-a/t,t.solveQuadratic=(t,a,i,s=1e-9)=>{const n=2*t;let e=a*a-4*t*i;return e<0?[]:e<s?[-a/n]:[(-a-(e=Math.sqrt(e)))/n,(-a+e)/n]},t.step=(t,a)=>a<t?0:1,t.subi16=(t,a)=>N((0|t)-(0|a)),t.subi32=(t,a)=>(0|t)-(0|a)|0,t.subi8=(t,a)=>F((0|t)-(0|a)),t.subu16=(t,a)=>(t&L)-(a&L)&L,t.subu32=(t,a)=>(t>>>0)-(a>>>0)>>>0,t.subu8=(t,a)=>(t&y)-(a&y)&y,t.trunc=t=>t<0?Math.ceil(t):Math.floor(t),t.tween=(t,a,i)=>s=>j(a,i,t(s)),t.wrap=(t,a,i)=>t<a?t-a+i:t>=i?t-i+a: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.xori16=(t,a)=>N((0|t)^(0|a)),t.xori32=(t,a)=>(0|t)^(0|a),t.xori8=(t,a)=>F((0|t)^(0|a)),t.xoru16=(t,a)=>(t&L^a&L)&L,t.xoru32=(t,a)=>(t>>>0^a>>>0)>>>0,t.xoru8=(t,a)=>(t&y^a&y)&y,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "@thi.ng/math",
"version": "1.4.1",
"version": "1.4.2",
"description": "Assorted common math functions & utilities",

@@ -17,18 +17,19 @@ "module": "./index.js",

"scripts": {
"build": "yarn clean && yarn build:es6 && yarn build:bundle",
"build": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module",
"build:release": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module all",
"build:es6": "tsc --declaration",
"build:bundle": "../../scripts/bundle-module",
"test": "rimraf build && tsc -p test/tsconfig.json && nyc mocha build/test/*.js",
"build:test": "rimraf build && tsc -p test/tsconfig.json",
"test": "yarn build:test && mocha build/test/*.js",
"cover": "yarn build:test && nyc mocha build/test/*.js && nyc report --reporter=lcov",
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib",
"cover": "yarn test && nyc report --reporter=lcov",
"doc": "node_modules/.bin/typedoc --mode modules --out doc --ignoreCompilerErrors src",
"pub": "yarn build && yarn publish --access public"
"pub": "yarn build:release && yarn publish --access public"
},
"devDependencies": {
"@types/mocha": "^5.2.6",
"@types/node": "^12.0.8",
"@types/node": "^12.6.3",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.2"
"typescript": "^3.5.3"
},

@@ -48,3 +49,3 @@ "keywords": [

"sideEffects": false,
"gitHead": "47075afc37f3a16adee7c903a2935304c7cf5daf"
"gitHead": "53eec7988c378fc37ae140e7174f36ef9b6208fe"
}
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