UNPKG

@litecanvas/utils

Version:

Utilities to help build litecanvas games

2 lines (1 loc) 972 B
(()=>{var d=Object.defineProperty;var M=(e,t)=>{for(var r in t)d(e,r,{get:t[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=(e=!0)=>{for(let t in globalThis.utils)t!=="global"&&(e||globalThis[t]===void 0)&&(globalThis[t]=globalThis.utils[t])};var n={};M(n,{advance:()=>u,diff:()=>c,dist:()=>l,fract:()=>x,lerpAngle:()=>i,mag:()=>p,mean:()=>f,median:()=>y,mod:()=>a,sum:()=>s});var c=(e,t)=>Math.abs(t-e)||0;var x=e=>e%1||0;var T=2*Math.PI;var u=advance=(e,t,r,o=1)=>{r&&(t.x+=r.x*o,t.y+=r.y*o),e.x+=t.x*o,e.y+=t.y*o};var a=(e,t)=>(t+e%t)%t;var l=(e,t,r,o)=>Math.hypot(r-e,o-t);var p=(e,t)=>Math.hypot(e,t);var s=e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t};var f=e=>s(e)/e.length;var y=(...e)=>{let t=e.sort((o,h)=>o-h),r=Math.floor(t.length/2);return t.length%2===0?(t[r-1]+t[r])/2:t[r]};var i=(e,t,r)=>{let o=(t-e)%360;return o>180?o-=360:o<-180&&(o+=360),e+o*r};globalThis.utils=Object.assign(globalThis.utils||{},n);})();