untitled-rhythm-game/js/libcubicbezier.js
2025-04-18 09:42:30 +08:00

1 line
1.1 KiB
JavaScript

!function(){function r(r,n){return 1-3*n+3*r}function n(r,n){return 3*n-6*r}function t(t,u,e){return((r(u,e)*t+n(u,e))*t+3*u)*t}function u(t,u,e){return 3*r(u,e)*t*t+2*n(u,e)*t+3*u}function e(r){return r}function Bezier(r,n,f,i){if(!(0<=r&&r<=1&&0<=f&&f<=1))throw new Error("Bezier x value must be in [0, 1] range");if(r===n&&f===i)return e;for(var a=new(o?Float32Array:Array)(11),c=0;c<11;++c)a[c]=t(.1*c,r,f);return function(e){return 0===e||1===e?e:t(function(n){for(var i,c,e=0,o=1;10!==o&&a[o]<=n;++o)e+=.1;return.001<=(c=u(i=e+(n-a[--o])/(a[o+1]-a[o])*.1,r,f))?function(r,n,e,o){for(var i,f=0;f<4;++f){if(0===(i=u(n,e,o)))return n;n-=(t(n,e,o)-r)/i}return n}(n,i,r,f):0===c?i:function(r,n,u,e,o){for(var f,i,a=0;0<(f=t(i=n+(u-n)/2,e,o)-r)?u=i:n=i,1e-7<Math.abs(f)&&++a<10;);return i}(n,e,e+.1,r,f)}(e),n,i)}}var o="function"==typeof Float32Array;"object"==typeof exports&&"undefined"!=typeof module?module.exports={Bezier:Bezier}:"function"==typeof define&&define.amd?define([],Bezier):("undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window).Bezier=Bezier}();