UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 960 B
const t={DEG_TO_RAD:Math.PI/180,RAD_TO_DEG:180/Math.PI,clamp:(t,e,o)=>t>=o?o:t<=e?e:t,intToBytes24:t=>[t>>16&255,t>>8&255,255&t],intToBytes32:t=>[t>>24&255,t>>16&255,t>>8&255,255&t],bytesToInt24:(t,e,o)=>(t.length&&(o=t[2],e=t[1],t=t[0]),t<<16|e<<8|o),bytesToInt32:(t,e,o,n)=>(t.length&&(n=t[3],o=t[2],e=t[1],t=t[0]),(t<<24|e<<16|o<<8|n)>>>0),lerp:(e,o,n)=>e+(o-e)*t.clamp(n,0,1),lerpAngle:(e,o,n)=>(o-e>180&&(o-=360),o-e<-180&&(o+=360),t.lerp(e,o,t.clamp(n,0,1))),powerOfTwo:t=>0!==t&&!(t&t-1),nextPowerOfTwo:t=>(t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t),nearestPowerOfTwo:t=>Math.pow(2,Math.round(Math.log(t)/Math.log(2))),random(t,e){const o=e-t;return Math.random()*o+t},smoothstep:(t,e,o)=>o<=t?0:o>=e?1:(o=(o-t)/(e-t))*o*(3-2*o),smootherstep:(t,e,o)=>o<=t?0:o>=e?1:(o=(o-t)/(e-t))*o*o*(o*(6*o-15)+10),roundUp:(t,e)=>0===e?t:Math.ceil(t/e)*e,between(t,e,o,n){const a=Math.min(e,o),r=Math.max(e,o);return n?t>=a&&t<=r:t>a&&t<r}};export{t as math};