UNPKG

@litecanvas/utils

Version:

Utilities to help build litecanvas games

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