@thi.ng/math
Advanced tools
Comparing version 2.2.2 to 3.0.0
36
api.d.ts
@@ -21,21 +21,19 @@ export declare const PI: number; | ||
export declare let EPS: number; | ||
export declare enum Crossing { | ||
/** | ||
* lines A & B are equal | ||
*/ | ||
EQUAL = 0, | ||
/** | ||
* lines A & B are flat (all same values) | ||
*/ | ||
FLAT = 1, | ||
/** | ||
* line A crossed under B | ||
*/ | ||
UNDER = 2, | ||
/** | ||
* line A crossed over B | ||
*/ | ||
OVER = 3, | ||
OTHER = 4 | ||
} | ||
export declare type Crossing = | ||
/** | ||
* lines A & B are equal | ||
*/ | ||
"equal" | ||
/** | ||
* lines A & B are flat (all same values) | ||
*/ | ||
| "flat" | ||
/** | ||
* line A crossed under B | ||
*/ | ||
| "under" | ||
/** | ||
* line A crossed over B | ||
*/ | ||
| "over" | "other"; | ||
//# sourceMappingURL=api.d.ts.map |
20
api.js
@@ -21,21 +21,1 @@ export const PI = Math.PI; | ||
export let EPS = 1e-6; | ||
export var Crossing; | ||
(function (Crossing) { | ||
/** | ||
* lines A & B are equal | ||
*/ | ||
Crossing[Crossing["EQUAL"] = 0] = "EQUAL"; | ||
/** | ||
* lines A & B are flat (all same values) | ||
*/ | ||
Crossing[Crossing["FLAT"] = 1] = "FLAT"; | ||
/** | ||
* line A crossed under B | ||
*/ | ||
Crossing[Crossing["UNDER"] = 2] = "UNDER"; | ||
/** | ||
* line A crossed over B | ||
*/ | ||
Crossing[Crossing["OVER"] = 3] = "OVER"; | ||
Crossing[Crossing["OTHER"] = 4] = "OTHER"; | ||
})(Crossing || (Crossing = {})); |
@@ -6,32 +6,41 @@ # Change Log | ||
## [2.2.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.2.1...@thi.ng/math@2.2.2) (2020-12-07) | ||
# [3.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.2.2...@thi.ng/math@3.0.0) (2020-12-22) | ||
**Note:** Version bump only for package @thi.ng/math | ||
### Bug Fixes | ||
* **math:** fix [#256](https://github.com/thi-ng/umbrella/issues/256) replace enum w/ type alias ([8f00375](https://github.com/thi-ng/umbrella/commit/8f00375722ff3e207f1711229acff69c3bd1343f)) | ||
### Code Refactoring | ||
## [2.2.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.2.0...@thi.ng/math@2.2.1) (2020-11-26) | ||
* **math:** update/fix sigmoid() behavior ([07a278f](https://github.com/thi-ng/umbrella/commit/07a278fdd82004610aa9b7acb585c3c841af24ba)) | ||
**Note:** Version bump only for package @thi.ng/math | ||
### Features | ||
* **math:** add gaussian() ([138befe](https://github.com/thi-ng/umbrella/commit/138befe1f2d14eb9a4fb3829179b8d03d49e6bbc)) | ||
* **math:** add more parametric T-norms ([38bd40e](https://github.com/thi-ng/umbrella/commit/38bd40e1595e318c6472a526e03c8c8a06ebf396)) | ||
* **math:** add various T-norm functions ([ab4a810](https://github.com/thi-ng/umbrella/commit/ab4a810981c08c54365d5ea3212cd465d2589cf0)) | ||
### BREAKING CHANGES | ||
# [2.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.1.1...@thi.ng/math@2.2.0) (2020-11-24) | ||
* **math:** replace Crossing enum w/ type alias | ||
* **math:** add new bias arg for sigmoid() to satisfy more use cases. | ||
Use sigmoid01() for old behavior. | ||
- add/update docstrings | ||
- add desmos links | ||
### Features | ||
* **math:** add generalized schlick curve ([4b6eb84](https://github.com/thi-ng/umbrella/commit/4b6eb844f3588679ee78d0e7d60b52cfcec8eb87)) | ||
# [2.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.1.1...@thi.ng/math@2.2.0) (2020-11-24) | ||
## [2.1.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.1.0...@thi.ng/math@2.1.1) (2020-09-22) | ||
### Features | ||
**Note:** Version bump only for package @thi.ng/math | ||
* **math:** add generalized schlick curve ([4b6eb84](https://github.com/thi-ng/umbrella/commit/4b6eb844f3588679ee78d0e7d60b52cfcec8eb87)) | ||
@@ -53,26 +62,2 @@ | ||
## [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) | ||
**Note:** Version bump only for package @thi.ng/math | ||
## [2.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.0.2...@thi.ng/math@2.0.3) (2020-08-17) | ||
**Note:** Version bump only for package @thi.ng/math | ||
## [2.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@2.0.1...@thi.ng/math@2.0.2) (2020-08-16) | ||
**Note:** Version bump only for package @thi.ng/math | ||
# [2.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@1.7.13...@thi.ng/math@2.0.0) (2020-07-17) | ||
@@ -79,0 +64,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Crossing, EPS } from "./api"; | ||
import { EPS } from "./api"; | ||
import { eqDelta } from "./eqdelta"; | ||
@@ -52,14 +52,10 @@ /** | ||
*/ | ||
export const classifyCrossing = (a1, a2, b1, b2, eps = EPS) => { | ||
if (isCrossOver(a1, a2, b1, b2)) { | ||
return Crossing.OVER; | ||
} | ||
else if (isCrossUnder(a1, a2, b1, b2)) { | ||
return Crossing.UNDER; | ||
} | ||
return eqDelta(a1, b1, eps) && eqDelta(a2, b2, eps) | ||
? eqDelta(a1, b2, eps) | ||
? Crossing.FLAT | ||
: Crossing.EQUAL | ||
: Crossing.OTHER; | ||
}; | ||
export const classifyCrossing = (a1, a2, b1, b2, eps = EPS) => eqDelta(a1, b1, eps) && eqDelta(a2, b2, eps) | ||
? eqDelta(a1, b2, eps) | ||
? "flat" | ||
: "equal" | ||
: isCrossOver(a1, a2, b1, b2) | ||
? "over" | ||
: isCrossUnder(a1, a2, b1, b2) | ||
? "under" | ||
: "other"; |
@@ -25,9 +25,2 @@ 'use strict'; | ||
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 = {})); | ||
@@ -88,15 +81,11 @@ const absDiff = (x, y) => Math.abs(x - y); | ||
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 exports.Crossing.OVER; | ||
} | ||
else if (isCrossUnder(a1, a2, b1, b2)) { | ||
return exports.Crossing.UNDER; | ||
} | ||
return eqDelta(a1, b1, eps) && eqDelta(a2, b2, eps) | ||
? eqDelta(a1, b2, eps) | ||
? exports.Crossing.FLAT | ||
: exports.Crossing.EQUAL | ||
: exports.Crossing.OTHER; | ||
}; | ||
const classifyCrossing = (a1, a2, b1, b2, eps = EPS) => eqDelta(a1, b1, eps) && eqDelta(a2, b2, eps) | ||
? eqDelta(a1, b2, eps) | ||
? "flat" | ||
: "equal" | ||
: isCrossOver(a1, a2, b1, b2) | ||
? "over" | ||
: isCrossUnder(a1, a2, b1, b2) | ||
? "under" | ||
: "other"; | ||
@@ -354,4 +343,5 @@ const isMinima = (a, b, c) => a > b && b < c; | ||
}; | ||
const sigmoid = (k, t) => 1 / (1 + Math.exp(-k * (2 * t - 1))); | ||
const sigmoid11 = (k, t) => 1 / (1 + Math.exp(-k * t)); | ||
const sigmoid = (bias, k, t) => t != bias ? 1 / (1 + Math.exp(-k * (t - bias))) : 0.5; | ||
const sigmoid01 = (k, t) => sigmoid(0.5, k, t); | ||
const sigmoid11 = (k, t) => sigmoid(0, k, t); | ||
const schlick = (a, b, t) => t <= b | ||
@@ -361,2 +351,3 @@ ? (b * t) / (t + a * (b - t) + EPS) | ||
const expFactor = (a, b, num) => (b / a) ** (1 / num); | ||
const gaussian = (bias, sigma, t) => Math.exp(-((t - bias) ** 2) / (2 * sigma * sigma)); | ||
@@ -526,2 +517,3 @@ const fmod = (a, b) => a - b * Math.floor(a / b); | ||
exports.gain = gain; | ||
exports.gaussian = gaussian; | ||
exports.impulse = impulse; | ||
@@ -598,2 +590,3 @@ exports.inOpenRange = inOpenRange; | ||
exports.sigmoid = sigmoid; | ||
exports.sigmoid01 = sigmoid01; | ||
exports.sigmoid11 = sigmoid11; | ||
@@ -600,0 +593,0 @@ exports.sign = sign; |
@@ -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,l=Math.SQRT2,f=Math.sqrt(3),m=l/2,b=f/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,k=t=>32768&(t&=V)?t|~V:t,G=(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 G(t,i,a,n,s-1,Math.max(u-h,0),Math.min(u+h,1))},X=(t,i,a)=>t+(i-t)*a,Z=t=>(t=1-t,Math.sqrt(1-t*t)),B=t=>1-Z(1-t),W=t=>t-Math.floor(t),z=(t,i)=>0!==i?t/i: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=i,t.QUARTER_PI=r,t.RAD2DEG=M,t.SIXTH=1/6,t.SIXTH_PI=e,t.SQRT2=l,t.SQRT2_2=m,t.SQRT2_3=b,t.SQRT3=f,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)=>k((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)=>k((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=Z,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)=>k((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=W,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.invCircular=B,t.isCrossOver=A,t.isCrossUnder=q,t.isMaxima=P,t.isMinima=H,t.lens=(t,i,a)=>{const n=i>0?B:Z,s=1-t,r=a<=t?n(a/t)*t:1-n((1-a)/s)*s;return X(a,r,Math.abs(i))},t.loc=(t,i,a)=>Math.sqrt(t*t+i*i-2*t*i*Math.cos(a)),t.lshifti16=(t,i)=>k((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=G,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=X,t.mixBilinear=(t,i,a,n,s,r)=>X(X(t,i,s),X(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)=>k((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=>k(~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)=>k(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=W(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)=>k((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=z,t.schlick=(t,i,a)=>a<=i?i*a/(a+t*(i-a)+p):(1-i)*(a-1)/(1-a-t*(i-a)+p)+1,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=k,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)=>z(-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)=>k((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=>X(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)=>k((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,e=a/4,r=a/6,o=1/a,u=1/i,h=1/n,c=a/180,M=180/a,d=(1+Math.sqrt(5))/2,l=Math.SQRT2,f=Math.sqrt(3),m=l/2,b=f/2;let p=1e-6;const x=t=>(t%=i)<0?i+t:t,g=t=>(t=Math.abs(t))>a?i-t:t,I=t=>{const a=t*t;return.99940307+a*(.03679168*a-.49558072)},T=t=>{switch((t%=i)<0&&(t=-t),t*h|0){case 0:return I(t);case 1:return-I(a-t);case 2:return-I(t-a);default:return I(i-t)}},v=Math.abs,R=Math.max,q=(t,a,i=p)=>v(t-a)<=i,D=q,P=(t,a,i,n)=>t<i&&a>n,S=(t,a,i,n)=>t>i&&a<n,_=(t,a,i)=>t>a&&a<i,w=(t,a,i)=>t<a&&a>i,C=(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},H=(t,a=0,i=t.length)=>C(_,t,a,i);function*A(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 y=t=>t<0?0:t>1?1:t,E=t=>t<-1?-1:t>1?1:t,Q=(t,a)=>0!==t?0!==a?Math.min(t,a):t:a,N=(t,a,i)=>O(t,a,-i),O=(t,a,i)=>{const n=Math.exp(t*i),s=Math.exp(a*i);return(t*n+a*s)/(n+s)},F=(t,a,i)=>i!==a?(t-a)/(i-a):0,U=255,L=65535,V=t=>128&(t&=U)?t|~U:t,j=t=>32768&(t&=L)?t|~L:t,k=(t,a,i,n=16,s=8,e=0,r=1,o=p)=>{if(s<=0)return(e+r)/2;const u=(r-e)/n;let h=e,c=1/0;for(let s=0;s<=n;s++){const n=e+s*u,r=a(i,t(n));if(r<c){if(r<=o)return n;c=r,h=n}}return k(t,a,i,n,s-1,Math.max(h-u,0),Math.min(h+u,1))},G=(t,a,i)=>t+(a-t)*i,X=t=>(t=1-t,Math.sqrt(1-t*t)),Z=t=>1-X(1-t),B=(t,a,i)=>i!=t?1/(1+Math.exp(-a*(i-t))):.5,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=h,t.INV_PI=o,t.INV_TAU=u,t.PHI=d,t.PI=a,t.QUARTER_PI=e,t.RAD2DEG=M,t.SIXTH=1/6,t.SIXTH_PI=r,t.SQRT2=l,t.SQRT2_2=m,t.SQRT2_3=b,t.SQRT3=f,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=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)=>j((0|t)+(0|a)),t.addi32=(t,a)=>(0|t)+(0|a)|0,t.addi8=(t,a)=>V((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&U)+(a&U)&U,t.andi16=(t,a)=>j((0|t)&(0|a)),t.andi32=(t,a)=>(0|t)&(0|a),t.andi8=(t,a)=>V((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&U&a&U&U,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 s=i*t;return 1-a*Math.sin(s)/s*Math.cos(i*n)},t.circular=X,t.clamp=(t,a,i)=>t<a?a:t>i?i:t,t.clamp01=y,t.clamp05=t=>t<0?0:t>.5?.5:t,t.clamp11=E,t.classifyCrossing=(t,a,i,n,s=p)=>q(t,i,s)&&q(a,n,s)?q(t,n,s)?"flat":"equal":P(t,a,i,n)?"over":S(t,a,i,n)?"under":"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)=>j((0|t)/(0|a)),t.divi32=(t,a)=>(0|t)/(0|a)|0,t.divi8=(t,a)=>V((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&U)/(a&U)&U,t.ease=(t,a)=>Math.pow(a,t),t.eqDelta=q,t.eqDeltaFixed=D,t.eqDeltaScaled=(t,a,i=p)=>v(t-a)<=i*R(1,v(t),v(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=T,t.fastSin=t=>T(n-t),t.fit=(t,a,i,n,s)=>n+(s-n)*F(t,a,i),t.fit01=(t,a,i)=>a+(i-a)*y(t),t.fit10=(t,a,i)=>i+(a-i)*y(t),t.fit11=(t,a,i)=>a+(i-a)*(.5+.5*E(t)),t.fitClamped=(t,a,i,n,s)=>n+(s-n)*y(F(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.gaussian=(t,a,i)=>Math.exp(-((i-t)**2)/(2*a*a)),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=Z,t.isCrossOver=P,t.isCrossUnder=S,t.isMaxima=w,t.isMinima=_,t.lens=(t,a,i)=>{const n=a>0?Z:X,s=1-t,e=i<=t?n(i/t)*t:1-n((1-i)/s)*s;return G(i,e,Math.abs(a))},t.loc=(t,a,i)=>Math.sqrt(t*t+a*a-2*t*a*Math.cos(i)),t.lshifti16=(t,a)=>j((0|t)<<(0|a)),t.lshifti32=(t,a)=>(0|t)<<(0|a),t.lshifti8=(t,a)=>V((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&U)<<(a&U)&U,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)=>C(w,t,a,i),t.maximaIndices=(t,a=0,i=t.length)=>A(H,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=k,t.minNonZero2=Q,t.minNonZero3=(t,a,i)=>Q(Q(t,a),i),t.minimaIndex=H,t.minimaIndices=(t,a=0,i=t.length)=>A(H,t,a,i),t.mix=G,t.mixBilinear=(t,a,i,n,s,e)=>G(G(t,a,s),G(i,n,s),e),t.mixCubic=(t,a,i,n,s)=>{const e=s*s,r=1-s,o=r*r;return t*o*r+3*a*o*s+3*i*e*r+n*e*s},t.mixCubicHermite=(t,a,i,n,s)=>{const e=s-1,r=s*s,o=e*e;return(1+2*s)*o*t+s*o*a+r*(3-2*s)*i+r*e*n},t.mixHermite=(t,a,i,n,s)=>{const e=.5*(i-t),r=1.5*(a-i)+.5*(n-t);return((r*s+t-a+e-r)*s+e)*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)=>j((0|t)*(0|a)),t.muli32=(t,a)=>(0|t)*(0|a)|0,t.muli8=(t,a)=>V((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&U)*(a&U)&U,t.norm=F,t.normCos=t=>{const a=t*t;return 1+a*(2*a-4)},t.noti16=t=>j(~t),t.noti32=t=>~t,t.noti8=t=>V(~t),t.notu16=t=>~t&L,t.notu32=t=>~t>>>0,t.notu8=t=>~t&U,t.ori16=(t,a)=>j(0|t|a),t.ori32=(t,a)=>0|t|a,t.ori8=(t,a)=>V(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&U|a&U)&U,t.parabola=(t,a)=>Math.pow(4*a*(1-a),t),t.quadrant=t=>x(t)*h|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)=>j((0|t)>>(0|a)),t.rshifti32=(t,a)=>(0|t)>>(0|a),t.rshifti8=(t,a)=>V((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&U)>>>(a&U)&U,t.safeDiv=z,t.schlick=(t,a,i)=>i<=a?a*i/(i+t*(a-i)+p):(1-a)*(i-1)/(1-i-t*(a-i)+p)+1,t.sclamp=(t,a,i,n)=>N(O(t,a,n),i,n),t.sec=t=>1/Math.cos(t),t.sigmoid=B,t.sigmoid01=(t,a)=>B(.5,t,a),t.sigmoid11=(t,a)=>B(0,t,a),t.sign=(t,a=p)=>t>a?1:t<-a?-1:0,t.signExtend16=j,t.signExtend8=V,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=O,t.smin=N,t.smoothStep=(t,a,i)=>(3-2*(i=y((i-t)/(a-t))))*i*i,t.smootherStep=(t,a,i)=>(i=y((i-t)/(a-t)))*i*i*(i*(6*i-15)+10),t.solveCubic=(t,a,i,n,s=1e-9)=>{const e=t*t,r=a*a,o=a/(3*t),u=(3*t*i-r)/(3*e),h=(2*r*a-9*t*a*i+27*e*n)/(27*e*t);if(Math.abs(u)<s)return[Math.cbrt(-h)-o];if(Math.abs(h)<s)return u<0?[-Math.sqrt(-u)-o,-o,Math.sqrt(-u)-o]:[-o];{const t=h*h/4+u*u*u/27;if(Math.abs(t)<s)return[-1.5*h/u-o,3*h/u-o];if(t>0){const a=Math.cbrt(-h/2-Math.sqrt(t));return[a-u/(3*a)-o]}{const t=2*Math.sqrt(-u/3),a=Math.acos(3*h/u/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 e=a*a-4*t*i;return e<0?[]:e<n?[-a/s]:(e=Math.sqrt(e),[(-a-e)/s,(-a+e)/s])},t.step=(t,a)=>a<t?0:1,t.subi16=(t,a)=>j((0|t)-(0|a)),t.subi32=(t,a)=>(0|t)-(0|a)|0,t.subi8=(t,a)=>V((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&U)-(a&U)&U,t.tangentCardinal=(t,a,i=.5,n=0,s=2)=>i*((a-t)/(s-n)),t.tangentDiff3=(t,a,i,n=0,s=1,e=2)=>.5*((i-a)/(e-s)+(a-t)/(s-n)),t.trunc=t=>t<0?Math.ceil(t):Math.floor(t),t.tween=(t,a,i)=>n=>G(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)=>j((0|t)^(0|a)),t.xori32=(t,a)=>(0|t)^(0|a),t.xori8=(t,a)=>V((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&U^a&U)&U,Object.defineProperty(t,"__esModule",{value:!0})})); |
46
mix.d.ts
import type { FnN, FnN2, FnN3, FnN4, FnN5, FnN6 } from "@thi.ng/api"; | ||
/** | ||
* Linear interpolation without clamping. Computes `a + (b - a) * t` | ||
* | ||
* @param a - start value | ||
* @param b - end value | ||
* @param t - interpolation factor [0..1] | ||
*/ | ||
export declare const mix: FnN3; | ||
@@ -104,5 +111,5 @@ /** | ||
/** | ||
* HOF interpolator. Takes a timing function `f` and interval `[from, | ||
* to]`. Returns function which takes normalized time as single arg and | ||
* returns interpolated value. | ||
* HOF interpolator. Takes a timing function `f` and interval `[from,to]`. | ||
* Returns function which takes normalized time (in [0,1] range) as single arg | ||
* and returns interpolated value. | ||
* | ||
@@ -185,11 +192,23 @@ * @param f - | ||
/** | ||
* Sigmoid function for inputs in [0..1] interval. | ||
* Sigmoid function for inputs arounds center bias. | ||
* | ||
* @param k - | ||
* @param t - | ||
* @remarks | ||
* Updated in v3.0.0 to add bias value to satisfy more use cases. Use | ||
* {@link sigmoid01} for old behavior. | ||
* | ||
* @param bias - center value (for which result = 0.5) | ||
* @param k - steepness | ||
* @param t - input value | ||
*/ | ||
export declare const sigmoid: FnN2; | ||
export declare const sigmoid: FnN3; | ||
/** | ||
* Sigmoid function for inputs in [-1..+1] interval. | ||
* Sigmoid function for inputs in [0..1] interval. Center bias = 0.5. | ||
* | ||
* @param k - steepness | ||
* @param t - input value | ||
*/ | ||
export declare const sigmoid01: FnN3; | ||
/** | ||
* Sigmoid function for inputs in [-1..+1] interval. Center bias = 0 | ||
* | ||
* @param k - | ||
@@ -222,2 +241,13 @@ * @param t - | ||
export declare const expFactor: FnN3; | ||
/** | ||
* Computes gaussian bell curve for given center `bias` and `sigma` (spread). | ||
* | ||
* @remarks | ||
* Interactive graph: https://www.desmos.com/calculator/aq6hdzxprv | ||
* | ||
* @param bias | ||
* @param sigma | ||
* @param t | ||
*/ | ||
export declare const gaussian: FnN3; | ||
//# sourceMappingURL=mix.d.ts.map |
48
mix.js
import { EPS, HALF_PI, PI } from "./api"; | ||
/** | ||
* Linear interpolation without clamping. Computes `a + (b - a) * t` | ||
* | ||
* @param a - start value | ||
* @param b - end value | ||
* @param t - interpolation factor [0..1] | ||
*/ | ||
export const mix = (a, b, t) => a + (b - a) * t; | ||
@@ -125,5 +132,5 @@ /** | ||
/** | ||
* HOF interpolator. Takes a timing function `f` and interval `[from, | ||
* to]`. Returns function which takes normalized time as single arg and | ||
* returns interpolated value. | ||
* HOF interpolator. Takes a timing function `f` and interval `[from,to]`. | ||
* Returns function which takes normalized time (in [0,1] range) as single arg | ||
* and returns interpolated value. | ||
* | ||
@@ -226,15 +233,27 @@ * @param f - | ||
/** | ||
* Sigmoid function for inputs in [0..1] interval. | ||
* Sigmoid function for inputs arounds center bias. | ||
* | ||
* @param k - | ||
* @param t - | ||
* @remarks | ||
* Updated in v3.0.0 to add bias value to satisfy more use cases. Use | ||
* {@link sigmoid01} for old behavior. | ||
* | ||
* @param bias - center value (for which result = 0.5) | ||
* @param k - steepness | ||
* @param t - input value | ||
*/ | ||
export const sigmoid = (k, t) => 1 / (1 + Math.exp(-k * (2 * t - 1))); | ||
export const sigmoid = (bias, k, t) => t != bias ? 1 / (1 + Math.exp(-k * (t - bias))) : 0.5; | ||
/** | ||
* Sigmoid function for inputs in [-1..+1] interval. | ||
* Sigmoid function for inputs in [0..1] interval. Center bias = 0.5. | ||
* | ||
* @param k - steepness | ||
* @param t - input value | ||
*/ | ||
export const sigmoid01 = (k, t) => sigmoid(0.5, k, t); | ||
/** | ||
* Sigmoid function for inputs in [-1..+1] interval. Center bias = 0 | ||
* | ||
* @param k - | ||
* @param t - | ||
*/ | ||
export const sigmoid11 = (k, t) => 1 / (1 + Math.exp(-k * t)); | ||
export const sigmoid11 = (k, t) => sigmoid(0, k, t); | ||
/** | ||
@@ -265,1 +284,12 @@ * Generalized Schlick bias gain curve, based on: | ||
export const expFactor = (a, b, num) => (b / a) ** (1 / num); | ||
/** | ||
* Computes gaussian bell curve for given center `bias` and `sigma` (spread). | ||
* | ||
* @remarks | ||
* Interactive graph: https://www.desmos.com/calculator/aq6hdzxprv | ||
* | ||
* @param bias | ||
* @param sigma | ||
* @param t | ||
*/ | ||
export const gaussian = (bias, sigma, t) => Math.exp(-((t - bias) ** 2) / (2 * sigma * sigma)); |
{ | ||
"name": "@thi.ng/math", | ||
"version": "2.2.2", | ||
"version": "3.0.0", | ||
"description": "Assorted common math functions & utilities", | ||
@@ -42,13 +42,13 @@ "module": "./index.js", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@microsoft/api-extractor": "^7.12.0", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^14.6.1", | ||
"@microsoft/api-extractor": "^7.12.1", | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.14", | ||
"mocha": "^8.2.1", | ||
"nyc": "^15.1.0", | ||
"ts-node": "^9.0.0", | ||
"ts-node": "^9.1.1", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.1.2" | ||
"typescript": "^4.1.3" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/api": "^6.13.4" | ||
"@thi.ng/api": "^6.13.5" | ||
}, | ||
@@ -71,2 +71,3 @@ "files": [ | ||
"solver", | ||
"t-norm", | ||
"trigonometry", | ||
@@ -82,3 +83,3 @@ "typescript" | ||
}, | ||
"gitHead": "b735cef6fb43db0f54ea8bb2a840d279225e95e0" | ||
"gitHead": "8fed74edc94bfb65f84e8982e6724619bbfbd1d0" | ||
} |
@@ -54,3 +54,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (gzipped, pre-treeshake): ESM: 3.60 KB / CJS: 4.16 KB / UMD: 3.43 KB | ||
Package sizes (gzipped, pre-treeshake): ESM: 3.56 KB / CJS: 4.13 KB / UMD: 3.40 KB | ||
@@ -57,0 +57,0 @@ ## Dependencies |
@@ -16,7 +16,7 @@ import type { FnN2, FnN3 } from "@thi.ng/api"; | ||
* @param x - test value | ||
* @returns 0, if `x < edge1`, 1 if `x > edge2`, else sigmoid interpolation | ||
* @returns 0, if `x < edge1`, 1 if `x > edge2`, else S-curve polynomial interpolation | ||
*/ | ||
export declare const smoothStep: FnN3; | ||
/** | ||
* Similar to {@link smoothStep} but using different polynomial. | ||
* Similar to {@link smoothStep} but using different, higher degree polynomial. | ||
* | ||
@@ -29,4 +29,7 @@ * @param edge - | ||
/** | ||
* Exponential ramp with variable shape, e.g. | ||
* Exponential ramp with variable shape | ||
* | ||
* @remarks | ||
* Example configurations: | ||
* | ||
* - S-curve: k=8, n=4 | ||
@@ -37,2 +40,4 @@ * - Step near 1.0: k=8, n=20 | ||
* | ||
* Interactive graph: https://www.desmos.com/calculator/gcnuyppycz | ||
* | ||
* @param k - | ||
@@ -39,0 +44,0 @@ * @param n - |
11
step.js
@@ -16,3 +16,3 @@ import { clamp01 } from "./interval"; | ||
* @param x - test value | ||
* @returns 0, if `x < edge1`, 1 if `x > edge2`, else sigmoid interpolation | ||
* @returns 0, if `x < edge1`, 1 if `x > edge2`, else S-curve polynomial interpolation | ||
*/ | ||
@@ -24,3 +24,3 @@ export const smoothStep = (edge, edge2, x) => { | ||
/** | ||
* Similar to {@link smoothStep} but using different polynomial. | ||
* Similar to {@link smoothStep} but using different, higher degree polynomial. | ||
* | ||
@@ -36,4 +36,7 @@ * @param edge - | ||
/** | ||
* Exponential ramp with variable shape, e.g. | ||
* Exponential ramp with variable shape | ||
* | ||
* @remarks | ||
* Example configurations: | ||
* | ||
* - S-curve: k=8, n=4 | ||
@@ -44,2 +47,4 @@ * - Step near 1.0: k=8, n=20 | ||
* | ||
* Interactive graph: https://www.desmos.com/calculator/gcnuyppycz | ||
* | ||
* @param k - | ||
@@ -46,0 +51,0 @@ * @param n - |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172320
2638
Updated@thi.ng/api@^6.13.5