2 lines
953 B
JavaScript
2 lines
953 B
JavaScript
|
var y=4,z=.001,_=1e-7,d=10,l=11,S=1/(l-1),h=typeof Float32Array=="function";function N(e,r){return 1-3*r+3*e}function E(e,r){return 3*r-6*e}function O(e){return 3*e}function c(e,r,n){return((N(r,n)*e+E(r,n))*e+O(r))*e}function b(e,r,n){return 3*N(r,n)*e*e+2*E(r,n)*e+O(r)}function B(e,r,n,t,o){var i,u,I=0;do u=r+(n-r)/2,i=c(u,t,o)-e,i>0?n=u:r=u;while(Math.abs(i)>_&&++I<d);return u}function F(e,r,n,t){for(var o=0;o<y;++o){var i=b(r,n,t);if(i===0)return r;var u=c(r,n,t)-e;r-=u/i}return r}function R(e){return e}var M=function(r,n,t,o){if(!(0<=r&&r<=1&&0<=t&&t<=1))throw new Error("bezier x values must be in [0, 1] range");if(r===n&&t===o)return R;for(var i=h?new Float32Array(l):new Array(l),u=0;u<l;++u)i[u]=c(u*S,r,t);function I(v){for(var a=0,f=1,g=l-1;f!==g&&i[f]<=v;++f)a+=S;--f;var w=(v-i[f])/(i[f+1]-i[f]),p=a+w*S,s=b(p,r,t);return s>=z?F(v,p,r,t):s===0?p:B(v,a,a+S,r,t)}return function(a){return a===0?0:a===1?1:c(I(a),n,o)}};export{M as s};
|