From 34a021c5505a78db703f41d6cbf1a3979034d57d Mon Sep 17 00:00:00 2001 From: Miriam Zusin Date: Tue, 20 Feb 2024 18:45:03 +0200 Subject: [PATCH] mlNormalize --- dist/mz-math.esm.js | 4 ++-- dist/mz-math.esm.js.map | 8 ++++---- dist/mz-math.min.js | 4 ++-- dist/mz-math.min.js.map | 8 ++++---- dist/mz-math.node.cjs | 4 ++-- dist/mz-math.node.cjs.map | 8 ++++---- src/index-esm.ts | 3 ++- src/index.ts | 5 ++++- src/main/ml.ts | 21 +++++++++++++++++++++ src/main/statistics.ts | 3 +-- test/ml.test.ts | 27 +++++++++++++++++++++++++++ 11 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 src/main/ml.ts create mode 100644 test/ml.test.ts diff --git a/dist/mz-math.esm.js b/dist/mz-math.esm.js index 15deb711..b3111731 100644 --- a/dist/mz-math.esm.js +++ b/dist/mz-math.esm.js @@ -5,10 +5,10 @@ https://github.com/mzusin/mz-math Licensed GPLv3 for open source use, or Commercial License for commercial use - https://github.com/mzusin/index/blob/main/LICENSE.md Copyright (c) 2023-present, Miriam Zusin */ -var h=Math.pow;var s=(t,r=1/0)=>{if(r===1/0)return t;r<0&&(r=0);let e=h(10,r);return Math.round(t*e)/e};var l=(t,r)=>(t%r+r)%r,j=(t,r,e,n,o)=>(o-n)*(t-r)/(e-r)+n,xr=(t,r,e,n)=>Math.max(t,e)<=Math.min(r,n),B=t=>!isNaN(parseFloat(t))&&isFinite(t),ar=(t,r,e,n=1/0)=>{let[o,i]=t,[c,u]=r;return[s(o+c*Math.cos(e),n),s(i+u*Math.sin(e),n)]};var L=(t,r=1/0)=>{let e=Math.atan2(t[1],t[0]);return s(e,r)},hr=(t,r,e=1/0)=>{let n=Math.atan2(t[1]/r[1],t[0]/r[0]);return s(n,e)},K=(t,r,e=1/0)=>{let n=U(t);return[s(Math.cos(r)*n,e),s(Math.sin(r)*n,e)]},br=(t,r=1/0)=>{let e=t*(180/Math.PI);return s(e,r)},Vr=(t,r=1/0)=>{let e=t*(Math.PI/180);return s(e,r)},Tt=(t,r,e=1/0)=>{let n=T(t),o=T(r),i=S(n,o),c=Math.acos(i);return s(c,e)},yr=(t,r,e=1/0)=>{let n=d(t,r),o=Math.atan2(n[1],n[0]);return s(o,e)},lr=(t,r,e=1/0)=>Tt(t,r,e),Ir=(t,r,e)=>{let n=D(r,e),o=D(r,t),i=D(e,t),c=o+i;return Math.abs(c-n)<=.001},J=(t,r,e=0)=>(t=t%360,r=r%360,t=t),D=(t,r,e=1/0)=>{let n=Math.abs(l(t,360)-l(r,360));return s(n<=180?n:360-n,e)},Lt=(t,r,e=0,n=1/0)=>(t=t%360,r=r%360,t{t<0&&(t=0),t>100&&(t=100);let o=Lt(r,e,n);return J(r,e,n)?l(n+t*o/100,360):l(n-t*o/100,360)};var N=(t,r,e=1/0)=>{let n=[];for(let o=0;oN(t,r,e),wr=(t,r,e=1/0)=>N(t,r,e),d=(t,r,e=1/0)=>{let n=[];for(let o=0;od(t,r,e),Hr=(t,r,e=1/0)=>d(t,r,e),C=(t,r,e=1/0)=>{let n=[];for(let o=0;oC(t,r,e),k=(t,r,e=1/0)=>C(t,r,e),X=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o=0;oX(t,r,e),Tr=(t,r,e=1/0)=>X(t,r,e),H=(t,r=1/0)=>{let e=0;for(let n=0;nH(t,r),Lr=(t,r=1/0)=>H(t,r),$t=(t,r,e=1/0)=>{let n=L(t);return[s(Math.cos(n)*r,e),s(Math.sin(n)*r,e)]},$r=(t,r,e=1/0)=>{let n=d(t,r);return H(n,e)},Er=(t,r,e=1/0)=>{let n=d(t,r);return H(n,e)},qr=(t,r,e=1/0)=>{let n=d(t,r);return H(n,e)},T=(t,r=1/0)=>{let e=H(t),n=[];for(let o=0;oT(t,r),g=(t,r=1/0)=>T(t,r),S=(t,r,e=1/0)=>{let n=0;for(let o=0;oS(t,r,e),Ar=(t,r,e=1/0)=>S(t,r,e),Nr=(t,r,e=1/0)=>[s(t[1]*r[2]-t[2]*r[1],e),s(t[2]*r[0]-t[0]*r[2],e),s(t[0]*r[1]-t[1]*r[0],e)],Cr=(t=0)=>[t,t],Xr=(t=0)=>[t,t,t],Yr=(t=0)=>[t,t,t,t],tt=(t,r=0)=>{if(t<0)throw new Error("N must be a non-negative number.");let e=[];for(let n=0;n{let e=[0,0];return e=$t(e,t),K(e,r)},rt=(t,r)=>{if(t.length!==r.length)return!1;for(let e=0;e{let n=w(r,t);return[-s(n[1],e),s(n[0],e)]};var nt=(t,r,e=1/0)=>{let n=[];for(let o=0;ont(t,r,e),kr=(t,r,e=1/0)=>nt(t,r,e),ot=(t,r,e=1/0)=>{let n=[];for(let o=0;oot(t,r,e),Qr=(t,r,e=1/0)=>ot(t,r,e),it=(t,r,e=1/0)=>{let n=[];for(let o of t)n.push(C(o,r,e));return n},Zr=(t,r,e=1/0)=>it(t,r,e),Wr=(t,r,e=1/0)=>it(t,r,e),F=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o of t)n.push(X(o,r,e));return n},Et=(t,r,e=1/0)=>F(t,r,e),_r=(t,r,e=1/0)=>F(t,r,e),Y=t=>{let r=t.length;if(r<=0)return t;let e=t[0].length;if(e<=0)return t;let n=[];for(let o=0;oY(t),Jr=t=>Y(t),ct=(t,r=0)=>{if(t.length<=0)return[];let e=[];for(let n=0;nct(t,r),Pr=(t,r=0)=>ct(t,r),te=(t=0)=>[[t,t],[t,t]],re=(t=0)=>[[t,t,t],[t,t,t],[t,t,t]],ee=(t=0)=>[[t,t,t,t],[t,t,t,t],[t,t,t,t],[t,t,t,t]],ne=(t,r,e=0)=>{if(t<=0||r<=0)throw new Error("M and N must be positive numbers.");let n=[];for(let o=0;o[[1,0],[0,1]],ie=()=>[[1,0,0],[0,1,0],[0,0,1]],ce=()=>[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],se=t=>{if(t<0)throw new Error("N must be a non-negative number.");if(t===0)return[];let r=[];for(let e=0;e{let r=[];for(let e=0;eI(t),ut=t=>I(t),ue=(t,r)=>{if(t.length<=0)return[];let e=I(t);for(let n=0;n{if(t.length<=0)return[];let e=I(t);for(let n=0;n{let e=I(t);return e.push(r),e},me=(t,r)=>{let e=st(t);return e.push(r),e},fe=(t,r)=>{let e=ut(t);return e.push(r),e},pe=(t,r)=>{let e=I(t);return e.unshift(r),e},Me=(t,r)=>{let e=st(t);return e.unshift(r),e},he=(t,r)=>{let e=ut(t);return e.unshift(r),e},be=t=>{if(t.length<=0)return[];let r=I(t);return r.pop(),r},Ve=t=>{if(t.length<=0)return[];let r=I(t);return r.shift(),r},xt=t=>{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=[];for(let e=0;e{if(t.length<=0)return[];let r=t[0].length,e=[];for(let n=0;n{if(t.length<=0)return[];let e=[];for(let n=0;n{let n=[];for(let i=0;i{if(t.length<0)return[];if(t[0].length!==r.length)throw new Error("The number of columns in the matrix must be equal to the length of the vector.");let n=[];for(let o=0;o{if(t.length!==r.length)return!1;for(let e=0;e{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=[];for(let i=0;i{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=qt(t,r,e);return G(o)},G=t=>{let r=t.length;if(r===0)return 1;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t[0][0];if(r===2)return ft(t);let e=0;for(let n=0;n{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return t[0][0]*t[1][1]-t[1][0]*t[0][1]},ve=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return G(t)},pt=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return[[t[1][1],-t[0][1]],[-t[1][0],t[0][0]]]},ge=t=>Mt(t),Mt=t=>{let r=t.length;if(r<=0)return null;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t;if(r===2)return pt(t);let e=[];for(let n=0;n{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");return G(t)===0},ht=(t,r=1/0)=>{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");let e=ft(t);if(e===0)return null;let n=pt(t);return n===null?null:Et(n,e,r)},bt=(t,r=1/0)=>Q(t,r),Q=(t,r=1/0)=>{let e=t.length;if(e>0&&e!==t[0].length)throw new Error("The matrix must be square.");let n=G(t),o=Mt(t);return o===null?null:F(o,n,r)};var Be=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1];return`matrix(${r}, ${e}, ${n}, ${o}, 0, 0)`},Te=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix(${r}, ${e}, ${n}, ${o}, ${i}, ${c})`},Le=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix3d(${r}, ${e}, 0, 0, ${n}, ${o}, 0, 0, 0, 0, 1, 0, ${i}, ${c}, 0, 1)`},$e=t=>`matrix3d( +var h=Math.pow;var s=(t,r=1/0)=>{if(r===1/0)return t;r<0&&(r=0);let e=h(10,r);return Math.round(t*e)/e};var l=(t,r)=>(t%r+r)%r,j=(t,r,e,n,o)=>(o-n)*(t-r)/(e-r)+n,xr=(t,r,e,n)=>Math.max(t,e)<=Math.min(r,n),B=t=>!isNaN(parseFloat(t))&&isFinite(t),ar=(t,r,e,n=1/0)=>{let[o,i]=t,[c,u]=r;return[s(o+c*Math.cos(e),n),s(i+u*Math.sin(e),n)]};var L=(t,r=1/0)=>{let e=Math.atan2(t[1],t[0]);return s(e,r)},hr=(t,r,e=1/0)=>{let n=Math.atan2(t[1]/r[1],t[0]/r[0]);return s(n,e)},K=(t,r,e=1/0)=>{let n=U(t);return[s(Math.cos(r)*n,e),s(Math.sin(r)*n,e)]},br=(t,r=1/0)=>{let e=t*(180/Math.PI);return s(e,r)},Vr=(t,r=1/0)=>{let e=t*(Math.PI/180);return s(e,r)},Tt=(t,r,e=1/0)=>{let n=T(t),o=T(r),i=S(n,o),c=Math.acos(i);return s(c,e)},yr=(t,r,e=1/0)=>{let n=d(t,r),o=Math.atan2(n[1],n[0]);return s(o,e)},lr=(t,r,e=1/0)=>Tt(t,r,e),Ir=(t,r,e)=>{let n=D(r,e),o=D(r,t),i=D(e,t),c=o+i;return Math.abs(c-n)<=.001},J=(t,r,e=0)=>(t=t%360,r=r%360,t=t),D=(t,r,e=1/0)=>{let n=Math.abs(l(t,360)-l(r,360));return s(n<=180?n:360-n,e)},Lt=(t,r,e=0,n=1/0)=>(t=t%360,r=r%360,t{t<0&&(t=0),t>100&&(t=100);let o=Lt(r,e,n);return J(r,e,n)?l(n+t*o/100,360):l(n-t*o/100,360)};var N=(t,r,e=1/0)=>{let n=[];for(let o=0;oN(t,r,e),wr=(t,r,e=1/0)=>N(t,r,e),d=(t,r,e=1/0)=>{let n=[];for(let o=0;od(t,r,e),zr=(t,r,e=1/0)=>d(t,r,e),C=(t,r,e=1/0)=>{let n=[];for(let o=0;oC(t,r,e),k=(t,r,e=1/0)=>C(t,r,e),X=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o=0;oX(t,r,e),Tr=(t,r,e=1/0)=>X(t,r,e),z=(t,r=1/0)=>{let e=0;for(let n=0;nz(t,r),Lr=(t,r=1/0)=>z(t,r),$t=(t,r,e=1/0)=>{let n=L(t);return[s(Math.cos(n)*r,e),s(Math.sin(n)*r,e)]},$r=(t,r,e=1/0)=>{let n=d(t,r);return z(n,e)},Er=(t,r,e=1/0)=>{let n=d(t,r);return z(n,e)},qr=(t,r,e=1/0)=>{let n=d(t,r);return z(n,e)},T=(t,r=1/0)=>{let e=z(t),n=[];for(let o=0;oT(t,r),g=(t,r=1/0)=>T(t,r),S=(t,r,e=1/0)=>{let n=0;for(let o=0;oS(t,r,e),Ar=(t,r,e=1/0)=>S(t,r,e),Nr=(t,r,e=1/0)=>[s(t[1]*r[2]-t[2]*r[1],e),s(t[2]*r[0]-t[0]*r[2],e),s(t[0]*r[1]-t[1]*r[0],e)],Cr=(t=0)=>[t,t],Xr=(t=0)=>[t,t,t],Yr=(t=0)=>[t,t,t,t],tt=(t,r=0)=>{if(t<0)throw new Error("N must be a non-negative number.");let e=[];for(let n=0;n{let e=[0,0];return e=$t(e,t),K(e,r)},rt=(t,r)=>{if(t.length!==r.length)return!1;for(let e=0;e{let n=w(r,t);return[-s(n[1],e),s(n[0],e)]};var nt=(t,r,e=1/0)=>{let n=[];for(let o=0;ont(t,r,e),kr=(t,r,e=1/0)=>nt(t,r,e),ot=(t,r,e=1/0)=>{let n=[];for(let o=0;oot(t,r,e),Qr=(t,r,e=1/0)=>ot(t,r,e),it=(t,r,e=1/0)=>{let n=[];for(let o of t)n.push(C(o,r,e));return n},Zr=(t,r,e=1/0)=>it(t,r,e),Wr=(t,r,e=1/0)=>it(t,r,e),F=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o of t)n.push(X(o,r,e));return n},Et=(t,r,e=1/0)=>F(t,r,e),_r=(t,r,e=1/0)=>F(t,r,e),Y=t=>{let r=t.length;if(r<=0)return t;let e=t[0].length;if(e<=0)return t;let n=[];for(let o=0;oY(t),Jr=t=>Y(t),ct=(t,r=0)=>{if(t.length<=0)return[];let e=[];for(let n=0;nct(t,r),Pr=(t,r=0)=>ct(t,r),te=(t=0)=>[[t,t],[t,t]],re=(t=0)=>[[t,t,t],[t,t,t],[t,t,t]],ee=(t=0)=>[[t,t,t,t],[t,t,t,t],[t,t,t,t],[t,t,t,t]],ne=(t,r,e=0)=>{if(t<=0||r<=0)throw new Error("M and N must be positive numbers.");let n=[];for(let o=0;o[[1,0],[0,1]],ie=()=>[[1,0,0],[0,1,0],[0,0,1]],ce=()=>[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],se=t=>{if(t<0)throw new Error("N must be a non-negative number.");if(t===0)return[];let r=[];for(let e=0;e{let r=[];for(let e=0;eI(t),ut=t=>I(t),ue=(t,r)=>{if(t.length<=0)return[];let e=I(t);for(let n=0;n{if(t.length<=0)return[];let e=I(t);for(let n=0;n{let e=I(t);return e.push(r),e},me=(t,r)=>{let e=st(t);return e.push(r),e},fe=(t,r)=>{let e=ut(t);return e.push(r),e},pe=(t,r)=>{let e=I(t);return e.unshift(r),e},Me=(t,r)=>{let e=st(t);return e.unshift(r),e},he=(t,r)=>{let e=ut(t);return e.unshift(r),e},be=t=>{if(t.length<=0)return[];let r=I(t);return r.pop(),r},Ve=t=>{if(t.length<=0)return[];let r=I(t);return r.shift(),r},xt=t=>{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=[];for(let e=0;e{if(t.length<=0)return[];let r=t[0].length,e=[];for(let n=0;n{if(t.length<=0)return[];let e=[];for(let n=0;n{let n=[];for(let i=0;i{if(t.length<0)return[];if(t[0].length!==r.length)throw new Error("The number of columns in the matrix must be equal to the length of the vector.");let n=[];for(let o=0;o{if(t.length!==r.length)return!1;for(let e=0;e{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=[];for(let i=0;i{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=qt(t,r,e);return G(o)},G=t=>{let r=t.length;if(r===0)return 1;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t[0][0];if(r===2)return ft(t);let e=0;for(let n=0;n{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return t[0][0]*t[1][1]-t[1][0]*t[0][1]},ve=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return G(t)},pt=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return[[t[1][1],-t[0][1]],[-t[1][0],t[0][0]]]},ge=t=>Mt(t),Mt=t=>{let r=t.length;if(r<=0)return null;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t;if(r===2)return pt(t);let e=[];for(let n=0;n{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");return G(t)===0},ht=(t,r=1/0)=>{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");let e=ft(t);if(e===0)return null;let n=pt(t);return n===null?null:Et(n,e,r)},bt=(t,r=1/0)=>Q(t,r),Q=(t,r=1/0)=>{let e=t.length;if(e>0&&e!==t[0].length)throw new Error("The matrix must be square.");let n=G(t),o=Mt(t);return o===null?null:F(o,n,r)};var Be=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1];return`matrix(${r}, ${e}, ${n}, ${o}, 0, 0)`},Te=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix(${r}, ${e}, ${n}, ${o}, ${i}, ${c})`},Le=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix3d(${r}, ${e}, 0, 0, ${n}, ${o}, 0, 0, 0, 0, 1, 0, ${i}, ${c}, 0, 1)`},$e=t=>`matrix3d( ${t[0][0]}, ${t[0][1]}, ${t[0][2]}, ${t[0][3]}, ${t[1][0]}, ${t[1][1]}, ${t[1][2]}, ${t[1][3]}, ${t[2][0]}, ${t[2][1]}, ${t[2][2]}, ${t[2][3]}, ${t[3][0]}, ${t[3][1]}, ${t[3][2]}, ${t[3][3]} - )`,Ee=(t,r=1/0)=>[[1,0],[0,1],[s(t[0],r),s(t[1],r)]],qe=(t,r=1/0)=>[[1,0,0],[0,1,0],[0,0,1],[s(t[0],r),s(t[1],r),s(t[2],r)]],O=(t,r=1/0)=>[[1,0,s(t[0],r)],[0,1,s(t[1],r)],[0,0,1]],Ae=(t,r=1/0)=>[[1,0,0,s(t[0],r)],[0,1,0,s(t[1],r)],[0,0,1,s(t[2],r)],[0,0,0,1]],At=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o],[o,n]]:[[n,o],[-o,n]]},Vt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Nt=(t,r,e=!0,n=1/0)=>{let o=O(r,n),i=Vt(t,e,n),c=O(k(r,-1),n),u=E(o,i);return E(u,c)},Ne=(t,r,e,n=!0,o=1/0)=>{let i=Nt(t,r,n,o);return b(i,e)},Ce=(t,r,e=!0,n=1/0)=>{let o=$(r);return b(At(t,e,n),o)},Xe=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Vt(t,e,n),o)},Ct=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0],[0,n,-o],[0,o,n]]:[[1,0,0],[0,n,o],[0,-o,n]]},Ye=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0,0],[0,n,-o,0],[0,o,n,0],[0,0,0,1]]:[[1,0,0,0],[0,n,o,0],[0,-o,n,0],[0,0,0,1]]},Ge=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Ct(t,e,n),o)},Xt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o],[0,1,0],[-o,0,n]]:[[n,0,-o],[0,1,0],[o,0,n]]},Oe=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o,0],[0,1,0,0],[-o,0,n,0],[0,0,0,1]]:[[n,0,-o,0],[0,1,0,0],[o,0,n,0],[0,0,0,1]]},je=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Xt(t,e,n),o)},Yt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},De=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0,0],[o,n,0,0],[0,0,1,0],[0,0,0,1]]:[[n,o,0,0],[-o,n,0,0],[0,0,1,0],[0,0,0,1]]},ke=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Yt(t,e,n),o)},Gt=(t,r,e=1/0)=>{let n=O(r,e),o=jt(t),i=O(k(r,-1),e),c=E(n,o);return E(c,i)},Fe=(t,r,e,n=1/0)=>{let o=Gt(t,r,n);return b(o,e)},Ot=t=>[[t[0],0],[0,t[1]]],Qe=(t,r)=>b(Ot(t),r),jt=t=>[[t[0],0,0],[0,t[1],0],[0,0,1]],Dt=t=>[[t[0],0,0],[0,t[1],0],[0,0,t[2]]],Ze=t=>[[t[0],0,0,0],[0,t[1],0,0],[0,0,t[2],0],[0,0,0,1]],We=(t,r)=>b(Dt(t),r),_e=t=>[[t,0],[0,1]],Ke=t=>[[t,0,0],[0,1,0],[0,0,1]],Je=t=>[[t,0,0],[0,1,0],[0,0,1]],Ue=t=>[[t,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Pe=t=>[[1,0,0],[0,t,0],[0,0,1]],tn=t=>[[1,0,0,0],[0,t,0,0],[0,0,1,0],[0,0,0,1]],rn=t=>[[1,0,0],[0,1,0],[0,0,t]],en=t=>[[1,0,0,0],[0,1,0,0],[0,0,t,0],[0,0,0,1]],nn=t=>[[1,0],[0,t]],on=t=>[[1,0,0],[0,t,0],[0,0,1]],cn=()=>[[-1,0],[0,-1]],sn=()=>[[-1,0,0],[0,-1,0],[0,0,1]],un=()=>[[-1,0,0],[0,-1,0],[0,0,-1]],xn=()=>[[-1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]],an=()=>[[0,-1],[-1,0]],mn=()=>[[1,0],[0,-1]],fn=()=>[[1,0,0],[0,-1,0],[0,0,1]],pn=()=>[[-1,0],[0,1]],Mn=()=>[[-1,0,0],[0,1,0],[0,0,1]],hn=()=>[[-1,0,0],[0,1,0],[0,0,1]],bn=()=>[[-1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Vn=()=>[[1,0,0],[0,-1,0],[0,0,1]],yn=()=>[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]],ln=()=>[[1,0,0],[0,1,0],[0,0,-1]],In=()=>[[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]],dn=t=>[[1,t],[0,1]],vn=t=>[[1,0],[t,1]];var V=(t,r,e=1/0)=>s(Math.random()*(r-t)+t,e),kt=(t,r)=>Math.floor(Math.random()*(r-t+1)+t),Rn=()=>Math.random()<.5,wn=t=>{let r=kt(0,t.length-1);return t[r]};var zn=(t,r)=>{var n;if(t==null)return r;let e=(n=Number(t))!=null?n:r;return isNaN(e)?r:e};var Ln=(t,r,e=1/0)=>{let n=0;for(let o of r){if(o.length!==2)return NaN;let i=o[0],c=o[1];n+=i*c*Math.pow(t,c-1)}return s(n,e)},yt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},lt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},It=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},dt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},$n=(t,r=1/0)=>s(Math.cos(t),r),En=(t,r=1/0)=>s(-Math.sin(t),r),qn=(t,r=1/0)=>s(1/h(Math.cos(t),2),r),An=(t,r=1/0)=>s(-1/h(Math.sin(t),2),r),Nn=(t,r=1/0)=>s(1/Math.sqrt(1-h(t,2)),r),Cn=(t,r=1/0)=>s(-1/Math.sqrt(1-h(t,2)),r),Xn=(t,r=1/0)=>s(1/(1+h(t,2)),r),Yn=(t,r=1/0)=>s(-1/(1+h(t,2)),r);var q=(t,r=1/0)=>{let e=t[0],n=t[1],i=t[2]-n;return e===0&&i===0?1/0:e===0?NaN:s(i/e,r)},Fn=(t,r,e=1/0)=>{let n=[[t[0],t[1]],[r[0],r[1]]],o=ht(n);if(o===null)return null;let i=[t[2],r[2]];return b(o,i,e)},Qn=(t,r,e,n=1/0)=>{let o=[[t[0],t[1],t[2]],[r[0],r[1],r[2]],[e[0],e[1],e[2]]],i=bt(o);if(i===null)return null;let c=[t[3],r[3],e[3]];return b(i,c,n)},Zn=(t,r=1/0)=>{if(t.length<=0)return null;let e=xt(t),n=Q(e);if(n===null)return null;let o=at(t);return b(n,o,r)},Wn=(t,r)=>{let[e,n]=w(r,t),[o,i]=t;if(e===0)return{slope:void 0,xIntercept:o,yIntercept:void 0,formula:`x = ${o}`};let c=n/e,u=i-c*o,x="";return c===0?x=`y = ${u}`:(x=`y = ${c===1?"":c}x`,u!==0&&(x+=` ${u<0?"-":"+"} ${Math.abs(u)}`)),{slope:c,xIntercept:void 0,yIntercept:u,formula:x}};var Z=(t,r=1/0)=>{let e=t[0],n=t[1],o=t[2],i=t[3];if(e===0){let f=q([n,o,i],r);return B(f)?[f]:[]}let c=o-i,u=n*n-4*e*c;if(u<0)return[];if(u===0)return[s(-n/(2*e),r)];let x=2*e,a=Math.sqrt(u);return[s((-n+a)/x,r),s((-n-a)/x,r)]};var Ft=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},co=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},Qt=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},so=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},Zt=(t,r,e,n,o=1/0)=>{let i=yt(t,r,e,n);return $(i,o)},uo=(t,r,e,n,o=1/0)=>{let i=lt(t,r,e,n);return g(i,o)},Wt=(t,r,e,n,o,i=1/0)=>{let c=It(t,r,e,n,o);return $(c,i)},xo=(t,r,e,n,o,i=1/0)=>{let c=dt(t,r,e,n,o);return g(c,i)},ao=(t,r,e,n,o=1/0)=>{let i=Zt(t,r,e,n,o);return[-i[1],i[0]]},mo=(t,r,e,n,o,i=1/0)=>{let c=Wt(t,r,e,n,o,i);return[-c[1],c[0]]},_t=(t,r,e,n=1/0)=>{let o=2*t[0]-4*r[0]+2*e[0],i=-2*t[0]+2*r[0],u=q([o,i,0],n),x=2*t[1]-4*r[1]+2*e[1],a=-2*t[1]+2*r[1],p=q([x,a,0],n),m=[];return B(u)&&m.push(u),B(p)&&m.push(p),m},Kt=(t,r,e,n,o=1/0)=>{let i=-3*t[0]+9*r[0]-9*e[0]+3*n[0],c=6*t[0]-12*r[0]+6*e[0],u=-3*t[0]+3*r[0],x=[i,c,u,0],a=-3*t[1]+9*r[1]-9*e[1]+3*n[1],f=6*t[1]-12*r[1]+6*e[1],p=-3*t[1]+3*r[1],m=[a,f,p,0],M=Z(x,o).filter(y=>y>=0&&y<=1),v=Z(m,o).filter(y=>y>=0&&y<=1);return[...M,...v].length===2?[...M,...v]:null},fo=(t,r,e,n=1/0)=>{let o=_t(t,r,e),i=1/0,c=1/0,u=-1/0,x=-1/0;for(let a of o){let f=Ft(a,t,r,e),p=f[0],m=f[1];i=Math.min(i,p),u=Math.max(u,p),c=Math.min(c,m),x=Math.max(x,m)}return i=s(Math.min(i,t[0],e[0]),n),u=s(Math.max(u,t[0],e[0]),n),c=s(Math.min(c,t[1],e[1]),n),x=s(Math.max(x,t[1],e[1]),n),{x:i,y:c,w:Math.abs(u-i),h:Math.abs(x-c),x2:u,y2:x}},po=(t,r,e,n,o=1/0)=>{let i=Kt(t,r,e,n)||[],c=1/0,u=1/0,x=-1/0,a=-1/0;for(let f of i){let p=Qt(f,t,r,e,n),m=p[0],M=p[1];c=Math.min(c,m!=null?m:1/0),x=Math.max(x,m!=null?m:-1/0),u=Math.min(u,M!=null?M:1/0),a=Math.max(a,M!=null?M:-1/0)}return c=s(Math.min(c,t[0],n[0]),o),x=s(Math.max(x,t[0],n[0]),o),u=s(Math.min(u,t[1],n[1]),o),a=s(Math.max(a,t[1],n[1]),o),{x:c,y:u,w:Math.abs(x-c),h:Math.abs(a-u),x2:x,y2:a}};var Jt=(t,r,e)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*e]),yo=(t,r,e)=>{let n=w(t,r),o=L(n);return o=j(o,0,Math.PI*2,0,Math.PI),Jt(r,o,e)},Ut=(t,r,e,n)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*n]),lo=(t,r,e)=>{let n=w(t,r),o=L(n);return o=j(o,0,Math.PI*2,0,Math.PI),Ut(r,o,e[0],e[1])},Io=(t,r,e,n)=>{let o=r*Math.sin(2*Math.PI*e*t+n);return[t,o]},vo=(t,r,e,n,o,i,c)=>[t*Math.cos(n*e-i),r*Math.cos(o*e-c)];var Ho=()=>{let t=gt();return er(t)},zo=()=>{let t=gt();return nr(t)},gt=()=>{let t=V(1,360),r=V(0,100),e=V(0,100);return[t,r,e]},Bo=t=>{let r=V(0,100),e=V(0,100);return[t,r,e]},To=t=>{let r=V(1,360),e=V(0,100);return[r,t,e]},Lo=t=>{let r=V(1,360),e=V(0,100);return[r,e,t]},$o=()=>[0,0,V(0,100)],Eo=(t=1,r=360,e=0,n=100,o=0,i=100)=>{let c=V(t,r),u=V(e,n),x=V(o,i);return[c,u,x]},Pt=t=>(t*=60,t<0&&(t+=360),t),tr=(t,r,e,n=void 0,o=void 0)=>{if(n=n===void 0?Math.min(t,r,e):n,o=o===void 0?Math.max(t,r,e):o,n===o)return 0;let i=o-n,c=0;return o===t&&(c=(r-e)/i+(r(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,(n+o)/2*100),rr=(t,r,e,n=void 0,o=void 0,i=void 0)=>(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,n===o?0:(i=i===void 0?St(t,r,e):i,(i<=50?(o-n)/(o+n):(o-n)/(2-o-n))*100)),qo=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255,i=Math.min(e,n,o),c=Math.max(e,n,o),u=St(e,n,o,i,c),x=rr(e,n,o,i,c,u),a=tr(e,n,o,i,c);return a>360||x>100||u>100?[0,0,100]:a<0||x<0||u<0?[0,0,0]:[s(a,r),s(x,r),s(u,r)]},W=(t,r,e)=>(e<0&&(e+=1),e>1&&(e-=1),e*6<1?r+(t-r)*6*e:e*2<1?t:e*3<2?r+(t-r)*(.666-e)*6:r),er=(t,r=1/0)=>{let e=t[0]/100,n=t[1]/100,o=t[2]/100;if(n===0){let M=o*255;return[M,M,M]}let i=o<.5?o*(1+n):o+n-o*n,c=2*o-i,u=e+.333,x=e,a=e-.333,f=W(i,c,u),p=W(i,c,x),m=W(i,c,a);return f*=255,p*=255,m*=255,f>255||p>255||m>255?[255,255,255]:f<0||p<0||m<0?[0,0,0]:[s(f,r),s(p,r),s(m,r)]},nr=t=>{if(t[0]>360||t[1]>100||t[2]>100)return"#ffffff";if(t[0]<0||t[1]<0||t[2]<0)return"#000000";let r=t[0]/360,e=t[1]/100,n=t[2]/100,o,i,c;if(e===0)o=i=c=n;else{let x=(p,m,M)=>(M<0&&(M+=1),M>1&&(M-=1),M<.16666666666666666?p+(m-p)*6*M:M<.5?m:M<.6666666666666666?p+(m-p)*(.6666666666666666-M)*6:p),a=n<.5?n*(1+e):n+e-n*e,f=2*n-a;o=x(f,a,r+1/3),i=x(f,a,r),c=x(f,a,r-1/3)}let u=x=>{let a=Math.round(x*255).toString(16);return a.length===1?"0"+a:a};return`#${u(o)}${u(i)}${u(c)}`},Ao=t=>{let[r,e,n]=t;return"#"+(1<<24|r<<16|e<<8|n).toString(16).slice(1)},No=t=>{let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,e=t.replace(r,(u,x,a,f)=>x+x+a+a+f+f),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)return null;let o=parseInt(n[1],16),i=parseInt(n[2],16),c=parseInt(n[3],16);return[o,i,c]},vt=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,o=o>.04045?Math.pow((o+.055)/1.055,2.4):o/12.92;let i=(e*.4124+n*.3576+o*.1805)/.95047,c=(e*.2126+n*.7152+o*.0722)/1,u=(e*.0193+n*.1192+o*.9505)/1.08883;return i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,c=c>.008856?Math.pow(c,1/3):7.787*c+16/116,u=u>.008856?Math.pow(u,1/3):7.787*u+16/116,[s(116*c-16,r),s(500*(i-c),r),s(200*(c-u),r)]},Co=(t,r=1/0)=>{let e=(t[0]+16)/116,n=t[1]/500+e,o=e-t[2]/200;n=.95047*(n*n*n>.008856?n*n*n:(n-16/116)/7.787),e=1*(e*e*e>.008856?e*e*e:(e-16/116)/7.787),o=1.08883*(o*o*o>.008856?o*o*o:(o-16/116)/7.787);let i=n*3.2406+e*-1.5372+o*-.4986,c=n*-.9689+e*1.8758+o*.0415,u=n*.0557+e*-.204+o*1.057;return i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,u=u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u,[s(Math.max(0,Math.min(1,i))*255,r),s(Math.max(0,Math.min(1,c))*255,r),s(Math.max(0,Math.min(1,u))*255,r)]},Xo=(t,r=180)=>{let e=t[0];return e+=r,(e>360||e<0)&&(e=l(e,360)),[e,t[1],t[2]]},Yo=(t,r=10)=>{let e=t[2];return e+=r,(e>100||e<0)&&(e=l(e,100)),[t[0],t[1],e]},Go=(t,r=10)=>{let e=t[1];return e+=r,e>100&&(e-=100),e<0&&(e+=100),[t[0],e,t[2]]},Oo=(t,r,e=1/0)=>{let n=vt(t,e),o=vt(r,e),i=n[0]-o[0],c=n[1]-o[1],u=n[2]-o[2],x=Math.sqrt(n[1]*n[1]+n[2]*n[2]),a=Math.sqrt(o[1]*o[1]+o[2]*o[2]),f=x-a,p=c*c+u*u-f*f;p=p<0?0:Math.sqrt(p);let m=1+.045*x,M=1+.015*x,v=i/1,z=f/m,y=p/M,A=v*v+z*z+y*y;return A<0?0:Math.sqrt(A)};var Do=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)}),ko=()=>Math.random().toString(36).substring(2)+new Date().getTime().toString(36);var Wo=(t,r)=>t.x<=r.x+r.w&&t.x+t.w>=r.x&&t.y<=r.y+r.h&&t.h+t.y>=r.y,_o=(t,r)=>{let e=Math.abs(t.cx-r.cx),n=Math.abs(t.cy-r.cy);return Math.sqrt(e*e+n*n)<=t.r+r.r},Rt=t=>{let r=[];for(let e=0;e{let e=[];e.push(...Rt(t)),e.push(...Rt(r));for(let n of e){let o=et(n[0],n[1]),i=wt(t,o),c=wt(r,o);if(!(i.max>=c.min&&c.max>=i.min))return!1}return!0},wt=(t,r)=>{let e=1/0,n=-1/0;for(let o of t){let i=P(o,r);e=Math.min(e,i),n=Math.max(n,i)}return{min:e,max:n}};var Uo=t=>{let r=t.duration!==void 0?t.duration:1/0,e,n,o,i,c=!1,u,x=()=>{e=void 0,o=void 0,i=void 0,c=!1,n!==void 0&&window.cancelAnimationFrame(n)},a=()=>{x(),v()},f=()=>{c=!1},p=()=>{c=!0},m=R=>{e===void 0&&(e=R),o=R-e,c&&i!==R&&typeof t.callback=="function"&&t.callback(_()),o<=r?(i=R,n=window.requestAnimationFrame(m)):x()},M=(R,Bt)=>{a(),typeof t.resizeCallback=="function"&&t.resizeCallback(R,Bt)},v=()=>{e=void 0,o=void 0,i=void 0,c=!0,t.restartOnResize&&window.ResizeObserver&&u===void 0?(u=new ResizeObserver(M),u.observe(document.body,{box:"border-box"})):n=window.requestAnimationFrame(m)},z=()=>o,y=()=>c,A=()=>e,Ht=()=>{if(!(r===1/0||o===void 0))return o*100/r},zt=()=>u,_=()=>({start:v,stop:x,pause:f,resume:p,restart:a,isAnimating:y,getElapsedTime:z,getStartTime:A,getPercent:Ht,getResizeObserver:zt});return _()};var ri=(t,r=1/0)=>s(2*Math.PI*t,r),ei=(t,r,e=1/0)=>s(2*Math.PI*Math.sqrt((h(t,2)+h(r,2))/2),e),ni=(t,r,e)=>(t>r&&(r+=360),e>=t&&e<=r||e+360>=t&&e+360<=r),oi=(t,r=1/0)=>s(t*2/Math.sqrt(2),r);var si=t=>t*(t+1)/2,ui=(t,r,e)=>t/2*(2*r+(t-1)*e);var or=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=t.reduce((n,o)=>n+o,0);return s(e/t.length,r)},mi=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=[...t].sort((o,i)=>o-i),n=Math.floor(e.length/2);return e.length%2===0?s((e[n]+e[n-1])/2,r):s(e[n],r)},fi=t=>{if(!t||t.length<=0)return;let r=new Map;for(let o of t)r.set(o,(r.get(o)||0)+1);let e=0,n=[];for(let[o,i]of r)i>e?(e=i,n=[o]):i===e&&n.push(o);if(n.length!==t.length)return n.length===1?[n[0]]:n},pi=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=or(t);if(e===void 0)return;let n=t.reduce((o,i)=>o+h(i-e,2),0);return s(n/t.length,r)};export{Uo as animate,ui as arithmeticSequenceSum,_o as circleCollide,Jt as circleMovement,yo as circleMovementAfterMouse,j as convertRange,Ko as convexPolygonsCollide,Vr as degreesToRadians,xr as doRangesOverlap,Cn as dxArcCos,Yn as dxArcCot,Nn as dxArcSin,Xn as dxArcTan,En as dxCos,An as dxCot,Ln as dxPolynomial,$n as dxSin,qn as dxTan,It as dxV2CubicBezierCurve,yt as dxV2QuadraticBezierCurve,dt as dxV3CubicBezierCurve,lt as dxV3QuadraticBezierCurve,Ut as ellipseMovement,lo as ellipseMovementAfterMouse,Lt as getAnglesDistance,D as getAnglesSub,or as getArithmeticMean,ri as getCircleCircumference,Oo as getColorsDelta,ei as getEllipseCircumference,Wn as getLinearEquationBy2Points,mi as getMedian,fi as getMode,V as getRandom,Rn as getRandomBoolean,$o as getRandomGrayscaleHSLColor,gt as getRandomHSLColor,Bo as getRandomHSLColorWithHue,Lo as getRandomHSLColorWithLightness,To as getRandomHSLColorWithSaturation,Eo as getRandomHSLColorWithinRanges,zo as getRandomHexColor,kt as getRandomInt,wn as getRandomItemFromArray,Ho as getRandomRGBColor,Xo as getShiftedHue,Yo as getShiftedLightness,Go as getShiftedSaturation,oi as getSquareInCircleSide,L as getV2Angle,yr as getV2AngleBetween,hr as getV2AngleInEllipse,lr as getV3AngleBetween,Tt as getVNAngleBetween,pi as getVariance,Do as guid,No as hexToRgb,nr as hslToHex,er as hslToRgb,oe as identity2,ie as identity3,ce as identity4,se as identityN,Ir as isAngleBetween,ni as isAngleInCircleArc,J as isClockwise,B as isNumber,Se as isSingularMatrix,Co as labToRgb,q as linearEquation,Fn as linearEquationSystem2,Qn as linearEquationSystem3,Zn as linearEquationSystemN,vo as lissajousCurve,pt as m2Adjugate,me as m2AppendRow,st as m2DeepCopy,ft as m2Determinant,Et as m2DivideScalar,ht as m2Inverse,Zr as m2MulScalar,Me as m2PrependRow,cn as m2ReflectionOrigin,sn as m2ReflectionOriginH,mn as m2ReflectionX,fn as m2ReflectionXH,pn as m2ReflectionY,Mn as m2ReflectionYH,an as m2ReflectionYmX,Ur as m2Reset,Ne as m2RotateAroundPointH,At as m2Rotation,Nt as m2RotationAroundPointH,Vt as m2RotationH,Ot as m2Scale,Fe as m2ScaleAtPointH,Gt as m2ScaleAtPointHMatrix,jt as m2ScaleH,_e as m2ScaleX,Ke as m2ScaleXH,nn as m2ScaleY,on as m2ScaleYH,vn as m2ShearingX,dn as m2ShearingY,Fr as m2Sub,Dr as m2Sum,Be as m2ToCSS,Ee as m2Translation,O as m2TranslationH,Kr as m2Transpose,Te as m2hToCSS,Le as m2hToCSS3d,te as m2x2,ge as m3Adjugate,fe as m3AppendRow,ut as m3DeepCopy,ve as m3Determinant,_r as m3DivideScalar,bt as m3Inverse,Wr as m3MulScalar,he as m3PrependRow,un as m3ReflectionOrigin,xn as m3ReflectionOriginH,ln as m3ReflectionXY,In as m3ReflectionXYH,Vn as m3ReflectionXZ,yn as m3ReflectionXZH,hn as m3ReflectionYZ,bn as m3ReflectionYZH,Pr as m3Reset,Ct as m3RotationX,Ye as m3RotationXH,Xt as m3RotationY,Oe as m3RotationYH,Yt as m3RotationZ,De as m3RotationZH,Dt as m3Scale,Ze as m3ScaleH,Je as m3ScaleX,Ue as m3ScaleXH,Pe as m3ScaleY,tn as m3ScaleYH,rn as m3ScaleZ,en as m3ScaleZH,Qr as m3Sub,kr as m3Sum,qe as m3Translation,Ae as m3TranslationH,Jr as m3Transpose,$e as m3hToCSS3d,re as m3x3,ee as m4x4,Mt as mAdjugate,ue as mAppendCol,ae as mAppendRow,I as mDeepCopy,ye as mDelFirstColumn,Ve as mDelFirstRow,xt as mDelLastColumn,be as mDelLastRow,G as mDeterminant,F as mDivideScalar,de as mEqual,Ie as mGetColumn,le as mGetFirstColumn,at as mGetLastColumn,Q as mInverse,mt as mMinor,E as mMul,it as mMulScalar,b as mMulVector,ne as mNxM,xe as mPrependCol,pe as mPrependRow,ct as mReset,ot as mSub,nt as mSum,Y as mTranspose,l as mod,si as naturalNumbersSequenceSum,ko as newId,dr as percentToAngle,ar as polarToCartesian,br as radiansToDegrees,Wo as rectCollide,Ao as rgbToHex,qo as rgbToHsl,vt as rgbToLab,s as setDecimalPlaces,K as setV2Angle,Io as sineWaveMovement,zn as stringToNumber,Cr as v2,po as v2CubicBezierBBox,Qt as v2CubicBezierCurve,Kt as v2CubicBezierCurveExtrema,mo as v2CubicBezierCurveNormal,Wt as v2CubicBezierCurveTangent,Er as v2Distance,Br as v2DivideScalar,P as v2DotProduct,Gr as v2FromPolarCoords,et as v2GetNormal,U as v2Length,zr as v2MulScalar,$ as v2Normalize,fo as v2QuadraticBezierBBox,Ft as v2QuadraticBezierCurve,_t as v2QuadraticBezierCurveExtrema,ao as v2QuadraticBezierCurveNormal,Zt as v2QuadraticBezierCurveTangent,Ce as v2Rotate,Xe as v2RotateH,Qe as v2Scale,$t as v2SetLength,w as v2Sub,Rr as v2Sum,Xr as v3,Nr as v3CrossProduct,so as v3CubicBezierCurve,xo as v3CubicBezierCurveTangent,qr as v3Distance,Tr as v3DivideScalar,Ar as v3DotProduct,Lr as v3Length,k as v3MulScalar,g as v3Normalize,co as v3QuadraticBezierCurve,uo as v3QuadraticBezierCurveTangent,Ge as v3RotateX,je as v3RotateY,ke as v3RotateZ,We as v3Scale,Hr as v3Sub,wr as v3Sum,Yr as v4,$r as vDistance,X as vDivideScalar,S as vDotProduct,rt as vEqual,H as vLength,C as vMulScalar,tt as vN,T as vNormalize,d as vSub,N as vSum}; + )`,Ee=(t,r=1/0)=>[[1,0],[0,1],[s(t[0],r),s(t[1],r)]],qe=(t,r=1/0)=>[[1,0,0],[0,1,0],[0,0,1],[s(t[0],r),s(t[1],r),s(t[2],r)]],O=(t,r=1/0)=>[[1,0,s(t[0],r)],[0,1,s(t[1],r)],[0,0,1]],Ae=(t,r=1/0)=>[[1,0,0,s(t[0],r)],[0,1,0,s(t[1],r)],[0,0,1,s(t[2],r)],[0,0,0,1]],At=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o],[o,n]]:[[n,o],[-o,n]]},Vt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Nt=(t,r,e=!0,n=1/0)=>{let o=O(r,n),i=Vt(t,e,n),c=O(k(r,-1),n),u=E(o,i);return E(u,c)},Ne=(t,r,e,n=!0,o=1/0)=>{let i=Nt(t,r,n,o);return b(i,e)},Ce=(t,r,e=!0,n=1/0)=>{let o=$(r);return b(At(t,e,n),o)},Xe=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Vt(t,e,n),o)},Ct=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0],[0,n,-o],[0,o,n]]:[[1,0,0],[0,n,o],[0,-o,n]]},Ye=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0,0],[0,n,-o,0],[0,o,n,0],[0,0,0,1]]:[[1,0,0,0],[0,n,o,0],[0,-o,n,0],[0,0,0,1]]},Ge=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Ct(t,e,n),o)},Xt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o],[0,1,0],[-o,0,n]]:[[n,0,-o],[0,1,0],[o,0,n]]},Oe=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o,0],[0,1,0,0],[-o,0,n,0],[0,0,0,1]]:[[n,0,-o,0],[0,1,0,0],[o,0,n,0],[0,0,0,1]]},je=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Xt(t,e,n),o)},Yt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},De=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0,0],[o,n,0,0],[0,0,1,0],[0,0,0,1]]:[[n,o,0,0],[-o,n,0,0],[0,0,1,0],[0,0,0,1]]},ke=(t,r,e=!0,n=1/0)=>{let o=g(r);return b(Yt(t,e,n),o)},Gt=(t,r,e=1/0)=>{let n=O(r,e),o=jt(t),i=O(k(r,-1),e),c=E(n,o);return E(c,i)},Fe=(t,r,e,n=1/0)=>{let o=Gt(t,r,n);return b(o,e)},Ot=t=>[[t[0],0],[0,t[1]]],Qe=(t,r)=>b(Ot(t),r),jt=t=>[[t[0],0,0],[0,t[1],0],[0,0,1]],Dt=t=>[[t[0],0,0],[0,t[1],0],[0,0,t[2]]],Ze=t=>[[t[0],0,0,0],[0,t[1],0,0],[0,0,t[2],0],[0,0,0,1]],We=(t,r)=>b(Dt(t),r),_e=t=>[[t,0],[0,1]],Ke=t=>[[t,0,0],[0,1,0],[0,0,1]],Je=t=>[[t,0,0],[0,1,0],[0,0,1]],Ue=t=>[[t,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Pe=t=>[[1,0,0],[0,t,0],[0,0,1]],tn=t=>[[1,0,0,0],[0,t,0,0],[0,0,1,0],[0,0,0,1]],rn=t=>[[1,0,0],[0,1,0],[0,0,t]],en=t=>[[1,0,0,0],[0,1,0,0],[0,0,t,0],[0,0,0,1]],nn=t=>[[1,0],[0,t]],on=t=>[[1,0,0],[0,t,0],[0,0,1]],cn=()=>[[-1,0],[0,-1]],sn=()=>[[-1,0,0],[0,-1,0],[0,0,1]],un=()=>[[-1,0,0],[0,-1,0],[0,0,-1]],xn=()=>[[-1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]],an=()=>[[0,-1],[-1,0]],mn=()=>[[1,0],[0,-1]],fn=()=>[[1,0,0],[0,-1,0],[0,0,1]],pn=()=>[[-1,0],[0,1]],Mn=()=>[[-1,0,0],[0,1,0],[0,0,1]],hn=()=>[[-1,0,0],[0,1,0],[0,0,1]],bn=()=>[[-1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Vn=()=>[[1,0,0],[0,-1,0],[0,0,1]],yn=()=>[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]],ln=()=>[[1,0,0],[0,1,0],[0,0,-1]],In=()=>[[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]],dn=t=>[[1,t],[0,1]],vn=t=>[[1,0],[t,1]];var V=(t,r,e=1/0)=>s(Math.random()*(r-t)+t,e),kt=(t,r)=>Math.floor(Math.random()*(r-t+1)+t),Rn=()=>Math.random()<.5,wn=t=>{let r=kt(0,t.length-1);return t[r]};var Hn=(t,r)=>{var n;if(t==null)return r;let e=(n=Number(t))!=null?n:r;return isNaN(e)?r:e};var Ln=(t,r,e=1/0)=>{let n=0;for(let o of r){if(o.length!==2)return NaN;let i=o[0],c=o[1];n+=i*c*Math.pow(t,c-1)}return s(n,e)},yt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},lt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},It=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},dt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},$n=(t,r=1/0)=>s(Math.cos(t),r),En=(t,r=1/0)=>s(-Math.sin(t),r),qn=(t,r=1/0)=>s(1/h(Math.cos(t),2),r),An=(t,r=1/0)=>s(-1/h(Math.sin(t),2),r),Nn=(t,r=1/0)=>s(1/Math.sqrt(1-h(t,2)),r),Cn=(t,r=1/0)=>s(-1/Math.sqrt(1-h(t,2)),r),Xn=(t,r=1/0)=>s(1/(1+h(t,2)),r),Yn=(t,r=1/0)=>s(-1/(1+h(t,2)),r);var q=(t,r=1/0)=>{let e=t[0],n=t[1],i=t[2]-n;return e===0&&i===0?1/0:e===0?NaN:s(i/e,r)},Fn=(t,r,e=1/0)=>{let n=[[t[0],t[1]],[r[0],r[1]]],o=ht(n);if(o===null)return null;let i=[t[2],r[2]];return b(o,i,e)},Qn=(t,r,e,n=1/0)=>{let o=[[t[0],t[1],t[2]],[r[0],r[1],r[2]],[e[0],e[1],e[2]]],i=bt(o);if(i===null)return null;let c=[t[3],r[3],e[3]];return b(i,c,n)},Zn=(t,r=1/0)=>{if(t.length<=0)return null;let e=xt(t),n=Q(e);if(n===null)return null;let o=at(t);return b(n,o,r)},Wn=(t,r)=>{let[e,n]=w(r,t),[o,i]=t;if(e===0)return{slope:void 0,xIntercept:o,yIntercept:void 0,formula:`x = ${o}`};let c=n/e,u=i-c*o,x="";return c===0?x=`y = ${u}`:(x=`y = ${c===1?"":c}x`,u!==0&&(x+=` ${u<0?"-":"+"} ${Math.abs(u)}`)),{slope:c,xIntercept:void 0,yIntercept:u,formula:x}};var Z=(t,r=1/0)=>{let e=t[0],n=t[1],o=t[2],i=t[3];if(e===0){let f=q([n,o,i],r);return B(f)?[f]:[]}let c=o-i,u=n*n-4*e*c;if(u<0)return[];if(u===0)return[s(-n/(2*e),r)];let x=2*e,a=Math.sqrt(u);return[s((-n+a)/x,r),s((-n-a)/x,r)]};var Ft=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},co=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},Qt=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},so=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},Zt=(t,r,e,n,o=1/0)=>{let i=yt(t,r,e,n);return $(i,o)},uo=(t,r,e,n,o=1/0)=>{let i=lt(t,r,e,n);return g(i,o)},Wt=(t,r,e,n,o,i=1/0)=>{let c=It(t,r,e,n,o);return $(c,i)},xo=(t,r,e,n,o,i=1/0)=>{let c=dt(t,r,e,n,o);return g(c,i)},ao=(t,r,e,n,o=1/0)=>{let i=Zt(t,r,e,n,o);return[-i[1],i[0]]},mo=(t,r,e,n,o,i=1/0)=>{let c=Wt(t,r,e,n,o,i);return[-c[1],c[0]]},_t=(t,r,e,n=1/0)=>{let o=2*t[0]-4*r[0]+2*e[0],i=-2*t[0]+2*r[0],u=q([o,i,0],n),x=2*t[1]-4*r[1]+2*e[1],a=-2*t[1]+2*r[1],p=q([x,a,0],n),m=[];return B(u)&&m.push(u),B(p)&&m.push(p),m},Kt=(t,r,e,n,o=1/0)=>{let i=-3*t[0]+9*r[0]-9*e[0]+3*n[0],c=6*t[0]-12*r[0]+6*e[0],u=-3*t[0]+3*r[0],x=[i,c,u,0],a=-3*t[1]+9*r[1]-9*e[1]+3*n[1],f=6*t[1]-12*r[1]+6*e[1],p=-3*t[1]+3*r[1],m=[a,f,p,0],M=Z(x,o).filter(y=>y>=0&&y<=1),v=Z(m,o).filter(y=>y>=0&&y<=1);return[...M,...v].length===2?[...M,...v]:null},fo=(t,r,e,n=1/0)=>{let o=_t(t,r,e),i=1/0,c=1/0,u=-1/0,x=-1/0;for(let a of o){let f=Ft(a,t,r,e),p=f[0],m=f[1];i=Math.min(i,p),u=Math.max(u,p),c=Math.min(c,m),x=Math.max(x,m)}return i=s(Math.min(i,t[0],e[0]),n),u=s(Math.max(u,t[0],e[0]),n),c=s(Math.min(c,t[1],e[1]),n),x=s(Math.max(x,t[1],e[1]),n),{x:i,y:c,w:Math.abs(u-i),h:Math.abs(x-c),x2:u,y2:x}},po=(t,r,e,n,o=1/0)=>{let i=Kt(t,r,e,n)||[],c=1/0,u=1/0,x=-1/0,a=-1/0;for(let f of i){let p=Qt(f,t,r,e,n),m=p[0],M=p[1];c=Math.min(c,m!=null?m:1/0),x=Math.max(x,m!=null?m:-1/0),u=Math.min(u,M!=null?M:1/0),a=Math.max(a,M!=null?M:-1/0)}return c=s(Math.min(c,t[0],n[0]),o),x=s(Math.max(x,t[0],n[0]),o),u=s(Math.min(u,t[1],n[1]),o),a=s(Math.max(a,t[1],n[1]),o),{x:c,y:u,w:Math.abs(x-c),h:Math.abs(a-u),x2:x,y2:a}};var Jt=(t,r,e)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*e]),yo=(t,r,e)=>{let n=w(t,r),o=L(n);return o=j(o,0,Math.PI*2,0,Math.PI),Jt(r,o,e)},Ut=(t,r,e,n)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*n]),lo=(t,r,e)=>{let n=w(t,r),o=L(n);return o=j(o,0,Math.PI*2,0,Math.PI),Ut(r,o,e[0],e[1])},Io=(t,r,e,n)=>{let o=r*Math.sin(2*Math.PI*e*t+n);return[t,o]},vo=(t,r,e,n,o,i,c)=>[t*Math.cos(n*e-i),r*Math.cos(o*e-c)];var zo=()=>{let t=gt();return er(t)},Ho=()=>{let t=gt();return nr(t)},gt=()=>{let t=V(1,360),r=V(0,100),e=V(0,100);return[t,r,e]},Bo=t=>{let r=V(0,100),e=V(0,100);return[t,r,e]},To=t=>{let r=V(1,360),e=V(0,100);return[r,t,e]},Lo=t=>{let r=V(1,360),e=V(0,100);return[r,e,t]},$o=()=>[0,0,V(0,100)],Eo=(t=1,r=360,e=0,n=100,o=0,i=100)=>{let c=V(t,r),u=V(e,n),x=V(o,i);return[c,u,x]},Pt=t=>(t*=60,t<0&&(t+=360),t),tr=(t,r,e,n=void 0,o=void 0)=>{if(n=n===void 0?Math.min(t,r,e):n,o=o===void 0?Math.max(t,r,e):o,n===o)return 0;let i=o-n,c=0;return o===t&&(c=(r-e)/i+(r(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,(n+o)/2*100),rr=(t,r,e,n=void 0,o=void 0,i=void 0)=>(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,n===o?0:(i=i===void 0?St(t,r,e):i,(i<=50?(o-n)/(o+n):(o-n)/(2-o-n))*100)),qo=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255,i=Math.min(e,n,o),c=Math.max(e,n,o),u=St(e,n,o,i,c),x=rr(e,n,o,i,c,u),a=tr(e,n,o,i,c);return a>360||x>100||u>100?[0,0,100]:a<0||x<0||u<0?[0,0,0]:[s(a,r),s(x,r),s(u,r)]},W=(t,r,e)=>(e<0&&(e+=1),e>1&&(e-=1),e*6<1?r+(t-r)*6*e:e*2<1?t:e*3<2?r+(t-r)*(.666-e)*6:r),er=(t,r=1/0)=>{let e=t[0]/100,n=t[1]/100,o=t[2]/100;if(n===0){let M=o*255;return[M,M,M]}let i=o<.5?o*(1+n):o+n-o*n,c=2*o-i,u=e+.333,x=e,a=e-.333,f=W(i,c,u),p=W(i,c,x),m=W(i,c,a);return f*=255,p*=255,m*=255,f>255||p>255||m>255?[255,255,255]:f<0||p<0||m<0?[0,0,0]:[s(f,r),s(p,r),s(m,r)]},nr=t=>{if(t[0]>360||t[1]>100||t[2]>100)return"#ffffff";if(t[0]<0||t[1]<0||t[2]<0)return"#000000";let r=t[0]/360,e=t[1]/100,n=t[2]/100,o,i,c;if(e===0)o=i=c=n;else{let x=(p,m,M)=>(M<0&&(M+=1),M>1&&(M-=1),M<.16666666666666666?p+(m-p)*6*M:M<.5?m:M<.6666666666666666?p+(m-p)*(.6666666666666666-M)*6:p),a=n<.5?n*(1+e):n+e-n*e,f=2*n-a;o=x(f,a,r+1/3),i=x(f,a,r),c=x(f,a,r-1/3)}let u=x=>{let a=Math.round(x*255).toString(16);return a.length===1?"0"+a:a};return`#${u(o)}${u(i)}${u(c)}`},Ao=t=>{let[r,e,n]=t;return"#"+(1<<24|r<<16|e<<8|n).toString(16).slice(1)},No=t=>{let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,e=t.replace(r,(u,x,a,f)=>x+x+a+a+f+f),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)return null;let o=parseInt(n[1],16),i=parseInt(n[2],16),c=parseInt(n[3],16);return[o,i,c]},vt=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,o=o>.04045?Math.pow((o+.055)/1.055,2.4):o/12.92;let i=(e*.4124+n*.3576+o*.1805)/.95047,c=(e*.2126+n*.7152+o*.0722)/1,u=(e*.0193+n*.1192+o*.9505)/1.08883;return i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,c=c>.008856?Math.pow(c,1/3):7.787*c+16/116,u=u>.008856?Math.pow(u,1/3):7.787*u+16/116,[s(116*c-16,r),s(500*(i-c),r),s(200*(c-u),r)]},Co=(t,r=1/0)=>{let e=(t[0]+16)/116,n=t[1]/500+e,o=e-t[2]/200;n=.95047*(n*n*n>.008856?n*n*n:(n-16/116)/7.787),e=1*(e*e*e>.008856?e*e*e:(e-16/116)/7.787),o=1.08883*(o*o*o>.008856?o*o*o:(o-16/116)/7.787);let i=n*3.2406+e*-1.5372+o*-.4986,c=n*-.9689+e*1.8758+o*.0415,u=n*.0557+e*-.204+o*1.057;return i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,u=u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u,[s(Math.max(0,Math.min(1,i))*255,r),s(Math.max(0,Math.min(1,c))*255,r),s(Math.max(0,Math.min(1,u))*255,r)]},Xo=(t,r=180)=>{let e=t[0];return e+=r,(e>360||e<0)&&(e=l(e,360)),[e,t[1],t[2]]},Yo=(t,r=10)=>{let e=t[2];return e+=r,(e>100||e<0)&&(e=l(e,100)),[t[0],t[1],e]},Go=(t,r=10)=>{let e=t[1];return e+=r,e>100&&(e-=100),e<0&&(e+=100),[t[0],e,t[2]]},Oo=(t,r,e=1/0)=>{let n=vt(t,e),o=vt(r,e),i=n[0]-o[0],c=n[1]-o[1],u=n[2]-o[2],x=Math.sqrt(n[1]*n[1]+n[2]*n[2]),a=Math.sqrt(o[1]*o[1]+o[2]*o[2]),f=x-a,p=c*c+u*u-f*f;p=p<0?0:Math.sqrt(p);let m=1+.045*x,M=1+.015*x,v=i/1,H=f/m,y=p/M,A=v*v+H*H+y*y;return A<0?0:Math.sqrt(A)};var Do=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)}),ko=()=>Math.random().toString(36).substring(2)+new Date().getTime().toString(36);var Wo=(t,r)=>t.x<=r.x+r.w&&t.x+t.w>=r.x&&t.y<=r.y+r.h&&t.h+t.y>=r.y,_o=(t,r)=>{let e=Math.abs(t.cx-r.cx),n=Math.abs(t.cy-r.cy);return Math.sqrt(e*e+n*n)<=t.r+r.r},Rt=t=>{let r=[];for(let e=0;e{let e=[];e.push(...Rt(t)),e.push(...Rt(r));for(let n of e){let o=et(n[0],n[1]),i=wt(t,o),c=wt(r,o);if(!(i.max>=c.min&&c.max>=i.min))return!1}return!0},wt=(t,r)=>{let e=1/0,n=-1/0;for(let o of t){let i=P(o,r);e=Math.min(e,i),n=Math.max(n,i)}return{min:e,max:n}};var Uo=t=>{let r=t.duration!==void 0?t.duration:1/0,e,n,o,i,c=!1,u,x=()=>{e=void 0,o=void 0,i=void 0,c=!1,n!==void 0&&window.cancelAnimationFrame(n)},a=()=>{x(),v()},f=()=>{c=!1},p=()=>{c=!0},m=R=>{e===void 0&&(e=R),o=R-e,c&&i!==R&&typeof t.callback=="function"&&t.callback(_()),o<=r?(i=R,n=window.requestAnimationFrame(m)):x()},M=(R,Bt)=>{a(),typeof t.resizeCallback=="function"&&t.resizeCallback(R,Bt)},v=()=>{e=void 0,o=void 0,i=void 0,c=!0,t.restartOnResize&&window.ResizeObserver&&u===void 0?(u=new ResizeObserver(M),u.observe(document.body,{box:"border-box"})):n=window.requestAnimationFrame(m)},H=()=>o,y=()=>c,A=()=>e,zt=()=>{if(!(r===1/0||o===void 0))return o*100/r},Ht=()=>u,_=()=>({start:v,stop:x,pause:f,resume:p,restart:a,isAnimating:y,getElapsedTime:H,getStartTime:A,getPercent:zt,getResizeObserver:Ht});return _()};var ri=(t,r=1/0)=>s(2*Math.PI*t,r),ei=(t,r,e=1/0)=>s(2*Math.PI*Math.sqrt((h(t,2)+h(r,2))/2),e),ni=(t,r,e)=>(t>r&&(r+=360),e>=t&&e<=r||e+360>=t&&e+360<=r),oi=(t,r=1/0)=>s(t*2/Math.sqrt(2),r);var si=t=>t*(t+1)/2,ui=(t,r,e)=>t/2*(2*r+(t-1)*e);var or=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=t.reduce((n,o)=>n+o,0);return s(e/t.length,r)},mi=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=[...t].sort((o,i)=>o-i),n=Math.floor(e.length/2);return e.length%2===0?s((e[n]+e[n-1])/2,r):s(e[n],r)},fi=t=>{if(!t||t.length<=0)return;let r=new Map;for(let o of t)r.set(o,(r.get(o)||0)+1);let e=0,n=[];for(let[o,i]of r)i>e?(e=i,n=[o]):i===e&&n.push(o);if(n.length!==t.length)return n.length===1?[n[0]]:n},pi=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=or(t);if(e===void 0)return;let n=t.reduce((o,i)=>o+h(i-e,2),0);return s(n/t.length,r)};var Vi=(t,r=1/0)=>{let e=[...t],n=Math.min(...e),i=Math.max(...e)-n;if(i===0)return[0];for(let c=0;c {\n if(decimalPlaces === Infinity) return num;\n\n if(decimalPlaces < 0){\n decimalPlaces = 0;\n }\n\n const coefficient = 10 ** decimalPlaces;\n return Math.round(num * coefficient) / coefficient;\n};", "import { Vector2 } from '../types';\nimport { setDecimalPlaces } from './format';\n\nexport const mod = (n: number, m: number) => {\n return ((n % m) + m) % m;\n};\n\n/**\n * Convert range [a, b] to [c, d].\n * f(x) = (d - c) * (x - a) / (b - a) + c\n */\nexport const convertRange = (x: number, a: number, b: number, c: number, d: number) => {\n return (d - c) * (x - a) / (b - a) + c;\n};\n\n/**\n * Check if 2 ranges [a,b] and [c,d] overlap.\n */\nexport const doRangesOverlap = (a: number, b: number, c: number, d: number) => {\n return Math.max(a, c) <= Math.min(b, d) ;\n};\n\n// eslint-disable-next-line\nexport const isNumber = (value: any) => {\n return !isNaN(parseFloat(value)) && isFinite(value);\n};\n\n/**\n * Convert polar coordinates to cartesian coordinates.\n */\nexport const polarToCartesian = (center: Vector2, radii: Vector2, angleInRad: number, decimalPlaces = Infinity) : Vector2 => {\n const [cx, cy] = center;\n const [rx, ry] = radii;\n\n return [\n setDecimalPlaces(cx + (rx * Math.cos(angleInRad)), decimalPlaces),\n setDecimalPlaces(cy + (ry * Math.sin(angleInRad)), decimalPlaces),\n ];\n};", "import { Vector, Vector2, Vector3 } from '../types';\nimport { setDecimalPlaces } from './format';\nimport { v2Length, vNormalize, vDotProduct, vSub } from './linear-algebra/vector';\nimport { mod } from './other';\n\nexport const getV2Angle = (v2: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1], v2[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleInEllipse = (v2: Vector2, radii: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1]/radii[1], v2[0]/radii[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const setV2Angle = (v2: Vector2, newAngleRad: number, decimalPlaces = Infinity): Vector2 => {\n const length = v2Length(v2);\n return [\n setDecimalPlaces(Math.cos(newAngleRad) * length, decimalPlaces),\n setDecimalPlaces(Math.sin(newAngleRad) * length, decimalPlaces),\n ];\n};\n\nexport const radiansToDegrees = (radians: number, decimalPlaces = Infinity) => {\n const res = radians * (180 / Math.PI);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\nexport const degreesToRadians = (degrees: number, decimalPlaces = Infinity) => {\n const res = degrees * (Math.PI / 180);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\n/**\n * Returns the range [0, Math.PI]\n * A = Math.acos( dot(v1, v2)/(v1.length()*v2.length()) );\n */\nexport const getVNAngleBetween = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n const unitVector1 = vNormalize(vector1);\n const unitVector2 = vNormalize(vector2);\n const dotProduct = vDotProduct(unitVector1, unitVector2);\n const angle = Math.acos(dotProduct);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleBetween = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) : number => {\n // return getVNAngleBetween(vector1, vector2, decimalPlaces);\n const diff = vSub(vector1, vector2);\n const angle = Math.atan2(diff[1], diff[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV3AngleBetween = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return getVNAngleBetween(vector1, vector2, decimalPlaces);\n};\n\nexport const isAngleBetween = (angleDegrees: number, startAngleDegrees: number, endAngleDegrees: number) : boolean => {\n const distance = getAnglesSub(startAngleDegrees, endAngleDegrees);\n const distance1 = getAnglesSub(startAngleDegrees, angleDegrees);\n const distance2 = getAnglesSub(endAngleDegrees, angleDegrees);\n const totalDistance = distance1 + distance2;\n\n // Use a small threshold for floating point errors\n return Math.abs(totalDistance - distance) <= 0.001;\n}\n\nexport const isClockwise = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n return angle2Deg >= angle1Deg;\n};\n\n/**\n * Shortest distance (angular) between two angles.\n */\nexport const getAnglesSub = (angleDegrees1: number, angleDegrees2: number, decimalPlaces = Infinity) : number => {\n const angleDistance = Math.abs(mod(angleDegrees1, 360) - mod(angleDegrees2, 360));\n return setDecimalPlaces(angleDistance <= 180 ? angleDistance : 360 - angleDistance, decimalPlaces);\n};\n\nexport const getAnglesDistance = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0, decimalPlaces = Infinity) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n if(isClockwise(angle1Deg, angle2Deg, startAngleDeg)) {\n return setDecimalPlaces((angle2Deg - angle1Deg + 360) % 360, decimalPlaces);\n }\n else{\n return setDecimalPlaces((angle1Deg - angle2Deg + 360) % 360, decimalPlaces);\n }\n};\n\nexport const percentToAngle = (percent: number, startAngleDeg: number, endAngleDeg: number, circleStartAngle = 0) => {\n if(percent < 0) {\n percent = 0;\n }\n\n if(percent > 100) {\n percent = 100;\n }\n\n const distance = getAnglesDistance(startAngleDeg, endAngleDeg, circleStartAngle);\n\n const clockwise = isClockwise(startAngleDeg, endAngleDeg, circleStartAngle);\n if(clockwise) {\n return mod(circleStartAngle + (percent * distance / 100), 360);\n }\n else {\n return mod(circleStartAngle - (percent * distance / 100), 360);\n }\n};", "import { Vector, Vector2, Vector3, Vector4 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { getV2Angle, setV2Angle } from '../angle';\n\n// ------------ SUM ------------------------\n\nexport const vSum = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSum(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sum = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSum(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ SUB ------------------------\n\nexport const vSub = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSub(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sub = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSub(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ MUL SCALAR ------------------------\n\nexport const vMulScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n const vector: Vector = [];\n\n for(let i=0; i {\n return vMulScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3MulScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vMulScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ DIVIDE ------------------------\n\nexport const vDivideScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vDivideScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3DivideScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vDivideScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ LENGTH ------------------------\n\nexport const vLength = (vector: Vector, decimalPlaces = Infinity) => {\n let sum = 0;\n\n for(let i=0; i {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v3Length = (vector: Vector3, decimalPlaces = Infinity) => {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v2SetLength = (v2: Vector2, newLength: number, decimalPlaces = Infinity): Vector2 => {\n const angle = getV2Angle(v2);\n return [\n setDecimalPlaces(Math.cos(angle) * newLength, decimalPlaces),\n setDecimalPlaces(Math.sin(angle) * newLength, decimalPlaces),\n ];\n};\n\n// ----------- DISTANCE ------------------------\n\nexport const vDistance = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v2Distance = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v3Distance = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\n// ------------ NORMALIZE ------------------------\n\n/**\n * Normalization creates a unit vector, which is a vector of length 1.\n */\nexport const vNormalize = (v: Vector, decimalPlaces = Infinity) : Vector => {\n const length = vLength(v);\n const unitVector: Vector = [];\n\n for(let i=0; i {\n return vNormalize(v2, decimalPlaces) as Vector2;\n};\n\nexport const v3Normalize = (v3: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vNormalize(v3, decimalPlaces) as Vector3;\n};\n\n// ------------ DOT PRODUCT ------------------------\n\nexport const vDotProduct = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n let sum = 0;\n\n for(let i=0; i {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\nexport const v3DotProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\n// ------------ CROSS PRODUCT ------------------------\n\n/**\n * Cross product is possible on 3D vectors only.\n * The cross product a \u00D7 b is defined as a vector c that is perpendicular (orthogonal) to both a and b.\n */\nexport const v3CrossProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity): Vector3 => {\n return [\n setDecimalPlaces(vector1[1] * vector2[2] - vector1[2] * vector2[1], decimalPlaces),\n setDecimalPlaces(vector1[2] * vector2[0] - vector1[0] * vector2[2], decimalPlaces),\n setDecimalPlaces(vector1[0] * vector2[1] - vector1[1] * vector2[0], decimalPlaces),\n ];\n};\n\n// --------------- INIT VECTOR HELPER -----------------\n\nexport const v2 = (defaultValue = 0): Vector2 => {\n return [defaultValue, defaultValue];\n};\n\nexport const v3 = (defaultValue = 0): Vector3 => {\n return [defaultValue, defaultValue, defaultValue];\n};\n\nexport const v4 = (defaultValue = 0): Vector4 => {\n return [defaultValue, defaultValue, defaultValue, defaultValue];\n};\n\nexport const vN = (N: number, defaultValue = 0): Vector => {\n\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n const vector: Vector = [];\n for(let i=0; i {\n let vector: Vector2 = [0, 0];\n vector = v2SetLength(vector, distance);\n return setV2Angle(vector, angleRad);\n};\n\n// --------------- EQUALITY -------------------------\n\nexport const vEqual = (vector1: Vector, vector2: Vector): boolean => {\n if(vector1.length !== vector2.length) return false;\n\n for(let i=0; i {\n const sub = v2Sub(vector2, vector1);\n return [\n -setDecimalPlaces(sub[1], decimalPlaces),\n setDecimalPlaces(sub[0], decimalPlaces)\n ];\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector, Vector2, Vector3 } from '../../types';\nimport { vMulScalar, vSum, vSub, vDotProduct, vN, vEqual, vDivideScalar } from './vector';\n\n// --------------- SUM ----------------------\n\nexport const mSum = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sum = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- SUB ----------------------\n\nexport const mSub = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sub = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- MUL SCALAR ----------------------\n\nexport const mMulScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vMulScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2MulScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mMulScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3MulScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mMulScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n// --------------- DIVIDE SCALAR ----------------------\n\nexport const mDivideScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vDivideScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2DivideScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mDivideScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3DivideScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mDivideScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n\n// --------------- TRANSPOSE ----------------------\n\nexport const mTranspose = (m: Matrix): Matrix => {\n\n const vectorsCount = m.length;\n if(vectorsCount <= 0) return m;\n\n const vectorLength = m[0].length;\n if(vectorLength <= 0) return m;\n\n const matrix: Matrix = [];\n for(let i=0; i {\n return mTranspose(m2);\n};\n\nexport const m3Transpose = (m3: Matrix3): Matrix => {\n return mTranspose(m3);\n};\n\n// ----------------- RESET ----------------------\n\nexport const mReset = (m: Matrix, defaultValue = 0): Matrix => {\n\n if(m.length <= 0) return [];\n\n const res: Matrix = [];\n\n for(let i=0; i {\n return mReset(m2, defaultValue) as Matrix2;\n};\n\nexport const m3Reset = (m3: Matrix3, defaultValue = 0): Matrix3 => {\n return mReset(m3, defaultValue) as Matrix3;\n};\n\n// --------------- MATRIX INIT HELPERS -----------------\n\nexport const m2x2 = (defaultValue = 0): Matrix2 => {\n return [\n [defaultValue, defaultValue],\n [defaultValue, defaultValue],\n ];\n};\n\nexport const m3x3 = (defaultValue = 0): Matrix3 => {\n return [\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const m4x4 = (defaultValue = 0): Matrix4 => {\n return [\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const mNxM = (N: number, M: number, defaultValue = 0): Matrix => {\n if(N <= 0 || M <= 0){\n throw new Error('M and N must be positive numbers.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return [\n [1, 0],\n [0, 1],\n ];\n};\n\nexport const identity3 = (): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\nexport const identity4 = (): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Identity Matrix (I).\n * M x I = I x M = M for any matrix M.\n * Identity Matrix is a special case of scale matrix.\n */\nexport const identityN = (N: number): Matrix => {\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n if(N === 0) return [];\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mDeepCopy(m2) as Matrix2;\n};\n\nexport const m3DeepCopy = (m3: Matrix3): Matrix3 => {\n return mDeepCopy(m3) as Matrix3;\n};\n\n// -------------- APPEND / PREPEND ROW OR COLUMN ---------------\n\nexport const mAppendCol = (m: Matrix, col: Vector): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n const copy = mDeepCopy(m);\n copy.push(row);\n return copy;\n};\n\nexport const m2AppendRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.push(row);\n return copy;\n};\n\nexport const m3AppendRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.push(row);\n return copy;\n};\n\nexport const mPrependRow = (m: Matrix, row: Vector) : Matrix => {\n const copy = mDeepCopy(m);\n copy.unshift(row);\n return copy;\n};\n\nexport const m2PrependRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.unshift(row);\n return copy;\n};\n\nexport const m3PrependRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.unshift(row);\n return copy;\n};\n\n// ------------ DELETE ROW OR COLUMN ----------------------------\n\nexport const mDelLastRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.pop();\n return copy;\n};\n\nexport const mDelFirstRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.shift();\n return copy;\n};\n\nexport const mDelLastColumn = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const size = m[0].length;\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n\n const matrix: Matrix = [];\n for(let i=0; i {\n\n if(matrix.length < 0) return [];\n\n if(matrix[0].length !== vector.length){\n throw new Error('The number of columns in the matrix must be equal to the length of the vector.');\n }\n\n const res: Vector = [];\n\n for(let i=0; i {\n if(matrix1.length !== matrix2.length) return false;\n\n for(let i=0; i returns matrix N (m-1 x m-1)\n * The matrix must be square.\n */\nconst mMinorHelper = (m: Matrix, row: number, col: number) => {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // prepare the matrix without provided row and column\n const matrix = mMinorHelper(m, row, col);\n\n // calculate the matrix determinant\n return mDeterminant(matrix);\n};\n\n/**\n * Calculate determinant for NxN matrix.\n * Matrix should be square.\n */\nexport const mDeterminant = (matrix: Matrix): number => {\n const size = matrix.length;\n if(size === 0) return 1;\n\n if(size !== matrix[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return matrix[0][0];\n if(size === 2) return m2Determinant(matrix as Matrix2);\n\n let d = 0;\n\n for(let i=0; i {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return m2[0][0] * m2[1][1] - m2[1][0] * m2[0][1];\n};\n\n/**\n * Calculate determinant for 3x3 matrix.\n * Matrix should be square.\n */\nexport const m3Determinant = (m3: Matrix3): number => {\n if(m3.length !== m3[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return mDeterminant(m3);\n};\n\n// ------------------ INVERSE -----------------------\n\nexport const m2Adjugate = (m2: Matrix2): Matrix2|null => {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return [\n [m2[1][1], -m2[0][1]],\n [-m2[1][0], m2[0][0]],\n ];\n};\n\nexport const m3Adjugate = (m3: Matrix3) : Matrix3|null => {\n return mAdjugate(m3) as (Matrix3|null);\n};\n\n/**\n * Adjugate is a transpose of a cofactor matrix\n */\nexport const mAdjugate = (m: Matrix): Matrix|null => {\n\n const size = m.length;\n if(size <= 0) return null;\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return m;\n\n if(size === 2) return m2Adjugate(m as Matrix2);\n\n // build a cofactor matrix ----------------\n const cofactors: Matrix = [];\n\n for(let i=0; i {\n if(m.length > 0 && m.length !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = mDeterminant(m);\n return d === 0;\n};\n\n/**\n * Square matrix A (nxn) is invertible is there is another square matrix B (nxn) so AxB = BxA = I\n * For A (2x2) matrix, the inverse is:\n * (1 / (determinant(A))) * adj(A)\n */\nexport const m2Inverse = (m2: Matrix2, decimalPlaces = Infinity): (Matrix2 | null) => {\n if(m2.length > 0 && m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = m2Determinant(m2);\n if(d === 0) return null;\n\n const adj = m2Adjugate(m2);\n if(adj === null) return null;\n\n return m2DivideScalar(adj, d, decimalPlaces);\n};\n\nexport const m3Inverse = (m3: Matrix3, decimalPlaces = Infinity): (Matrix3 | null) => {\n return mInverse(m3, decimalPlaces) as (Matrix3|null);\n};\n\nexport const mInverse = (m: Matrix, decimalPlaces = Infinity): (Matrix | null) => {\n const size = m.length;\n\n if(size > 0 && size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // find a determinant ----------------------\n const d = mDeterminant(m);\n\n // find an Adjugate - a transpose of a cofactor matrix\n const adj = mAdjugate(m);\n if(adj === null) return null;\n\n return mDivideScalar(adj, d, decimalPlaces);\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector2, Vector3, Vector4 } from '../../types';\nimport { v2Normalize, v3MulScalar, v3Normalize } from './vector';\nimport { mMulVector, mMul } from './matrix';\nimport { setDecimalPlaces } from '../format';\n\n/*\nAny 2D affine transformation can be decomposed\ninto a rotation, followed by a scaling, followed by a\nshearing, and followed by a translation.\n---------------------------------------------------------\nAffine matrix = translation x shearing x scaling x rotation\n */\n\n// ----------------- CSS -------------------------------------\n\n/**\n * Matrix 2D in non-homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2ToCSS = (m: Matrix2) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, 0, 0)`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2hToCSS = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ tx }, ${ ty })`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m2hToCSS3d = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix3d(${ a }, ${ b }, 0, 0, ${ c }, ${ d }, 0, 0, 0, 0, 1, 0, ${ tx }, ${ ty }, 0, 1)`;\n};\n\n/**\n * Matrix 3D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m3hToCSS3d = (m: Matrix4) : string => {\n\n return `matrix3d(\n ${ m[0][0] }, ${ m[0][1] }, ${ m[0][2] }, ${ m[0][3] },\n ${ m[1][0] }, ${ m[1][1] }, ${ m[1][2] }, ${ m[1][3] },\n ${ m[2][0] }, ${ m[2][1] }, ${ m[2][2] }, ${ m[2][3] },\n ${ m[3][0] }, ${ m[3][1] }, ${ m[3][2] }, ${ m[3][3] }\n )`;\n};\n\n// ---------------- TRANSLATION MATRICES ----------------------\n\nexport const m2Translation = (position: Vector2, decimalPlaces = Infinity): Matrix2 => {\n\n return [\n [1, 0],\n [0, 1],\n [setDecimalPlaces(position[0], decimalPlaces), setDecimalPlaces(position[1], decimalPlaces)],\n ];\n};\n\nexport const m3Translation = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n [\n setDecimalPlaces(position[0], decimalPlaces),\n setDecimalPlaces(position[1], decimalPlaces),\n setDecimalPlaces(position[2], decimalPlaces)\n ],\n ];\n};\n\n/**\n * 2D Translation matrix in homogeneous coordinates.\n */\nexport const m2TranslationH = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1],\n ];\n};\n\n/**\n * 3D Translation matrix in homogeneous coordinates.\n */\nexport const m3TranslationH = (position: Vector4, decimalPlaces = Infinity): Matrix4 => {\n\n return [\n [1, 0, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, 0, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1, setDecimalPlaces(position[2], decimalPlaces)],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- ROTATION MATRICES -------------------------\n\n/**\n * Rotation of an angle about the origin.\n */\nexport const m2Rotation = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix2 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin],\n [sin, cos],\n ] :\n [\n [cos, sin],\n [-sin, cos],\n ];\n};\n\n/**\n * Rotation of an angle about the origin in homogeneous coordinates (clockwise).\n */\nexport const m2RotationH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ]:\n [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation of an angle \"angleRad\" around the given point (transformOrigin) in homogeneous coordinates (clockwise).\n * result_vector = TranslationMatrix(x, y) * RotationMatrix() * TranslationMatrix(-x, -y) * position_vector\n */\nexport const m2RotationAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const rotation = m2RotationH(angleRad, isClockwise, decimalPlaces);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, rotation);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2RotateAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n position: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2RotationAroundPointH(angleRad, transformOrigin, isClockwise, decimalPlaces);\n return mMulVector(mat3h, position) as Vector3;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2Rotate = (angleRad: number, vector: Vector2, isClockwise = true, decimalPlaces = Infinity): Vector2 => {\n const unitVector = v2Normalize(vector);\n return mMulVector(m2Rotation(angleRad, isClockwise, decimalPlaces), unitVector) as Vector2;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2RotateH = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m2RotationH(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the X axis (clockwise).\n */\nexport const m3RotationX = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0],\n [0, cos, -sin],\n [0, sin, cos],\n ] :\n [\n [1, 0, 0],\n [0, cos, sin],\n [0, -sin, cos],\n ];\n};\n\n/**\n * Rotation around the X axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationXH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0, 0],\n [0, cos, -sin, 0],\n [0, sin, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [1, 0, 0, 0],\n [0, cos, sin, 0],\n [0, -sin, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateX = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationX(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Y axis (clockwise).\n */\nexport const m3RotationY = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin],\n [0, 1, 0],\n [-sin, 0, cos],\n ] :\n [\n [cos, 0, -sin],\n [0, 1, 0],\n [sin, 0, cos],\n ];\n};\n\n/**\n * Rotation around the Y axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationYH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin, 0],\n [0, 1, 0, 0],\n [-sin, 0, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [cos, 0, -sin, 0],\n [0, 1, 0, 0],\n [sin, 0, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateY = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationY(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Z axis (clockwise).\n */\nexport const m3RotationZ = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ] : [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation around the Z axis (clockwise)- in homogeneous coordinates\n */\nexport const m3RotationZH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0, 0],\n [sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ] : [\n [cos, sin, 0, 0],\n [-sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateZ = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationZ(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n// ---------------- SCALE MATRICES -------------\n\n/**\n * Get matrix for arbitrary scaling pivot point.\n * result_vector = TranslationMatrix(x, y) * ScaleMatrix() * TranslationMatrix(-x, -y) * scale_vector\n */\nexport const m2ScaleAtPointHMatrix = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const scale = m2ScaleH(scaleVector);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, scale);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2ScaleAtPointH = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n point: Vector3,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2ScaleAtPointHMatrix(scaleVector, transformOrigin, decimalPlaces);\n return mMulVector(mat3h, point) as Vector3;\n};\n\nexport const m2Scale = (scaleVector: Vector2): Matrix2 => {\n return [\n [scaleVector[0], 0],\n [0, scaleVector[1]],\n ];\n};\n\nexport const v2Scale = (scaleVector: Vector2, vector: Vector2): Vector2 => {\n return mMulVector(m2Scale(scaleVector), vector) as Vector2;\n};\n\n/**\n * homogeneous coordinates\n */\nexport const m2ScaleH = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, 1],\n ];\n};\n\nexport const m3Scale = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, scaleVector[2]],\n ];\n};\n\nexport const m3ScaleH = (scaleVector: Vector4): Matrix4 => {\n return [\n [scaleVector[0], 0, 0, 0],\n [0, scaleVector[1], 0, 0],\n [0, 0, scaleVector[2], 0],\n [0, 0, 0, 1]\n ];\n};\n\nexport const v3Scale = (scaleVector: Vector3, vector: Vector3): Vector3 => {\n return mMulVector(m3Scale(scaleVector), vector) as Vector3;\n};\n\n/**\n * Stretch, parallel to the x-axis.\n */\nexport const m2ScaleX = (scale: number): Matrix2 => {\n return [\n [scale, 0],\n [0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the x-axis - homogeneous coordinates\n */\nexport const m2ScaleXH = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleX = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleXH = (scale: number): Matrix4 => {\n return [\n [scale, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleY = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleYH = (scale: number): Matrix => {\n return [\n [1, 0, 0, 0],\n [0, scale, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZ = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, scale],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZH = (scale: number): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, scale, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis.\n */\nexport const m2ScaleY = (scale: number): Matrix2 => {\n return [\n [1, 0],\n [0, scale],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis - homogeneous coordinates\n */\nexport const m2ScaleYH = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n// ---------------- REFLECTION MATRICES -------------------------\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOrigin = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOriginH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection about the origin in non-homogeneous coordinates\n */\nexport const m3ReflectionOrigin = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection about the origin in homogeneous coordinates\n */\nexport const m3ReflectionOriginH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection about y=-x\n */\nexport const m2ReflectionYmX = (): Matrix2 => {\n\n return [\n [0, -1],\n [-1, 0],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionX = (): Matrix2 => {\n\n return [\n [1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionXH = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection in the y-axis.\n */\nexport const m2ReflectionY = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, 1],\n ];\n};\n\nexport const m2ReflectionYH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionYZ = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in homogeneous coordinates\n */\nexport const m3ReflectionYZH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXZ = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in homogeneous coordinates\n */\nexport const m3ReflectionXZH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXY = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in homogeneous coordinates\n */\nexport const m3ReflectionXYH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- SHEARING MATRICES -------------------------\n\n\n/**\n * Shearing in y-axis, with x-axis fixed with (0,1) moving to (factor, 1)\n */\nexport const m2ShearingY = (factor: number): Matrix2 => {\n\n return [\n [1, factor],\n [0, 1],\n ];\n};\n\n/**\n * Shearing in x-axis, with y-axis fixed with (1,0) moving to (1, factor)\n */\nexport const m2ShearingX = (factor: number): Matrix2 => {\n\n return [\n [1, 0],\n [factor, 1],\n ];\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a random number in the [min,max] range.\n */\nexport const getRandom = (min: number, max: number, decimalPlaces = Infinity): number => {\n return setDecimalPlaces(Math.random() * (max - min) + min, decimalPlaces);\n};\n\n/**\n * Returns a random integer number in the [min,max] range.\n */\nexport const getRandomInt = (min: number, max: number): number => {\n return Math.floor(Math.random() * (max - min + 1) + min);\n};\n\nexport const getRandomBoolean = () => Math.random() < 0.5;\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getRandomItemFromArray = (array: any[]) => {\n const randomIndex = getRandomInt(0, array.length - 1);\n return array[randomIndex];\n};", "export const stringToNumber = (value: string|undefined|null|number, defaultNumber: number) => {\n if(value === undefined || value === null) return defaultNumber;\n const res = Number(value) ?? defaultNumber;\n return isNaN(res) ? defaultNumber : res;\n};", "import { setDecimalPlaces } from './format';\nimport { Vector2, Vector3 } from '../types';\n\n/**\n * u(x) and v(x) are functions ---------->\n *\n * dx(u + v) = dx(u) + dx(v)\n * dx(u - v) = dx(u) - dx(v)\n * dx(u * v) = dx(u) * v + u * dx(v)\n * dx(u / v) = (dx(u) * v - u * dx(v)) / (v ^ 2), when v(x) != 0\n */\n\n// ------------------ Derivatives of Polynomial ---------------------------\n\n/**\n * y = 3x+2\n * dxPolynomial(10, [[3, 1], [2, 0]])\n */\nexport const dxPolynomial = (x: number, polynomial: number[][], decimalPlaces = Infinity) => {\n let res = 0;\n\n for(const part of polynomial){\n if(part.length !== 2) return NaN;\n\n const coeff = part[0];\n const power = part[1];\n res += coeff * power * Math.pow(x, power - 1);\n }\n\n return setDecimalPlaces(res, decimalPlaces);\n}\n\n// ---------------------- Bezier Curves ---------------------------\n\n/**\n * Derivative of Bezier Curve is another Bezier Curve.\n * t must min in range [0, 1]\n */\nexport const dxV2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n // The derivative: P1 * (2t-2) + (2*P3-4*P2) * t + 2 * P2\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\nexport const dxV2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n\n// ----------------- Derivatives of trigonometry functions ---------------------------\n\nexport const dxSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(Math.cos(x), decimalPlaces);\n};\n\nexport const dxCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-Math.sin(x), decimalPlaces);\n};\n\nexport const dxTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.cos(x) ** 2), decimalPlaces);\n};\n\n/**\n * x != Math.PI * n, where n is an integer\n */\nexport const dxCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sin(x) ** 2), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\nexport const dxArcTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (1 + x ** 2), decimalPlaces);\n};\n\nexport const dxArcCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (1 + x ** 2), decimalPlaces);\n};\n", "import { Matrix, Matrix2, Matrix3, Vector, Vector2, Vector3 } from '../../types';\nimport { m2Inverse, m3Inverse, mInverse, mMulVector, mDelLastColumn, mGetLastColumn } from '../linear-algebra/matrix';\nimport { setDecimalPlaces } from '../format';\nimport { v2Sub } from '../linear-algebra/vector';\n\n/**\n * Linear equation\n * ax + b = c\n * x = (c - b) / a; a != 0\n */\nexport const linearEquation = (equation: Vector3, decimalPlaces = Infinity) : number => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n\n const diff = c - b;\n\n if(a === 0 && diff === 0) return Infinity; // any number is a solution\n if(a === 0) return NaN; // no solution\n\n return setDecimalPlaces(diff / a, decimalPlaces);\n};\n\n/**\n * System of 2 linear equations.\n * [x, y] = inverse(Matrix of equation parameters) x (vector of equation results)\n * ---------------\n * 3x + 2y = 7\n * -6x + 6y = 6\n */\nexport const linearEquationSystem2 = (equation1: Vector3, equation2: Vector3, decimalPlaces = Infinity) : Vector2 | null => {\n const equationParams: Matrix2 = [\n [equation1[0], equation1[1]],\n [equation2[0], equation2[1]],\n ];\n\n const inversed = m2Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector2 = [\n equation1[2],\n equation2[2]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector2;\n};\n\n/**\n * System of 3 linear equations.\n * ---------------------------------------\n * 3x + 2y + 5z = 7\n * -6x + 6y + 6z = 6\n * 2x + 7y - z = 4\n */\nexport const linearEquationSystem3 = (\n equation1: Vector,\n equation2: Vector,\n equation3: Vector,\n decimalPlaces = Infinity) : Vector3 | null => {\n const equationParams: Matrix3 = [\n [equation1[0], equation1[1], equation1[2]],\n [equation2[0], equation2[1], equation2[2]],\n [equation3[0], equation3[1], equation3[2]],\n ];\n\n const inversed = m3Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector3 = [\n equation1[3],\n equation2[3],\n equation3[3]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector3;\n};\n\n/**\n * System of N linear equations.\n */\nexport const linearEquationSystemN = (equations: Matrix, decimalPlaces = Infinity) : Vector | null => {\n if(equations.length <= 0) return null;\n\n const equationParams = mDelLastColumn(equations);\n\n const inversed = mInverse(equationParams);\n if(inversed === null) return null; // no results\n\n // the last column of the equations matrix\n const equationResults = mGetLastColumn(equations);\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector;\n};\n\n/**\n * Calculate the equation of a line given two points in a 2D space.\n * y = ax + b\n * y - y1 = m(x - x1)\n * m = (y2 - y1) / (x2 - x1)\n */\nexport const getLinearEquationBy2Points = (point1: Vector2, point2: Vector2) : {\n slope: number|undefined,\n yIntercept: number|undefined,\n xIntercept: number|undefined,\n formula: string,\n} => {\n const [deltaX, deltaY] = v2Sub(point2, point1);\n const [x, y] = point1;\n\n if(deltaX === 0) {\n return {\n slope: undefined,\n xIntercept: x,\n yIntercept: undefined,\n formula: `x = ${ x }`,\n };\n }\n\n const m = deltaY / deltaX;\n const b = y - m * x;\n let formula = '';\n\n if(m === 0) {\n formula = `y = ${ b }`;\n }\n else{\n formula = `y = ${ m === 1 ? '' : m }x`;\n\n if(b !== 0) {\n formula += ` ${ b < 0 ? '-' : '+' } ${ Math.abs(b) }`;\n }\n }\n\n return {\n slope: m,\n xIntercept: undefined,\n yIntercept: b,\n formula,\n };\n};", "import { Vector } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { linearEquation } from './linear-equations';\nimport { isNumber } from '../other';\n\n/**\n * Quadratic Equation.\n * ax^2 + bx + c = d\n */\nexport const quadraticEquation = (equation: Vector, decimalPlaces = Infinity) : Vector => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n const d = equation[3];\n\n if(a === 0){\n // it's a linear equation -------------------------------------------\n const res = linearEquation([b, c, d], decimalPlaces);\n if(isNumber(res)) return [res];\n return [];\n }\n\n const diff = c - d;\n\n const discriminant = b * b - (4 * a * diff);\n\n if(discriminant < 0){\n return []; // no results\n }\n\n if(discriminant === 0){\n return [ setDecimalPlaces(-b / (2 * a), decimalPlaces) ]; // 1 result\n }\n\n // if(determinant > 0) ---> 2 results\n const t1 = 2 * a;\n const t2 = Math.sqrt(discriminant);\n\n return [\n setDecimalPlaces((-b + t2) / t1, decimalPlaces),\n setDecimalPlaces((-b - t2) / t1, decimalPlaces),\n ];\n};", "import { IBBox, Vector, Vector2, Vector3 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport {\n dxV2CubicBezierCurve,\n dxV2QuadraticBezierCurve,\n dxV3CubicBezierCurve,\n dxV3QuadraticBezierCurve\n} from '../derivative';\nimport { v2Normalize, v3Normalize } from '../linear-algebra/vector';\nimport { linearEquation } from '../equations/linear-equations';\nimport { quadraticEquation } from '../equations/quadratic-equations';\nimport { isNumber } from '../other';\n\n/**\n * B\u00E9zier Curves\n * quadratic: y = P1 * (1-t)\u00B2 + P2 * 2 * (1-t)t + P3 * t\u00B2\n * t in range [0, 1]\n */\n\n// -------------------- GET POINT ON CURVE --------------------------\n\n/**\n * Get a point on a quadratic B\u00E9zier curve as a function of time.\n */\nexport const v2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n/**\n * Get a point on a cubic B\u00E9zier curve as a function of time.\n */\nexport const v2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n// -------------------- TANGENT --------------------------\n\n/**\n * Tangent indicates the direction of travel at specific points along the B\u00E9zier curve,\n * and is literally just the first derivative of our curve.\n */\nexport const v2QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\nexport const v2CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\n// -------------------- NORMAL --------------------------\n\n/**\n * Normal is a vector that runs at a right angle to the direction of the curve, and is typically of length 1.\n * To find it, we take the normalised tangent vector, and then rotate it by a 90 degrees.\n */\nexport const v2QuadraticBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2QuadraticBezierCurveTangent(t, startControlPoint, centerControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\nexport const v2CubicBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2CubicBezierCurveTangent(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\n// -------------------- EXTREMA --------------------------\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2QuadraticBezierCurveExtrema = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector => {\n\n /*\n (-2 * (1 - t)) * startControlPoint[0] + (2 - 4 * t) * centerControlPoint[0] + (2 * t) * endControlPoint[0]\n 2 * t * startControlPoint[0] - 4 * t * centerControlPoint[0] + 2 * t * endControlPoint[0] - 2 * startControlPoint[0] + 2 * centerControlPoint[0]\n t * (2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0]) + (- 2 * startControlPoint[0] + 2 * centerControlPoint[0])\n */\n\n const a1 = 2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0];\n const b1 = -2 * startControlPoint[0] + 2 * centerControlPoint[0];\n const equation1: Vector3 = [a1, b1, 0];\n const res1 = linearEquation(equation1, decimalPlaces);\n\n const a2 = 2 * startControlPoint[1] - 4 * centerControlPoint[1] + 2 * endControlPoint[1];\n const b2 = -2 * startControlPoint[1] + 2 * centerControlPoint[1];\n const equation2: Vector3 = [a2, b2, 0];\n const res2 = linearEquation(equation2, decimalPlaces);\n\n const res: Vector = [];\n\n if(isNumber(res1)){\n res.push(res1);\n }\n\n if(isNumber(res2)){\n res.push(res2);\n }\n\n return res;\n};\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2CubicBezierCurveExtrema = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2|null => {\n\n const a1 = -3 * startControlPoint[0] + 9 * center1ControlPoint[0] - 9 * center2ControlPoint[0] + 3 * endControlPoint[0];\n const b1 = 6 * startControlPoint[0] - 12 * center1ControlPoint[0] + 6 * center2ControlPoint[0];\n const c1 = -3 * startControlPoint[0] + 3 * center1ControlPoint[0];\n const equation1: Vector = [a1, b1, c1, 0];\n\n const a2 = -3 * startControlPoint[1] + 9 * center1ControlPoint[1] - 9 * center2ControlPoint[1] + 3 * endControlPoint[1];\n const b2 = 6 * startControlPoint[1] - 12 * center1ControlPoint[1] + 6 * center2ControlPoint[1];\n const c2 = -3 * startControlPoint[1] + 3 * center1ControlPoint[1];\n const equation2: Vector = [a2, b2, c2, 0];\n\n // Any value between 0 and 1 is a root that matters for B\u00E9zier curves, anything below or above that is irrelevant (because B\u00E9zier curves are only defined over the interval [0,1]).\n const res1 = quadraticEquation(equation1, decimalPlaces).filter(num => num >= 0 && num <= 1);\n const res2 = quadraticEquation(equation2, decimalPlaces).filter(num => num >= 0 && num <= 1);\n\n const res = [...res1, ...res2];\n if(res.length === 2){\n return [...res1, ...res2] as Vector2;\n }\n\n return null;\n};\n\n// -------------------- BOUNDING BOX --------------------------\n\nexport const v2QuadraticBezierBBox = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2QuadraticBezierCurveExtrema(startControlPoint, centerControlPoint, endControlPoint);\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2QuadraticBezierCurve(percent, startControlPoint, centerControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\nexport const v2CubicBezierBBox = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2CubicBezierCurveExtrema(startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint) || [];\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2CubicBezierCurve(percent, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x ?? Infinity);\n maxX = Math.max(maxX, x ?? -Infinity);\n\n minY = Math.min(minY, y ?? Infinity);\n maxY = Math.max(maxY, y ?? -Infinity);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\n\n", "import { Vector2 } from '../types';\nimport { v2Sub } from './linear-algebra/vector';\nimport { getV2Angle } from './angle';\nimport { convertRange } from './other';\n\n/**\n * Circle Equation\n * x^2 + y^2 = radius^2\n * ----------------------\n * Circle Parametric Equation\n * x(t) = radius * cos(t)\n * y(t) = radius * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const circleMovement = (center: Vector2, angle: number, radius: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius,\n center[1] + Math.sin(angle) * radius\n ];\n};\n\n/**\n * Circle Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const circleMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radius: number\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return circleMovement(center, angle, radius);\n};\n\n/**\n * Ellipse Equation\n * (x - centerX)^2 / (radius1^2) + (y - centerY)^2 / (radius2^2) = 1\n * -----------------------------------------------------------------\n * Ellipse Parametric Equation\n * x(t) = radius1 * cos(t)\n * y(t) = radius2 * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const ellipseMovement = (center: Vector2, angle: number, radius1: number, radius2: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius1,\n center[1] + Math.sin(angle) * radius2\n ];\n};\n\n/**\n * Ellipse Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const ellipseMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radii: Vector2\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return ellipseMovement(center, angle, radii[0], radii[1]);\n};\n\n/**\n * Sine Wave Equation (Sinusoid)\n * -----------------------------\n * const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n * amplitude = the peak deviation of the function from zero\n * frequency = number of cycles\n * phase = specifies (in radians) where in its cycle the oscillation is at t = 0.\n * think of it as \"shifting\" the starting point of the function to the right (positive p) or left (negative)\n */\nexport const sineWaveMovement = (x: number, amplitude: number, frequency: number, phase: number) : Vector2 => {\n /*\n example values:\n const amplitude = 50;\n const frequency = 0.005;\n const phase = 0;\n x: [0, 1000]\n */\n const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n\n return [x, y];\n};\n\n/**\n * Lissajous curve (Lissajous figure or Bowditch curve)\n * Parametric equation #1\n * f(t) = A * sin(k * t + m)\n * f(t) = B * sin(n * t)\n * 0 <= m <= PI/2\n * k, n >= 1\n * -----------------------\n * Parametric equation #2\n * f(t) = A * cos(k * t - m)\n * f(t) = B * cos(n * t - p)\n * -----------------------------\n * Shapes:\n * k = 1, n = 1, m = 0, p = 0 ---> line\n * A = B, k = 1, n = 1, m = PI/2, p = PI/2 ----> circle\n * A != B, k = 1, n = 1, m = PI/2, p = PI/2 ----> ellipse\n * k = 2, n = 2, m = PI/2, p = PI/2 ----> section of a parabola\n */\nexport const lissajousCurve = (\n width: number,\n height: number,\n t: number,\n k: number,\n n: number,\n m: number,\n p: number\n) :Vector2 => {\n return [\n width * Math.cos(k * t - m),\n height * Math.cos(n * t - p),\n ];\n};\n", "import { getRandom } from './random';\nimport { HSLColor, LABColor, RGBColor } from '../types';\nimport { mod } from './other';\nimport { setDecimalPlaces } from './format';\n\n// ------------------------ RANDOM COLOR -------------------------------------\n\nexport const getRandomRGBColor = () : RGBColor => {\n const hslColor = getRandomHSLColor();\n return hslToRgb(hslColor);\n};\n\nexport const getRandomHexColor = () : string => {\n const hslColor = getRandomHSLColor();\n return hslToHex(hslColor);\n};\n\nexport const getRandomHSLColor = () : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given hue\n */\nexport const getRandomHSLColorWithHue = (h: number) : HSLColor => {\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given saturation\n */\nexport const getRandomHSLColorWithSaturation = (s: number) : HSLColor => {\n const h = getRandom(1, 360);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given lightness\n */\nexport const getRandomHSLColorWithLightness = (l: number) : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n return [h, s, l];\n};\n\nexport const getRandomGrayscaleHSLColor = () : HSLColor => {\n const l = getRandom(0, 100);\n return [0, 0, l];\n};\n\nexport const getRandomHSLColorWithinRanges = (\n hueStart = 1, hueEnd = 360,\n saturationStart = 0, saturationEnd = 100,\n lightStart = 0, lightEnd = 100\n) : HSLColor => {\n const h = getRandom(hueStart, hueEnd);\n const s = getRandom(saturationStart, saturationEnd);\n const l = getRandom(lightStart, lightEnd);\n return [h, s, l];\n};\n\n// ----------------------- CONVERT COLORS --------------------------------------\n\n/**\n * helper: convert hue value to degrees.\n * @param {number} h\n * @return {number} [0, 360] degrees\n */\nconst convertHueToDegrees = (h : number) : number => {\n\n // the hue value needs to be multiplied by 60 to convert it to degrees\n h *= 60;\n\n // if hue becomes negative, you need to add 360 to, because a circle has 360 degrees\n if(h < 0){\n h += 360;\n }\n\n return h;\n // convert huw to %\n // return h * 100 / 360;\n};\n\n/**\n * get hue from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] % - we use here % instead of [0, 359] degrees\n */\nconst getHue = (r : number, g : number, b : number, min : number | undefined = undefined, max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (max === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no hue, as it's gray\n if(min === max) return 0;\n\n const diff = max - min;\n\n let h = 0;\n\n // if red is max\n if(max === r){\n h = (g - b) / diff + (g < b ? 6 : 0);\n }\n\n // if green is max\n if(max === g){\n h = 2 + (b - r) / diff;\n }\n\n // if blue is max\n if(max === b){\n h = 4 + (r - g) / diff;\n }\n\n return convertHueToDegrees(h);\n};\n\n/**\n * get luminance from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] %\n */\nconst getLuminance = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // calculate the luminance value\n // @ts-ignore\n const l = (min + max) / 2; // [0, 1]\n\n // return l value in %\n return l * 100;\n};\n\n/**\n * get saturation from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @param {number|undefined=} l - luminance in [0, 100] %\n * @return {number} [0, 100] %\n */\nconst getSaturation = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined,\n l : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no saturation, as it's gray\n if(min === max) return 0;\n\n // calculate luminance if it's not provided\n l = (l === undefined) ? getLuminance(r, g, b) : l;\n\n // check the level of luminance\n const s = (l <= 50) ?\n // @ts-ignore\n ((max - min) / (max + min)) : // this formula is used when luminance <= 50%\n // @ts-ignore\n (max - min) / (2.0 - max - min); // this formula is used when luminance > 50%\n\n // return saturation in %\n return s * 100;\n};\n\nexport const rgbToHsl = (rgb: RGBColor, decimalPlaces = Infinity): HSLColor => {\n\n // convert rgb values to the range [0, 1]\n const r = rgb[0] / 255;\n const g = rgb[1] / 255;\n const b = rgb[2] / 255;\n\n // find the minimum and maximum values of r, g, and b\n const min = Math.min(r, g, b);\n const max = Math.max(r, g, b);\n\n // calculate the luminance value in %\n const l = getLuminance(r, g, b, min, max);\n\n // calculate the saturation in %\n const s = getSaturation(r, g, b, min, max, l);\n\n // calculate the hue in % (not in degrees!)\n const h = getHue(r, g, b, min, max);\n\n if(h > 360 || s > 100 || l > 100){\n return [0, 0, 100];\n }\n\n if(h < 0 || s < 0 || l < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(h, decimalPlaces),\n setDecimalPlaces(s, decimalPlaces),\n setDecimalPlaces(l, decimalPlaces),\n ];\n};\n\n/**\n * helper: HSL to RGB\n */\nconst hslToRgbHelper = (helper1 : number, helper2 : number, colorHelper : number) : number => {\n\n // all values need to be between 0 and 1\n // if you get a negative value you need to add 1 to it\n if(colorHelper < 0) colorHelper += 1;\n\n // if you get a value above 1 you need to subtract 1 from it.\n if(colorHelper > 1) colorHelper -= 1;\n\n if(colorHelper * 6 < 1) return helper2 + (helper1 - helper2) * 6 * colorHelper;\n\n if(colorHelper * 2 < 1) return helper1;\n\n if(colorHelper * 3 < 2){\n return helper2 + (helper1 - helper2) * (0.666 - colorHelper) * 6;\n }\n else{\n return helper2;\n }\n};\n\nexport const hslToRgb = (hsl: HSLColor, decimalPlaces = Infinity): RGBColor => {\n\n // convert all values to [0, 1] from %\n const h = hsl[0] / 100;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n // if there is no saturation -> it\u2019s grey\n if(s === 0){\n // convert the luminance from [0, 1] to [0, 255]\n const gray = l * 255;\n return [gray, gray, gray];\n }\n\n // check the level of luminance\n const helper1 = (l < 0.5) ?\n (l * (1.0 + s)) :\n (l + s - l * s);\n\n const helper2 = 2 * l - helper1;\n\n const rHelper = h + 0.333;\n const gHelper = h;\n const bHelper = h - 0.333;\n\n let r = hslToRgbHelper(helper1, helper2, rHelper);\n let g = hslToRgbHelper(helper1, helper2, gHelper);\n let b = hslToRgbHelper(helper1, helper2, bHelper);\n\n // convert rgb to [0, 255]\n r *= 255;\n g *= 255;\n b *= 255;\n\n if(r > 255 || g > 255 || b > 255){\n return [255, 255, 255];\n }\n\n if(r < 0 || g < 0 || b < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(r, decimalPlaces),\n setDecimalPlaces(g, decimalPlaces),\n setDecimalPlaces(b, decimalPlaces),\n ];\n};\n\n/**\n * HSL to hex\n * hslToHex(360, 100, 50) // [360, 100, 5] ==> \"#ff0000\" (red)\n */\nexport const hslToHex = (hsl: HSLColor) => {\n\n if(hsl[0] > 360 || hsl[1] > 100 || hsl[2] > 100){\n return '#ffffff';\n }\n\n if(hsl[0] < 0 || hsl[1] < 0 || hsl[2] < 0){\n return '#000000';\n }\n\n const h = hsl[0] / 360;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n let r, g, b;\n if (s === 0) {\n r = g = b = l; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n r = hue2rgb(p, q, h + 1 / 3);\n g = hue2rgb(p, q, h);\n b = hue2rgb(p, q, h - 1 / 3);\n }\n const toHex = (x: number) => {\n const hex = Math.round(x * 255).toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n};\n\n/**\n * RGB to HEX\n * rgbToHex([235, 64, 52]) // #eb4034\n */\nexport const rgbToHex = (rgb: RGBColor) => {\n const [r, g, b] = rgb;\n return '#' + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);\n};\n\nexport const hexToRgb = (hex: string) : RGBColor | null => {\n\n const shorthandRegex = /^#?([a-f\\d])([a-f\\d])([a-f\\d])$/i;\n const _hex = hex.replace(shorthandRegex, (_m, r, g, b) => {\n return r + r + g + g + b + b;\n });\n\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(_hex);\n if(!result) return null;\n\n const r = parseInt(result[1], 16);\n const g = parseInt(result[2], 16);\n const b = parseInt(result[3], 16);\n\n return [r, g, b];\n};\n\nexport const rgbToLab = (rgb: RGBColor, decimalPlaces = Infinity) : LABColor => {\n\n let r = rgb[0] / 255;\n let g = rgb[1] / 255;\n let b = rgb[2] / 255;\n\n r = (r > 0.04045) ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;\n g = (g > 0.04045) ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;\n b = (b > 0.04045) ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;\n\n let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;\n let y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;\n let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;\n\n x = (x > 0.008856) ? Math.pow(x, 1/3) : (7.787 * x) + 16/116;\n y = (y > 0.008856) ? Math.pow(y, 1/3) : (7.787 * y) + 16/116;\n z = (z > 0.008856) ? Math.pow(z, 1/3) : (7.787 * z) + 16/116;\n\n return [\n setDecimalPlaces((116 * y) - 16, decimalPlaces),\n setDecimalPlaces(500 * (x - y), decimalPlaces),\n setDecimalPlaces(200 * (y - z), decimalPlaces),\n ];\n};\n\nexport const labToRgb = (lab: LABColor, decimalPlaces = Infinity) : RGBColor => {\n let y = (lab[0] + 16) / 116;\n let x = lab[1] / 500 + y;\n let z = y - lab[2] / 200;\n\n x = 0.95047 * ((x * x * x > 0.008856) ? x * x * x : (x - 16/116) / 7.787);\n y = 1.00000 * ((y * y * y > 0.008856) ? y * y * y : (y - 16/116) / 7.787);\n z = 1.08883 * ((z * z * z > 0.008856) ? z * z * z : (z - 16/116) / 7.787);\n\n let r = x * 3.2406 + y * -1.5372 + z * -0.4986;\n let g = x * -0.9689 + y * 1.8758 + z * 0.0415;\n let b = x * 0.0557 + y * -0.2040 + z * 1.0570;\n\n r = (r > 0.0031308) ? (1.055 * Math.pow(r, 1/2.4) - 0.055) : 12.92 * r;\n g = (g > 0.0031308) ? (1.055 * Math.pow(g, 1/2.4) - 0.055) : 12.92 * g;\n b = (b > 0.0031308) ? (1.055 * Math.pow(b, 1/2.4) - 0.055) : 12.92 * b;\n\n return [\n setDecimalPlaces(Math.max(0, Math.min(1, r)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, g)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, b)) * 255, decimalPlaces),\n ];\n};\n\n// ----------------------- GET SHIFTED COLORS --------------------------------------\n\nexport const getShiftedHue = (color: HSLColor, shift = 180) : HSLColor => {\n let hue = color[0];\n hue += shift;\n\n if (hue > 360 || hue < 0) {\n hue = mod(hue, 360);\n }\n\n return [hue, color[1], color[2]];\n};\n\nexport const getShiftedLightness = (color: HSLColor, shift = 10) : HSLColor => {\n let lightness = color[2];\n lightness += shift;\n\n if (lightness > 100 || lightness < 0) {\n lightness = mod(lightness, 100);\n }\n\n return [color[0], color[1], lightness];\n};\n\nexport const getShiftedSaturation = (color: HSLColor, shift = 10) : HSLColor => {\n let saturation = color[1];\n saturation += shift;\n\n if (saturation > 100) {\n saturation -= 100;\n }\n\n if(saturation < 0){\n saturation += 100;\n }\n\n return [color[0], saturation, color[2]];\n};\n\n// ----------------------- SIMILAR COLORS --------------------------------------\n\n/**\n * Measure the perceptual difference between two RGB colors using the CIE76 color difference formula:\n * delta = Math.sqrt((L2 - L1)^2 + (a2 - a1)^2 + (b2 - b1)^2)\n * https://en.wikipedia.org/wiki/Color_difference\n * https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js\n * <= 1.0 Not perceptible by human eyes.\n * 1 - 2 Perceptible through close observation.\n * 2 - 10 Perceptible at a glance.\n * 11 - 49 Colors are more similar than opposite\n * 100 Colors are exact opposite\n */\nexport const getColorsDelta = (rgbA: RGBColor, rgbB: RGBColor, decimalPlaces = Infinity) => {\n const labA = rgbToLab(rgbA, decimalPlaces);\n const labB = rgbToLab(rgbB, decimalPlaces);\n\n // differences between the LAB components of the two colors\n const deltaL = labA[0] - labB[0];\n const deltaA = labA[1] - labB[1];\n const deltaB = labA[2] - labB[2];\n\n // chroma components\n const c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);\n const c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);\n const deltaC = c1 - c2;\n\n // difference in hue, deltaH, which takes into account both the differences\n // in the a* and b* components of LAB and the differences in chroma.\n let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;\n deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);\n\n const sc = 1.0 + 0.045 * c1;\n const sh = 1.0 + 0.015 * c1;\n\n // It applies weighting factors to the differences in lightness (deltaL),\n // chroma (deltaC), and hue (deltaH).\n const deltaLKlsl = deltaL / (1.0);\n const deltaCkcsc = deltaC / (sc);\n const deltaHkhsh = deltaH / (sh);\n\n // It computes the final color difference using the CIE76 formula:\n // deltaE = sqrt(deltaLKlsl^2 + deltaCkcsc^2 + deltaHkhsh^2),\n // where deltaLKlsl is the weighted lightness difference,\n // deltaCkcsc is the weighted chroma difference,\n // and deltaHkhsh is the weighted hue difference.\n const i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;\n\n // It returns the calculated color difference,\n // optionally rounded to the specified number of decimal places.\n return i < 0 ? 0 : Math.sqrt(i);\n};\n", "/**\n * guid like '932ade5e-c515-4807-ac01-73b20ab3fb66'\n */\nexport const guid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0;\n return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);\n });\n};\n\n/**\n * id like 'df4unio1opulby2uqh4'\n */\nexport const newId = () => {\n return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);\n};\n", "import { ICircle, IPolygon, IRect, Matrix2, Vector2 } from '../types';\nimport { mod } from './other';\nimport { v2GetNormal, v2DotProduct } from './linear-algebra/vector';\n\n/**\n * Rectangles collision detection.\n * Rectangles should not be rotated.\n * The algorithm works by ensuring there is no gap between any of the 4 sides of the rectangles.\n * Any gap means a collision does not exist.\n * Returns true if collision is detected.\n */\nexport const rectCollide = (rect1: IRect, rect2: IRect) : boolean => {\n return rect1.x <= rect2.x + rect2.w &&\n rect1.x + rect1.w >= rect2.x &&\n rect1.y <= rect2.y + rect2.h &&\n rect1.h + rect1.y >= rect2.y;\n};\n\n/**\n * Circles collision detection.\n * This algorithm works by taking the center points of the two circles\n * and ensuring the distance between the center points\n * are less than the two radii added together.\n * Returns true if collision is detected.\n */\nexport const circleCollide = (circle1: ICircle, circle2: ICircle) => {\n const dx = Math.abs(circle1.cx - circle2.cx);\n const dy = Math.abs(circle1.cy - circle2.cy);\n const distance = Math.sqrt(dx * dx + dy * dy);\n return distance <= circle1.r + circle2.r;\n};\n\n//-------------------- Separating Axis Theorem (SAT) Collision detection -------------------------\n\nconst getEdges = (poly: IPolygon) : Matrix2[] => {\n const edges: Matrix2[] = [];\n\n for(let i= 0; i {\n const edges: Matrix2[] = [];\n\n // collect polygon edges, and combine then into a single array\n edges.push(...getEdges(poly1));\n edges.push(...getEdges(poly2));\n\n // for each edge, find the normal vector and project both polygons onto it\n for (const edge of edges) {\n const normal = v2GetNormal(edge[0], edge[1]);\n const p1Proj = projectPolygon(poly1, normal);\n const p2Proj = projectPolygon(poly2, normal);\n\n // Check if the projections overlap\n const isOverlap = p1Proj.max >= p2Proj.min && p2Proj.max >= p1Proj.min;\n\n // Check if the projections overlap; if not, the polygons do not collide\n if (!isOverlap) return false;\n }\n\n // If all tests pass, the polygons overlap and collide\n return true;\n};\n\n/**\n * Project every polygon point onto the normal.\n * Then find min and max.\n */\nconst projectPolygon = (polygon: IPolygon, normal: Vector2): { min: number, max: number } => {\n let min = Infinity;\n let max = -Infinity;\n\n // Project each vertex of the polygon onto the axis\n for (const vertex of polygon) {\n const projection = v2DotProduct(vertex, normal);\n min = Math.min(min, projection);\n max = Math.max(max, projection);\n }\n\n return { min, max };\n};", "export interface IAnimationProps {\n duration?: number;\n callback: (result: IAnimationResult) => void;\n restartOnResize?: boolean;\n resizeCallback?: (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => void;\n}\n\nexport interface IAnimationResult {\n start: () => void;\n stop: () => void;\n pause: () => void;\n resume: () => void;\n restart: () => void;\n isAnimating: () => boolean;\n getStartTime: () => number|undefined;\n getElapsedTime: () => number|undefined;\n getPercent: () => number|undefined;\n getResizeObserver: () => ResizeObserver|undefined;\n}\n\nexport const animate = (props: IAnimationProps) : IAnimationResult => {\n\n const _duration = props.duration !== undefined ? props.duration : Infinity;\n\n let startTime: number|undefined = undefined; // in milliseconds\n let animationId: number|undefined = undefined;\n\n // the time elapsed since the start of the animation (in milliseconds)\n let elapsed: number|undefined = undefined;\n let previousTimeStamp: number|undefined = undefined;\n\n let animating = false;\n let observer: ResizeObserver|undefined = undefined;\n\n // -------------------- COMMANDS ---------------------\n\n const stop = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = false;\n\n /*if(observer !== undefined){\n observer.disconnect();\n observer = undefined;\n }*/\n\n if(animationId === undefined) return;\n window.cancelAnimationFrame(animationId);\n };\n\n const restart = () => {\n stop();\n start();\n };\n\n const pause = () => {\n animating = false;\n };\n\n const resume = () => {\n animating = true;\n };\n\n /**\n * Animation Step.\n * @param {number} timeStamp in milliseconds\n */\n const step = (timeStamp: DOMHighResTimeStamp) => {\n\n if (startTime === undefined) {\n startTime = timeStamp;\n }\n\n // the time elapsed since the start of the animation (in milliseconds)\n elapsed = timeStamp - startTime;\n\n if (animating && previousTimeStamp !== timeStamp && typeof props.callback === 'function') {\n\n // do the rendering .............\n props.callback(getResult());\n }\n\n if(elapsed <= _duration){\n previousTimeStamp = timeStamp;\n animationId = window.requestAnimationFrame(step);\n }\n else{\n stop();\n }\n };\n\n const observerHandler = (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => {\n restart();\n\n if(typeof props.resizeCallback === 'function'){\n props.resizeCallback(_entries, _observer);\n }\n };\n\n const start = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = true;\n\n if(props.restartOnResize && window.ResizeObserver && observer === undefined){\n observer = new ResizeObserver(observerHandler);\n observer.observe(document.body, { box: 'border-box' });\n }\n else{\n animationId = window.requestAnimationFrame(step);\n }\n };\n\n // --------------- GET INFO ----------------------\n\n /**\n * the time elapsed since the start of the animation (in milliseconds)\n */\n const getElapsedTime = () : number|undefined => {\n return elapsed;\n };\n\n const isAnimating = () => {\n return animating;\n };\n\n const getStartTime = () => {\n return startTime;\n };\n\n const getPercent = () => {\n if(_duration === Infinity || elapsed === undefined) return undefined;\n return elapsed * 100 / _duration;\n };\n\n const getResizeObserver = () => {\n return observer;\n };\n\n const getResult = () : IAnimationResult => {\n return {\n\n // commands --------------\n start,\n stop,\n pause,\n resume,\n restart,\n\n // information -------\n isAnimating,\n getElapsedTime,\n getStartTime,\n getPercent,\n getResizeObserver,\n };\n };\n\n return getResult();\n};\n", "import { setDecimalPlaces } from './format';\n\nexport const getCircleCircumference = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * radius, decimalPlaces);\n};\n\nexport const getEllipseCircumference = (radius1: number, radius2: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * Math.sqrt((radius1 ** 2 + radius2 ** 2) / 2), decimalPlaces);\n};\n\nexport const isAngleInCircleArc = (startAngleDeg: number, endAngleDeg: number, currentDegrees: number) : boolean => {\n\n if(startAngleDeg > endAngleDeg) {\n endAngleDeg += 360;\n }\n\n return currentDegrees >= startAngleDeg && currentDegrees <= endAngleDeg ||\n (currentDegrees + 360) >= startAngleDeg && (currentDegrees + 360) <= endAngleDeg;\n};\n\n/**\n * get the side of a square inscribed in a circle\n */\nexport const getSquareInCircleSide = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(radius * 2 / Math.sqrt(2), decimalPlaces);\n};\n", "/**\n * 1 + 2 + ... + n = n * (n + 1) / 2\n */\nexport const naturalNumbersSequenceSum = (n: number) => {\n return n * (n + 1) / 2;\n};\n\n/**\n * n = the number of terms to be added\n * a = the first term in the sequence\n * d = the constant value between terms\n */\nexport const arithmeticSequenceSum = (n: number, a: number, d: number) => {\n return (n / 2) * (2 * a + (n - 1) * d);\n};", "\n// -------------------- CENTRAL TENDENCY ----------------------------\n\nimport { setDecimalPlaces } from './format';\n\n/**\n * Central tendency: Calculate the Average (mean)\n * Sum of all numbers divided by the array length.\n */\nexport const getArithmeticMean = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const sum = data.reduce((acc, val) => acc + val, 0);\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};\n\n/**\n * Central tendency: What is the central number in the sorted array?\n * Good for lists like [3, 3, 3, 3, 3, 3, 100] - 100 here is called \"Outlier\"\n */\nexport const getMedian = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const copy = [...data].sort((num1, num2) => num1 - num2);\n const mid = Math.floor(copy.length / 2);\n\n if(copy.length % 2 === 0) {\n return setDecimalPlaces((copy[mid] + copy[mid - 1]) / 2, decimalPlaces);\n }\n else {\n return setDecimalPlaces(copy[mid], decimalPlaces);\n }\n};\n\n/**\n * Central tendency: What number is most common in the set.\n * If all numbers have the same frequency, there is no mode.\n */\nexport const getMode = (data: number[]) : number[]|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n // Count frequency of each number in the data array.\n const frequencyMap: Map = new Map();\n for (const num of data) {\n frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);\n }\n\n let maxFrequency = 0;\n let modes: number[] = [];\n\n // Find the maximum frequency\n for (const [num, frequency] of frequencyMap) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency;\n modes = [num];\n }\n else if (frequency === maxFrequency) {\n modes.push(num);\n }\n }\n\n // If all numbers have the same frequency, there is no mode\n if (modes.length === data.length) {\n return undefined;\n }\n\n // Return the mode(s)\n return modes.length === 1 ? [modes[0]] : modes;\n};\n\n/*\nTODO:\n- geometric mean\n- harmonic mean\n */\n\n// -------------------- DISPERSION ----------------------------\n\nexport const getVariance = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const mean = getArithmeticMean(data);\n if(mean === undefined) return undefined;\n\n const sum = data.reduce((acc, val) => acc + ((val - mean) ** 2), 0);\n\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};"], - "mappings": ";;;;;;;eAAO,IAAMA,EAAmB,CAACC,EAAaC,EAAoC,MAAa,CAC3F,GAAGA,IAAkB,IAAU,OAAOD,EAEnCC,EAAgB,IACfA,EAAgB,GAGpB,IAAMC,EAAcC,EAAA,GAAMF,GAC1B,OAAO,KAAK,MAAMD,EAAME,CAAW,EAAIA,CAC3C,ECNO,IAAME,EAAM,CAACC,EAAWC,KAClBD,EAAIC,EAAKA,GAAKA,EAOdC,EAAe,CAACC,EAAWC,EAAWC,EAAWC,EAAWC,KAC7DA,EAAID,IAAMH,EAAIC,IAAMC,EAAID,GAAKE,EAM5BE,GAAkB,CAACJ,EAAWC,EAAWC,EAAWC,IACtD,KAAK,IAAIH,EAAGE,CAAC,GAAK,KAAK,IAAID,EAAGE,CAAC,EAI7BE,EAAYC,GACd,CAAC,MAAM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E9B,IAAMkB,EAAOnB,GAAkBC,CAAI,EACnC,GAAGkB,IAAS,OAAW,OAEvB,IAAMhB,EAAMF,EAAK,OAAO,CAACG,EAAKC,IAAQD,EAAQgB,EAAAf,EAAMc,EAAS,GAAI,CAAC,EAElE,OAAOb,EAAiBH,EAAMF,EAAK,OAAQC,CAAa,CAC5D", - "names": ["setDecimalPlaces", "num", "decimalPlaces", "coefficient", "__pow", "mod", "n", "m", "convertRange", "x", "a", "b", "c", "d", "doRangesOverlap", "isNumber", "value", "polarToCartesian", "center", "radii", "angleInRad", "decimalPlaces", "cx", "cy", "rx", "ry", "setDecimalPlaces", "getV2Angle", "v2", "decimalPlaces", "angle", "setDecimalPlaces", "getV2AngleInEllipse", "radii", "setV2Angle", "newAngleRad", "length", "v2Length", "radiansToDegrees", "radians", "res", "degreesToRadians", "degrees", "getVNAngleBetween", "vector1", "vector2", "unitVector1", "vNormalize", "unitVector2", "dotProduct", "vDotProduct", "getV2AngleBetween", "diff", "vSub", "getV3AngleBetween", "isAngleBetween", "angleDegrees", "startAngleDegrees", "endAngleDegrees", "distance", "getAnglesSub", "distance1", "distance2", "totalDistance", "isClockwise", "angle1Deg", "angle2Deg", "startAngleDeg", "angleDegrees1", "angleDegrees2", "angleDistance", "mod", "getAnglesDistance", "percentToAngle", "percent", "endAngleDeg", "circleStartAngle", "vSum", "vector1", "vector2", "decimalPlaces", "vector", "i", "setDecimalPlaces", "v2Sum", "v3Sum", "vSub", "v2Sub", "v3Sub", "vMulScalar", "v", "scalar", "v2MulScalar", "v2", "v3MulScalar", "v3", "vDivideScalar", "v2DivideScalar", "v3DivideScalar", "vLength", "sum", "v2Length", "v3Length", "v2SetLength", "newLength", "angle", "getV2Angle", "vDistance", "diff", "v2Distance", "v3Distance", "vNormalize", "length", "unitVector", "v2Normalize", "v3Normalize", "vDotProduct", "v2DotProduct", "v3DotProduct", "v3CrossProduct", "defaultValue", "v4", "vN", "N", "v2FromPolarCoords", "distance", "angleRad", "setV2Angle", "vEqual", "v2GetNormal", "sub", "mSum", "matrix1", "matrix2", "decimalPlaces", "matrix", "i", "vSum", "m2Sum", "m3Sum", "mSub", "vSub", "m2Sub", "m3Sub", "mMulScalar", "m", "scalar", "v", "vMulScalar", "m2MulScalar", "m2", "m3MulScalar", "m3", "mDivideScalar", "vDivideScalar", "m2DivideScalar", "m3DivideScalar", "mTranspose", "vectorsCount", "vectorLength", "j", "m2Transpose", "m3Transpose", "mReset", "defaultValue", "res", "size", "vector", "m2Reset", "m3Reset", "m2x2", "m3x3", "m4x4", "mNxM", "N", "M", "vN", "identity2", "identity3", "identity4", "identityN", "mDeepCopy", "m2DeepCopy", "m3DeepCopy", "mAppendCol", "col", "copy", "mPrependCol", "mAppendRow", "row", "m2AppendRow", "m3AppendRow", "mPrependRow", "m2PrependRow", "m3PrependRow", "mDelLastRow", "mDelFirstRow", "mDelLastColumn", "mDelFirstColumn", "mGetFirstColumn", "mGetLastColumn", "mGetColumn", "colIndex", "mMul", "transposed", "vector1", "vector2", "product", "vDotProduct", "mMulVector", "mEqual", "vEqual", "mMinorHelper", "mMinor", "mDeterminant", "m2Determinant", "d", "minor", "param", "m3Determinant", "m2Adjugate", "m3Adjugate", "mAdjugate", "cofactors", "sign", "isSingularMatrix", "m2Inverse", "adj", "m3Inverse", "mInverse", "m2ToCSS", "m", "a", "b", "c", "d", "m2hToCSS", "tx", "ty", "m2hToCSS3d", "m3hToCSS3d", "m2Translation", "position", "decimalPlaces", "setDecimalPlaces", "m3Translation", "m2TranslationH", "m3TranslationH", "m2Rotation", "angleRad", "isClockwise", "cos", "sin", "m2RotationH", "m2RotationAroundPointH", "transformOrigin", "translation", "rotation", "translationBack", "v3MulScalar", "temp1", "mMul", "m2RotateAroundPointH", "mat3h", "mMulVector", "v2Rotate", "vector", "unitVector", "v2Normalize", "v2RotateH", "v3Normalize", "m3RotationX", "m3RotationXH", "v3RotateX", "m3RotationY", "m3RotationYH", "v3RotateY", "m3RotationZ", "m3RotationZH", "v3RotateZ", "m2ScaleAtPointHMatrix", "scaleVector", "scale", "m2ScaleH", "m2ScaleAtPointH", "point", "m2Scale", "v2Scale", "m3Scale", "m3ScaleH", "v3Scale", "m2ScaleX", "m2ScaleXH", "m3ScaleX", "m3ScaleXH", "m3ScaleY", "m3ScaleYH", "m3ScaleZ", "m3ScaleZH", "m2ScaleY", "m2ScaleYH", "m2ReflectionOrigin", "m2ReflectionOriginH", "m3ReflectionOrigin", "m3ReflectionOriginH", "m2ReflectionYmX", "m2ReflectionX", "m2ReflectionXH", "m2ReflectionY", "m2ReflectionYH", "m3ReflectionYZ", "m3ReflectionYZH", "m3ReflectionXZ", "m3ReflectionXZH", "m3ReflectionXY", "m3ReflectionXYH", "m2ShearingY", "factor", "m2ShearingX", "getRandom", "min", "max", "decimalPlaces", "setDecimalPlaces", "getRandomInt", "getRandomBoolean", "getRandomItemFromArray", "array", "randomIndex", "stringToNumber", "value", "defaultNumber", "_a", "res", "dxPolynomial", "x", "polynomial", "decimalPlaces", "res", "part", "coeff", "power", "setDecimalPlaces", "dxV2QuadraticBezierCurve", "startControlPoint", "centerControlPoint", "endControlPoint", "temp1", "temp2", "temp3", "dxV3QuadraticBezierCurve", "dxV2CubicBezierCurve", "center1ControlPoint", "center2ControlPoint", "temp4", "dxV3CubicBezierCurve", "dxSin", "dxCos", "dxTan", "__pow", "dxCot", "dxArcSin", "dxArcCos", "dxArcTan", "dxArcCot", "linearEquation", "equation", "decimalPlaces", "a", "b", "diff", "setDecimalPlaces", "linearEquationSystem2", "equation1", "equation2", "equationParams", "inversed", "m2Inverse", "equationResults", "mMulVector", "linearEquationSystem3", "equation3", "m3Inverse", "linearEquationSystemN", "equations", "mDelLastColumn", "mInverse", "mGetLastColumn", "getLinearEquationBy2Points", "point1", "point2", "deltaX", "deltaY", "v2Sub", "x", "y", "m", "formula", "quadraticEquation", "equation", "decimalPlaces", "a", "b", "c", "d", "res", "linearEquation", "isNumber", "diff", "discriminant", "setDecimalPlaces", "t1", "t2", "v2QuadraticBezierCurve", "startControlPoint", "centerControlPoint", "endControlPoint", "decimalPlaces", "temp1", "temp2", "temp3", "setDecimalPlaces", "v3QuadraticBezierCurve", "v2CubicBezierCurve", "center1ControlPoint", "center2ControlPoint", "temp4", "v3CubicBezierCurve", "v2QuadraticBezierCurveTangent", "dxVector", "dxV2QuadraticBezierCurve", "v2Normalize", "v3QuadraticBezierCurveTangent", "dxV3QuadraticBezierCurve", "v3Normalize", "v2CubicBezierCurveTangent", "dxV2CubicBezierCurve", "v3CubicBezierCurveTangent", "dxV3CubicBezierCurve", "v2QuadraticBezierCurveNormal", "tangent", "v2CubicBezierCurveNormal", "v2QuadraticBezierCurveExtrema", "a1", "b1", "res1", "linearEquation", "a2", "b2", "res2", "res", "isNumber", "v2CubicBezierCurveExtrema", "c1", "equation1", "c2", "equation2", "quadraticEquation", "num", "v2QuadraticBezierBBox", "extrema", "minX", "minY", "maxX", "maxY", "percent", "point", "x", "y", "v2CubicBezierBBox", "circleMovement", "center", "angle", "radius", "circleMovementAfterMouse", "mouse", "vector", "v2Sub", "getV2Angle", "convertRange", "ellipseMovement", "radius1", "radius2", "ellipseMovementAfterMouse", "radii", "sineWaveMovement", "x", "amplitude", "frequency", "phase", "y", "lissajousCurve", "width", "height", "t", "k", "n", "m", "p", "getRandomRGBColor", "hslColor", "getRandomHSLColor", "hslToRgb", "getRandomHexColor", "hslToHex", "h", "getRandom", "s", "l", "getRandomHSLColorWithHue", "getRandomHSLColorWithSaturation", "getRandomHSLColorWithLightness", "getRandomGrayscaleHSLColor", "getRandomHSLColorWithinRanges", "hueStart", "hueEnd", "saturationStart", "saturationEnd", "lightStart", "lightEnd", "convertHueToDegrees", "getHue", "r", "g", "b", "min", "max", "diff", "getLuminance", "getSaturation", "rgbToHsl", "rgb", "decimalPlaces", "setDecimalPlaces", "hslToRgbHelper", "helper1", "helper2", "colorHelper", "hsl", "gray", "rHelper", "gHelper", "bHelper", "hue2rgb", "q", "t", "p", "toHex", "hex", "rgbToHex", "hexToRgb", "shorthandRegex", "_hex", "_m", "result", "rgbToLab", "x", "y", "z", "labToRgb", "lab", "getShiftedHue", "color", "shift", "hue", "mod", "getShiftedLightness", "lightness", "getShiftedSaturation", "saturation", "getColorsDelta", "rgbA", "rgbB", "labA", "labB", "deltaL", "deltaA", "deltaB", "c1", "c2", "deltaC", "deltaH", "sc", "sh", "deltaLKlsl", "deltaCkcsc", "deltaHkhsh", "i", "guid", "c", "newId", "rectCollide", "rect1", "rect2", "circleCollide", "circle1", "circle2", "dx", "dy", "getEdges", "poly", "edges", "i", "nextIndex", "mod", "edge", "convexPolygonsCollide", "poly1", "poly2", "normal", "v2GetNormal", "p1Proj", "projectPolygon", "p2Proj", "polygon", "min", "max", "vertex", "projection", "v2DotProduct", "animate", "props", "_duration", "startTime", "animationId", "elapsed", "previousTimeStamp", "animating", "observer", "stop", "restart", "start", "pause", "resume", "step", "timeStamp", "getResult", "observerHandler", "_entries", "_observer", "getElapsedTime", "isAnimating", "getStartTime", "getPercent", "getResizeObserver", "getCircleCircumference", "radius", "decimalPlaces", "setDecimalPlaces", "getEllipseCircumference", "radius1", "radius2", "__pow", "isAngleInCircleArc", "startAngleDeg", "endAngleDeg", "currentDegrees", "getSquareInCircleSide", "naturalNumbersSequenceSum", "n", "arithmeticSequenceSum", "a", "d", "getArithmeticMean", "data", "decimalPlaces", "sum", "acc", "val", "setDecimalPlaces", "getMedian", "copy", "num1", "num2", "mid", "getMode", "frequencyMap", "num", "maxFrequency", "modes", "frequency", "getVariance", "mean", "__pow"] + "sources": ["../src/main/format.ts", "../src/main/other.ts", "../src/main/angle.ts", "../src/main/linear-algebra/vector.ts", "../src/main/linear-algebra/matrix.ts", "../src/main/linear-algebra/matrix-transformations.ts", "../src/main/random.ts", "../src/main/convert.ts", "../src/main/derivative.ts", "../src/main/equations/linear-equations.ts", "../src/main/equations/quadratic-equations.ts", "../src/main/bezier-curves/bezier-curve.ts", "../src/main/path-movement.ts", "../src/main/color.ts", "../src/main/id.ts", "../src/main/collision-detection.ts", "../src/main/animation.ts", "../src/main/circle-ellipse.ts", "../src/main/sequence.ts", "../src/main/statistics.ts", "../src/main/ml.ts"], + "sourcesContent": ["export const setDecimalPlaces = (num: number, decimalPlaces: number | undefined = Infinity) => {\n if(decimalPlaces === Infinity) return num;\n\n if(decimalPlaces < 0){\n decimalPlaces = 0;\n }\n\n const coefficient = 10 ** decimalPlaces;\n return Math.round(num * coefficient) / coefficient;\n};", "import { Vector2 } from '../types';\nimport { setDecimalPlaces } from './format';\n\nexport const mod = (n: number, m: number) => {\n return ((n % m) + m) % m;\n};\n\n/**\n * Convert range [a, b] to [c, d].\n * f(x) = (d - c) * (x - a) / (b - a) + c\n */\nexport const convertRange = (x: number, a: number, b: number, c: number, d: number) => {\n return (d - c) * (x - a) / (b - a) + c;\n};\n\n/**\n * Check if 2 ranges [a,b] and [c,d] overlap.\n */\nexport const doRangesOverlap = (a: number, b: number, c: number, d: number) => {\n return Math.max(a, c) <= Math.min(b, d) ;\n};\n\n// eslint-disable-next-line\nexport const isNumber = (value: any) => {\n return !isNaN(parseFloat(value)) && isFinite(value);\n};\n\n/**\n * Convert polar coordinates to cartesian coordinates.\n */\nexport const polarToCartesian = (center: Vector2, radii: Vector2, angleInRad: number, decimalPlaces = Infinity) : Vector2 => {\n const [cx, cy] = center;\n const [rx, ry] = radii;\n\n return [\n setDecimalPlaces(cx + (rx * Math.cos(angleInRad)), decimalPlaces),\n setDecimalPlaces(cy + (ry * Math.sin(angleInRad)), decimalPlaces),\n ];\n};", "import { Vector, Vector2, Vector3 } from '../types';\nimport { setDecimalPlaces } from './format';\nimport { v2Length, vNormalize, vDotProduct, vSub } from './linear-algebra/vector';\nimport { mod } from './other';\n\nexport const getV2Angle = (v2: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1], v2[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleInEllipse = (v2: Vector2, radii: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1]/radii[1], v2[0]/radii[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const setV2Angle = (v2: Vector2, newAngleRad: number, decimalPlaces = Infinity): Vector2 => {\n const length = v2Length(v2);\n return [\n setDecimalPlaces(Math.cos(newAngleRad) * length, decimalPlaces),\n setDecimalPlaces(Math.sin(newAngleRad) * length, decimalPlaces),\n ];\n};\n\nexport const radiansToDegrees = (radians: number, decimalPlaces = Infinity) => {\n const res = radians * (180 / Math.PI);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\nexport const degreesToRadians = (degrees: number, decimalPlaces = Infinity) => {\n const res = degrees * (Math.PI / 180);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\n/**\n * Returns the range [0, Math.PI]\n * A = Math.acos( dot(v1, v2)/(v1.length()*v2.length()) );\n */\nexport const getVNAngleBetween = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n const unitVector1 = vNormalize(vector1);\n const unitVector2 = vNormalize(vector2);\n const dotProduct = vDotProduct(unitVector1, unitVector2);\n const angle = Math.acos(dotProduct);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleBetween = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) : number => {\n // return getVNAngleBetween(vector1, vector2, decimalPlaces);\n const diff = vSub(vector1, vector2);\n const angle = Math.atan2(diff[1], diff[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV3AngleBetween = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return getVNAngleBetween(vector1, vector2, decimalPlaces);\n};\n\nexport const isAngleBetween = (angleDegrees: number, startAngleDegrees: number, endAngleDegrees: number) : boolean => {\n const distance = getAnglesSub(startAngleDegrees, endAngleDegrees);\n const distance1 = getAnglesSub(startAngleDegrees, angleDegrees);\n const distance2 = getAnglesSub(endAngleDegrees, angleDegrees);\n const totalDistance = distance1 + distance2;\n\n // Use a small threshold for floating point errors\n return Math.abs(totalDistance - distance) <= 0.001;\n}\n\nexport const isClockwise = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n return angle2Deg >= angle1Deg;\n};\n\n/**\n * Shortest distance (angular) between two angles.\n */\nexport const getAnglesSub = (angleDegrees1: number, angleDegrees2: number, decimalPlaces = Infinity) : number => {\n const angleDistance = Math.abs(mod(angleDegrees1, 360) - mod(angleDegrees2, 360));\n return setDecimalPlaces(angleDistance <= 180 ? angleDistance : 360 - angleDistance, decimalPlaces);\n};\n\nexport const getAnglesDistance = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0, decimalPlaces = Infinity) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n if(isClockwise(angle1Deg, angle2Deg, startAngleDeg)) {\n return setDecimalPlaces((angle2Deg - angle1Deg + 360) % 360, decimalPlaces);\n }\n else{\n return setDecimalPlaces((angle1Deg - angle2Deg + 360) % 360, decimalPlaces);\n }\n};\n\nexport const percentToAngle = (percent: number, startAngleDeg: number, endAngleDeg: number, circleStartAngle = 0) => {\n if(percent < 0) {\n percent = 0;\n }\n\n if(percent > 100) {\n percent = 100;\n }\n\n const distance = getAnglesDistance(startAngleDeg, endAngleDeg, circleStartAngle);\n\n const clockwise = isClockwise(startAngleDeg, endAngleDeg, circleStartAngle);\n if(clockwise) {\n return mod(circleStartAngle + (percent * distance / 100), 360);\n }\n else {\n return mod(circleStartAngle - (percent * distance / 100), 360);\n }\n};", "import { Vector, Vector2, Vector3, Vector4 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { getV2Angle, setV2Angle } from '../angle';\n\n// ------------ SUM ------------------------\n\nexport const vSum = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSum(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sum = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSum(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ SUB ------------------------\n\nexport const vSub = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSub(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sub = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSub(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ MUL SCALAR ------------------------\n\nexport const vMulScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n const vector: Vector = [];\n\n for(let i=0; i {\n return vMulScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3MulScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vMulScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ DIVIDE ------------------------\n\nexport const vDivideScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vDivideScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3DivideScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vDivideScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ LENGTH ------------------------\n\nexport const vLength = (vector: Vector, decimalPlaces = Infinity) => {\n let sum = 0;\n\n for(let i=0; i {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v3Length = (vector: Vector3, decimalPlaces = Infinity) => {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v2SetLength = (v2: Vector2, newLength: number, decimalPlaces = Infinity): Vector2 => {\n const angle = getV2Angle(v2);\n return [\n setDecimalPlaces(Math.cos(angle) * newLength, decimalPlaces),\n setDecimalPlaces(Math.sin(angle) * newLength, decimalPlaces),\n ];\n};\n\n// ----------- DISTANCE ------------------------\n\nexport const vDistance = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v2Distance = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v3Distance = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\n// ------------ NORMALIZE ------------------------\n\n/**\n * Normalization creates a unit vector, which is a vector of length 1.\n */\nexport const vNormalize = (v: Vector, decimalPlaces = Infinity) : Vector => {\n const length = vLength(v);\n const unitVector: Vector = [];\n\n for(let i=0; i {\n return vNormalize(v2, decimalPlaces) as Vector2;\n};\n\nexport const v3Normalize = (v3: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vNormalize(v3, decimalPlaces) as Vector3;\n};\n\n// ------------ DOT PRODUCT ------------------------\n\nexport const vDotProduct = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n let sum = 0;\n\n for(let i=0; i {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\nexport const v3DotProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\n// ------------ CROSS PRODUCT ------------------------\n\n/**\n * Cross product is possible on 3D vectors only.\n * The cross product a \u00D7 b is defined as a vector c that is perpendicular (orthogonal) to both a and b.\n */\nexport const v3CrossProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity): Vector3 => {\n return [\n setDecimalPlaces(vector1[1] * vector2[2] - vector1[2] * vector2[1], decimalPlaces),\n setDecimalPlaces(vector1[2] * vector2[0] - vector1[0] * vector2[2], decimalPlaces),\n setDecimalPlaces(vector1[0] * vector2[1] - vector1[1] * vector2[0], decimalPlaces),\n ];\n};\n\n// --------------- INIT VECTOR HELPER -----------------\n\nexport const v2 = (defaultValue = 0): Vector2 => {\n return [defaultValue, defaultValue];\n};\n\nexport const v3 = (defaultValue = 0): Vector3 => {\n return [defaultValue, defaultValue, defaultValue];\n};\n\nexport const v4 = (defaultValue = 0): Vector4 => {\n return [defaultValue, defaultValue, defaultValue, defaultValue];\n};\n\nexport const vN = (N: number, defaultValue = 0): Vector => {\n\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n const vector: Vector = [];\n for(let i=0; i {\n let vector: Vector2 = [0, 0];\n vector = v2SetLength(vector, distance);\n return setV2Angle(vector, angleRad);\n};\n\n// --------------- EQUALITY -------------------------\n\nexport const vEqual = (vector1: Vector, vector2: Vector): boolean => {\n if(vector1.length !== vector2.length) return false;\n\n for(let i=0; i {\n const sub = v2Sub(vector2, vector1);\n return [\n -setDecimalPlaces(sub[1], decimalPlaces),\n setDecimalPlaces(sub[0], decimalPlaces)\n ];\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector, Vector2, Vector3 } from '../../types';\nimport { vMulScalar, vSum, vSub, vDotProduct, vN, vEqual, vDivideScalar } from './vector';\n\n// --------------- SUM ----------------------\n\nexport const mSum = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sum = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- SUB ----------------------\n\nexport const mSub = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sub = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- MUL SCALAR ----------------------\n\nexport const mMulScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vMulScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2MulScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mMulScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3MulScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mMulScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n// --------------- DIVIDE SCALAR ----------------------\n\nexport const mDivideScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vDivideScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2DivideScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mDivideScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3DivideScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mDivideScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n\n// --------------- TRANSPOSE ----------------------\n\nexport const mTranspose = (m: Matrix): Matrix => {\n\n const vectorsCount = m.length;\n if(vectorsCount <= 0) return m;\n\n const vectorLength = m[0].length;\n if(vectorLength <= 0) return m;\n\n const matrix: Matrix = [];\n for(let i=0; i {\n return mTranspose(m2);\n};\n\nexport const m3Transpose = (m3: Matrix3): Matrix => {\n return mTranspose(m3);\n};\n\n// ----------------- RESET ----------------------\n\nexport const mReset = (m: Matrix, defaultValue = 0): Matrix => {\n\n if(m.length <= 0) return [];\n\n const res: Matrix = [];\n\n for(let i=0; i {\n return mReset(m2, defaultValue) as Matrix2;\n};\n\nexport const m3Reset = (m3: Matrix3, defaultValue = 0): Matrix3 => {\n return mReset(m3, defaultValue) as Matrix3;\n};\n\n// --------------- MATRIX INIT HELPERS -----------------\n\nexport const m2x2 = (defaultValue = 0): Matrix2 => {\n return [\n [defaultValue, defaultValue],\n [defaultValue, defaultValue],\n ];\n};\n\nexport const m3x3 = (defaultValue = 0): Matrix3 => {\n return [\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const m4x4 = (defaultValue = 0): Matrix4 => {\n return [\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const mNxM = (N: number, M: number, defaultValue = 0): Matrix => {\n if(N <= 0 || M <= 0){\n throw new Error('M and N must be positive numbers.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return [\n [1, 0],\n [0, 1],\n ];\n};\n\nexport const identity3 = (): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\nexport const identity4 = (): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Identity Matrix (I).\n * M x I = I x M = M for any matrix M.\n * Identity Matrix is a special case of scale matrix.\n */\nexport const identityN = (N: number): Matrix => {\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n if(N === 0) return [];\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mDeepCopy(m2) as Matrix2;\n};\n\nexport const m3DeepCopy = (m3: Matrix3): Matrix3 => {\n return mDeepCopy(m3) as Matrix3;\n};\n\n// -------------- APPEND / PREPEND ROW OR COLUMN ---------------\n\nexport const mAppendCol = (m: Matrix, col: Vector): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n const copy = mDeepCopy(m);\n copy.push(row);\n return copy;\n};\n\nexport const m2AppendRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.push(row);\n return copy;\n};\n\nexport const m3AppendRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.push(row);\n return copy;\n};\n\nexport const mPrependRow = (m: Matrix, row: Vector) : Matrix => {\n const copy = mDeepCopy(m);\n copy.unshift(row);\n return copy;\n};\n\nexport const m2PrependRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.unshift(row);\n return copy;\n};\n\nexport const m3PrependRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.unshift(row);\n return copy;\n};\n\n// ------------ DELETE ROW OR COLUMN ----------------------------\n\nexport const mDelLastRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.pop();\n return copy;\n};\n\nexport const mDelFirstRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.shift();\n return copy;\n};\n\nexport const mDelLastColumn = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const size = m[0].length;\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n\n const matrix: Matrix = [];\n for(let i=0; i {\n\n if(matrix.length < 0) return [];\n\n if(matrix[0].length !== vector.length){\n throw new Error('The number of columns in the matrix must be equal to the length of the vector.');\n }\n\n const res: Vector = [];\n\n for(let i=0; i {\n if(matrix1.length !== matrix2.length) return false;\n\n for(let i=0; i returns matrix N (m-1 x m-1)\n * The matrix must be square.\n */\nconst mMinorHelper = (m: Matrix, row: number, col: number) => {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // prepare the matrix without provided row and column\n const matrix = mMinorHelper(m, row, col);\n\n // calculate the matrix determinant\n return mDeterminant(matrix);\n};\n\n/**\n * Calculate determinant for NxN matrix.\n * Matrix should be square.\n */\nexport const mDeterminant = (matrix: Matrix): number => {\n const size = matrix.length;\n if(size === 0) return 1;\n\n if(size !== matrix[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return matrix[0][0];\n if(size === 2) return m2Determinant(matrix as Matrix2);\n\n let d = 0;\n\n for(let i=0; i {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return m2[0][0] * m2[1][1] - m2[1][0] * m2[0][1];\n};\n\n/**\n * Calculate determinant for 3x3 matrix.\n * Matrix should be square.\n */\nexport const m3Determinant = (m3: Matrix3): number => {\n if(m3.length !== m3[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return mDeterminant(m3);\n};\n\n// ------------------ INVERSE -----------------------\n\nexport const m2Adjugate = (m2: Matrix2): Matrix2|null => {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return [\n [m2[1][1], -m2[0][1]],\n [-m2[1][0], m2[0][0]],\n ];\n};\n\nexport const m3Adjugate = (m3: Matrix3) : Matrix3|null => {\n return mAdjugate(m3) as (Matrix3|null);\n};\n\n/**\n * Adjugate is a transpose of a cofactor matrix\n */\nexport const mAdjugate = (m: Matrix): Matrix|null => {\n\n const size = m.length;\n if(size <= 0) return null;\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return m;\n\n if(size === 2) return m2Adjugate(m as Matrix2);\n\n // build a cofactor matrix ----------------\n const cofactors: Matrix = [];\n\n for(let i=0; i {\n if(m.length > 0 && m.length !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = mDeterminant(m);\n return d === 0;\n};\n\n/**\n * Square matrix A (nxn) is invertible is there is another square matrix B (nxn) so AxB = BxA = I\n * For A (2x2) matrix, the inverse is:\n * (1 / (determinant(A))) * adj(A)\n */\nexport const m2Inverse = (m2: Matrix2, decimalPlaces = Infinity): (Matrix2 | null) => {\n if(m2.length > 0 && m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = m2Determinant(m2);\n if(d === 0) return null;\n\n const adj = m2Adjugate(m2);\n if(adj === null) return null;\n\n return m2DivideScalar(adj, d, decimalPlaces);\n};\n\nexport const m3Inverse = (m3: Matrix3, decimalPlaces = Infinity): (Matrix3 | null) => {\n return mInverse(m3, decimalPlaces) as (Matrix3|null);\n};\n\nexport const mInverse = (m: Matrix, decimalPlaces = Infinity): (Matrix | null) => {\n const size = m.length;\n\n if(size > 0 && size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // find a determinant ----------------------\n const d = mDeterminant(m);\n\n // find an Adjugate - a transpose of a cofactor matrix\n const adj = mAdjugate(m);\n if(adj === null) return null;\n\n return mDivideScalar(adj, d, decimalPlaces);\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector2, Vector3, Vector4 } from '../../types';\nimport { v2Normalize, v3MulScalar, v3Normalize } from './vector';\nimport { mMulVector, mMul } from './matrix';\nimport { setDecimalPlaces } from '../format';\n\n/*\nAny 2D affine transformation can be decomposed\ninto a rotation, followed by a scaling, followed by a\nshearing, and followed by a translation.\n---------------------------------------------------------\nAffine matrix = translation x shearing x scaling x rotation\n */\n\n// ----------------- CSS -------------------------------------\n\n/**\n * Matrix 2D in non-homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2ToCSS = (m: Matrix2) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, 0, 0)`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2hToCSS = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ tx }, ${ ty })`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m2hToCSS3d = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix3d(${ a }, ${ b }, 0, 0, ${ c }, ${ d }, 0, 0, 0, 0, 1, 0, ${ tx }, ${ ty }, 0, 1)`;\n};\n\n/**\n * Matrix 3D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m3hToCSS3d = (m: Matrix4) : string => {\n\n return `matrix3d(\n ${ m[0][0] }, ${ m[0][1] }, ${ m[0][2] }, ${ m[0][3] },\n ${ m[1][0] }, ${ m[1][1] }, ${ m[1][2] }, ${ m[1][3] },\n ${ m[2][0] }, ${ m[2][1] }, ${ m[2][2] }, ${ m[2][3] },\n ${ m[3][0] }, ${ m[3][1] }, ${ m[3][2] }, ${ m[3][3] }\n )`;\n};\n\n// ---------------- TRANSLATION MATRICES ----------------------\n\nexport const m2Translation = (position: Vector2, decimalPlaces = Infinity): Matrix2 => {\n\n return [\n [1, 0],\n [0, 1],\n [setDecimalPlaces(position[0], decimalPlaces), setDecimalPlaces(position[1], decimalPlaces)],\n ];\n};\n\nexport const m3Translation = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n [\n setDecimalPlaces(position[0], decimalPlaces),\n setDecimalPlaces(position[1], decimalPlaces),\n setDecimalPlaces(position[2], decimalPlaces)\n ],\n ];\n};\n\n/**\n * 2D Translation matrix in homogeneous coordinates.\n */\nexport const m2TranslationH = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1],\n ];\n};\n\n/**\n * 3D Translation matrix in homogeneous coordinates.\n */\nexport const m3TranslationH = (position: Vector4, decimalPlaces = Infinity): Matrix4 => {\n\n return [\n [1, 0, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, 0, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1, setDecimalPlaces(position[2], decimalPlaces)],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- ROTATION MATRICES -------------------------\n\n/**\n * Rotation of an angle about the origin.\n */\nexport const m2Rotation = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix2 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin],\n [sin, cos],\n ] :\n [\n [cos, sin],\n [-sin, cos],\n ];\n};\n\n/**\n * Rotation of an angle about the origin in homogeneous coordinates (clockwise).\n */\nexport const m2RotationH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ]:\n [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation of an angle \"angleRad\" around the given point (transformOrigin) in homogeneous coordinates (clockwise).\n * result_vector = TranslationMatrix(x, y) * RotationMatrix() * TranslationMatrix(-x, -y) * position_vector\n */\nexport const m2RotationAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const rotation = m2RotationH(angleRad, isClockwise, decimalPlaces);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, rotation);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2RotateAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n position: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2RotationAroundPointH(angleRad, transformOrigin, isClockwise, decimalPlaces);\n return mMulVector(mat3h, position) as Vector3;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2Rotate = (angleRad: number, vector: Vector2, isClockwise = true, decimalPlaces = Infinity): Vector2 => {\n const unitVector = v2Normalize(vector);\n return mMulVector(m2Rotation(angleRad, isClockwise, decimalPlaces), unitVector) as Vector2;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2RotateH = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m2RotationH(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the X axis (clockwise).\n */\nexport const m3RotationX = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0],\n [0, cos, -sin],\n [0, sin, cos],\n ] :\n [\n [1, 0, 0],\n [0, cos, sin],\n [0, -sin, cos],\n ];\n};\n\n/**\n * Rotation around the X axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationXH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0, 0],\n [0, cos, -sin, 0],\n [0, sin, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [1, 0, 0, 0],\n [0, cos, sin, 0],\n [0, -sin, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateX = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationX(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Y axis (clockwise).\n */\nexport const m3RotationY = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin],\n [0, 1, 0],\n [-sin, 0, cos],\n ] :\n [\n [cos, 0, -sin],\n [0, 1, 0],\n [sin, 0, cos],\n ];\n};\n\n/**\n * Rotation around the Y axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationYH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin, 0],\n [0, 1, 0, 0],\n [-sin, 0, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [cos, 0, -sin, 0],\n [0, 1, 0, 0],\n [sin, 0, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateY = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationY(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Z axis (clockwise).\n */\nexport const m3RotationZ = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ] : [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation around the Z axis (clockwise)- in homogeneous coordinates\n */\nexport const m3RotationZH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0, 0],\n [sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ] : [\n [cos, sin, 0, 0],\n [-sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateZ = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationZ(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n// ---------------- SCALE MATRICES -------------\n\n/**\n * Get matrix for arbitrary scaling pivot point.\n * result_vector = TranslationMatrix(x, y) * ScaleMatrix() * TranslationMatrix(-x, -y) * scale_vector\n */\nexport const m2ScaleAtPointHMatrix = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const scale = m2ScaleH(scaleVector);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, scale);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2ScaleAtPointH = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n point: Vector3,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2ScaleAtPointHMatrix(scaleVector, transformOrigin, decimalPlaces);\n return mMulVector(mat3h, point) as Vector3;\n};\n\nexport const m2Scale = (scaleVector: Vector2): Matrix2 => {\n return [\n [scaleVector[0], 0],\n [0, scaleVector[1]],\n ];\n};\n\nexport const v2Scale = (scaleVector: Vector2, vector: Vector2): Vector2 => {\n return mMulVector(m2Scale(scaleVector), vector) as Vector2;\n};\n\n/**\n * homogeneous coordinates\n */\nexport const m2ScaleH = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, 1],\n ];\n};\n\nexport const m3Scale = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, scaleVector[2]],\n ];\n};\n\nexport const m3ScaleH = (scaleVector: Vector4): Matrix4 => {\n return [\n [scaleVector[0], 0, 0, 0],\n [0, scaleVector[1], 0, 0],\n [0, 0, scaleVector[2], 0],\n [0, 0, 0, 1]\n ];\n};\n\nexport const v3Scale = (scaleVector: Vector3, vector: Vector3): Vector3 => {\n return mMulVector(m3Scale(scaleVector), vector) as Vector3;\n};\n\n/**\n * Stretch, parallel to the x-axis.\n */\nexport const m2ScaleX = (scale: number): Matrix2 => {\n return [\n [scale, 0],\n [0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the x-axis - homogeneous coordinates\n */\nexport const m2ScaleXH = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleX = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleXH = (scale: number): Matrix4 => {\n return [\n [scale, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleY = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleYH = (scale: number): Matrix => {\n return [\n [1, 0, 0, 0],\n [0, scale, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZ = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, scale],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZH = (scale: number): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, scale, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis.\n */\nexport const m2ScaleY = (scale: number): Matrix2 => {\n return [\n [1, 0],\n [0, scale],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis - homogeneous coordinates\n */\nexport const m2ScaleYH = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n// ---------------- REFLECTION MATRICES -------------------------\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOrigin = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOriginH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection about the origin in non-homogeneous coordinates\n */\nexport const m3ReflectionOrigin = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection about the origin in homogeneous coordinates\n */\nexport const m3ReflectionOriginH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection about y=-x\n */\nexport const m2ReflectionYmX = (): Matrix2 => {\n\n return [\n [0, -1],\n [-1, 0],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionX = (): Matrix2 => {\n\n return [\n [1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionXH = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection in the y-axis.\n */\nexport const m2ReflectionY = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, 1],\n ];\n};\n\nexport const m2ReflectionYH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionYZ = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in homogeneous coordinates\n */\nexport const m3ReflectionYZH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXZ = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in homogeneous coordinates\n */\nexport const m3ReflectionXZH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXY = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in homogeneous coordinates\n */\nexport const m3ReflectionXYH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- SHEARING MATRICES -------------------------\n\n\n/**\n * Shearing in y-axis, with x-axis fixed with (0,1) moving to (factor, 1)\n */\nexport const m2ShearingY = (factor: number): Matrix2 => {\n\n return [\n [1, factor],\n [0, 1],\n ];\n};\n\n/**\n * Shearing in x-axis, with y-axis fixed with (1,0) moving to (1, factor)\n */\nexport const m2ShearingX = (factor: number): Matrix2 => {\n\n return [\n [1, 0],\n [factor, 1],\n ];\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a random number in the [min,max] range.\n */\nexport const getRandom = (min: number, max: number, decimalPlaces = Infinity): number => {\n return setDecimalPlaces(Math.random() * (max - min) + min, decimalPlaces);\n};\n\n/**\n * Returns a random integer number in the [min,max] range.\n */\nexport const getRandomInt = (min: number, max: number): number => {\n return Math.floor(Math.random() * (max - min + 1) + min);\n};\n\nexport const getRandomBoolean = () => Math.random() < 0.5;\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getRandomItemFromArray = (array: any[]) => {\n const randomIndex = getRandomInt(0, array.length - 1);\n return array[randomIndex];\n};", "export const stringToNumber = (value: string|undefined|null|number, defaultNumber: number) => {\n if(value === undefined || value === null) return defaultNumber;\n const res = Number(value) ?? defaultNumber;\n return isNaN(res) ? defaultNumber : res;\n};", "import { setDecimalPlaces } from './format';\nimport { Vector2, Vector3 } from '../types';\n\n/**\n * u(x) and v(x) are functions ---------->\n *\n * dx(u + v) = dx(u) + dx(v)\n * dx(u - v) = dx(u) - dx(v)\n * dx(u * v) = dx(u) * v + u * dx(v)\n * dx(u / v) = (dx(u) * v - u * dx(v)) / (v ^ 2), when v(x) != 0\n */\n\n// ------------------ Derivatives of Polynomial ---------------------------\n\n/**\n * y = 3x+2\n * dxPolynomial(10, [[3, 1], [2, 0]])\n */\nexport const dxPolynomial = (x: number, polynomial: number[][], decimalPlaces = Infinity) => {\n let res = 0;\n\n for(const part of polynomial){\n if(part.length !== 2) return NaN;\n\n const coeff = part[0];\n const power = part[1];\n res += coeff * power * Math.pow(x, power - 1);\n }\n\n return setDecimalPlaces(res, decimalPlaces);\n}\n\n// ---------------------- Bezier Curves ---------------------------\n\n/**\n * Derivative of Bezier Curve is another Bezier Curve.\n * t must min in range [0, 1]\n */\nexport const dxV2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n // The derivative: P1 * (2t-2) + (2*P3-4*P2) * t + 2 * P2\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\nexport const dxV2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n\n// ----------------- Derivatives of trigonometry functions ---------------------------\n\nexport const dxSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(Math.cos(x), decimalPlaces);\n};\n\nexport const dxCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-Math.sin(x), decimalPlaces);\n};\n\nexport const dxTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.cos(x) ** 2), decimalPlaces);\n};\n\n/**\n * x != Math.PI * n, where n is an integer\n */\nexport const dxCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sin(x) ** 2), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\nexport const dxArcTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (1 + x ** 2), decimalPlaces);\n};\n\nexport const dxArcCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (1 + x ** 2), decimalPlaces);\n};\n", "import { Matrix, Matrix2, Matrix3, Vector, Vector2, Vector3 } from '../../types';\nimport { m2Inverse, m3Inverse, mInverse, mMulVector, mDelLastColumn, mGetLastColumn } from '../linear-algebra/matrix';\nimport { setDecimalPlaces } from '../format';\nimport { v2Sub } from '../linear-algebra/vector';\n\n/**\n * Linear equation\n * ax + b = c\n * x = (c - b) / a; a != 0\n */\nexport const linearEquation = (equation: Vector3, decimalPlaces = Infinity) : number => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n\n const diff = c - b;\n\n if(a === 0 && diff === 0) return Infinity; // any number is a solution\n if(a === 0) return NaN; // no solution\n\n return setDecimalPlaces(diff / a, decimalPlaces);\n};\n\n/**\n * System of 2 linear equations.\n * [x, y] = inverse(Matrix of equation parameters) x (vector of equation results)\n * ---------------\n * 3x + 2y = 7\n * -6x + 6y = 6\n */\nexport const linearEquationSystem2 = (equation1: Vector3, equation2: Vector3, decimalPlaces = Infinity) : Vector2 | null => {\n const equationParams: Matrix2 = [\n [equation1[0], equation1[1]],\n [equation2[0], equation2[1]],\n ];\n\n const inversed = m2Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector2 = [\n equation1[2],\n equation2[2]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector2;\n};\n\n/**\n * System of 3 linear equations.\n * ---------------------------------------\n * 3x + 2y + 5z = 7\n * -6x + 6y + 6z = 6\n * 2x + 7y - z = 4\n */\nexport const linearEquationSystem3 = (\n equation1: Vector,\n equation2: Vector,\n equation3: Vector,\n decimalPlaces = Infinity) : Vector3 | null => {\n const equationParams: Matrix3 = [\n [equation1[0], equation1[1], equation1[2]],\n [equation2[0], equation2[1], equation2[2]],\n [equation3[0], equation3[1], equation3[2]],\n ];\n\n const inversed = m3Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector3 = [\n equation1[3],\n equation2[3],\n equation3[3]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector3;\n};\n\n/**\n * System of N linear equations.\n */\nexport const linearEquationSystemN = (equations: Matrix, decimalPlaces = Infinity) : Vector | null => {\n if(equations.length <= 0) return null;\n\n const equationParams = mDelLastColumn(equations);\n\n const inversed = mInverse(equationParams);\n if(inversed === null) return null; // no results\n\n // the last column of the equations matrix\n const equationResults = mGetLastColumn(equations);\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector;\n};\n\n/**\n * Calculate the equation of a line given two points in a 2D space.\n * y = ax + b\n * y - y1 = m(x - x1)\n * m = (y2 - y1) / (x2 - x1)\n */\nexport const getLinearEquationBy2Points = (point1: Vector2, point2: Vector2) : {\n slope: number|undefined,\n yIntercept: number|undefined,\n xIntercept: number|undefined,\n formula: string,\n} => {\n const [deltaX, deltaY] = v2Sub(point2, point1);\n const [x, y] = point1;\n\n if(deltaX === 0) {\n return {\n slope: undefined,\n xIntercept: x,\n yIntercept: undefined,\n formula: `x = ${ x }`,\n };\n }\n\n const m = deltaY / deltaX;\n const b = y - m * x;\n let formula = '';\n\n if(m === 0) {\n formula = `y = ${ b }`;\n }\n else{\n formula = `y = ${ m === 1 ? '' : m }x`;\n\n if(b !== 0) {\n formula += ` ${ b < 0 ? '-' : '+' } ${ Math.abs(b) }`;\n }\n }\n\n return {\n slope: m,\n xIntercept: undefined,\n yIntercept: b,\n formula,\n };\n};", "import { Vector } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { linearEquation } from './linear-equations';\nimport { isNumber } from '../other';\n\n/**\n * Quadratic Equation.\n * ax^2 + bx + c = d\n */\nexport const quadraticEquation = (equation: Vector, decimalPlaces = Infinity) : Vector => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n const d = equation[3];\n\n if(a === 0){\n // it's a linear equation -------------------------------------------\n const res = linearEquation([b, c, d], decimalPlaces);\n if(isNumber(res)) return [res];\n return [];\n }\n\n const diff = c - d;\n\n const discriminant = b * b - (4 * a * diff);\n\n if(discriminant < 0){\n return []; // no results\n }\n\n if(discriminant === 0){\n return [ setDecimalPlaces(-b / (2 * a), decimalPlaces) ]; // 1 result\n }\n\n // if(determinant > 0) ---> 2 results\n const t1 = 2 * a;\n const t2 = Math.sqrt(discriminant);\n\n return [\n setDecimalPlaces((-b + t2) / t1, decimalPlaces),\n setDecimalPlaces((-b - t2) / t1, decimalPlaces),\n ];\n};", "import { IBBox, Vector, Vector2, Vector3 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport {\n dxV2CubicBezierCurve,\n dxV2QuadraticBezierCurve,\n dxV3CubicBezierCurve,\n dxV3QuadraticBezierCurve\n} from '../derivative';\nimport { v2Normalize, v3Normalize } from '../linear-algebra/vector';\nimport { linearEquation } from '../equations/linear-equations';\nimport { quadraticEquation } from '../equations/quadratic-equations';\nimport { isNumber } from '../other';\n\n/**\n * B\u00E9zier Curves\n * quadratic: y = P1 * (1-t)\u00B2 + P2 * 2 * (1-t)t + P3 * t\u00B2\n * t in range [0, 1]\n */\n\n// -------------------- GET POINT ON CURVE --------------------------\n\n/**\n * Get a point on a quadratic B\u00E9zier curve as a function of time.\n */\nexport const v2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n/**\n * Get a point on a cubic B\u00E9zier curve as a function of time.\n */\nexport const v2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n// -------------------- TANGENT --------------------------\n\n/**\n * Tangent indicates the direction of travel at specific points along the B\u00E9zier curve,\n * and is literally just the first derivative of our curve.\n */\nexport const v2QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\nexport const v2CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\n// -------------------- NORMAL --------------------------\n\n/**\n * Normal is a vector that runs at a right angle to the direction of the curve, and is typically of length 1.\n * To find it, we take the normalised tangent vector, and then rotate it by a 90 degrees.\n */\nexport const v2QuadraticBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2QuadraticBezierCurveTangent(t, startControlPoint, centerControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\nexport const v2CubicBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2CubicBezierCurveTangent(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\n// -------------------- EXTREMA --------------------------\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2QuadraticBezierCurveExtrema = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector => {\n\n /*\n (-2 * (1 - t)) * startControlPoint[0] + (2 - 4 * t) * centerControlPoint[0] + (2 * t) * endControlPoint[0]\n 2 * t * startControlPoint[0] - 4 * t * centerControlPoint[0] + 2 * t * endControlPoint[0] - 2 * startControlPoint[0] + 2 * centerControlPoint[0]\n t * (2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0]) + (- 2 * startControlPoint[0] + 2 * centerControlPoint[0])\n */\n\n const a1 = 2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0];\n const b1 = -2 * startControlPoint[0] + 2 * centerControlPoint[0];\n const equation1: Vector3 = [a1, b1, 0];\n const res1 = linearEquation(equation1, decimalPlaces);\n\n const a2 = 2 * startControlPoint[1] - 4 * centerControlPoint[1] + 2 * endControlPoint[1];\n const b2 = -2 * startControlPoint[1] + 2 * centerControlPoint[1];\n const equation2: Vector3 = [a2, b2, 0];\n const res2 = linearEquation(equation2, decimalPlaces);\n\n const res: Vector = [];\n\n if(isNumber(res1)){\n res.push(res1);\n }\n\n if(isNumber(res2)){\n res.push(res2);\n }\n\n return res;\n};\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2CubicBezierCurveExtrema = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2|null => {\n\n const a1 = -3 * startControlPoint[0] + 9 * center1ControlPoint[0] - 9 * center2ControlPoint[0] + 3 * endControlPoint[0];\n const b1 = 6 * startControlPoint[0] - 12 * center1ControlPoint[0] + 6 * center2ControlPoint[0];\n const c1 = -3 * startControlPoint[0] + 3 * center1ControlPoint[0];\n const equation1: Vector = [a1, b1, c1, 0];\n\n const a2 = -3 * startControlPoint[1] + 9 * center1ControlPoint[1] - 9 * center2ControlPoint[1] + 3 * endControlPoint[1];\n const b2 = 6 * startControlPoint[1] - 12 * center1ControlPoint[1] + 6 * center2ControlPoint[1];\n const c2 = -3 * startControlPoint[1] + 3 * center1ControlPoint[1];\n const equation2: Vector = [a2, b2, c2, 0];\n\n // Any value between 0 and 1 is a root that matters for B\u00E9zier curves, anything below or above that is irrelevant (because B\u00E9zier curves are only defined over the interval [0,1]).\n const res1 = quadraticEquation(equation1, decimalPlaces).filter(num => num >= 0 && num <= 1);\n const res2 = quadraticEquation(equation2, decimalPlaces).filter(num => num >= 0 && num <= 1);\n\n const res = [...res1, ...res2];\n if(res.length === 2){\n return [...res1, ...res2] as Vector2;\n }\n\n return null;\n};\n\n// -------------------- BOUNDING BOX --------------------------\n\nexport const v2QuadraticBezierBBox = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2QuadraticBezierCurveExtrema(startControlPoint, centerControlPoint, endControlPoint);\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2QuadraticBezierCurve(percent, startControlPoint, centerControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\nexport const v2CubicBezierBBox = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2CubicBezierCurveExtrema(startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint) || [];\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2CubicBezierCurve(percent, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x ?? Infinity);\n maxX = Math.max(maxX, x ?? -Infinity);\n\n minY = Math.min(minY, y ?? Infinity);\n maxY = Math.max(maxY, y ?? -Infinity);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\n\n", "import { Vector2 } from '../types';\nimport { v2Sub } from './linear-algebra/vector';\nimport { getV2Angle } from './angle';\nimport { convertRange } from './other';\n\n/**\n * Circle Equation\n * x^2 + y^2 = radius^2\n * ----------------------\n * Circle Parametric Equation\n * x(t) = radius * cos(t)\n * y(t) = radius * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const circleMovement = (center: Vector2, angle: number, radius: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius,\n center[1] + Math.sin(angle) * radius\n ];\n};\n\n/**\n * Circle Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const circleMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radius: number\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return circleMovement(center, angle, radius);\n};\n\n/**\n * Ellipse Equation\n * (x - centerX)^2 / (radius1^2) + (y - centerY)^2 / (radius2^2) = 1\n * -----------------------------------------------------------------\n * Ellipse Parametric Equation\n * x(t) = radius1 * cos(t)\n * y(t) = radius2 * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const ellipseMovement = (center: Vector2, angle: number, radius1: number, radius2: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius1,\n center[1] + Math.sin(angle) * radius2\n ];\n};\n\n/**\n * Ellipse Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const ellipseMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radii: Vector2\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return ellipseMovement(center, angle, radii[0], radii[1]);\n};\n\n/**\n * Sine Wave Equation (Sinusoid)\n * -----------------------------\n * const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n * amplitude = the peak deviation of the function from zero\n * frequency = number of cycles\n * phase = specifies (in radians) where in its cycle the oscillation is at t = 0.\n * think of it as \"shifting\" the starting point of the function to the right (positive p) or left (negative)\n */\nexport const sineWaveMovement = (x: number, amplitude: number, frequency: number, phase: number) : Vector2 => {\n /*\n example values:\n const amplitude = 50;\n const frequency = 0.005;\n const phase = 0;\n x: [0, 1000]\n */\n const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n\n return [x, y];\n};\n\n/**\n * Lissajous curve (Lissajous figure or Bowditch curve)\n * Parametric equation #1\n * f(t) = A * sin(k * t + m)\n * f(t) = B * sin(n * t)\n * 0 <= m <= PI/2\n * k, n >= 1\n * -----------------------\n * Parametric equation #2\n * f(t) = A * cos(k * t - m)\n * f(t) = B * cos(n * t - p)\n * -----------------------------\n * Shapes:\n * k = 1, n = 1, m = 0, p = 0 ---> line\n * A = B, k = 1, n = 1, m = PI/2, p = PI/2 ----> circle\n * A != B, k = 1, n = 1, m = PI/2, p = PI/2 ----> ellipse\n * k = 2, n = 2, m = PI/2, p = PI/2 ----> section of a parabola\n */\nexport const lissajousCurve = (\n width: number,\n height: number,\n t: number,\n k: number,\n n: number,\n m: number,\n p: number\n) :Vector2 => {\n return [\n width * Math.cos(k * t - m),\n height * Math.cos(n * t - p),\n ];\n};\n", "import { getRandom } from './random';\nimport { HSLColor, LABColor, RGBColor } from '../types';\nimport { mod } from './other';\nimport { setDecimalPlaces } from './format';\n\n// ------------------------ RANDOM COLOR -------------------------------------\n\nexport const getRandomRGBColor = () : RGBColor => {\n const hslColor = getRandomHSLColor();\n return hslToRgb(hslColor);\n};\n\nexport const getRandomHexColor = () : string => {\n const hslColor = getRandomHSLColor();\n return hslToHex(hslColor);\n};\n\nexport const getRandomHSLColor = () : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given hue\n */\nexport const getRandomHSLColorWithHue = (h: number) : HSLColor => {\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given saturation\n */\nexport const getRandomHSLColorWithSaturation = (s: number) : HSLColor => {\n const h = getRandom(1, 360);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given lightness\n */\nexport const getRandomHSLColorWithLightness = (l: number) : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n return [h, s, l];\n};\n\nexport const getRandomGrayscaleHSLColor = () : HSLColor => {\n const l = getRandom(0, 100);\n return [0, 0, l];\n};\n\nexport const getRandomHSLColorWithinRanges = (\n hueStart = 1, hueEnd = 360,\n saturationStart = 0, saturationEnd = 100,\n lightStart = 0, lightEnd = 100\n) : HSLColor => {\n const h = getRandom(hueStart, hueEnd);\n const s = getRandom(saturationStart, saturationEnd);\n const l = getRandom(lightStart, lightEnd);\n return [h, s, l];\n};\n\n// ----------------------- CONVERT COLORS --------------------------------------\n\n/**\n * helper: convert hue value to degrees.\n * @param {number} h\n * @return {number} [0, 360] degrees\n */\nconst convertHueToDegrees = (h : number) : number => {\n\n // the hue value needs to be multiplied by 60 to convert it to degrees\n h *= 60;\n\n // if hue becomes negative, you need to add 360 to, because a circle has 360 degrees\n if(h < 0){\n h += 360;\n }\n\n return h;\n // convert huw to %\n // return h * 100 / 360;\n};\n\n/**\n * get hue from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] % - we use here % instead of [0, 359] degrees\n */\nconst getHue = (r : number, g : number, b : number, min : number | undefined = undefined, max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (max === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no hue, as it's gray\n if(min === max) return 0;\n\n const diff = max - min;\n\n let h = 0;\n\n // if red is max\n if(max === r){\n h = (g - b) / diff + (g < b ? 6 : 0);\n }\n\n // if green is max\n if(max === g){\n h = 2 + (b - r) / diff;\n }\n\n // if blue is max\n if(max === b){\n h = 4 + (r - g) / diff;\n }\n\n return convertHueToDegrees(h);\n};\n\n/**\n * get luminance from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] %\n */\nconst getLuminance = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // calculate the luminance value\n // @ts-ignore\n const l = (min + max) / 2; // [0, 1]\n\n // return l value in %\n return l * 100;\n};\n\n/**\n * get saturation from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @param {number|undefined=} l - luminance in [0, 100] %\n * @return {number} [0, 100] %\n */\nconst getSaturation = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined,\n l : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no saturation, as it's gray\n if(min === max) return 0;\n\n // calculate luminance if it's not provided\n l = (l === undefined) ? getLuminance(r, g, b) : l;\n\n // check the level of luminance\n const s = (l <= 50) ?\n // @ts-ignore\n ((max - min) / (max + min)) : // this formula is used when luminance <= 50%\n // @ts-ignore\n (max - min) / (2.0 - max - min); // this formula is used when luminance > 50%\n\n // return saturation in %\n return s * 100;\n};\n\nexport const rgbToHsl = (rgb: RGBColor, decimalPlaces = Infinity): HSLColor => {\n\n // convert rgb values to the range [0, 1]\n const r = rgb[0] / 255;\n const g = rgb[1] / 255;\n const b = rgb[2] / 255;\n\n // find the minimum and maximum values of r, g, and b\n const min = Math.min(r, g, b);\n const max = Math.max(r, g, b);\n\n // calculate the luminance value in %\n const l = getLuminance(r, g, b, min, max);\n\n // calculate the saturation in %\n const s = getSaturation(r, g, b, min, max, l);\n\n // calculate the hue in % (not in degrees!)\n const h = getHue(r, g, b, min, max);\n\n if(h > 360 || s > 100 || l > 100){\n return [0, 0, 100];\n }\n\n if(h < 0 || s < 0 || l < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(h, decimalPlaces),\n setDecimalPlaces(s, decimalPlaces),\n setDecimalPlaces(l, decimalPlaces),\n ];\n};\n\n/**\n * helper: HSL to RGB\n */\nconst hslToRgbHelper = (helper1 : number, helper2 : number, colorHelper : number) : number => {\n\n // all values need to be between 0 and 1\n // if you get a negative value you need to add 1 to it\n if(colorHelper < 0) colorHelper += 1;\n\n // if you get a value above 1 you need to subtract 1 from it.\n if(colorHelper > 1) colorHelper -= 1;\n\n if(colorHelper * 6 < 1) return helper2 + (helper1 - helper2) * 6 * colorHelper;\n\n if(colorHelper * 2 < 1) return helper1;\n\n if(colorHelper * 3 < 2){\n return helper2 + (helper1 - helper2) * (0.666 - colorHelper) * 6;\n }\n else{\n return helper2;\n }\n};\n\nexport const hslToRgb = (hsl: HSLColor, decimalPlaces = Infinity): RGBColor => {\n\n // convert all values to [0, 1] from %\n const h = hsl[0] / 100;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n // if there is no saturation -> it\u2019s grey\n if(s === 0){\n // convert the luminance from [0, 1] to [0, 255]\n const gray = l * 255;\n return [gray, gray, gray];\n }\n\n // check the level of luminance\n const helper1 = (l < 0.5) ?\n (l * (1.0 + s)) :\n (l + s - l * s);\n\n const helper2 = 2 * l - helper1;\n\n const rHelper = h + 0.333;\n const gHelper = h;\n const bHelper = h - 0.333;\n\n let r = hslToRgbHelper(helper1, helper2, rHelper);\n let g = hslToRgbHelper(helper1, helper2, gHelper);\n let b = hslToRgbHelper(helper1, helper2, bHelper);\n\n // convert rgb to [0, 255]\n r *= 255;\n g *= 255;\n b *= 255;\n\n if(r > 255 || g > 255 || b > 255){\n return [255, 255, 255];\n }\n\n if(r < 0 || g < 0 || b < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(r, decimalPlaces),\n setDecimalPlaces(g, decimalPlaces),\n setDecimalPlaces(b, decimalPlaces),\n ];\n};\n\n/**\n * HSL to hex\n * hslToHex(360, 100, 50) // [360, 100, 5] ==> \"#ff0000\" (red)\n */\nexport const hslToHex = (hsl: HSLColor) => {\n\n if(hsl[0] > 360 || hsl[1] > 100 || hsl[2] > 100){\n return '#ffffff';\n }\n\n if(hsl[0] < 0 || hsl[1] < 0 || hsl[2] < 0){\n return '#000000';\n }\n\n const h = hsl[0] / 360;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n let r, g, b;\n if (s === 0) {\n r = g = b = l; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n r = hue2rgb(p, q, h + 1 / 3);\n g = hue2rgb(p, q, h);\n b = hue2rgb(p, q, h - 1 / 3);\n }\n const toHex = (x: number) => {\n const hex = Math.round(x * 255).toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n};\n\n/**\n * RGB to HEX\n * rgbToHex([235, 64, 52]) // #eb4034\n */\nexport const rgbToHex = (rgb: RGBColor) => {\n const [r, g, b] = rgb;\n return '#' + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);\n};\n\nexport const hexToRgb = (hex: string) : RGBColor | null => {\n\n const shorthandRegex = /^#?([a-f\\d])([a-f\\d])([a-f\\d])$/i;\n const _hex = hex.replace(shorthandRegex, (_m, r, g, b) => {\n return r + r + g + g + b + b;\n });\n\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(_hex);\n if(!result) return null;\n\n const r = parseInt(result[1], 16);\n const g = parseInt(result[2], 16);\n const b = parseInt(result[3], 16);\n\n return [r, g, b];\n};\n\nexport const rgbToLab = (rgb: RGBColor, decimalPlaces = Infinity) : LABColor => {\n\n let r = rgb[0] / 255;\n let g = rgb[1] / 255;\n let b = rgb[2] / 255;\n\n r = (r > 0.04045) ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;\n g = (g > 0.04045) ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;\n b = (b > 0.04045) ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;\n\n let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;\n let y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;\n let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;\n\n x = (x > 0.008856) ? Math.pow(x, 1/3) : (7.787 * x) + 16/116;\n y = (y > 0.008856) ? Math.pow(y, 1/3) : (7.787 * y) + 16/116;\n z = (z > 0.008856) ? Math.pow(z, 1/3) : (7.787 * z) + 16/116;\n\n return [\n setDecimalPlaces((116 * y) - 16, decimalPlaces),\n setDecimalPlaces(500 * (x - y), decimalPlaces),\n setDecimalPlaces(200 * (y - z), decimalPlaces),\n ];\n};\n\nexport const labToRgb = (lab: LABColor, decimalPlaces = Infinity) : RGBColor => {\n let y = (lab[0] + 16) / 116;\n let x = lab[1] / 500 + y;\n let z = y - lab[2] / 200;\n\n x = 0.95047 * ((x * x * x > 0.008856) ? x * x * x : (x - 16/116) / 7.787);\n y = 1.00000 * ((y * y * y > 0.008856) ? y * y * y : (y - 16/116) / 7.787);\n z = 1.08883 * ((z * z * z > 0.008856) ? z * z * z : (z - 16/116) / 7.787);\n\n let r = x * 3.2406 + y * -1.5372 + z * -0.4986;\n let g = x * -0.9689 + y * 1.8758 + z * 0.0415;\n let b = x * 0.0557 + y * -0.2040 + z * 1.0570;\n\n r = (r > 0.0031308) ? (1.055 * Math.pow(r, 1/2.4) - 0.055) : 12.92 * r;\n g = (g > 0.0031308) ? (1.055 * Math.pow(g, 1/2.4) - 0.055) : 12.92 * g;\n b = (b > 0.0031308) ? (1.055 * Math.pow(b, 1/2.4) - 0.055) : 12.92 * b;\n\n return [\n setDecimalPlaces(Math.max(0, Math.min(1, r)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, g)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, b)) * 255, decimalPlaces),\n ];\n};\n\n// ----------------------- GET SHIFTED COLORS --------------------------------------\n\nexport const getShiftedHue = (color: HSLColor, shift = 180) : HSLColor => {\n let hue = color[0];\n hue += shift;\n\n if (hue > 360 || hue < 0) {\n hue = mod(hue, 360);\n }\n\n return [hue, color[1], color[2]];\n};\n\nexport const getShiftedLightness = (color: HSLColor, shift = 10) : HSLColor => {\n let lightness = color[2];\n lightness += shift;\n\n if (lightness > 100 || lightness < 0) {\n lightness = mod(lightness, 100);\n }\n\n return [color[0], color[1], lightness];\n};\n\nexport const getShiftedSaturation = (color: HSLColor, shift = 10) : HSLColor => {\n let saturation = color[1];\n saturation += shift;\n\n if (saturation > 100) {\n saturation -= 100;\n }\n\n if(saturation < 0){\n saturation += 100;\n }\n\n return [color[0], saturation, color[2]];\n};\n\n// ----------------------- SIMILAR COLORS --------------------------------------\n\n/**\n * Measure the perceptual difference between two RGB colors using the CIE76 color difference formula:\n * delta = Math.sqrt((L2 - L1)^2 + (a2 - a1)^2 + (b2 - b1)^2)\n * https://en.wikipedia.org/wiki/Color_difference\n * https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js\n * <= 1.0 Not perceptible by human eyes.\n * 1 - 2 Perceptible through close observation.\n * 2 - 10 Perceptible at a glance.\n * 11 - 49 Colors are more similar than opposite\n * 100 Colors are exact opposite\n */\nexport const getColorsDelta = (rgbA: RGBColor, rgbB: RGBColor, decimalPlaces = Infinity) => {\n const labA = rgbToLab(rgbA, decimalPlaces);\n const labB = rgbToLab(rgbB, decimalPlaces);\n\n // differences between the LAB components of the two colors\n const deltaL = labA[0] - labB[0];\n const deltaA = labA[1] - labB[1];\n const deltaB = labA[2] - labB[2];\n\n // chroma components\n const c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);\n const c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);\n const deltaC = c1 - c2;\n\n // difference in hue, deltaH, which takes into account both the differences\n // in the a* and b* components of LAB and the differences in chroma.\n let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;\n deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);\n\n const sc = 1.0 + 0.045 * c1;\n const sh = 1.0 + 0.015 * c1;\n\n // It applies weighting factors to the differences in lightness (deltaL),\n // chroma (deltaC), and hue (deltaH).\n const deltaLKlsl = deltaL / (1.0);\n const deltaCkcsc = deltaC / (sc);\n const deltaHkhsh = deltaH / (sh);\n\n // It computes the final color difference using the CIE76 formula:\n // deltaE = sqrt(deltaLKlsl^2 + deltaCkcsc^2 + deltaHkhsh^2),\n // where deltaLKlsl is the weighted lightness difference,\n // deltaCkcsc is the weighted chroma difference,\n // and deltaHkhsh is the weighted hue difference.\n const i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;\n\n // It returns the calculated color difference,\n // optionally rounded to the specified number of decimal places.\n return i < 0 ? 0 : Math.sqrt(i);\n};\n", "/**\n * guid like '932ade5e-c515-4807-ac01-73b20ab3fb66'\n */\nexport const guid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0;\n return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);\n });\n};\n\n/**\n * id like 'df4unio1opulby2uqh4'\n */\nexport const newId = () => {\n return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);\n};\n", "import { ICircle, IPolygon, IRect, Matrix2, Vector2 } from '../types';\nimport { mod } from './other';\nimport { v2GetNormal, v2DotProduct } from './linear-algebra/vector';\n\n/**\n * Rectangles collision detection.\n * Rectangles should not be rotated.\n * The algorithm works by ensuring there is no gap between any of the 4 sides of the rectangles.\n * Any gap means a collision does not exist.\n * Returns true if collision is detected.\n */\nexport const rectCollide = (rect1: IRect, rect2: IRect) : boolean => {\n return rect1.x <= rect2.x + rect2.w &&\n rect1.x + rect1.w >= rect2.x &&\n rect1.y <= rect2.y + rect2.h &&\n rect1.h + rect1.y >= rect2.y;\n};\n\n/**\n * Circles collision detection.\n * This algorithm works by taking the center points of the two circles\n * and ensuring the distance between the center points\n * are less than the two radii added together.\n * Returns true if collision is detected.\n */\nexport const circleCollide = (circle1: ICircle, circle2: ICircle) => {\n const dx = Math.abs(circle1.cx - circle2.cx);\n const dy = Math.abs(circle1.cy - circle2.cy);\n const distance = Math.sqrt(dx * dx + dy * dy);\n return distance <= circle1.r + circle2.r;\n};\n\n//-------------------- Separating Axis Theorem (SAT) Collision detection -------------------------\n\nconst getEdges = (poly: IPolygon) : Matrix2[] => {\n const edges: Matrix2[] = [];\n\n for(let i= 0; i {\n const edges: Matrix2[] = [];\n\n // collect polygon edges, and combine then into a single array\n edges.push(...getEdges(poly1));\n edges.push(...getEdges(poly2));\n\n // for each edge, find the normal vector and project both polygons onto it\n for (const edge of edges) {\n const normal = v2GetNormal(edge[0], edge[1]);\n const p1Proj = projectPolygon(poly1, normal);\n const p2Proj = projectPolygon(poly2, normal);\n\n // Check if the projections overlap\n const isOverlap = p1Proj.max >= p2Proj.min && p2Proj.max >= p1Proj.min;\n\n // Check if the projections overlap; if not, the polygons do not collide\n if (!isOverlap) return false;\n }\n\n // If all tests pass, the polygons overlap and collide\n return true;\n};\n\n/**\n * Project every polygon point onto the normal.\n * Then find min and max.\n */\nconst projectPolygon = (polygon: IPolygon, normal: Vector2): { min: number, max: number } => {\n let min = Infinity;\n let max = -Infinity;\n\n // Project each vertex of the polygon onto the axis\n for (const vertex of polygon) {\n const projection = v2DotProduct(vertex, normal);\n min = Math.min(min, projection);\n max = Math.max(max, projection);\n }\n\n return { min, max };\n};", "export interface IAnimationProps {\n duration?: number;\n callback: (result: IAnimationResult) => void;\n restartOnResize?: boolean;\n resizeCallback?: (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => void;\n}\n\nexport interface IAnimationResult {\n start: () => void;\n stop: () => void;\n pause: () => void;\n resume: () => void;\n restart: () => void;\n isAnimating: () => boolean;\n getStartTime: () => number|undefined;\n getElapsedTime: () => number|undefined;\n getPercent: () => number|undefined;\n getResizeObserver: () => ResizeObserver|undefined;\n}\n\nexport const animate = (props: IAnimationProps) : IAnimationResult => {\n\n const _duration = props.duration !== undefined ? props.duration : Infinity;\n\n let startTime: number|undefined = undefined; // in milliseconds\n let animationId: number|undefined = undefined;\n\n // the time elapsed since the start of the animation (in milliseconds)\n let elapsed: number|undefined = undefined;\n let previousTimeStamp: number|undefined = undefined;\n\n let animating = false;\n let observer: ResizeObserver|undefined = undefined;\n\n // -------------------- COMMANDS ---------------------\n\n const stop = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = false;\n\n /*if(observer !== undefined){\n observer.disconnect();\n observer = undefined;\n }*/\n\n if(animationId === undefined) return;\n window.cancelAnimationFrame(animationId);\n };\n\n const restart = () => {\n stop();\n start();\n };\n\n const pause = () => {\n animating = false;\n };\n\n const resume = () => {\n animating = true;\n };\n\n /**\n * Animation Step.\n * @param {number} timeStamp in milliseconds\n */\n const step = (timeStamp: DOMHighResTimeStamp) => {\n\n if (startTime === undefined) {\n startTime = timeStamp;\n }\n\n // the time elapsed since the start of the animation (in milliseconds)\n elapsed = timeStamp - startTime;\n\n if (animating && previousTimeStamp !== timeStamp && typeof props.callback === 'function') {\n\n // do the rendering .............\n props.callback(getResult());\n }\n\n if(elapsed <= _duration){\n previousTimeStamp = timeStamp;\n animationId = window.requestAnimationFrame(step);\n }\n else{\n stop();\n }\n };\n\n const observerHandler = (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => {\n restart();\n\n if(typeof props.resizeCallback === 'function'){\n props.resizeCallback(_entries, _observer);\n }\n };\n\n const start = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = true;\n\n if(props.restartOnResize && window.ResizeObserver && observer === undefined){\n observer = new ResizeObserver(observerHandler);\n observer.observe(document.body, { box: 'border-box' });\n }\n else{\n animationId = window.requestAnimationFrame(step);\n }\n };\n\n // --------------- GET INFO ----------------------\n\n /**\n * the time elapsed since the start of the animation (in milliseconds)\n */\n const getElapsedTime = () : number|undefined => {\n return elapsed;\n };\n\n const isAnimating = () => {\n return animating;\n };\n\n const getStartTime = () => {\n return startTime;\n };\n\n const getPercent = () => {\n if(_duration === Infinity || elapsed === undefined) return undefined;\n return elapsed * 100 / _duration;\n };\n\n const getResizeObserver = () => {\n return observer;\n };\n\n const getResult = () : IAnimationResult => {\n return {\n\n // commands --------------\n start,\n stop,\n pause,\n resume,\n restart,\n\n // information -------\n isAnimating,\n getElapsedTime,\n getStartTime,\n getPercent,\n getResizeObserver,\n };\n };\n\n return getResult();\n};\n", "import { setDecimalPlaces } from './format';\n\nexport const getCircleCircumference = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * radius, decimalPlaces);\n};\n\nexport const getEllipseCircumference = (radius1: number, radius2: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * Math.sqrt((radius1 ** 2 + radius2 ** 2) / 2), decimalPlaces);\n};\n\nexport const isAngleInCircleArc = (startAngleDeg: number, endAngleDeg: number, currentDegrees: number) : boolean => {\n\n if(startAngleDeg > endAngleDeg) {\n endAngleDeg += 360;\n }\n\n return currentDegrees >= startAngleDeg && currentDegrees <= endAngleDeg ||\n (currentDegrees + 360) >= startAngleDeg && (currentDegrees + 360) <= endAngleDeg;\n};\n\n/**\n * get the side of a square inscribed in a circle\n */\nexport const getSquareInCircleSide = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(radius * 2 / Math.sqrt(2), decimalPlaces);\n};\n", "/**\n * 1 + 2 + ... + n = n * (n + 1) / 2\n */\nexport const naturalNumbersSequenceSum = (n: number) => {\n return n * (n + 1) / 2;\n};\n\n/**\n * n = the number of terms to be added\n * a = the first term in the sequence\n * d = the constant value between terms\n */\nexport const arithmeticSequenceSum = (n: number, a: number, d: number) => {\n return (n / 2) * (2 * a + (n - 1) * d);\n};", "import { setDecimalPlaces } from './format';\n\n// -------------------- CENTRAL TENDENCY ----------------------------\n\n/**\n * Central tendency: Calculate the Average (mean)\n * Sum of all numbers divided by the array length.\n */\nexport const getArithmeticMean = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const sum = data.reduce((acc, val) => acc + val, 0);\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};\n\n/**\n * Central tendency: What is the central number in the sorted array?\n * Good for lists like [3, 3, 3, 3, 3, 3, 100] - 100 here is called \"Outlier\"\n */\nexport const getMedian = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const copy = [...data].sort((num1, num2) => num1 - num2);\n const mid = Math.floor(copy.length / 2);\n\n if(copy.length % 2 === 0) {\n return setDecimalPlaces((copy[mid] + copy[mid - 1]) / 2, decimalPlaces);\n }\n else {\n return setDecimalPlaces(copy[mid], decimalPlaces);\n }\n};\n\n/**\n * Central tendency: What number is most common in the set.\n * If all numbers have the same frequency, there is no mode.\n */\nexport const getMode = (data: number[]) : number[]|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n // Count frequency of each number in the data array.\n const frequencyMap: Map = new Map();\n for (const num of data) {\n frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);\n }\n\n let maxFrequency = 0;\n let modes: number[] = [];\n\n // Find the maximum frequency\n for (const [num, frequency] of frequencyMap) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency;\n modes = [num];\n }\n else if (frequency === maxFrequency) {\n modes.push(num);\n }\n }\n\n // If all numbers have the same frequency, there is no mode\n if (modes.length === data.length) {\n return undefined;\n }\n\n // Return the mode(s)\n return modes.length === 1 ? [modes[0]] : modes;\n};\n\n/*\nTODO:\n- geometric mean\n- harmonic mean\n */\n\n// -------------------- DISPERSION ----------------------------\n\n/**\n * Dispersion: the average square distance from the mean.\n */\nexport const getVariance = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const mean = getArithmeticMean(data);\n if(mean === undefined) return undefined;\n\n const sum = data.reduce((acc, val) => acc + ((val - mean) ** 2), 0);\n\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a copy of array, where each value will be in the range [0, 1].\n * const newValue = (value - array_min) / (array_max - array_min)\n */\nexport const mlNormalize = (data: number[], decimalPlaces = Infinity): number[] => {\n const copy = [...data];\n\n const min = Math.min(...copy);\n const max = Math.max(...copy);\n\n const diff = max - min;\n if(diff === 0) return [0];\n\n for(let i=0; i{var Zt=Object.defineProperty;var Ft=Object.getOwnPropertySymbols;var Rr=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable;var l=Math.pow,Qt=(t,r,e)=>r in t?Zt(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,h=(t,r)=>{for(var e in r||(r={}))Rr.call(r,e)&&Qt(t,e,r[e]);if(Ft)for(var e of Ft(r))zr.call(r,e)&&Qt(t,e,r[e]);return t};var b=(t,r)=>{for(var e in r)Zt(t,e,{get:r[e],enumerable:!0})};var it={};b(it,{v2:()=>_r,v2Distance:()=>Fr,v2DivideScalar:()=>Or,v2DotProduct:()=>rt,v2FromPolarCoords:()=>Ur,v2GetNormal:()=>ot,v2Length:()=>tt,v2MulScalar:()=>Gr,v2Normalize:()=>E,v2SetLength:()=>Kt,v2Sub:()=>z,v2Sum:()=>Nr,v3:()=>Kr,v3CrossProduct:()=>Wr,v3Distance:()=>Qr,v3DivideScalar:()=>jr,v3DotProduct:()=>Zr,v3Length:()=>Dr,v3MulScalar:()=>Q,v3Normalize:()=>S,v3Sub:()=>Yr,v3Sum:()=>Xr,v4:()=>Jr,vDistance:()=>kr,vDivideScalar:()=>Y,vDotProduct:()=>R,vEqual:()=>nt,vLength:()=>H,vMulScalar:()=>X,vN:()=>et,vNormalize:()=>L,vSub:()=>g,vSum:()=>N});var _={};b(_,{setDecimalPlaces:()=>s});var s=(t,r=1/0)=>{if(r===1/0)return t;r<0&&(r=0);let e=l(10,r);return Math.round(t*e)/e};var P={};b(P,{degreesToRadians:()=>$r,getAnglesDistance:()=>_t,getAnglesSub:()=>F,getV2Angle:()=>$,getV2AngleBetween:()=>Er,getV2AngleInEllipse:()=>Tr,getV3AngleBetween:()=>qr,getVNAngleBetween:()=>Wt,isAngleBetween:()=>Ar,isClockwise:()=>U,percentToAngle:()=>Cr,radiansToDegrees:()=>Lr,setV2Angle:()=>J});var K={};b(K,{convertRange:()=>k,doRangesOverlap:()=>Hr,isNumber:()=>T,mod:()=>d,polarToCartesian:()=>Br});var d=(t,r)=>(t%r+r)%r,k=(t,r,e,n,o)=>(o-n)*(t-r)/(e-r)+n,Hr=(t,r,e,n)=>Math.max(t,e)<=Math.min(r,n),T=t=>!isNaN(parseFloat(t))&&isFinite(t),Br=(t,r,e,n=1/0)=>{let[o,i]=t,[c,u]=r;return[s(o+c*Math.cos(e),n),s(i+u*Math.sin(e),n)]};var $=(t,r=1/0)=>{let e=Math.atan2(t[1],t[0]);return s(e,r)},Tr=(t,r,e=1/0)=>{let n=Math.atan2(t[1]/r[1],t[0]/r[0]);return s(n,e)},J=(t,r,e=1/0)=>{let n=tt(t);return[s(Math.cos(r)*n,e),s(Math.sin(r)*n,e)]},Lr=(t,r=1/0)=>{let e=t*(180/Math.PI);return s(e,r)},$r=(t,r=1/0)=>{let e=t*(Math.PI/180);return s(e,r)},Wt=(t,r,e=1/0)=>{let n=L(t),o=L(r),i=R(n,o),c=Math.acos(i);return s(c,e)},Er=(t,r,e=1/0)=>{let n=g(t,r),o=Math.atan2(n[1],n[0]);return s(o,e)},qr=(t,r,e=1/0)=>Wt(t,r,e),Ar=(t,r,e)=>{let n=F(r,e),o=F(r,t),i=F(e,t),c=o+i;return Math.abs(c-n)<=.001},U=(t,r,e=0)=>(t=t%360,r=r%360,t=t),F=(t,r,e=1/0)=>{let n=Math.abs(d(t,360)-d(r,360));return s(n<=180?n:360-n,e)},_t=(t,r,e=0,n=1/0)=>(t=t%360,r=r%360,t{t<0&&(t=0),t>100&&(t=100);let o=_t(r,e,n);return U(r,e,n)?d(n+t*o/100,360):d(n-t*o/100,360)};var N=(t,r,e=1/0)=>{let n=[];for(let o=0;oN(t,r,e),Xr=(t,r,e=1/0)=>N(t,r,e),g=(t,r,e=1/0)=>{let n=[];for(let o=0;og(t,r,e),Yr=(t,r,e=1/0)=>g(t,r,e),X=(t,r,e=1/0)=>{let n=[];for(let o=0;oX(t,r,e),Q=(t,r,e=1/0)=>X(t,r,e),Y=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o=0;oY(t,r,e),jr=(t,r,e=1/0)=>Y(t,r,e),H=(t,r=1/0)=>{let e=0;for(let n=0;nH(t,r),Dr=(t,r=1/0)=>H(t,r),Kt=(t,r,e=1/0)=>{let n=$(t);return[s(Math.cos(n)*r,e),s(Math.sin(n)*r,e)]},kr=(t,r,e=1/0)=>{let n=g(t,r);return H(n,e)},Fr=(t,r,e=1/0)=>{let n=g(t,r);return H(n,e)},Qr=(t,r,e=1/0)=>{let n=g(t,r);return H(n,e)},L=(t,r=1/0)=>{let e=H(t),n=[];for(let o=0;oL(t,r),S=(t,r=1/0)=>L(t,r),R=(t,r,e=1/0)=>{let n=0;for(let o=0;oR(t,r,e),Zr=(t,r,e=1/0)=>R(t,r,e),Wr=(t,r,e=1/0)=>[s(t[1]*r[2]-t[2]*r[1],e),s(t[2]*r[0]-t[0]*r[2],e),s(t[0]*r[1]-t[1]*r[0],e)],_r=(t=0)=>[t,t],Kr=(t=0)=>[t,t,t],Jr=(t=0)=>[t,t,t,t],et=(t,r=0)=>{if(t<0)throw new Error("N must be a non-negative number.");let e=[];for(let n=0;n{let e=[0,0];return e=Kt(e,t),J(e,r)},nt=(t,r)=>{if(t.length!==r.length)return!1;for(let e=0;e{let n=z(r,t);return[-s(n[1],e),s(n[0],e)]};var dt={};b(dt,{identity2:()=>Me,identity3:()=>he,identity4:()=>be,identityN:()=>Ve,isSingularMatrix:()=>Ae,m2Adjugate:()=>bt,m2AppendRow:()=>Ie,m2DeepCopy:()=>mt,m2Determinant:()=>ht,m2DivideScalar:()=>Jt,m2Inverse:()=>yt,m2MulScalar:()=>ne,m2PrependRow:()=>Se,m2Reset:()=>ue,m2Sub:()=>re,m2Sum:()=>Pr,m2Transpose:()=>ce,m2x2:()=>me,m3Adjugate:()=>qe,m3AppendRow:()=>ve,m3DeepCopy:()=>at,m3Determinant:()=>Ee,m3DivideScalar:()=>ie,m3Inverse:()=>lt,m3MulScalar:()=>oe,m3PrependRow:()=>we,m3Reset:()=>xe,m3Sub:()=>ee,m3Sum:()=>te,m3Transpose:()=>se,m3x3:()=>ae,m4x4:()=>fe,mAdjugate:()=>Vt,mAppendCol:()=>ye,mAppendRow:()=>de,mDeepCopy:()=>I,mDelFirstColumn:()=>He,mDelFirstRow:()=>ze,mDelLastColumn:()=>ft,mDelLastRow:()=>Re,mDeterminant:()=>O,mDivideScalar:()=>Z,mEqual:()=>Le,mGetColumn:()=>Te,mGetFirstColumn:()=>Be,mGetLastColumn:()=>pt,mInverse:()=>W,mMinor:()=>Mt,mMul:()=>q,mMulScalar:()=>ut,mMulVector:()=>V,mNxM:()=>pe,mPrependCol:()=>le,mPrependRow:()=>ge,mReset:()=>xt,mSub:()=>st,mSum:()=>ct,mTranspose:()=>G});var ct=(t,r,e=1/0)=>{let n=[];for(let o=0;oct(t,r,e),te=(t,r,e=1/0)=>ct(t,r,e),st=(t,r,e=1/0)=>{let n=[];for(let o=0;ost(t,r,e),ee=(t,r,e=1/0)=>st(t,r,e),ut=(t,r,e=1/0)=>{let n=[];for(let o of t)n.push(X(o,r,e));return n},ne=(t,r,e=1/0)=>ut(t,r,e),oe=(t,r,e=1/0)=>ut(t,r,e),Z=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o of t)n.push(Y(o,r,e));return n},Jt=(t,r,e=1/0)=>Z(t,r,e),ie=(t,r,e=1/0)=>Z(t,r,e),G=t=>{let r=t.length;if(r<=0)return t;let e=t[0].length;if(e<=0)return t;let n=[];for(let o=0;oG(t),se=t=>G(t),xt=(t,r=0)=>{if(t.length<=0)return[];let e=[];for(let n=0;nxt(t,r),xe=(t,r=0)=>xt(t,r),me=(t=0)=>[[t,t],[t,t]],ae=(t=0)=>[[t,t,t],[t,t,t],[t,t,t]],fe=(t=0)=>[[t,t,t,t],[t,t,t,t],[t,t,t,t],[t,t,t,t]],pe=(t,r,e=0)=>{if(t<=0||r<=0)throw new Error("M and N must be positive numbers.");let n=[];for(let o=0;o[[1,0],[0,1]],he=()=>[[1,0,0],[0,1,0],[0,0,1]],be=()=>[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Ve=t=>{if(t<0)throw new Error("N must be a non-negative number.");if(t===0)return[];let r=[];for(let e=0;e{let r=[];for(let e=0;eI(t),at=t=>I(t),ye=(t,r)=>{if(t.length<=0)return[];let e=I(t);for(let n=0;n{if(t.length<=0)return[];let e=I(t);for(let n=0;n{let e=I(t);return e.push(r),e},Ie=(t,r)=>{let e=mt(t);return e.push(r),e},ve=(t,r)=>{let e=at(t);return e.push(r),e},ge=(t,r)=>{let e=I(t);return e.unshift(r),e},Se=(t,r)=>{let e=mt(t);return e.unshift(r),e},we=(t,r)=>{let e=at(t);return e.unshift(r),e},Re=t=>{if(t.length<=0)return[];let r=I(t);return r.pop(),r},ze=t=>{if(t.length<=0)return[];let r=I(t);return r.shift(),r},ft=t=>{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=[];for(let e=0;e{if(t.length<=0)return[];let r=t[0].length,e=[];for(let n=0;n{if(t.length<=0)return[];let e=[];for(let n=0;n{let n=[];for(let i=0;i{if(t.length<0)return[];if(t[0].length!==r.length)throw new Error("The number of columns in the matrix must be equal to the length of the vector.");let n=[];for(let o=0;o{if(t.length!==r.length)return!1;for(let e=0;e{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=[];for(let i=0;i{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=$e(t,r,e);return O(o)},O=t=>{let r=t.length;if(r===0)return 1;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t[0][0];if(r===2)return ht(t);let e=0;for(let n=0;n{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return t[0][0]*t[1][1]-t[1][0]*t[0][1]},Ee=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return O(t)},bt=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return[[t[1][1],-t[0][1]],[-t[1][0],t[0][0]]]},qe=t=>Vt(t),Vt=t=>{let r=t.length;if(r<=0)return null;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t;if(r===2)return bt(t);let e=[];for(let n=0;n{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");return O(t)===0},yt=(t,r=1/0)=>{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");let e=ht(t);if(e===0)return null;let n=bt(t);return n===null?null:Jt(n,e,r)},lt=(t,r=1/0)=>W(t,r),W=(t,r=1/0)=>{let e=t.length;if(e>0&&e!==t[0].length)throw new Error("The matrix must be square.");let n=O(t),o=Vt(t);return o===null?null:Z(o,n,r)};var vt={};b(vt,{m2ReflectionOrigin:()=>pn,m2ReflectionOriginH:()=>Mn,m2ReflectionX:()=>yn,m2ReflectionXH:()=>ln,m2ReflectionY:()=>dn,m2ReflectionYH:()=>In,m2ReflectionYmX:()=>Vn,m2RotateAroundPointH:()=>De,m2Rotation:()=>Ut,m2RotationAroundPointH:()=>Pt,m2RotationH:()=>It,m2Scale:()=>or,m2ScaleAtPointH:()=>Ue,m2ScaleAtPointHMatrix:()=>nr,m2ScaleH:()=>ir,m2ScaleX:()=>en,m2ScaleXH:()=>nn,m2ScaleY:()=>an,m2ScaleYH:()=>fn,m2ShearingX:()=>Bn,m2ShearingY:()=>Hn,m2ToCSS:()=>Ce,m2Translation:()=>Ge,m2TranslationH:()=>j,m2hToCSS:()=>Ne,m2hToCSS3d:()=>Xe,m3ReflectionOrigin:()=>hn,m3ReflectionOriginH:()=>bn,m3ReflectionXY:()=>Rn,m3ReflectionXYH:()=>zn,m3ReflectionXZ:()=>Sn,m3ReflectionXZH:()=>wn,m3ReflectionYZ:()=>vn,m3ReflectionYZH:()=>gn,m3RotationX:()=>tr,m3RotationXH:()=>Qe,m3RotationY:()=>rr,m3RotationYH:()=>We,m3RotationZ:()=>er,m3RotationZH:()=>Ke,m3Scale:()=>cr,m3ScaleH:()=>tn,m3ScaleX:()=>on,m3ScaleXH:()=>cn,m3ScaleY:()=>sn,m3ScaleYH:()=>un,m3ScaleZ:()=>xn,m3ScaleZH:()=>mn,m3Translation:()=>Oe,m3TranslationH:()=>je,m3hToCSS3d:()=>Ye,v2Rotate:()=>ke,v2RotateH:()=>Fe,v2Scale:()=>Pe,v3RotateX:()=>Ze,v3RotateY:()=>_e,v3RotateZ:()=>Je,v3Scale:()=>rn});var Ce=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1];return`matrix(${r}, ${e}, ${n}, ${o}, 0, 0)`},Ne=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix(${r}, ${e}, ${n}, ${o}, ${i}, ${c})`},Xe=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix3d(${r}, ${e}, 0, 0, ${n}, ${o}, 0, 0, 0, 0, 1, 0, ${i}, ${c}, 0, 1)`},Ye=t=>`matrix3d( +(()=>{var Wt=Object.defineProperty;var Qt=Object.getOwnPropertySymbols;var zr=Object.prototype.hasOwnProperty,Hr=Object.prototype.propertyIsEnumerable;var y=Math.pow,Zt=(t,r,e)=>r in t?Wt(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,h=(t,r)=>{for(var e in r||(r={}))zr.call(r,e)&&Zt(t,e,r[e]);if(Qt)for(var e of Qt(r))Hr.call(r,e)&&Zt(t,e,r[e]);return t};var b=(t,r)=>{for(var e in r)Wt(t,e,{get:r[e],enumerable:!0})};var it={};b(it,{v2:()=>Kr,v2Distance:()=>Qr,v2DivideScalar:()=>jr,v2DotProduct:()=>rt,v2FromPolarCoords:()=>Pr,v2GetNormal:()=>ot,v2Length:()=>tt,v2MulScalar:()=>Or,v2Normalize:()=>E,v2SetLength:()=>Jt,v2Sub:()=>z,v2Sum:()=>Xr,v3:()=>Jr,v3CrossProduct:()=>_r,v3Distance:()=>Zr,v3DivideScalar:()=>Dr,v3DotProduct:()=>Wr,v3Length:()=>kr,v3MulScalar:()=>Q,v3Normalize:()=>S,v3Sub:()=>Gr,v3Sum:()=>Yr,v4:()=>Ur,vDistance:()=>Fr,vDivideScalar:()=>Y,vDotProduct:()=>R,vEqual:()=>nt,vLength:()=>H,vMulScalar:()=>X,vN:()=>et,vNormalize:()=>L,vSub:()=>g,vSum:()=>C});var _={};b(_,{setDecimalPlaces:()=>s});var s=(t,r=1/0)=>{if(r===1/0)return t;r<0&&(r=0);let e=y(10,r);return Math.round(t*e)/e};var P={};b(P,{degreesToRadians:()=>Er,getAnglesDistance:()=>Kt,getAnglesSub:()=>F,getV2Angle:()=>$,getV2AngleBetween:()=>qr,getV2AngleInEllipse:()=>Lr,getV3AngleBetween:()=>Ar,getVNAngleBetween:()=>_t,isAngleBetween:()=>Nr,isClockwise:()=>U,percentToAngle:()=>Cr,radiansToDegrees:()=>$r,setV2Angle:()=>J});var K={};b(K,{convertRange:()=>k,doRangesOverlap:()=>Br,isNumber:()=>T,mod:()=>d,polarToCartesian:()=>Tr});var d=(t,r)=>(t%r+r)%r,k=(t,r,e,n,o)=>(o-n)*(t-r)/(e-r)+n,Br=(t,r,e,n)=>Math.max(t,e)<=Math.min(r,n),T=t=>!isNaN(parseFloat(t))&&isFinite(t),Tr=(t,r,e,n=1/0)=>{let[o,i]=t,[c,u]=r;return[s(o+c*Math.cos(e),n),s(i+u*Math.sin(e),n)]};var $=(t,r=1/0)=>{let e=Math.atan2(t[1],t[0]);return s(e,r)},Lr=(t,r,e=1/0)=>{let n=Math.atan2(t[1]/r[1],t[0]/r[0]);return s(n,e)},J=(t,r,e=1/0)=>{let n=tt(t);return[s(Math.cos(r)*n,e),s(Math.sin(r)*n,e)]},$r=(t,r=1/0)=>{let e=t*(180/Math.PI);return s(e,r)},Er=(t,r=1/0)=>{let e=t*(Math.PI/180);return s(e,r)},_t=(t,r,e=1/0)=>{let n=L(t),o=L(r),i=R(n,o),c=Math.acos(i);return s(c,e)},qr=(t,r,e=1/0)=>{let n=g(t,r),o=Math.atan2(n[1],n[0]);return s(o,e)},Ar=(t,r,e=1/0)=>_t(t,r,e),Nr=(t,r,e)=>{let n=F(r,e),o=F(r,t),i=F(e,t),c=o+i;return Math.abs(c-n)<=.001},U=(t,r,e=0)=>(t=t%360,r=r%360,t=t),F=(t,r,e=1/0)=>{let n=Math.abs(d(t,360)-d(r,360));return s(n<=180?n:360-n,e)},Kt=(t,r,e=0,n=1/0)=>(t=t%360,r=r%360,t{t<0&&(t=0),t>100&&(t=100);let o=Kt(r,e,n);return U(r,e,n)?d(n+t*o/100,360):d(n-t*o/100,360)};var C=(t,r,e=1/0)=>{let n=[];for(let o=0;oC(t,r,e),Yr=(t,r,e=1/0)=>C(t,r,e),g=(t,r,e=1/0)=>{let n=[];for(let o=0;og(t,r,e),Gr=(t,r,e=1/0)=>g(t,r,e),X=(t,r,e=1/0)=>{let n=[];for(let o=0;oX(t,r,e),Q=(t,r,e=1/0)=>X(t,r,e),Y=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o=0;oY(t,r,e),Dr=(t,r,e=1/0)=>Y(t,r,e),H=(t,r=1/0)=>{let e=0;for(let n=0;nH(t,r),kr=(t,r=1/0)=>H(t,r),Jt=(t,r,e=1/0)=>{let n=$(t);return[s(Math.cos(n)*r,e),s(Math.sin(n)*r,e)]},Fr=(t,r,e=1/0)=>{let n=g(t,r);return H(n,e)},Qr=(t,r,e=1/0)=>{let n=g(t,r);return H(n,e)},Zr=(t,r,e=1/0)=>{let n=g(t,r);return H(n,e)},L=(t,r=1/0)=>{let e=H(t),n=[];for(let o=0;oL(t,r),S=(t,r=1/0)=>L(t,r),R=(t,r,e=1/0)=>{let n=0;for(let o=0;oR(t,r,e),Wr=(t,r,e=1/0)=>R(t,r,e),_r=(t,r,e=1/0)=>[s(t[1]*r[2]-t[2]*r[1],e),s(t[2]*r[0]-t[0]*r[2],e),s(t[0]*r[1]-t[1]*r[0],e)],Kr=(t=0)=>[t,t],Jr=(t=0)=>[t,t,t],Ur=(t=0)=>[t,t,t,t],et=(t,r=0)=>{if(t<0)throw new Error("N must be a non-negative number.");let e=[];for(let n=0;n{let e=[0,0];return e=Jt(e,t),J(e,r)},nt=(t,r)=>{if(t.length!==r.length)return!1;for(let e=0;e{let n=z(r,t);return[-s(n[1],e),s(n[0],e)]};var dt={};b(dt,{identity2:()=>he,identity3:()=>be,identity4:()=>Ve,identityN:()=>le,isSingularMatrix:()=>Ne,m2Adjugate:()=>bt,m2AppendRow:()=>ve,m2DeepCopy:()=>mt,m2Determinant:()=>ht,m2DivideScalar:()=>Ut,m2Inverse:()=>lt,m2MulScalar:()=>oe,m2PrependRow:()=>we,m2Reset:()=>xe,m2Sub:()=>ee,m2Sum:()=>te,m2Transpose:()=>se,m2x2:()=>ae,m3Adjugate:()=>Ae,m3AppendRow:()=>ge,m3DeepCopy:()=>at,m3Determinant:()=>qe,m3DivideScalar:()=>ce,m3Inverse:()=>yt,m3MulScalar:()=>ie,m3PrependRow:()=>Re,m3Reset:()=>me,m3Sub:()=>ne,m3Sum:()=>re,m3Transpose:()=>ue,m3x3:()=>fe,m4x4:()=>pe,mAdjugate:()=>Vt,mAppendCol:()=>ye,mAppendRow:()=>Ie,mDeepCopy:()=>I,mDelFirstColumn:()=>Be,mDelFirstRow:()=>He,mDelLastColumn:()=>ft,mDelLastRow:()=>ze,mDeterminant:()=>O,mDivideScalar:()=>Z,mEqual:()=>$e,mGetColumn:()=>Le,mGetFirstColumn:()=>Te,mGetLastColumn:()=>pt,mInverse:()=>W,mMinor:()=>Mt,mMul:()=>q,mMulScalar:()=>ut,mMulVector:()=>V,mNxM:()=>Me,mPrependCol:()=>de,mPrependRow:()=>Se,mReset:()=>xt,mSub:()=>st,mSum:()=>ct,mTranspose:()=>G});var ct=(t,r,e=1/0)=>{let n=[];for(let o=0;oct(t,r,e),re=(t,r,e=1/0)=>ct(t,r,e),st=(t,r,e=1/0)=>{let n=[];for(let o=0;ost(t,r,e),ne=(t,r,e=1/0)=>st(t,r,e),ut=(t,r,e=1/0)=>{let n=[];for(let o of t)n.push(X(o,r,e));return n},oe=(t,r,e=1/0)=>ut(t,r,e),ie=(t,r,e=1/0)=>ut(t,r,e),Z=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o of t)n.push(Y(o,r,e));return n},Ut=(t,r,e=1/0)=>Z(t,r,e),ce=(t,r,e=1/0)=>Z(t,r,e),G=t=>{let r=t.length;if(r<=0)return t;let e=t[0].length;if(e<=0)return t;let n=[];for(let o=0;oG(t),ue=t=>G(t),xt=(t,r=0)=>{if(t.length<=0)return[];let e=[];for(let n=0;nxt(t,r),me=(t,r=0)=>xt(t,r),ae=(t=0)=>[[t,t],[t,t]],fe=(t=0)=>[[t,t,t],[t,t,t],[t,t,t]],pe=(t=0)=>[[t,t,t,t],[t,t,t,t],[t,t,t,t],[t,t,t,t]],Me=(t,r,e=0)=>{if(t<=0||r<=0)throw new Error("M and N must be positive numbers.");let n=[];for(let o=0;o[[1,0],[0,1]],be=()=>[[1,0,0],[0,1,0],[0,0,1]],Ve=()=>[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],le=t=>{if(t<0)throw new Error("N must be a non-negative number.");if(t===0)return[];let r=[];for(let e=0;e{let r=[];for(let e=0;eI(t),at=t=>I(t),ye=(t,r)=>{if(t.length<=0)return[];let e=I(t);for(let n=0;n{if(t.length<=0)return[];let e=I(t);for(let n=0;n{let e=I(t);return e.push(r),e},ve=(t,r)=>{let e=mt(t);return e.push(r),e},ge=(t,r)=>{let e=at(t);return e.push(r),e},Se=(t,r)=>{let e=I(t);return e.unshift(r),e},we=(t,r)=>{let e=mt(t);return e.unshift(r),e},Re=(t,r)=>{let e=at(t);return e.unshift(r),e},ze=t=>{if(t.length<=0)return[];let r=I(t);return r.pop(),r},He=t=>{if(t.length<=0)return[];let r=I(t);return r.shift(),r},ft=t=>{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=I(t);for(let e=0;e{if(t.length<=0)return[];let r=[];for(let e=0;e{if(t.length<=0)return[];let r=t[0].length,e=[];for(let n=0;n{if(t.length<=0)return[];let e=[];for(let n=0;n{let n=[];for(let i=0;i{if(t.length<0)return[];if(t[0].length!==r.length)throw new Error("The number of columns in the matrix must be equal to the length of the vector.");let n=[];for(let o=0;o{if(t.length!==r.length)return!1;for(let e=0;e{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=[];for(let i=0;i{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=Ee(t,r,e);return O(o)},O=t=>{let r=t.length;if(r===0)return 1;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t[0][0];if(r===2)return ht(t);let e=0;for(let n=0;n{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return t[0][0]*t[1][1]-t[1][0]*t[0][1]},qe=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return O(t)},bt=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return[[t[1][1],-t[0][1]],[-t[1][0],t[0][0]]]},Ae=t=>Vt(t),Vt=t=>{let r=t.length;if(r<=0)return null;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t;if(r===2)return bt(t);let e=[];for(let n=0;n{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");return O(t)===0},lt=(t,r=1/0)=>{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");let e=ht(t);if(e===0)return null;let n=bt(t);return n===null?null:Ut(n,e,r)},yt=(t,r=1/0)=>W(t,r),W=(t,r=1/0)=>{let e=t.length;if(e>0&&e!==t[0].length)throw new Error("The matrix must be square.");let n=O(t),o=Vt(t);return o===null?null:Z(o,n,r)};var vt={};b(vt,{m2ReflectionOrigin:()=>Mn,m2ReflectionOriginH:()=>hn,m2ReflectionX:()=>yn,m2ReflectionXH:()=>dn,m2ReflectionY:()=>In,m2ReflectionYH:()=>vn,m2ReflectionYmX:()=>ln,m2RotateAroundPointH:()=>ke,m2Rotation:()=>Pt,m2RotationAroundPointH:()=>tr,m2RotationH:()=>It,m2Scale:()=>ir,m2ScaleAtPointH:()=>Pe,m2ScaleAtPointHMatrix:()=>or,m2ScaleH:()=>cr,m2ScaleX:()=>nn,m2ScaleXH:()=>on,m2ScaleY:()=>fn,m2ScaleYH:()=>pn,m2ShearingX:()=>Tn,m2ShearingY:()=>Bn,m2ToCSS:()=>Ce,m2Translation:()=>Oe,m2TranslationH:()=>j,m2hToCSS:()=>Xe,m2hToCSS3d:()=>Ye,m3ReflectionOrigin:()=>bn,m3ReflectionOriginH:()=>Vn,m3ReflectionXY:()=>zn,m3ReflectionXYH:()=>Hn,m3ReflectionXZ:()=>wn,m3ReflectionXZH:()=>Rn,m3ReflectionYZ:()=>gn,m3ReflectionYZH:()=>Sn,m3RotationX:()=>rr,m3RotationXH:()=>Ze,m3RotationY:()=>er,m3RotationYH:()=>_e,m3RotationZ:()=>nr,m3RotationZH:()=>Je,m3Scale:()=>sr,m3ScaleH:()=>rn,m3ScaleX:()=>cn,m3ScaleXH:()=>sn,m3ScaleY:()=>un,m3ScaleYH:()=>xn,m3ScaleZ:()=>mn,m3ScaleZH:()=>an,m3Translation:()=>je,m3TranslationH:()=>De,m3hToCSS3d:()=>Ge,v2Rotate:()=>Fe,v2RotateH:()=>Qe,v2Scale:()=>tn,v3RotateX:()=>We,v3RotateY:()=>Ke,v3RotateZ:()=>Ue,v3Scale:()=>en});var Ce=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1];return`matrix(${r}, ${e}, ${n}, ${o}, 0, 0)`},Xe=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix(${r}, ${e}, ${n}, ${o}, ${i}, ${c})`},Ye=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix3d(${r}, ${e}, 0, 0, ${n}, ${o}, 0, 0, 0, 0, 1, 0, ${i}, ${c}, 0, 1)`},Ge=t=>`matrix3d( ${t[0][0]}, ${t[0][1]}, ${t[0][2]}, ${t[0][3]}, ${t[1][0]}, ${t[1][1]}, ${t[1][2]}, ${t[1][3]}, ${t[2][0]}, ${t[2][1]}, ${t[2][2]}, ${t[2][3]}, ${t[3][0]}, ${t[3][1]}, ${t[3][2]}, ${t[3][3]} - )`,Ge=(t,r=1/0)=>[[1,0],[0,1],[s(t[0],r),s(t[1],r)]],Oe=(t,r=1/0)=>[[1,0,0],[0,1,0],[0,0,1],[s(t[0],r),s(t[1],r),s(t[2],r)]],j=(t,r=1/0)=>[[1,0,s(t[0],r)],[0,1,s(t[1],r)],[0,0,1]],je=(t,r=1/0)=>[[1,0,0,s(t[0],r)],[0,1,0,s(t[1],r)],[0,0,1,s(t[2],r)],[0,0,0,1]],Ut=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o],[o,n]]:[[n,o],[-o,n]]},It=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Pt=(t,r,e=!0,n=1/0)=>{let o=j(r,n),i=It(t,e,n),c=j(Q(r,-1),n),u=q(o,i);return q(u,c)},De=(t,r,e,n=!0,o=1/0)=>{let i=Pt(t,r,n,o);return V(i,e)},ke=(t,r,e=!0,n=1/0)=>{let o=E(r);return V(Ut(t,e,n),o)},Fe=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(It(t,e,n),o)},tr=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0],[0,n,-o],[0,o,n]]:[[1,0,0],[0,n,o],[0,-o,n]]},Qe=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0,0],[0,n,-o,0],[0,o,n,0],[0,0,0,1]]:[[1,0,0,0],[0,n,o,0],[0,-o,n,0],[0,0,0,1]]},Ze=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(tr(t,e,n),o)},rr=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o],[0,1,0],[-o,0,n]]:[[n,0,-o],[0,1,0],[o,0,n]]},We=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o,0],[0,1,0,0],[-o,0,n,0],[0,0,0,1]]:[[n,0,-o,0],[0,1,0,0],[o,0,n,0],[0,0,0,1]]},_e=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(rr(t,e,n),o)},er=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Ke=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0,0],[o,n,0,0],[0,0,1,0],[0,0,0,1]]:[[n,o,0,0],[-o,n,0,0],[0,0,1,0],[0,0,0,1]]},Je=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(er(t,e,n),o)},nr=(t,r,e=1/0)=>{let n=j(r,e),o=ir(t),i=j(Q(r,-1),e),c=q(n,o);return q(c,i)},Ue=(t,r,e,n=1/0)=>{let o=nr(t,r,n);return V(o,e)},or=t=>[[t[0],0],[0,t[1]]],Pe=(t,r)=>V(or(t),r),ir=t=>[[t[0],0,0],[0,t[1],0],[0,0,1]],cr=t=>[[t[0],0,0],[0,t[1],0],[0,0,t[2]]],tn=t=>[[t[0],0,0,0],[0,t[1],0,0],[0,0,t[2],0],[0,0,0,1]],rn=(t,r)=>V(cr(t),r),en=t=>[[t,0],[0,1]],nn=t=>[[t,0,0],[0,1,0],[0,0,1]],on=t=>[[t,0,0],[0,1,0],[0,0,1]],cn=t=>[[t,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],sn=t=>[[1,0,0],[0,t,0],[0,0,1]],un=t=>[[1,0,0,0],[0,t,0,0],[0,0,1,0],[0,0,0,1]],xn=t=>[[1,0,0],[0,1,0],[0,0,t]],mn=t=>[[1,0,0,0],[0,1,0,0],[0,0,t,0],[0,0,0,1]],an=t=>[[1,0],[0,t]],fn=t=>[[1,0,0],[0,t,0],[0,0,1]],pn=()=>[[-1,0],[0,-1]],Mn=()=>[[-1,0,0],[0,-1,0],[0,0,1]],hn=()=>[[-1,0,0],[0,-1,0],[0,0,-1]],bn=()=>[[-1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]],Vn=()=>[[0,-1],[-1,0]],yn=()=>[[1,0],[0,-1]],ln=()=>[[1,0,0],[0,-1,0],[0,0,1]],dn=()=>[[-1,0],[0,1]],In=()=>[[-1,0,0],[0,1,0],[0,0,1]],vn=()=>[[-1,0,0],[0,1,0],[0,0,1]],gn=()=>[[-1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Sn=()=>[[1,0,0],[0,-1,0],[0,0,1]],wn=()=>[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]],Rn=()=>[[1,0,0],[0,1,0],[0,0,-1]],zn=()=>[[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]],Hn=t=>[[1,t],[0,1]],Bn=t=>[[1,0],[t,1]];var gt={};b(gt,{getRandom:()=>y,getRandomBoolean:()=>Tn,getRandomInt:()=>sr,getRandomItemFromArray:()=>Ln});var y=(t,r,e=1/0)=>s(Math.random()*(r-t)+t,e),sr=(t,r)=>Math.floor(Math.random()*(r-t+1)+t),Tn=()=>Math.random()<.5,Ln=t=>{let r=sr(0,t.length-1);return t[r]};var St={};b(St,{stringToNumber:()=>$n});var $n=(t,r)=>{var n;if(t==null)return r;let e=(n=Number(t))!=null?n:r;return isNaN(e)?r:e};var $t={};b($t,{v2CubicBezierBBox:()=>Pn,v2CubicBezierCurve:()=>xr,v2CubicBezierCurveExtrema:()=>pr,v2CubicBezierCurveNormal:()=>Jn,v2CubicBezierCurveTangent:()=>ar,v2QuadraticBezierBBox:()=>Un,v2QuadraticBezierCurve:()=>ur,v2QuadraticBezierCurveExtrema:()=>fr,v2QuadraticBezierCurveNormal:()=>Kn,v2QuadraticBezierCurveTangent:()=>mr,v3CubicBezierCurve:()=>Zn,v3CubicBezierCurveTangent:()=>_n,v3QuadraticBezierCurve:()=>Qn,v3QuadraticBezierCurveTangent:()=>Wn});var Bt={};b(Bt,{dxArcCos:()=>Yn,dxArcCot:()=>On,dxArcSin:()=>Xn,dxArcTan:()=>Gn,dxCos:()=>An,dxCot:()=>Nn,dxPolynomial:()=>En,dxSin:()=>qn,dxTan:()=>Cn,dxV2CubicBezierCurve:()=>zt,dxV2QuadraticBezierCurve:()=>wt,dxV3CubicBezierCurve:()=>Ht,dxV3QuadraticBezierCurve:()=>Rt});var En=(t,r,e=1/0)=>{let n=0;for(let o of r){if(o.length!==2)return NaN;let i=o[0],c=o[1];n+=i*c*Math.pow(t,c-1)}return s(n,e)},wt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},Rt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},zt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,m=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i)]},Ht=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,m=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+m*o[2],i)]},qn=(t,r=1/0)=>s(Math.cos(t),r),An=(t,r=1/0)=>s(-Math.sin(t),r),Cn=(t,r=1/0)=>s(1/l(Math.cos(t),2),r),Nn=(t,r=1/0)=>s(-1/l(Math.sin(t),2),r),Xn=(t,r=1/0)=>s(1/Math.sqrt(1-l(t,2)),r),Yn=(t,r=1/0)=>s(-1/Math.sqrt(1-l(t,2)),r),Gn=(t,r=1/0)=>s(1/(1+l(t,2)),r),On=(t,r=1/0)=>s(-1/(1+l(t,2)),r);var Tt={};b(Tt,{getLinearEquationBy2Points:()=>Fn,linearEquation:()=>A,linearEquationSystem2:()=>jn,linearEquationSystem3:()=>Dn,linearEquationSystemN:()=>kn});var A=(t,r=1/0)=>{let e=t[0],n=t[1],i=t[2]-n;return e===0&&i===0?1/0:e===0?NaN:s(i/e,r)},jn=(t,r,e=1/0)=>{let n=[[t[0],t[1]],[r[0],r[1]]],o=yt(n);if(o===null)return null;let i=[t[2],r[2]];return V(o,i,e)},Dn=(t,r,e,n=1/0)=>{let o=[[t[0],t[1],t[2]],[r[0],r[1],r[2]],[e[0],e[1],e[2]]],i=lt(o);if(i===null)return null;let c=[t[3],r[3],e[3]];return V(i,c,n)},kn=(t,r=1/0)=>{if(t.length<=0)return null;let e=ft(t),n=W(e);if(n===null)return null;let o=pt(t);return V(n,o,r)},Fn=(t,r)=>{let[e,n]=z(r,t),[o,i]=t;if(e===0)return{slope:void 0,xIntercept:o,yIntercept:void 0,formula:`x = ${o}`};let c=n/e,u=i-c*o,x="";return c===0?x=`y = ${u}`:(x=`y = ${c===1?"":c}x`,u!==0&&(x+=` ${u<0?"-":"+"} ${Math.abs(u)}`)),{slope:c,xIntercept:void 0,yIntercept:u,formula:x}};var Lt=(t,r=1/0)=>{let e=t[0],n=t[1],o=t[2],i=t[3];if(e===0){let f=A([n,o,i],r);return T(f)?[f]:[]}let c=o-i,u=n*n-4*e*c;if(u<0)return[];if(u===0)return[s(-n/(2*e),r)];let x=2*e,m=Math.sqrt(u);return[s((-n+m)/x,r),s((-n-m)/x,r)]};var ur=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},Qn=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},xr=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,m=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i)]},Zn=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,m=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+m*o[2],i)]},mr=(t,r,e,n,o=1/0)=>{let i=wt(t,r,e,n);return E(i,o)},Wn=(t,r,e,n,o=1/0)=>{let i=Rt(t,r,e,n);return S(i,o)},ar=(t,r,e,n,o,i=1/0)=>{let c=zt(t,r,e,n,o);return E(c,i)},_n=(t,r,e,n,o,i=1/0)=>{let c=Ht(t,r,e,n,o);return S(c,i)},Kn=(t,r,e,n,o=1/0)=>{let i=mr(t,r,e,n,o);return[-i[1],i[0]]},Jn=(t,r,e,n,o,i=1/0)=>{let c=ar(t,r,e,n,o,i);return[-c[1],c[0]]},fr=(t,r,e,n=1/0)=>{let o=2*t[0]-4*r[0]+2*e[0],i=-2*t[0]+2*r[0],u=A([o,i,0],n),x=2*t[1]-4*r[1]+2*e[1],m=-2*t[1]+2*r[1],p=A([x,m,0],n),a=[];return T(u)&&a.push(u),T(p)&&a.push(p),a},pr=(t,r,e,n,o=1/0)=>{let i=-3*t[0]+9*r[0]-9*e[0]+3*n[0],c=6*t[0]-12*r[0]+6*e[0],u=-3*t[0]+3*r[0],x=[i,c,u,0],m=-3*t[1]+9*r[1]-9*e[1]+3*n[1],f=6*t[1]-12*r[1]+6*e[1],p=-3*t[1]+3*r[1],a=[m,f,p,0],M=Lt(x,o).filter(v=>v>=0&&v<=1),w=Lt(a,o).filter(v=>v>=0&&v<=1);return[...M,...w].length===2?[...M,...w]:null},Un=(t,r,e,n=1/0)=>{let o=fr(t,r,e),i=1/0,c=1/0,u=-1/0,x=-1/0;for(let m of o){let f=ur(m,t,r,e),p=f[0],a=f[1];i=Math.min(i,p),u=Math.max(u,p),c=Math.min(c,a),x=Math.max(x,a)}return i=s(Math.min(i,t[0],e[0]),n),u=s(Math.max(u,t[0],e[0]),n),c=s(Math.min(c,t[1],e[1]),n),x=s(Math.max(x,t[1],e[1]),n),{x:i,y:c,w:Math.abs(u-i),h:Math.abs(x-c),x2:u,y2:x}},Pn=(t,r,e,n,o=1/0)=>{let i=pr(t,r,e,n)||[],c=1/0,u=1/0,x=-1/0,m=-1/0;for(let f of i){let p=xr(f,t,r,e,n),a=p[0],M=p[1];c=Math.min(c,a!=null?a:1/0),x=Math.max(x,a!=null?a:-1/0),u=Math.min(u,M!=null?M:1/0),m=Math.max(m,M!=null?M:-1/0)}return c=s(Math.min(c,t[0],n[0]),o),x=s(Math.max(x,t[0],n[0]),o),u=s(Math.min(u,t[1],n[1]),o),m=s(Math.max(m,t[1],n[1]),o),{x:c,y:u,w:Math.abs(x-c),h:Math.abs(m-u),x2:x,y2:m}};var Et={};b(Et,{circleMovement:()=>Mr,circleMovementAfterMouse:()=>to,ellipseMovement:()=>hr,ellipseMovementAfterMouse:()=>ro,lissajousCurve:()=>no,sineWaveMovement:()=>eo});var Mr=(t,r,e)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*e]),to=(t,r,e)=>{let n=z(t,r),o=$(n);return o=k(o,0,Math.PI*2,0,Math.PI),Mr(r,o,e)},hr=(t,r,e,n)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*n]),ro=(t,r,e)=>{let n=z(t,r),o=$(n);return o=k(o,0,Math.PI*2,0,Math.PI),hr(r,o,e[0],e[1])},eo=(t,r,e,n)=>{let o=r*Math.sin(2*Math.PI*e*t+n);return[t,o]},no=(t,r,e,n,o,i,c)=>[t*Math.cos(n*e-i),r*Math.cos(o*e-c)];var Nt={};b(Nt,{getColorsDelta:()=>vo,getRandomGrayscaleHSLColor:()=>xo,getRandomHSLColor:()=>Ct,getRandomHSLColorWithHue:()=>co,getRandomHSLColorWithLightness:()=>uo,getRandomHSLColorWithSaturation:()=>so,getRandomHSLColorWithinRanges:()=>mo,getRandomHexColor:()=>io,getRandomRGBColor:()=>oo,getShiftedHue:()=>yo,getShiftedLightness:()=>lo,getShiftedSaturation:()=>Io,hexToRgb:()=>bo,hslToHex:()=>yr,hslToRgb:()=>Vr,labToRgb:()=>Vo,rgbToHex:()=>ho,rgbToHsl:()=>Mo,rgbToLab:()=>At});var oo=()=>{let t=Ct();return Vr(t)},io=()=>{let t=Ct();return yr(t)},Ct=()=>{let t=y(1,360),r=y(0,100),e=y(0,100);return[t,r,e]},co=t=>{let r=y(0,100),e=y(0,100);return[t,r,e]},so=t=>{let r=y(1,360),e=y(0,100);return[r,t,e]},uo=t=>{let r=y(1,360),e=y(0,100);return[r,e,t]},xo=()=>[0,0,y(0,100)],mo=(t=1,r=360,e=0,n=100,o=0,i=100)=>{let c=y(t,r),u=y(e,n),x=y(o,i);return[c,u,x]},ao=t=>(t*=60,t<0&&(t+=360),t),fo=(t,r,e,n=void 0,o=void 0)=>{if(n=n===void 0?Math.min(t,r,e):n,o=o===void 0?Math.max(t,r,e):o,n===o)return 0;let i=o-n,c=0;return o===t&&(c=(r-e)/i+(r(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,(n+o)/2*100),po=(t,r,e,n=void 0,o=void 0,i=void 0)=>(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,n===o?0:(i=i===void 0?br(t,r,e):i,(i<=50?(o-n)/(o+n):(o-n)/(2-o-n))*100)),Mo=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255,i=Math.min(e,n,o),c=Math.max(e,n,o),u=br(e,n,o,i,c),x=po(e,n,o,i,c,u),m=fo(e,n,o,i,c);return m>360||x>100||u>100?[0,0,100]:m<0||x<0||u<0?[0,0,0]:[s(m,r),s(x,r),s(u,r)]},qt=(t,r,e)=>(e<0&&(e+=1),e>1&&(e-=1),e*6<1?r+(t-r)*6*e:e*2<1?t:e*3<2?r+(t-r)*(.666-e)*6:r),Vr=(t,r=1/0)=>{let e=t[0]/100,n=t[1]/100,o=t[2]/100;if(n===0){let M=o*255;return[M,M,M]}let i=o<.5?o*(1+n):o+n-o*n,c=2*o-i,u=e+.333,x=e,m=e-.333,f=qt(i,c,u),p=qt(i,c,x),a=qt(i,c,m);return f*=255,p*=255,a*=255,f>255||p>255||a>255?[255,255,255]:f<0||p<0||a<0?[0,0,0]:[s(f,r),s(p,r),s(a,r)]},yr=t=>{if(t[0]>360||t[1]>100||t[2]>100)return"#ffffff";if(t[0]<0||t[1]<0||t[2]<0)return"#000000";let r=t[0]/360,e=t[1]/100,n=t[2]/100,o,i,c;if(e===0)o=i=c=n;else{let x=(p,a,M)=>(M<0&&(M+=1),M>1&&(M-=1),M<.16666666666666666?p+(a-p)*6*M:M<.5?a:M<.6666666666666666?p+(a-p)*(.6666666666666666-M)*6:p),m=n<.5?n*(1+e):n+e-n*e,f=2*n-m;o=x(f,m,r+1/3),i=x(f,m,r),c=x(f,m,r-1/3)}let u=x=>{let m=Math.round(x*255).toString(16);return m.length===1?"0"+m:m};return`#${u(o)}${u(i)}${u(c)}`},ho=t=>{let[r,e,n]=t;return"#"+(1<<24|r<<16|e<<8|n).toString(16).slice(1)},bo=t=>{let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,e=t.replace(r,(u,x,m,f)=>x+x+m+m+f+f),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)return null;let o=parseInt(n[1],16),i=parseInt(n[2],16),c=parseInt(n[3],16);return[o,i,c]},At=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,o=o>.04045?Math.pow((o+.055)/1.055,2.4):o/12.92;let i=(e*.4124+n*.3576+o*.1805)/.95047,c=(e*.2126+n*.7152+o*.0722)/1,u=(e*.0193+n*.1192+o*.9505)/1.08883;return i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,c=c>.008856?Math.pow(c,1/3):7.787*c+16/116,u=u>.008856?Math.pow(u,1/3):7.787*u+16/116,[s(116*c-16,r),s(500*(i-c),r),s(200*(c-u),r)]},Vo=(t,r=1/0)=>{let e=(t[0]+16)/116,n=t[1]/500+e,o=e-t[2]/200;n=.95047*(n*n*n>.008856?n*n*n:(n-16/116)/7.787),e=1*(e*e*e>.008856?e*e*e:(e-16/116)/7.787),o=1.08883*(o*o*o>.008856?o*o*o:(o-16/116)/7.787);let i=n*3.2406+e*-1.5372+o*-.4986,c=n*-.9689+e*1.8758+o*.0415,u=n*.0557+e*-.204+o*1.057;return i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,u=u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u,[s(Math.max(0,Math.min(1,i))*255,r),s(Math.max(0,Math.min(1,c))*255,r),s(Math.max(0,Math.min(1,u))*255,r)]},yo=(t,r=180)=>{let e=t[0];return e+=r,(e>360||e<0)&&(e=d(e,360)),[e,t[1],t[2]]},lo=(t,r=10)=>{let e=t[2];return e+=r,(e>100||e<0)&&(e=d(e,100)),[t[0],t[1],e]},Io=(t,r=10)=>{let e=t[1];return e+=r,e>100&&(e-=100),e<0&&(e+=100),[t[0],e,t[2]]},vo=(t,r,e=1/0)=>{let n=At(t,e),o=At(r,e),i=n[0]-o[0],c=n[1]-o[1],u=n[2]-o[2],x=Math.sqrt(n[1]*n[1]+n[2]*n[2]),m=Math.sqrt(o[1]*o[1]+o[2]*o[2]),f=x-m,p=c*c+u*u-f*f;p=p<0?0:Math.sqrt(p);let a=1+.045*x,M=1+.015*x,w=i/1,C=f/a,v=p/M,D=w*w+C*C+v*v;return D<0?0:Math.sqrt(D)};var lr={};var Xt={};b(Xt,{guid:()=>go,newId:()=>So});var go=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)}),So=()=>Math.random().toString(36).substring(2)+new Date().getTime().toString(36);var Yt={};b(Yt,{circleCollide:()=>Ro,convexPolygonsCollide:()=>zo,rectCollide:()=>wo});var wo=(t,r)=>t.x<=r.x+r.w&&t.x+t.w>=r.x&&t.y<=r.y+r.h&&t.h+t.y>=r.y,Ro=(t,r)=>{let e=Math.abs(t.cx-r.cx),n=Math.abs(t.cy-r.cy);return Math.sqrt(e*e+n*n)<=t.r+r.r},dr=t=>{let r=[];for(let e=0;e{let e=[];e.push(...dr(t)),e.push(...dr(r));for(let n of e){let o=ot(n[0],n[1]),i=Ir(t,o),c=Ir(r,o);if(!(i.max>=c.min&&c.max>=i.min))return!1}return!0},Ir=(t,r)=>{let e=1/0,n=-1/0;for(let o of t){let i=rt(o,r);e=Math.min(e,i),n=Math.max(n,i)}return{min:e,max:n}};var Gt={};b(Gt,{animate:()=>Ho});var Ho=t=>{let r=t.duration!==void 0?t.duration:1/0,e,n,o,i,c=!1,u,x=()=>{e=void 0,o=void 0,i=void 0,c=!1,n!==void 0&&window.cancelAnimationFrame(n)},m=()=>{x(),w()},f=()=>{c=!1},p=()=>{c=!0},a=B=>{e===void 0&&(e=B),o=B-e,c&&i!==B&&typeof t.callback=="function"&&t.callback(kt()),o<=r?(i=B,n=window.requestAnimationFrame(a)):x()},M=(B,wr)=>{m(),typeof t.resizeCallback=="function"&&t.resizeCallback(B,wr)},w=()=>{e=void 0,o=void 0,i=void 0,c=!0,t.restartOnResize&&window.ResizeObserver&&u===void 0?(u=new ResizeObserver(M),u.observe(document.body,{box:"border-box"})):n=window.requestAnimationFrame(a)},C=()=>o,v=()=>c,D=()=>e,gr=()=>{if(!(r===1/0||o===void 0))return o*100/r},Sr=()=>u,kt=()=>({start:w,stop:x,pause:f,resume:p,restart:m,isAnimating:v,getElapsedTime:C,getStartTime:D,getPercent:gr,getResizeObserver:Sr});return kt()};var Ot={};b(Ot,{getCircleCircumference:()=>Bo,getEllipseCircumference:()=>To,getSquareInCircleSide:()=>$o,isAngleInCircleArc:()=>Lo});var Bo=(t,r=1/0)=>s(2*Math.PI*t,r),To=(t,r,e=1/0)=>s(2*Math.PI*Math.sqrt((l(t,2)+l(r,2))/2),e),Lo=(t,r,e)=>(t>r&&(r+=360),e>=t&&e<=r||e+360>=t&&e+360<=r),$o=(t,r=1/0)=>s(t*2/Math.sqrt(2),r);var jt={};b(jt,{arithmeticSequenceSum:()=>qo,naturalNumbersSequenceSum:()=>Eo});var Eo=t=>t*(t+1)/2,qo=(t,r,e)=>t/2*(2*r+(t-1)*e);var Dt={};b(Dt,{getArithmeticMean:()=>vr,getMedian:()=>Ao,getMode:()=>Co,getVariance:()=>No});var vr=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=t.reduce((n,o)=>n+o,0);return s(e/t.length,r)},Ao=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=[...t].sort((o,i)=>o-i),n=Math.floor(e.length/2);return e.length%2===0?s((e[n]+e[n-1])/2,r):s(e[n],r)},Co=t=>{if(!t||t.length<=0)return;let r=new Map;for(let o of t)r.set(o,(r.get(o)||0)+1);let e=0,n=[];for(let[o,i]of r)i>e?(e=i,n=[o]):i===e&&n.push(o);if(n.length!==t.length)return n.length===1?[n[0]]:n},No=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=vr(t);if(e===void 0)return;let n=t.reduce((o,i)=>o+l(i-e,2),0);return s(n/t.length,r)};var Xo=h(h(h(h(h(h(h(h(h(h(h(h(h(h(h(h(h(h(h(h({},it),dt),vt),_),P),gt),K),St),$t),Tt),Et),Nt),lr),Xt),Bt),Yt),Gt),Ot),jt),Dt);window.mzMath=window.mzMath||Xo;})(); + )`,Oe=(t,r=1/0)=>[[1,0],[0,1],[s(t[0],r),s(t[1],r)]],je=(t,r=1/0)=>[[1,0,0],[0,1,0],[0,0,1],[s(t[0],r),s(t[1],r),s(t[2],r)]],j=(t,r=1/0)=>[[1,0,s(t[0],r)],[0,1,s(t[1],r)],[0,0,1]],De=(t,r=1/0)=>[[1,0,0,s(t[0],r)],[0,1,0,s(t[1],r)],[0,0,1,s(t[2],r)],[0,0,0,1]],Pt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o],[o,n]]:[[n,o],[-o,n]]},It=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},tr=(t,r,e=!0,n=1/0)=>{let o=j(r,n),i=It(t,e,n),c=j(Q(r,-1),n),u=q(o,i);return q(u,c)},ke=(t,r,e,n=!0,o=1/0)=>{let i=tr(t,r,n,o);return V(i,e)},Fe=(t,r,e=!0,n=1/0)=>{let o=E(r);return V(Pt(t,e,n),o)},Qe=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(It(t,e,n),o)},rr=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0],[0,n,-o],[0,o,n]]:[[1,0,0],[0,n,o],[0,-o,n]]},Ze=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0,0],[0,n,-o,0],[0,o,n,0],[0,0,0,1]]:[[1,0,0,0],[0,n,o,0],[0,-o,n,0],[0,0,0,1]]},We=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(rr(t,e,n),o)},er=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o],[0,1,0],[-o,0,n]]:[[n,0,-o],[0,1,0],[o,0,n]]},_e=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o,0],[0,1,0,0],[-o,0,n,0],[0,0,0,1]]:[[n,0,-o,0],[0,1,0,0],[o,0,n,0],[0,0,0,1]]},Ke=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(er(t,e,n),o)},nr=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Je=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0,0],[o,n,0,0],[0,0,1,0],[0,0,0,1]]:[[n,o,0,0],[-o,n,0,0],[0,0,1,0],[0,0,0,1]]},Ue=(t,r,e=!0,n=1/0)=>{let o=S(r);return V(nr(t,e,n),o)},or=(t,r,e=1/0)=>{let n=j(r,e),o=cr(t),i=j(Q(r,-1),e),c=q(n,o);return q(c,i)},Pe=(t,r,e,n=1/0)=>{let o=or(t,r,n);return V(o,e)},ir=t=>[[t[0],0],[0,t[1]]],tn=(t,r)=>V(ir(t),r),cr=t=>[[t[0],0,0],[0,t[1],0],[0,0,1]],sr=t=>[[t[0],0,0],[0,t[1],0],[0,0,t[2]]],rn=t=>[[t[0],0,0,0],[0,t[1],0,0],[0,0,t[2],0],[0,0,0,1]],en=(t,r)=>V(sr(t),r),nn=t=>[[t,0],[0,1]],on=t=>[[t,0,0],[0,1,0],[0,0,1]],cn=t=>[[t,0,0],[0,1,0],[0,0,1]],sn=t=>[[t,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],un=t=>[[1,0,0],[0,t,0],[0,0,1]],xn=t=>[[1,0,0,0],[0,t,0,0],[0,0,1,0],[0,0,0,1]],mn=t=>[[1,0,0],[0,1,0],[0,0,t]],an=t=>[[1,0,0,0],[0,1,0,0],[0,0,t,0],[0,0,0,1]],fn=t=>[[1,0],[0,t]],pn=t=>[[1,0,0],[0,t,0],[0,0,1]],Mn=()=>[[-1,0],[0,-1]],hn=()=>[[-1,0,0],[0,-1,0],[0,0,1]],bn=()=>[[-1,0,0],[0,-1,0],[0,0,-1]],Vn=()=>[[-1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]],ln=()=>[[0,-1],[-1,0]],yn=()=>[[1,0],[0,-1]],dn=()=>[[1,0,0],[0,-1,0],[0,0,1]],In=()=>[[-1,0],[0,1]],vn=()=>[[-1,0,0],[0,1,0],[0,0,1]],gn=()=>[[-1,0,0],[0,1,0],[0,0,1]],Sn=()=>[[-1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],wn=()=>[[1,0,0],[0,-1,0],[0,0,1]],Rn=()=>[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]],zn=()=>[[1,0,0],[0,1,0],[0,0,-1]],Hn=()=>[[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]],Bn=t=>[[1,t],[0,1]],Tn=t=>[[1,0],[t,1]];var gt={};b(gt,{getRandom:()=>l,getRandomBoolean:()=>Ln,getRandomInt:()=>ur,getRandomItemFromArray:()=>$n});var l=(t,r,e=1/0)=>s(Math.random()*(r-t)+t,e),ur=(t,r)=>Math.floor(Math.random()*(r-t+1)+t),Ln=()=>Math.random()<.5,$n=t=>{let r=ur(0,t.length-1);return t[r]};var St={};b(St,{stringToNumber:()=>En});var En=(t,r)=>{var n;if(t==null)return r;let e=(n=Number(t))!=null?n:r;return isNaN(e)?r:e};var $t={};b($t,{v2CubicBezierBBox:()=>to,v2CubicBezierCurve:()=>mr,v2CubicBezierCurveExtrema:()=>Mr,v2CubicBezierCurveNormal:()=>Un,v2CubicBezierCurveTangent:()=>fr,v2QuadraticBezierBBox:()=>Pn,v2QuadraticBezierCurve:()=>xr,v2QuadraticBezierCurveExtrema:()=>pr,v2QuadraticBezierCurveNormal:()=>Jn,v2QuadraticBezierCurveTangent:()=>ar,v3CubicBezierCurve:()=>Wn,v3CubicBezierCurveTangent:()=>Kn,v3QuadraticBezierCurve:()=>Zn,v3QuadraticBezierCurveTangent:()=>_n});var Bt={};b(Bt,{dxArcCos:()=>Gn,dxArcCot:()=>jn,dxArcSin:()=>Yn,dxArcTan:()=>On,dxCos:()=>Nn,dxCot:()=>Xn,dxPolynomial:()=>qn,dxSin:()=>An,dxTan:()=>Cn,dxV2CubicBezierCurve:()=>zt,dxV2QuadraticBezierCurve:()=>wt,dxV3CubicBezierCurve:()=>Ht,dxV3QuadraticBezierCurve:()=>Rt});var qn=(t,r,e=1/0)=>{let n=0;for(let o of r){if(o.length!==2)return NaN;let i=o[0],c=o[1];n+=i*c*Math.pow(t,c-1)}return s(n,e)},wt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},Rt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},zt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,m=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i)]},Ht=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,m=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+m*o[2],i)]},An=(t,r=1/0)=>s(Math.cos(t),r),Nn=(t,r=1/0)=>s(-Math.sin(t),r),Cn=(t,r=1/0)=>s(1/y(Math.cos(t),2),r),Xn=(t,r=1/0)=>s(-1/y(Math.sin(t),2),r),Yn=(t,r=1/0)=>s(1/Math.sqrt(1-y(t,2)),r),Gn=(t,r=1/0)=>s(-1/Math.sqrt(1-y(t,2)),r),On=(t,r=1/0)=>s(1/(1+y(t,2)),r),jn=(t,r=1/0)=>s(-1/(1+y(t,2)),r);var Tt={};b(Tt,{getLinearEquationBy2Points:()=>Qn,linearEquation:()=>A,linearEquationSystem2:()=>Dn,linearEquationSystem3:()=>kn,linearEquationSystemN:()=>Fn});var A=(t,r=1/0)=>{let e=t[0],n=t[1],i=t[2]-n;return e===0&&i===0?1/0:e===0?NaN:s(i/e,r)},Dn=(t,r,e=1/0)=>{let n=[[t[0],t[1]],[r[0],r[1]]],o=lt(n);if(o===null)return null;let i=[t[2],r[2]];return V(o,i,e)},kn=(t,r,e,n=1/0)=>{let o=[[t[0],t[1],t[2]],[r[0],r[1],r[2]],[e[0],e[1],e[2]]],i=yt(o);if(i===null)return null;let c=[t[3],r[3],e[3]];return V(i,c,n)},Fn=(t,r=1/0)=>{if(t.length<=0)return null;let e=ft(t),n=W(e);if(n===null)return null;let o=pt(t);return V(n,o,r)},Qn=(t,r)=>{let[e,n]=z(r,t),[o,i]=t;if(e===0)return{slope:void 0,xIntercept:o,yIntercept:void 0,formula:`x = ${o}`};let c=n/e,u=i-c*o,x="";return c===0?x=`y = ${u}`:(x=`y = ${c===1?"":c}x`,u!==0&&(x+=` ${u<0?"-":"+"} ${Math.abs(u)}`)),{slope:c,xIntercept:void 0,yIntercept:u,formula:x}};var Lt=(t,r=1/0)=>{let e=t[0],n=t[1],o=t[2],i=t[3];if(e===0){let f=A([n,o,i],r);return T(f)?[f]:[]}let c=o-i,u=n*n-4*e*c;if(u<0)return[];if(u===0)return[s(-n/(2*e),r)];let x=2*e,m=Math.sqrt(u);return[s((-n+m)/x,r),s((-n-m)/x,r)]};var xr=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},Zn=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},mr=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,m=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i)]},Wn=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,m=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+m*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+m*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+m*o[2],i)]},ar=(t,r,e,n,o=1/0)=>{let i=wt(t,r,e,n);return E(i,o)},_n=(t,r,e,n,o=1/0)=>{let i=Rt(t,r,e,n);return S(i,o)},fr=(t,r,e,n,o,i=1/0)=>{let c=zt(t,r,e,n,o);return E(c,i)},Kn=(t,r,e,n,o,i=1/0)=>{let c=Ht(t,r,e,n,o);return S(c,i)},Jn=(t,r,e,n,o=1/0)=>{let i=ar(t,r,e,n,o);return[-i[1],i[0]]},Un=(t,r,e,n,o,i=1/0)=>{let c=fr(t,r,e,n,o,i);return[-c[1],c[0]]},pr=(t,r,e,n=1/0)=>{let o=2*t[0]-4*r[0]+2*e[0],i=-2*t[0]+2*r[0],u=A([o,i,0],n),x=2*t[1]-4*r[1]+2*e[1],m=-2*t[1]+2*r[1],p=A([x,m,0],n),a=[];return T(u)&&a.push(u),T(p)&&a.push(p),a},Mr=(t,r,e,n,o=1/0)=>{let i=-3*t[0]+9*r[0]-9*e[0]+3*n[0],c=6*t[0]-12*r[0]+6*e[0],u=-3*t[0]+3*r[0],x=[i,c,u,0],m=-3*t[1]+9*r[1]-9*e[1]+3*n[1],f=6*t[1]-12*r[1]+6*e[1],p=-3*t[1]+3*r[1],a=[m,f,p,0],M=Lt(x,o).filter(v=>v>=0&&v<=1),w=Lt(a,o).filter(v=>v>=0&&v<=1);return[...M,...w].length===2?[...M,...w]:null},Pn=(t,r,e,n=1/0)=>{let o=pr(t,r,e),i=1/0,c=1/0,u=-1/0,x=-1/0;for(let m of o){let f=xr(m,t,r,e),p=f[0],a=f[1];i=Math.min(i,p),u=Math.max(u,p),c=Math.min(c,a),x=Math.max(x,a)}return i=s(Math.min(i,t[0],e[0]),n),u=s(Math.max(u,t[0],e[0]),n),c=s(Math.min(c,t[1],e[1]),n),x=s(Math.max(x,t[1],e[1]),n),{x:i,y:c,w:Math.abs(u-i),h:Math.abs(x-c),x2:u,y2:x}},to=(t,r,e,n,o=1/0)=>{let i=Mr(t,r,e,n)||[],c=1/0,u=1/0,x=-1/0,m=-1/0;for(let f of i){let p=mr(f,t,r,e,n),a=p[0],M=p[1];c=Math.min(c,a!=null?a:1/0),x=Math.max(x,a!=null?a:-1/0),u=Math.min(u,M!=null?M:1/0),m=Math.max(m,M!=null?M:-1/0)}return c=s(Math.min(c,t[0],n[0]),o),x=s(Math.max(x,t[0],n[0]),o),u=s(Math.min(u,t[1],n[1]),o),m=s(Math.max(m,t[1],n[1]),o),{x:c,y:u,w:Math.abs(x-c),h:Math.abs(m-u),x2:x,y2:m}};var Et={};b(Et,{circleMovement:()=>hr,circleMovementAfterMouse:()=>ro,ellipseMovement:()=>br,ellipseMovementAfterMouse:()=>eo,lissajousCurve:()=>oo,sineWaveMovement:()=>no});var hr=(t,r,e)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*e]),ro=(t,r,e)=>{let n=z(t,r),o=$(n);return o=k(o,0,Math.PI*2,0,Math.PI),hr(r,o,e)},br=(t,r,e,n)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*n]),eo=(t,r,e)=>{let n=z(t,r),o=$(n);return o=k(o,0,Math.PI*2,0,Math.PI),br(r,o,e[0],e[1])},no=(t,r,e,n)=>{let o=r*Math.sin(2*Math.PI*e*t+n);return[t,o]},oo=(t,r,e,n,o,i,c)=>[t*Math.cos(n*e-i),r*Math.cos(o*e-c)];var Ct={};b(Ct,{getColorsDelta:()=>go,getRandomGrayscaleHSLColor:()=>mo,getRandomHSLColor:()=>Nt,getRandomHSLColorWithHue:()=>so,getRandomHSLColorWithLightness:()=>xo,getRandomHSLColorWithSaturation:()=>uo,getRandomHSLColorWithinRanges:()=>ao,getRandomHexColor:()=>co,getRandomRGBColor:()=>io,getShiftedHue:()=>yo,getShiftedLightness:()=>Io,getShiftedSaturation:()=>vo,hexToRgb:()=>Vo,hslToHex:()=>yr,hslToRgb:()=>lr,labToRgb:()=>lo,rgbToHex:()=>bo,rgbToHsl:()=>ho,rgbToLab:()=>At});var io=()=>{let t=Nt();return lr(t)},co=()=>{let t=Nt();return yr(t)},Nt=()=>{let t=l(1,360),r=l(0,100),e=l(0,100);return[t,r,e]},so=t=>{let r=l(0,100),e=l(0,100);return[t,r,e]},uo=t=>{let r=l(1,360),e=l(0,100);return[r,t,e]},xo=t=>{let r=l(1,360),e=l(0,100);return[r,e,t]},mo=()=>[0,0,l(0,100)],ao=(t=1,r=360,e=0,n=100,o=0,i=100)=>{let c=l(t,r),u=l(e,n),x=l(o,i);return[c,u,x]},fo=t=>(t*=60,t<0&&(t+=360),t),po=(t,r,e,n=void 0,o=void 0)=>{if(n=n===void 0?Math.min(t,r,e):n,o=o===void 0?Math.max(t,r,e):o,n===o)return 0;let i=o-n,c=0;return o===t&&(c=(r-e)/i+(r(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,(n+o)/2*100),Mo=(t,r,e,n=void 0,o=void 0,i=void 0)=>(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,n===o?0:(i=i===void 0?Vr(t,r,e):i,(i<=50?(o-n)/(o+n):(o-n)/(2-o-n))*100)),ho=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255,i=Math.min(e,n,o),c=Math.max(e,n,o),u=Vr(e,n,o,i,c),x=Mo(e,n,o,i,c,u),m=po(e,n,o,i,c);return m>360||x>100||u>100?[0,0,100]:m<0||x<0||u<0?[0,0,0]:[s(m,r),s(x,r),s(u,r)]},qt=(t,r,e)=>(e<0&&(e+=1),e>1&&(e-=1),e*6<1?r+(t-r)*6*e:e*2<1?t:e*3<2?r+(t-r)*(.666-e)*6:r),lr=(t,r=1/0)=>{let e=t[0]/100,n=t[1]/100,o=t[2]/100;if(n===0){let M=o*255;return[M,M,M]}let i=o<.5?o*(1+n):o+n-o*n,c=2*o-i,u=e+.333,x=e,m=e-.333,f=qt(i,c,u),p=qt(i,c,x),a=qt(i,c,m);return f*=255,p*=255,a*=255,f>255||p>255||a>255?[255,255,255]:f<0||p<0||a<0?[0,0,0]:[s(f,r),s(p,r),s(a,r)]},yr=t=>{if(t[0]>360||t[1]>100||t[2]>100)return"#ffffff";if(t[0]<0||t[1]<0||t[2]<0)return"#000000";let r=t[0]/360,e=t[1]/100,n=t[2]/100,o,i,c;if(e===0)o=i=c=n;else{let x=(p,a,M)=>(M<0&&(M+=1),M>1&&(M-=1),M<.16666666666666666?p+(a-p)*6*M:M<.5?a:M<.6666666666666666?p+(a-p)*(.6666666666666666-M)*6:p),m=n<.5?n*(1+e):n+e-n*e,f=2*n-m;o=x(f,m,r+1/3),i=x(f,m,r),c=x(f,m,r-1/3)}let u=x=>{let m=Math.round(x*255).toString(16);return m.length===1?"0"+m:m};return`#${u(o)}${u(i)}${u(c)}`},bo=t=>{let[r,e,n]=t;return"#"+(1<<24|r<<16|e<<8|n).toString(16).slice(1)},Vo=t=>{let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,e=t.replace(r,(u,x,m,f)=>x+x+m+m+f+f),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)return null;let o=parseInt(n[1],16),i=parseInt(n[2],16),c=parseInt(n[3],16);return[o,i,c]},At=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,o=o>.04045?Math.pow((o+.055)/1.055,2.4):o/12.92;let i=(e*.4124+n*.3576+o*.1805)/.95047,c=(e*.2126+n*.7152+o*.0722)/1,u=(e*.0193+n*.1192+o*.9505)/1.08883;return i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,c=c>.008856?Math.pow(c,1/3):7.787*c+16/116,u=u>.008856?Math.pow(u,1/3):7.787*u+16/116,[s(116*c-16,r),s(500*(i-c),r),s(200*(c-u),r)]},lo=(t,r=1/0)=>{let e=(t[0]+16)/116,n=t[1]/500+e,o=e-t[2]/200;n=.95047*(n*n*n>.008856?n*n*n:(n-16/116)/7.787),e=1*(e*e*e>.008856?e*e*e:(e-16/116)/7.787),o=1.08883*(o*o*o>.008856?o*o*o:(o-16/116)/7.787);let i=n*3.2406+e*-1.5372+o*-.4986,c=n*-.9689+e*1.8758+o*.0415,u=n*.0557+e*-.204+o*1.057;return i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,u=u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u,[s(Math.max(0,Math.min(1,i))*255,r),s(Math.max(0,Math.min(1,c))*255,r),s(Math.max(0,Math.min(1,u))*255,r)]},yo=(t,r=180)=>{let e=t[0];return e+=r,(e>360||e<0)&&(e=d(e,360)),[e,t[1],t[2]]},Io=(t,r=10)=>{let e=t[2];return e+=r,(e>100||e<0)&&(e=d(e,100)),[t[0],t[1],e]},vo=(t,r=10)=>{let e=t[1];return e+=r,e>100&&(e-=100),e<0&&(e+=100),[t[0],e,t[2]]},go=(t,r,e=1/0)=>{let n=At(t,e),o=At(r,e),i=n[0]-o[0],c=n[1]-o[1],u=n[2]-o[2],x=Math.sqrt(n[1]*n[1]+n[2]*n[2]),m=Math.sqrt(o[1]*o[1]+o[2]*o[2]),f=x-m,p=c*c+u*u-f*f;p=p<0?0:Math.sqrt(p);let a=1+.045*x,M=1+.015*x,w=i/1,N=f/a,v=p/M,D=w*w+N*N+v*v;return D<0?0:Math.sqrt(D)};var dr={};var Xt={};b(Xt,{guid:()=>So,newId:()=>wo});var So=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)}),wo=()=>Math.random().toString(36).substring(2)+new Date().getTime().toString(36);var Yt={};b(Yt,{circleCollide:()=>zo,convexPolygonsCollide:()=>Ho,rectCollide:()=>Ro});var Ro=(t,r)=>t.x<=r.x+r.w&&t.x+t.w>=r.x&&t.y<=r.y+r.h&&t.h+t.y>=r.y,zo=(t,r)=>{let e=Math.abs(t.cx-r.cx),n=Math.abs(t.cy-r.cy);return Math.sqrt(e*e+n*n)<=t.r+r.r},Ir=t=>{let r=[];for(let e=0;e{let e=[];e.push(...Ir(t)),e.push(...Ir(r));for(let n of e){let o=ot(n[0],n[1]),i=vr(t,o),c=vr(r,o);if(!(i.max>=c.min&&c.max>=i.min))return!1}return!0},vr=(t,r)=>{let e=1/0,n=-1/0;for(let o of t){let i=rt(o,r);e=Math.min(e,i),n=Math.max(n,i)}return{min:e,max:n}};var Gt={};b(Gt,{animate:()=>Bo});var Bo=t=>{let r=t.duration!==void 0?t.duration:1/0,e,n,o,i,c=!1,u,x=()=>{e=void 0,o=void 0,i=void 0,c=!1,n!==void 0&&window.cancelAnimationFrame(n)},m=()=>{x(),w()},f=()=>{c=!1},p=()=>{c=!0},a=B=>{e===void 0&&(e=B),o=B-e,c&&i!==B&&typeof t.callback=="function"&&t.callback(Ft()),o<=r?(i=B,n=window.requestAnimationFrame(a)):x()},M=(B,Rr)=>{m(),typeof t.resizeCallback=="function"&&t.resizeCallback(B,Rr)},w=()=>{e=void 0,o=void 0,i=void 0,c=!0,t.restartOnResize&&window.ResizeObserver&&u===void 0?(u=new ResizeObserver(M),u.observe(document.body,{box:"border-box"})):n=window.requestAnimationFrame(a)},N=()=>o,v=()=>c,D=()=>e,Sr=()=>{if(!(r===1/0||o===void 0))return o*100/r},wr=()=>u,Ft=()=>({start:w,stop:x,pause:f,resume:p,restart:m,isAnimating:v,getElapsedTime:N,getStartTime:D,getPercent:Sr,getResizeObserver:wr});return Ft()};var Ot={};b(Ot,{getCircleCircumference:()=>To,getEllipseCircumference:()=>Lo,getSquareInCircleSide:()=>Eo,isAngleInCircleArc:()=>$o});var To=(t,r=1/0)=>s(2*Math.PI*t,r),Lo=(t,r,e=1/0)=>s(2*Math.PI*Math.sqrt((y(t,2)+y(r,2))/2),e),$o=(t,r,e)=>(t>r&&(r+=360),e>=t&&e<=r||e+360>=t&&e+360<=r),Eo=(t,r=1/0)=>s(t*2/Math.sqrt(2),r);var jt={};b(jt,{arithmeticSequenceSum:()=>Ao,naturalNumbersSequenceSum:()=>qo});var qo=t=>t*(t+1)/2,Ao=(t,r,e)=>t/2*(2*r+(t-1)*e);var Dt={};b(Dt,{getArithmeticMean:()=>gr,getMedian:()=>No,getMode:()=>Co,getVariance:()=>Xo});var gr=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=t.reduce((n,o)=>n+o,0);return s(e/t.length,r)},No=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=[...t].sort((o,i)=>o-i),n=Math.floor(e.length/2);return e.length%2===0?s((e[n]+e[n-1])/2,r):s(e[n],r)},Co=t=>{if(!t||t.length<=0)return;let r=new Map;for(let o of t)r.set(o,(r.get(o)||0)+1);let e=0,n=[];for(let[o,i]of r)i>e?(e=i,n=[o]):i===e&&n.push(o);if(n.length!==t.length)return n.length===1?[n[0]]:n},Xo=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=gr(t);if(e===void 0)return;let n=t.reduce((o,i)=>o+y(i-e,2),0);return s(n/t.length,r)};var kt={};b(kt,{mlNormalize:()=>Yo});var Yo=(t,r=1/0)=>{let e=[...t],n=Math.min(...e),i=Math.max(...e)-n;if(i===0)return[0];for(let c=0;c {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSum(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sum = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSum(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ SUB ------------------------\n\nexport const vSub = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSub(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sub = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSub(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ MUL SCALAR ------------------------\n\nexport const vMulScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n const vector: Vector = [];\n\n for(let i=0; i {\n return vMulScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3MulScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vMulScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ DIVIDE ------------------------\n\nexport const vDivideScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vDivideScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3DivideScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vDivideScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ LENGTH ------------------------\n\nexport const vLength = (vector: Vector, decimalPlaces = Infinity) => {\n let sum = 0;\n\n for(let i=0; i {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v3Length = (vector: Vector3, decimalPlaces = Infinity) => {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v2SetLength = (v2: Vector2, newLength: number, decimalPlaces = Infinity): Vector2 => {\n const angle = getV2Angle(v2);\n return [\n setDecimalPlaces(Math.cos(angle) * newLength, decimalPlaces),\n setDecimalPlaces(Math.sin(angle) * newLength, decimalPlaces),\n ];\n};\n\n// ----------- DISTANCE ------------------------\n\nexport const vDistance = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v2Distance = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v3Distance = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\n// ------------ NORMALIZE ------------------------\n\n/**\n * Normalization creates a unit vector, which is a vector of length 1.\n */\nexport const vNormalize = (v: Vector, decimalPlaces = Infinity) : Vector => {\n const length = vLength(v);\n const unitVector: Vector = [];\n\n for(let i=0; i {\n return vNormalize(v2, decimalPlaces) as Vector2;\n};\n\nexport const v3Normalize = (v3: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vNormalize(v3, decimalPlaces) as Vector3;\n};\n\n// ------------ DOT PRODUCT ------------------------\n\nexport const vDotProduct = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n let sum = 0;\n\n for(let i=0; i {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\nexport const v3DotProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\n// ------------ CROSS PRODUCT ------------------------\n\n/**\n * Cross product is possible on 3D vectors only.\n * The cross product a \u00D7 b is defined as a vector c that is perpendicular (orthogonal) to both a and b.\n */\nexport const v3CrossProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity): Vector3 => {\n return [\n setDecimalPlaces(vector1[1] * vector2[2] - vector1[2] * vector2[1], decimalPlaces),\n setDecimalPlaces(vector1[2] * vector2[0] - vector1[0] * vector2[2], decimalPlaces),\n setDecimalPlaces(vector1[0] * vector2[1] - vector1[1] * vector2[0], decimalPlaces),\n ];\n};\n\n// --------------- INIT VECTOR HELPER -----------------\n\nexport const v2 = (defaultValue = 0): Vector2 => {\n return [defaultValue, defaultValue];\n};\n\nexport const v3 = (defaultValue = 0): Vector3 => {\n return [defaultValue, defaultValue, defaultValue];\n};\n\nexport const v4 = (defaultValue = 0): Vector4 => {\n return [defaultValue, defaultValue, defaultValue, defaultValue];\n};\n\nexport const vN = (N: number, defaultValue = 0): Vector => {\n\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n const vector: Vector = [];\n for(let i=0; i {\n let vector: Vector2 = [0, 0];\n vector = v2SetLength(vector, distance);\n return setV2Angle(vector, angleRad);\n};\n\n// --------------- EQUALITY -------------------------\n\nexport const vEqual = (vector1: Vector, vector2: Vector): boolean => {\n if(vector1.length !== vector2.length) return false;\n\n for(let i=0; i {\n const sub = v2Sub(vector2, vector1);\n return [\n -setDecimalPlaces(sub[1], decimalPlaces),\n setDecimalPlaces(sub[0], decimalPlaces)\n ];\n};", "export const setDecimalPlaces = (num: number, decimalPlaces: number | undefined = Infinity) => {\n if(decimalPlaces === Infinity) return num;\n\n if(decimalPlaces < 0){\n decimalPlaces = 0;\n }\n\n const coefficient = 10 ** decimalPlaces;\n return Math.round(num * coefficient) / coefficient;\n};", "import { Vector, Vector2, Vector3 } from '../types';\nimport { setDecimalPlaces } from './format';\nimport { v2Length, vNormalize, vDotProduct, vSub } from './linear-algebra/vector';\nimport { mod } from './other';\n\nexport const getV2Angle = (v2: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1], v2[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleInEllipse = (v2: Vector2, radii: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1]/radii[1], v2[0]/radii[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const setV2Angle = (v2: Vector2, newAngleRad: number, decimalPlaces = Infinity): Vector2 => {\n const length = v2Length(v2);\n return [\n setDecimalPlaces(Math.cos(newAngleRad) * length, decimalPlaces),\n setDecimalPlaces(Math.sin(newAngleRad) * length, decimalPlaces),\n ];\n};\n\nexport const radiansToDegrees = (radians: number, decimalPlaces = Infinity) => {\n const res = radians * (180 / Math.PI);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\nexport const degreesToRadians = (degrees: number, decimalPlaces = Infinity) => {\n const res = degrees * (Math.PI / 180);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\n/**\n * Returns the range [0, Math.PI]\n * A = Math.acos( dot(v1, v2)/(v1.length()*v2.length()) );\n */\nexport const getVNAngleBetween = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n const unitVector1 = vNormalize(vector1);\n const unitVector2 = vNormalize(vector2);\n const dotProduct = vDotProduct(unitVector1, unitVector2);\n const angle = Math.acos(dotProduct);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleBetween = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) : number => {\n // return getVNAngleBetween(vector1, vector2, decimalPlaces);\n const diff = vSub(vector1, vector2);\n const angle = Math.atan2(diff[1], diff[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV3AngleBetween = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return getVNAngleBetween(vector1, vector2, decimalPlaces);\n};\n\nexport const isAngleBetween = (angleDegrees: number, startAngleDegrees: number, endAngleDegrees: number) : boolean => {\n const distance = getAnglesSub(startAngleDegrees, endAngleDegrees);\n const distance1 = getAnglesSub(startAngleDegrees, angleDegrees);\n const distance2 = getAnglesSub(endAngleDegrees, angleDegrees);\n const totalDistance = distance1 + distance2;\n\n // Use a small threshold for floating point errors\n return Math.abs(totalDistance - distance) <= 0.001;\n}\n\nexport const isClockwise = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n return angle2Deg >= angle1Deg;\n};\n\n/**\n * Shortest distance (angular) between two angles.\n */\nexport const getAnglesSub = (angleDegrees1: number, angleDegrees2: number, decimalPlaces = Infinity) : number => {\n const angleDistance = Math.abs(mod(angleDegrees1, 360) - mod(angleDegrees2, 360));\n return setDecimalPlaces(angleDistance <= 180 ? angleDistance : 360 - angleDistance, decimalPlaces);\n};\n\nexport const getAnglesDistance = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0, decimalPlaces = Infinity) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n if(isClockwise(angle1Deg, angle2Deg, startAngleDeg)) {\n return setDecimalPlaces((angle2Deg - angle1Deg + 360) % 360, decimalPlaces);\n }\n else{\n return setDecimalPlaces((angle1Deg - angle2Deg + 360) % 360, decimalPlaces);\n }\n};\n\nexport const percentToAngle = (percent: number, startAngleDeg: number, endAngleDeg: number, circleStartAngle = 0) => {\n if(percent < 0) {\n percent = 0;\n }\n\n if(percent > 100) {\n percent = 100;\n }\n\n const distance = getAnglesDistance(startAngleDeg, endAngleDeg, circleStartAngle);\n\n const clockwise = isClockwise(startAngleDeg, endAngleDeg, circleStartAngle);\n if(clockwise) {\n return mod(circleStartAngle + (percent * distance / 100), 360);\n }\n else {\n return mod(circleStartAngle - (percent * distance / 100), 360);\n }\n};", "import { Vector2 } from '../types';\nimport { setDecimalPlaces } from './format';\n\nexport const mod = (n: number, m: number) => {\n return ((n % m) + m) % m;\n};\n\n/**\n * Convert range [a, b] to [c, d].\n * f(x) = (d - c) * (x - a) / (b - a) + c\n */\nexport const convertRange = (x: number, a: number, b: number, c: number, d: number) => {\n return (d - c) * (x - a) / (b - a) + c;\n};\n\n/**\n * Check if 2 ranges [a,b] and [c,d] overlap.\n */\nexport const doRangesOverlap = (a: number, b: number, c: number, d: number) => {\n return Math.max(a, c) <= Math.min(b, d) ;\n};\n\n// eslint-disable-next-line\nexport const isNumber = (value: any) => {\n return !isNaN(parseFloat(value)) && isFinite(value);\n};\n\n/**\n * Convert polar coordinates to cartesian coordinates.\n */\nexport const polarToCartesian = (center: Vector2, radii: Vector2, angleInRad: number, decimalPlaces = Infinity) : Vector2 => {\n const [cx, cy] = center;\n const [rx, ry] = radii;\n\n return [\n setDecimalPlaces(cx + (rx * Math.cos(angleInRad)), decimalPlaces),\n setDecimalPlaces(cy + (ry * Math.sin(angleInRad)), decimalPlaces),\n ];\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector, Vector2, Vector3 } from '../../types';\nimport { vMulScalar, vSum, vSub, vDotProduct, vN, vEqual, vDivideScalar } from './vector';\n\n// --------------- SUM ----------------------\n\nexport const mSum = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sum = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- SUB ----------------------\n\nexport const mSub = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sub = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- MUL SCALAR ----------------------\n\nexport const mMulScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vMulScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2MulScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mMulScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3MulScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mMulScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n// --------------- DIVIDE SCALAR ----------------------\n\nexport const mDivideScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vDivideScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2DivideScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mDivideScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3DivideScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mDivideScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n\n// --------------- TRANSPOSE ----------------------\n\nexport const mTranspose = (m: Matrix): Matrix => {\n\n const vectorsCount = m.length;\n if(vectorsCount <= 0) return m;\n\n const vectorLength = m[0].length;\n if(vectorLength <= 0) return m;\n\n const matrix: Matrix = [];\n for(let i=0; i {\n return mTranspose(m2);\n};\n\nexport const m3Transpose = (m3: Matrix3): Matrix => {\n return mTranspose(m3);\n};\n\n// ----------------- RESET ----------------------\n\nexport const mReset = (m: Matrix, defaultValue = 0): Matrix => {\n\n if(m.length <= 0) return [];\n\n const res: Matrix = [];\n\n for(let i=0; i {\n return mReset(m2, defaultValue) as Matrix2;\n};\n\nexport const m3Reset = (m3: Matrix3, defaultValue = 0): Matrix3 => {\n return mReset(m3, defaultValue) as Matrix3;\n};\n\n// --------------- MATRIX INIT HELPERS -----------------\n\nexport const m2x2 = (defaultValue = 0): Matrix2 => {\n return [\n [defaultValue, defaultValue],\n [defaultValue, defaultValue],\n ];\n};\n\nexport const m3x3 = (defaultValue = 0): Matrix3 => {\n return [\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const m4x4 = (defaultValue = 0): Matrix4 => {\n return [\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const mNxM = (N: number, M: number, defaultValue = 0): Matrix => {\n if(N <= 0 || M <= 0){\n throw new Error('M and N must be positive numbers.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return [\n [1, 0],\n [0, 1],\n ];\n};\n\nexport const identity3 = (): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\nexport const identity4 = (): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Identity Matrix (I).\n * M x I = I x M = M for any matrix M.\n * Identity Matrix is a special case of scale matrix.\n */\nexport const identityN = (N: number): Matrix => {\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n if(N === 0) return [];\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mDeepCopy(m2) as Matrix2;\n};\n\nexport const m3DeepCopy = (m3: Matrix3): Matrix3 => {\n return mDeepCopy(m3) as Matrix3;\n};\n\n// -------------- APPEND / PREPEND ROW OR COLUMN ---------------\n\nexport const mAppendCol = (m: Matrix, col: Vector): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n const copy = mDeepCopy(m);\n copy.push(row);\n return copy;\n};\n\nexport const m2AppendRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.push(row);\n return copy;\n};\n\nexport const m3AppendRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.push(row);\n return copy;\n};\n\nexport const mPrependRow = (m: Matrix, row: Vector) : Matrix => {\n const copy = mDeepCopy(m);\n copy.unshift(row);\n return copy;\n};\n\nexport const m2PrependRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.unshift(row);\n return copy;\n};\n\nexport const m3PrependRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.unshift(row);\n return copy;\n};\n\n// ------------ DELETE ROW OR COLUMN ----------------------------\n\nexport const mDelLastRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.pop();\n return copy;\n};\n\nexport const mDelFirstRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.shift();\n return copy;\n};\n\nexport const mDelLastColumn = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const size = m[0].length;\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n\n const matrix: Matrix = [];\n for(let i=0; i {\n\n if(matrix.length < 0) return [];\n\n if(matrix[0].length !== vector.length){\n throw new Error('The number of columns in the matrix must be equal to the length of the vector.');\n }\n\n const res: Vector = [];\n\n for(let i=0; i {\n if(matrix1.length !== matrix2.length) return false;\n\n for(let i=0; i returns matrix N (m-1 x m-1)\n * The matrix must be square.\n */\nconst mMinorHelper = (m: Matrix, row: number, col: number) => {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // prepare the matrix without provided row and column\n const matrix = mMinorHelper(m, row, col);\n\n // calculate the matrix determinant\n return mDeterminant(matrix);\n};\n\n/**\n * Calculate determinant for NxN matrix.\n * Matrix should be square.\n */\nexport const mDeterminant = (matrix: Matrix): number => {\n const size = matrix.length;\n if(size === 0) return 1;\n\n if(size !== matrix[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return matrix[0][0];\n if(size === 2) return m2Determinant(matrix as Matrix2);\n\n let d = 0;\n\n for(let i=0; i {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return m2[0][0] * m2[1][1] - m2[1][0] * m2[0][1];\n};\n\n/**\n * Calculate determinant for 3x3 matrix.\n * Matrix should be square.\n */\nexport const m3Determinant = (m3: Matrix3): number => {\n if(m3.length !== m3[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return mDeterminant(m3);\n};\n\n// ------------------ INVERSE -----------------------\n\nexport const m2Adjugate = (m2: Matrix2): Matrix2|null => {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return [\n [m2[1][1], -m2[0][1]],\n [-m2[1][0], m2[0][0]],\n ];\n};\n\nexport const m3Adjugate = (m3: Matrix3) : Matrix3|null => {\n return mAdjugate(m3) as (Matrix3|null);\n};\n\n/**\n * Adjugate is a transpose of a cofactor matrix\n */\nexport const mAdjugate = (m: Matrix): Matrix|null => {\n\n const size = m.length;\n if(size <= 0) return null;\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return m;\n\n if(size === 2) return m2Adjugate(m as Matrix2);\n\n // build a cofactor matrix ----------------\n const cofactors: Matrix = [];\n\n for(let i=0; i {\n if(m.length > 0 && m.length !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = mDeterminant(m);\n return d === 0;\n};\n\n/**\n * Square matrix A (nxn) is invertible is there is another square matrix B (nxn) so AxB = BxA = I\n * For A (2x2) matrix, the inverse is:\n * (1 / (determinant(A))) * adj(A)\n */\nexport const m2Inverse = (m2: Matrix2, decimalPlaces = Infinity): (Matrix2 | null) => {\n if(m2.length > 0 && m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = m2Determinant(m2);\n if(d === 0) return null;\n\n const adj = m2Adjugate(m2);\n if(adj === null) return null;\n\n return m2DivideScalar(adj, d, decimalPlaces);\n};\n\nexport const m3Inverse = (m3: Matrix3, decimalPlaces = Infinity): (Matrix3 | null) => {\n return mInverse(m3, decimalPlaces) as (Matrix3|null);\n};\n\nexport const mInverse = (m: Matrix, decimalPlaces = Infinity): (Matrix | null) => {\n const size = m.length;\n\n if(size > 0 && size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // find a determinant ----------------------\n const d = mDeterminant(m);\n\n // find an Adjugate - a transpose of a cofactor matrix\n const adj = mAdjugate(m);\n if(adj === null) return null;\n\n return mDivideScalar(adj, d, decimalPlaces);\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector2, Vector3, Vector4 } from '../../types';\nimport { v2Normalize, v3MulScalar, v3Normalize } from './vector';\nimport { mMulVector, mMul } from './matrix';\nimport { setDecimalPlaces } from '../format';\n\n/*\nAny 2D affine transformation can be decomposed\ninto a rotation, followed by a scaling, followed by a\nshearing, and followed by a translation.\n---------------------------------------------------------\nAffine matrix = translation x shearing x scaling x rotation\n */\n\n// ----------------- CSS -------------------------------------\n\n/**\n * Matrix 2D in non-homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2ToCSS = (m: Matrix2) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, 0, 0)`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2hToCSS = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ tx }, ${ ty })`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m2hToCSS3d = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix3d(${ a }, ${ b }, 0, 0, ${ c }, ${ d }, 0, 0, 0, 0, 1, 0, ${ tx }, ${ ty }, 0, 1)`;\n};\n\n/**\n * Matrix 3D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m3hToCSS3d = (m: Matrix4) : string => {\n\n return `matrix3d(\n ${ m[0][0] }, ${ m[0][1] }, ${ m[0][2] }, ${ m[0][3] },\n ${ m[1][0] }, ${ m[1][1] }, ${ m[1][2] }, ${ m[1][3] },\n ${ m[2][0] }, ${ m[2][1] }, ${ m[2][2] }, ${ m[2][3] },\n ${ m[3][0] }, ${ m[3][1] }, ${ m[3][2] }, ${ m[3][3] }\n )`;\n};\n\n// ---------------- TRANSLATION MATRICES ----------------------\n\nexport const m2Translation = (position: Vector2, decimalPlaces = Infinity): Matrix2 => {\n\n return [\n [1, 0],\n [0, 1],\n [setDecimalPlaces(position[0], decimalPlaces), setDecimalPlaces(position[1], decimalPlaces)],\n ];\n};\n\nexport const m3Translation = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n [\n setDecimalPlaces(position[0], decimalPlaces),\n setDecimalPlaces(position[1], decimalPlaces),\n setDecimalPlaces(position[2], decimalPlaces)\n ],\n ];\n};\n\n/**\n * 2D Translation matrix in homogeneous coordinates.\n */\nexport const m2TranslationH = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1],\n ];\n};\n\n/**\n * 3D Translation matrix in homogeneous coordinates.\n */\nexport const m3TranslationH = (position: Vector4, decimalPlaces = Infinity): Matrix4 => {\n\n return [\n [1, 0, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, 0, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1, setDecimalPlaces(position[2], decimalPlaces)],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- ROTATION MATRICES -------------------------\n\n/**\n * Rotation of an angle about the origin.\n */\nexport const m2Rotation = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix2 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin],\n [sin, cos],\n ] :\n [\n [cos, sin],\n [-sin, cos],\n ];\n};\n\n/**\n * Rotation of an angle about the origin in homogeneous coordinates (clockwise).\n */\nexport const m2RotationH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ]:\n [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation of an angle \"angleRad\" around the given point (transformOrigin) in homogeneous coordinates (clockwise).\n * result_vector = TranslationMatrix(x, y) * RotationMatrix() * TranslationMatrix(-x, -y) * position_vector\n */\nexport const m2RotationAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const rotation = m2RotationH(angleRad, isClockwise, decimalPlaces);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, rotation);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2RotateAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n position: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2RotationAroundPointH(angleRad, transformOrigin, isClockwise, decimalPlaces);\n return mMulVector(mat3h, position) as Vector3;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2Rotate = (angleRad: number, vector: Vector2, isClockwise = true, decimalPlaces = Infinity): Vector2 => {\n const unitVector = v2Normalize(vector);\n return mMulVector(m2Rotation(angleRad, isClockwise, decimalPlaces), unitVector) as Vector2;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2RotateH = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m2RotationH(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the X axis (clockwise).\n */\nexport const m3RotationX = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0],\n [0, cos, -sin],\n [0, sin, cos],\n ] :\n [\n [1, 0, 0],\n [0, cos, sin],\n [0, -sin, cos],\n ];\n};\n\n/**\n * Rotation around the X axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationXH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0, 0],\n [0, cos, -sin, 0],\n [0, sin, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [1, 0, 0, 0],\n [0, cos, sin, 0],\n [0, -sin, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateX = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationX(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Y axis (clockwise).\n */\nexport const m3RotationY = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin],\n [0, 1, 0],\n [-sin, 0, cos],\n ] :\n [\n [cos, 0, -sin],\n [0, 1, 0],\n [sin, 0, cos],\n ];\n};\n\n/**\n * Rotation around the Y axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationYH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin, 0],\n [0, 1, 0, 0],\n [-sin, 0, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [cos, 0, -sin, 0],\n [0, 1, 0, 0],\n [sin, 0, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateY = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationY(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Z axis (clockwise).\n */\nexport const m3RotationZ = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ] : [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation around the Z axis (clockwise)- in homogeneous coordinates\n */\nexport const m3RotationZH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0, 0],\n [sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ] : [\n [cos, sin, 0, 0],\n [-sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateZ = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationZ(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n// ---------------- SCALE MATRICES -------------\n\n/**\n * Get matrix for arbitrary scaling pivot point.\n * result_vector = TranslationMatrix(x, y) * ScaleMatrix() * TranslationMatrix(-x, -y) * scale_vector\n */\nexport const m2ScaleAtPointHMatrix = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const scale = m2ScaleH(scaleVector);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, scale);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2ScaleAtPointH = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n point: Vector3,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2ScaleAtPointHMatrix(scaleVector, transformOrigin, decimalPlaces);\n return mMulVector(mat3h, point) as Vector3;\n};\n\nexport const m2Scale = (scaleVector: Vector2): Matrix2 => {\n return [\n [scaleVector[0], 0],\n [0, scaleVector[1]],\n ];\n};\n\nexport const v2Scale = (scaleVector: Vector2, vector: Vector2): Vector2 => {\n return mMulVector(m2Scale(scaleVector), vector) as Vector2;\n};\n\n/**\n * homogeneous coordinates\n */\nexport const m2ScaleH = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, 1],\n ];\n};\n\nexport const m3Scale = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, scaleVector[2]],\n ];\n};\n\nexport const m3ScaleH = (scaleVector: Vector4): Matrix4 => {\n return [\n [scaleVector[0], 0, 0, 0],\n [0, scaleVector[1], 0, 0],\n [0, 0, scaleVector[2], 0],\n [0, 0, 0, 1]\n ];\n};\n\nexport const v3Scale = (scaleVector: Vector3, vector: Vector3): Vector3 => {\n return mMulVector(m3Scale(scaleVector), vector) as Vector3;\n};\n\n/**\n * Stretch, parallel to the x-axis.\n */\nexport const m2ScaleX = (scale: number): Matrix2 => {\n return [\n [scale, 0],\n [0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the x-axis - homogeneous coordinates\n */\nexport const m2ScaleXH = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleX = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleXH = (scale: number): Matrix4 => {\n return [\n [scale, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleY = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleYH = (scale: number): Matrix => {\n return [\n [1, 0, 0, 0],\n [0, scale, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZ = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, scale],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZH = (scale: number): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, scale, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis.\n */\nexport const m2ScaleY = (scale: number): Matrix2 => {\n return [\n [1, 0],\n [0, scale],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis - homogeneous coordinates\n */\nexport const m2ScaleYH = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n// ---------------- REFLECTION MATRICES -------------------------\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOrigin = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOriginH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection about the origin in non-homogeneous coordinates\n */\nexport const m3ReflectionOrigin = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection about the origin in homogeneous coordinates\n */\nexport const m3ReflectionOriginH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection about y=-x\n */\nexport const m2ReflectionYmX = (): Matrix2 => {\n\n return [\n [0, -1],\n [-1, 0],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionX = (): Matrix2 => {\n\n return [\n [1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionXH = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection in the y-axis.\n */\nexport const m2ReflectionY = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, 1],\n ];\n};\n\nexport const m2ReflectionYH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionYZ = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in homogeneous coordinates\n */\nexport const m3ReflectionYZH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXZ = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in homogeneous coordinates\n */\nexport const m3ReflectionXZH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXY = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in homogeneous coordinates\n */\nexport const m3ReflectionXYH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- SHEARING MATRICES -------------------------\n\n\n/**\n * Shearing in y-axis, with x-axis fixed with (0,1) moving to (factor, 1)\n */\nexport const m2ShearingY = (factor: number): Matrix2 => {\n\n return [\n [1, factor],\n [0, 1],\n ];\n};\n\n/**\n * Shearing in x-axis, with y-axis fixed with (1,0) moving to (1, factor)\n */\nexport const m2ShearingX = (factor: number): Matrix2 => {\n\n return [\n [1, 0],\n [factor, 1],\n ];\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a random number in the [min,max] range.\n */\nexport const getRandom = (min: number, max: number, decimalPlaces = Infinity): number => {\n return setDecimalPlaces(Math.random() * (max - min) + min, decimalPlaces);\n};\n\n/**\n * Returns a random integer number in the [min,max] range.\n */\nexport const getRandomInt = (min: number, max: number): number => {\n return Math.floor(Math.random() * (max - min + 1) + min);\n};\n\nexport const getRandomBoolean = () => Math.random() < 0.5;\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getRandomItemFromArray = (array: any[]) => {\n const randomIndex = getRandomInt(0, array.length - 1);\n return array[randomIndex];\n};", "export const stringToNumber = (value: string|undefined|null|number, defaultNumber: number) => {\n if(value === undefined || value === null) return defaultNumber;\n const res = Number(value) ?? defaultNumber;\n return isNaN(res) ? defaultNumber : res;\n};", "import { IBBox, Vector, Vector2, Vector3 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport {\n dxV2CubicBezierCurve,\n dxV2QuadraticBezierCurve,\n dxV3CubicBezierCurve,\n dxV3QuadraticBezierCurve\n} from '../derivative';\nimport { v2Normalize, v3Normalize } from '../linear-algebra/vector';\nimport { linearEquation } from '../equations/linear-equations';\nimport { quadraticEquation } from '../equations/quadratic-equations';\nimport { isNumber } from '../other';\n\n/**\n * B\u00E9zier Curves\n * quadratic: y = P1 * (1-t)\u00B2 + P2 * 2 * (1-t)t + P3 * t\u00B2\n * t in range [0, 1]\n */\n\n// -------------------- GET POINT ON CURVE --------------------------\n\n/**\n * Get a point on a quadratic B\u00E9zier curve as a function of time.\n */\nexport const v2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n/**\n * Get a point on a cubic B\u00E9zier curve as a function of time.\n */\nexport const v2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n// -------------------- TANGENT --------------------------\n\n/**\n * Tangent indicates the direction of travel at specific points along the B\u00E9zier curve,\n * and is literally just the first derivative of our curve.\n */\nexport const v2QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\nexport const v2CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\n// -------------------- NORMAL --------------------------\n\n/**\n * Normal is a vector that runs at a right angle to the direction of the curve, and is typically of length 1.\n * To find it, we take the normalised tangent vector, and then rotate it by a 90 degrees.\n */\nexport const v2QuadraticBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2QuadraticBezierCurveTangent(t, startControlPoint, centerControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\nexport const v2CubicBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2CubicBezierCurveTangent(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\n// -------------------- EXTREMA --------------------------\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2QuadraticBezierCurveExtrema = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector => {\n\n /*\n (-2 * (1 - t)) * startControlPoint[0] + (2 - 4 * t) * centerControlPoint[0] + (2 * t) * endControlPoint[0]\n 2 * t * startControlPoint[0] - 4 * t * centerControlPoint[0] + 2 * t * endControlPoint[0] - 2 * startControlPoint[0] + 2 * centerControlPoint[0]\n t * (2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0]) + (- 2 * startControlPoint[0] + 2 * centerControlPoint[0])\n */\n\n const a1 = 2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0];\n const b1 = -2 * startControlPoint[0] + 2 * centerControlPoint[0];\n const equation1: Vector3 = [a1, b1, 0];\n const res1 = linearEquation(equation1, decimalPlaces);\n\n const a2 = 2 * startControlPoint[1] - 4 * centerControlPoint[1] + 2 * endControlPoint[1];\n const b2 = -2 * startControlPoint[1] + 2 * centerControlPoint[1];\n const equation2: Vector3 = [a2, b2, 0];\n const res2 = linearEquation(equation2, decimalPlaces);\n\n const res: Vector = [];\n\n if(isNumber(res1)){\n res.push(res1);\n }\n\n if(isNumber(res2)){\n res.push(res2);\n }\n\n return res;\n};\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2CubicBezierCurveExtrema = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2|null => {\n\n const a1 = -3 * startControlPoint[0] + 9 * center1ControlPoint[0] - 9 * center2ControlPoint[0] + 3 * endControlPoint[0];\n const b1 = 6 * startControlPoint[0] - 12 * center1ControlPoint[0] + 6 * center2ControlPoint[0];\n const c1 = -3 * startControlPoint[0] + 3 * center1ControlPoint[0];\n const equation1: Vector = [a1, b1, c1, 0];\n\n const a2 = -3 * startControlPoint[1] + 9 * center1ControlPoint[1] - 9 * center2ControlPoint[1] + 3 * endControlPoint[1];\n const b2 = 6 * startControlPoint[1] - 12 * center1ControlPoint[1] + 6 * center2ControlPoint[1];\n const c2 = -3 * startControlPoint[1] + 3 * center1ControlPoint[1];\n const equation2: Vector = [a2, b2, c2, 0];\n\n // Any value between 0 and 1 is a root that matters for B\u00E9zier curves, anything below or above that is irrelevant (because B\u00E9zier curves are only defined over the interval [0,1]).\n const res1 = quadraticEquation(equation1, decimalPlaces).filter(num => num >= 0 && num <= 1);\n const res2 = quadraticEquation(equation2, decimalPlaces).filter(num => num >= 0 && num <= 1);\n\n const res = [...res1, ...res2];\n if(res.length === 2){\n return [...res1, ...res2] as Vector2;\n }\n\n return null;\n};\n\n// -------------------- BOUNDING BOX --------------------------\n\nexport const v2QuadraticBezierBBox = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2QuadraticBezierCurveExtrema(startControlPoint, centerControlPoint, endControlPoint);\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2QuadraticBezierCurve(percent, startControlPoint, centerControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\nexport const v2CubicBezierBBox = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2CubicBezierCurveExtrema(startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint) || [];\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2CubicBezierCurve(percent, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x ?? Infinity);\n maxX = Math.max(maxX, x ?? -Infinity);\n\n minY = Math.min(minY, y ?? Infinity);\n maxY = Math.max(maxY, y ?? -Infinity);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\n\n", "import { setDecimalPlaces } from './format';\nimport { Vector2, Vector3 } from '../types';\n\n/**\n * u(x) and v(x) are functions ---------->\n *\n * dx(u + v) = dx(u) + dx(v)\n * dx(u - v) = dx(u) - dx(v)\n * dx(u * v) = dx(u) * v + u * dx(v)\n * dx(u / v) = (dx(u) * v - u * dx(v)) / (v ^ 2), when v(x) != 0\n */\n\n// ------------------ Derivatives of Polynomial ---------------------------\n\n/**\n * y = 3x+2\n * dxPolynomial(10, [[3, 1], [2, 0]])\n */\nexport const dxPolynomial = (x: number, polynomial: number[][], decimalPlaces = Infinity) => {\n let res = 0;\n\n for(const part of polynomial){\n if(part.length !== 2) return NaN;\n\n const coeff = part[0];\n const power = part[1];\n res += coeff * power * Math.pow(x, power - 1);\n }\n\n return setDecimalPlaces(res, decimalPlaces);\n}\n\n// ---------------------- Bezier Curves ---------------------------\n\n/**\n * Derivative of Bezier Curve is another Bezier Curve.\n * t must min in range [0, 1]\n */\nexport const dxV2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n // The derivative: P1 * (2t-2) + (2*P3-4*P2) * t + 2 * P2\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\nexport const dxV2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n\n// ----------------- Derivatives of trigonometry functions ---------------------------\n\nexport const dxSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(Math.cos(x), decimalPlaces);\n};\n\nexport const dxCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-Math.sin(x), decimalPlaces);\n};\n\nexport const dxTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.cos(x) ** 2), decimalPlaces);\n};\n\n/**\n * x != Math.PI * n, where n is an integer\n */\nexport const dxCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sin(x) ** 2), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\nexport const dxArcTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (1 + x ** 2), decimalPlaces);\n};\n\nexport const dxArcCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (1 + x ** 2), decimalPlaces);\n};\n", "import { Matrix, Matrix2, Matrix3, Vector, Vector2, Vector3 } from '../../types';\nimport { m2Inverse, m3Inverse, mInverse, mMulVector, mDelLastColumn, mGetLastColumn } from '../linear-algebra/matrix';\nimport { setDecimalPlaces } from '../format';\nimport { v2Sub } from '../linear-algebra/vector';\n\n/**\n * Linear equation\n * ax + b = c\n * x = (c - b) / a; a != 0\n */\nexport const linearEquation = (equation: Vector3, decimalPlaces = Infinity) : number => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n\n const diff = c - b;\n\n if(a === 0 && diff === 0) return Infinity; // any number is a solution\n if(a === 0) return NaN; // no solution\n\n return setDecimalPlaces(diff / a, decimalPlaces);\n};\n\n/**\n * System of 2 linear equations.\n * [x, y] = inverse(Matrix of equation parameters) x (vector of equation results)\n * ---------------\n * 3x + 2y = 7\n * -6x + 6y = 6\n */\nexport const linearEquationSystem2 = (equation1: Vector3, equation2: Vector3, decimalPlaces = Infinity) : Vector2 | null => {\n const equationParams: Matrix2 = [\n [equation1[0], equation1[1]],\n [equation2[0], equation2[1]],\n ];\n\n const inversed = m2Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector2 = [\n equation1[2],\n equation2[2]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector2;\n};\n\n/**\n * System of 3 linear equations.\n * ---------------------------------------\n * 3x + 2y + 5z = 7\n * -6x + 6y + 6z = 6\n * 2x + 7y - z = 4\n */\nexport const linearEquationSystem3 = (\n equation1: Vector,\n equation2: Vector,\n equation3: Vector,\n decimalPlaces = Infinity) : Vector3 | null => {\n const equationParams: Matrix3 = [\n [equation1[0], equation1[1], equation1[2]],\n [equation2[0], equation2[1], equation2[2]],\n [equation3[0], equation3[1], equation3[2]],\n ];\n\n const inversed = m3Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector3 = [\n equation1[3],\n equation2[3],\n equation3[3]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector3;\n};\n\n/**\n * System of N linear equations.\n */\nexport const linearEquationSystemN = (equations: Matrix, decimalPlaces = Infinity) : Vector | null => {\n if(equations.length <= 0) return null;\n\n const equationParams = mDelLastColumn(equations);\n\n const inversed = mInverse(equationParams);\n if(inversed === null) return null; // no results\n\n // the last column of the equations matrix\n const equationResults = mGetLastColumn(equations);\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector;\n};\n\n/**\n * Calculate the equation of a line given two points in a 2D space.\n * y = ax + b\n * y - y1 = m(x - x1)\n * m = (y2 - y1) / (x2 - x1)\n */\nexport const getLinearEquationBy2Points = (point1: Vector2, point2: Vector2) : {\n slope: number|undefined,\n yIntercept: number|undefined,\n xIntercept: number|undefined,\n formula: string,\n} => {\n const [deltaX, deltaY] = v2Sub(point2, point1);\n const [x, y] = point1;\n\n if(deltaX === 0) {\n return {\n slope: undefined,\n xIntercept: x,\n yIntercept: undefined,\n formula: `x = ${ x }`,\n };\n }\n\n const m = deltaY / deltaX;\n const b = y - m * x;\n let formula = '';\n\n if(m === 0) {\n formula = `y = ${ b }`;\n }\n else{\n formula = `y = ${ m === 1 ? '' : m }x`;\n\n if(b !== 0) {\n formula += ` ${ b < 0 ? '-' : '+' } ${ Math.abs(b) }`;\n }\n }\n\n return {\n slope: m,\n xIntercept: undefined,\n yIntercept: b,\n formula,\n };\n};", "import { Vector } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { linearEquation } from './linear-equations';\nimport { isNumber } from '../other';\n\n/**\n * Quadratic Equation.\n * ax^2 + bx + c = d\n */\nexport const quadraticEquation = (equation: Vector, decimalPlaces = Infinity) : Vector => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n const d = equation[3];\n\n if(a === 0){\n // it's a linear equation -------------------------------------------\n const res = linearEquation([b, c, d], decimalPlaces);\n if(isNumber(res)) return [res];\n return [];\n }\n\n const diff = c - d;\n\n const discriminant = b * b - (4 * a * diff);\n\n if(discriminant < 0){\n return []; // no results\n }\n\n if(discriminant === 0){\n return [ setDecimalPlaces(-b / (2 * a), decimalPlaces) ]; // 1 result\n }\n\n // if(determinant > 0) ---> 2 results\n const t1 = 2 * a;\n const t2 = Math.sqrt(discriminant);\n\n return [\n setDecimalPlaces((-b + t2) / t1, decimalPlaces),\n setDecimalPlaces((-b - t2) / t1, decimalPlaces),\n ];\n};", "import { Vector2 } from '../types';\nimport { v2Sub } from './linear-algebra/vector';\nimport { getV2Angle } from './angle';\nimport { convertRange } from './other';\n\n/**\n * Circle Equation\n * x^2 + y^2 = radius^2\n * ----------------------\n * Circle Parametric Equation\n * x(t) = radius * cos(t)\n * y(t) = radius * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const circleMovement = (center: Vector2, angle: number, radius: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius,\n center[1] + Math.sin(angle) * radius\n ];\n};\n\n/**\n * Circle Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const circleMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radius: number\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return circleMovement(center, angle, radius);\n};\n\n/**\n * Ellipse Equation\n * (x - centerX)^2 / (radius1^2) + (y - centerY)^2 / (radius2^2) = 1\n * -----------------------------------------------------------------\n * Ellipse Parametric Equation\n * x(t) = radius1 * cos(t)\n * y(t) = radius2 * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const ellipseMovement = (center: Vector2, angle: number, radius1: number, radius2: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius1,\n center[1] + Math.sin(angle) * radius2\n ];\n};\n\n/**\n * Ellipse Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const ellipseMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radii: Vector2\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return ellipseMovement(center, angle, radii[0], radii[1]);\n};\n\n/**\n * Sine Wave Equation (Sinusoid)\n * -----------------------------\n * const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n * amplitude = the peak deviation of the function from zero\n * frequency = number of cycles\n * phase = specifies (in radians) where in its cycle the oscillation is at t = 0.\n * think of it as \"shifting\" the starting point of the function to the right (positive p) or left (negative)\n */\nexport const sineWaveMovement = (x: number, amplitude: number, frequency: number, phase: number) : Vector2 => {\n /*\n example values:\n const amplitude = 50;\n const frequency = 0.005;\n const phase = 0;\n x: [0, 1000]\n */\n const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n\n return [x, y];\n};\n\n/**\n * Lissajous curve (Lissajous figure or Bowditch curve)\n * Parametric equation #1\n * f(t) = A * sin(k * t + m)\n * f(t) = B * sin(n * t)\n * 0 <= m <= PI/2\n * k, n >= 1\n * -----------------------\n * Parametric equation #2\n * f(t) = A * cos(k * t - m)\n * f(t) = B * cos(n * t - p)\n * -----------------------------\n * Shapes:\n * k = 1, n = 1, m = 0, p = 0 ---> line\n * A = B, k = 1, n = 1, m = PI/2, p = PI/2 ----> circle\n * A != B, k = 1, n = 1, m = PI/2, p = PI/2 ----> ellipse\n * k = 2, n = 2, m = PI/2, p = PI/2 ----> section of a parabola\n */\nexport const lissajousCurve = (\n width: number,\n height: number,\n t: number,\n k: number,\n n: number,\n m: number,\n p: number\n) :Vector2 => {\n return [\n width * Math.cos(k * t - m),\n height * Math.cos(n * t - p),\n ];\n};\n", "import { getRandom } from './random';\nimport { HSLColor, LABColor, RGBColor } from '../types';\nimport { mod } from './other';\nimport { setDecimalPlaces } from './format';\n\n// ------------------------ RANDOM COLOR -------------------------------------\n\nexport const getRandomRGBColor = () : RGBColor => {\n const hslColor = getRandomHSLColor();\n return hslToRgb(hslColor);\n};\n\nexport const getRandomHexColor = () : string => {\n const hslColor = getRandomHSLColor();\n return hslToHex(hslColor);\n};\n\nexport const getRandomHSLColor = () : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given hue\n */\nexport const getRandomHSLColorWithHue = (h: number) : HSLColor => {\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given saturation\n */\nexport const getRandomHSLColorWithSaturation = (s: number) : HSLColor => {\n const h = getRandom(1, 360);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given lightness\n */\nexport const getRandomHSLColorWithLightness = (l: number) : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n return [h, s, l];\n};\n\nexport const getRandomGrayscaleHSLColor = () : HSLColor => {\n const l = getRandom(0, 100);\n return [0, 0, l];\n};\n\nexport const getRandomHSLColorWithinRanges = (\n hueStart = 1, hueEnd = 360,\n saturationStart = 0, saturationEnd = 100,\n lightStart = 0, lightEnd = 100\n) : HSLColor => {\n const h = getRandom(hueStart, hueEnd);\n const s = getRandom(saturationStart, saturationEnd);\n const l = getRandom(lightStart, lightEnd);\n return [h, s, l];\n};\n\n// ----------------------- CONVERT COLORS --------------------------------------\n\n/**\n * helper: convert hue value to degrees.\n * @param {number} h\n * @return {number} [0, 360] degrees\n */\nconst convertHueToDegrees = (h : number) : number => {\n\n // the hue value needs to be multiplied by 60 to convert it to degrees\n h *= 60;\n\n // if hue becomes negative, you need to add 360 to, because a circle has 360 degrees\n if(h < 0){\n h += 360;\n }\n\n return h;\n // convert huw to %\n // return h * 100 / 360;\n};\n\n/**\n * get hue from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] % - we use here % instead of [0, 359] degrees\n */\nconst getHue = (r : number, g : number, b : number, min : number | undefined = undefined, max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (max === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no hue, as it's gray\n if(min === max) return 0;\n\n const diff = max - min;\n\n let h = 0;\n\n // if red is max\n if(max === r){\n h = (g - b) / diff + (g < b ? 6 : 0);\n }\n\n // if green is max\n if(max === g){\n h = 2 + (b - r) / diff;\n }\n\n // if blue is max\n if(max === b){\n h = 4 + (r - g) / diff;\n }\n\n return convertHueToDegrees(h);\n};\n\n/**\n * get luminance from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] %\n */\nconst getLuminance = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // calculate the luminance value\n // @ts-ignore\n const l = (min + max) / 2; // [0, 1]\n\n // return l value in %\n return l * 100;\n};\n\n/**\n * get saturation from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @param {number|undefined=} l - luminance in [0, 100] %\n * @return {number} [0, 100] %\n */\nconst getSaturation = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined,\n l : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no saturation, as it's gray\n if(min === max) return 0;\n\n // calculate luminance if it's not provided\n l = (l === undefined) ? getLuminance(r, g, b) : l;\n\n // check the level of luminance\n const s = (l <= 50) ?\n // @ts-ignore\n ((max - min) / (max + min)) : // this formula is used when luminance <= 50%\n // @ts-ignore\n (max - min) / (2.0 - max - min); // this formula is used when luminance > 50%\n\n // return saturation in %\n return s * 100;\n};\n\nexport const rgbToHsl = (rgb: RGBColor, decimalPlaces = Infinity): HSLColor => {\n\n // convert rgb values to the range [0, 1]\n const r = rgb[0] / 255;\n const g = rgb[1] / 255;\n const b = rgb[2] / 255;\n\n // find the minimum and maximum values of r, g, and b\n const min = Math.min(r, g, b);\n const max = Math.max(r, g, b);\n\n // calculate the luminance value in %\n const l = getLuminance(r, g, b, min, max);\n\n // calculate the saturation in %\n const s = getSaturation(r, g, b, min, max, l);\n\n // calculate the hue in % (not in degrees!)\n const h = getHue(r, g, b, min, max);\n\n if(h > 360 || s > 100 || l > 100){\n return [0, 0, 100];\n }\n\n if(h < 0 || s < 0 || l < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(h, decimalPlaces),\n setDecimalPlaces(s, decimalPlaces),\n setDecimalPlaces(l, decimalPlaces),\n ];\n};\n\n/**\n * helper: HSL to RGB\n */\nconst hslToRgbHelper = (helper1 : number, helper2 : number, colorHelper : number) : number => {\n\n // all values need to be between 0 and 1\n // if you get a negative value you need to add 1 to it\n if(colorHelper < 0) colorHelper += 1;\n\n // if you get a value above 1 you need to subtract 1 from it.\n if(colorHelper > 1) colorHelper -= 1;\n\n if(colorHelper * 6 < 1) return helper2 + (helper1 - helper2) * 6 * colorHelper;\n\n if(colorHelper * 2 < 1) return helper1;\n\n if(colorHelper * 3 < 2){\n return helper2 + (helper1 - helper2) * (0.666 - colorHelper) * 6;\n }\n else{\n return helper2;\n }\n};\n\nexport const hslToRgb = (hsl: HSLColor, decimalPlaces = Infinity): RGBColor => {\n\n // convert all values to [0, 1] from %\n const h = hsl[0] / 100;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n // if there is no saturation -> it\u2019s grey\n if(s === 0){\n // convert the luminance from [0, 1] to [0, 255]\n const gray = l * 255;\n return [gray, gray, gray];\n }\n\n // check the level of luminance\n const helper1 = (l < 0.5) ?\n (l * (1.0 + s)) :\n (l + s - l * s);\n\n const helper2 = 2 * l - helper1;\n\n const rHelper = h + 0.333;\n const gHelper = h;\n const bHelper = h - 0.333;\n\n let r = hslToRgbHelper(helper1, helper2, rHelper);\n let g = hslToRgbHelper(helper1, helper2, gHelper);\n let b = hslToRgbHelper(helper1, helper2, bHelper);\n\n // convert rgb to [0, 255]\n r *= 255;\n g *= 255;\n b *= 255;\n\n if(r > 255 || g > 255 || b > 255){\n return [255, 255, 255];\n }\n\n if(r < 0 || g < 0 || b < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(r, decimalPlaces),\n setDecimalPlaces(g, decimalPlaces),\n setDecimalPlaces(b, decimalPlaces),\n ];\n};\n\n/**\n * HSL to hex\n * hslToHex(360, 100, 50) // [360, 100, 5] ==> \"#ff0000\" (red)\n */\nexport const hslToHex = (hsl: HSLColor) => {\n\n if(hsl[0] > 360 || hsl[1] > 100 || hsl[2] > 100){\n return '#ffffff';\n }\n\n if(hsl[0] < 0 || hsl[1] < 0 || hsl[2] < 0){\n return '#000000';\n }\n\n const h = hsl[0] / 360;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n let r, g, b;\n if (s === 0) {\n r = g = b = l; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n r = hue2rgb(p, q, h + 1 / 3);\n g = hue2rgb(p, q, h);\n b = hue2rgb(p, q, h - 1 / 3);\n }\n const toHex = (x: number) => {\n const hex = Math.round(x * 255).toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n};\n\n/**\n * RGB to HEX\n * rgbToHex([235, 64, 52]) // #eb4034\n */\nexport const rgbToHex = (rgb: RGBColor) => {\n const [r, g, b] = rgb;\n return '#' + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);\n};\n\nexport const hexToRgb = (hex: string) : RGBColor | null => {\n\n const shorthandRegex = /^#?([a-f\\d])([a-f\\d])([a-f\\d])$/i;\n const _hex = hex.replace(shorthandRegex, (_m, r, g, b) => {\n return r + r + g + g + b + b;\n });\n\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(_hex);\n if(!result) return null;\n\n const r = parseInt(result[1], 16);\n const g = parseInt(result[2], 16);\n const b = parseInt(result[3], 16);\n\n return [r, g, b];\n};\n\nexport const rgbToLab = (rgb: RGBColor, decimalPlaces = Infinity) : LABColor => {\n\n let r = rgb[0] / 255;\n let g = rgb[1] / 255;\n let b = rgb[2] / 255;\n\n r = (r > 0.04045) ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;\n g = (g > 0.04045) ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;\n b = (b > 0.04045) ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;\n\n let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;\n let y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;\n let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;\n\n x = (x > 0.008856) ? Math.pow(x, 1/3) : (7.787 * x) + 16/116;\n y = (y > 0.008856) ? Math.pow(y, 1/3) : (7.787 * y) + 16/116;\n z = (z > 0.008856) ? Math.pow(z, 1/3) : (7.787 * z) + 16/116;\n\n return [\n setDecimalPlaces((116 * y) - 16, decimalPlaces),\n setDecimalPlaces(500 * (x - y), decimalPlaces),\n setDecimalPlaces(200 * (y - z), decimalPlaces),\n ];\n};\n\nexport const labToRgb = (lab: LABColor, decimalPlaces = Infinity) : RGBColor => {\n let y = (lab[0] + 16) / 116;\n let x = lab[1] / 500 + y;\n let z = y - lab[2] / 200;\n\n x = 0.95047 * ((x * x * x > 0.008856) ? x * x * x : (x - 16/116) / 7.787);\n y = 1.00000 * ((y * y * y > 0.008856) ? y * y * y : (y - 16/116) / 7.787);\n z = 1.08883 * ((z * z * z > 0.008856) ? z * z * z : (z - 16/116) / 7.787);\n\n let r = x * 3.2406 + y * -1.5372 + z * -0.4986;\n let g = x * -0.9689 + y * 1.8758 + z * 0.0415;\n let b = x * 0.0557 + y * -0.2040 + z * 1.0570;\n\n r = (r > 0.0031308) ? (1.055 * Math.pow(r, 1/2.4) - 0.055) : 12.92 * r;\n g = (g > 0.0031308) ? (1.055 * Math.pow(g, 1/2.4) - 0.055) : 12.92 * g;\n b = (b > 0.0031308) ? (1.055 * Math.pow(b, 1/2.4) - 0.055) : 12.92 * b;\n\n return [\n setDecimalPlaces(Math.max(0, Math.min(1, r)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, g)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, b)) * 255, decimalPlaces),\n ];\n};\n\n// ----------------------- GET SHIFTED COLORS --------------------------------------\n\nexport const getShiftedHue = (color: HSLColor, shift = 180) : HSLColor => {\n let hue = color[0];\n hue += shift;\n\n if (hue > 360 || hue < 0) {\n hue = mod(hue, 360);\n }\n\n return [hue, color[1], color[2]];\n};\n\nexport const getShiftedLightness = (color: HSLColor, shift = 10) : HSLColor => {\n let lightness = color[2];\n lightness += shift;\n\n if (lightness > 100 || lightness < 0) {\n lightness = mod(lightness, 100);\n }\n\n return [color[0], color[1], lightness];\n};\n\nexport const getShiftedSaturation = (color: HSLColor, shift = 10) : HSLColor => {\n let saturation = color[1];\n saturation += shift;\n\n if (saturation > 100) {\n saturation -= 100;\n }\n\n if(saturation < 0){\n saturation += 100;\n }\n\n return [color[0], saturation, color[2]];\n};\n\n// ----------------------- SIMILAR COLORS --------------------------------------\n\n/**\n * Measure the perceptual difference between two RGB colors using the CIE76 color difference formula:\n * delta = Math.sqrt((L2 - L1)^2 + (a2 - a1)^2 + (b2 - b1)^2)\n * https://en.wikipedia.org/wiki/Color_difference\n * https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js\n * <= 1.0 Not perceptible by human eyes.\n * 1 - 2 Perceptible through close observation.\n * 2 - 10 Perceptible at a glance.\n * 11 - 49 Colors are more similar than opposite\n * 100 Colors are exact opposite\n */\nexport const getColorsDelta = (rgbA: RGBColor, rgbB: RGBColor, decimalPlaces = Infinity) => {\n const labA = rgbToLab(rgbA, decimalPlaces);\n const labB = rgbToLab(rgbB, decimalPlaces);\n\n // differences between the LAB components of the two colors\n const deltaL = labA[0] - labB[0];\n const deltaA = labA[1] - labB[1];\n const deltaB = labA[2] - labB[2];\n\n // chroma components\n const c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);\n const c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);\n const deltaC = c1 - c2;\n\n // difference in hue, deltaH, which takes into account both the differences\n // in the a* and b* components of LAB and the differences in chroma.\n let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;\n deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);\n\n const sc = 1.0 + 0.045 * c1;\n const sh = 1.0 + 0.015 * c1;\n\n // It applies weighting factors to the differences in lightness (deltaL),\n // chroma (deltaC), and hue (deltaH).\n const deltaLKlsl = deltaL / (1.0);\n const deltaCkcsc = deltaC / (sc);\n const deltaHkhsh = deltaH / (sh);\n\n // It computes the final color difference using the CIE76 formula:\n // deltaE = sqrt(deltaLKlsl^2 + deltaCkcsc^2 + deltaHkhsh^2),\n // where deltaLKlsl is the weighted lightness difference,\n // deltaCkcsc is the weighted chroma difference,\n // and deltaHkhsh is the weighted hue difference.\n const i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;\n\n // It returns the calculated color difference,\n // optionally rounded to the specified number of decimal places.\n return i < 0 ? 0 : Math.sqrt(i);\n};\n", "import { Vector2 } from '../types';\n\n/**\n * Speed = how far something moves in a given amount of time.\n * Speed is also a vector:\n * magnitude = distance\n * direction = time\n */\nexport type Speed = Vector2;\n\n/**\n * Velocity is a measure of how fast an object is moving in a particular direction.\n * Velocity = Distance traveled / Time taken\n * It has a magnitude and direction, and can be represented as a vector.\n */\nexport type Velocity = Vector2;\n\n/**\n * Acceleration is a measure of how quickly an object's velocity changes over time.\n * Acceleration = (Final velocity - Initial velocity) / Time taken\n * a = (vf - v0)/t.\n * Distance = Initial velocity * time + (acceleration * time^2) / 2\n * It also has a magnitude and direction, and can be represented as a vector.\n * When the direction is negative ----> it's a \"slowdown\" movement\n */\nexport type Acceleration = Vector2;\n\n/**\n * Gravity is the force that attracts two objects with mass toward each other.\n * Newton's law of universal gravitation formula:\n * Gravitational force = (Gravitational constant * Mass of object 1 * Mass of object 2) / Distance between objects^2\n * It also has a magnitude and direction, and can be represented as a vector.\n * magnitude = the strength of the gravitational force\n * direction = the direction in which the force is acting (the direction of the gravitational force is always toward the center of mass of the objects involved)\n */\nexport type Gravity = Vector2;\n\n", "/**\n * guid like '932ade5e-c515-4807-ac01-73b20ab3fb66'\n */\nexport const guid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0;\n return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);\n });\n};\n\n/**\n * id like 'df4unio1opulby2uqh4'\n */\nexport const newId = () => {\n return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);\n};\n", "import { ICircle, IPolygon, IRect, Matrix2, Vector2 } from '../types';\nimport { mod } from './other';\nimport { v2GetNormal, v2DotProduct } from './linear-algebra/vector';\n\n/**\n * Rectangles collision detection.\n * Rectangles should not be rotated.\n * The algorithm works by ensuring there is no gap between any of the 4 sides of the rectangles.\n * Any gap means a collision does not exist.\n * Returns true if collision is detected.\n */\nexport const rectCollide = (rect1: IRect, rect2: IRect) : boolean => {\n return rect1.x <= rect2.x + rect2.w &&\n rect1.x + rect1.w >= rect2.x &&\n rect1.y <= rect2.y + rect2.h &&\n rect1.h + rect1.y >= rect2.y;\n};\n\n/**\n * Circles collision detection.\n * This algorithm works by taking the center points of the two circles\n * and ensuring the distance between the center points\n * are less than the two radii added together.\n * Returns true if collision is detected.\n */\nexport const circleCollide = (circle1: ICircle, circle2: ICircle) => {\n const dx = Math.abs(circle1.cx - circle2.cx);\n const dy = Math.abs(circle1.cy - circle2.cy);\n const distance = Math.sqrt(dx * dx + dy * dy);\n return distance <= circle1.r + circle2.r;\n};\n\n//-------------------- Separating Axis Theorem (SAT) Collision detection -------------------------\n\nconst getEdges = (poly: IPolygon) : Matrix2[] => {\n const edges: Matrix2[] = [];\n\n for(let i= 0; i {\n const edges: Matrix2[] = [];\n\n // collect polygon edges, and combine then into a single array\n edges.push(...getEdges(poly1));\n edges.push(...getEdges(poly2));\n\n // for each edge, find the normal vector and project both polygons onto it\n for (const edge of edges) {\n const normal = v2GetNormal(edge[0], edge[1]);\n const p1Proj = projectPolygon(poly1, normal);\n const p2Proj = projectPolygon(poly2, normal);\n\n // Check if the projections overlap\n const isOverlap = p1Proj.max >= p2Proj.min && p2Proj.max >= p1Proj.min;\n\n // Check if the projections overlap; if not, the polygons do not collide\n if (!isOverlap) return false;\n }\n\n // If all tests pass, the polygons overlap and collide\n return true;\n};\n\n/**\n * Project every polygon point onto the normal.\n * Then find min and max.\n */\nconst projectPolygon = (polygon: IPolygon, normal: Vector2): { min: number, max: number } => {\n let min = Infinity;\n let max = -Infinity;\n\n // Project each vertex of the polygon onto the axis\n for (const vertex of polygon) {\n const projection = v2DotProduct(vertex, normal);\n min = Math.min(min, projection);\n max = Math.max(max, projection);\n }\n\n return { min, max };\n};", "export interface IAnimationProps {\n duration?: number;\n callback: (result: IAnimationResult) => void;\n restartOnResize?: boolean;\n resizeCallback?: (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => void;\n}\n\nexport interface IAnimationResult {\n start: () => void;\n stop: () => void;\n pause: () => void;\n resume: () => void;\n restart: () => void;\n isAnimating: () => boolean;\n getStartTime: () => number|undefined;\n getElapsedTime: () => number|undefined;\n getPercent: () => number|undefined;\n getResizeObserver: () => ResizeObserver|undefined;\n}\n\nexport const animate = (props: IAnimationProps) : IAnimationResult => {\n\n const _duration = props.duration !== undefined ? props.duration : Infinity;\n\n let startTime: number|undefined = undefined; // in milliseconds\n let animationId: number|undefined = undefined;\n\n // the time elapsed since the start of the animation (in milliseconds)\n let elapsed: number|undefined = undefined;\n let previousTimeStamp: number|undefined = undefined;\n\n let animating = false;\n let observer: ResizeObserver|undefined = undefined;\n\n // -------------------- COMMANDS ---------------------\n\n const stop = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = false;\n\n /*if(observer !== undefined){\n observer.disconnect();\n observer = undefined;\n }*/\n\n if(animationId === undefined) return;\n window.cancelAnimationFrame(animationId);\n };\n\n const restart = () => {\n stop();\n start();\n };\n\n const pause = () => {\n animating = false;\n };\n\n const resume = () => {\n animating = true;\n };\n\n /**\n * Animation Step.\n * @param {number} timeStamp in milliseconds\n */\n const step = (timeStamp: DOMHighResTimeStamp) => {\n\n if (startTime === undefined) {\n startTime = timeStamp;\n }\n\n // the time elapsed since the start of the animation (in milliseconds)\n elapsed = timeStamp - startTime;\n\n if (animating && previousTimeStamp !== timeStamp && typeof props.callback === 'function') {\n\n // do the rendering .............\n props.callback(getResult());\n }\n\n if(elapsed <= _duration){\n previousTimeStamp = timeStamp;\n animationId = window.requestAnimationFrame(step);\n }\n else{\n stop();\n }\n };\n\n const observerHandler = (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => {\n restart();\n\n if(typeof props.resizeCallback === 'function'){\n props.resizeCallback(_entries, _observer);\n }\n };\n\n const start = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = true;\n\n if(props.restartOnResize && window.ResizeObserver && observer === undefined){\n observer = new ResizeObserver(observerHandler);\n observer.observe(document.body, { box: 'border-box' });\n }\n else{\n animationId = window.requestAnimationFrame(step);\n }\n };\n\n // --------------- GET INFO ----------------------\n\n /**\n * the time elapsed since the start of the animation (in milliseconds)\n */\n const getElapsedTime = () : number|undefined => {\n return elapsed;\n };\n\n const isAnimating = () => {\n return animating;\n };\n\n const getStartTime = () => {\n return startTime;\n };\n\n const getPercent = () => {\n if(_duration === Infinity || elapsed === undefined) return undefined;\n return elapsed * 100 / _duration;\n };\n\n const getResizeObserver = () => {\n return observer;\n };\n\n const getResult = () : IAnimationResult => {\n return {\n\n // commands --------------\n start,\n stop,\n pause,\n resume,\n restart,\n\n // information -------\n isAnimating,\n getElapsedTime,\n getStartTime,\n getPercent,\n getResizeObserver,\n };\n };\n\n return getResult();\n};\n", "import { setDecimalPlaces } from './format';\n\nexport const getCircleCircumference = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * radius, decimalPlaces);\n};\n\nexport const getEllipseCircumference = (radius1: number, radius2: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * Math.sqrt((radius1 ** 2 + radius2 ** 2) / 2), decimalPlaces);\n};\n\nexport const isAngleInCircleArc = (startAngleDeg: number, endAngleDeg: number, currentDegrees: number) : boolean => {\n\n if(startAngleDeg > endAngleDeg) {\n endAngleDeg += 360;\n }\n\n return currentDegrees >= startAngleDeg && currentDegrees <= endAngleDeg ||\n (currentDegrees + 360) >= startAngleDeg && (currentDegrees + 360) <= endAngleDeg;\n};\n\n/**\n * get the side of a square inscribed in a circle\n */\nexport const getSquareInCircleSide = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(radius * 2 / Math.sqrt(2), decimalPlaces);\n};\n", "/**\n * 1 + 2 + ... + n = n * (n + 1) / 2\n */\nexport const naturalNumbersSequenceSum = (n: number) => {\n return n * (n + 1) / 2;\n};\n\n/**\n * n = the number of terms to be added\n * a = the first term in the sequence\n * d = the constant value between terms\n */\nexport const arithmeticSequenceSum = (n: number, a: number, d: number) => {\n return (n / 2) * (2 * a + (n - 1) * d);\n};", "\n// -------------------- CENTRAL TENDENCY ----------------------------\n\nimport { setDecimalPlaces } from './format';\n\n/**\n * Central tendency: Calculate the Average (mean)\n * Sum of all numbers divided by the array length.\n */\nexport const getArithmeticMean = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const sum = data.reduce((acc, val) => acc + val, 0);\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};\n\n/**\n * Central tendency: What is the central number in the sorted array?\n * Good for lists like [3, 3, 3, 3, 3, 3, 100] - 100 here is called \"Outlier\"\n */\nexport const getMedian = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const copy = [...data].sort((num1, num2) => num1 - num2);\n const mid = Math.floor(copy.length / 2);\n\n if(copy.length % 2 === 0) {\n return setDecimalPlaces((copy[mid] + copy[mid - 1]) / 2, decimalPlaces);\n }\n else {\n return setDecimalPlaces(copy[mid], decimalPlaces);\n }\n};\n\n/**\n * Central tendency: What number is most common in the set.\n * If all numbers have the same frequency, there is no mode.\n */\nexport const getMode = (data: number[]) : number[]|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n // Count frequency of each number in the data array.\n const frequencyMap: Map = new Map();\n for (const num of data) {\n frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);\n }\n\n let maxFrequency = 0;\n let modes: number[] = [];\n\n // Find the maximum frequency\n for (const [num, frequency] of frequencyMap) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency;\n modes = [num];\n }\n else if (frequency === maxFrequency) {\n modes.push(num);\n }\n }\n\n // If all numbers have the same frequency, there is no mode\n if (modes.length === data.length) {\n return undefined;\n }\n\n // Return the mode(s)\n return modes.length === 1 ? [modes[0]] : modes;\n};\n\n/*\nTODO:\n- geometric mean\n- harmonic mean\n */\n\n// -------------------- DISPERSION ----------------------------\n\nexport const getVariance = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const mean = getArithmeticMean(data);\n if(mean === undefined) return undefined;\n\n const sum = data.reduce((acc, val) => acc + ((val - mean) ** 2), 0);\n\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};", "import * as vector from './main/linear-algebra/vector';\nimport * as matrix from './main/linear-algebra/matrix';\nimport * as matrixTransformations from './main/linear-algebra/matrix-transformations';\nimport * as format from './main/format';\nimport * as angle from './main/angle';\nimport * as random from './main/random';\nimport * as other from './main/other';\nimport * as convert from './main/convert';\nimport * as bezierCurve from './main/bezier-curves/bezier-curve';\nimport * as equations from './main/equations/linear-equations';\nimport * as pathMovement from './main/path-movement';\nimport * as color from './main/color';\nimport * as physics from './main/physics';\nimport * as id from './main/id';\nimport * as derivative from './main/derivative';\nimport * as collisions from './main/collision-detection';\nimport * as animation from './main/animation';\nimport * as circleEllipse from './main/circle-ellipse';\nimport * as sequence from './main/sequence';\nimport * as statistics from './main/statistics';\n\nconst api = {\n ...vector,\n ...matrix,\n ...matrixTransformations,\n ...format,\n ...angle,\n ...random,\n ...other,\n ...convert,\n ...bezierCurve,\n ...equations,\n ...pathMovement,\n ...color,\n ...physics,\n ...id,\n ...derivative,\n ...collisions,\n ...animation,\n ...circleEllipse,\n ...sequence,\n ...statistics,\n};\n\ndeclare global {\n interface Window {\n mzMath: typeof api,\n }\n}\n\nwindow.mzMath = window.mzMath || api;\n\nexport * from './main/linear-algebra/vector';\nexport * from './main/linear-algebra/matrix';\nexport * from './main/linear-algebra/matrix-transformations';\nexport * from './main/format';\nexport * from './main/angle';\nexport * from './main/random';\nexport * from './main/other';\nexport * from './main/convert';\nexport * from './main/bezier-curves/bezier-curve';\nexport * from './main/equations/linear-equations';\nexport * from './main/path-movement';\nexport * from './main/color';\nexport * from './main/physics';\nexport * from './main/id';\nexport * from './main/derivative';\nexport * from './main/collision-detection';\nexport * from './main/animation';\nexport * from './main/circle-ellipse';\nexport * from './main/sequence';\nexport * from './main/statistics';"], - "mappings": ";;;;;;;qbAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,QAAAE,GAAA,eAAAC,GAAA,mBAAAC,GAAA,iBAAAC,GAAA,sBAAAC,GAAA,gBAAAC,GAAA,aAAAC,GAAA,gBAAAC,GAAA,gBAAAC,EAAA,gBAAAC,GAAA,UAAAC,EAAA,UAAAC,GAAA,OAAAC,GAAA,mBAAAC,GAAA,eAAAC,GAAA,mBAAAC,GAAA,iBAAAC,GAAA,aAAAC,GAAA,gBAAAC,EAAA,gBAAAC,EAAA,UAAAC,GAAA,UAAAC,GAAA,OAAAC,GAAA,cAAAC,GAAA,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C,CAC5D,GAAG,CAACA,GAAQA,EAAK,QAAU,EAAG,OAG9B,IAAMY,EAAoC,IAAI,IAC9C,QAAWC,KAAOb,EACdY,EAAa,IAAIC,GAAMD,EAAa,IAAIC,CAAG,GAAK,GAAK,CAAC,EAG1D,IAAIC,EAAe,EACfC,EAAkB,CAAC,EAGvB,OAAW,CAACF,EAAKG,CAAS,IAAKJ,EACvBI,EAAYF,GACZA,EAAeE,EACfD,EAAQ,CAACF,CAAG,GAEPG,IAAcF,GACnBC,EAAM,KAAKF,CAAG,EAKtB,GAAIE,EAAM,SAAWf,EAAK,OAK1B,OAAOe,EAAM,SAAW,EAAI,CAACA,EAAM,EAAE,EAAIA,CAC7C,EAUaE,GAAc,CAACjB,EAAgBC,EAAgB,MAAgC,CACxF,GAAG,CAACD,GAAQA,EAAK,QAAU,EAAG,OAE9B,IAAMkB,EAAOnB,GAAkBC,CAAI,EACnC,GAAGkB,IAAS,OAAW,OAEvB,IAAMhB,EAAMF,EAAK,OAAO,CAACG,EAAKC,IAAQD,EAAQgB,EAAAf,EAAMc,EAAS,GAAI,CAAC,EAElE,OAAOb,EAAiBH,EAAMF,EAAK,OAAQC,CAAa,CAC5D,EClEA,IAAMmB,GAAMC,wCAAA,GACLC,IACAC,IACAC,IACAC,GACAC,GACAC,IACAC,GACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IACAC,IASP,OAAO,OAAS,OAAO,QAAUrB", - "names": ["vector_exports", "__export", "v2", "v2Distance", "v2DivideScalar", "v2DotProduct", "v2FromPolarCoords", "v2GetNormal", "v2Length", "v2MulScalar", "v2Normalize", "v2SetLength", "v2Sub", "v2Sum", "v3", "v3CrossProduct", "v3Distance", "v3DivideScalar", "v3DotProduct", "v3Length", "v3MulScalar", "v3Normalize", "v3Sub", "v3Sum", "v4", "vDistance", "vDivideScalar", "vDotProduct", "vEqual", "vLength", "vMulScalar", "vN", "vNormalize", "vSub", "vSum", "format_exports", "__export", "setDecimalPlaces", "setDecimalPlaces", "num", "decimalPlaces", "coefficient", "__pow", "angle_exports", "__export", "degreesToRadians", "getAnglesDistance", "getAnglesSub", "getV2Angle", "getV2AngleBetween", "getV2AngleInEllipse", "getV3AngleBetween", "getVNAngleBetween", "isAngleBetween", "isClockwise", "percentToAngle", "radiansToDegrees", "setV2Angle", "other_exports", "__export", "convertRange", "doRangesOverlap", "isNumber", "mod", "polarToCartesian", "mod", "n", "m", "convertRange", "x", "a", "b", "c", "d", "doRangesOverlap", "isNumber", "value", "polarToCartesian", "center", "radii", "angleInRad", "decimalPlaces", "cx", "cy", "rx", "ry", "setDecimalPlaces", "getV2Angle", "v2", "decimalPlaces", "angle", "setDecimalPlaces", "getV2AngleInEllipse", "radii", "setV2Angle", "newAngleRad", "length", "v2Length", "radiansToDegrees", "radians", "res", "degreesToRadians", "degrees", "getVNAngleBetween", "vector1", "vector2", "unitVector1", "vNormalize", "unitVector2", "dotProduct", "vDotProduct", "getV2AngleBetween", "diff", "vSub", "getV3AngleBetween", "isAngleBetween", "angleDegrees", "startAngleDegrees", "endAngleDegrees", "distance", "getAnglesSub", "distance1", "distance2", "totalDistance", "isClockwise", "angle1Deg", "angle2Deg", "startAngleDeg", "angleDegrees1", "angleDegrees2", "angleDistance", "mod", "getAnglesDistance", "percentToAngle", "percent", "endAngleDeg", "circleStartAngle", "vSum", "vector1", "vector2", "decimalPlaces", "vector", "i", "setDecimalPlaces", "v2Sum", "v3Sum", "vSub", "v2Sub", "v3Sub", "vMulScalar", "v", "scalar", "v2MulScalar", "v2", "v3MulScalar", "v3", "vDivideScalar", "v2DivideScalar", "v3DivideScalar", "vLength", "sum", "v2Length", "v3Length", "v2SetLength", "newLength", "angle", "getV2Angle", "vDistance", "diff", "v2Distance", "v3Distance", "vNormalize", "length", "unitVector", "v2Normalize", "v3Normalize", "vDotProduct", "v2DotProduct", "v3DotProduct", "v3CrossProduct", "defaultValue", "v4", "vN", "N", "v2FromPolarCoords", "distance", "angleRad", "setV2Angle", "vEqual", "v2GetNormal", "sub", "matrix_exports", "__export", "identity2", "identity3", "identity4", "identityN", "isSingularMatrix", "m2Adjugate", "m2AppendRow", "m2DeepCopy", "m2Determinant", "m2DivideScalar", "m2Inverse", "m2MulScalar", "m2PrependRow", "m2Reset", "m2Sub", "m2Sum", "m2Transpose", "m2x2", "m3Adjugate", "m3AppendRow", "m3DeepCopy", "m3Determinant", "m3DivideScalar", "m3Inverse", "m3MulScalar", "m3PrependRow", "m3Reset", "m3Sub", "m3Sum", "m3Transpose", "m3x3", "m4x4", "mAdjugate", "mAppendCol", "mAppendRow", "mDeepCopy", "mDelFirstColumn", "mDelFirstRow", "mDelLastColumn", "mDelLastRow", "mDeterminant", "mDivideScalar", "mEqual", "mGetColumn", "mGetFirstColumn", "mGetLastColumn", "mInverse", "mMinor", "mMul", "mMulScalar", "mMulVector", "mNxM", "mPrependCol", "mPrependRow", "mReset", "mSub", "mSum", "mTranspose", "mSum", "matrix1", "matrix2", "decimalPlaces", "matrix", "i", "vSum", "m2Sum", "m3Sum", "mSub", "vSub", "m2Sub", "m3Sub", "mMulScalar", "m", "scalar", "v", "vMulScalar", "m2MulScalar", "m2", "m3MulScalar", "m3", "mDivideScalar", "vDivideScalar", "m2DivideScalar", "m3DivideScalar", "mTranspose", "vectorsCount", "vectorLength", "j", "m2Transpose", "m3Transpose", "mReset", "defaultValue", "res", "size", "vector", "m2Reset", "m3Reset", "m2x2", "m3x3", "m4x4", "mNxM", "N", "M", "vN", "identity2", "identity3", "identity4", "identityN", "mDeepCopy", "m2DeepCopy", "m3DeepCopy", "mAppendCol", "col", "copy", "mPrependCol", "mAppendRow", "row", "m2AppendRow", "m3AppendRow", "mPrependRow", "m2PrependRow", "m3PrependRow", "mDelLastRow", "mDelFirstRow", "mDelLastColumn", "mDelFirstColumn", "mGetFirstColumn", "mGetLastColumn", "mGetColumn", "colIndex", "mMul", "transposed", "vector1", "vector2", "product", "vDotProduct", "mMulVector", "mEqual", "vEqual", "mMinorHelper", "mMinor", "mDeterminant", "m2Determinant", "d", "minor", "param", "m3Determinant", "m2Adjugate", "m3Adjugate", "mAdjugate", "cofactors", "sign", "isSingularMatrix", "m2Inverse", "adj", "m3Inverse", "mInverse", "matrix_transformations_exports", "__export", "m2ReflectionOrigin", "m2ReflectionOriginH", "m2ReflectionX", "m2ReflectionXH", "m2ReflectionY", "m2ReflectionYH", "m2ReflectionYmX", "m2RotateAroundPointH", "m2Rotation", "m2RotationAroundPointH", "m2RotationH", "m2Scale", "m2ScaleAtPointH", "m2ScaleAtPointHMatrix", "m2ScaleH", "m2ScaleX", "m2ScaleXH", "m2ScaleY", "m2ScaleYH", "m2ShearingX", "m2ShearingY", "m2ToCSS", "m2Translation", "m2TranslationH", "m2hToCSS", "m2hToCSS3d", "m3ReflectionOrigin", "m3ReflectionOriginH", "m3ReflectionXY", "m3ReflectionXYH", "m3ReflectionXZ", "m3ReflectionXZH", "m3ReflectionYZ", "m3ReflectionYZH", "m3RotationX", "m3RotationXH", "m3RotationY", "m3RotationYH", "m3RotationZ", "m3RotationZH", "m3Scale", "m3ScaleH", "m3ScaleX", "m3ScaleXH", "m3ScaleY", "m3ScaleYH", "m3ScaleZ", "m3ScaleZH", "m3Translation", "m3TranslationH", "m3hToCSS3d", "v2Rotate", "v2RotateH", "v2Scale", "v3RotateX", "v3RotateY", "v3RotateZ", "v3Scale", "m2ToCSS", "m", "a", "b", "c", "d", "m2hToCSS", "tx", "ty", "m2hToCSS3d", "m3hToCSS3d", "m2Translation", "position", "decimalPlaces", "setDecimalPlaces", "m3Translation", "m2TranslationH", "m3TranslationH", "m2Rotation", "angleRad", "isClockwise", "cos", "sin", "m2RotationH", "m2RotationAroundPointH", "transformOrigin", "translation", "rotation", "translationBack", "v3MulScalar", "temp1", "mMul", "m2RotateAroundPointH", "mat3h", "mMulVector", "v2Rotate", "vector", "unitVector", "v2Normalize", "v2RotateH", "v3Normalize", "m3RotationX", "m3RotationXH", "v3RotateX", "m3RotationY", "m3RotationYH", "v3RotateY", "m3RotationZ", "m3RotationZH", "v3RotateZ", "m2ScaleAtPointHMatrix", "scaleVector", "scale", "m2ScaleH", "m2ScaleAtPointH", "point", "m2Scale", "v2Scale", "m3Scale", "m3ScaleH", "v3Scale", "m2ScaleX", "m2ScaleXH", "m3ScaleX", "m3ScaleXH", "m3ScaleY", "m3ScaleYH", "m3ScaleZ", "m3ScaleZH", "m2ScaleY", "m2ScaleYH", "m2ReflectionOrigin", "m2ReflectionOriginH", "m3ReflectionOrigin", "m3ReflectionOriginH", "m2ReflectionYmX", "m2ReflectionX", "m2ReflectionXH", "m2ReflectionY", "m2ReflectionYH", "m3ReflectionYZ", "m3ReflectionYZH", "m3ReflectionXZ", "m3ReflectionXZH", "m3ReflectionXY", "m3ReflectionXYH", "m2ShearingY", "factor", "m2ShearingX", "random_exports", "__export", "getRandom", "getRandomBoolean", "getRandomInt", "getRandomItemFromArray", "getRandom", "min", "max", "decimalPlaces", "setDecimalPlaces", "getRandomInt", "getRandomBoolean", "getRandomItemFromArray", "array", "randomIndex", "convert_exports", "__export", "stringToNumber", "value", "defaultNumber", "_a", "res", "bezier_curve_exports", "__export", "v2CubicBezierBBox", "v2CubicBezierCurve", "v2CubicBezierCurveExtrema", "v2CubicBezierCurveNormal", "v2CubicBezierCurveTangent", "v2QuadraticBezierBBox", "v2QuadraticBezierCurve", "v2QuadraticBezierCurveExtrema", "v2QuadraticBezierCurveNormal", "v2QuadraticBezierCurveTangent", "v3CubicBezierCurve", "v3CubicBezierCurveTangent", "v3QuadraticBezierCurve", "v3QuadraticBezierCurveTangent", "derivative_exports", "__export", "dxArcCos", "dxArcCot", "dxArcSin", "dxArcTan", "dxCos", "dxCot", "dxPolynomial", "dxSin", "dxTan", "dxV2CubicBezierCurve", "dxV2QuadraticBezierCurve", "dxV3CubicBezierCurve", "dxV3QuadraticBezierCurve", "dxPolynomial", "x", "polynomial", "decimalPlaces", "res", "part", "coeff", "power", "setDecimalPlaces", "dxV2QuadraticBezierCurve", "startControlPoint", "centerControlPoint", "endControlPoint", "temp1", "temp2", "temp3", "dxV3QuadraticBezierCurve", "dxV2CubicBezierCurve", "center1ControlPoint", "center2ControlPoint", "temp4", "dxV3CubicBezierCurve", "dxSin", "dxCos", "dxTan", "__pow", "dxCot", "dxArcSin", "dxArcCos", "dxArcTan", "dxArcCot", "linear_equations_exports", "__export", "getLinearEquationBy2Points", "linearEquation", "linearEquationSystem2", "linearEquationSystem3", "linearEquationSystemN", "linearEquation", "equation", "decimalPlaces", "a", "b", "diff", "setDecimalPlaces", "linearEquationSystem2", "equation1", "equation2", "equationParams", "inversed", "m2Inverse", "equationResults", "mMulVector", "linearEquationSystem3", "equation3", "m3Inverse", "linearEquationSystemN", "equations", "mDelLastColumn", "mInverse", "mGetLastColumn", "getLinearEquationBy2Points", "point1", "point2", "deltaX", "deltaY", "v2Sub", "x", "y", "m", "formula", "quadraticEquation", "equation", "decimalPlaces", "a", "b", "c", "d", "res", "linearEquation", "isNumber", "diff", "discriminant", "setDecimalPlaces", "t1", "t2", "v2QuadraticBezierCurve", "startControlPoint", "centerControlPoint", "endControlPoint", "decimalPlaces", "temp1", "temp2", "temp3", "setDecimalPlaces", "v3QuadraticBezierCurve", "v2CubicBezierCurve", "center1ControlPoint", "center2ControlPoint", "temp4", "v3CubicBezierCurve", "v2QuadraticBezierCurveTangent", "dxVector", "dxV2QuadraticBezierCurve", "v2Normalize", "v3QuadraticBezierCurveTangent", "dxV3QuadraticBezierCurve", "v3Normalize", "v2CubicBezierCurveTangent", "dxV2CubicBezierCurve", "v3CubicBezierCurveTangent", "dxV3CubicBezierCurve", "v2QuadraticBezierCurveNormal", "tangent", "v2CubicBezierCurveNormal", "v2QuadraticBezierCurveExtrema", "a1", "b1", "res1", "linearEquation", "a2", "b2", "res2", "res", "isNumber", "v2CubicBezierCurveExtrema", "c1", "equation1", "c2", "equation2", "quadraticEquation", "num", "v2QuadraticBezierBBox", "extrema", "minX", "minY", "maxX", "maxY", "percent", "point", "x", "y", "v2CubicBezierBBox", "path_movement_exports", "__export", "circleMovement", "circleMovementAfterMouse", "ellipseMovement", "ellipseMovementAfterMouse", "lissajousCurve", "sineWaveMovement", "circleMovement", "center", "angle", "radius", "circleMovementAfterMouse", "mouse", "vector", "v2Sub", "getV2Angle", "convertRange", "ellipseMovement", "radius1", "radius2", "ellipseMovementAfterMouse", "radii", "sineWaveMovement", "x", "amplitude", "frequency", "phase", "y", "lissajousCurve", "width", "height", "t", "k", "n", "m", "p", "color_exports", "__export", "getColorsDelta", "getRandomGrayscaleHSLColor", "getRandomHSLColor", "getRandomHSLColorWithHue", "getRandomHSLColorWithLightness", "getRandomHSLColorWithSaturation", "getRandomHSLColorWithinRanges", "getRandomHexColor", "getRandomRGBColor", "getShiftedHue", "getShiftedLightness", "getShiftedSaturation", "hexToRgb", "hslToHex", "hslToRgb", "labToRgb", "rgbToHex", "rgbToHsl", "rgbToLab", "getRandomRGBColor", "hslColor", "getRandomHSLColor", "hslToRgb", "getRandomHexColor", "hslToHex", "h", "getRandom", "s", "l", "getRandomHSLColorWithHue", "getRandomHSLColorWithSaturation", "getRandomHSLColorWithLightness", "getRandomGrayscaleHSLColor", "getRandomHSLColorWithinRanges", "hueStart", "hueEnd", "saturationStart", "saturationEnd", "lightStart", "lightEnd", "convertHueToDegrees", "getHue", "r", "g", "b", "min", "max", "diff", "getLuminance", "getSaturation", "rgbToHsl", "rgb", "decimalPlaces", "setDecimalPlaces", "hslToRgbHelper", "helper1", "helper2", "colorHelper", "hsl", "gray", "rHelper", "gHelper", "bHelper", "hue2rgb", "q", "t", "p", "toHex", "hex", "rgbToHex", "hexToRgb", "shorthandRegex", "_hex", "_m", "result", "rgbToLab", "x", "y", "z", "labToRgb", "lab", "getShiftedHue", "color", "shift", "hue", "mod", "getShiftedLightness", "lightness", "getShiftedSaturation", "saturation", "getColorsDelta", "rgbA", "rgbB", "labA", "labB", "deltaL", "deltaA", "deltaB", "c1", "c2", "deltaC", "deltaH", "sc", "sh", "deltaLKlsl", "deltaCkcsc", "deltaHkhsh", "i", "physics_exports", "id_exports", "__export", "guid", "newId", "c", "collision_detection_exports", "__export", "circleCollide", "convexPolygonsCollide", "rectCollide", "rectCollide", "rect1", "rect2", "circleCollide", "circle1", "circle2", "dx", "dy", "getEdges", "poly", "edges", "i", "nextIndex", "mod", "edge", "convexPolygonsCollide", "poly1", "poly2", "normal", "v2GetNormal", "p1Proj", "projectPolygon", "p2Proj", "polygon", "min", "max", "vertex", "projection", "v2DotProduct", "animation_exports", "__export", "animate", "props", "_duration", "startTime", "animationId", "elapsed", "previousTimeStamp", "animating", "observer", "stop", "restart", "start", "pause", "resume", "step", "timeStamp", "getResult", "observerHandler", "_entries", "_observer", "getElapsedTime", "isAnimating", "getStartTime", "getPercent", "getResizeObserver", "circle_ellipse_exports", "__export", "getCircleCircumference", "getEllipseCircumference", "getSquareInCircleSide", "isAngleInCircleArc", "getCircleCircumference", "radius", "decimalPlaces", "setDecimalPlaces", "getEllipseCircumference", "radius1", "radius2", "__pow", "isAngleInCircleArc", "startAngleDeg", "endAngleDeg", "currentDegrees", "getSquareInCircleSide", "sequence_exports", "__export", "arithmeticSequenceSum", "naturalNumbersSequenceSum", "n", "a", "d", "statistics_exports", "__export", "getArithmeticMean", "getMedian", "getMode", "getVariance", "getArithmeticMean", "data", "decimalPlaces", "sum", "acc", "val", "setDecimalPlaces", "getMedian", "copy", "num1", "num2", "mid", "getMode", "frequencyMap", "num", "maxFrequency", "modes", "frequency", "getVariance", "mean", "__pow", "api", "__spreadValues", "vector_exports", "matrix_exports", "matrix_transformations_exports", "format_exports", "angle_exports", "random_exports", "other_exports", "convert_exports", "bezier_curve_exports", "linear_equations_exports", "path_movement_exports", "color_exports", "physics_exports", "id_exports", "derivative_exports", "collision_detection_exports", "animation_exports", "circle_ellipse_exports", "sequence_exports", "statistics_exports"] + "sources": ["../src/main/linear-algebra/vector.ts", "../src/main/format.ts", "../src/main/angle.ts", "../src/main/other.ts", "../src/main/linear-algebra/matrix.ts", "../src/main/linear-algebra/matrix-transformations.ts", "../src/main/random.ts", "../src/main/convert.ts", "../src/main/bezier-curves/bezier-curve.ts", "../src/main/derivative.ts", "../src/main/equations/linear-equations.ts", "../src/main/equations/quadratic-equations.ts", "../src/main/path-movement.ts", "../src/main/color.ts", "../src/main/physics.ts", "../src/main/id.ts", "../src/main/collision-detection.ts", "../src/main/animation.ts", "../src/main/circle-ellipse.ts", "../src/main/sequence.ts", "../src/main/statistics.ts", "../src/main/ml.ts", "../src/index.ts"], + "sourcesContent": ["import { Vector, Vector2, Vector3, Vector4 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { getV2Angle, setV2Angle } from '../angle';\n\n// ------------ SUM ------------------------\n\nexport const vSum = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSum(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sum = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSum(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ SUB ------------------------\n\nexport const vSub = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSub(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sub = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSub(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ MUL SCALAR ------------------------\n\nexport const vMulScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n const vector: Vector = [];\n\n for(let i=0; i {\n return vMulScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3MulScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vMulScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ DIVIDE ------------------------\n\nexport const vDivideScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vDivideScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3DivideScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vDivideScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ LENGTH ------------------------\n\nexport const vLength = (vector: Vector, decimalPlaces = Infinity) => {\n let sum = 0;\n\n for(let i=0; i {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v3Length = (vector: Vector3, decimalPlaces = Infinity) => {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v2SetLength = (v2: Vector2, newLength: number, decimalPlaces = Infinity): Vector2 => {\n const angle = getV2Angle(v2);\n return [\n setDecimalPlaces(Math.cos(angle) * newLength, decimalPlaces),\n setDecimalPlaces(Math.sin(angle) * newLength, decimalPlaces),\n ];\n};\n\n// ----------- DISTANCE ------------------------\n\nexport const vDistance = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v2Distance = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v3Distance = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\n// ------------ NORMALIZE ------------------------\n\n/**\n * Normalization creates a unit vector, which is a vector of length 1.\n */\nexport const vNormalize = (v: Vector, decimalPlaces = Infinity) : Vector => {\n const length = vLength(v);\n const unitVector: Vector = [];\n\n for(let i=0; i {\n return vNormalize(v2, decimalPlaces) as Vector2;\n};\n\nexport const v3Normalize = (v3: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vNormalize(v3, decimalPlaces) as Vector3;\n};\n\n// ------------ DOT PRODUCT ------------------------\n\nexport const vDotProduct = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n let sum = 0;\n\n for(let i=0; i {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\nexport const v3DotProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\n// ------------ CROSS PRODUCT ------------------------\n\n/**\n * Cross product is possible on 3D vectors only.\n * The cross product a \u00D7 b is defined as a vector c that is perpendicular (orthogonal) to both a and b.\n */\nexport const v3CrossProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity): Vector3 => {\n return [\n setDecimalPlaces(vector1[1] * vector2[2] - vector1[2] * vector2[1], decimalPlaces),\n setDecimalPlaces(vector1[2] * vector2[0] - vector1[0] * vector2[2], decimalPlaces),\n setDecimalPlaces(vector1[0] * vector2[1] - vector1[1] * vector2[0], decimalPlaces),\n ];\n};\n\n// --------------- INIT VECTOR HELPER -----------------\n\nexport const v2 = (defaultValue = 0): Vector2 => {\n return [defaultValue, defaultValue];\n};\n\nexport const v3 = (defaultValue = 0): Vector3 => {\n return [defaultValue, defaultValue, defaultValue];\n};\n\nexport const v4 = (defaultValue = 0): Vector4 => {\n return [defaultValue, defaultValue, defaultValue, defaultValue];\n};\n\nexport const vN = (N: number, defaultValue = 0): Vector => {\n\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n const vector: Vector = [];\n for(let i=0; i {\n let vector: Vector2 = [0, 0];\n vector = v2SetLength(vector, distance);\n return setV2Angle(vector, angleRad);\n};\n\n// --------------- EQUALITY -------------------------\n\nexport const vEqual = (vector1: Vector, vector2: Vector): boolean => {\n if(vector1.length !== vector2.length) return false;\n\n for(let i=0; i {\n const sub = v2Sub(vector2, vector1);\n return [\n -setDecimalPlaces(sub[1], decimalPlaces),\n setDecimalPlaces(sub[0], decimalPlaces)\n ];\n};", "export const setDecimalPlaces = (num: number, decimalPlaces: number | undefined = Infinity) => {\n if(decimalPlaces === Infinity) return num;\n\n if(decimalPlaces < 0){\n decimalPlaces = 0;\n }\n\n const coefficient = 10 ** decimalPlaces;\n return Math.round(num * coefficient) / coefficient;\n};", "import { Vector, Vector2, Vector3 } from '../types';\nimport { setDecimalPlaces } from './format';\nimport { v2Length, vNormalize, vDotProduct, vSub } from './linear-algebra/vector';\nimport { mod } from './other';\n\nexport const getV2Angle = (v2: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1], v2[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleInEllipse = (v2: Vector2, radii: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1]/radii[1], v2[0]/radii[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const setV2Angle = (v2: Vector2, newAngleRad: number, decimalPlaces = Infinity): Vector2 => {\n const length = v2Length(v2);\n return [\n setDecimalPlaces(Math.cos(newAngleRad) * length, decimalPlaces),\n setDecimalPlaces(Math.sin(newAngleRad) * length, decimalPlaces),\n ];\n};\n\nexport const radiansToDegrees = (radians: number, decimalPlaces = Infinity) => {\n const res = radians * (180 / Math.PI);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\nexport const degreesToRadians = (degrees: number, decimalPlaces = Infinity) => {\n const res = degrees * (Math.PI / 180);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\n/**\n * Returns the range [0, Math.PI]\n * A = Math.acos( dot(v1, v2)/(v1.length()*v2.length()) );\n */\nexport const getVNAngleBetween = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n const unitVector1 = vNormalize(vector1);\n const unitVector2 = vNormalize(vector2);\n const dotProduct = vDotProduct(unitVector1, unitVector2);\n const angle = Math.acos(dotProduct);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleBetween = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) : number => {\n // return getVNAngleBetween(vector1, vector2, decimalPlaces);\n const diff = vSub(vector1, vector2);\n const angle = Math.atan2(diff[1], diff[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV3AngleBetween = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return getVNAngleBetween(vector1, vector2, decimalPlaces);\n};\n\nexport const isAngleBetween = (angleDegrees: number, startAngleDegrees: number, endAngleDegrees: number) : boolean => {\n const distance = getAnglesSub(startAngleDegrees, endAngleDegrees);\n const distance1 = getAnglesSub(startAngleDegrees, angleDegrees);\n const distance2 = getAnglesSub(endAngleDegrees, angleDegrees);\n const totalDistance = distance1 + distance2;\n\n // Use a small threshold for floating point errors\n return Math.abs(totalDistance - distance) <= 0.001;\n}\n\nexport const isClockwise = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n return angle2Deg >= angle1Deg;\n};\n\n/**\n * Shortest distance (angular) between two angles.\n */\nexport const getAnglesSub = (angleDegrees1: number, angleDegrees2: number, decimalPlaces = Infinity) : number => {\n const angleDistance = Math.abs(mod(angleDegrees1, 360) - mod(angleDegrees2, 360));\n return setDecimalPlaces(angleDistance <= 180 ? angleDistance : 360 - angleDistance, decimalPlaces);\n};\n\nexport const getAnglesDistance = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0, decimalPlaces = Infinity) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n if(isClockwise(angle1Deg, angle2Deg, startAngleDeg)) {\n return setDecimalPlaces((angle2Deg - angle1Deg + 360) % 360, decimalPlaces);\n }\n else{\n return setDecimalPlaces((angle1Deg - angle2Deg + 360) % 360, decimalPlaces);\n }\n};\n\nexport const percentToAngle = (percent: number, startAngleDeg: number, endAngleDeg: number, circleStartAngle = 0) => {\n if(percent < 0) {\n percent = 0;\n }\n\n if(percent > 100) {\n percent = 100;\n }\n\n const distance = getAnglesDistance(startAngleDeg, endAngleDeg, circleStartAngle);\n\n const clockwise = isClockwise(startAngleDeg, endAngleDeg, circleStartAngle);\n if(clockwise) {\n return mod(circleStartAngle + (percent * distance / 100), 360);\n }\n else {\n return mod(circleStartAngle - (percent * distance / 100), 360);\n }\n};", "import { Vector2 } from '../types';\nimport { setDecimalPlaces } from './format';\n\nexport const mod = (n: number, m: number) => {\n return ((n % m) + m) % m;\n};\n\n/**\n * Convert range [a, b] to [c, d].\n * f(x) = (d - c) * (x - a) / (b - a) + c\n */\nexport const convertRange = (x: number, a: number, b: number, c: number, d: number) => {\n return (d - c) * (x - a) / (b - a) + c;\n};\n\n/**\n * Check if 2 ranges [a,b] and [c,d] overlap.\n */\nexport const doRangesOverlap = (a: number, b: number, c: number, d: number) => {\n return Math.max(a, c) <= Math.min(b, d) ;\n};\n\n// eslint-disable-next-line\nexport const isNumber = (value: any) => {\n return !isNaN(parseFloat(value)) && isFinite(value);\n};\n\n/**\n * Convert polar coordinates to cartesian coordinates.\n */\nexport const polarToCartesian = (center: Vector2, radii: Vector2, angleInRad: number, decimalPlaces = Infinity) : Vector2 => {\n const [cx, cy] = center;\n const [rx, ry] = radii;\n\n return [\n setDecimalPlaces(cx + (rx * Math.cos(angleInRad)), decimalPlaces),\n setDecimalPlaces(cy + (ry * Math.sin(angleInRad)), decimalPlaces),\n ];\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector, Vector2, Vector3 } from '../../types';\nimport { vMulScalar, vSum, vSub, vDotProduct, vN, vEqual, vDivideScalar } from './vector';\n\n// --------------- SUM ----------------------\n\nexport const mSum = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sum = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- SUB ----------------------\n\nexport const mSub = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sub = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- MUL SCALAR ----------------------\n\nexport const mMulScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vMulScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2MulScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mMulScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3MulScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mMulScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n// --------------- DIVIDE SCALAR ----------------------\n\nexport const mDivideScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vDivideScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2DivideScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mDivideScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3DivideScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mDivideScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n\n// --------------- TRANSPOSE ----------------------\n\nexport const mTranspose = (m: Matrix): Matrix => {\n\n const vectorsCount = m.length;\n if(vectorsCount <= 0) return m;\n\n const vectorLength = m[0].length;\n if(vectorLength <= 0) return m;\n\n const matrix: Matrix = [];\n for(let i=0; i {\n return mTranspose(m2);\n};\n\nexport const m3Transpose = (m3: Matrix3): Matrix => {\n return mTranspose(m3);\n};\n\n// ----------------- RESET ----------------------\n\nexport const mReset = (m: Matrix, defaultValue = 0): Matrix => {\n\n if(m.length <= 0) return [];\n\n const res: Matrix = [];\n\n for(let i=0; i {\n return mReset(m2, defaultValue) as Matrix2;\n};\n\nexport const m3Reset = (m3: Matrix3, defaultValue = 0): Matrix3 => {\n return mReset(m3, defaultValue) as Matrix3;\n};\n\n// --------------- MATRIX INIT HELPERS -----------------\n\nexport const m2x2 = (defaultValue = 0): Matrix2 => {\n return [\n [defaultValue, defaultValue],\n [defaultValue, defaultValue],\n ];\n};\n\nexport const m3x3 = (defaultValue = 0): Matrix3 => {\n return [\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const m4x4 = (defaultValue = 0): Matrix4 => {\n return [\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const mNxM = (N: number, M: number, defaultValue = 0): Matrix => {\n if(N <= 0 || M <= 0){\n throw new Error('M and N must be positive numbers.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return [\n [1, 0],\n [0, 1],\n ];\n};\n\nexport const identity3 = (): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\nexport const identity4 = (): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Identity Matrix (I).\n * M x I = I x M = M for any matrix M.\n * Identity Matrix is a special case of scale matrix.\n */\nexport const identityN = (N: number): Matrix => {\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n if(N === 0) return [];\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mDeepCopy(m2) as Matrix2;\n};\n\nexport const m3DeepCopy = (m3: Matrix3): Matrix3 => {\n return mDeepCopy(m3) as Matrix3;\n};\n\n// -------------- APPEND / PREPEND ROW OR COLUMN ---------------\n\nexport const mAppendCol = (m: Matrix, col: Vector): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n const copy = mDeepCopy(m);\n copy.push(row);\n return copy;\n};\n\nexport const m2AppendRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.push(row);\n return copy;\n};\n\nexport const m3AppendRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.push(row);\n return copy;\n};\n\nexport const mPrependRow = (m: Matrix, row: Vector) : Matrix => {\n const copy = mDeepCopy(m);\n copy.unshift(row);\n return copy;\n};\n\nexport const m2PrependRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.unshift(row);\n return copy;\n};\n\nexport const m3PrependRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.unshift(row);\n return copy;\n};\n\n// ------------ DELETE ROW OR COLUMN ----------------------------\n\nexport const mDelLastRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.pop();\n return copy;\n};\n\nexport const mDelFirstRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.shift();\n return copy;\n};\n\nexport const mDelLastColumn = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const size = m[0].length;\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n\n const matrix: Matrix = [];\n for(let i=0; i {\n\n if(matrix.length < 0) return [];\n\n if(matrix[0].length !== vector.length){\n throw new Error('The number of columns in the matrix must be equal to the length of the vector.');\n }\n\n const res: Vector = [];\n\n for(let i=0; i {\n if(matrix1.length !== matrix2.length) return false;\n\n for(let i=0; i returns matrix N (m-1 x m-1)\n * The matrix must be square.\n */\nconst mMinorHelper = (m: Matrix, row: number, col: number) => {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // prepare the matrix without provided row and column\n const matrix = mMinorHelper(m, row, col);\n\n // calculate the matrix determinant\n return mDeterminant(matrix);\n};\n\n/**\n * Calculate determinant for NxN matrix.\n * Matrix should be square.\n */\nexport const mDeterminant = (matrix: Matrix): number => {\n const size = matrix.length;\n if(size === 0) return 1;\n\n if(size !== matrix[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return matrix[0][0];\n if(size === 2) return m2Determinant(matrix as Matrix2);\n\n let d = 0;\n\n for(let i=0; i {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return m2[0][0] * m2[1][1] - m2[1][0] * m2[0][1];\n};\n\n/**\n * Calculate determinant for 3x3 matrix.\n * Matrix should be square.\n */\nexport const m3Determinant = (m3: Matrix3): number => {\n if(m3.length !== m3[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return mDeterminant(m3);\n};\n\n// ------------------ INVERSE -----------------------\n\nexport const m2Adjugate = (m2: Matrix2): Matrix2|null => {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return [\n [m2[1][1], -m2[0][1]],\n [-m2[1][0], m2[0][0]],\n ];\n};\n\nexport const m3Adjugate = (m3: Matrix3) : Matrix3|null => {\n return mAdjugate(m3) as (Matrix3|null);\n};\n\n/**\n * Adjugate is a transpose of a cofactor matrix\n */\nexport const mAdjugate = (m: Matrix): Matrix|null => {\n\n const size = m.length;\n if(size <= 0) return null;\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return m;\n\n if(size === 2) return m2Adjugate(m as Matrix2);\n\n // build a cofactor matrix ----------------\n const cofactors: Matrix = [];\n\n for(let i=0; i {\n if(m.length > 0 && m.length !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = mDeterminant(m);\n return d === 0;\n};\n\n/**\n * Square matrix A (nxn) is invertible is there is another square matrix B (nxn) so AxB = BxA = I\n * For A (2x2) matrix, the inverse is:\n * (1 / (determinant(A))) * adj(A)\n */\nexport const m2Inverse = (m2: Matrix2, decimalPlaces = Infinity): (Matrix2 | null) => {\n if(m2.length > 0 && m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = m2Determinant(m2);\n if(d === 0) return null;\n\n const adj = m2Adjugate(m2);\n if(adj === null) return null;\n\n return m2DivideScalar(adj, d, decimalPlaces);\n};\n\nexport const m3Inverse = (m3: Matrix3, decimalPlaces = Infinity): (Matrix3 | null) => {\n return mInverse(m3, decimalPlaces) as (Matrix3|null);\n};\n\nexport const mInverse = (m: Matrix, decimalPlaces = Infinity): (Matrix | null) => {\n const size = m.length;\n\n if(size > 0 && size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // find a determinant ----------------------\n const d = mDeterminant(m);\n\n // find an Adjugate - a transpose of a cofactor matrix\n const adj = mAdjugate(m);\n if(adj === null) return null;\n\n return mDivideScalar(adj, d, decimalPlaces);\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector2, Vector3, Vector4 } from '../../types';\nimport { v2Normalize, v3MulScalar, v3Normalize } from './vector';\nimport { mMulVector, mMul } from './matrix';\nimport { setDecimalPlaces } from '../format';\n\n/*\nAny 2D affine transformation can be decomposed\ninto a rotation, followed by a scaling, followed by a\nshearing, and followed by a translation.\n---------------------------------------------------------\nAffine matrix = translation x shearing x scaling x rotation\n */\n\n// ----------------- CSS -------------------------------------\n\n/**\n * Matrix 2D in non-homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2ToCSS = (m: Matrix2) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, 0, 0)`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2hToCSS = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ tx }, ${ ty })`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m2hToCSS3d = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix3d(${ a }, ${ b }, 0, 0, ${ c }, ${ d }, 0, 0, 0, 0, 1, 0, ${ tx }, ${ ty }, 0, 1)`;\n};\n\n/**\n * Matrix 3D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m3hToCSS3d = (m: Matrix4) : string => {\n\n return `matrix3d(\n ${ m[0][0] }, ${ m[0][1] }, ${ m[0][2] }, ${ m[0][3] },\n ${ m[1][0] }, ${ m[1][1] }, ${ m[1][2] }, ${ m[1][3] },\n ${ m[2][0] }, ${ m[2][1] }, ${ m[2][2] }, ${ m[2][3] },\n ${ m[3][0] }, ${ m[3][1] }, ${ m[3][2] }, ${ m[3][3] }\n )`;\n};\n\n// ---------------- TRANSLATION MATRICES ----------------------\n\nexport const m2Translation = (position: Vector2, decimalPlaces = Infinity): Matrix2 => {\n\n return [\n [1, 0],\n [0, 1],\n [setDecimalPlaces(position[0], decimalPlaces), setDecimalPlaces(position[1], decimalPlaces)],\n ];\n};\n\nexport const m3Translation = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n [\n setDecimalPlaces(position[0], decimalPlaces),\n setDecimalPlaces(position[1], decimalPlaces),\n setDecimalPlaces(position[2], decimalPlaces)\n ],\n ];\n};\n\n/**\n * 2D Translation matrix in homogeneous coordinates.\n */\nexport const m2TranslationH = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1],\n ];\n};\n\n/**\n * 3D Translation matrix in homogeneous coordinates.\n */\nexport const m3TranslationH = (position: Vector4, decimalPlaces = Infinity): Matrix4 => {\n\n return [\n [1, 0, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, 0, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1, setDecimalPlaces(position[2], decimalPlaces)],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- ROTATION MATRICES -------------------------\n\n/**\n * Rotation of an angle about the origin.\n */\nexport const m2Rotation = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix2 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin],\n [sin, cos],\n ] :\n [\n [cos, sin],\n [-sin, cos],\n ];\n};\n\n/**\n * Rotation of an angle about the origin in homogeneous coordinates (clockwise).\n */\nexport const m2RotationH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ]:\n [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation of an angle \"angleRad\" around the given point (transformOrigin) in homogeneous coordinates (clockwise).\n * result_vector = TranslationMatrix(x, y) * RotationMatrix() * TranslationMatrix(-x, -y) * position_vector\n */\nexport const m2RotationAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const rotation = m2RotationH(angleRad, isClockwise, decimalPlaces);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, rotation);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2RotateAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n position: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2RotationAroundPointH(angleRad, transformOrigin, isClockwise, decimalPlaces);\n return mMulVector(mat3h, position) as Vector3;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2Rotate = (angleRad: number, vector: Vector2, isClockwise = true, decimalPlaces = Infinity): Vector2 => {\n const unitVector = v2Normalize(vector);\n return mMulVector(m2Rotation(angleRad, isClockwise, decimalPlaces), unitVector) as Vector2;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2RotateH = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m2RotationH(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the X axis (clockwise).\n */\nexport const m3RotationX = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0],\n [0, cos, -sin],\n [0, sin, cos],\n ] :\n [\n [1, 0, 0],\n [0, cos, sin],\n [0, -sin, cos],\n ];\n};\n\n/**\n * Rotation around the X axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationXH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0, 0],\n [0, cos, -sin, 0],\n [0, sin, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [1, 0, 0, 0],\n [0, cos, sin, 0],\n [0, -sin, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateX = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationX(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Y axis (clockwise).\n */\nexport const m3RotationY = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin],\n [0, 1, 0],\n [-sin, 0, cos],\n ] :\n [\n [cos, 0, -sin],\n [0, 1, 0],\n [sin, 0, cos],\n ];\n};\n\n/**\n * Rotation around the Y axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationYH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin, 0],\n [0, 1, 0, 0],\n [-sin, 0, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [cos, 0, -sin, 0],\n [0, 1, 0, 0],\n [sin, 0, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateY = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationY(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Z axis (clockwise).\n */\nexport const m3RotationZ = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ] : [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation around the Z axis (clockwise)- in homogeneous coordinates\n */\nexport const m3RotationZH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0, 0],\n [sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ] : [\n [cos, sin, 0, 0],\n [-sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateZ = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationZ(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n// ---------------- SCALE MATRICES -------------\n\n/**\n * Get matrix for arbitrary scaling pivot point.\n * result_vector = TranslationMatrix(x, y) * ScaleMatrix() * TranslationMatrix(-x, -y) * scale_vector\n */\nexport const m2ScaleAtPointHMatrix = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const scale = m2ScaleH(scaleVector);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, scale);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2ScaleAtPointH = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n point: Vector3,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2ScaleAtPointHMatrix(scaleVector, transformOrigin, decimalPlaces);\n return mMulVector(mat3h, point) as Vector3;\n};\n\nexport const m2Scale = (scaleVector: Vector2): Matrix2 => {\n return [\n [scaleVector[0], 0],\n [0, scaleVector[1]],\n ];\n};\n\nexport const v2Scale = (scaleVector: Vector2, vector: Vector2): Vector2 => {\n return mMulVector(m2Scale(scaleVector), vector) as Vector2;\n};\n\n/**\n * homogeneous coordinates\n */\nexport const m2ScaleH = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, 1],\n ];\n};\n\nexport const m3Scale = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, scaleVector[2]],\n ];\n};\n\nexport const m3ScaleH = (scaleVector: Vector4): Matrix4 => {\n return [\n [scaleVector[0], 0, 0, 0],\n [0, scaleVector[1], 0, 0],\n [0, 0, scaleVector[2], 0],\n [0, 0, 0, 1]\n ];\n};\n\nexport const v3Scale = (scaleVector: Vector3, vector: Vector3): Vector3 => {\n return mMulVector(m3Scale(scaleVector), vector) as Vector3;\n};\n\n/**\n * Stretch, parallel to the x-axis.\n */\nexport const m2ScaleX = (scale: number): Matrix2 => {\n return [\n [scale, 0],\n [0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the x-axis - homogeneous coordinates\n */\nexport const m2ScaleXH = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleX = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleXH = (scale: number): Matrix4 => {\n return [\n [scale, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleY = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleYH = (scale: number): Matrix => {\n return [\n [1, 0, 0, 0],\n [0, scale, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZ = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, scale],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZH = (scale: number): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, scale, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis.\n */\nexport const m2ScaleY = (scale: number): Matrix2 => {\n return [\n [1, 0],\n [0, scale],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis - homogeneous coordinates\n */\nexport const m2ScaleYH = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n// ---------------- REFLECTION MATRICES -------------------------\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOrigin = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOriginH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection about the origin in non-homogeneous coordinates\n */\nexport const m3ReflectionOrigin = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection about the origin in homogeneous coordinates\n */\nexport const m3ReflectionOriginH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection about y=-x\n */\nexport const m2ReflectionYmX = (): Matrix2 => {\n\n return [\n [0, -1],\n [-1, 0],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionX = (): Matrix2 => {\n\n return [\n [1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionXH = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection in the y-axis.\n */\nexport const m2ReflectionY = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, 1],\n ];\n};\n\nexport const m2ReflectionYH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionYZ = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in homogeneous coordinates\n */\nexport const m3ReflectionYZH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXZ = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in homogeneous coordinates\n */\nexport const m3ReflectionXZH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXY = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in homogeneous coordinates\n */\nexport const m3ReflectionXYH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- SHEARING MATRICES -------------------------\n\n\n/**\n * Shearing in y-axis, with x-axis fixed with (0,1) moving to (factor, 1)\n */\nexport const m2ShearingY = (factor: number): Matrix2 => {\n\n return [\n [1, factor],\n [0, 1],\n ];\n};\n\n/**\n * Shearing in x-axis, with y-axis fixed with (1,0) moving to (1, factor)\n */\nexport const m2ShearingX = (factor: number): Matrix2 => {\n\n return [\n [1, 0],\n [factor, 1],\n ];\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a random number in the [min,max] range.\n */\nexport const getRandom = (min: number, max: number, decimalPlaces = Infinity): number => {\n return setDecimalPlaces(Math.random() * (max - min) + min, decimalPlaces);\n};\n\n/**\n * Returns a random integer number in the [min,max] range.\n */\nexport const getRandomInt = (min: number, max: number): number => {\n return Math.floor(Math.random() * (max - min + 1) + min);\n};\n\nexport const getRandomBoolean = () => Math.random() < 0.5;\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getRandomItemFromArray = (array: any[]) => {\n const randomIndex = getRandomInt(0, array.length - 1);\n return array[randomIndex];\n};", "export const stringToNumber = (value: string|undefined|null|number, defaultNumber: number) => {\n if(value === undefined || value === null) return defaultNumber;\n const res = Number(value) ?? defaultNumber;\n return isNaN(res) ? defaultNumber : res;\n};", "import { IBBox, Vector, Vector2, Vector3 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport {\n dxV2CubicBezierCurve,\n dxV2QuadraticBezierCurve,\n dxV3CubicBezierCurve,\n dxV3QuadraticBezierCurve\n} from '../derivative';\nimport { v2Normalize, v3Normalize } from '../linear-algebra/vector';\nimport { linearEquation } from '../equations/linear-equations';\nimport { quadraticEquation } from '../equations/quadratic-equations';\nimport { isNumber } from '../other';\n\n/**\n * B\u00E9zier Curves\n * quadratic: y = P1 * (1-t)\u00B2 + P2 * 2 * (1-t)t + P3 * t\u00B2\n * t in range [0, 1]\n */\n\n// -------------------- GET POINT ON CURVE --------------------------\n\n/**\n * Get a point on a quadratic B\u00E9zier curve as a function of time.\n */\nexport const v2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n/**\n * Get a point on a cubic B\u00E9zier curve as a function of time.\n */\nexport const v2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n// -------------------- TANGENT --------------------------\n\n/**\n * Tangent indicates the direction of travel at specific points along the B\u00E9zier curve,\n * and is literally just the first derivative of our curve.\n */\nexport const v2QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\nexport const v2CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\n// -------------------- NORMAL --------------------------\n\n/**\n * Normal is a vector that runs at a right angle to the direction of the curve, and is typically of length 1.\n * To find it, we take the normalised tangent vector, and then rotate it by a 90 degrees.\n */\nexport const v2QuadraticBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2QuadraticBezierCurveTangent(t, startControlPoint, centerControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\nexport const v2CubicBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2CubicBezierCurveTangent(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\n// -------------------- EXTREMA --------------------------\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2QuadraticBezierCurveExtrema = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector => {\n\n /*\n (-2 * (1 - t)) * startControlPoint[0] + (2 - 4 * t) * centerControlPoint[0] + (2 * t) * endControlPoint[0]\n 2 * t * startControlPoint[0] - 4 * t * centerControlPoint[0] + 2 * t * endControlPoint[0] - 2 * startControlPoint[0] + 2 * centerControlPoint[0]\n t * (2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0]) + (- 2 * startControlPoint[0] + 2 * centerControlPoint[0])\n */\n\n const a1 = 2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0];\n const b1 = -2 * startControlPoint[0] + 2 * centerControlPoint[0];\n const equation1: Vector3 = [a1, b1, 0];\n const res1 = linearEquation(equation1, decimalPlaces);\n\n const a2 = 2 * startControlPoint[1] - 4 * centerControlPoint[1] + 2 * endControlPoint[1];\n const b2 = -2 * startControlPoint[1] + 2 * centerControlPoint[1];\n const equation2: Vector3 = [a2, b2, 0];\n const res2 = linearEquation(equation2, decimalPlaces);\n\n const res: Vector = [];\n\n if(isNumber(res1)){\n res.push(res1);\n }\n\n if(isNumber(res2)){\n res.push(res2);\n }\n\n return res;\n};\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2CubicBezierCurveExtrema = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2|null => {\n\n const a1 = -3 * startControlPoint[0] + 9 * center1ControlPoint[0] - 9 * center2ControlPoint[0] + 3 * endControlPoint[0];\n const b1 = 6 * startControlPoint[0] - 12 * center1ControlPoint[0] + 6 * center2ControlPoint[0];\n const c1 = -3 * startControlPoint[0] + 3 * center1ControlPoint[0];\n const equation1: Vector = [a1, b1, c1, 0];\n\n const a2 = -3 * startControlPoint[1] + 9 * center1ControlPoint[1] - 9 * center2ControlPoint[1] + 3 * endControlPoint[1];\n const b2 = 6 * startControlPoint[1] - 12 * center1ControlPoint[1] + 6 * center2ControlPoint[1];\n const c2 = -3 * startControlPoint[1] + 3 * center1ControlPoint[1];\n const equation2: Vector = [a2, b2, c2, 0];\n\n // Any value between 0 and 1 is a root that matters for B\u00E9zier curves, anything below or above that is irrelevant (because B\u00E9zier curves are only defined over the interval [0,1]).\n const res1 = quadraticEquation(equation1, decimalPlaces).filter(num => num >= 0 && num <= 1);\n const res2 = quadraticEquation(equation2, decimalPlaces).filter(num => num >= 0 && num <= 1);\n\n const res = [...res1, ...res2];\n if(res.length === 2){\n return [...res1, ...res2] as Vector2;\n }\n\n return null;\n};\n\n// -------------------- BOUNDING BOX --------------------------\n\nexport const v2QuadraticBezierBBox = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2QuadraticBezierCurveExtrema(startControlPoint, centerControlPoint, endControlPoint);\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2QuadraticBezierCurve(percent, startControlPoint, centerControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\nexport const v2CubicBezierBBox = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2CubicBezierCurveExtrema(startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint) || [];\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2CubicBezierCurve(percent, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x ?? Infinity);\n maxX = Math.max(maxX, x ?? -Infinity);\n\n minY = Math.min(minY, y ?? Infinity);\n maxY = Math.max(maxY, y ?? -Infinity);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\n\n", "import { setDecimalPlaces } from './format';\nimport { Vector2, Vector3 } from '../types';\n\n/**\n * u(x) and v(x) are functions ---------->\n *\n * dx(u + v) = dx(u) + dx(v)\n * dx(u - v) = dx(u) - dx(v)\n * dx(u * v) = dx(u) * v + u * dx(v)\n * dx(u / v) = (dx(u) * v - u * dx(v)) / (v ^ 2), when v(x) != 0\n */\n\n// ------------------ Derivatives of Polynomial ---------------------------\n\n/**\n * y = 3x+2\n * dxPolynomial(10, [[3, 1], [2, 0]])\n */\nexport const dxPolynomial = (x: number, polynomial: number[][], decimalPlaces = Infinity) => {\n let res = 0;\n\n for(const part of polynomial){\n if(part.length !== 2) return NaN;\n\n const coeff = part[0];\n const power = part[1];\n res += coeff * power * Math.pow(x, power - 1);\n }\n\n return setDecimalPlaces(res, decimalPlaces);\n}\n\n// ---------------------- Bezier Curves ---------------------------\n\n/**\n * Derivative of Bezier Curve is another Bezier Curve.\n * t must min in range [0, 1]\n */\nexport const dxV2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n // The derivative: P1 * (2t-2) + (2*P3-4*P2) * t + 2 * P2\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\nexport const dxV2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n\n// ----------------- Derivatives of trigonometry functions ---------------------------\n\nexport const dxSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(Math.cos(x), decimalPlaces);\n};\n\nexport const dxCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-Math.sin(x), decimalPlaces);\n};\n\nexport const dxTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.cos(x) ** 2), decimalPlaces);\n};\n\n/**\n * x != Math.PI * n, where n is an integer\n */\nexport const dxCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sin(x) ** 2), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\nexport const dxArcTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (1 + x ** 2), decimalPlaces);\n};\n\nexport const dxArcCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (1 + x ** 2), decimalPlaces);\n};\n", "import { Matrix, Matrix2, Matrix3, Vector, Vector2, Vector3 } from '../../types';\nimport { m2Inverse, m3Inverse, mInverse, mMulVector, mDelLastColumn, mGetLastColumn } from '../linear-algebra/matrix';\nimport { setDecimalPlaces } from '../format';\nimport { v2Sub } from '../linear-algebra/vector';\n\n/**\n * Linear equation\n * ax + b = c\n * x = (c - b) / a; a != 0\n */\nexport const linearEquation = (equation: Vector3, decimalPlaces = Infinity) : number => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n\n const diff = c - b;\n\n if(a === 0 && diff === 0) return Infinity; // any number is a solution\n if(a === 0) return NaN; // no solution\n\n return setDecimalPlaces(diff / a, decimalPlaces);\n};\n\n/**\n * System of 2 linear equations.\n * [x, y] = inverse(Matrix of equation parameters) x (vector of equation results)\n * ---------------\n * 3x + 2y = 7\n * -6x + 6y = 6\n */\nexport const linearEquationSystem2 = (equation1: Vector3, equation2: Vector3, decimalPlaces = Infinity) : Vector2 | null => {\n const equationParams: Matrix2 = [\n [equation1[0], equation1[1]],\n [equation2[0], equation2[1]],\n ];\n\n const inversed = m2Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector2 = [\n equation1[2],\n equation2[2]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector2;\n};\n\n/**\n * System of 3 linear equations.\n * ---------------------------------------\n * 3x + 2y + 5z = 7\n * -6x + 6y + 6z = 6\n * 2x + 7y - z = 4\n */\nexport const linearEquationSystem3 = (\n equation1: Vector,\n equation2: Vector,\n equation3: Vector,\n decimalPlaces = Infinity) : Vector3 | null => {\n const equationParams: Matrix3 = [\n [equation1[0], equation1[1], equation1[2]],\n [equation2[0], equation2[1], equation2[2]],\n [equation3[0], equation3[1], equation3[2]],\n ];\n\n const inversed = m3Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector3 = [\n equation1[3],\n equation2[3],\n equation3[3]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector3;\n};\n\n/**\n * System of N linear equations.\n */\nexport const linearEquationSystemN = (equations: Matrix, decimalPlaces = Infinity) : Vector | null => {\n if(equations.length <= 0) return null;\n\n const equationParams = mDelLastColumn(equations);\n\n const inversed = mInverse(equationParams);\n if(inversed === null) return null; // no results\n\n // the last column of the equations matrix\n const equationResults = mGetLastColumn(equations);\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector;\n};\n\n/**\n * Calculate the equation of a line given two points in a 2D space.\n * y = ax + b\n * y - y1 = m(x - x1)\n * m = (y2 - y1) / (x2 - x1)\n */\nexport const getLinearEquationBy2Points = (point1: Vector2, point2: Vector2) : {\n slope: number|undefined,\n yIntercept: number|undefined,\n xIntercept: number|undefined,\n formula: string,\n} => {\n const [deltaX, deltaY] = v2Sub(point2, point1);\n const [x, y] = point1;\n\n if(deltaX === 0) {\n return {\n slope: undefined,\n xIntercept: x,\n yIntercept: undefined,\n formula: `x = ${ x }`,\n };\n }\n\n const m = deltaY / deltaX;\n const b = y - m * x;\n let formula = '';\n\n if(m === 0) {\n formula = `y = ${ b }`;\n }\n else{\n formula = `y = ${ m === 1 ? '' : m }x`;\n\n if(b !== 0) {\n formula += ` ${ b < 0 ? '-' : '+' } ${ Math.abs(b) }`;\n }\n }\n\n return {\n slope: m,\n xIntercept: undefined,\n yIntercept: b,\n formula,\n };\n};", "import { Vector } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { linearEquation } from './linear-equations';\nimport { isNumber } from '../other';\n\n/**\n * Quadratic Equation.\n * ax^2 + bx + c = d\n */\nexport const quadraticEquation = (equation: Vector, decimalPlaces = Infinity) : Vector => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n const d = equation[3];\n\n if(a === 0){\n // it's a linear equation -------------------------------------------\n const res = linearEquation([b, c, d], decimalPlaces);\n if(isNumber(res)) return [res];\n return [];\n }\n\n const diff = c - d;\n\n const discriminant = b * b - (4 * a * diff);\n\n if(discriminant < 0){\n return []; // no results\n }\n\n if(discriminant === 0){\n return [ setDecimalPlaces(-b / (2 * a), decimalPlaces) ]; // 1 result\n }\n\n // if(determinant > 0) ---> 2 results\n const t1 = 2 * a;\n const t2 = Math.sqrt(discriminant);\n\n return [\n setDecimalPlaces((-b + t2) / t1, decimalPlaces),\n setDecimalPlaces((-b - t2) / t1, decimalPlaces),\n ];\n};", "import { Vector2 } from '../types';\nimport { v2Sub } from './linear-algebra/vector';\nimport { getV2Angle } from './angle';\nimport { convertRange } from './other';\n\n/**\n * Circle Equation\n * x^2 + y^2 = radius^2\n * ----------------------\n * Circle Parametric Equation\n * x(t) = radius * cos(t)\n * y(t) = radius * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const circleMovement = (center: Vector2, angle: number, radius: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius,\n center[1] + Math.sin(angle) * radius\n ];\n};\n\n/**\n * Circle Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const circleMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radius: number\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return circleMovement(center, angle, radius);\n};\n\n/**\n * Ellipse Equation\n * (x - centerX)^2 / (radius1^2) + (y - centerY)^2 / (radius2^2) = 1\n * -----------------------------------------------------------------\n * Ellipse Parametric Equation\n * x(t) = radius1 * cos(t)\n * y(t) = radius2 * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const ellipseMovement = (center: Vector2, angle: number, radius1: number, radius2: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius1,\n center[1] + Math.sin(angle) * radius2\n ];\n};\n\n/**\n * Ellipse Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const ellipseMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radii: Vector2\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return ellipseMovement(center, angle, radii[0], radii[1]);\n};\n\n/**\n * Sine Wave Equation (Sinusoid)\n * -----------------------------\n * const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n * amplitude = the peak deviation of the function from zero\n * frequency = number of cycles\n * phase = specifies (in radians) where in its cycle the oscillation is at t = 0.\n * think of it as \"shifting\" the starting point of the function to the right (positive p) or left (negative)\n */\nexport const sineWaveMovement = (x: number, amplitude: number, frequency: number, phase: number) : Vector2 => {\n /*\n example values:\n const amplitude = 50;\n const frequency = 0.005;\n const phase = 0;\n x: [0, 1000]\n */\n const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n\n return [x, y];\n};\n\n/**\n * Lissajous curve (Lissajous figure or Bowditch curve)\n * Parametric equation #1\n * f(t) = A * sin(k * t + m)\n * f(t) = B * sin(n * t)\n * 0 <= m <= PI/2\n * k, n >= 1\n * -----------------------\n * Parametric equation #2\n * f(t) = A * cos(k * t - m)\n * f(t) = B * cos(n * t - p)\n * -----------------------------\n * Shapes:\n * k = 1, n = 1, m = 0, p = 0 ---> line\n * A = B, k = 1, n = 1, m = PI/2, p = PI/2 ----> circle\n * A != B, k = 1, n = 1, m = PI/2, p = PI/2 ----> ellipse\n * k = 2, n = 2, m = PI/2, p = PI/2 ----> section of a parabola\n */\nexport const lissajousCurve = (\n width: number,\n height: number,\n t: number,\n k: number,\n n: number,\n m: number,\n p: number\n) :Vector2 => {\n return [\n width * Math.cos(k * t - m),\n height * Math.cos(n * t - p),\n ];\n};\n", "import { getRandom } from './random';\nimport { HSLColor, LABColor, RGBColor } from '../types';\nimport { mod } from './other';\nimport { setDecimalPlaces } from './format';\n\n// ------------------------ RANDOM COLOR -------------------------------------\n\nexport const getRandomRGBColor = () : RGBColor => {\n const hslColor = getRandomHSLColor();\n return hslToRgb(hslColor);\n};\n\nexport const getRandomHexColor = () : string => {\n const hslColor = getRandomHSLColor();\n return hslToHex(hslColor);\n};\n\nexport const getRandomHSLColor = () : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given hue\n */\nexport const getRandomHSLColorWithHue = (h: number) : HSLColor => {\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given saturation\n */\nexport const getRandomHSLColorWithSaturation = (s: number) : HSLColor => {\n const h = getRandom(1, 360);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given lightness\n */\nexport const getRandomHSLColorWithLightness = (l: number) : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n return [h, s, l];\n};\n\nexport const getRandomGrayscaleHSLColor = () : HSLColor => {\n const l = getRandom(0, 100);\n return [0, 0, l];\n};\n\nexport const getRandomHSLColorWithinRanges = (\n hueStart = 1, hueEnd = 360,\n saturationStart = 0, saturationEnd = 100,\n lightStart = 0, lightEnd = 100\n) : HSLColor => {\n const h = getRandom(hueStart, hueEnd);\n const s = getRandom(saturationStart, saturationEnd);\n const l = getRandom(lightStart, lightEnd);\n return [h, s, l];\n};\n\n// ----------------------- CONVERT COLORS --------------------------------------\n\n/**\n * helper: convert hue value to degrees.\n * @param {number} h\n * @return {number} [0, 360] degrees\n */\nconst convertHueToDegrees = (h : number) : number => {\n\n // the hue value needs to be multiplied by 60 to convert it to degrees\n h *= 60;\n\n // if hue becomes negative, you need to add 360 to, because a circle has 360 degrees\n if(h < 0){\n h += 360;\n }\n\n return h;\n // convert huw to %\n // return h * 100 / 360;\n};\n\n/**\n * get hue from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] % - we use here % instead of [0, 359] degrees\n */\nconst getHue = (r : number, g : number, b : number, min : number | undefined = undefined, max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (max === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no hue, as it's gray\n if(min === max) return 0;\n\n const diff = max - min;\n\n let h = 0;\n\n // if red is max\n if(max === r){\n h = (g - b) / diff + (g < b ? 6 : 0);\n }\n\n // if green is max\n if(max === g){\n h = 2 + (b - r) / diff;\n }\n\n // if blue is max\n if(max === b){\n h = 4 + (r - g) / diff;\n }\n\n return convertHueToDegrees(h);\n};\n\n/**\n * get luminance from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] %\n */\nconst getLuminance = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // calculate the luminance value\n // @ts-ignore\n const l = (min + max) / 2; // [0, 1]\n\n // return l value in %\n return l * 100;\n};\n\n/**\n * get saturation from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @param {number|undefined=} l - luminance in [0, 100] %\n * @return {number} [0, 100] %\n */\nconst getSaturation = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined,\n l : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no saturation, as it's gray\n if(min === max) return 0;\n\n // calculate luminance if it's not provided\n l = (l === undefined) ? getLuminance(r, g, b) : l;\n\n // check the level of luminance\n const s = (l <= 50) ?\n // @ts-ignore\n ((max - min) / (max + min)) : // this formula is used when luminance <= 50%\n // @ts-ignore\n (max - min) / (2.0 - max - min); // this formula is used when luminance > 50%\n\n // return saturation in %\n return s * 100;\n};\n\nexport const rgbToHsl = (rgb: RGBColor, decimalPlaces = Infinity): HSLColor => {\n\n // convert rgb values to the range [0, 1]\n const r = rgb[0] / 255;\n const g = rgb[1] / 255;\n const b = rgb[2] / 255;\n\n // find the minimum and maximum values of r, g, and b\n const min = Math.min(r, g, b);\n const max = Math.max(r, g, b);\n\n // calculate the luminance value in %\n const l = getLuminance(r, g, b, min, max);\n\n // calculate the saturation in %\n const s = getSaturation(r, g, b, min, max, l);\n\n // calculate the hue in % (not in degrees!)\n const h = getHue(r, g, b, min, max);\n\n if(h > 360 || s > 100 || l > 100){\n return [0, 0, 100];\n }\n\n if(h < 0 || s < 0 || l < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(h, decimalPlaces),\n setDecimalPlaces(s, decimalPlaces),\n setDecimalPlaces(l, decimalPlaces),\n ];\n};\n\n/**\n * helper: HSL to RGB\n */\nconst hslToRgbHelper = (helper1 : number, helper2 : number, colorHelper : number) : number => {\n\n // all values need to be between 0 and 1\n // if you get a negative value you need to add 1 to it\n if(colorHelper < 0) colorHelper += 1;\n\n // if you get a value above 1 you need to subtract 1 from it.\n if(colorHelper > 1) colorHelper -= 1;\n\n if(colorHelper * 6 < 1) return helper2 + (helper1 - helper2) * 6 * colorHelper;\n\n if(colorHelper * 2 < 1) return helper1;\n\n if(colorHelper * 3 < 2){\n return helper2 + (helper1 - helper2) * (0.666 - colorHelper) * 6;\n }\n else{\n return helper2;\n }\n};\n\nexport const hslToRgb = (hsl: HSLColor, decimalPlaces = Infinity): RGBColor => {\n\n // convert all values to [0, 1] from %\n const h = hsl[0] / 100;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n // if there is no saturation -> it\u2019s grey\n if(s === 0){\n // convert the luminance from [0, 1] to [0, 255]\n const gray = l * 255;\n return [gray, gray, gray];\n }\n\n // check the level of luminance\n const helper1 = (l < 0.5) ?\n (l * (1.0 + s)) :\n (l + s - l * s);\n\n const helper2 = 2 * l - helper1;\n\n const rHelper = h + 0.333;\n const gHelper = h;\n const bHelper = h - 0.333;\n\n let r = hslToRgbHelper(helper1, helper2, rHelper);\n let g = hslToRgbHelper(helper1, helper2, gHelper);\n let b = hslToRgbHelper(helper1, helper2, bHelper);\n\n // convert rgb to [0, 255]\n r *= 255;\n g *= 255;\n b *= 255;\n\n if(r > 255 || g > 255 || b > 255){\n return [255, 255, 255];\n }\n\n if(r < 0 || g < 0 || b < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(r, decimalPlaces),\n setDecimalPlaces(g, decimalPlaces),\n setDecimalPlaces(b, decimalPlaces),\n ];\n};\n\n/**\n * HSL to hex\n * hslToHex(360, 100, 50) // [360, 100, 5] ==> \"#ff0000\" (red)\n */\nexport const hslToHex = (hsl: HSLColor) => {\n\n if(hsl[0] > 360 || hsl[1] > 100 || hsl[2] > 100){\n return '#ffffff';\n }\n\n if(hsl[0] < 0 || hsl[1] < 0 || hsl[2] < 0){\n return '#000000';\n }\n\n const h = hsl[0] / 360;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n let r, g, b;\n if (s === 0) {\n r = g = b = l; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n r = hue2rgb(p, q, h + 1 / 3);\n g = hue2rgb(p, q, h);\n b = hue2rgb(p, q, h - 1 / 3);\n }\n const toHex = (x: number) => {\n const hex = Math.round(x * 255).toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n};\n\n/**\n * RGB to HEX\n * rgbToHex([235, 64, 52]) // #eb4034\n */\nexport const rgbToHex = (rgb: RGBColor) => {\n const [r, g, b] = rgb;\n return '#' + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);\n};\n\nexport const hexToRgb = (hex: string) : RGBColor | null => {\n\n const shorthandRegex = /^#?([a-f\\d])([a-f\\d])([a-f\\d])$/i;\n const _hex = hex.replace(shorthandRegex, (_m, r, g, b) => {\n return r + r + g + g + b + b;\n });\n\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(_hex);\n if(!result) return null;\n\n const r = parseInt(result[1], 16);\n const g = parseInt(result[2], 16);\n const b = parseInt(result[3], 16);\n\n return [r, g, b];\n};\n\nexport const rgbToLab = (rgb: RGBColor, decimalPlaces = Infinity) : LABColor => {\n\n let r = rgb[0] / 255;\n let g = rgb[1] / 255;\n let b = rgb[2] / 255;\n\n r = (r > 0.04045) ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;\n g = (g > 0.04045) ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;\n b = (b > 0.04045) ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;\n\n let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;\n let y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;\n let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;\n\n x = (x > 0.008856) ? Math.pow(x, 1/3) : (7.787 * x) + 16/116;\n y = (y > 0.008856) ? Math.pow(y, 1/3) : (7.787 * y) + 16/116;\n z = (z > 0.008856) ? Math.pow(z, 1/3) : (7.787 * z) + 16/116;\n\n return [\n setDecimalPlaces((116 * y) - 16, decimalPlaces),\n setDecimalPlaces(500 * (x - y), decimalPlaces),\n setDecimalPlaces(200 * (y - z), decimalPlaces),\n ];\n};\n\nexport const labToRgb = (lab: LABColor, decimalPlaces = Infinity) : RGBColor => {\n let y = (lab[0] + 16) / 116;\n let x = lab[1] / 500 + y;\n let z = y - lab[2] / 200;\n\n x = 0.95047 * ((x * x * x > 0.008856) ? x * x * x : (x - 16/116) / 7.787);\n y = 1.00000 * ((y * y * y > 0.008856) ? y * y * y : (y - 16/116) / 7.787);\n z = 1.08883 * ((z * z * z > 0.008856) ? z * z * z : (z - 16/116) / 7.787);\n\n let r = x * 3.2406 + y * -1.5372 + z * -0.4986;\n let g = x * -0.9689 + y * 1.8758 + z * 0.0415;\n let b = x * 0.0557 + y * -0.2040 + z * 1.0570;\n\n r = (r > 0.0031308) ? (1.055 * Math.pow(r, 1/2.4) - 0.055) : 12.92 * r;\n g = (g > 0.0031308) ? (1.055 * Math.pow(g, 1/2.4) - 0.055) : 12.92 * g;\n b = (b > 0.0031308) ? (1.055 * Math.pow(b, 1/2.4) - 0.055) : 12.92 * b;\n\n return [\n setDecimalPlaces(Math.max(0, Math.min(1, r)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, g)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, b)) * 255, decimalPlaces),\n ];\n};\n\n// ----------------------- GET SHIFTED COLORS --------------------------------------\n\nexport const getShiftedHue = (color: HSLColor, shift = 180) : HSLColor => {\n let hue = color[0];\n hue += shift;\n\n if (hue > 360 || hue < 0) {\n hue = mod(hue, 360);\n }\n\n return [hue, color[1], color[2]];\n};\n\nexport const getShiftedLightness = (color: HSLColor, shift = 10) : HSLColor => {\n let lightness = color[2];\n lightness += shift;\n\n if (lightness > 100 || lightness < 0) {\n lightness = mod(lightness, 100);\n }\n\n return [color[0], color[1], lightness];\n};\n\nexport const getShiftedSaturation = (color: HSLColor, shift = 10) : HSLColor => {\n let saturation = color[1];\n saturation += shift;\n\n if (saturation > 100) {\n saturation -= 100;\n }\n\n if(saturation < 0){\n saturation += 100;\n }\n\n return [color[0], saturation, color[2]];\n};\n\n// ----------------------- SIMILAR COLORS --------------------------------------\n\n/**\n * Measure the perceptual difference between two RGB colors using the CIE76 color difference formula:\n * delta = Math.sqrt((L2 - L1)^2 + (a2 - a1)^2 + (b2 - b1)^2)\n * https://en.wikipedia.org/wiki/Color_difference\n * https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js\n * <= 1.0 Not perceptible by human eyes.\n * 1 - 2 Perceptible through close observation.\n * 2 - 10 Perceptible at a glance.\n * 11 - 49 Colors are more similar than opposite\n * 100 Colors are exact opposite\n */\nexport const getColorsDelta = (rgbA: RGBColor, rgbB: RGBColor, decimalPlaces = Infinity) => {\n const labA = rgbToLab(rgbA, decimalPlaces);\n const labB = rgbToLab(rgbB, decimalPlaces);\n\n // differences between the LAB components of the two colors\n const deltaL = labA[0] - labB[0];\n const deltaA = labA[1] - labB[1];\n const deltaB = labA[2] - labB[2];\n\n // chroma components\n const c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);\n const c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);\n const deltaC = c1 - c2;\n\n // difference in hue, deltaH, which takes into account both the differences\n // in the a* and b* components of LAB and the differences in chroma.\n let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;\n deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);\n\n const sc = 1.0 + 0.045 * c1;\n const sh = 1.0 + 0.015 * c1;\n\n // It applies weighting factors to the differences in lightness (deltaL),\n // chroma (deltaC), and hue (deltaH).\n const deltaLKlsl = deltaL / (1.0);\n const deltaCkcsc = deltaC / (sc);\n const deltaHkhsh = deltaH / (sh);\n\n // It computes the final color difference using the CIE76 formula:\n // deltaE = sqrt(deltaLKlsl^2 + deltaCkcsc^2 + deltaHkhsh^2),\n // where deltaLKlsl is the weighted lightness difference,\n // deltaCkcsc is the weighted chroma difference,\n // and deltaHkhsh is the weighted hue difference.\n const i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;\n\n // It returns the calculated color difference,\n // optionally rounded to the specified number of decimal places.\n return i < 0 ? 0 : Math.sqrt(i);\n};\n", "import { Vector2 } from '../types';\n\n/**\n * Speed = how far something moves in a given amount of time.\n * Speed is also a vector:\n * magnitude = distance\n * direction = time\n */\nexport type Speed = Vector2;\n\n/**\n * Velocity is a measure of how fast an object is moving in a particular direction.\n * Velocity = Distance traveled / Time taken\n * It has a magnitude and direction, and can be represented as a vector.\n */\nexport type Velocity = Vector2;\n\n/**\n * Acceleration is a measure of how quickly an object's velocity changes over time.\n * Acceleration = (Final velocity - Initial velocity) / Time taken\n * a = (vf - v0)/t.\n * Distance = Initial velocity * time + (acceleration * time^2) / 2\n * It also has a magnitude and direction, and can be represented as a vector.\n * When the direction is negative ----> it's a \"slowdown\" movement\n */\nexport type Acceleration = Vector2;\n\n/**\n * Gravity is the force that attracts two objects with mass toward each other.\n * Newton's law of universal gravitation formula:\n * Gravitational force = (Gravitational constant * Mass of object 1 * Mass of object 2) / Distance between objects^2\n * It also has a magnitude and direction, and can be represented as a vector.\n * magnitude = the strength of the gravitational force\n * direction = the direction in which the force is acting (the direction of the gravitational force is always toward the center of mass of the objects involved)\n */\nexport type Gravity = Vector2;\n\n", "/**\n * guid like '932ade5e-c515-4807-ac01-73b20ab3fb66'\n */\nexport const guid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0;\n return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);\n });\n};\n\n/**\n * id like 'df4unio1opulby2uqh4'\n */\nexport const newId = () => {\n return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);\n};\n", "import { ICircle, IPolygon, IRect, Matrix2, Vector2 } from '../types';\nimport { mod } from './other';\nimport { v2GetNormal, v2DotProduct } from './linear-algebra/vector';\n\n/**\n * Rectangles collision detection.\n * Rectangles should not be rotated.\n * The algorithm works by ensuring there is no gap between any of the 4 sides of the rectangles.\n * Any gap means a collision does not exist.\n * Returns true if collision is detected.\n */\nexport const rectCollide = (rect1: IRect, rect2: IRect) : boolean => {\n return rect1.x <= rect2.x + rect2.w &&\n rect1.x + rect1.w >= rect2.x &&\n rect1.y <= rect2.y + rect2.h &&\n rect1.h + rect1.y >= rect2.y;\n};\n\n/**\n * Circles collision detection.\n * This algorithm works by taking the center points of the two circles\n * and ensuring the distance between the center points\n * are less than the two radii added together.\n * Returns true if collision is detected.\n */\nexport const circleCollide = (circle1: ICircle, circle2: ICircle) => {\n const dx = Math.abs(circle1.cx - circle2.cx);\n const dy = Math.abs(circle1.cy - circle2.cy);\n const distance = Math.sqrt(dx * dx + dy * dy);\n return distance <= circle1.r + circle2.r;\n};\n\n//-------------------- Separating Axis Theorem (SAT) Collision detection -------------------------\n\nconst getEdges = (poly: IPolygon) : Matrix2[] => {\n const edges: Matrix2[] = [];\n\n for(let i= 0; i {\n const edges: Matrix2[] = [];\n\n // collect polygon edges, and combine then into a single array\n edges.push(...getEdges(poly1));\n edges.push(...getEdges(poly2));\n\n // for each edge, find the normal vector and project both polygons onto it\n for (const edge of edges) {\n const normal = v2GetNormal(edge[0], edge[1]);\n const p1Proj = projectPolygon(poly1, normal);\n const p2Proj = projectPolygon(poly2, normal);\n\n // Check if the projections overlap\n const isOverlap = p1Proj.max >= p2Proj.min && p2Proj.max >= p1Proj.min;\n\n // Check if the projections overlap; if not, the polygons do not collide\n if (!isOverlap) return false;\n }\n\n // If all tests pass, the polygons overlap and collide\n return true;\n};\n\n/**\n * Project every polygon point onto the normal.\n * Then find min and max.\n */\nconst projectPolygon = (polygon: IPolygon, normal: Vector2): { min: number, max: number } => {\n let min = Infinity;\n let max = -Infinity;\n\n // Project each vertex of the polygon onto the axis\n for (const vertex of polygon) {\n const projection = v2DotProduct(vertex, normal);\n min = Math.min(min, projection);\n max = Math.max(max, projection);\n }\n\n return { min, max };\n};", "export interface IAnimationProps {\n duration?: number;\n callback: (result: IAnimationResult) => void;\n restartOnResize?: boolean;\n resizeCallback?: (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => void;\n}\n\nexport interface IAnimationResult {\n start: () => void;\n stop: () => void;\n pause: () => void;\n resume: () => void;\n restart: () => void;\n isAnimating: () => boolean;\n getStartTime: () => number|undefined;\n getElapsedTime: () => number|undefined;\n getPercent: () => number|undefined;\n getResizeObserver: () => ResizeObserver|undefined;\n}\n\nexport const animate = (props: IAnimationProps) : IAnimationResult => {\n\n const _duration = props.duration !== undefined ? props.duration : Infinity;\n\n let startTime: number|undefined = undefined; // in milliseconds\n let animationId: number|undefined = undefined;\n\n // the time elapsed since the start of the animation (in milliseconds)\n let elapsed: number|undefined = undefined;\n let previousTimeStamp: number|undefined = undefined;\n\n let animating = false;\n let observer: ResizeObserver|undefined = undefined;\n\n // -------------------- COMMANDS ---------------------\n\n const stop = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = false;\n\n /*if(observer !== undefined){\n observer.disconnect();\n observer = undefined;\n }*/\n\n if(animationId === undefined) return;\n window.cancelAnimationFrame(animationId);\n };\n\n const restart = () => {\n stop();\n start();\n };\n\n const pause = () => {\n animating = false;\n };\n\n const resume = () => {\n animating = true;\n };\n\n /**\n * Animation Step.\n * @param {number} timeStamp in milliseconds\n */\n const step = (timeStamp: DOMHighResTimeStamp) => {\n\n if (startTime === undefined) {\n startTime = timeStamp;\n }\n\n // the time elapsed since the start of the animation (in milliseconds)\n elapsed = timeStamp - startTime;\n\n if (animating && previousTimeStamp !== timeStamp && typeof props.callback === 'function') {\n\n // do the rendering .............\n props.callback(getResult());\n }\n\n if(elapsed <= _duration){\n previousTimeStamp = timeStamp;\n animationId = window.requestAnimationFrame(step);\n }\n else{\n stop();\n }\n };\n\n const observerHandler = (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => {\n restart();\n\n if(typeof props.resizeCallback === 'function'){\n props.resizeCallback(_entries, _observer);\n }\n };\n\n const start = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = true;\n\n if(props.restartOnResize && window.ResizeObserver && observer === undefined){\n observer = new ResizeObserver(observerHandler);\n observer.observe(document.body, { box: 'border-box' });\n }\n else{\n animationId = window.requestAnimationFrame(step);\n }\n };\n\n // --------------- GET INFO ----------------------\n\n /**\n * the time elapsed since the start of the animation (in milliseconds)\n */\n const getElapsedTime = () : number|undefined => {\n return elapsed;\n };\n\n const isAnimating = () => {\n return animating;\n };\n\n const getStartTime = () => {\n return startTime;\n };\n\n const getPercent = () => {\n if(_duration === Infinity || elapsed === undefined) return undefined;\n return elapsed * 100 / _duration;\n };\n\n const getResizeObserver = () => {\n return observer;\n };\n\n const getResult = () : IAnimationResult => {\n return {\n\n // commands --------------\n start,\n stop,\n pause,\n resume,\n restart,\n\n // information -------\n isAnimating,\n getElapsedTime,\n getStartTime,\n getPercent,\n getResizeObserver,\n };\n };\n\n return getResult();\n};\n", "import { setDecimalPlaces } from './format';\n\nexport const getCircleCircumference = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * radius, decimalPlaces);\n};\n\nexport const getEllipseCircumference = (radius1: number, radius2: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * Math.sqrt((radius1 ** 2 + radius2 ** 2) / 2), decimalPlaces);\n};\n\nexport const isAngleInCircleArc = (startAngleDeg: number, endAngleDeg: number, currentDegrees: number) : boolean => {\n\n if(startAngleDeg > endAngleDeg) {\n endAngleDeg += 360;\n }\n\n return currentDegrees >= startAngleDeg && currentDegrees <= endAngleDeg ||\n (currentDegrees + 360) >= startAngleDeg && (currentDegrees + 360) <= endAngleDeg;\n};\n\n/**\n * get the side of a square inscribed in a circle\n */\nexport const getSquareInCircleSide = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(radius * 2 / Math.sqrt(2), decimalPlaces);\n};\n", "/**\n * 1 + 2 + ... + n = n * (n + 1) / 2\n */\nexport const naturalNumbersSequenceSum = (n: number) => {\n return n * (n + 1) / 2;\n};\n\n/**\n * n = the number of terms to be added\n * a = the first term in the sequence\n * d = the constant value between terms\n */\nexport const arithmeticSequenceSum = (n: number, a: number, d: number) => {\n return (n / 2) * (2 * a + (n - 1) * d);\n};", "import { setDecimalPlaces } from './format';\n\n// -------------------- CENTRAL TENDENCY ----------------------------\n\n/**\n * Central tendency: Calculate the Average (mean)\n * Sum of all numbers divided by the array length.\n */\nexport const getArithmeticMean = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const sum = data.reduce((acc, val) => acc + val, 0);\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};\n\n/**\n * Central tendency: What is the central number in the sorted array?\n * Good for lists like [3, 3, 3, 3, 3, 3, 100] - 100 here is called \"Outlier\"\n */\nexport const getMedian = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const copy = [...data].sort((num1, num2) => num1 - num2);\n const mid = Math.floor(copy.length / 2);\n\n if(copy.length % 2 === 0) {\n return setDecimalPlaces((copy[mid] + copy[mid - 1]) / 2, decimalPlaces);\n }\n else {\n return setDecimalPlaces(copy[mid], decimalPlaces);\n }\n};\n\n/**\n * Central tendency: What number is most common in the set.\n * If all numbers have the same frequency, there is no mode.\n */\nexport const getMode = (data: number[]) : number[]|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n // Count frequency of each number in the data array.\n const frequencyMap: Map = new Map();\n for (const num of data) {\n frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);\n }\n\n let maxFrequency = 0;\n let modes: number[] = [];\n\n // Find the maximum frequency\n for (const [num, frequency] of frequencyMap) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency;\n modes = [num];\n }\n else if (frequency === maxFrequency) {\n modes.push(num);\n }\n }\n\n // If all numbers have the same frequency, there is no mode\n if (modes.length === data.length) {\n return undefined;\n }\n\n // Return the mode(s)\n return modes.length === 1 ? [modes[0]] : modes;\n};\n\n/*\nTODO:\n- geometric mean\n- harmonic mean\n */\n\n// -------------------- DISPERSION ----------------------------\n\n/**\n * Dispersion: the average square distance from the mean.\n */\nexport const getVariance = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const mean = getArithmeticMean(data);\n if(mean === undefined) return undefined;\n\n const sum = data.reduce((acc, val) => acc + ((val - mean) ** 2), 0);\n\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a copy of array, where each value will be in the range [0, 1].\n * const newValue = (value - array_min) / (array_max - array_min)\n */\nexport const mlNormalize = (data: number[], decimalPlaces = Infinity): number[] => {\n const copy = [...data];\n\n const min = Math.min(...copy);\n const max = Math.max(...copy);\n\n const diff = max - min;\n if(diff === 0) return [0];\n\n for(let i=0; i{for(var e in r)Z(t,e,{get:r[e],enumerable:!0})},cr=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of nr(r))!or.call(t,o)&&o!==e&&Z(t,o,{get:()=>r[o],enumerable:!(n=er(r,o))||n.enumerable});return t};var sr=t=>cr(Z({},"__esModule",{value:!0}),t);var Vo={};ir(Vo,{animate:()=>so,arithmeticSequenceSum:()=>po,circleCollide:()=>io,circleMovement:()=>Ft,circleMovementAfterMouse:()=>qn,convertRange:()=>j,convexPolygonsCollide:()=>co,degreesToRadians:()=>fr,doRangesOverlap:()=>ur,dxArcCos:()=>ln,dxArcCot:()=>dn,dxArcSin:()=>yn,dxArcTan:()=>In,dxCos:()=>hn,dxCot:()=>Vn,dxPolynomial:()=>pn,dxSin:()=>Mn,dxTan:()=>bn,dxV2CubicBezierCurve:()=>yt,dxV2QuadraticBezierCurve:()=>bt,dxV3CubicBezierCurve:()=>lt,dxV3QuadraticBezierCurve:()=>Vt,ellipseMovement:()=>Qt,ellipseMovementAfterMouse:()=>An,getAnglesDistance:()=>wt,getAnglesSub:()=>D,getArithmeticMean:()=>Ut,getCircleCircumference:()=>uo,getColorsDelta:()=>ro,getEllipseCircumference:()=>xo,getLinearEquationBy2Points:()=>Rn,getMedian:()=>Mo,getMode:()=>ho,getRandom:()=>b,getRandomBoolean:()=>an,getRandomGrayscaleHSLColor:()=>Dn,getRandomHSLColor:()=>gt,getRandomHSLColorWithHue:()=>Gn,getRandomHSLColorWithLightness:()=>jn,getRandomHSLColorWithSaturation:()=>On,getRandomHSLColorWithinRanges:()=>kn,getRandomHexColor:()=>Yn,getRandomInt:()=>Xt,getRandomItemFromArray:()=>mn,getRandomRGBColor:()=>Xn,getShiftedHue:()=>Un,getShiftedLightness:()=>Pn,getShiftedSaturation:()=>to,getSquareInCircleSide:()=>mo,getV2Angle:()=>T,getV2AngleBetween:()=>pr,getV2AngleInEllipse:()=>ar,getV3AngleBetween:()=>Mr,getVNAngleBetween:()=>Rt,getVariance:()=>bo,guid:()=>eo,hexToRgb:()=>Kn,hslToHex:()=>_t,hslToRgb:()=>Wt,identity2:()=>Wr,identity3:()=>_r,identity4:()=>Kr,identityN:()=>Jr,isAngleBetween:()=>hr,isAngleInCircleArc:()=>ao,isClockwise:()=>_,isNumber:()=>z,isSingularMatrix:()=>he,labToRgb:()=>Jn,linearEquation:()=>E,linearEquationSystem2:()=>vn,linearEquationSystem3:()=>gn,linearEquationSystemN:()=>Sn,lissajousCurve:()=>Cn,m2Adjugate:()=>mt,m2AppendRow:()=>re,m2DeepCopy:()=>it,m2Determinant:()=>at,m2DivideScalar:()=>zt,m2Inverse:()=>pt,m2MulScalar:()=>Cr,m2PrependRow:()=>oe,m2ReflectionOrigin:()=>Qe,m2ReflectionOriginH:()=>Ze,m2ReflectionX:()=>Je,m2ReflectionXH:()=>Ue,m2ReflectionY:()=>Pe,m2ReflectionYH:()=>tn,m2ReflectionYmX:()=>Ke,m2Reset:()=>jr,m2RotateAroundPointH:()=>ge,m2Rotation:()=>Bt,m2RotationAroundPointH:()=>Tt,m2RotationH:()=>ht,m2Scale:()=>At,m2ScaleAtPointH:()=>$e,m2ScaleAtPointHMatrix:()=>qt,m2ScaleH:()=>Nt,m2ScaleX:()=>Ne,m2ScaleXH:()=>Ce,m2ScaleY:()=>ke,m2ScaleYH:()=>Fe,m2ShearingX:()=>xn,m2ShearingY:()=>un,m2Sub:()=>Ar,m2Sum:()=>Er,m2ToCSS:()=>be,m2Translation:()=>Ie,m2TranslationH:()=>G,m2Transpose:()=>Gr,m2hToCSS:()=>Ve,m2hToCSS3d:()=>ye,m2x2:()=>kr,m3Adjugate:()=>Me,m3AppendRow:()=>ee,m3DeepCopy:()=>ct,m3Determinant:()=>pe,m3DivideScalar:()=>Yr,m3Inverse:()=>Mt,m3MulScalar:()=>Xr,m3PrependRow:()=>ie,m3ReflectionOrigin:()=>We,m3ReflectionOriginH:()=>_e,m3ReflectionXY:()=>cn,m3ReflectionXYH:()=>sn,m3ReflectionXZ:()=>nn,m3ReflectionXZH:()=>on,m3ReflectionYZ:()=>rn,m3ReflectionYZH:()=>en,m3Reset:()=>Dr,m3RotationX:()=>Lt,m3RotationXH:()=>we,m3RotationY:()=>$t,m3RotationYH:()=>ze,m3RotationZ:()=>Et,m3RotationZH:()=>Te,m3Scale:()=>Ct,m3ScaleH:()=>qe,m3ScaleX:()=>Xe,m3ScaleXH:()=>Ye,m3ScaleY:()=>Ge,m3ScaleYH:()=>Oe,m3ScaleZ:()=>je,m3ScaleZH:()=>De,m3Sub:()=>Nr,m3Sum:()=>qr,m3Translation:()=>de,m3TranslationH:()=>ve,m3Transpose:()=>Or,m3hToCSS3d:()=>le,m3x3:()=>Fr,m4x4:()=>Qr,mAdjugate:()=>ft,mAppendCol:()=>Ur,mAppendRow:()=>te,mDeepCopy:()=>l,mDelFirstColumn:()=>ue,mDelFirstRow:()=>se,mDelLastColumn:()=>st,mDelLastRow:()=>ce,mDeterminant:()=>Y,mDivideScalar:()=>F,mEqual:()=>me,mGetColumn:()=>ae,mGetFirstColumn:()=>xe,mGetLastColumn:()=>ut,mInverse:()=>Q,mMinor:()=>xt,mMul:()=>$,mMulScalar:()=>nt,mMulVector:()=>h,mNxM:()=>Zr,mPrependCol:()=>Pr,mPrependRow:()=>ne,mReset:()=>ot,mSub:()=>et,mSum:()=>rt,mTranspose:()=>X,mod:()=>y,naturalNumbersSequenceSum:()=>fo,newId:()=>no,percentToAngle:()=>br,polarToCartesian:()=>xr,radiansToDegrees:()=>mr,rectCollide:()=>oo,rgbToHex:()=>_n,rgbToHsl:()=>Wn,rgbToLab:()=>vt,setDecimalPlaces:()=>s,setV2Angle:()=>W,sineWaveMovement:()=>Nn,stringToNumber:()=>fn,v2:()=>Br,v2CubicBezierBBox:()=>En,v2CubicBezierCurve:()=>Gt,v2CubicBezierCurveExtrema:()=>kt,v2CubicBezierCurveNormal:()=>Ln,v2CubicBezierCurveTangent:()=>jt,v2Distance:()=>Rr,v2DivideScalar:()=>dr,v2DotProduct:()=>J,v2FromPolarCoords:()=>$r,v2GetNormal:()=>tt,v2Length:()=>K,v2MulScalar:()=>Ir,v2Normalize:()=>L,v2QuadraticBezierBBox:()=>$n,v2QuadraticBezierCurve:()=>Yt,v2QuadraticBezierCurveExtrema:()=>Dt,v2QuadraticBezierCurveNormal:()=>Tn,v2QuadraticBezierCurveTangent:()=>Ot,v2Rotate:()=>Se,v2RotateH:()=>Re,v2Scale:()=>Ee,v2SetLength:()=>Ht,v2Sub:()=>R,v2Sum:()=>Vr,v3:()=>Tr,v3CrossProduct:()=>zr,v3CubicBezierCurve:()=>Hn,v3CubicBezierCurveTangent:()=>Bn,v3Distance:()=>wr,v3DivideScalar:()=>vr,v3DotProduct:()=>Hr,v3Length:()=>gr,v3MulScalar:()=>k,v3Normalize:()=>v,v3QuadraticBezierCurve:()=>wn,v3QuadraticBezierCurveTangent:()=>zn,v3RotateX:()=>He,v3RotateY:()=>Be,v3RotateZ:()=>Le,v3Scale:()=>Ae,v3Sub:()=>lr,v3Sum:()=>yr,v4:()=>Lr,vDistance:()=>Sr,vDivideScalar:()=>C,vDotProduct:()=>S,vEqual:()=>P,vLength:()=>w,vMulScalar:()=>N,vN:()=>U,vNormalize:()=>B,vSub:()=>d,vSum:()=>A});module.exports=sr(Vo);var s=(t,r=1/0)=>{if(r===1/0)return t;r<0&&(r=0);let e=V(10,r);return Math.round(t*e)/e};var y=(t,r)=>(t%r+r)%r,j=(t,r,e,n,o)=>(o-n)*(t-r)/(e-r)+n,ur=(t,r,e,n)=>Math.max(t,e)<=Math.min(r,n),z=t=>!isNaN(parseFloat(t))&&isFinite(t),xr=(t,r,e,n=1/0)=>{let[o,i]=t,[c,u]=r;return[s(o+c*Math.cos(e),n),s(i+u*Math.sin(e),n)]};var T=(t,r=1/0)=>{let e=Math.atan2(t[1],t[0]);return s(e,r)},ar=(t,r,e=1/0)=>{let n=Math.atan2(t[1]/r[1],t[0]/r[0]);return s(n,e)},W=(t,r,e=1/0)=>{let n=K(t);return[s(Math.cos(r)*n,e),s(Math.sin(r)*n,e)]},mr=(t,r=1/0)=>{let e=t*(180/Math.PI);return s(e,r)},fr=(t,r=1/0)=>{let e=t*(Math.PI/180);return s(e,r)},Rt=(t,r,e=1/0)=>{let n=B(t),o=B(r),i=S(n,o),c=Math.acos(i);return s(c,e)},pr=(t,r,e=1/0)=>{let n=d(t,r),o=Math.atan2(n[1],n[0]);return s(o,e)},Mr=(t,r,e=1/0)=>Rt(t,r,e),hr=(t,r,e)=>{let n=D(r,e),o=D(r,t),i=D(e,t),c=o+i;return Math.abs(c-n)<=.001},_=(t,r,e=0)=>(t=t%360,r=r%360,t=t),D=(t,r,e=1/0)=>{let n=Math.abs(y(t,360)-y(r,360));return s(n<=180?n:360-n,e)},wt=(t,r,e=0,n=1/0)=>(t=t%360,r=r%360,t{t<0&&(t=0),t>100&&(t=100);let o=wt(r,e,n);return _(r,e,n)?y(n+t*o/100,360):y(n-t*o/100,360)};var A=(t,r,e=1/0)=>{let n=[];for(let o=0;oA(t,r,e),yr=(t,r,e=1/0)=>A(t,r,e),d=(t,r,e=1/0)=>{let n=[];for(let o=0;od(t,r,e),lr=(t,r,e=1/0)=>d(t,r,e),N=(t,r,e=1/0)=>{let n=[];for(let o=0;oN(t,r,e),k=(t,r,e=1/0)=>N(t,r,e),C=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o=0;oC(t,r,e),vr=(t,r,e=1/0)=>C(t,r,e),w=(t,r=1/0)=>{let e=0;for(let n=0;nw(t,r),gr=(t,r=1/0)=>w(t,r),Ht=(t,r,e=1/0)=>{let n=T(t);return[s(Math.cos(n)*r,e),s(Math.sin(n)*r,e)]},Sr=(t,r,e=1/0)=>{let n=d(t,r);return w(n,e)},Rr=(t,r,e=1/0)=>{let n=d(t,r);return w(n,e)},wr=(t,r,e=1/0)=>{let n=d(t,r);return w(n,e)},B=(t,r=1/0)=>{let e=w(t),n=[];for(let o=0;oB(t,r),v=(t,r=1/0)=>B(t,r),S=(t,r,e=1/0)=>{let n=0;for(let o=0;oS(t,r,e),Hr=(t,r,e=1/0)=>S(t,r,e),zr=(t,r,e=1/0)=>[s(t[1]*r[2]-t[2]*r[1],e),s(t[2]*r[0]-t[0]*r[2],e),s(t[0]*r[1]-t[1]*r[0],e)],Br=(t=0)=>[t,t],Tr=(t=0)=>[t,t,t],Lr=(t=0)=>[t,t,t,t],U=(t,r=0)=>{if(t<0)throw new Error("N must be a non-negative number.");let e=[];for(let n=0;n{let e=[0,0];return e=Ht(e,t),W(e,r)},P=(t,r)=>{if(t.length!==r.length)return!1;for(let e=0;e{let n=R(r,t);return[-s(n[1],e),s(n[0],e)]};var rt=(t,r,e=1/0)=>{let n=[];for(let o=0;ort(t,r,e),qr=(t,r,e=1/0)=>rt(t,r,e),et=(t,r,e=1/0)=>{let n=[];for(let o=0;oet(t,r,e),Nr=(t,r,e=1/0)=>et(t,r,e),nt=(t,r,e=1/0)=>{let n=[];for(let o of t)n.push(N(o,r,e));return n},Cr=(t,r,e=1/0)=>nt(t,r,e),Xr=(t,r,e=1/0)=>nt(t,r,e),F=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o of t)n.push(C(o,r,e));return n},zt=(t,r,e=1/0)=>F(t,r,e),Yr=(t,r,e=1/0)=>F(t,r,e),X=t=>{let r=t.length;if(r<=0)return t;let e=t[0].length;if(e<=0)return t;let n=[];for(let o=0;oX(t),Or=t=>X(t),ot=(t,r=0)=>{if(t.length<=0)return[];let e=[];for(let n=0;not(t,r),Dr=(t,r=0)=>ot(t,r),kr=(t=0)=>[[t,t],[t,t]],Fr=(t=0)=>[[t,t,t],[t,t,t],[t,t,t]],Qr=(t=0)=>[[t,t,t,t],[t,t,t,t],[t,t,t,t],[t,t,t,t]],Zr=(t,r,e=0)=>{if(t<=0||r<=0)throw new Error("M and N must be positive numbers.");let n=[];for(let o=0;o[[1,0],[0,1]],_r=()=>[[1,0,0],[0,1,0],[0,0,1]],Kr=()=>[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Jr=t=>{if(t<0)throw new Error("N must be a non-negative number.");if(t===0)return[];let r=[];for(let e=0;e{let r=[];for(let e=0;el(t),ct=t=>l(t),Ur=(t,r)=>{if(t.length<=0)return[];let e=l(t);for(let n=0;n{if(t.length<=0)return[];let e=l(t);for(let n=0;n{let e=l(t);return e.push(r),e},re=(t,r)=>{let e=it(t);return e.push(r),e},ee=(t,r)=>{let e=ct(t);return e.push(r),e},ne=(t,r)=>{let e=l(t);return e.unshift(r),e},oe=(t,r)=>{let e=it(t);return e.unshift(r),e},ie=(t,r)=>{let e=ct(t);return e.unshift(r),e},ce=t=>{if(t.length<=0)return[];let r=l(t);return r.pop(),r},se=t=>{if(t.length<=0)return[];let r=l(t);return r.shift(),r},st=t=>{if(t.length<=0)return[];let r=l(t);for(let e=0;e{if(t.length<=0)return[];let r=l(t);for(let e=0;e{if(t.length<=0)return[];let r=[];for(let e=0;e{if(t.length<=0)return[];let r=t[0].length,e=[];for(let n=0;n{if(t.length<=0)return[];let e=[];for(let n=0;n{let n=[];for(let i=0;i{if(t.length<0)return[];if(t[0].length!==r.length)throw new Error("The number of columns in the matrix must be equal to the length of the vector.");let n=[];for(let o=0;o{if(t.length!==r.length)return!1;for(let e=0;e{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=[];for(let i=0;i{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=fe(t,r,e);return Y(o)},Y=t=>{let r=t.length;if(r===0)return 1;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t[0][0];if(r===2)return at(t);let e=0;for(let n=0;n{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return t[0][0]*t[1][1]-t[1][0]*t[0][1]},pe=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return Y(t)},mt=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return[[t[1][1],-t[0][1]],[-t[1][0],t[0][0]]]},Me=t=>ft(t),ft=t=>{let r=t.length;if(r<=0)return null;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t;if(r===2)return mt(t);let e=[];for(let n=0;n{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");return Y(t)===0},pt=(t,r=1/0)=>{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");let e=at(t);if(e===0)return null;let n=mt(t);return n===null?null:zt(n,e,r)},Mt=(t,r=1/0)=>Q(t,r),Q=(t,r=1/0)=>{let e=t.length;if(e>0&&e!==t[0].length)throw new Error("The matrix must be square.");let n=Y(t),o=ft(t);return o===null?null:F(o,n,r)};var be=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1];return`matrix(${r}, ${e}, ${n}, ${o}, 0, 0)`},Ve=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix(${r}, ${e}, ${n}, ${o}, ${i}, ${c})`},ye=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix3d(${r}, ${e}, 0, 0, ${n}, ${o}, 0, 0, 0, 0, 1, 0, ${i}, ${c}, 0, 1)`},le=t=>`matrix3d( +var Z=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var nr=Object.getOwnPropertyNames;var or=Object.prototype.hasOwnProperty;var V=Math.pow;var ir=(t,r)=>{for(var e in r)Z(t,e,{get:r[e],enumerable:!0})},cr=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of nr(r))!or.call(t,o)&&o!==e&&Z(t,o,{get:()=>r[o],enumerable:!(n=er(r,o))||n.enumerable});return t};var sr=t=>cr(Z({},"__esModule",{value:!0}),t);var yo={};ir(yo,{animate:()=>so,arithmeticSequenceSum:()=>po,circleCollide:()=>io,circleMovement:()=>Ft,circleMovementAfterMouse:()=>qn,convertRange:()=>j,convexPolygonsCollide:()=>co,degreesToRadians:()=>fr,doRangesOverlap:()=>ur,dxArcCos:()=>ln,dxArcCot:()=>dn,dxArcSin:()=>yn,dxArcTan:()=>In,dxCos:()=>hn,dxCot:()=>Vn,dxPolynomial:()=>pn,dxSin:()=>Mn,dxTan:()=>bn,dxV2CubicBezierCurve:()=>yt,dxV2QuadraticBezierCurve:()=>bt,dxV3CubicBezierCurve:()=>lt,dxV3QuadraticBezierCurve:()=>Vt,ellipseMovement:()=>Qt,ellipseMovementAfterMouse:()=>An,getAnglesDistance:()=>wt,getAnglesSub:()=>D,getArithmeticMean:()=>Ut,getCircleCircumference:()=>uo,getColorsDelta:()=>ro,getEllipseCircumference:()=>xo,getLinearEquationBy2Points:()=>Rn,getMedian:()=>Mo,getMode:()=>ho,getRandom:()=>b,getRandomBoolean:()=>an,getRandomGrayscaleHSLColor:()=>Dn,getRandomHSLColor:()=>gt,getRandomHSLColorWithHue:()=>Gn,getRandomHSLColorWithLightness:()=>jn,getRandomHSLColorWithSaturation:()=>On,getRandomHSLColorWithinRanges:()=>kn,getRandomHexColor:()=>Yn,getRandomInt:()=>Xt,getRandomItemFromArray:()=>mn,getRandomRGBColor:()=>Xn,getShiftedHue:()=>Un,getShiftedLightness:()=>Pn,getShiftedSaturation:()=>to,getSquareInCircleSide:()=>mo,getV2Angle:()=>T,getV2AngleBetween:()=>pr,getV2AngleInEllipse:()=>ar,getV3AngleBetween:()=>Mr,getVNAngleBetween:()=>Rt,getVariance:()=>bo,guid:()=>eo,hexToRgb:()=>Kn,hslToHex:()=>_t,hslToRgb:()=>Wt,identity2:()=>Wr,identity3:()=>_r,identity4:()=>Kr,identityN:()=>Jr,isAngleBetween:()=>hr,isAngleInCircleArc:()=>ao,isClockwise:()=>_,isNumber:()=>H,isSingularMatrix:()=>he,labToRgb:()=>Jn,linearEquation:()=>E,linearEquationSystem2:()=>vn,linearEquationSystem3:()=>gn,linearEquationSystemN:()=>Sn,lissajousCurve:()=>Cn,m2Adjugate:()=>mt,m2AppendRow:()=>re,m2DeepCopy:()=>it,m2Determinant:()=>at,m2DivideScalar:()=>Ht,m2Inverse:()=>pt,m2MulScalar:()=>Cr,m2PrependRow:()=>oe,m2ReflectionOrigin:()=>Qe,m2ReflectionOriginH:()=>Ze,m2ReflectionX:()=>Je,m2ReflectionXH:()=>Ue,m2ReflectionY:()=>Pe,m2ReflectionYH:()=>tn,m2ReflectionYmX:()=>Ke,m2Reset:()=>jr,m2RotateAroundPointH:()=>ge,m2Rotation:()=>Bt,m2RotationAroundPointH:()=>Tt,m2RotationH:()=>ht,m2Scale:()=>At,m2ScaleAtPointH:()=>$e,m2ScaleAtPointHMatrix:()=>qt,m2ScaleH:()=>Nt,m2ScaleX:()=>Ne,m2ScaleXH:()=>Ce,m2ScaleY:()=>ke,m2ScaleYH:()=>Fe,m2ShearingX:()=>xn,m2ShearingY:()=>un,m2Sub:()=>Ar,m2Sum:()=>Er,m2ToCSS:()=>be,m2Translation:()=>Ie,m2TranslationH:()=>G,m2Transpose:()=>Gr,m2hToCSS:()=>Ve,m2hToCSS3d:()=>ye,m2x2:()=>kr,m3Adjugate:()=>Me,m3AppendRow:()=>ee,m3DeepCopy:()=>ct,m3Determinant:()=>pe,m3DivideScalar:()=>Yr,m3Inverse:()=>Mt,m3MulScalar:()=>Xr,m3PrependRow:()=>ie,m3ReflectionOrigin:()=>We,m3ReflectionOriginH:()=>_e,m3ReflectionXY:()=>cn,m3ReflectionXYH:()=>sn,m3ReflectionXZ:()=>nn,m3ReflectionXZH:()=>on,m3ReflectionYZ:()=>rn,m3ReflectionYZH:()=>en,m3Reset:()=>Dr,m3RotationX:()=>Lt,m3RotationXH:()=>we,m3RotationY:()=>$t,m3RotationYH:()=>He,m3RotationZ:()=>Et,m3RotationZH:()=>Te,m3Scale:()=>Ct,m3ScaleH:()=>qe,m3ScaleX:()=>Xe,m3ScaleXH:()=>Ye,m3ScaleY:()=>Ge,m3ScaleYH:()=>Oe,m3ScaleZ:()=>je,m3ScaleZH:()=>De,m3Sub:()=>Nr,m3Sum:()=>qr,m3Translation:()=>de,m3TranslationH:()=>ve,m3Transpose:()=>Or,m3hToCSS3d:()=>le,m3x3:()=>Fr,m4x4:()=>Qr,mAdjugate:()=>ft,mAppendCol:()=>Ur,mAppendRow:()=>te,mDeepCopy:()=>l,mDelFirstColumn:()=>ue,mDelFirstRow:()=>se,mDelLastColumn:()=>st,mDelLastRow:()=>ce,mDeterminant:()=>Y,mDivideScalar:()=>F,mEqual:()=>me,mGetColumn:()=>ae,mGetFirstColumn:()=>xe,mGetLastColumn:()=>ut,mInverse:()=>Q,mMinor:()=>xt,mMul:()=>$,mMulScalar:()=>nt,mMulVector:()=>h,mNxM:()=>Zr,mPrependCol:()=>Pr,mPrependRow:()=>ne,mReset:()=>ot,mSub:()=>et,mSum:()=>rt,mTranspose:()=>X,mlNormalize:()=>Vo,mod:()=>y,naturalNumbersSequenceSum:()=>fo,newId:()=>no,percentToAngle:()=>br,polarToCartesian:()=>xr,radiansToDegrees:()=>mr,rectCollide:()=>oo,rgbToHex:()=>_n,rgbToHsl:()=>Wn,rgbToLab:()=>vt,setDecimalPlaces:()=>s,setV2Angle:()=>W,sineWaveMovement:()=>Nn,stringToNumber:()=>fn,v2:()=>Br,v2CubicBezierBBox:()=>En,v2CubicBezierCurve:()=>Gt,v2CubicBezierCurveExtrema:()=>kt,v2CubicBezierCurveNormal:()=>Ln,v2CubicBezierCurveTangent:()=>jt,v2Distance:()=>Rr,v2DivideScalar:()=>dr,v2DotProduct:()=>J,v2FromPolarCoords:()=>$r,v2GetNormal:()=>tt,v2Length:()=>K,v2MulScalar:()=>Ir,v2Normalize:()=>L,v2QuadraticBezierBBox:()=>$n,v2QuadraticBezierCurve:()=>Yt,v2QuadraticBezierCurveExtrema:()=>Dt,v2QuadraticBezierCurveNormal:()=>Tn,v2QuadraticBezierCurveTangent:()=>Ot,v2Rotate:()=>Se,v2RotateH:()=>Re,v2Scale:()=>Ee,v2SetLength:()=>zt,v2Sub:()=>R,v2Sum:()=>Vr,v3:()=>Tr,v3CrossProduct:()=>Hr,v3CubicBezierCurve:()=>zn,v3CubicBezierCurveTangent:()=>Bn,v3Distance:()=>wr,v3DivideScalar:()=>vr,v3DotProduct:()=>zr,v3Length:()=>gr,v3MulScalar:()=>k,v3Normalize:()=>v,v3QuadraticBezierCurve:()=>wn,v3QuadraticBezierCurveTangent:()=>Hn,v3RotateX:()=>ze,v3RotateY:()=>Be,v3RotateZ:()=>Le,v3Scale:()=>Ae,v3Sub:()=>lr,v3Sum:()=>yr,v4:()=>Lr,vDistance:()=>Sr,vDivideScalar:()=>C,vDotProduct:()=>S,vEqual:()=>P,vLength:()=>w,vMulScalar:()=>N,vN:()=>U,vNormalize:()=>B,vSub:()=>d,vSum:()=>A});module.exports=sr(yo);var s=(t,r=1/0)=>{if(r===1/0)return t;r<0&&(r=0);let e=V(10,r);return Math.round(t*e)/e};var y=(t,r)=>(t%r+r)%r,j=(t,r,e,n,o)=>(o-n)*(t-r)/(e-r)+n,ur=(t,r,e,n)=>Math.max(t,e)<=Math.min(r,n),H=t=>!isNaN(parseFloat(t))&&isFinite(t),xr=(t,r,e,n=1/0)=>{let[o,i]=t,[c,u]=r;return[s(o+c*Math.cos(e),n),s(i+u*Math.sin(e),n)]};var T=(t,r=1/0)=>{let e=Math.atan2(t[1],t[0]);return s(e,r)},ar=(t,r,e=1/0)=>{let n=Math.atan2(t[1]/r[1],t[0]/r[0]);return s(n,e)},W=(t,r,e=1/0)=>{let n=K(t);return[s(Math.cos(r)*n,e),s(Math.sin(r)*n,e)]},mr=(t,r=1/0)=>{let e=t*(180/Math.PI);return s(e,r)},fr=(t,r=1/0)=>{let e=t*(Math.PI/180);return s(e,r)},Rt=(t,r,e=1/0)=>{let n=B(t),o=B(r),i=S(n,o),c=Math.acos(i);return s(c,e)},pr=(t,r,e=1/0)=>{let n=d(t,r),o=Math.atan2(n[1],n[0]);return s(o,e)},Mr=(t,r,e=1/0)=>Rt(t,r,e),hr=(t,r,e)=>{let n=D(r,e),o=D(r,t),i=D(e,t),c=o+i;return Math.abs(c-n)<=.001},_=(t,r,e=0)=>(t=t%360,r=r%360,t=t),D=(t,r,e=1/0)=>{let n=Math.abs(y(t,360)-y(r,360));return s(n<=180?n:360-n,e)},wt=(t,r,e=0,n=1/0)=>(t=t%360,r=r%360,t{t<0&&(t=0),t>100&&(t=100);let o=wt(r,e,n);return _(r,e,n)?y(n+t*o/100,360):y(n-t*o/100,360)};var A=(t,r,e=1/0)=>{let n=[];for(let o=0;oA(t,r,e),yr=(t,r,e=1/0)=>A(t,r,e),d=(t,r,e=1/0)=>{let n=[];for(let o=0;od(t,r,e),lr=(t,r,e=1/0)=>d(t,r,e),N=(t,r,e=1/0)=>{let n=[];for(let o=0;oN(t,r,e),k=(t,r,e=1/0)=>N(t,r,e),C=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o=0;oC(t,r,e),vr=(t,r,e=1/0)=>C(t,r,e),w=(t,r=1/0)=>{let e=0;for(let n=0;nw(t,r),gr=(t,r=1/0)=>w(t,r),zt=(t,r,e=1/0)=>{let n=T(t);return[s(Math.cos(n)*r,e),s(Math.sin(n)*r,e)]},Sr=(t,r,e=1/0)=>{let n=d(t,r);return w(n,e)},Rr=(t,r,e=1/0)=>{let n=d(t,r);return w(n,e)},wr=(t,r,e=1/0)=>{let n=d(t,r);return w(n,e)},B=(t,r=1/0)=>{let e=w(t),n=[];for(let o=0;oB(t,r),v=(t,r=1/0)=>B(t,r),S=(t,r,e=1/0)=>{let n=0;for(let o=0;oS(t,r,e),zr=(t,r,e=1/0)=>S(t,r,e),Hr=(t,r,e=1/0)=>[s(t[1]*r[2]-t[2]*r[1],e),s(t[2]*r[0]-t[0]*r[2],e),s(t[0]*r[1]-t[1]*r[0],e)],Br=(t=0)=>[t,t],Tr=(t=0)=>[t,t,t],Lr=(t=0)=>[t,t,t,t],U=(t,r=0)=>{if(t<0)throw new Error("N must be a non-negative number.");let e=[];for(let n=0;n{let e=[0,0];return e=zt(e,t),W(e,r)},P=(t,r)=>{if(t.length!==r.length)return!1;for(let e=0;e{let n=R(r,t);return[-s(n[1],e),s(n[0],e)]};var rt=(t,r,e=1/0)=>{let n=[];for(let o=0;ort(t,r,e),qr=(t,r,e=1/0)=>rt(t,r,e),et=(t,r,e=1/0)=>{let n=[];for(let o=0;oet(t,r,e),Nr=(t,r,e=1/0)=>et(t,r,e),nt=(t,r,e=1/0)=>{let n=[];for(let o of t)n.push(N(o,r,e));return n},Cr=(t,r,e=1/0)=>nt(t,r,e),Xr=(t,r,e=1/0)=>nt(t,r,e),F=(t,r,e=1/0)=>{if(r===0)throw new Error("Division by zero error.");let n=[];for(let o of t)n.push(C(o,r,e));return n},Ht=(t,r,e=1/0)=>F(t,r,e),Yr=(t,r,e=1/0)=>F(t,r,e),X=t=>{let r=t.length;if(r<=0)return t;let e=t[0].length;if(e<=0)return t;let n=[];for(let o=0;oX(t),Or=t=>X(t),ot=(t,r=0)=>{if(t.length<=0)return[];let e=[];for(let n=0;not(t,r),Dr=(t,r=0)=>ot(t,r),kr=(t=0)=>[[t,t],[t,t]],Fr=(t=0)=>[[t,t,t],[t,t,t],[t,t,t]],Qr=(t=0)=>[[t,t,t,t],[t,t,t,t],[t,t,t,t],[t,t,t,t]],Zr=(t,r,e=0)=>{if(t<=0||r<=0)throw new Error("M and N must be positive numbers.");let n=[];for(let o=0;o[[1,0],[0,1]],_r=()=>[[1,0,0],[0,1,0],[0,0,1]],Kr=()=>[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Jr=t=>{if(t<0)throw new Error("N must be a non-negative number.");if(t===0)return[];let r=[];for(let e=0;e{let r=[];for(let e=0;el(t),ct=t=>l(t),Ur=(t,r)=>{if(t.length<=0)return[];let e=l(t);for(let n=0;n{if(t.length<=0)return[];let e=l(t);for(let n=0;n{let e=l(t);return e.push(r),e},re=(t,r)=>{let e=it(t);return e.push(r),e},ee=(t,r)=>{let e=ct(t);return e.push(r),e},ne=(t,r)=>{let e=l(t);return e.unshift(r),e},oe=(t,r)=>{let e=it(t);return e.unshift(r),e},ie=(t,r)=>{let e=ct(t);return e.unshift(r),e},ce=t=>{if(t.length<=0)return[];let r=l(t);return r.pop(),r},se=t=>{if(t.length<=0)return[];let r=l(t);return r.shift(),r},st=t=>{if(t.length<=0)return[];let r=l(t);for(let e=0;e{if(t.length<=0)return[];let r=l(t);for(let e=0;e{if(t.length<=0)return[];let r=[];for(let e=0;e{if(t.length<=0)return[];let r=t[0].length,e=[];for(let n=0;n{if(t.length<=0)return[];let e=[];for(let n=0;n{let n=[];for(let i=0;i{if(t.length<0)return[];if(t[0].length!==r.length)throw new Error("The number of columns in the matrix must be equal to the length of the vector.");let n=[];for(let o=0;o{if(t.length!==r.length)return!1;for(let e=0;e{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=[];for(let i=0;i{let n=t.length;if(n<=0)throw new Error("The matrix should not be empty.");if(n!==t[0].length)throw new Error("The matrix must be square.");let o=fe(t,r,e);return Y(o)},Y=t=>{let r=t.length;if(r===0)return 1;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t[0][0];if(r===2)return at(t);let e=0;for(let n=0;n{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return t[0][0]*t[1][1]-t[1][0]*t[0][1]},pe=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return Y(t)},mt=t=>{if(t.length!==t[0].length)throw new Error("The matrix must be square.");return[[t[1][1],-t[0][1]],[-t[1][0],t[0][0]]]},Me=t=>ft(t),ft=t=>{let r=t.length;if(r<=0)return null;if(r!==t[0].length)throw new Error("The matrix must be square.");if(r===1)return t;if(r===2)return mt(t);let e=[];for(let n=0;n{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");return Y(t)===0},pt=(t,r=1/0)=>{if(t.length>0&&t.length!==t[0].length)throw new Error("The matrix must be square.");let e=at(t);if(e===0)return null;let n=mt(t);return n===null?null:Ht(n,e,r)},Mt=(t,r=1/0)=>Q(t,r),Q=(t,r=1/0)=>{let e=t.length;if(e>0&&e!==t[0].length)throw new Error("The matrix must be square.");let n=Y(t),o=ft(t);return o===null?null:F(o,n,r)};var be=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1];return`matrix(${r}, ${e}, ${n}, ${o}, 0, 0)`},Ve=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix(${r}, ${e}, ${n}, ${o}, ${i}, ${c})`},ye=t=>{let r=t[0][0],e=t[1][0],n=t[0][1],o=t[1][1],i=t[0][2],c=t[1][2];return`matrix3d(${r}, ${e}, 0, 0, ${n}, ${o}, 0, 0, 0, 0, 1, 0, ${i}, ${c}, 0, 1)`},le=t=>`matrix3d( ${t[0][0]}, ${t[0][1]}, ${t[0][2]}, ${t[0][3]}, ${t[1][0]}, ${t[1][1]}, ${t[1][2]}, ${t[1][3]}, ${t[2][0]}, ${t[2][1]}, ${t[2][2]}, ${t[2][3]}, ${t[3][0]}, ${t[3][1]}, ${t[3][2]}, ${t[3][3]} - )`,Ie=(t,r=1/0)=>[[1,0],[0,1],[s(t[0],r),s(t[1],r)]],de=(t,r=1/0)=>[[1,0,0],[0,1,0],[0,0,1],[s(t[0],r),s(t[1],r),s(t[2],r)]],G=(t,r=1/0)=>[[1,0,s(t[0],r)],[0,1,s(t[1],r)],[0,0,1]],ve=(t,r=1/0)=>[[1,0,0,s(t[0],r)],[0,1,0,s(t[1],r)],[0,0,1,s(t[2],r)],[0,0,0,1]],Bt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o],[o,n]]:[[n,o],[-o,n]]},ht=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Tt=(t,r,e=!0,n=1/0)=>{let o=G(r,n),i=ht(t,e,n),c=G(k(r,-1),n),u=$(o,i);return $(u,c)},ge=(t,r,e,n=!0,o=1/0)=>{let i=Tt(t,r,n,o);return h(i,e)},Se=(t,r,e=!0,n=1/0)=>{let o=L(r);return h(Bt(t,e,n),o)},Re=(t,r,e=!0,n=1/0)=>{let o=v(r);return h(ht(t,e,n),o)},Lt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0],[0,n,-o],[0,o,n]]:[[1,0,0],[0,n,o],[0,-o,n]]},we=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0,0],[0,n,-o,0],[0,o,n,0],[0,0,0,1]]:[[1,0,0,0],[0,n,o,0],[0,-o,n,0],[0,0,0,1]]},He=(t,r,e=!0,n=1/0)=>{let o=v(r);return h(Lt(t,e,n),o)},$t=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o],[0,1,0],[-o,0,n]]:[[n,0,-o],[0,1,0],[o,0,n]]},ze=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o,0],[0,1,0,0],[-o,0,n,0],[0,0,0,1]]:[[n,0,-o,0],[0,1,0,0],[o,0,n,0],[0,0,0,1]]},Be=(t,r,e=!0,n=1/0)=>{let o=v(r);return h($t(t,e,n),o)},Et=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Te=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0,0],[o,n,0,0],[0,0,1,0],[0,0,0,1]]:[[n,o,0,0],[-o,n,0,0],[0,0,1,0],[0,0,0,1]]},Le=(t,r,e=!0,n=1/0)=>{let o=v(r);return h(Et(t,e,n),o)},qt=(t,r,e=1/0)=>{let n=G(r,e),o=Nt(t),i=G(k(r,-1),e),c=$(n,o);return $(c,i)},$e=(t,r,e,n=1/0)=>{let o=qt(t,r,n);return h(o,e)},At=t=>[[t[0],0],[0,t[1]]],Ee=(t,r)=>h(At(t),r),Nt=t=>[[t[0],0,0],[0,t[1],0],[0,0,1]],Ct=t=>[[t[0],0,0],[0,t[1],0],[0,0,t[2]]],qe=t=>[[t[0],0,0,0],[0,t[1],0,0],[0,0,t[2],0],[0,0,0,1]],Ae=(t,r)=>h(Ct(t),r),Ne=t=>[[t,0],[0,1]],Ce=t=>[[t,0,0],[0,1,0],[0,0,1]],Xe=t=>[[t,0,0],[0,1,0],[0,0,1]],Ye=t=>[[t,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Ge=t=>[[1,0,0],[0,t,0],[0,0,1]],Oe=t=>[[1,0,0,0],[0,t,0,0],[0,0,1,0],[0,0,0,1]],je=t=>[[1,0,0],[0,1,0],[0,0,t]],De=t=>[[1,0,0,0],[0,1,0,0],[0,0,t,0],[0,0,0,1]],ke=t=>[[1,0],[0,t]],Fe=t=>[[1,0,0],[0,t,0],[0,0,1]],Qe=()=>[[-1,0],[0,-1]],Ze=()=>[[-1,0,0],[0,-1,0],[0,0,1]],We=()=>[[-1,0,0],[0,-1,0],[0,0,-1]],_e=()=>[[-1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]],Ke=()=>[[0,-1],[-1,0]],Je=()=>[[1,0],[0,-1]],Ue=()=>[[1,0,0],[0,-1,0],[0,0,1]],Pe=()=>[[-1,0],[0,1]],tn=()=>[[-1,0,0],[0,1,0],[0,0,1]],rn=()=>[[-1,0,0],[0,1,0],[0,0,1]],en=()=>[[-1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],nn=()=>[[1,0,0],[0,-1,0],[0,0,1]],on=()=>[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]],cn=()=>[[1,0,0],[0,1,0],[0,0,-1]],sn=()=>[[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]],un=t=>[[1,t],[0,1]],xn=t=>[[1,0],[t,1]];var b=(t,r,e=1/0)=>s(Math.random()*(r-t)+t,e),Xt=(t,r)=>Math.floor(Math.random()*(r-t+1)+t),an=()=>Math.random()<.5,mn=t=>{let r=Xt(0,t.length-1);return t[r]};var fn=(t,r)=>{var n;if(t==null)return r;let e=(n=Number(t))!=null?n:r;return isNaN(e)?r:e};var pn=(t,r,e=1/0)=>{let n=0;for(let o of r){if(o.length!==2)return NaN;let i=o[0],c=o[1];n+=i*c*Math.pow(t,c-1)}return s(n,e)},bt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},Vt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},yt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},lt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},Mn=(t,r=1/0)=>s(Math.cos(t),r),hn=(t,r=1/0)=>s(-Math.sin(t),r),bn=(t,r=1/0)=>s(1/V(Math.cos(t),2),r),Vn=(t,r=1/0)=>s(-1/V(Math.sin(t),2),r),yn=(t,r=1/0)=>s(1/Math.sqrt(1-V(t,2)),r),ln=(t,r=1/0)=>s(-1/Math.sqrt(1-V(t,2)),r),In=(t,r=1/0)=>s(1/(1+V(t,2)),r),dn=(t,r=1/0)=>s(-1/(1+V(t,2)),r);var E=(t,r=1/0)=>{let e=t[0],n=t[1],i=t[2]-n;return e===0&&i===0?1/0:e===0?NaN:s(i/e,r)},vn=(t,r,e=1/0)=>{let n=[[t[0],t[1]],[r[0],r[1]]],o=pt(n);if(o===null)return null;let i=[t[2],r[2]];return h(o,i,e)},gn=(t,r,e,n=1/0)=>{let o=[[t[0],t[1],t[2]],[r[0],r[1],r[2]],[e[0],e[1],e[2]]],i=Mt(o);if(i===null)return null;let c=[t[3],r[3],e[3]];return h(i,c,n)},Sn=(t,r=1/0)=>{if(t.length<=0)return null;let e=st(t),n=Q(e);if(n===null)return null;let o=ut(t);return h(n,o,r)},Rn=(t,r)=>{let[e,n]=R(r,t),[o,i]=t;if(e===0)return{slope:void 0,xIntercept:o,yIntercept:void 0,formula:`x = ${o}`};let c=n/e,u=i-c*o,x="";return c===0?x=`y = ${u}`:(x=`y = ${c===1?"":c}x`,u!==0&&(x+=` ${u<0?"-":"+"} ${Math.abs(u)}`)),{slope:c,xIntercept:void 0,yIntercept:u,formula:x}};var It=(t,r=1/0)=>{let e=t[0],n=t[1],o=t[2],i=t[3];if(e===0){let f=E([n,o,i],r);return z(f)?[f]:[]}let c=o-i,u=n*n-4*e*c;if(u<0)return[];if(u===0)return[s(-n/(2*e),r)];let x=2*e,a=Math.sqrt(u);return[s((-n+a)/x,r),s((-n-a)/x,r)]};var Yt=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},wn=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},Gt=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},Hn=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},Ot=(t,r,e,n,o=1/0)=>{let i=bt(t,r,e,n);return L(i,o)},zn=(t,r,e,n,o=1/0)=>{let i=Vt(t,r,e,n);return v(i,o)},jt=(t,r,e,n,o,i=1/0)=>{let c=yt(t,r,e,n,o);return L(c,i)},Bn=(t,r,e,n,o,i=1/0)=>{let c=lt(t,r,e,n,o);return v(c,i)},Tn=(t,r,e,n,o=1/0)=>{let i=Ot(t,r,e,n,o);return[-i[1],i[0]]},Ln=(t,r,e,n,o,i=1/0)=>{let c=jt(t,r,e,n,o,i);return[-c[1],c[0]]},Dt=(t,r,e,n=1/0)=>{let o=2*t[0]-4*r[0]+2*e[0],i=-2*t[0]+2*r[0],u=E([o,i,0],n),x=2*t[1]-4*r[1]+2*e[1],a=-2*t[1]+2*r[1],p=E([x,a,0],n),m=[];return z(u)&&m.push(u),z(p)&&m.push(p),m},kt=(t,r,e,n,o=1/0)=>{let i=-3*t[0]+9*r[0]-9*e[0]+3*n[0],c=6*t[0]-12*r[0]+6*e[0],u=-3*t[0]+3*r[0],x=[i,c,u,0],a=-3*t[1]+9*r[1]-9*e[1]+3*n[1],f=6*t[1]-12*r[1]+6*e[1],p=-3*t[1]+3*r[1],m=[a,f,p,0],M=It(x,o).filter(I=>I>=0&&I<=1),g=It(m,o).filter(I=>I>=0&&I<=1);return[...M,...g].length===2?[...M,...g]:null},$n=(t,r,e,n=1/0)=>{let o=Dt(t,r,e),i=1/0,c=1/0,u=-1/0,x=-1/0;for(let a of o){let f=Yt(a,t,r,e),p=f[0],m=f[1];i=Math.min(i,p),u=Math.max(u,p),c=Math.min(c,m),x=Math.max(x,m)}return i=s(Math.min(i,t[0],e[0]),n),u=s(Math.max(u,t[0],e[0]),n),c=s(Math.min(c,t[1],e[1]),n),x=s(Math.max(x,t[1],e[1]),n),{x:i,y:c,w:Math.abs(u-i),h:Math.abs(x-c),x2:u,y2:x}},En=(t,r,e,n,o=1/0)=>{let i=kt(t,r,e,n)||[],c=1/0,u=1/0,x=-1/0,a=-1/0;for(let f of i){let p=Gt(f,t,r,e,n),m=p[0],M=p[1];c=Math.min(c,m!=null?m:1/0),x=Math.max(x,m!=null?m:-1/0),u=Math.min(u,M!=null?M:1/0),a=Math.max(a,M!=null?M:-1/0)}return c=s(Math.min(c,t[0],n[0]),o),x=s(Math.max(x,t[0],n[0]),o),u=s(Math.min(u,t[1],n[1]),o),a=s(Math.max(a,t[1],n[1]),o),{x:c,y:u,w:Math.abs(x-c),h:Math.abs(a-u),x2:x,y2:a}};var Ft=(t,r,e)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*e]),qn=(t,r,e)=>{let n=R(t,r),o=T(n);return o=j(o,0,Math.PI*2,0,Math.PI),Ft(r,o,e)},Qt=(t,r,e,n)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*n]),An=(t,r,e)=>{let n=R(t,r),o=T(n);return o=j(o,0,Math.PI*2,0,Math.PI),Qt(r,o,e[0],e[1])},Nn=(t,r,e,n)=>{let o=r*Math.sin(2*Math.PI*e*t+n);return[t,o]},Cn=(t,r,e,n,o,i,c)=>[t*Math.cos(n*e-i),r*Math.cos(o*e-c)];var Xn=()=>{let t=gt();return Wt(t)},Yn=()=>{let t=gt();return _t(t)},gt=()=>{let t=b(1,360),r=b(0,100),e=b(0,100);return[t,r,e]},Gn=t=>{let r=b(0,100),e=b(0,100);return[t,r,e]},On=t=>{let r=b(1,360),e=b(0,100);return[r,t,e]},jn=t=>{let r=b(1,360),e=b(0,100);return[r,e,t]},Dn=()=>[0,0,b(0,100)],kn=(t=1,r=360,e=0,n=100,o=0,i=100)=>{let c=b(t,r),u=b(e,n),x=b(o,i);return[c,u,x]},Fn=t=>(t*=60,t<0&&(t+=360),t),Qn=(t,r,e,n=void 0,o=void 0)=>{if(n=n===void 0?Math.min(t,r,e):n,o=o===void 0?Math.max(t,r,e):o,n===o)return 0;let i=o-n,c=0;return o===t&&(c=(r-e)/i+(r(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,(n+o)/2*100),Zn=(t,r,e,n=void 0,o=void 0,i=void 0)=>(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,n===o?0:(i=i===void 0?Zt(t,r,e):i,(i<=50?(o-n)/(o+n):(o-n)/(2-o-n))*100)),Wn=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255,i=Math.min(e,n,o),c=Math.max(e,n,o),u=Zt(e,n,o,i,c),x=Zn(e,n,o,i,c,u),a=Qn(e,n,o,i,c);return a>360||x>100||u>100?[0,0,100]:a<0||x<0||u<0?[0,0,0]:[s(a,r),s(x,r),s(u,r)]},dt=(t,r,e)=>(e<0&&(e+=1),e>1&&(e-=1),e*6<1?r+(t-r)*6*e:e*2<1?t:e*3<2?r+(t-r)*(.666-e)*6:r),Wt=(t,r=1/0)=>{let e=t[0]/100,n=t[1]/100,o=t[2]/100;if(n===0){let M=o*255;return[M,M,M]}let i=o<.5?o*(1+n):o+n-o*n,c=2*o-i,u=e+.333,x=e,a=e-.333,f=dt(i,c,u),p=dt(i,c,x),m=dt(i,c,a);return f*=255,p*=255,m*=255,f>255||p>255||m>255?[255,255,255]:f<0||p<0||m<0?[0,0,0]:[s(f,r),s(p,r),s(m,r)]},_t=t=>{if(t[0]>360||t[1]>100||t[2]>100)return"#ffffff";if(t[0]<0||t[1]<0||t[2]<0)return"#000000";let r=t[0]/360,e=t[1]/100,n=t[2]/100,o,i,c;if(e===0)o=i=c=n;else{let x=(p,m,M)=>(M<0&&(M+=1),M>1&&(M-=1),M<.16666666666666666?p+(m-p)*6*M:M<.5?m:M<.6666666666666666?p+(m-p)*(.6666666666666666-M)*6:p),a=n<.5?n*(1+e):n+e-n*e,f=2*n-a;o=x(f,a,r+1/3),i=x(f,a,r),c=x(f,a,r-1/3)}let u=x=>{let a=Math.round(x*255).toString(16);return a.length===1?"0"+a:a};return`#${u(o)}${u(i)}${u(c)}`},_n=t=>{let[r,e,n]=t;return"#"+(1<<24|r<<16|e<<8|n).toString(16).slice(1)},Kn=t=>{let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,e=t.replace(r,(u,x,a,f)=>x+x+a+a+f+f),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)return null;let o=parseInt(n[1],16),i=parseInt(n[2],16),c=parseInt(n[3],16);return[o,i,c]},vt=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,o=o>.04045?Math.pow((o+.055)/1.055,2.4):o/12.92;let i=(e*.4124+n*.3576+o*.1805)/.95047,c=(e*.2126+n*.7152+o*.0722)/1,u=(e*.0193+n*.1192+o*.9505)/1.08883;return i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,c=c>.008856?Math.pow(c,1/3):7.787*c+16/116,u=u>.008856?Math.pow(u,1/3):7.787*u+16/116,[s(116*c-16,r),s(500*(i-c),r),s(200*(c-u),r)]},Jn=(t,r=1/0)=>{let e=(t[0]+16)/116,n=t[1]/500+e,o=e-t[2]/200;n=.95047*(n*n*n>.008856?n*n*n:(n-16/116)/7.787),e=1*(e*e*e>.008856?e*e*e:(e-16/116)/7.787),o=1.08883*(o*o*o>.008856?o*o*o:(o-16/116)/7.787);let i=n*3.2406+e*-1.5372+o*-.4986,c=n*-.9689+e*1.8758+o*.0415,u=n*.0557+e*-.204+o*1.057;return i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,u=u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u,[s(Math.max(0,Math.min(1,i))*255,r),s(Math.max(0,Math.min(1,c))*255,r),s(Math.max(0,Math.min(1,u))*255,r)]},Un=(t,r=180)=>{let e=t[0];return e+=r,(e>360||e<0)&&(e=y(e,360)),[e,t[1],t[2]]},Pn=(t,r=10)=>{let e=t[2];return e+=r,(e>100||e<0)&&(e=y(e,100)),[t[0],t[1],e]},to=(t,r=10)=>{let e=t[1];return e+=r,e>100&&(e-=100),e<0&&(e+=100),[t[0],e,t[2]]},ro=(t,r,e=1/0)=>{let n=vt(t,e),o=vt(r,e),i=n[0]-o[0],c=n[1]-o[1],u=n[2]-o[2],x=Math.sqrt(n[1]*n[1]+n[2]*n[2]),a=Math.sqrt(o[1]*o[1]+o[2]*o[2]),f=x-a,p=c*c+u*u-f*f;p=p<0?0:Math.sqrt(p);let m=1+.045*x,M=1+.015*x,g=i/1,q=f/m,I=p/M,O=g*g+q*q+I*I;return O<0?0:Math.sqrt(O)};var eo=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)}),no=()=>Math.random().toString(36).substring(2)+new Date().getTime().toString(36);var oo=(t,r)=>t.x<=r.x+r.w&&t.x+t.w>=r.x&&t.y<=r.y+r.h&&t.h+t.y>=r.y,io=(t,r)=>{let e=Math.abs(t.cx-r.cx),n=Math.abs(t.cy-r.cy);return Math.sqrt(e*e+n*n)<=t.r+r.r},Kt=t=>{let r=[];for(let e=0;e{let e=[];e.push(...Kt(t)),e.push(...Kt(r));for(let n of e){let o=tt(n[0],n[1]),i=Jt(t,o),c=Jt(r,o);if(!(i.max>=c.min&&c.max>=i.min))return!1}return!0},Jt=(t,r)=>{let e=1/0,n=-1/0;for(let o of t){let i=J(o,r);e=Math.min(e,i),n=Math.max(n,i)}return{min:e,max:n}};var so=t=>{let r=t.duration!==void 0?t.duration:1/0,e,n,o,i,c=!1,u,x=()=>{e=void 0,o=void 0,i=void 0,c=!1,n!==void 0&&window.cancelAnimationFrame(n)},a=()=>{x(),g()},f=()=>{c=!1},p=()=>{c=!0},m=H=>{e===void 0&&(e=H),o=H-e,c&&i!==H&&typeof t.callback=="function"&&t.callback(St()),o<=r?(i=H,n=window.requestAnimationFrame(m)):x()},M=(H,rr)=>{a(),typeof t.resizeCallback=="function"&&t.resizeCallback(H,rr)},g=()=>{e=void 0,o=void 0,i=void 0,c=!0,t.restartOnResize&&window.ResizeObserver&&u===void 0?(u=new ResizeObserver(M),u.observe(document.body,{box:"border-box"})):n=window.requestAnimationFrame(m)},q=()=>o,I=()=>c,O=()=>e,Pt=()=>{if(!(r===1/0||o===void 0))return o*100/r},tr=()=>u,St=()=>({start:g,stop:x,pause:f,resume:p,restart:a,isAnimating:I,getElapsedTime:q,getStartTime:O,getPercent:Pt,getResizeObserver:tr});return St()};var uo=(t,r=1/0)=>s(2*Math.PI*t,r),xo=(t,r,e=1/0)=>s(2*Math.PI*Math.sqrt((V(t,2)+V(r,2))/2),e),ao=(t,r,e)=>(t>r&&(r+=360),e>=t&&e<=r||e+360>=t&&e+360<=r),mo=(t,r=1/0)=>s(t*2/Math.sqrt(2),r);var fo=t=>t*(t+1)/2,po=(t,r,e)=>t/2*(2*r+(t-1)*e);var Ut=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=t.reduce((n,o)=>n+o,0);return s(e/t.length,r)},Mo=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=[...t].sort((o,i)=>o-i),n=Math.floor(e.length/2);return e.length%2===0?s((e[n]+e[n-1])/2,r):s(e[n],r)},ho=t=>{if(!t||t.length<=0)return;let r=new Map;for(let o of t)r.set(o,(r.get(o)||0)+1);let e=0,n=[];for(let[o,i]of r)i>e?(e=i,n=[o]):i===e&&n.push(o);if(n.length!==t.length)return n.length===1?[n[0]]:n},bo=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=Ut(t);if(e===void 0)return;let n=t.reduce((o,i)=>o+V(i-e,2),0);return s(n/t.length,r)};0&&(module.exports={animate,arithmeticSequenceSum,circleCollide,circleMovement,circleMovementAfterMouse,convertRange,convexPolygonsCollide,degreesToRadians,doRangesOverlap,dxArcCos,dxArcCot,dxArcSin,dxArcTan,dxCos,dxCot,dxPolynomial,dxSin,dxTan,dxV2CubicBezierCurve,dxV2QuadraticBezierCurve,dxV3CubicBezierCurve,dxV3QuadraticBezierCurve,ellipseMovement,ellipseMovementAfterMouse,getAnglesDistance,getAnglesSub,getArithmeticMean,getCircleCircumference,getColorsDelta,getEllipseCircumference,getLinearEquationBy2Points,getMedian,getMode,getRandom,getRandomBoolean,getRandomGrayscaleHSLColor,getRandomHSLColor,getRandomHSLColorWithHue,getRandomHSLColorWithLightness,getRandomHSLColorWithSaturation,getRandomHSLColorWithinRanges,getRandomHexColor,getRandomInt,getRandomItemFromArray,getRandomRGBColor,getShiftedHue,getShiftedLightness,getShiftedSaturation,getSquareInCircleSide,getV2Angle,getV2AngleBetween,getV2AngleInEllipse,getV3AngleBetween,getVNAngleBetween,getVariance,guid,hexToRgb,hslToHex,hslToRgb,identity2,identity3,identity4,identityN,isAngleBetween,isAngleInCircleArc,isClockwise,isNumber,isSingularMatrix,labToRgb,linearEquation,linearEquationSystem2,linearEquationSystem3,linearEquationSystemN,lissajousCurve,m2Adjugate,m2AppendRow,m2DeepCopy,m2Determinant,m2DivideScalar,m2Inverse,m2MulScalar,m2PrependRow,m2ReflectionOrigin,m2ReflectionOriginH,m2ReflectionX,m2ReflectionXH,m2ReflectionY,m2ReflectionYH,m2ReflectionYmX,m2Reset,m2RotateAroundPointH,m2Rotation,m2RotationAroundPointH,m2RotationH,m2Scale,m2ScaleAtPointH,m2ScaleAtPointHMatrix,m2ScaleH,m2ScaleX,m2ScaleXH,m2ScaleY,m2ScaleYH,m2ShearingX,m2ShearingY,m2Sub,m2Sum,m2ToCSS,m2Translation,m2TranslationH,m2Transpose,m2hToCSS,m2hToCSS3d,m2x2,m3Adjugate,m3AppendRow,m3DeepCopy,m3Determinant,m3DivideScalar,m3Inverse,m3MulScalar,m3PrependRow,m3ReflectionOrigin,m3ReflectionOriginH,m3ReflectionXY,m3ReflectionXYH,m3ReflectionXZ,m3ReflectionXZH,m3ReflectionYZ,m3ReflectionYZH,m3Reset,m3RotationX,m3RotationXH,m3RotationY,m3RotationYH,m3RotationZ,m3RotationZH,m3Scale,m3ScaleH,m3ScaleX,m3ScaleXH,m3ScaleY,m3ScaleYH,m3ScaleZ,m3ScaleZH,m3Sub,m3Sum,m3Translation,m3TranslationH,m3Transpose,m3hToCSS3d,m3x3,m4x4,mAdjugate,mAppendCol,mAppendRow,mDeepCopy,mDelFirstColumn,mDelFirstRow,mDelLastColumn,mDelLastRow,mDeterminant,mDivideScalar,mEqual,mGetColumn,mGetFirstColumn,mGetLastColumn,mInverse,mMinor,mMul,mMulScalar,mMulVector,mNxM,mPrependCol,mPrependRow,mReset,mSub,mSum,mTranspose,mod,naturalNumbersSequenceSum,newId,percentToAngle,polarToCartesian,radiansToDegrees,rectCollide,rgbToHex,rgbToHsl,rgbToLab,setDecimalPlaces,setV2Angle,sineWaveMovement,stringToNumber,v2,v2CubicBezierBBox,v2CubicBezierCurve,v2CubicBezierCurveExtrema,v2CubicBezierCurveNormal,v2CubicBezierCurveTangent,v2Distance,v2DivideScalar,v2DotProduct,v2FromPolarCoords,v2GetNormal,v2Length,v2MulScalar,v2Normalize,v2QuadraticBezierBBox,v2QuadraticBezierCurve,v2QuadraticBezierCurveExtrema,v2QuadraticBezierCurveNormal,v2QuadraticBezierCurveTangent,v2Rotate,v2RotateH,v2Scale,v2SetLength,v2Sub,v2Sum,v3,v3CrossProduct,v3CubicBezierCurve,v3CubicBezierCurveTangent,v3Distance,v3DivideScalar,v3DotProduct,v3Length,v3MulScalar,v3Normalize,v3QuadraticBezierCurve,v3QuadraticBezierCurveTangent,v3RotateX,v3RotateY,v3RotateZ,v3Scale,v3Sub,v3Sum,v4,vDistance,vDivideScalar,vDotProduct,vEqual,vLength,vMulScalar,vN,vNormalize,vSub,vSum}); + )`,Ie=(t,r=1/0)=>[[1,0],[0,1],[s(t[0],r),s(t[1],r)]],de=(t,r=1/0)=>[[1,0,0],[0,1,0],[0,0,1],[s(t[0],r),s(t[1],r),s(t[2],r)]],G=(t,r=1/0)=>[[1,0,s(t[0],r)],[0,1,s(t[1],r)],[0,0,1]],ve=(t,r=1/0)=>[[1,0,0,s(t[0],r)],[0,1,0,s(t[1],r)],[0,0,1,s(t[2],r)],[0,0,0,1]],Bt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o],[o,n]]:[[n,o],[-o,n]]},ht=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Tt=(t,r,e=!0,n=1/0)=>{let o=G(r,n),i=ht(t,e,n),c=G(k(r,-1),n),u=$(o,i);return $(u,c)},ge=(t,r,e,n=!0,o=1/0)=>{let i=Tt(t,r,n,o);return h(i,e)},Se=(t,r,e=!0,n=1/0)=>{let o=L(r);return h(Bt(t,e,n),o)},Re=(t,r,e=!0,n=1/0)=>{let o=v(r);return h(ht(t,e,n),o)},Lt=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0],[0,n,-o],[0,o,n]]:[[1,0,0],[0,n,o],[0,-o,n]]},we=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[1,0,0,0],[0,n,-o,0],[0,o,n,0],[0,0,0,1]]:[[1,0,0,0],[0,n,o,0],[0,-o,n,0],[0,0,0,1]]},ze=(t,r,e=!0,n=1/0)=>{let o=v(r);return h(Lt(t,e,n),o)},$t=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o],[0,1,0],[-o,0,n]]:[[n,0,-o],[0,1,0],[o,0,n]]},He=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,0,o,0],[0,1,0,0],[-o,0,n,0],[0,0,0,1]]:[[n,0,-o,0],[0,1,0,0],[o,0,n,0],[0,0,0,1]]},Be=(t,r,e=!0,n=1/0)=>{let o=v(r);return h($t(t,e,n),o)},Et=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0],[o,n,0],[0,0,1]]:[[n,o,0],[-o,n,0],[0,0,1]]},Te=(t,r=!0,e=1/0)=>{let n=s(Math.cos(t),e),o=s(Math.sin(t),e);return r?[[n,-o,0,0],[o,n,0,0],[0,0,1,0],[0,0,0,1]]:[[n,o,0,0],[-o,n,0,0],[0,0,1,0],[0,0,0,1]]},Le=(t,r,e=!0,n=1/0)=>{let o=v(r);return h(Et(t,e,n),o)},qt=(t,r,e=1/0)=>{let n=G(r,e),o=Nt(t),i=G(k(r,-1),e),c=$(n,o);return $(c,i)},$e=(t,r,e,n=1/0)=>{let o=qt(t,r,n);return h(o,e)},At=t=>[[t[0],0],[0,t[1]]],Ee=(t,r)=>h(At(t),r),Nt=t=>[[t[0],0,0],[0,t[1],0],[0,0,1]],Ct=t=>[[t[0],0,0],[0,t[1],0],[0,0,t[2]]],qe=t=>[[t[0],0,0,0],[0,t[1],0,0],[0,0,t[2],0],[0,0,0,1]],Ae=(t,r)=>h(Ct(t),r),Ne=t=>[[t,0],[0,1]],Ce=t=>[[t,0,0],[0,1,0],[0,0,1]],Xe=t=>[[t,0,0],[0,1,0],[0,0,1]],Ye=t=>[[t,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],Ge=t=>[[1,0,0],[0,t,0],[0,0,1]],Oe=t=>[[1,0,0,0],[0,t,0,0],[0,0,1,0],[0,0,0,1]],je=t=>[[1,0,0],[0,1,0],[0,0,t]],De=t=>[[1,0,0,0],[0,1,0,0],[0,0,t,0],[0,0,0,1]],ke=t=>[[1,0],[0,t]],Fe=t=>[[1,0,0],[0,t,0],[0,0,1]],Qe=()=>[[-1,0],[0,-1]],Ze=()=>[[-1,0,0],[0,-1,0],[0,0,1]],We=()=>[[-1,0,0],[0,-1,0],[0,0,-1]],_e=()=>[[-1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]],Ke=()=>[[0,-1],[-1,0]],Je=()=>[[1,0],[0,-1]],Ue=()=>[[1,0,0],[0,-1,0],[0,0,1]],Pe=()=>[[-1,0],[0,1]],tn=()=>[[-1,0,0],[0,1,0],[0,0,1]],rn=()=>[[-1,0,0],[0,1,0],[0,0,1]],en=()=>[[-1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],nn=()=>[[1,0,0],[0,-1,0],[0,0,1]],on=()=>[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]],cn=()=>[[1,0,0],[0,1,0],[0,0,-1]],sn=()=>[[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]],un=t=>[[1,t],[0,1]],xn=t=>[[1,0],[t,1]];var b=(t,r,e=1/0)=>s(Math.random()*(r-t)+t,e),Xt=(t,r)=>Math.floor(Math.random()*(r-t+1)+t),an=()=>Math.random()<.5,mn=t=>{let r=Xt(0,t.length-1);return t[r]};var fn=(t,r)=>{var n;if(t==null)return r;let e=(n=Number(t))!=null?n:r;return isNaN(e)?r:e};var pn=(t,r,e=1/0)=>{let n=0;for(let o of r){if(o.length!==2)return NaN;let i=o[0],c=o[1];n+=i*c*Math.pow(t,c-1)}return s(n,e)},bt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},Vt=(t,r,e,n,o=1/0)=>{let i=-2*(1-t),c=2-4*t,u=2*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},yt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},lt=(t,r,e,n,o,i=1/0)=>{let c=-3*Math.pow(1-t,2),u=3*(t-1)*(3*t-1),x=6*t-9*t*t,a=3*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},Mn=(t,r=1/0)=>s(Math.cos(t),r),hn=(t,r=1/0)=>s(-Math.sin(t),r),bn=(t,r=1/0)=>s(1/V(Math.cos(t),2),r),Vn=(t,r=1/0)=>s(-1/V(Math.sin(t),2),r),yn=(t,r=1/0)=>s(1/Math.sqrt(1-V(t,2)),r),ln=(t,r=1/0)=>s(-1/Math.sqrt(1-V(t,2)),r),In=(t,r=1/0)=>s(1/(1+V(t,2)),r),dn=(t,r=1/0)=>s(-1/(1+V(t,2)),r);var E=(t,r=1/0)=>{let e=t[0],n=t[1],i=t[2]-n;return e===0&&i===0?1/0:e===0?NaN:s(i/e,r)},vn=(t,r,e=1/0)=>{let n=[[t[0],t[1]],[r[0],r[1]]],o=pt(n);if(o===null)return null;let i=[t[2],r[2]];return h(o,i,e)},gn=(t,r,e,n=1/0)=>{let o=[[t[0],t[1],t[2]],[r[0],r[1],r[2]],[e[0],e[1],e[2]]],i=Mt(o);if(i===null)return null;let c=[t[3],r[3],e[3]];return h(i,c,n)},Sn=(t,r=1/0)=>{if(t.length<=0)return null;let e=st(t),n=Q(e);if(n===null)return null;let o=ut(t);return h(n,o,r)},Rn=(t,r)=>{let[e,n]=R(r,t),[o,i]=t;if(e===0)return{slope:void 0,xIntercept:o,yIntercept:void 0,formula:`x = ${o}`};let c=n/e,u=i-c*o,x="";return c===0?x=`y = ${u}`:(x=`y = ${c===1?"":c}x`,u!==0&&(x+=` ${u<0?"-":"+"} ${Math.abs(u)}`)),{slope:c,xIntercept:void 0,yIntercept:u,formula:x}};var It=(t,r=1/0)=>{let e=t[0],n=t[1],o=t[2],i=t[3];if(e===0){let f=E([n,o,i],r);return H(f)?[f]:[]}let c=o-i,u=n*n-4*e*c;if(u<0)return[];if(u===0)return[s(-n/(2*e),r)];let x=2*e,a=Math.sqrt(u);return[s((-n+a)/x,r),s((-n-a)/x,r)]};var Yt=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o)]},wn=(t,r,e,n,o=1/0)=>{let i=Math.pow(1-t,2),c=(1-t)*2*t,u=t*t;return[s(i*r[0]+c*e[0]+u*n[0],o),s(i*r[1]+c*e[1]+u*n[1],o),s(i*r[2]+c*e[2]+u*n[2],o)]},Gt=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i)]},zn=(t,r,e,n,o,i=1/0)=>{let c=Math.pow(1-t,3),u=Math.pow(1-t,2)*3*t,x=(1-t)*3*t*t,a=t*t*t;return[s(c*r[0]+u*e[0]+x*n[0]+a*o[0],i),s(c*r[1]+u*e[1]+x*n[1]+a*o[1],i),s(c*r[2]+u*e[2]+x*n[2]+a*o[2],i)]},Ot=(t,r,e,n,o=1/0)=>{let i=bt(t,r,e,n);return L(i,o)},Hn=(t,r,e,n,o=1/0)=>{let i=Vt(t,r,e,n);return v(i,o)},jt=(t,r,e,n,o,i=1/0)=>{let c=yt(t,r,e,n,o);return L(c,i)},Bn=(t,r,e,n,o,i=1/0)=>{let c=lt(t,r,e,n,o);return v(c,i)},Tn=(t,r,e,n,o=1/0)=>{let i=Ot(t,r,e,n,o);return[-i[1],i[0]]},Ln=(t,r,e,n,o,i=1/0)=>{let c=jt(t,r,e,n,o,i);return[-c[1],c[0]]},Dt=(t,r,e,n=1/0)=>{let o=2*t[0]-4*r[0]+2*e[0],i=-2*t[0]+2*r[0],u=E([o,i,0],n),x=2*t[1]-4*r[1]+2*e[1],a=-2*t[1]+2*r[1],p=E([x,a,0],n),m=[];return H(u)&&m.push(u),H(p)&&m.push(p),m},kt=(t,r,e,n,o=1/0)=>{let i=-3*t[0]+9*r[0]-9*e[0]+3*n[0],c=6*t[0]-12*r[0]+6*e[0],u=-3*t[0]+3*r[0],x=[i,c,u,0],a=-3*t[1]+9*r[1]-9*e[1]+3*n[1],f=6*t[1]-12*r[1]+6*e[1],p=-3*t[1]+3*r[1],m=[a,f,p,0],M=It(x,o).filter(I=>I>=0&&I<=1),g=It(m,o).filter(I=>I>=0&&I<=1);return[...M,...g].length===2?[...M,...g]:null},$n=(t,r,e,n=1/0)=>{let o=Dt(t,r,e),i=1/0,c=1/0,u=-1/0,x=-1/0;for(let a of o){let f=Yt(a,t,r,e),p=f[0],m=f[1];i=Math.min(i,p),u=Math.max(u,p),c=Math.min(c,m),x=Math.max(x,m)}return i=s(Math.min(i,t[0],e[0]),n),u=s(Math.max(u,t[0],e[0]),n),c=s(Math.min(c,t[1],e[1]),n),x=s(Math.max(x,t[1],e[1]),n),{x:i,y:c,w:Math.abs(u-i),h:Math.abs(x-c),x2:u,y2:x}},En=(t,r,e,n,o=1/0)=>{let i=kt(t,r,e,n)||[],c=1/0,u=1/0,x=-1/0,a=-1/0;for(let f of i){let p=Gt(f,t,r,e,n),m=p[0],M=p[1];c=Math.min(c,m!=null?m:1/0),x=Math.max(x,m!=null?m:-1/0),u=Math.min(u,M!=null?M:1/0),a=Math.max(a,M!=null?M:-1/0)}return c=s(Math.min(c,t[0],n[0]),o),x=s(Math.max(x,t[0],n[0]),o),u=s(Math.min(u,t[1],n[1]),o),a=s(Math.max(a,t[1],n[1]),o),{x:c,y:u,w:Math.abs(x-c),h:Math.abs(a-u),x2:x,y2:a}};var Ft=(t,r,e)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*e]),qn=(t,r,e)=>{let n=R(t,r),o=T(n);return o=j(o,0,Math.PI*2,0,Math.PI),Ft(r,o,e)},Qt=(t,r,e,n)=>(r=r%Math.PI*2,[t[0]+Math.cos(r)*e,t[1]+Math.sin(r)*n]),An=(t,r,e)=>{let n=R(t,r),o=T(n);return o=j(o,0,Math.PI*2,0,Math.PI),Qt(r,o,e[0],e[1])},Nn=(t,r,e,n)=>{let o=r*Math.sin(2*Math.PI*e*t+n);return[t,o]},Cn=(t,r,e,n,o,i,c)=>[t*Math.cos(n*e-i),r*Math.cos(o*e-c)];var Xn=()=>{let t=gt();return Wt(t)},Yn=()=>{let t=gt();return _t(t)},gt=()=>{let t=b(1,360),r=b(0,100),e=b(0,100);return[t,r,e]},Gn=t=>{let r=b(0,100),e=b(0,100);return[t,r,e]},On=t=>{let r=b(1,360),e=b(0,100);return[r,t,e]},jn=t=>{let r=b(1,360),e=b(0,100);return[r,e,t]},Dn=()=>[0,0,b(0,100)],kn=(t=1,r=360,e=0,n=100,o=0,i=100)=>{let c=b(t,r),u=b(e,n),x=b(o,i);return[c,u,x]},Fn=t=>(t*=60,t<0&&(t+=360),t),Qn=(t,r,e,n=void 0,o=void 0)=>{if(n=n===void 0?Math.min(t,r,e):n,o=o===void 0?Math.max(t,r,e):o,n===o)return 0;let i=o-n,c=0;return o===t&&(c=(r-e)/i+(r(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,(n+o)/2*100),Zn=(t,r,e,n=void 0,o=void 0,i=void 0)=>(n=n===void 0?Math.min(t,r,e):n,o=n===void 0?Math.max(t,r,e):o,n===o?0:(i=i===void 0?Zt(t,r,e):i,(i<=50?(o-n)/(o+n):(o-n)/(2-o-n))*100)),Wn=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255,i=Math.min(e,n,o),c=Math.max(e,n,o),u=Zt(e,n,o,i,c),x=Zn(e,n,o,i,c,u),a=Qn(e,n,o,i,c);return a>360||x>100||u>100?[0,0,100]:a<0||x<0||u<0?[0,0,0]:[s(a,r),s(x,r),s(u,r)]},dt=(t,r,e)=>(e<0&&(e+=1),e>1&&(e-=1),e*6<1?r+(t-r)*6*e:e*2<1?t:e*3<2?r+(t-r)*(.666-e)*6:r),Wt=(t,r=1/0)=>{let e=t[0]/100,n=t[1]/100,o=t[2]/100;if(n===0){let M=o*255;return[M,M,M]}let i=o<.5?o*(1+n):o+n-o*n,c=2*o-i,u=e+.333,x=e,a=e-.333,f=dt(i,c,u),p=dt(i,c,x),m=dt(i,c,a);return f*=255,p*=255,m*=255,f>255||p>255||m>255?[255,255,255]:f<0||p<0||m<0?[0,0,0]:[s(f,r),s(p,r),s(m,r)]},_t=t=>{if(t[0]>360||t[1]>100||t[2]>100)return"#ffffff";if(t[0]<0||t[1]<0||t[2]<0)return"#000000";let r=t[0]/360,e=t[1]/100,n=t[2]/100,o,i,c;if(e===0)o=i=c=n;else{let x=(p,m,M)=>(M<0&&(M+=1),M>1&&(M-=1),M<.16666666666666666?p+(m-p)*6*M:M<.5?m:M<.6666666666666666?p+(m-p)*(.6666666666666666-M)*6:p),a=n<.5?n*(1+e):n+e-n*e,f=2*n-a;o=x(f,a,r+1/3),i=x(f,a,r),c=x(f,a,r-1/3)}let u=x=>{let a=Math.round(x*255).toString(16);return a.length===1?"0"+a:a};return`#${u(o)}${u(i)}${u(c)}`},_n=t=>{let[r,e,n]=t;return"#"+(1<<24|r<<16|e<<8|n).toString(16).slice(1)},Kn=t=>{let r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,e=t.replace(r,(u,x,a,f)=>x+x+a+a+f+f),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)return null;let o=parseInt(n[1],16),i=parseInt(n[2],16),c=parseInt(n[3],16);return[o,i,c]},vt=(t,r=1/0)=>{let e=t[0]/255,n=t[1]/255,o=t[2]/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,o=o>.04045?Math.pow((o+.055)/1.055,2.4):o/12.92;let i=(e*.4124+n*.3576+o*.1805)/.95047,c=(e*.2126+n*.7152+o*.0722)/1,u=(e*.0193+n*.1192+o*.9505)/1.08883;return i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,c=c>.008856?Math.pow(c,1/3):7.787*c+16/116,u=u>.008856?Math.pow(u,1/3):7.787*u+16/116,[s(116*c-16,r),s(500*(i-c),r),s(200*(c-u),r)]},Jn=(t,r=1/0)=>{let e=(t[0]+16)/116,n=t[1]/500+e,o=e-t[2]/200;n=.95047*(n*n*n>.008856?n*n*n:(n-16/116)/7.787),e=1*(e*e*e>.008856?e*e*e:(e-16/116)/7.787),o=1.08883*(o*o*o>.008856?o*o*o:(o-16/116)/7.787);let i=n*3.2406+e*-1.5372+o*-.4986,c=n*-.9689+e*1.8758+o*.0415,u=n*.0557+e*-.204+o*1.057;return i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,u=u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u,[s(Math.max(0,Math.min(1,i))*255,r),s(Math.max(0,Math.min(1,c))*255,r),s(Math.max(0,Math.min(1,u))*255,r)]},Un=(t,r=180)=>{let e=t[0];return e+=r,(e>360||e<0)&&(e=y(e,360)),[e,t[1],t[2]]},Pn=(t,r=10)=>{let e=t[2];return e+=r,(e>100||e<0)&&(e=y(e,100)),[t[0],t[1],e]},to=(t,r=10)=>{let e=t[1];return e+=r,e>100&&(e-=100),e<0&&(e+=100),[t[0],e,t[2]]},ro=(t,r,e=1/0)=>{let n=vt(t,e),o=vt(r,e),i=n[0]-o[0],c=n[1]-o[1],u=n[2]-o[2],x=Math.sqrt(n[1]*n[1]+n[2]*n[2]),a=Math.sqrt(o[1]*o[1]+o[2]*o[2]),f=x-a,p=c*c+u*u-f*f;p=p<0?0:Math.sqrt(p);let m=1+.045*x,M=1+.015*x,g=i/1,q=f/m,I=p/M,O=g*g+q*q+I*I;return O<0?0:Math.sqrt(O)};var eo=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)}),no=()=>Math.random().toString(36).substring(2)+new Date().getTime().toString(36);var oo=(t,r)=>t.x<=r.x+r.w&&t.x+t.w>=r.x&&t.y<=r.y+r.h&&t.h+t.y>=r.y,io=(t,r)=>{let e=Math.abs(t.cx-r.cx),n=Math.abs(t.cy-r.cy);return Math.sqrt(e*e+n*n)<=t.r+r.r},Kt=t=>{let r=[];for(let e=0;e{let e=[];e.push(...Kt(t)),e.push(...Kt(r));for(let n of e){let o=tt(n[0],n[1]),i=Jt(t,o),c=Jt(r,o);if(!(i.max>=c.min&&c.max>=i.min))return!1}return!0},Jt=(t,r)=>{let e=1/0,n=-1/0;for(let o of t){let i=J(o,r);e=Math.min(e,i),n=Math.max(n,i)}return{min:e,max:n}};var so=t=>{let r=t.duration!==void 0?t.duration:1/0,e,n,o,i,c=!1,u,x=()=>{e=void 0,o=void 0,i=void 0,c=!1,n!==void 0&&window.cancelAnimationFrame(n)},a=()=>{x(),g()},f=()=>{c=!1},p=()=>{c=!0},m=z=>{e===void 0&&(e=z),o=z-e,c&&i!==z&&typeof t.callback=="function"&&t.callback(St()),o<=r?(i=z,n=window.requestAnimationFrame(m)):x()},M=(z,rr)=>{a(),typeof t.resizeCallback=="function"&&t.resizeCallback(z,rr)},g=()=>{e=void 0,o=void 0,i=void 0,c=!0,t.restartOnResize&&window.ResizeObserver&&u===void 0?(u=new ResizeObserver(M),u.observe(document.body,{box:"border-box"})):n=window.requestAnimationFrame(m)},q=()=>o,I=()=>c,O=()=>e,Pt=()=>{if(!(r===1/0||o===void 0))return o*100/r},tr=()=>u,St=()=>({start:g,stop:x,pause:f,resume:p,restart:a,isAnimating:I,getElapsedTime:q,getStartTime:O,getPercent:Pt,getResizeObserver:tr});return St()};var uo=(t,r=1/0)=>s(2*Math.PI*t,r),xo=(t,r,e=1/0)=>s(2*Math.PI*Math.sqrt((V(t,2)+V(r,2))/2),e),ao=(t,r,e)=>(t>r&&(r+=360),e>=t&&e<=r||e+360>=t&&e+360<=r),mo=(t,r=1/0)=>s(t*2/Math.sqrt(2),r);var fo=t=>t*(t+1)/2,po=(t,r,e)=>t/2*(2*r+(t-1)*e);var Ut=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=t.reduce((n,o)=>n+o,0);return s(e/t.length,r)},Mo=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=[...t].sort((o,i)=>o-i),n=Math.floor(e.length/2);return e.length%2===0?s((e[n]+e[n-1])/2,r):s(e[n],r)},ho=t=>{if(!t||t.length<=0)return;let r=new Map;for(let o of t)r.set(o,(r.get(o)||0)+1);let e=0,n=[];for(let[o,i]of r)i>e?(e=i,n=[o]):i===e&&n.push(o);if(n.length!==t.length)return n.length===1?[n[0]]:n},bo=(t,r=1/0)=>{if(!t||t.length<=0)return;let e=Ut(t);if(e===void 0)return;let n=t.reduce((o,i)=>o+V(i-e,2),0);return s(n/t.length,r)};var Vo=(t,r=1/0)=>{let e=[...t],n=Math.min(...e),i=Math.max(...e)-n;if(i===0)return[0];for(let c=0;c {\n if(decimalPlaces === Infinity) return num;\n\n if(decimalPlaces < 0){\n decimalPlaces = 0;\n }\n\n const coefficient = 10 ** decimalPlaces;\n return Math.round(num * coefficient) / coefficient;\n};", "import { Vector2 } from '../types';\nimport { setDecimalPlaces } from './format';\n\nexport const mod = (n: number, m: number) => {\n return ((n % m) + m) % m;\n};\n\n/**\n * Convert range [a, b] to [c, d].\n * f(x) = (d - c) * (x - a) / (b - a) + c\n */\nexport const convertRange = (x: number, a: number, b: number, c: number, d: number) => {\n return (d - c) * (x - a) / (b - a) + c;\n};\n\n/**\n * Check if 2 ranges [a,b] and [c,d] overlap.\n */\nexport const doRangesOverlap = (a: number, b: number, c: number, d: number) => {\n return Math.max(a, c) <= Math.min(b, d) ;\n};\n\n// eslint-disable-next-line\nexport const isNumber = (value: any) => {\n return !isNaN(parseFloat(value)) && isFinite(value);\n};\n\n/**\n * Convert polar coordinates to cartesian coordinates.\n */\nexport const polarToCartesian = (center: Vector2, radii: Vector2, angleInRad: number, decimalPlaces = Infinity) : Vector2 => {\n const [cx, cy] = center;\n const [rx, ry] = radii;\n\n return [\n setDecimalPlaces(cx + (rx * Math.cos(angleInRad)), decimalPlaces),\n setDecimalPlaces(cy + (ry * Math.sin(angleInRad)), decimalPlaces),\n ];\n};", "import { Vector, Vector2, Vector3 } from '../types';\nimport { setDecimalPlaces } from './format';\nimport { v2Length, vNormalize, vDotProduct, vSub } from './linear-algebra/vector';\nimport { mod } from './other';\n\nexport const getV2Angle = (v2: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1], v2[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleInEllipse = (v2: Vector2, radii: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1]/radii[1], v2[0]/radii[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const setV2Angle = (v2: Vector2, newAngleRad: number, decimalPlaces = Infinity): Vector2 => {\n const length = v2Length(v2);\n return [\n setDecimalPlaces(Math.cos(newAngleRad) * length, decimalPlaces),\n setDecimalPlaces(Math.sin(newAngleRad) * length, decimalPlaces),\n ];\n};\n\nexport const radiansToDegrees = (radians: number, decimalPlaces = Infinity) => {\n const res = radians * (180 / Math.PI);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\nexport const degreesToRadians = (degrees: number, decimalPlaces = Infinity) => {\n const res = degrees * (Math.PI / 180);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\n/**\n * Returns the range [0, Math.PI]\n * A = Math.acos( dot(v1, v2)/(v1.length()*v2.length()) );\n */\nexport const getVNAngleBetween = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n const unitVector1 = vNormalize(vector1);\n const unitVector2 = vNormalize(vector2);\n const dotProduct = vDotProduct(unitVector1, unitVector2);\n const angle = Math.acos(dotProduct);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleBetween = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) : number => {\n // return getVNAngleBetween(vector1, vector2, decimalPlaces);\n const diff = vSub(vector1, vector2);\n const angle = Math.atan2(diff[1], diff[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV3AngleBetween = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return getVNAngleBetween(vector1, vector2, decimalPlaces);\n};\n\nexport const isAngleBetween = (angleDegrees: number, startAngleDegrees: number, endAngleDegrees: number) : boolean => {\n const distance = getAnglesSub(startAngleDegrees, endAngleDegrees);\n const distance1 = getAnglesSub(startAngleDegrees, angleDegrees);\n const distance2 = getAnglesSub(endAngleDegrees, angleDegrees);\n const totalDistance = distance1 + distance2;\n\n // Use a small threshold for floating point errors\n return Math.abs(totalDistance - distance) <= 0.001;\n}\n\nexport const isClockwise = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n return angle2Deg >= angle1Deg;\n};\n\n/**\n * Shortest distance (angular) between two angles.\n */\nexport const getAnglesSub = (angleDegrees1: number, angleDegrees2: number, decimalPlaces = Infinity) : number => {\n const angleDistance = Math.abs(mod(angleDegrees1, 360) - mod(angleDegrees2, 360));\n return setDecimalPlaces(angleDistance <= 180 ? angleDistance : 360 - angleDistance, decimalPlaces);\n};\n\nexport const getAnglesDistance = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0, decimalPlaces = Infinity) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n if(isClockwise(angle1Deg, angle2Deg, startAngleDeg)) {\n return setDecimalPlaces((angle2Deg - angle1Deg + 360) % 360, decimalPlaces);\n }\n else{\n return setDecimalPlaces((angle1Deg - angle2Deg + 360) % 360, decimalPlaces);\n }\n};\n\nexport const percentToAngle = (percent: number, startAngleDeg: number, endAngleDeg: number, circleStartAngle = 0) => {\n if(percent < 0) {\n percent = 0;\n }\n\n if(percent > 100) {\n percent = 100;\n }\n\n const distance = getAnglesDistance(startAngleDeg, endAngleDeg, circleStartAngle);\n\n const clockwise = isClockwise(startAngleDeg, endAngleDeg, circleStartAngle);\n if(clockwise) {\n return mod(circleStartAngle + (percent * distance / 100), 360);\n }\n else {\n return mod(circleStartAngle - (percent * distance / 100), 360);\n }\n};", "import { Vector, Vector2, Vector3, Vector4 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { getV2Angle, setV2Angle } from '../angle';\n\n// ------------ SUM ------------------------\n\nexport const vSum = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSum(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sum = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSum(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ SUB ------------------------\n\nexport const vSub = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSub(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sub = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSub(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ MUL SCALAR ------------------------\n\nexport const vMulScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n const vector: Vector = [];\n\n for(let i=0; i {\n return vMulScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3MulScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vMulScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ DIVIDE ------------------------\n\nexport const vDivideScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vDivideScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3DivideScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vDivideScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ LENGTH ------------------------\n\nexport const vLength = (vector: Vector, decimalPlaces = Infinity) => {\n let sum = 0;\n\n for(let i=0; i {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v3Length = (vector: Vector3, decimalPlaces = Infinity) => {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v2SetLength = (v2: Vector2, newLength: number, decimalPlaces = Infinity): Vector2 => {\n const angle = getV2Angle(v2);\n return [\n setDecimalPlaces(Math.cos(angle) * newLength, decimalPlaces),\n setDecimalPlaces(Math.sin(angle) * newLength, decimalPlaces),\n ];\n};\n\n// ----------- DISTANCE ------------------------\n\nexport const vDistance = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v2Distance = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v3Distance = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\n// ------------ NORMALIZE ------------------------\n\n/**\n * Normalization creates a unit vector, which is a vector of length 1.\n */\nexport const vNormalize = (v: Vector, decimalPlaces = Infinity) : Vector => {\n const length = vLength(v);\n const unitVector: Vector = [];\n\n for(let i=0; i {\n return vNormalize(v2, decimalPlaces) as Vector2;\n};\n\nexport const v3Normalize = (v3: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vNormalize(v3, decimalPlaces) as Vector3;\n};\n\n// ------------ DOT PRODUCT ------------------------\n\nexport const vDotProduct = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n let sum = 0;\n\n for(let i=0; i {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\nexport const v3DotProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\n// ------------ CROSS PRODUCT ------------------------\n\n/**\n * Cross product is possible on 3D vectors only.\n * The cross product a \u00D7 b is defined as a vector c that is perpendicular (orthogonal) to both a and b.\n */\nexport const v3CrossProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity): Vector3 => {\n return [\n setDecimalPlaces(vector1[1] * vector2[2] - vector1[2] * vector2[1], decimalPlaces),\n setDecimalPlaces(vector1[2] * vector2[0] - vector1[0] * vector2[2], decimalPlaces),\n setDecimalPlaces(vector1[0] * vector2[1] - vector1[1] * vector2[0], decimalPlaces),\n ];\n};\n\n// --------------- INIT VECTOR HELPER -----------------\n\nexport const v2 = (defaultValue = 0): Vector2 => {\n return [defaultValue, defaultValue];\n};\n\nexport const v3 = (defaultValue = 0): Vector3 => {\n return [defaultValue, defaultValue, defaultValue];\n};\n\nexport const v4 = (defaultValue = 0): Vector4 => {\n return [defaultValue, defaultValue, defaultValue, defaultValue];\n};\n\nexport const vN = (N: number, defaultValue = 0): Vector => {\n\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n const vector: Vector = [];\n for(let i=0; i {\n let vector: Vector2 = [0, 0];\n vector = v2SetLength(vector, distance);\n return setV2Angle(vector, angleRad);\n};\n\n// --------------- EQUALITY -------------------------\n\nexport const vEqual = (vector1: Vector, vector2: Vector): boolean => {\n if(vector1.length !== vector2.length) return false;\n\n for(let i=0; i {\n const sub = v2Sub(vector2, vector1);\n return [\n -setDecimalPlaces(sub[1], decimalPlaces),\n setDecimalPlaces(sub[0], decimalPlaces)\n ];\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector, Vector2, Vector3 } from '../../types';\nimport { vMulScalar, vSum, vSub, vDotProduct, vN, vEqual, vDivideScalar } from './vector';\n\n// --------------- SUM ----------------------\n\nexport const mSum = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sum = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- SUB ----------------------\n\nexport const mSub = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sub = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- MUL SCALAR ----------------------\n\nexport const mMulScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vMulScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2MulScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mMulScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3MulScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mMulScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n// --------------- DIVIDE SCALAR ----------------------\n\nexport const mDivideScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vDivideScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2DivideScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mDivideScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3DivideScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mDivideScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n\n// --------------- TRANSPOSE ----------------------\n\nexport const mTranspose = (m: Matrix): Matrix => {\n\n const vectorsCount = m.length;\n if(vectorsCount <= 0) return m;\n\n const vectorLength = m[0].length;\n if(vectorLength <= 0) return m;\n\n const matrix: Matrix = [];\n for(let i=0; i {\n return mTranspose(m2);\n};\n\nexport const m3Transpose = (m3: Matrix3): Matrix => {\n return mTranspose(m3);\n};\n\n// ----------------- RESET ----------------------\n\nexport const mReset = (m: Matrix, defaultValue = 0): Matrix => {\n\n if(m.length <= 0) return [];\n\n const res: Matrix = [];\n\n for(let i=0; i {\n return mReset(m2, defaultValue) as Matrix2;\n};\n\nexport const m3Reset = (m3: Matrix3, defaultValue = 0): Matrix3 => {\n return mReset(m3, defaultValue) as Matrix3;\n};\n\n// --------------- MATRIX INIT HELPERS -----------------\n\nexport const m2x2 = (defaultValue = 0): Matrix2 => {\n return [\n [defaultValue, defaultValue],\n [defaultValue, defaultValue],\n ];\n};\n\nexport const m3x3 = (defaultValue = 0): Matrix3 => {\n return [\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const m4x4 = (defaultValue = 0): Matrix4 => {\n return [\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const mNxM = (N: number, M: number, defaultValue = 0): Matrix => {\n if(N <= 0 || M <= 0){\n throw new Error('M and N must be positive numbers.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return [\n [1, 0],\n [0, 1],\n ];\n};\n\nexport const identity3 = (): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\nexport const identity4 = (): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Identity Matrix (I).\n * M x I = I x M = M for any matrix M.\n * Identity Matrix is a special case of scale matrix.\n */\nexport const identityN = (N: number): Matrix => {\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n if(N === 0) return [];\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mDeepCopy(m2) as Matrix2;\n};\n\nexport const m3DeepCopy = (m3: Matrix3): Matrix3 => {\n return mDeepCopy(m3) as Matrix3;\n};\n\n// -------------- APPEND / PREPEND ROW OR COLUMN ---------------\n\nexport const mAppendCol = (m: Matrix, col: Vector): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n const copy = mDeepCopy(m);\n copy.push(row);\n return copy;\n};\n\nexport const m2AppendRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.push(row);\n return copy;\n};\n\nexport const m3AppendRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.push(row);\n return copy;\n};\n\nexport const mPrependRow = (m: Matrix, row: Vector) : Matrix => {\n const copy = mDeepCopy(m);\n copy.unshift(row);\n return copy;\n};\n\nexport const m2PrependRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.unshift(row);\n return copy;\n};\n\nexport const m3PrependRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.unshift(row);\n return copy;\n};\n\n// ------------ DELETE ROW OR COLUMN ----------------------------\n\nexport const mDelLastRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.pop();\n return copy;\n};\n\nexport const mDelFirstRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.shift();\n return copy;\n};\n\nexport const mDelLastColumn = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const size = m[0].length;\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n\n const matrix: Matrix = [];\n for(let i=0; i {\n\n if(matrix.length < 0) return [];\n\n if(matrix[0].length !== vector.length){\n throw new Error('The number of columns in the matrix must be equal to the length of the vector.');\n }\n\n const res: Vector = [];\n\n for(let i=0; i {\n if(matrix1.length !== matrix2.length) return false;\n\n for(let i=0; i returns matrix N (m-1 x m-1)\n * The matrix must be square.\n */\nconst mMinorHelper = (m: Matrix, row: number, col: number) => {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // prepare the matrix without provided row and column\n const matrix = mMinorHelper(m, row, col);\n\n // calculate the matrix determinant\n return mDeterminant(matrix);\n};\n\n/**\n * Calculate determinant for NxN matrix.\n * Matrix should be square.\n */\nexport const mDeterminant = (matrix: Matrix): number => {\n const size = matrix.length;\n if(size === 0) return 1;\n\n if(size !== matrix[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return matrix[0][0];\n if(size === 2) return m2Determinant(matrix as Matrix2);\n\n let d = 0;\n\n for(let i=0; i {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return m2[0][0] * m2[1][1] - m2[1][0] * m2[0][1];\n};\n\n/**\n * Calculate determinant for 3x3 matrix.\n * Matrix should be square.\n */\nexport const m3Determinant = (m3: Matrix3): number => {\n if(m3.length !== m3[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return mDeterminant(m3);\n};\n\n// ------------------ INVERSE -----------------------\n\nexport const m2Adjugate = (m2: Matrix2): Matrix2|null => {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return [\n [m2[1][1], -m2[0][1]],\n [-m2[1][0], m2[0][0]],\n ];\n};\n\nexport const m3Adjugate = (m3: Matrix3) : Matrix3|null => {\n return mAdjugate(m3) as (Matrix3|null);\n};\n\n/**\n * Adjugate is a transpose of a cofactor matrix\n */\nexport const mAdjugate = (m: Matrix): Matrix|null => {\n\n const size = m.length;\n if(size <= 0) return null;\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return m;\n\n if(size === 2) return m2Adjugate(m as Matrix2);\n\n // build a cofactor matrix ----------------\n const cofactors: Matrix = [];\n\n for(let i=0; i {\n if(m.length > 0 && m.length !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = mDeterminant(m);\n return d === 0;\n};\n\n/**\n * Square matrix A (nxn) is invertible is there is another square matrix B (nxn) so AxB = BxA = I\n * For A (2x2) matrix, the inverse is:\n * (1 / (determinant(A))) * adj(A)\n */\nexport const m2Inverse = (m2: Matrix2, decimalPlaces = Infinity): (Matrix2 | null) => {\n if(m2.length > 0 && m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = m2Determinant(m2);\n if(d === 0) return null;\n\n const adj = m2Adjugate(m2);\n if(adj === null) return null;\n\n return m2DivideScalar(adj, d, decimalPlaces);\n};\n\nexport const m3Inverse = (m3: Matrix3, decimalPlaces = Infinity): (Matrix3 | null) => {\n return mInverse(m3, decimalPlaces) as (Matrix3|null);\n};\n\nexport const mInverse = (m: Matrix, decimalPlaces = Infinity): (Matrix | null) => {\n const size = m.length;\n\n if(size > 0 && size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // find a determinant ----------------------\n const d = mDeterminant(m);\n\n // find an Adjugate - a transpose of a cofactor matrix\n const adj = mAdjugate(m);\n if(adj === null) return null;\n\n return mDivideScalar(adj, d, decimalPlaces);\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector2, Vector3, Vector4 } from '../../types';\nimport { v2Normalize, v3MulScalar, v3Normalize } from './vector';\nimport { mMulVector, mMul } from './matrix';\nimport { setDecimalPlaces } from '../format';\n\n/*\nAny 2D affine transformation can be decomposed\ninto a rotation, followed by a scaling, followed by a\nshearing, and followed by a translation.\n---------------------------------------------------------\nAffine matrix = translation x shearing x scaling x rotation\n */\n\n// ----------------- CSS -------------------------------------\n\n/**\n * Matrix 2D in non-homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2ToCSS = (m: Matrix2) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, 0, 0)`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2hToCSS = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ tx }, ${ ty })`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m2hToCSS3d = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix3d(${ a }, ${ b }, 0, 0, ${ c }, ${ d }, 0, 0, 0, 0, 1, 0, ${ tx }, ${ ty }, 0, 1)`;\n};\n\n/**\n * Matrix 3D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m3hToCSS3d = (m: Matrix4) : string => {\n\n return `matrix3d(\n ${ m[0][0] }, ${ m[0][1] }, ${ m[0][2] }, ${ m[0][3] },\n ${ m[1][0] }, ${ m[1][1] }, ${ m[1][2] }, ${ m[1][3] },\n ${ m[2][0] }, ${ m[2][1] }, ${ m[2][2] }, ${ m[2][3] },\n ${ m[3][0] }, ${ m[3][1] }, ${ m[3][2] }, ${ m[3][3] }\n )`;\n};\n\n// ---------------- TRANSLATION MATRICES ----------------------\n\nexport const m2Translation = (position: Vector2, decimalPlaces = Infinity): Matrix2 => {\n\n return [\n [1, 0],\n [0, 1],\n [setDecimalPlaces(position[0], decimalPlaces), setDecimalPlaces(position[1], decimalPlaces)],\n ];\n};\n\nexport const m3Translation = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n [\n setDecimalPlaces(position[0], decimalPlaces),\n setDecimalPlaces(position[1], decimalPlaces),\n setDecimalPlaces(position[2], decimalPlaces)\n ],\n ];\n};\n\n/**\n * 2D Translation matrix in homogeneous coordinates.\n */\nexport const m2TranslationH = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1],\n ];\n};\n\n/**\n * 3D Translation matrix in homogeneous coordinates.\n */\nexport const m3TranslationH = (position: Vector4, decimalPlaces = Infinity): Matrix4 => {\n\n return [\n [1, 0, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, 0, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1, setDecimalPlaces(position[2], decimalPlaces)],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- ROTATION MATRICES -------------------------\n\n/**\n * Rotation of an angle about the origin.\n */\nexport const m2Rotation = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix2 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin],\n [sin, cos],\n ] :\n [\n [cos, sin],\n [-sin, cos],\n ];\n};\n\n/**\n * Rotation of an angle about the origin in homogeneous coordinates (clockwise).\n */\nexport const m2RotationH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ]:\n [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation of an angle \"angleRad\" around the given point (transformOrigin) in homogeneous coordinates (clockwise).\n * result_vector = TranslationMatrix(x, y) * RotationMatrix() * TranslationMatrix(-x, -y) * position_vector\n */\nexport const m2RotationAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const rotation = m2RotationH(angleRad, isClockwise, decimalPlaces);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, rotation);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2RotateAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n position: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2RotationAroundPointH(angleRad, transformOrigin, isClockwise, decimalPlaces);\n return mMulVector(mat3h, position) as Vector3;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2Rotate = (angleRad: number, vector: Vector2, isClockwise = true, decimalPlaces = Infinity): Vector2 => {\n const unitVector = v2Normalize(vector);\n return mMulVector(m2Rotation(angleRad, isClockwise, decimalPlaces), unitVector) as Vector2;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2RotateH = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m2RotationH(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the X axis (clockwise).\n */\nexport const m3RotationX = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0],\n [0, cos, -sin],\n [0, sin, cos],\n ] :\n [\n [1, 0, 0],\n [0, cos, sin],\n [0, -sin, cos],\n ];\n};\n\n/**\n * Rotation around the X axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationXH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0, 0],\n [0, cos, -sin, 0],\n [0, sin, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [1, 0, 0, 0],\n [0, cos, sin, 0],\n [0, -sin, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateX = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationX(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Y axis (clockwise).\n */\nexport const m3RotationY = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin],\n [0, 1, 0],\n [-sin, 0, cos],\n ] :\n [\n [cos, 0, -sin],\n [0, 1, 0],\n [sin, 0, cos],\n ];\n};\n\n/**\n * Rotation around the Y axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationYH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin, 0],\n [0, 1, 0, 0],\n [-sin, 0, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [cos, 0, -sin, 0],\n [0, 1, 0, 0],\n [sin, 0, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateY = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationY(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Z axis (clockwise).\n */\nexport const m3RotationZ = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ] : [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation around the Z axis (clockwise)- in homogeneous coordinates\n */\nexport const m3RotationZH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0, 0],\n [sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ] : [\n [cos, sin, 0, 0],\n [-sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateZ = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationZ(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n// ---------------- SCALE MATRICES -------------\n\n/**\n * Get matrix for arbitrary scaling pivot point.\n * result_vector = TranslationMatrix(x, y) * ScaleMatrix() * TranslationMatrix(-x, -y) * scale_vector\n */\nexport const m2ScaleAtPointHMatrix = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const scale = m2ScaleH(scaleVector);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, scale);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2ScaleAtPointH = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n point: Vector3,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2ScaleAtPointHMatrix(scaleVector, transformOrigin, decimalPlaces);\n return mMulVector(mat3h, point) as Vector3;\n};\n\nexport const m2Scale = (scaleVector: Vector2): Matrix2 => {\n return [\n [scaleVector[0], 0],\n [0, scaleVector[1]],\n ];\n};\n\nexport const v2Scale = (scaleVector: Vector2, vector: Vector2): Vector2 => {\n return mMulVector(m2Scale(scaleVector), vector) as Vector2;\n};\n\n/**\n * homogeneous coordinates\n */\nexport const m2ScaleH = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, 1],\n ];\n};\n\nexport const m3Scale = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, scaleVector[2]],\n ];\n};\n\nexport const m3ScaleH = (scaleVector: Vector4): Matrix4 => {\n return [\n [scaleVector[0], 0, 0, 0],\n [0, scaleVector[1], 0, 0],\n [0, 0, scaleVector[2], 0],\n [0, 0, 0, 1]\n ];\n};\n\nexport const v3Scale = (scaleVector: Vector3, vector: Vector3): Vector3 => {\n return mMulVector(m3Scale(scaleVector), vector) as Vector3;\n};\n\n/**\n * Stretch, parallel to the x-axis.\n */\nexport const m2ScaleX = (scale: number): Matrix2 => {\n return [\n [scale, 0],\n [0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the x-axis - homogeneous coordinates\n */\nexport const m2ScaleXH = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleX = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleXH = (scale: number): Matrix4 => {\n return [\n [scale, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleY = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleYH = (scale: number): Matrix => {\n return [\n [1, 0, 0, 0],\n [0, scale, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZ = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, scale],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZH = (scale: number): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, scale, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis.\n */\nexport const m2ScaleY = (scale: number): Matrix2 => {\n return [\n [1, 0],\n [0, scale],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis - homogeneous coordinates\n */\nexport const m2ScaleYH = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n// ---------------- REFLECTION MATRICES -------------------------\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOrigin = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOriginH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection about the origin in non-homogeneous coordinates\n */\nexport const m3ReflectionOrigin = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection about the origin in homogeneous coordinates\n */\nexport const m3ReflectionOriginH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection about y=-x\n */\nexport const m2ReflectionYmX = (): Matrix2 => {\n\n return [\n [0, -1],\n [-1, 0],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionX = (): Matrix2 => {\n\n return [\n [1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionXH = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection in the y-axis.\n */\nexport const m2ReflectionY = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, 1],\n ];\n};\n\nexport const m2ReflectionYH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionYZ = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in homogeneous coordinates\n */\nexport const m3ReflectionYZH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXZ = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in homogeneous coordinates\n */\nexport const m3ReflectionXZH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXY = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in homogeneous coordinates\n */\nexport const m3ReflectionXYH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- SHEARING MATRICES -------------------------\n\n\n/**\n * Shearing in y-axis, with x-axis fixed with (0,1) moving to (factor, 1)\n */\nexport const m2ShearingY = (factor: number): Matrix2 => {\n\n return [\n [1, factor],\n [0, 1],\n ];\n};\n\n/**\n * Shearing in x-axis, with y-axis fixed with (1,0) moving to (1, factor)\n */\nexport const m2ShearingX = (factor: number): Matrix2 => {\n\n return [\n [1, 0],\n [factor, 1],\n ];\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a random number in the [min,max] range.\n */\nexport const getRandom = (min: number, max: number, decimalPlaces = Infinity): number => {\n return setDecimalPlaces(Math.random() * (max - min) + min, decimalPlaces);\n};\n\n/**\n * Returns a random integer number in the [min,max] range.\n */\nexport const getRandomInt = (min: number, max: number): number => {\n return Math.floor(Math.random() * (max - min + 1) + min);\n};\n\nexport const getRandomBoolean = () => Math.random() < 0.5;\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getRandomItemFromArray = (array: any[]) => {\n const randomIndex = getRandomInt(0, array.length - 1);\n return array[randomIndex];\n};", "export const stringToNumber = (value: string|undefined|null|number, defaultNumber: number) => {\n if(value === undefined || value === null) return defaultNumber;\n const res = Number(value) ?? defaultNumber;\n return isNaN(res) ? defaultNumber : res;\n};", "import { setDecimalPlaces } from './format';\nimport { Vector2, Vector3 } from '../types';\n\n/**\n * u(x) and v(x) are functions ---------->\n *\n * dx(u + v) = dx(u) + dx(v)\n * dx(u - v) = dx(u) - dx(v)\n * dx(u * v) = dx(u) * v + u * dx(v)\n * dx(u / v) = (dx(u) * v - u * dx(v)) / (v ^ 2), when v(x) != 0\n */\n\n// ------------------ Derivatives of Polynomial ---------------------------\n\n/**\n * y = 3x+2\n * dxPolynomial(10, [[3, 1], [2, 0]])\n */\nexport const dxPolynomial = (x: number, polynomial: number[][], decimalPlaces = Infinity) => {\n let res = 0;\n\n for(const part of polynomial){\n if(part.length !== 2) return NaN;\n\n const coeff = part[0];\n const power = part[1];\n res += coeff * power * Math.pow(x, power - 1);\n }\n\n return setDecimalPlaces(res, decimalPlaces);\n}\n\n// ---------------------- Bezier Curves ---------------------------\n\n/**\n * Derivative of Bezier Curve is another Bezier Curve.\n * t must min in range [0, 1]\n */\nexport const dxV2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n // The derivative: P1 * (2t-2) + (2*P3-4*P2) * t + 2 * P2\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\nexport const dxV2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n\n// ----------------- Derivatives of trigonometry functions ---------------------------\n\nexport const dxSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(Math.cos(x), decimalPlaces);\n};\n\nexport const dxCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-Math.sin(x), decimalPlaces);\n};\n\nexport const dxTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.cos(x) ** 2), decimalPlaces);\n};\n\n/**\n * x != Math.PI * n, where n is an integer\n */\nexport const dxCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sin(x) ** 2), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\nexport const dxArcTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (1 + x ** 2), decimalPlaces);\n};\n\nexport const dxArcCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (1 + x ** 2), decimalPlaces);\n};\n", "import { Matrix, Matrix2, Matrix3, Vector, Vector2, Vector3 } from '../../types';\nimport { m2Inverse, m3Inverse, mInverse, mMulVector, mDelLastColumn, mGetLastColumn } from '../linear-algebra/matrix';\nimport { setDecimalPlaces } from '../format';\nimport { v2Sub } from '../linear-algebra/vector';\n\n/**\n * Linear equation\n * ax + b = c\n * x = (c - b) / a; a != 0\n */\nexport const linearEquation = (equation: Vector3, decimalPlaces = Infinity) : number => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n\n const diff = c - b;\n\n if(a === 0 && diff === 0) return Infinity; // any number is a solution\n if(a === 0) return NaN; // no solution\n\n return setDecimalPlaces(diff / a, decimalPlaces);\n};\n\n/**\n * System of 2 linear equations.\n * [x, y] = inverse(Matrix of equation parameters) x (vector of equation results)\n * ---------------\n * 3x + 2y = 7\n * -6x + 6y = 6\n */\nexport const linearEquationSystem2 = (equation1: Vector3, equation2: Vector3, decimalPlaces = Infinity) : Vector2 | null => {\n const equationParams: Matrix2 = [\n [equation1[0], equation1[1]],\n [equation2[0], equation2[1]],\n ];\n\n const inversed = m2Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector2 = [\n equation1[2],\n equation2[2]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector2;\n};\n\n/**\n * System of 3 linear equations.\n * ---------------------------------------\n * 3x + 2y + 5z = 7\n * -6x + 6y + 6z = 6\n * 2x + 7y - z = 4\n */\nexport const linearEquationSystem3 = (\n equation1: Vector,\n equation2: Vector,\n equation3: Vector,\n decimalPlaces = Infinity) : Vector3 | null => {\n const equationParams: Matrix3 = [\n [equation1[0], equation1[1], equation1[2]],\n [equation2[0], equation2[1], equation2[2]],\n [equation3[0], equation3[1], equation3[2]],\n ];\n\n const inversed = m3Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector3 = [\n equation1[3],\n equation2[3],\n equation3[3]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector3;\n};\n\n/**\n * System of N linear equations.\n */\nexport const linearEquationSystemN = (equations: Matrix, decimalPlaces = Infinity) : Vector | null => {\n if(equations.length <= 0) return null;\n\n const equationParams = mDelLastColumn(equations);\n\n const inversed = mInverse(equationParams);\n if(inversed === null) return null; // no results\n\n // the last column of the equations matrix\n const equationResults = mGetLastColumn(equations);\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector;\n};\n\n/**\n * Calculate the equation of a line given two points in a 2D space.\n * y = ax + b\n * y - y1 = m(x - x1)\n * m = (y2 - y1) / (x2 - x1)\n */\nexport const getLinearEquationBy2Points = (point1: Vector2, point2: Vector2) : {\n slope: number|undefined,\n yIntercept: number|undefined,\n xIntercept: number|undefined,\n formula: string,\n} => {\n const [deltaX, deltaY] = v2Sub(point2, point1);\n const [x, y] = point1;\n\n if(deltaX === 0) {\n return {\n slope: undefined,\n xIntercept: x,\n yIntercept: undefined,\n formula: `x = ${ x }`,\n };\n }\n\n const m = deltaY / deltaX;\n const b = y - m * x;\n let formula = '';\n\n if(m === 0) {\n formula = `y = ${ b }`;\n }\n else{\n formula = `y = ${ m === 1 ? '' : m }x`;\n\n if(b !== 0) {\n formula += ` ${ b < 0 ? '-' : '+' } ${ Math.abs(b) }`;\n }\n }\n\n return {\n slope: m,\n xIntercept: undefined,\n yIntercept: b,\n formula,\n };\n};", "import { Vector } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { linearEquation } from './linear-equations';\nimport { isNumber } from '../other';\n\n/**\n * Quadratic Equation.\n * ax^2 + bx + c = d\n */\nexport const quadraticEquation = (equation: Vector, decimalPlaces = Infinity) : Vector => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n const d = equation[3];\n\n if(a === 0){\n // it's a linear equation -------------------------------------------\n const res = linearEquation([b, c, d], decimalPlaces);\n if(isNumber(res)) return [res];\n return [];\n }\n\n const diff = c - d;\n\n const discriminant = b * b - (4 * a * diff);\n\n if(discriminant < 0){\n return []; // no results\n }\n\n if(discriminant === 0){\n return [ setDecimalPlaces(-b / (2 * a), decimalPlaces) ]; // 1 result\n }\n\n // if(determinant > 0) ---> 2 results\n const t1 = 2 * a;\n const t2 = Math.sqrt(discriminant);\n\n return [\n setDecimalPlaces((-b + t2) / t1, decimalPlaces),\n setDecimalPlaces((-b - t2) / t1, decimalPlaces),\n ];\n};", "import { IBBox, Vector, Vector2, Vector3 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport {\n dxV2CubicBezierCurve,\n dxV2QuadraticBezierCurve,\n dxV3CubicBezierCurve,\n dxV3QuadraticBezierCurve\n} from '../derivative';\nimport { v2Normalize, v3Normalize } from '../linear-algebra/vector';\nimport { linearEquation } from '../equations/linear-equations';\nimport { quadraticEquation } from '../equations/quadratic-equations';\nimport { isNumber } from '../other';\n\n/**\n * B\u00E9zier Curves\n * quadratic: y = P1 * (1-t)\u00B2 + P2 * 2 * (1-t)t + P3 * t\u00B2\n * t in range [0, 1]\n */\n\n// -------------------- GET POINT ON CURVE --------------------------\n\n/**\n * Get a point on a quadratic B\u00E9zier curve as a function of time.\n */\nexport const v2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n/**\n * Get a point on a cubic B\u00E9zier curve as a function of time.\n */\nexport const v2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n// -------------------- TANGENT --------------------------\n\n/**\n * Tangent indicates the direction of travel at specific points along the B\u00E9zier curve,\n * and is literally just the first derivative of our curve.\n */\nexport const v2QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\nexport const v2CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\n// -------------------- NORMAL --------------------------\n\n/**\n * Normal is a vector that runs at a right angle to the direction of the curve, and is typically of length 1.\n * To find it, we take the normalised tangent vector, and then rotate it by a 90 degrees.\n */\nexport const v2QuadraticBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2QuadraticBezierCurveTangent(t, startControlPoint, centerControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\nexport const v2CubicBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2CubicBezierCurveTangent(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\n// -------------------- EXTREMA --------------------------\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2QuadraticBezierCurveExtrema = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector => {\n\n /*\n (-2 * (1 - t)) * startControlPoint[0] + (2 - 4 * t) * centerControlPoint[0] + (2 * t) * endControlPoint[0]\n 2 * t * startControlPoint[0] - 4 * t * centerControlPoint[0] + 2 * t * endControlPoint[0] - 2 * startControlPoint[0] + 2 * centerControlPoint[0]\n t * (2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0]) + (- 2 * startControlPoint[0] + 2 * centerControlPoint[0])\n */\n\n const a1 = 2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0];\n const b1 = -2 * startControlPoint[0] + 2 * centerControlPoint[0];\n const equation1: Vector3 = [a1, b1, 0];\n const res1 = linearEquation(equation1, decimalPlaces);\n\n const a2 = 2 * startControlPoint[1] - 4 * centerControlPoint[1] + 2 * endControlPoint[1];\n const b2 = -2 * startControlPoint[1] + 2 * centerControlPoint[1];\n const equation2: Vector3 = [a2, b2, 0];\n const res2 = linearEquation(equation2, decimalPlaces);\n\n const res: Vector = [];\n\n if(isNumber(res1)){\n res.push(res1);\n }\n\n if(isNumber(res2)){\n res.push(res2);\n }\n\n return res;\n};\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2CubicBezierCurveExtrema = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2|null => {\n\n const a1 = -3 * startControlPoint[0] + 9 * center1ControlPoint[0] - 9 * center2ControlPoint[0] + 3 * endControlPoint[0];\n const b1 = 6 * startControlPoint[0] - 12 * center1ControlPoint[0] + 6 * center2ControlPoint[0];\n const c1 = -3 * startControlPoint[0] + 3 * center1ControlPoint[0];\n const equation1: Vector = [a1, b1, c1, 0];\n\n const a2 = -3 * startControlPoint[1] + 9 * center1ControlPoint[1] - 9 * center2ControlPoint[1] + 3 * endControlPoint[1];\n const b2 = 6 * startControlPoint[1] - 12 * center1ControlPoint[1] + 6 * center2ControlPoint[1];\n const c2 = -3 * startControlPoint[1] + 3 * center1ControlPoint[1];\n const equation2: Vector = [a2, b2, c2, 0];\n\n // Any value between 0 and 1 is a root that matters for B\u00E9zier curves, anything below or above that is irrelevant (because B\u00E9zier curves are only defined over the interval [0,1]).\n const res1 = quadraticEquation(equation1, decimalPlaces).filter(num => num >= 0 && num <= 1);\n const res2 = quadraticEquation(equation2, decimalPlaces).filter(num => num >= 0 && num <= 1);\n\n const res = [...res1, ...res2];\n if(res.length === 2){\n return [...res1, ...res2] as Vector2;\n }\n\n return null;\n};\n\n// -------------------- BOUNDING BOX --------------------------\n\nexport const v2QuadraticBezierBBox = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2QuadraticBezierCurveExtrema(startControlPoint, centerControlPoint, endControlPoint);\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2QuadraticBezierCurve(percent, startControlPoint, centerControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\nexport const v2CubicBezierBBox = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2CubicBezierCurveExtrema(startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint) || [];\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2CubicBezierCurve(percent, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x ?? Infinity);\n maxX = Math.max(maxX, x ?? -Infinity);\n\n minY = Math.min(minY, y ?? Infinity);\n maxY = Math.max(maxY, y ?? -Infinity);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\n\n", "import { Vector2 } from '../types';\nimport { v2Sub } from './linear-algebra/vector';\nimport { getV2Angle } from './angle';\nimport { convertRange } from './other';\n\n/**\n * Circle Equation\n * x^2 + y^2 = radius^2\n * ----------------------\n * Circle Parametric Equation\n * x(t) = radius * cos(t)\n * y(t) = radius * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const circleMovement = (center: Vector2, angle: number, radius: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius,\n center[1] + Math.sin(angle) * radius\n ];\n};\n\n/**\n * Circle Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const circleMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radius: number\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return circleMovement(center, angle, radius);\n};\n\n/**\n * Ellipse Equation\n * (x - centerX)^2 / (radius1^2) + (y - centerY)^2 / (radius2^2) = 1\n * -----------------------------------------------------------------\n * Ellipse Parametric Equation\n * x(t) = radius1 * cos(t)\n * y(t) = radius2 * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const ellipseMovement = (center: Vector2, angle: number, radius1: number, radius2: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius1,\n center[1] + Math.sin(angle) * radius2\n ];\n};\n\n/**\n * Ellipse Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const ellipseMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radii: Vector2\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return ellipseMovement(center, angle, radii[0], radii[1]);\n};\n\n/**\n * Sine Wave Equation (Sinusoid)\n * -----------------------------\n * const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n * amplitude = the peak deviation of the function from zero\n * frequency = number of cycles\n * phase = specifies (in radians) where in its cycle the oscillation is at t = 0.\n * think of it as \"shifting\" the starting point of the function to the right (positive p) or left (negative)\n */\nexport const sineWaveMovement = (x: number, amplitude: number, frequency: number, phase: number) : Vector2 => {\n /*\n example values:\n const amplitude = 50;\n const frequency = 0.005;\n const phase = 0;\n x: [0, 1000]\n */\n const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n\n return [x, y];\n};\n\n/**\n * Lissajous curve (Lissajous figure or Bowditch curve)\n * Parametric equation #1\n * f(t) = A * sin(k * t + m)\n * f(t) = B * sin(n * t)\n * 0 <= m <= PI/2\n * k, n >= 1\n * -----------------------\n * Parametric equation #2\n * f(t) = A * cos(k * t - m)\n * f(t) = B * cos(n * t - p)\n * -----------------------------\n * Shapes:\n * k = 1, n = 1, m = 0, p = 0 ---> line\n * A = B, k = 1, n = 1, m = PI/2, p = PI/2 ----> circle\n * A != B, k = 1, n = 1, m = PI/2, p = PI/2 ----> ellipse\n * k = 2, n = 2, m = PI/2, p = PI/2 ----> section of a parabola\n */\nexport const lissajousCurve = (\n width: number,\n height: number,\n t: number,\n k: number,\n n: number,\n m: number,\n p: number\n) :Vector2 => {\n return [\n width * Math.cos(k * t - m),\n height * Math.cos(n * t - p),\n ];\n};\n", "import { getRandom } from './random';\nimport { HSLColor, LABColor, RGBColor } from '../types';\nimport { mod } from './other';\nimport { setDecimalPlaces } from './format';\n\n// ------------------------ RANDOM COLOR -------------------------------------\n\nexport const getRandomRGBColor = () : RGBColor => {\n const hslColor = getRandomHSLColor();\n return hslToRgb(hslColor);\n};\n\nexport const getRandomHexColor = () : string => {\n const hslColor = getRandomHSLColor();\n return hslToHex(hslColor);\n};\n\nexport const getRandomHSLColor = () : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given hue\n */\nexport const getRandomHSLColorWithHue = (h: number) : HSLColor => {\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given saturation\n */\nexport const getRandomHSLColorWithSaturation = (s: number) : HSLColor => {\n const h = getRandom(1, 360);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given lightness\n */\nexport const getRandomHSLColorWithLightness = (l: number) : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n return [h, s, l];\n};\n\nexport const getRandomGrayscaleHSLColor = () : HSLColor => {\n const l = getRandom(0, 100);\n return [0, 0, l];\n};\n\nexport const getRandomHSLColorWithinRanges = (\n hueStart = 1, hueEnd = 360,\n saturationStart = 0, saturationEnd = 100,\n lightStart = 0, lightEnd = 100\n) : HSLColor => {\n const h = getRandom(hueStart, hueEnd);\n const s = getRandom(saturationStart, saturationEnd);\n const l = getRandom(lightStart, lightEnd);\n return [h, s, l];\n};\n\n// ----------------------- CONVERT COLORS --------------------------------------\n\n/**\n * helper: convert hue value to degrees.\n * @param {number} h\n * @return {number} [0, 360] degrees\n */\nconst convertHueToDegrees = (h : number) : number => {\n\n // the hue value needs to be multiplied by 60 to convert it to degrees\n h *= 60;\n\n // if hue becomes negative, you need to add 360 to, because a circle has 360 degrees\n if(h < 0){\n h += 360;\n }\n\n return h;\n // convert huw to %\n // return h * 100 / 360;\n};\n\n/**\n * get hue from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] % - we use here % instead of [0, 359] degrees\n */\nconst getHue = (r : number, g : number, b : number, min : number | undefined = undefined, max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (max === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no hue, as it's gray\n if(min === max) return 0;\n\n const diff = max - min;\n\n let h = 0;\n\n // if red is max\n if(max === r){\n h = (g - b) / diff + (g < b ? 6 : 0);\n }\n\n // if green is max\n if(max === g){\n h = 2 + (b - r) / diff;\n }\n\n // if blue is max\n if(max === b){\n h = 4 + (r - g) / diff;\n }\n\n return convertHueToDegrees(h);\n};\n\n/**\n * get luminance from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] %\n */\nconst getLuminance = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // calculate the luminance value\n // @ts-ignore\n const l = (min + max) / 2; // [0, 1]\n\n // return l value in %\n return l * 100;\n};\n\n/**\n * get saturation from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @param {number|undefined=} l - luminance in [0, 100] %\n * @return {number} [0, 100] %\n */\nconst getSaturation = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined,\n l : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no saturation, as it's gray\n if(min === max) return 0;\n\n // calculate luminance if it's not provided\n l = (l === undefined) ? getLuminance(r, g, b) : l;\n\n // check the level of luminance\n const s = (l <= 50) ?\n // @ts-ignore\n ((max - min) / (max + min)) : // this formula is used when luminance <= 50%\n // @ts-ignore\n (max - min) / (2.0 - max - min); // this formula is used when luminance > 50%\n\n // return saturation in %\n return s * 100;\n};\n\nexport const rgbToHsl = (rgb: RGBColor, decimalPlaces = Infinity): HSLColor => {\n\n // convert rgb values to the range [0, 1]\n const r = rgb[0] / 255;\n const g = rgb[1] / 255;\n const b = rgb[2] / 255;\n\n // find the minimum and maximum values of r, g, and b\n const min = Math.min(r, g, b);\n const max = Math.max(r, g, b);\n\n // calculate the luminance value in %\n const l = getLuminance(r, g, b, min, max);\n\n // calculate the saturation in %\n const s = getSaturation(r, g, b, min, max, l);\n\n // calculate the hue in % (not in degrees!)\n const h = getHue(r, g, b, min, max);\n\n if(h > 360 || s > 100 || l > 100){\n return [0, 0, 100];\n }\n\n if(h < 0 || s < 0 || l < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(h, decimalPlaces),\n setDecimalPlaces(s, decimalPlaces),\n setDecimalPlaces(l, decimalPlaces),\n ];\n};\n\n/**\n * helper: HSL to RGB\n */\nconst hslToRgbHelper = (helper1 : number, helper2 : number, colorHelper : number) : number => {\n\n // all values need to be between 0 and 1\n // if you get a negative value you need to add 1 to it\n if(colorHelper < 0) colorHelper += 1;\n\n // if you get a value above 1 you need to subtract 1 from it.\n if(colorHelper > 1) colorHelper -= 1;\n\n if(colorHelper * 6 < 1) return helper2 + (helper1 - helper2) * 6 * colorHelper;\n\n if(colorHelper * 2 < 1) return helper1;\n\n if(colorHelper * 3 < 2){\n return helper2 + (helper1 - helper2) * (0.666 - colorHelper) * 6;\n }\n else{\n return helper2;\n }\n};\n\nexport const hslToRgb = (hsl: HSLColor, decimalPlaces = Infinity): RGBColor => {\n\n // convert all values to [0, 1] from %\n const h = hsl[0] / 100;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n // if there is no saturation -> it\u2019s grey\n if(s === 0){\n // convert the luminance from [0, 1] to [0, 255]\n const gray = l * 255;\n return [gray, gray, gray];\n }\n\n // check the level of luminance\n const helper1 = (l < 0.5) ?\n (l * (1.0 + s)) :\n (l + s - l * s);\n\n const helper2 = 2 * l - helper1;\n\n const rHelper = h + 0.333;\n const gHelper = h;\n const bHelper = h - 0.333;\n\n let r = hslToRgbHelper(helper1, helper2, rHelper);\n let g = hslToRgbHelper(helper1, helper2, gHelper);\n let b = hslToRgbHelper(helper1, helper2, bHelper);\n\n // convert rgb to [0, 255]\n r *= 255;\n g *= 255;\n b *= 255;\n\n if(r > 255 || g > 255 || b > 255){\n return [255, 255, 255];\n }\n\n if(r < 0 || g < 0 || b < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(r, decimalPlaces),\n setDecimalPlaces(g, decimalPlaces),\n setDecimalPlaces(b, decimalPlaces),\n ];\n};\n\n/**\n * HSL to hex\n * hslToHex(360, 100, 50) // [360, 100, 5] ==> \"#ff0000\" (red)\n */\nexport const hslToHex = (hsl: HSLColor) => {\n\n if(hsl[0] > 360 || hsl[1] > 100 || hsl[2] > 100){\n return '#ffffff';\n }\n\n if(hsl[0] < 0 || hsl[1] < 0 || hsl[2] < 0){\n return '#000000';\n }\n\n const h = hsl[0] / 360;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n let r, g, b;\n if (s === 0) {\n r = g = b = l; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n r = hue2rgb(p, q, h + 1 / 3);\n g = hue2rgb(p, q, h);\n b = hue2rgb(p, q, h - 1 / 3);\n }\n const toHex = (x: number) => {\n const hex = Math.round(x * 255).toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n};\n\n/**\n * RGB to HEX\n * rgbToHex([235, 64, 52]) // #eb4034\n */\nexport const rgbToHex = (rgb: RGBColor) => {\n const [r, g, b] = rgb;\n return '#' + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);\n};\n\nexport const hexToRgb = (hex: string) : RGBColor | null => {\n\n const shorthandRegex = /^#?([a-f\\d])([a-f\\d])([a-f\\d])$/i;\n const _hex = hex.replace(shorthandRegex, (_m, r, g, b) => {\n return r + r + g + g + b + b;\n });\n\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(_hex);\n if(!result) return null;\n\n const r = parseInt(result[1], 16);\n const g = parseInt(result[2], 16);\n const b = parseInt(result[3], 16);\n\n return [r, g, b];\n};\n\nexport const rgbToLab = (rgb: RGBColor, decimalPlaces = Infinity) : LABColor => {\n\n let r = rgb[0] / 255;\n let g = rgb[1] / 255;\n let b = rgb[2] / 255;\n\n r = (r > 0.04045) ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;\n g = (g > 0.04045) ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;\n b = (b > 0.04045) ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;\n\n let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;\n let y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;\n let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;\n\n x = (x > 0.008856) ? Math.pow(x, 1/3) : (7.787 * x) + 16/116;\n y = (y > 0.008856) ? Math.pow(y, 1/3) : (7.787 * y) + 16/116;\n z = (z > 0.008856) ? Math.pow(z, 1/3) : (7.787 * z) + 16/116;\n\n return [\n setDecimalPlaces((116 * y) - 16, decimalPlaces),\n setDecimalPlaces(500 * (x - y), decimalPlaces),\n setDecimalPlaces(200 * (y - z), decimalPlaces),\n ];\n};\n\nexport const labToRgb = (lab: LABColor, decimalPlaces = Infinity) : RGBColor => {\n let y = (lab[0] + 16) / 116;\n let x = lab[1] / 500 + y;\n let z = y - lab[2] / 200;\n\n x = 0.95047 * ((x * x * x > 0.008856) ? x * x * x : (x - 16/116) / 7.787);\n y = 1.00000 * ((y * y * y > 0.008856) ? y * y * y : (y - 16/116) / 7.787);\n z = 1.08883 * ((z * z * z > 0.008856) ? z * z * z : (z - 16/116) / 7.787);\n\n let r = x * 3.2406 + y * -1.5372 + z * -0.4986;\n let g = x * -0.9689 + y * 1.8758 + z * 0.0415;\n let b = x * 0.0557 + y * -0.2040 + z * 1.0570;\n\n r = (r > 0.0031308) ? (1.055 * Math.pow(r, 1/2.4) - 0.055) : 12.92 * r;\n g = (g > 0.0031308) ? (1.055 * Math.pow(g, 1/2.4) - 0.055) : 12.92 * g;\n b = (b > 0.0031308) ? (1.055 * Math.pow(b, 1/2.4) - 0.055) : 12.92 * b;\n\n return [\n setDecimalPlaces(Math.max(0, Math.min(1, r)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, g)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, b)) * 255, decimalPlaces),\n ];\n};\n\n// ----------------------- GET SHIFTED COLORS --------------------------------------\n\nexport const getShiftedHue = (color: HSLColor, shift = 180) : HSLColor => {\n let hue = color[0];\n hue += shift;\n\n if (hue > 360 || hue < 0) {\n hue = mod(hue, 360);\n }\n\n return [hue, color[1], color[2]];\n};\n\nexport const getShiftedLightness = (color: HSLColor, shift = 10) : HSLColor => {\n let lightness = color[2];\n lightness += shift;\n\n if (lightness > 100 || lightness < 0) {\n lightness = mod(lightness, 100);\n }\n\n return [color[0], color[1], lightness];\n};\n\nexport const getShiftedSaturation = (color: HSLColor, shift = 10) : HSLColor => {\n let saturation = color[1];\n saturation += shift;\n\n if (saturation > 100) {\n saturation -= 100;\n }\n\n if(saturation < 0){\n saturation += 100;\n }\n\n return [color[0], saturation, color[2]];\n};\n\n// ----------------------- SIMILAR COLORS --------------------------------------\n\n/**\n * Measure the perceptual difference between two RGB colors using the CIE76 color difference formula:\n * delta = Math.sqrt((L2 - L1)^2 + (a2 - a1)^2 + (b2 - b1)^2)\n * https://en.wikipedia.org/wiki/Color_difference\n * https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js\n * <= 1.0 Not perceptible by human eyes.\n * 1 - 2 Perceptible through close observation.\n * 2 - 10 Perceptible at a glance.\n * 11 - 49 Colors are more similar than opposite\n * 100 Colors are exact opposite\n */\nexport const getColorsDelta = (rgbA: RGBColor, rgbB: RGBColor, decimalPlaces = Infinity) => {\n const labA = rgbToLab(rgbA, decimalPlaces);\n const labB = rgbToLab(rgbB, decimalPlaces);\n\n // differences between the LAB components of the two colors\n const deltaL = labA[0] - labB[0];\n const deltaA = labA[1] - labB[1];\n const deltaB = labA[2] - labB[2];\n\n // chroma components\n const c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);\n const c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);\n const deltaC = c1 - c2;\n\n // difference in hue, deltaH, which takes into account both the differences\n // in the a* and b* components of LAB and the differences in chroma.\n let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;\n deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);\n\n const sc = 1.0 + 0.045 * c1;\n const sh = 1.0 + 0.015 * c1;\n\n // It applies weighting factors to the differences in lightness (deltaL),\n // chroma (deltaC), and hue (deltaH).\n const deltaLKlsl = deltaL / (1.0);\n const deltaCkcsc = deltaC / (sc);\n const deltaHkhsh = deltaH / (sh);\n\n // It computes the final color difference using the CIE76 formula:\n // deltaE = sqrt(deltaLKlsl^2 + deltaCkcsc^2 + deltaHkhsh^2),\n // where deltaLKlsl is the weighted lightness difference,\n // deltaCkcsc is the weighted chroma difference,\n // and deltaHkhsh is the weighted hue difference.\n const i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;\n\n // It returns the calculated color difference,\n // optionally rounded to the specified number of decimal places.\n return i < 0 ? 0 : Math.sqrt(i);\n};\n", "/**\n * guid like '932ade5e-c515-4807-ac01-73b20ab3fb66'\n */\nexport const guid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0;\n return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);\n });\n};\n\n/**\n * id like 'df4unio1opulby2uqh4'\n */\nexport const newId = () => {\n return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);\n};\n", "import { ICircle, IPolygon, IRect, Matrix2, Vector2 } from '../types';\nimport { mod } from './other';\nimport { v2GetNormal, v2DotProduct } from './linear-algebra/vector';\n\n/**\n * Rectangles collision detection.\n * Rectangles should not be rotated.\n * The algorithm works by ensuring there is no gap between any of the 4 sides of the rectangles.\n * Any gap means a collision does not exist.\n * Returns true if collision is detected.\n */\nexport const rectCollide = (rect1: IRect, rect2: IRect) : boolean => {\n return rect1.x <= rect2.x + rect2.w &&\n rect1.x + rect1.w >= rect2.x &&\n rect1.y <= rect2.y + rect2.h &&\n rect1.h + rect1.y >= rect2.y;\n};\n\n/**\n * Circles collision detection.\n * This algorithm works by taking the center points of the two circles\n * and ensuring the distance between the center points\n * are less than the two radii added together.\n * Returns true if collision is detected.\n */\nexport const circleCollide = (circle1: ICircle, circle2: ICircle) => {\n const dx = Math.abs(circle1.cx - circle2.cx);\n const dy = Math.abs(circle1.cy - circle2.cy);\n const distance = Math.sqrt(dx * dx + dy * dy);\n return distance <= circle1.r + circle2.r;\n};\n\n//-------------------- Separating Axis Theorem (SAT) Collision detection -------------------------\n\nconst getEdges = (poly: IPolygon) : Matrix2[] => {\n const edges: Matrix2[] = [];\n\n for(let i= 0; i {\n const edges: Matrix2[] = [];\n\n // collect polygon edges, and combine then into a single array\n edges.push(...getEdges(poly1));\n edges.push(...getEdges(poly2));\n\n // for each edge, find the normal vector and project both polygons onto it\n for (const edge of edges) {\n const normal = v2GetNormal(edge[0], edge[1]);\n const p1Proj = projectPolygon(poly1, normal);\n const p2Proj = projectPolygon(poly2, normal);\n\n // Check if the projections overlap\n const isOverlap = p1Proj.max >= p2Proj.min && p2Proj.max >= p1Proj.min;\n\n // Check if the projections overlap; if not, the polygons do not collide\n if (!isOverlap) return false;\n }\n\n // If all tests pass, the polygons overlap and collide\n return true;\n};\n\n/**\n * Project every polygon point onto the normal.\n * Then find min and max.\n */\nconst projectPolygon = (polygon: IPolygon, normal: Vector2): { min: number, max: number } => {\n let min = Infinity;\n let max = -Infinity;\n\n // Project each vertex of the polygon onto the axis\n for (const vertex of polygon) {\n const projection = v2DotProduct(vertex, normal);\n min = Math.min(min, projection);\n max = Math.max(max, projection);\n }\n\n return { min, max };\n};", "export interface IAnimationProps {\n duration?: number;\n callback: (result: IAnimationResult) => void;\n restartOnResize?: boolean;\n resizeCallback?: (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => void;\n}\n\nexport interface IAnimationResult {\n start: () => void;\n stop: () => void;\n pause: () => void;\n resume: () => void;\n restart: () => void;\n isAnimating: () => boolean;\n getStartTime: () => number|undefined;\n getElapsedTime: () => number|undefined;\n getPercent: () => number|undefined;\n getResizeObserver: () => ResizeObserver|undefined;\n}\n\nexport const animate = (props: IAnimationProps) : IAnimationResult => {\n\n const _duration = props.duration !== undefined ? props.duration : Infinity;\n\n let startTime: number|undefined = undefined; // in milliseconds\n let animationId: number|undefined = undefined;\n\n // the time elapsed since the start of the animation (in milliseconds)\n let elapsed: number|undefined = undefined;\n let previousTimeStamp: number|undefined = undefined;\n\n let animating = false;\n let observer: ResizeObserver|undefined = undefined;\n\n // -------------------- COMMANDS ---------------------\n\n const stop = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = false;\n\n /*if(observer !== undefined){\n observer.disconnect();\n observer = undefined;\n }*/\n\n if(animationId === undefined) return;\n window.cancelAnimationFrame(animationId);\n };\n\n const restart = () => {\n stop();\n start();\n };\n\n const pause = () => {\n animating = false;\n };\n\n const resume = () => {\n animating = true;\n };\n\n /**\n * Animation Step.\n * @param {number} timeStamp in milliseconds\n */\n const step = (timeStamp: DOMHighResTimeStamp) => {\n\n if (startTime === undefined) {\n startTime = timeStamp;\n }\n\n // the time elapsed since the start of the animation (in milliseconds)\n elapsed = timeStamp - startTime;\n\n if (animating && previousTimeStamp !== timeStamp && typeof props.callback === 'function') {\n\n // do the rendering .............\n props.callback(getResult());\n }\n\n if(elapsed <= _duration){\n previousTimeStamp = timeStamp;\n animationId = window.requestAnimationFrame(step);\n }\n else{\n stop();\n }\n };\n\n const observerHandler = (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => {\n restart();\n\n if(typeof props.resizeCallback === 'function'){\n props.resizeCallback(_entries, _observer);\n }\n };\n\n const start = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = true;\n\n if(props.restartOnResize && window.ResizeObserver && observer === undefined){\n observer = new ResizeObserver(observerHandler);\n observer.observe(document.body, { box: 'border-box' });\n }\n else{\n animationId = window.requestAnimationFrame(step);\n }\n };\n\n // --------------- GET INFO ----------------------\n\n /**\n * the time elapsed since the start of the animation (in milliseconds)\n */\n const getElapsedTime = () : number|undefined => {\n return elapsed;\n };\n\n const isAnimating = () => {\n return animating;\n };\n\n const getStartTime = () => {\n return startTime;\n };\n\n const getPercent = () => {\n if(_duration === Infinity || elapsed === undefined) return undefined;\n return elapsed * 100 / _duration;\n };\n\n const getResizeObserver = () => {\n return observer;\n };\n\n const getResult = () : IAnimationResult => {\n return {\n\n // commands --------------\n start,\n stop,\n pause,\n resume,\n restart,\n\n // information -------\n isAnimating,\n getElapsedTime,\n getStartTime,\n getPercent,\n getResizeObserver,\n };\n };\n\n return getResult();\n};\n", "import { setDecimalPlaces } from './format';\n\nexport const getCircleCircumference = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * radius, decimalPlaces);\n};\n\nexport const getEllipseCircumference = (radius1: number, radius2: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * Math.sqrt((radius1 ** 2 + radius2 ** 2) / 2), decimalPlaces);\n};\n\nexport const isAngleInCircleArc = (startAngleDeg: number, endAngleDeg: number, currentDegrees: number) : boolean => {\n\n if(startAngleDeg > endAngleDeg) {\n endAngleDeg += 360;\n }\n\n return currentDegrees >= startAngleDeg && currentDegrees <= endAngleDeg ||\n (currentDegrees + 360) >= startAngleDeg && (currentDegrees + 360) <= endAngleDeg;\n};\n\n/**\n * get the side of a square inscribed in a circle\n */\nexport const getSquareInCircleSide = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(radius * 2 / Math.sqrt(2), decimalPlaces);\n};\n", "/**\n * 1 + 2 + ... + n = n * (n + 1) / 2\n */\nexport const naturalNumbersSequenceSum = (n: number) => {\n return n * (n + 1) / 2;\n};\n\n/**\n * n = the number of terms to be added\n * a = the first term in the sequence\n * d = the constant value between terms\n */\nexport const arithmeticSequenceSum = (n: number, a: number, d: number) => {\n return (n / 2) * (2 * a + (n - 1) * d);\n};", "\n// -------------------- CENTRAL TENDENCY ----------------------------\n\nimport { setDecimalPlaces } from './format';\n\n/**\n * Central tendency: Calculate the Average (mean)\n * Sum of all numbers divided by the array length.\n */\nexport const getArithmeticMean = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const sum = data.reduce((acc, val) => acc + val, 0);\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};\n\n/**\n * Central tendency: What is the central number in the sorted array?\n * Good for lists like [3, 3, 3, 3, 3, 3, 100] - 100 here is called \"Outlier\"\n */\nexport const getMedian = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const copy = [...data].sort((num1, num2) => num1 - num2);\n const mid = Math.floor(copy.length / 2);\n\n if(copy.length % 2 === 0) {\n return setDecimalPlaces((copy[mid] + copy[mid - 1]) / 2, decimalPlaces);\n }\n else {\n return setDecimalPlaces(copy[mid], decimalPlaces);\n }\n};\n\n/**\n * Central tendency: What number is most common in the set.\n * If all numbers have the same frequency, there is no mode.\n */\nexport const getMode = (data: number[]) : number[]|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n // Count frequency of each number in the data array.\n const frequencyMap: Map = new Map();\n for (const num of data) {\n frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);\n }\n\n let maxFrequency = 0;\n let modes: number[] = [];\n\n // Find the maximum frequency\n for (const [num, frequency] of frequencyMap) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency;\n modes = [num];\n }\n else if (frequency === maxFrequency) {\n modes.push(num);\n }\n }\n\n // If all numbers have the same frequency, there is no mode\n if (modes.length === data.length) {\n return undefined;\n }\n\n // Return the mode(s)\n return modes.length === 1 ? [modes[0]] : modes;\n};\n\n/*\nTODO:\n- geometric mean\n- harmonic mean\n */\n\n// -------------------- DISPERSION ----------------------------\n\nexport const getVariance = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const mean = getArithmeticMean(data);\n if(mean === undefined) return undefined;\n\n const sum = data.reduce((acc, val) => acc + ((val - mean) ** 2), 0);\n\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};"], - "mappings": ";;;;;;;qbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,aAAAE,GAAA,0BAAAC,GAAA,kBAAAC,GAAA,mBAAAC,GAAA,6BAAAC,GAAA,iBAAAC,EAAA,0BAAAC,GAAA,qBAAAC,GAAA,oBAAAC,GAAA,aAAAC,GAAA,aAAAC,GAAA,aAAAC,GAAA,aAAAC,GAAA,UAAAC,GAAA,UAAAC,GAAA,iBAAAC,GAAA,UAAAC,GAAA,UAAAC,GAAA,yBAAAC,GAAA,6BAAAC,GAAA,yBAAAC,GAAA,6BAAAC,GAAA,oBAAAC,GAAA,8BAAAC,GAAA,sBAAAC,GAAA,iBAAAC,EAAA,sBAAAC,GAAA,2BAAAC,GAAA,mBAAAC,GAAA,4BAAAC,GAAA,+BAAAC,GAAA,cAAAC,GAAA,YAAAC,GAAA,cAAAC,EAAA,qBAAAC,GAAA,+BAAAC,GAAA,sBAAAC,GAAA,6BAAAC,GAAA,mCAAAC,GAAA,oCAAAC,GAAA,kCAAAC,GAAA,sBAAAC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K,GAAY,CAACN,EAAgBC,EAAgB,MAAgC,CACtF,GAAG,CAACD,GAAQA,EAAK,QAAU,EAAG,OAE9B,IAAMO,EAAO,CAAC,GAAGP,CAAI,EAAE,KAAK,CAACQ,EAAMC,IAASD,EAAOC,CAAI,EACjDC,EAAM,KAAK,MAAMH,EAAK,OAAS,CAAC,EAEtC,OAAGA,EAAK,OAAS,IAAM,EACZF,GAAkBE,EAAKG,GAAOH,EAAKG,EAAM,IAAM,EAAGT,CAAa,EAG/DI,EAAiBE,EAAKG,GAAMT,CAAa,CAExD,EAMaU,GAAWX,GAAwC,CAC5D,GAAG,CAACA,GAAQA,EAAK,QAAU,EAAG,OAG9B,IAAMY,EAAoC,IAAI,IAC9C,QAAWC,KAAOb,EACdY,EAAa,IAAIC,GAAMD,EAAa,IAAIC,CAAG,GAAK,GAAK,CAAC,EAG1D,IAAIC,EAAe,EACfC,EAAkB,CAAC,EAGvB,OAAW,CAACF,EAAKG,CAAS,IAAKJ,EACvBI,EAAYF,GACZA,EAAeE,EACfD,EAAQ,CAACF,CAAG,GAEPG,IAAcF,GACnBC,EAAM,KAAKF,CAAG,EAKtB,GAAIE,EAAM,SAAWf,EAAK,OAK1B,OAAOe,EAAM,SAAW,EAAI,CAACA,EAAM,EAAE,EAAIA,CAC7C,EAUaE,GAAc,CAACjB,EAAgBC,EAAgB,MAAgC,CACxF,GAAG,CAACD,GAAQA,EAAK,QAAU,EAAG,OAE9B,IAAMkB,EAAOnB,GAAkBC,CAAI,EACnC,GAAGkB,IAAS,OAAW,OAEvB,IAAMhB,EAAMF,EAAK,OAAO,CAACG,EAAKC,IAAQD,EAAQgB,EAAAf,EAAMc,EAAS,GAAI,CAAC,EAElE,OAAOb,EAAiBH,EAAMF,EAAK,OAAQC,CAAa,CAC5D", - "names": ["index_esm_exports", "__export", "animate", "arithmeticSequenceSum", "circleCollide", "circleMovement", "circleMovementAfterMouse", "convertRange", "convexPolygonsCollide", "degreesToRadians", "doRangesOverlap", "dxArcCos", "dxArcCot", "dxArcSin", "dxArcTan", "dxCos", "dxCot", "dxPolynomial", "dxSin", "dxTan", "dxV2CubicBezierCurve", "dxV2QuadraticBezierCurve", "dxV3CubicBezierCurve", "dxV3QuadraticBezierCurve", "ellipseMovement", "ellipseMovementAfterMouse", "getAnglesDistance", "getAnglesSub", "getArithmeticMean", "getCircleCircumference", "getColorsDelta", "getEllipseCircumference", "getLinearEquationBy2Points", "getMedian", "getMode", "getRandom", "getRandomBoolean", "getRandomGrayscaleHSLColor", "getRandomHSLColor", "getRandomHSLColorWithHue", "getRandomHSLColorWithLightness", "getRandomHSLColorWithSaturation", "getRandomHSLColorWithinRanges", "getRandomHexColor", "getRandomInt", "getRandomItemFromArray", "getRandomRGBColor", "getShiftedHue", "getShiftedLightness", "getShiftedSaturation", "getSquareInCircleSide", "getV2Angle", "getV2AngleBetween", "getV2AngleInEllipse", "getV3AngleBetween", "getVNAngleBetween", "getVariance", "guid", "hexToRgb", "hslToHex", "hslToRgb", "identity2", "identity3", "identity4", "identityN", "isAngleBetween", "isAngleInCircleArc", "isClockwise", "isNumber", "isSingularMatrix", "labToRgb", "linearEquation", "linearEquationSystem2", "linearEquationSystem3", "linearEquationSystemN", "lissajousCurve", "m2Adjugate", "m2AppendRow", "m2DeepCopy", "m2Determinant", "m2DivideScalar", "m2Inverse", "m2MulScalar", "m2PrependRow", "m2ReflectionOrigin", "m2ReflectionOriginH", "m2ReflectionX", "m2ReflectionXH", "m2ReflectionY", "m2ReflectionYH", "m2ReflectionYmX", "m2Reset", "m2RotateAroundPointH", "m2Rotation", "m2RotationAroundPointH", "m2RotationH", "m2Scale", "m2ScaleAtPointH", "m2ScaleAtPointHMatrix", "m2ScaleH", "m2ScaleX", "m2ScaleXH", "m2ScaleY", "m2ScaleYH", "m2ShearingX", "m2ShearingY", "m2Sub", "m2Sum", "m2ToCSS", "m2Translation", "m2TranslationH", "m2Transpose", "m2hToCSS", "m2hToCSS3d", "m2x2", "m3Adjugate", "m3AppendRow", "m3DeepCopy", "m3Determinant", "m3DivideScalar", "m3Inverse", "m3MulScalar", "m3PrependRow", "m3ReflectionOrigin", "m3ReflectionOriginH", "m3ReflectionXY", "m3ReflectionXYH", "m3ReflectionXZ", "m3ReflectionXZH", "m3ReflectionYZ", "m3ReflectionYZH", "m3Reset", "m3RotationX", "m3RotationXH", "m3RotationY", "m3RotationYH", "m3RotationZ", "m3RotationZH", "m3Scale", "m3ScaleH", "m3ScaleX", "m3ScaleXH", "m3ScaleY", "m3ScaleYH", "m3ScaleZ", "m3ScaleZH", "m3Sub", "m3Sum", "m3Translation", "m3TranslationH", "m3Transpose", "m3hToCSS3d", "m3x3", "m4x4", "mAdjugate", "mAppendCol", "mAppendRow", "mDeepCopy", "mDelFirstColumn", "mDelFirstRow", "mDelLastColumn", "mDelLastRow", "mDeterminant", "mDivideScalar", "mEqual", "mGetColumn", "mGetFirstColumn", "mGetLastColumn", "mInverse", "mMinor", "mMul", "mMulScalar", "mMulVector", "mNxM", "mPrependCol", "mPrependRow", "mReset", "mSub", "mSum", "mTranspose", "mod", "naturalNumbersSequenceSum", "newId", "percentToAngle", "polarToCartesian", "radiansToDegrees", "rectCollide", "rgbToHex", "rgbToHsl", "rgbToLab", "setDecimalPlaces", "setV2Angle", "sineWaveMovement", "stringToNumber", "v2", "v2CubicBezierBBox", "v2CubicBezierCurve", "v2CubicBezierCurveExtrema", "v2CubicBezierCurveNormal", "v2CubicBezierCurveTangent", "v2Distance", "v2DivideScalar", "v2DotProduct", "v2FromPolarCoords", "v2GetNormal", "v2Length", "v2MulScalar", "v2Normalize", "v2QuadraticBezierBBox", "v2QuadraticBezierCurve", "v2QuadraticBezierCurveExtrema", "v2QuadraticBezierCurveNormal", "v2QuadraticBezierCurveTangent", "v2Rotate", "v2RotateH", "v2Scale", "v2SetLength", "v2Sub", "v2Sum", "v3", "v3CrossProduct", "v3CubicBezierCurve", "v3CubicBezierCurveTangent", "v3Distance", "v3DivideScalar", "v3DotProduct", "v3Length", "v3MulScalar", "v3Normalize", "v3QuadraticBezierCurve", "v3QuadraticBezierCurveTangent", "v3RotateX", "v3RotateY", "v3RotateZ", "v3Scale", "v3Sub", "v3Sum", "v4", "vDistance", "vDivideScalar", "vDotProduct", "vEqual", "vLength", "vMulScalar", "vN", "vNormalize", "vSub", "vSum", "__toCommonJS", "setDecimalPlaces", "num", "decimalPlaces", "coefficient", "__pow", "mod", "n", "m", "convertRange", "x", "a", "b", "c", "d", "doRangesOverlap", "isNumber", "value", "polarToCartesian", "center", "radii", "angleInRad", "decimalPlaces", "cx", "cy", "rx", "ry", "setDecimalPlaces", "getV2Angle", "v2", "decimalPlaces", "angle", "setDecimalPlaces", "getV2AngleInEllipse", "radii", "setV2Angle", "newAngleRad", "length", "v2Length", "radiansToDegrees", "radians", "res", "degreesToRadians", "degrees", "getVNAngleBetween", "vector1", "vector2", "unitVector1", "vNormalize", "unitVector2", "dotProduct", "vDotProduct", "getV2AngleBetween", "diff", "vSub", "getV3AngleBetween", "isAngleBetween", "angleDegrees", "startAngleDegrees", "endAngleDegrees", "distance", "getAnglesSub", "distance1", "distance2", "totalDistance", "isClockwise", "angle1Deg", "angle2Deg", "startAngleDeg", "angleDegrees1", "angleDegrees2", "angleDistance", "mod", "getAnglesDistance", "percentToAngle", "percent", "endAngleDeg", "circleStartAngle", "vSum", "vector1", "vector2", "decimalPlaces", "vector", "i", "setDecimalPlaces", "v2Sum", "v3Sum", "vSub", "v2Sub", "v3Sub", "vMulScalar", "v", "scalar", "v2MulScalar", "v2", "v3MulScalar", "v3", "vDivideScalar", "v2DivideScalar", "v3DivideScalar", "vLength", "sum", "v2Length", "v3Length", "v2SetLength", "newLength", "angle", "getV2Angle", "vDistance", "diff", "v2Distance", "v3Distance", "vNormalize", "length", "unitVector", "v2Normalize", "v3Normalize", "vDotProduct", "v2DotProduct", "v3DotProduct", "v3CrossProduct", "defaultValue", "v4", "vN", "N", "v2FromPolarCoords", "distance", "angleRad", "setV2Angle", "vEqual", "v2GetNormal", "sub", "mSum", "matrix1", "matrix2", "decimalPlaces", "matrix", "i", "vSum", "m2Sum", "m3Sum", "mSub", "vSub", "m2Sub", "m3Sub", "mMulScalar", "m", "scalar", "v", "vMulScalar", "m2MulScalar", "m2", "m3MulScalar", "m3", "mDivideScalar", "vDivideScalar", "m2DivideScalar", "m3DivideScalar", "mTranspose", "vectorsCount", "vectorLength", "j", "m2Transpose", "m3Transpose", "mReset", "defaultValue", "res", "size", "vector", "m2Reset", "m3Reset", "m2x2", "m3x3", "m4x4", "mNxM", "N", "M", "vN", "identity2", "identity3", "identity4", "identityN", "mDeepCopy", "m2DeepCopy", "m3DeepCopy", "mAppendCol", "col", "copy", "mPrependCol", "mAppendRow", "row", "m2AppendRow", "m3AppendRow", "mPrependRow", "m2PrependRow", "m3PrependRow", "mDelLastRow", "mDelFirstRow", "mDelLastColumn", "mDelFirstColumn", "mGetFirstColumn", "mGetLastColumn", "mGetColumn", "colIndex", "mMul", "transposed", "vector1", "vector2", "product", "vDotProduct", "mMulVector", "mEqual", "vEqual", "mMinorHelper", "mMinor", "mDeterminant", "m2Determinant", "d", "minor", "param", "m3Determinant", "m2Adjugate", "m3Adjugate", "mAdjugate", "cofactors", "sign", "isSingularMatrix", "m2Inverse", "adj", "m3Inverse", "mInverse", "m2ToCSS", "m", "a", "b", "c", "d", "m2hToCSS", "tx", "ty", "m2hToCSS3d", "m3hToCSS3d", "m2Translation", "position", "decimalPlaces", "setDecimalPlaces", "m3Translation", "m2TranslationH", "m3TranslationH", "m2Rotation", "angleRad", "isClockwise", "cos", "sin", "m2RotationH", "m2RotationAroundPointH", "transformOrigin", "translation", "rotation", "translationBack", "v3MulScalar", "temp1", "mMul", "m2RotateAroundPointH", "mat3h", "mMulVector", "v2Rotate", "vector", "unitVector", "v2Normalize", "v2RotateH", "v3Normalize", "m3RotationX", "m3RotationXH", "v3RotateX", "m3RotationY", "m3RotationYH", "v3RotateY", "m3RotationZ", "m3RotationZH", "v3RotateZ", "m2ScaleAtPointHMatrix", "scaleVector", "scale", "m2ScaleH", "m2ScaleAtPointH", "point", "m2Scale", "v2Scale", "m3Scale", "m3ScaleH", "v3Scale", "m2ScaleX", "m2ScaleXH", "m3ScaleX", "m3ScaleXH", "m3ScaleY", "m3ScaleYH", "m3ScaleZ", "m3ScaleZH", "m2ScaleY", "m2ScaleYH", "m2ReflectionOrigin", "m2ReflectionOriginH", "m3ReflectionOrigin", "m3ReflectionOriginH", "m2ReflectionYmX", "m2ReflectionX", "m2ReflectionXH", "m2ReflectionY", "m2ReflectionYH", "m3ReflectionYZ", "m3ReflectionYZH", "m3ReflectionXZ", "m3ReflectionXZH", "m3ReflectionXY", "m3ReflectionXYH", "m2ShearingY", "factor", "m2ShearingX", "getRandom", "min", "max", "decimalPlaces", "setDecimalPlaces", "getRandomInt", "getRandomBoolean", "getRandomItemFromArray", "array", "randomIndex", "stringToNumber", "value", "defaultNumber", "_a", "res", "dxPolynomial", "x", "polynomial", "decimalPlaces", "res", "part", "coeff", "power", "setDecimalPlaces", "dxV2QuadraticBezierCurve", "startControlPoint", "centerControlPoint", "endControlPoint", "temp1", "temp2", "temp3", "dxV3QuadraticBezierCurve", "dxV2CubicBezierCurve", "center1ControlPoint", "center2ControlPoint", "temp4", "dxV3CubicBezierCurve", "dxSin", "dxCos", "dxTan", "__pow", "dxCot", "dxArcSin", "dxArcCos", "dxArcTan", "dxArcCot", "linearEquation", "equation", "decimalPlaces", "a", "b", "diff", "setDecimalPlaces", "linearEquationSystem2", "equation1", "equation2", "equationParams", "inversed", "m2Inverse", "equationResults", "mMulVector", "linearEquationSystem3", "equation3", "m3Inverse", "linearEquationSystemN", "equations", "mDelLastColumn", "mInverse", "mGetLastColumn", "getLinearEquationBy2Points", "point1", "point2", "deltaX", "deltaY", "v2Sub", "x", "y", "m", "formula", "quadraticEquation", "equation", "decimalPlaces", "a", "b", "c", "d", "res", "linearEquation", "isNumber", "diff", "discriminant", "setDecimalPlaces", "t1", "t2", "v2QuadraticBezierCurve", "startControlPoint", "centerControlPoint", "endControlPoint", "decimalPlaces", "temp1", "temp2", "temp3", "setDecimalPlaces", "v3QuadraticBezierCurve", "v2CubicBezierCurve", "center1ControlPoint", "center2ControlPoint", "temp4", "v3CubicBezierCurve", "v2QuadraticBezierCurveTangent", "dxVector", "dxV2QuadraticBezierCurve", "v2Normalize", "v3QuadraticBezierCurveTangent", "dxV3QuadraticBezierCurve", "v3Normalize", "v2CubicBezierCurveTangent", "dxV2CubicBezierCurve", "v3CubicBezierCurveTangent", "dxV3CubicBezierCurve", "v2QuadraticBezierCurveNormal", "tangent", "v2CubicBezierCurveNormal", "v2QuadraticBezierCurveExtrema", "a1", "b1", "res1", "linearEquation", "a2", "b2", "res2", "res", "isNumber", "v2CubicBezierCurveExtrema", "c1", "equation1", "c2", "equation2", "quadraticEquation", "num", "v2QuadraticBezierBBox", "extrema", "minX", "minY", "maxX", "maxY", "percent", "point", "x", "y", "v2CubicBezierBBox", "circleMovement", "center", "angle", "radius", "circleMovementAfterMouse", "mouse", "vector", "v2Sub", "getV2Angle", "convertRange", "ellipseMovement", "radius1", "radius2", "ellipseMovementAfterMouse", "radii", "sineWaveMovement", "x", "amplitude", "frequency", "phase", "y", "lissajousCurve", "width", "height", "t", "k", "n", "m", "p", "getRandomRGBColor", "hslColor", "getRandomHSLColor", "hslToRgb", "getRandomHexColor", "hslToHex", "h", "getRandom", "s", "l", "getRandomHSLColorWithHue", "getRandomHSLColorWithSaturation", "getRandomHSLColorWithLightness", "getRandomGrayscaleHSLColor", "getRandomHSLColorWithinRanges", "hueStart", "hueEnd", "saturationStart", "saturationEnd", "lightStart", "lightEnd", "convertHueToDegrees", "getHue", "r", "g", "b", "min", "max", "diff", "getLuminance", "getSaturation", "rgbToHsl", "rgb", "decimalPlaces", "setDecimalPlaces", "hslToRgbHelper", "helper1", "helper2", "colorHelper", "hsl", "gray", "rHelper", "gHelper", "bHelper", "hue2rgb", "q", "t", "p", "toHex", "hex", "rgbToHex", "hexToRgb", "shorthandRegex", "_hex", "_m", "result", "rgbToLab", "x", "y", "z", "labToRgb", "lab", "getShiftedHue", "color", "shift", "hue", "mod", "getShiftedLightness", "lightness", "getShiftedSaturation", "saturation", "getColorsDelta", "rgbA", "rgbB", "labA", "labB", "deltaL", "deltaA", "deltaB", "c1", "c2", "deltaC", "deltaH", "sc", "sh", "deltaLKlsl", "deltaCkcsc", "deltaHkhsh", "i", "guid", "c", "newId", "rectCollide", "rect1", "rect2", "circleCollide", "circle1", "circle2", "dx", "dy", "getEdges", "poly", "edges", "i", "nextIndex", "mod", "edge", "convexPolygonsCollide", "poly1", "poly2", "normal", "v2GetNormal", "p1Proj", "projectPolygon", "p2Proj", "polygon", "min", "max", "vertex", "projection", "v2DotProduct", "animate", "props", "_duration", "startTime", "animationId", "elapsed", "previousTimeStamp", "animating", "observer", "stop", "restart", "start", "pause", "resume", "step", "timeStamp", "getResult", "observerHandler", "_entries", "_observer", "getElapsedTime", "isAnimating", "getStartTime", "getPercent", "getResizeObserver", "getCircleCircumference", "radius", "decimalPlaces", "setDecimalPlaces", "getEllipseCircumference", "radius1", "radius2", "__pow", "isAngleInCircleArc", "startAngleDeg", "endAngleDeg", "currentDegrees", "getSquareInCircleSide", "naturalNumbersSequenceSum", "n", "arithmeticSequenceSum", "a", "d", "getArithmeticMean", "data", "decimalPlaces", "sum", "acc", "val", "setDecimalPlaces", "getMedian", "copy", "num1", "num2", "mid", "getMode", "frequencyMap", "num", "maxFrequency", "modes", "frequency", "getVariance", "mean", "__pow"] + "sources": ["../src/index-esm.ts", "../src/main/format.ts", "../src/main/other.ts", "../src/main/angle.ts", "../src/main/linear-algebra/vector.ts", "../src/main/linear-algebra/matrix.ts", "../src/main/linear-algebra/matrix-transformations.ts", "../src/main/random.ts", "../src/main/convert.ts", "../src/main/derivative.ts", "../src/main/equations/linear-equations.ts", "../src/main/equations/quadratic-equations.ts", "../src/main/bezier-curves/bezier-curve.ts", "../src/main/path-movement.ts", "../src/main/color.ts", "../src/main/id.ts", "../src/main/collision-detection.ts", "../src/main/animation.ts", "../src/main/circle-ellipse.ts", "../src/main/sequence.ts", "../src/main/statistics.ts", "../src/main/ml.ts"], + "sourcesContent": ["export * from './main/linear-algebra/vector';\nexport * from './main/linear-algebra/matrix';\nexport * from './main/linear-algebra/matrix-transformations';\nexport * from './main/format';\nexport * from './main/angle';\nexport * from './main/random';\nexport * from './main/other';\nexport * from './main/convert';\nexport * from './main/bezier-curves/bezier-curve';\nexport * from './main/equations/linear-equations';\nexport * from './main/path-movement';\nexport * from './main/color';\nexport * from './main/physics';\nexport * from './main/id';\nexport * from './main/derivative';\nexport * from './main/collision-detection';\nexport * from './main/animation';\nexport * from './main/circle-ellipse';\nexport * from './main/sequence';\nexport * from './main/statistics';\nexport * from './main/ml';", "export const setDecimalPlaces = (num: number, decimalPlaces: number | undefined = Infinity) => {\n if(decimalPlaces === Infinity) return num;\n\n if(decimalPlaces < 0){\n decimalPlaces = 0;\n }\n\n const coefficient = 10 ** decimalPlaces;\n return Math.round(num * coefficient) / coefficient;\n};", "import { Vector2 } from '../types';\nimport { setDecimalPlaces } from './format';\n\nexport const mod = (n: number, m: number) => {\n return ((n % m) + m) % m;\n};\n\n/**\n * Convert range [a, b] to [c, d].\n * f(x) = (d - c) * (x - a) / (b - a) + c\n */\nexport const convertRange = (x: number, a: number, b: number, c: number, d: number) => {\n return (d - c) * (x - a) / (b - a) + c;\n};\n\n/**\n * Check if 2 ranges [a,b] and [c,d] overlap.\n */\nexport const doRangesOverlap = (a: number, b: number, c: number, d: number) => {\n return Math.max(a, c) <= Math.min(b, d) ;\n};\n\n// eslint-disable-next-line\nexport const isNumber = (value: any) => {\n return !isNaN(parseFloat(value)) && isFinite(value);\n};\n\n/**\n * Convert polar coordinates to cartesian coordinates.\n */\nexport const polarToCartesian = (center: Vector2, radii: Vector2, angleInRad: number, decimalPlaces = Infinity) : Vector2 => {\n const [cx, cy] = center;\n const [rx, ry] = radii;\n\n return [\n setDecimalPlaces(cx + (rx * Math.cos(angleInRad)), decimalPlaces),\n setDecimalPlaces(cy + (ry * Math.sin(angleInRad)), decimalPlaces),\n ];\n};", "import { Vector, Vector2, Vector3 } from '../types';\nimport { setDecimalPlaces } from './format';\nimport { v2Length, vNormalize, vDotProduct, vSub } from './linear-algebra/vector';\nimport { mod } from './other';\n\nexport const getV2Angle = (v2: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1], v2[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleInEllipse = (v2: Vector2, radii: Vector2, decimalPlaces = Infinity) => {\n const angle = Math.atan2(v2[1]/radii[1], v2[0]/radii[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const setV2Angle = (v2: Vector2, newAngleRad: number, decimalPlaces = Infinity): Vector2 => {\n const length = v2Length(v2);\n return [\n setDecimalPlaces(Math.cos(newAngleRad) * length, decimalPlaces),\n setDecimalPlaces(Math.sin(newAngleRad) * length, decimalPlaces),\n ];\n};\n\nexport const radiansToDegrees = (radians: number, decimalPlaces = Infinity) => {\n const res = radians * (180 / Math.PI);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\nexport const degreesToRadians = (degrees: number, decimalPlaces = Infinity) => {\n const res = degrees * (Math.PI / 180);\n return setDecimalPlaces(res, decimalPlaces);\n};\n\n/**\n * Returns the range [0, Math.PI]\n * A = Math.acos( dot(v1, v2)/(v1.length()*v2.length()) );\n */\nexport const getVNAngleBetween = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n const unitVector1 = vNormalize(vector1);\n const unitVector2 = vNormalize(vector2);\n const dotProduct = vDotProduct(unitVector1, unitVector2);\n const angle = Math.acos(dotProduct);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV2AngleBetween = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) : number => {\n // return getVNAngleBetween(vector1, vector2, decimalPlaces);\n const diff = vSub(vector1, vector2);\n const angle = Math.atan2(diff[1], diff[0]);\n return setDecimalPlaces(angle, decimalPlaces);\n};\n\nexport const getV3AngleBetween = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return getVNAngleBetween(vector1, vector2, decimalPlaces);\n};\n\nexport const isAngleBetween = (angleDegrees: number, startAngleDegrees: number, endAngleDegrees: number) : boolean => {\n const distance = getAnglesSub(startAngleDegrees, endAngleDegrees);\n const distance1 = getAnglesSub(startAngleDegrees, angleDegrees);\n const distance2 = getAnglesSub(endAngleDegrees, angleDegrees);\n const totalDistance = distance1 + distance2;\n\n // Use a small threshold for floating point errors\n return Math.abs(totalDistance - distance) <= 0.001;\n}\n\nexport const isClockwise = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n return angle2Deg >= angle1Deg;\n};\n\n/**\n * Shortest distance (angular) between two angles.\n */\nexport const getAnglesSub = (angleDegrees1: number, angleDegrees2: number, decimalPlaces = Infinity) : number => {\n const angleDistance = Math.abs(mod(angleDegrees1, 360) - mod(angleDegrees2, 360));\n return setDecimalPlaces(angleDistance <= 180 ? angleDistance : 360 - angleDistance, decimalPlaces);\n};\n\nexport const getAnglesDistance = (angle1Deg: number, angle2Deg: number, startAngleDeg = 0, decimalPlaces = Infinity) => {\n angle1Deg = angle1Deg % 360;\n angle2Deg = angle2Deg % 360;\n\n if(angle1Deg < startAngleDeg) {\n angle1Deg += 360;\n }\n\n if(angle2Deg < startAngleDeg) {\n angle2Deg += 360;\n }\n\n if(isClockwise(angle1Deg, angle2Deg, startAngleDeg)) {\n return setDecimalPlaces((angle2Deg - angle1Deg + 360) % 360, decimalPlaces);\n }\n else{\n return setDecimalPlaces((angle1Deg - angle2Deg + 360) % 360, decimalPlaces);\n }\n};\n\nexport const percentToAngle = (percent: number, startAngleDeg: number, endAngleDeg: number, circleStartAngle = 0) => {\n if(percent < 0) {\n percent = 0;\n }\n\n if(percent > 100) {\n percent = 100;\n }\n\n const distance = getAnglesDistance(startAngleDeg, endAngleDeg, circleStartAngle);\n\n const clockwise = isClockwise(startAngleDeg, endAngleDeg, circleStartAngle);\n if(clockwise) {\n return mod(circleStartAngle + (percent * distance / 100), 360);\n }\n else {\n return mod(circleStartAngle - (percent * distance / 100), 360);\n }\n};", "import { Vector, Vector2, Vector3, Vector4 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { getV2Angle, setV2Angle } from '../angle';\n\n// ------------ SUM ------------------------\n\nexport const vSum = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSum(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sum = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSum(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ SUB ------------------------\n\nexport const vSub = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : Vector => {\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vSub(vector1, vector2, decimalPlaces) as Vector2;\n};\n\nexport const v3Sub = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vSub(vector1, vector2, decimalPlaces) as Vector3;\n};\n\n// ------------ MUL SCALAR ------------------------\n\nexport const vMulScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n const vector: Vector = [];\n\n for(let i=0; i {\n return vMulScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3MulScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vMulScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ DIVIDE ------------------------\n\nexport const vDivideScalar = (v: Vector, scalar: number, decimalPlaces = Infinity): Vector => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const vector: Vector = [];\n\n for(let i=0; i {\n return vDivideScalar(v2, scalar, decimalPlaces) as Vector2;\n};\n\nexport const v3DivideScalar = (v3: Vector3, scalar: number, decimalPlaces = Infinity): Vector3 => {\n return vDivideScalar(v3, scalar, decimalPlaces) as Vector3;\n};\n\n// ------------ LENGTH ------------------------\n\nexport const vLength = (vector: Vector, decimalPlaces = Infinity) => {\n let sum = 0;\n\n for(let i=0; i {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v3Length = (vector: Vector3, decimalPlaces = Infinity) => {\n return vLength(vector, decimalPlaces);\n};\n\nexport const v2SetLength = (v2: Vector2, newLength: number, decimalPlaces = Infinity): Vector2 => {\n const angle = getV2Angle(v2);\n return [\n setDecimalPlaces(Math.cos(angle) * newLength, decimalPlaces),\n setDecimalPlaces(Math.sin(angle) * newLength, decimalPlaces),\n ];\n};\n\n// ----------- DISTANCE ------------------------\n\nexport const vDistance = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v2Distance = (vector1: Vector2, vector2: Vector2, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\nexport const v3Distance = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) => {\n const diff = vSub(vector1, vector2);\n return vLength(diff, decimalPlaces);\n};\n\n// ------------ NORMALIZE ------------------------\n\n/**\n * Normalization creates a unit vector, which is a vector of length 1.\n */\nexport const vNormalize = (v: Vector, decimalPlaces = Infinity) : Vector => {\n const length = vLength(v);\n const unitVector: Vector = [];\n\n for(let i=0; i {\n return vNormalize(v2, decimalPlaces) as Vector2;\n};\n\nexport const v3Normalize = (v3: Vector3, decimalPlaces = Infinity) : Vector3 => {\n return vNormalize(v3, decimalPlaces) as Vector3;\n};\n\n// ------------ DOT PRODUCT ------------------------\n\nexport const vDotProduct = (vector1: Vector, vector2: Vector, decimalPlaces = Infinity) : number => {\n let sum = 0;\n\n for(let i=0; i {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\nexport const v3DotProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity) : number => {\n return vDotProduct(vector1, vector2, decimalPlaces);\n};\n\n// ------------ CROSS PRODUCT ------------------------\n\n/**\n * Cross product is possible on 3D vectors only.\n * The cross product a \u00D7 b is defined as a vector c that is perpendicular (orthogonal) to both a and b.\n */\nexport const v3CrossProduct = (vector1: Vector3, vector2: Vector3, decimalPlaces = Infinity): Vector3 => {\n return [\n setDecimalPlaces(vector1[1] * vector2[2] - vector1[2] * vector2[1], decimalPlaces),\n setDecimalPlaces(vector1[2] * vector2[0] - vector1[0] * vector2[2], decimalPlaces),\n setDecimalPlaces(vector1[0] * vector2[1] - vector1[1] * vector2[0], decimalPlaces),\n ];\n};\n\n// --------------- INIT VECTOR HELPER -----------------\n\nexport const v2 = (defaultValue = 0): Vector2 => {\n return [defaultValue, defaultValue];\n};\n\nexport const v3 = (defaultValue = 0): Vector3 => {\n return [defaultValue, defaultValue, defaultValue];\n};\n\nexport const v4 = (defaultValue = 0): Vector4 => {\n return [defaultValue, defaultValue, defaultValue, defaultValue];\n};\n\nexport const vN = (N: number, defaultValue = 0): Vector => {\n\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n const vector: Vector = [];\n for(let i=0; i {\n let vector: Vector2 = [0, 0];\n vector = v2SetLength(vector, distance);\n return setV2Angle(vector, angleRad);\n};\n\n// --------------- EQUALITY -------------------------\n\nexport const vEqual = (vector1: Vector, vector2: Vector): boolean => {\n if(vector1.length !== vector2.length) return false;\n\n for(let i=0; i {\n const sub = v2Sub(vector2, vector1);\n return [\n -setDecimalPlaces(sub[1], decimalPlaces),\n setDecimalPlaces(sub[0], decimalPlaces)\n ];\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector, Vector2, Vector3 } from '../../types';\nimport { vMulScalar, vSum, vSub, vDotProduct, vN, vEqual, vDivideScalar } from './vector';\n\n// --------------- SUM ----------------------\n\nexport const mSum = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sum = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSum(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- SUB ----------------------\n\nexport const mSub = (matrix1: Matrix, matrix2: Matrix, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix2;\n};\n\nexport const m3Sub = (matrix1: Matrix3, matrix2: Matrix3, decimalPlaces = Infinity): Matrix3 => {\n return mSub(matrix1, matrix2, decimalPlaces) as Matrix3;\n};\n\n// --------------- MUL SCALAR ----------------------\n\nexport const mMulScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vMulScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2MulScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mMulScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3MulScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mMulScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n// --------------- DIVIDE SCALAR ----------------------\n\nexport const mDivideScalar = (m: Matrix, scalar: number, decimalPlaces = Infinity): Matrix => {\n if(scalar === 0){\n throw new Error('Division by zero error.');\n }\n\n const matrix: Matrix = [];\n\n for(const v of m){\n matrix.push(vDivideScalar(v, scalar, decimalPlaces));\n }\n\n return matrix;\n};\n\nexport const m2DivideScalar = (m2: Matrix2, scalar: number, decimalPlaces = Infinity): Matrix2 => {\n return mDivideScalar(m2, scalar, decimalPlaces) as Matrix2;\n};\n\nexport const m3DivideScalar = (m3: Matrix3, scalar: number, decimalPlaces = Infinity): Matrix3 => {\n return mDivideScalar(m3, scalar, decimalPlaces) as Matrix3;\n};\n\n\n// --------------- TRANSPOSE ----------------------\n\nexport const mTranspose = (m: Matrix): Matrix => {\n\n const vectorsCount = m.length;\n if(vectorsCount <= 0) return m;\n\n const vectorLength = m[0].length;\n if(vectorLength <= 0) return m;\n\n const matrix: Matrix = [];\n for(let i=0; i {\n return mTranspose(m2);\n};\n\nexport const m3Transpose = (m3: Matrix3): Matrix => {\n return mTranspose(m3);\n};\n\n// ----------------- RESET ----------------------\n\nexport const mReset = (m: Matrix, defaultValue = 0): Matrix => {\n\n if(m.length <= 0) return [];\n\n const res: Matrix = [];\n\n for(let i=0; i {\n return mReset(m2, defaultValue) as Matrix2;\n};\n\nexport const m3Reset = (m3: Matrix3, defaultValue = 0): Matrix3 => {\n return mReset(m3, defaultValue) as Matrix3;\n};\n\n// --------------- MATRIX INIT HELPERS -----------------\n\nexport const m2x2 = (defaultValue = 0): Matrix2 => {\n return [\n [defaultValue, defaultValue],\n [defaultValue, defaultValue],\n ];\n};\n\nexport const m3x3 = (defaultValue = 0): Matrix3 => {\n return [\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const m4x4 = (defaultValue = 0): Matrix4 => {\n return [\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n [defaultValue, defaultValue, defaultValue, defaultValue],\n ];\n};\n\nexport const mNxM = (N: number, M: number, defaultValue = 0): Matrix => {\n if(N <= 0 || M <= 0){\n throw new Error('M and N must be positive numbers.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return [\n [1, 0],\n [0, 1],\n ];\n};\n\nexport const identity3 = (): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\nexport const identity4 = (): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Identity Matrix (I).\n * M x I = I x M = M for any matrix M.\n * Identity Matrix is a special case of scale matrix.\n */\nexport const identityN = (N: number): Matrix => {\n if(N < 0){\n throw new Error('N must be a non-negative number.');\n }\n\n if(N === 0) return [];\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const matrix: Matrix = [];\n\n for(let i=0; i {\n return mDeepCopy(m2) as Matrix2;\n};\n\nexport const m3DeepCopy = (m3: Matrix3): Matrix3 => {\n return mDeepCopy(m3) as Matrix3;\n};\n\n// -------------- APPEND / PREPEND ROW OR COLUMN ---------------\n\nexport const mAppendCol = (m: Matrix, col: Vector): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n const copy = mDeepCopy(m);\n copy.push(row);\n return copy;\n};\n\nexport const m2AppendRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.push(row);\n return copy;\n};\n\nexport const m3AppendRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.push(row);\n return copy;\n};\n\nexport const mPrependRow = (m: Matrix, row: Vector) : Matrix => {\n const copy = mDeepCopy(m);\n copy.unshift(row);\n return copy;\n};\n\nexport const m2PrependRow = (m2: Matrix2, row: Vector2) : Matrix2 => {\n const copy = m2DeepCopy(m2);\n copy.unshift(row);\n return copy;\n};\n\nexport const m3PrependRow = (m3: Matrix3, row: Vector3) : Matrix3 => {\n const copy = m3DeepCopy(m3);\n copy.unshift(row);\n return copy;\n};\n\n// ------------ DELETE ROW OR COLUMN ----------------------------\n\nexport const mDelLastRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.pop();\n return copy;\n};\n\nexport const mDelFirstRow = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n copy.shift();\n return copy;\n};\n\nexport const mDelLastColumn = (m: Matrix): Matrix => {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const copy = mDeepCopy(m);\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const size = m[0].length;\n\n const vector: Vector = [];\n for(let i=0; i {\n if(m.length <= 0) return [];\n\n const vector: Vector = [];\n for(let i=0; i {\n\n const matrix: Matrix = [];\n for(let i=0; i {\n\n if(matrix.length < 0) return [];\n\n if(matrix[0].length !== vector.length){\n throw new Error('The number of columns in the matrix must be equal to the length of the vector.');\n }\n\n const res: Vector = [];\n\n for(let i=0; i {\n if(matrix1.length !== matrix2.length) return false;\n\n for(let i=0; i returns matrix N (m-1 x m-1)\n * The matrix must be square.\n */\nconst mMinorHelper = (m: Matrix, row: number, col: number) => {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const matrix: Matrix = [];\n\n for(let i=0; i {\n const size = m.length;\n\n if(size <= 0){\n throw new Error('The matrix should not be empty.');\n }\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // prepare the matrix without provided row and column\n const matrix = mMinorHelper(m, row, col);\n\n // calculate the matrix determinant\n return mDeterminant(matrix);\n};\n\n/**\n * Calculate determinant for NxN matrix.\n * Matrix should be square.\n */\nexport const mDeterminant = (matrix: Matrix): number => {\n const size = matrix.length;\n if(size === 0) return 1;\n\n if(size !== matrix[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return matrix[0][0];\n if(size === 2) return m2Determinant(matrix as Matrix2);\n\n let d = 0;\n\n for(let i=0; i {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return m2[0][0] * m2[1][1] - m2[1][0] * m2[0][1];\n};\n\n/**\n * Calculate determinant for 3x3 matrix.\n * Matrix should be square.\n */\nexport const m3Determinant = (m3: Matrix3): number => {\n if(m3.length !== m3[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return mDeterminant(m3);\n};\n\n// ------------------ INVERSE -----------------------\n\nexport const m2Adjugate = (m2: Matrix2): Matrix2|null => {\n if(m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n return [\n [m2[1][1], -m2[0][1]],\n [-m2[1][0], m2[0][0]],\n ];\n};\n\nexport const m3Adjugate = (m3: Matrix3) : Matrix3|null => {\n return mAdjugate(m3) as (Matrix3|null);\n};\n\n/**\n * Adjugate is a transpose of a cofactor matrix\n */\nexport const mAdjugate = (m: Matrix): Matrix|null => {\n\n const size = m.length;\n if(size <= 0) return null;\n\n if(size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n if(size === 1) return m;\n\n if(size === 2) return m2Adjugate(m as Matrix2);\n\n // build a cofactor matrix ----------------\n const cofactors: Matrix = [];\n\n for(let i=0; i {\n if(m.length > 0 && m.length !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = mDeterminant(m);\n return d === 0;\n};\n\n/**\n * Square matrix A (nxn) is invertible is there is another square matrix B (nxn) so AxB = BxA = I\n * For A (2x2) matrix, the inverse is:\n * (1 / (determinant(A))) * adj(A)\n */\nexport const m2Inverse = (m2: Matrix2, decimalPlaces = Infinity): (Matrix2 | null) => {\n if(m2.length > 0 && m2.length !== m2[0].length){\n throw new Error('The matrix must be square.');\n }\n\n const d = m2Determinant(m2);\n if(d === 0) return null;\n\n const adj = m2Adjugate(m2);\n if(adj === null) return null;\n\n return m2DivideScalar(adj, d, decimalPlaces);\n};\n\nexport const m3Inverse = (m3: Matrix3, decimalPlaces = Infinity): (Matrix3 | null) => {\n return mInverse(m3, decimalPlaces) as (Matrix3|null);\n};\n\nexport const mInverse = (m: Matrix, decimalPlaces = Infinity): (Matrix | null) => {\n const size = m.length;\n\n if(size > 0 && size !== m[0].length){\n throw new Error('The matrix must be square.');\n }\n\n // find a determinant ----------------------\n const d = mDeterminant(m);\n\n // find an Adjugate - a transpose of a cofactor matrix\n const adj = mAdjugate(m);\n if(adj === null) return null;\n\n return mDivideScalar(adj, d, decimalPlaces);\n};", "import { Matrix2, Matrix3, Matrix4, Matrix, Vector2, Vector3, Vector4 } from '../../types';\nimport { v2Normalize, v3MulScalar, v3Normalize } from './vector';\nimport { mMulVector, mMul } from './matrix';\nimport { setDecimalPlaces } from '../format';\n\n/*\nAny 2D affine transformation can be decomposed\ninto a rotation, followed by a scaling, followed by a\nshearing, and followed by a translation.\n---------------------------------------------------------\nAffine matrix = translation x shearing x scaling x rotation\n */\n\n// ----------------- CSS -------------------------------------\n\n/**\n * Matrix 2D in non-homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2ToCSS = (m: Matrix2) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, 0, 0)`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n */\nexport const m2hToCSS = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ tx }, ${ ty })`;\n};\n\n/**\n * Matrix 2D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m2hToCSS3d = (m: Matrix3) : string => {\n const a = m[0][0];\n const b = m[1][0];\n const c = m[0][1];\n const d = m[1][1];\n const tx = m[0][2];\n const ty = m[1][2];\n\n return `matrix3d(${ a }, ${ b }, 0, 0, ${ c }, ${ d }, 0, 0, 0, 0, 1, 0, ${ tx }, ${ ty }, 0, 1)`;\n};\n\n/**\n * Matrix 3D in homogeneous coordinates to CSS matrix3d() function\n * https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n */\nexport const m3hToCSS3d = (m: Matrix4) : string => {\n\n return `matrix3d(\n ${ m[0][0] }, ${ m[0][1] }, ${ m[0][2] }, ${ m[0][3] },\n ${ m[1][0] }, ${ m[1][1] }, ${ m[1][2] }, ${ m[1][3] },\n ${ m[2][0] }, ${ m[2][1] }, ${ m[2][2] }, ${ m[2][3] },\n ${ m[3][0] }, ${ m[3][1] }, ${ m[3][2] }, ${ m[3][3] }\n )`;\n};\n\n// ---------------- TRANSLATION MATRICES ----------------------\n\nexport const m2Translation = (position: Vector2, decimalPlaces = Infinity): Matrix2 => {\n\n return [\n [1, 0],\n [0, 1],\n [setDecimalPlaces(position[0], decimalPlaces), setDecimalPlaces(position[1], decimalPlaces)],\n ];\n};\n\nexport const m3Translation = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n [\n setDecimalPlaces(position[0], decimalPlaces),\n setDecimalPlaces(position[1], decimalPlaces),\n setDecimalPlaces(position[2], decimalPlaces)\n ],\n ];\n};\n\n/**\n * 2D Translation matrix in homogeneous coordinates.\n */\nexport const m2TranslationH = (position: Vector3, decimalPlaces = Infinity): Matrix3 => {\n\n return [\n [1, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1],\n ];\n};\n\n/**\n * 3D Translation matrix in homogeneous coordinates.\n */\nexport const m3TranslationH = (position: Vector4, decimalPlaces = Infinity): Matrix4 => {\n\n return [\n [1, 0, 0, setDecimalPlaces(position[0], decimalPlaces)],\n [0, 1, 0, setDecimalPlaces(position[1], decimalPlaces)],\n [0, 0, 1, setDecimalPlaces(position[2], decimalPlaces)],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- ROTATION MATRICES -------------------------\n\n/**\n * Rotation of an angle about the origin.\n */\nexport const m2Rotation = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix2 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin],\n [sin, cos],\n ] :\n [\n [cos, sin],\n [-sin, cos],\n ];\n};\n\n/**\n * Rotation of an angle about the origin in homogeneous coordinates (clockwise).\n */\nexport const m2RotationH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ]:\n [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation of an angle \"angleRad\" around the given point (transformOrigin) in homogeneous coordinates (clockwise).\n * result_vector = TranslationMatrix(x, y) * RotationMatrix() * TranslationMatrix(-x, -y) * position_vector\n */\nexport const m2RotationAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const rotation = m2RotationH(angleRad, isClockwise, decimalPlaces);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, rotation);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2RotateAroundPointH = (\n angleRad: number,\n transformOrigin: Vector3,\n position: Vector3,\n isClockwise = true,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2RotationAroundPointH(angleRad, transformOrigin, isClockwise, decimalPlaces);\n return mMulVector(mat3h, position) as Vector3;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2Rotate = (angleRad: number, vector: Vector2, isClockwise = true, decimalPlaces = Infinity): Vector2 => {\n const unitVector = v2Normalize(vector);\n return mMulVector(m2Rotation(angleRad, isClockwise, decimalPlaces), unitVector) as Vector2;\n};\n\n/**\n * Rotate vector around the origin by angle \"angleRad\" (clockwise).\n */\nexport const v2RotateH = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m2RotationH(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the X axis (clockwise).\n */\nexport const m3RotationX = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0],\n [0, cos, -sin],\n [0, sin, cos],\n ] :\n [\n [1, 0, 0],\n [0, cos, sin],\n [0, -sin, cos],\n ];\n};\n\n/**\n * Rotation around the X axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationXH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [1, 0, 0, 0],\n [0, cos, -sin, 0],\n [0, sin, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [1, 0, 0, 0],\n [0, cos, sin, 0],\n [0, -sin, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateX = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationX(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Y axis (clockwise).\n */\nexport const m3RotationY = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin],\n [0, 1, 0],\n [-sin, 0, cos],\n ] :\n [\n [cos, 0, -sin],\n [0, 1, 0],\n [sin, 0, cos],\n ];\n};\n\n/**\n * Rotation around the Y axis (clockwise) - in homogeneous coordinates\n */\nexport const m3RotationYH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, 0, sin, 0],\n [0, 1, 0, 0],\n [-sin, 0, cos, 0],\n [0, 0, 0, 1],\n ] :\n [\n [cos, 0, -sin, 0],\n [0, 1, 0, 0],\n [sin, 0, cos, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateY = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationY(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n/**\n * Rotation around the Z axis (clockwise).\n */\nexport const m3RotationZ = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix3 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0],\n [sin, cos, 0],\n [0, 0, 1],\n ] : [\n [cos, sin, 0],\n [-sin, cos, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Rotation around the Z axis (clockwise)- in homogeneous coordinates\n */\nexport const m3RotationZH = (angleRad: number, isClockwise = true, decimalPlaces = Infinity): Matrix4 => {\n\n const cos = setDecimalPlaces(Math.cos(angleRad), decimalPlaces);\n const sin = setDecimalPlaces(Math.sin(angleRad), decimalPlaces);\n\n return isClockwise ? [\n [cos, -sin, 0, 0],\n [sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ] : [\n [cos, sin, 0, 0],\n [-sin, cos, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\nexport const v3RotateZ = (angleRad: number, vector: Vector3, isClockwise = true, decimalPlaces = Infinity): Vector3 => {\n const unitVector = v3Normalize(vector);\n return mMulVector(m3RotationZ(angleRad, isClockwise, decimalPlaces), unitVector) as Vector3;\n};\n\n// ---------------- SCALE MATRICES -------------\n\n/**\n * Get matrix for arbitrary scaling pivot point.\n * result_vector = TranslationMatrix(x, y) * ScaleMatrix() * TranslationMatrix(-x, -y) * scale_vector\n */\nexport const m2ScaleAtPointHMatrix = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n decimalPlaces = Infinity): Matrix3 => {\n\n const translation = m2TranslationH(transformOrigin, decimalPlaces);\n const scale = m2ScaleH(scaleVector);\n const translationBack = m2TranslationH(v3MulScalar(transformOrigin, -1), decimalPlaces);\n const temp1 = mMul(translation, scale);\n return mMul(temp1, translationBack) as Matrix3;\n};\n\nexport const m2ScaleAtPointH = (\n scaleVector: Vector3,\n transformOrigin: Vector3,\n point: Vector3,\n decimalPlaces = Infinity): Vector3 => {\n\n const mat3h = m2ScaleAtPointHMatrix(scaleVector, transformOrigin, decimalPlaces);\n return mMulVector(mat3h, point) as Vector3;\n};\n\nexport const m2Scale = (scaleVector: Vector2): Matrix2 => {\n return [\n [scaleVector[0], 0],\n [0, scaleVector[1]],\n ];\n};\n\nexport const v2Scale = (scaleVector: Vector2, vector: Vector2): Vector2 => {\n return mMulVector(m2Scale(scaleVector), vector) as Vector2;\n};\n\n/**\n * homogeneous coordinates\n */\nexport const m2ScaleH = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, 1],\n ];\n};\n\nexport const m3Scale = (scaleVector: Vector3): Matrix3 => {\n return [\n [scaleVector[0], 0, 0],\n [0, scaleVector[1], 0],\n [0, 0, scaleVector[2]],\n ];\n};\n\nexport const m3ScaleH = (scaleVector: Vector4): Matrix4 => {\n return [\n [scaleVector[0], 0, 0, 0],\n [0, scaleVector[1], 0, 0],\n [0, 0, scaleVector[2], 0],\n [0, 0, 0, 1]\n ];\n};\n\nexport const v3Scale = (scaleVector: Vector3, vector: Vector3): Vector3 => {\n return mMulVector(m3Scale(scaleVector), vector) as Vector3;\n};\n\n/**\n * Stretch, parallel to the x-axis.\n */\nexport const m2ScaleX = (scale: number): Matrix2 => {\n return [\n [scale, 0],\n [0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the x-axis - homogeneous coordinates\n */\nexport const m2ScaleXH = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleX = (scale: number): Matrix3 => {\n return [\n [scale, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in x-direction\n */\nexport const m3ScaleXH = (scale: number): Matrix4 => {\n return [\n [scale, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleY = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Stretch in y-direction\n */\nexport const m3ScaleYH = (scale: number): Matrix => {\n return [\n [1, 0, 0, 0],\n [0, scale, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZ = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, scale],\n ];\n};\n\n/**\n * Stretch in z-direction\n */\nexport const m3ScaleZH = (scale: number): Matrix4 => {\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, scale, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis.\n */\nexport const m2ScaleY = (scale: number): Matrix2 => {\n return [\n [1, 0],\n [0, scale],\n ];\n};\n\n/**\n * Stretch, parallel to the y-axis - homogeneous coordinates\n */\nexport const m2ScaleYH = (scale: number): Matrix3 => {\n return [\n [1, 0, 0],\n [0, scale, 0],\n [0, 0, 1],\n ];\n};\n\n// ---------------- REFLECTION MATRICES -------------------------\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOrigin = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection about the origin.\n */\nexport const m2ReflectionOriginH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection about the origin in non-homogeneous coordinates\n */\nexport const m3ReflectionOrigin = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, -1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection about the origin in homogeneous coordinates\n */\nexport const m3ReflectionOriginH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection about y=-x\n */\nexport const m2ReflectionYmX = (): Matrix2 => {\n\n return [\n [0, -1],\n [-1, 0],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionX = (): Matrix2 => {\n\n return [\n [1, 0],\n [0, -1],\n ];\n};\n\n/**\n * Reflection in the x-axis.\n */\nexport const m2ReflectionXH = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection in the y-axis.\n */\nexport const m2ReflectionY = (): Matrix2 => {\n\n return [\n [-1, 0],\n [0, 1],\n ];\n};\n\nexport const m2ReflectionYH = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionYZ = (): Matrix3 => {\n\n return [\n [-1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to YZ plane in homogeneous coordinates\n */\nexport const m3ReflectionYZH = (): Matrix4 => {\n\n return [\n [-1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXZ = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, -1, 0],\n [0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XZ plane in homogeneous coordinates\n */\nexport const m3ReflectionXZH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, -1, 0, 0],\n [0, 0, 1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in non-homogeneous coordinates\n */\nexport const m3ReflectionXY = (): Matrix3 => {\n\n return [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, -1],\n ];\n};\n\n/**\n * Reflection relative to XY plane in homogeneous coordinates\n */\nexport const m3ReflectionXYH = (): Matrix4 => {\n\n return [\n [1, 0, 0, 0],\n [0, 1, 0, 0],\n [0, 0, -1, 0],\n [0, 0, 0, 1],\n ];\n};\n\n// ---------------- SHEARING MATRICES -------------------------\n\n\n/**\n * Shearing in y-axis, with x-axis fixed with (0,1) moving to (factor, 1)\n */\nexport const m2ShearingY = (factor: number): Matrix2 => {\n\n return [\n [1, factor],\n [0, 1],\n ];\n};\n\n/**\n * Shearing in x-axis, with y-axis fixed with (1,0) moving to (1, factor)\n */\nexport const m2ShearingX = (factor: number): Matrix2 => {\n\n return [\n [1, 0],\n [factor, 1],\n ];\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a random number in the [min,max] range.\n */\nexport const getRandom = (min: number, max: number, decimalPlaces = Infinity): number => {\n return setDecimalPlaces(Math.random() * (max - min) + min, decimalPlaces);\n};\n\n/**\n * Returns a random integer number in the [min,max] range.\n */\nexport const getRandomInt = (min: number, max: number): number => {\n return Math.floor(Math.random() * (max - min + 1) + min);\n};\n\nexport const getRandomBoolean = () => Math.random() < 0.5;\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getRandomItemFromArray = (array: any[]) => {\n const randomIndex = getRandomInt(0, array.length - 1);\n return array[randomIndex];\n};", "export const stringToNumber = (value: string|undefined|null|number, defaultNumber: number) => {\n if(value === undefined || value === null) return defaultNumber;\n const res = Number(value) ?? defaultNumber;\n return isNaN(res) ? defaultNumber : res;\n};", "import { setDecimalPlaces } from './format';\nimport { Vector2, Vector3 } from '../types';\n\n/**\n * u(x) and v(x) are functions ---------->\n *\n * dx(u + v) = dx(u) + dx(v)\n * dx(u - v) = dx(u) - dx(v)\n * dx(u * v) = dx(u) * v + u * dx(v)\n * dx(u / v) = (dx(u) * v - u * dx(v)) / (v ^ 2), when v(x) != 0\n */\n\n// ------------------ Derivatives of Polynomial ---------------------------\n\n/**\n * y = 3x+2\n * dxPolynomial(10, [[3, 1], [2, 0]])\n */\nexport const dxPolynomial = (x: number, polynomial: number[][], decimalPlaces = Infinity) => {\n let res = 0;\n\n for(const part of polynomial){\n if(part.length !== 2) return NaN;\n\n const coeff = part[0];\n const power = part[1];\n res += coeff * power * Math.pow(x, power - 1);\n }\n\n return setDecimalPlaces(res, decimalPlaces);\n}\n\n// ---------------------- Bezier Curves ---------------------------\n\n/**\n * Derivative of Bezier Curve is another Bezier Curve.\n * t must min in range [0, 1]\n */\nexport const dxV2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n // The derivative: P1 * (2t-2) + (2*P3-4*P2) * t + 2 * P2\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -2 * (1 - t); // Math.pow(1 - t, 2)\n const temp2 = 2 - 4 * t; // (1 - t) * 2 * t\n const temp3 = 2 * t; //t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\nexport const dxV2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const dxV3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = -3 * Math.pow(1 - t, 2); //Math.pow(1 - t, 3);\n const temp2 = 3 * (t - 1) * (3 * t - 1); //Math.pow(1 - t, 2) * 3 * t;\n const temp3 = 6 * t - 9 * t * t; // (1 - t) * 3 * t * t;\n const temp4 = 3 * t * t; //t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n\n// ----------------- Derivatives of trigonometry functions ---------------------------\n\nexport const dxSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(Math.cos(x), decimalPlaces);\n};\n\nexport const dxCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-Math.sin(x), decimalPlaces);\n};\n\nexport const dxTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.cos(x) ** 2), decimalPlaces);\n};\n\n/**\n * x != Math.PI * n, where n is an integer\n */\nexport const dxCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sin(x) ** 2), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcSin = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\n/**\n * -1 < x < 1\n */\nexport const dxArcCos = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (Math.sqrt(1 - x ** 2)), decimalPlaces);\n};\n\nexport const dxArcTan = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(1 / (1 + x ** 2), decimalPlaces);\n};\n\nexport const dxArcCot = (x: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(-1 / (1 + x ** 2), decimalPlaces);\n};\n", "import { Matrix, Matrix2, Matrix3, Vector, Vector2, Vector3 } from '../../types';\nimport { m2Inverse, m3Inverse, mInverse, mMulVector, mDelLastColumn, mGetLastColumn } from '../linear-algebra/matrix';\nimport { setDecimalPlaces } from '../format';\nimport { v2Sub } from '../linear-algebra/vector';\n\n/**\n * Linear equation\n * ax + b = c\n * x = (c - b) / a; a != 0\n */\nexport const linearEquation = (equation: Vector3, decimalPlaces = Infinity) : number => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n\n const diff = c - b;\n\n if(a === 0 && diff === 0) return Infinity; // any number is a solution\n if(a === 0) return NaN; // no solution\n\n return setDecimalPlaces(diff / a, decimalPlaces);\n};\n\n/**\n * System of 2 linear equations.\n * [x, y] = inverse(Matrix of equation parameters) x (vector of equation results)\n * ---------------\n * 3x + 2y = 7\n * -6x + 6y = 6\n */\nexport const linearEquationSystem2 = (equation1: Vector3, equation2: Vector3, decimalPlaces = Infinity) : Vector2 | null => {\n const equationParams: Matrix2 = [\n [equation1[0], equation1[1]],\n [equation2[0], equation2[1]],\n ];\n\n const inversed = m2Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector2 = [\n equation1[2],\n equation2[2]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector2;\n};\n\n/**\n * System of 3 linear equations.\n * ---------------------------------------\n * 3x + 2y + 5z = 7\n * -6x + 6y + 6z = 6\n * 2x + 7y - z = 4\n */\nexport const linearEquationSystem3 = (\n equation1: Vector,\n equation2: Vector,\n equation3: Vector,\n decimalPlaces = Infinity) : Vector3 | null => {\n const equationParams: Matrix3 = [\n [equation1[0], equation1[1], equation1[2]],\n [equation2[0], equation2[1], equation2[2]],\n [equation3[0], equation3[1], equation3[2]],\n ];\n\n const inversed = m3Inverse(equationParams);\n if(inversed === null) return null; // no results\n\n const equationResults: Vector3 = [\n equation1[3],\n equation2[3],\n equation3[3]\n ];\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector3;\n};\n\n/**\n * System of N linear equations.\n */\nexport const linearEquationSystemN = (equations: Matrix, decimalPlaces = Infinity) : Vector | null => {\n if(equations.length <= 0) return null;\n\n const equationParams = mDelLastColumn(equations);\n\n const inversed = mInverse(equationParams);\n if(inversed === null) return null; // no results\n\n // the last column of the equations matrix\n const equationResults = mGetLastColumn(equations);\n\n return mMulVector(inversed, equationResults, decimalPlaces) as Vector;\n};\n\n/**\n * Calculate the equation of a line given two points in a 2D space.\n * y = ax + b\n * y - y1 = m(x - x1)\n * m = (y2 - y1) / (x2 - x1)\n */\nexport const getLinearEquationBy2Points = (point1: Vector2, point2: Vector2) : {\n slope: number|undefined,\n yIntercept: number|undefined,\n xIntercept: number|undefined,\n formula: string,\n} => {\n const [deltaX, deltaY] = v2Sub(point2, point1);\n const [x, y] = point1;\n\n if(deltaX === 0) {\n return {\n slope: undefined,\n xIntercept: x,\n yIntercept: undefined,\n formula: `x = ${ x }`,\n };\n }\n\n const m = deltaY / deltaX;\n const b = y - m * x;\n let formula = '';\n\n if(m === 0) {\n formula = `y = ${ b }`;\n }\n else{\n formula = `y = ${ m === 1 ? '' : m }x`;\n\n if(b !== 0) {\n formula += ` ${ b < 0 ? '-' : '+' } ${ Math.abs(b) }`;\n }\n }\n\n return {\n slope: m,\n xIntercept: undefined,\n yIntercept: b,\n formula,\n };\n};", "import { Vector } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport { linearEquation } from './linear-equations';\nimport { isNumber } from '../other';\n\n/**\n * Quadratic Equation.\n * ax^2 + bx + c = d\n */\nexport const quadraticEquation = (equation: Vector, decimalPlaces = Infinity) : Vector => {\n const a = equation[0];\n const b = equation[1];\n const c = equation[2];\n const d = equation[3];\n\n if(a === 0){\n // it's a linear equation -------------------------------------------\n const res = linearEquation([b, c, d], decimalPlaces);\n if(isNumber(res)) return [res];\n return [];\n }\n\n const diff = c - d;\n\n const discriminant = b * b - (4 * a * diff);\n\n if(discriminant < 0){\n return []; // no results\n }\n\n if(discriminant === 0){\n return [ setDecimalPlaces(-b / (2 * a), decimalPlaces) ]; // 1 result\n }\n\n // if(determinant > 0) ---> 2 results\n const t1 = 2 * a;\n const t2 = Math.sqrt(discriminant);\n\n return [\n setDecimalPlaces((-b + t2) / t1, decimalPlaces),\n setDecimalPlaces((-b - t2) / t1, decimalPlaces),\n ];\n};", "import { IBBox, Vector, Vector2, Vector3 } from '../../types';\nimport { setDecimalPlaces } from '../format';\nimport {\n dxV2CubicBezierCurve,\n dxV2QuadraticBezierCurve,\n dxV3CubicBezierCurve,\n dxV3QuadraticBezierCurve\n} from '../derivative';\nimport { v2Normalize, v3Normalize } from '../linear-algebra/vector';\nimport { linearEquation } from '../equations/linear-equations';\nimport { quadraticEquation } from '../equations/quadratic-equations';\nimport { isNumber } from '../other';\n\n/**\n * B\u00E9zier Curves\n * quadratic: y = P1 * (1-t)\u00B2 + P2 * 2 * (1-t)t + P3 * t\u00B2\n * t in range [0, 1]\n */\n\n// -------------------- GET POINT ON CURVE --------------------------\n\n/**\n * Get a point on a quadratic B\u00E9zier curve as a function of time.\n */\nexport const v2QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3QuadraticBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 2);\n const temp2 = (1 - t) * 2 * t;\n const temp3 = t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * centerControlPoint[0] + temp3 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * centerControlPoint[1] + temp3 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * centerControlPoint[2] + temp3 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n/**\n * Get a point on a cubic B\u00E9zier curve as a function of time.\n */\nexport const v2CubicBezierCurve = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n ];\n};\n\nexport const v3CubicBezierCurve = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n\n const temp1 = Math.pow(1 - t, 3);\n const temp2 = Math.pow(1 - t, 2) * 3 * t;\n const temp3 = (1 - t) * 3 * t * t;\n const temp4 = t * t * t;\n\n return [\n setDecimalPlaces(temp1 * startControlPoint[0] + temp2 * center1ControlPoint[0] + temp3 * center2ControlPoint[0] + temp4 * endControlPoint[0], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[1] + temp2 * center1ControlPoint[1] + temp3 * center2ControlPoint[1] + temp4 * endControlPoint[1], decimalPlaces),\n setDecimalPlaces(temp1 * startControlPoint[2] + temp2 * center1ControlPoint[2] + temp3 * center2ControlPoint[2] + temp4 * endControlPoint[2], decimalPlaces),\n ];\n};\n\n// -------------------- TANGENT --------------------------\n\n/**\n * Tangent indicates the direction of travel at specific points along the B\u00E9zier curve,\n * and is literally just the first derivative of our curve.\n */\nexport const v2QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3QuadraticBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n centerControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3QuadraticBezierCurve(t, startControlPoint, centerControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\nexport const v2CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n const dxVector = dxV2CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v2Normalize(dxVector, decimalPlaces);\n};\n\nexport const v3CubicBezierCurveTangent = (\n t: number,\n startControlPoint: Vector3,\n center1ControlPoint: Vector3,\n center2ControlPoint: Vector3,\n endControlPoint: Vector3,\n decimalPlaces = Infinity\n) : Vector3 => {\n const dxVector = dxV3CubicBezierCurve(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n return v3Normalize(dxVector, decimalPlaces);\n};\n\n// -------------------- NORMAL --------------------------\n\n/**\n * Normal is a vector that runs at a right angle to the direction of the curve, and is typically of length 1.\n * To find it, we take the normalised tangent vector, and then rotate it by a 90 degrees.\n */\nexport const v2QuadraticBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2QuadraticBezierCurveTangent(t, startControlPoint, centerControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\nexport const v2CubicBezierCurveNormal = (\n t: number,\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2 => {\n\n const tangent = v2CubicBezierCurveTangent(t, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint, decimalPlaces);\n return [-tangent[1], tangent[0]];\n};\n\n// -------------------- EXTREMA --------------------------\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2QuadraticBezierCurveExtrema = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector => {\n\n /*\n (-2 * (1 - t)) * startControlPoint[0] + (2 - 4 * t) * centerControlPoint[0] + (2 * t) * endControlPoint[0]\n 2 * t * startControlPoint[0] - 4 * t * centerControlPoint[0] + 2 * t * endControlPoint[0] - 2 * startControlPoint[0] + 2 * centerControlPoint[0]\n t * (2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0]) + (- 2 * startControlPoint[0] + 2 * centerControlPoint[0])\n */\n\n const a1 = 2 * startControlPoint[0] - 4 * centerControlPoint[0] + 2 * endControlPoint[0];\n const b1 = -2 * startControlPoint[0] + 2 * centerControlPoint[0];\n const equation1: Vector3 = [a1, b1, 0];\n const res1 = linearEquation(equation1, decimalPlaces);\n\n const a2 = 2 * startControlPoint[1] - 4 * centerControlPoint[1] + 2 * endControlPoint[1];\n const b2 = -2 * startControlPoint[1] + 2 * centerControlPoint[1];\n const equation2: Vector3 = [a2, b2, 0];\n const res2 = linearEquation(equation2, decimalPlaces);\n\n const res: Vector = [];\n\n if(isNumber(res1)){\n res.push(res1);\n }\n\n if(isNumber(res2)){\n res.push(res2);\n }\n\n return res;\n};\n\n/**\n * Find maxima and minima by solving the equation B'(t) = 0\n * Returns result in [0, 1] range.\n */\nexport const v2CubicBezierCurveExtrema = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : Vector2|null => {\n\n const a1 = -3 * startControlPoint[0] + 9 * center1ControlPoint[0] - 9 * center2ControlPoint[0] + 3 * endControlPoint[0];\n const b1 = 6 * startControlPoint[0] - 12 * center1ControlPoint[0] + 6 * center2ControlPoint[0];\n const c1 = -3 * startControlPoint[0] + 3 * center1ControlPoint[0];\n const equation1: Vector = [a1, b1, c1, 0];\n\n const a2 = -3 * startControlPoint[1] + 9 * center1ControlPoint[1] - 9 * center2ControlPoint[1] + 3 * endControlPoint[1];\n const b2 = 6 * startControlPoint[1] - 12 * center1ControlPoint[1] + 6 * center2ControlPoint[1];\n const c2 = -3 * startControlPoint[1] + 3 * center1ControlPoint[1];\n const equation2: Vector = [a2, b2, c2, 0];\n\n // Any value between 0 and 1 is a root that matters for B\u00E9zier curves, anything below or above that is irrelevant (because B\u00E9zier curves are only defined over the interval [0,1]).\n const res1 = quadraticEquation(equation1, decimalPlaces).filter(num => num >= 0 && num <= 1);\n const res2 = quadraticEquation(equation2, decimalPlaces).filter(num => num >= 0 && num <= 1);\n\n const res = [...res1, ...res2];\n if(res.length === 2){\n return [...res1, ...res2] as Vector2;\n }\n\n return null;\n};\n\n// -------------------- BOUNDING BOX --------------------------\n\nexport const v2QuadraticBezierBBox = (\n startControlPoint: Vector2,\n centerControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2QuadraticBezierCurveExtrema(startControlPoint, centerControlPoint, endControlPoint);\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2QuadraticBezierCurve(percent, startControlPoint, centerControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\nexport const v2CubicBezierBBox = (\n startControlPoint: Vector2,\n center1ControlPoint: Vector2,\n center2ControlPoint: Vector2,\n endControlPoint: Vector2,\n decimalPlaces = Infinity\n) : IBBox => {\n\n const extrema = v2CubicBezierCurveExtrema(startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint) || [];\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for(const percent of extrema){\n const point = v2CubicBezierCurve(percent, startControlPoint, center1ControlPoint, center2ControlPoint, endControlPoint);\n\n const x = point[0];\n const y = point[1];\n\n minX = Math.min(minX, x ?? Infinity);\n maxX = Math.max(maxX, x ?? -Infinity);\n\n minY = Math.min(minY, y ?? Infinity);\n maxY = Math.max(maxY, y ?? -Infinity);\n }\n\n minX = setDecimalPlaces(Math.min(minX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n maxX = setDecimalPlaces(Math.max(maxX, startControlPoint[0], endControlPoint[0]), decimalPlaces);\n minY = setDecimalPlaces(Math.min(minY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n maxY = setDecimalPlaces(Math.max(maxY, startControlPoint[1], endControlPoint[1]), decimalPlaces);\n\n return {\n x: minX,\n y: minY,\n w: Math.abs(maxX - minX),\n h: Math.abs(maxY - minY),\n x2: maxX,\n y2: maxY,\n }\n};\n\n\n", "import { Vector2 } from '../types';\nimport { v2Sub } from './linear-algebra/vector';\nimport { getV2Angle } from './angle';\nimport { convertRange } from './other';\n\n/**\n * Circle Equation\n * x^2 + y^2 = radius^2\n * ----------------------\n * Circle Parametric Equation\n * x(t) = radius * cos(t)\n * y(t) = radius * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const circleMovement = (center: Vector2, angle: number, radius: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius,\n center[1] + Math.sin(angle) * radius\n ];\n};\n\n/**\n * Circle Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const circleMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radius: number\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return circleMovement(center, angle, radius);\n};\n\n/**\n * Ellipse Equation\n * (x - centerX)^2 / (radius1^2) + (y - centerY)^2 / (radius2^2) = 1\n * -----------------------------------------------------------------\n * Ellipse Parametric Equation\n * x(t) = radius1 * cos(t)\n * y(t) = radius2 * sin(t)\n * t is the parameter = angle\n *\n * Angle should be in the range [0, Math.PI]\n */\nexport const ellipseMovement = (center: Vector2, angle: number, radius1: number, radius2: number): Vector2 => {\n angle = angle % Math.PI * 2;\n\n return [\n center[0] + Math.cos(angle) * radius1,\n center[1] + Math.sin(angle) * radius2\n ];\n};\n\n/**\n * Ellipse Movement After Mouse.\n * Mouse Positions:\n * - pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling),\n * - screenX and screenY: Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.\n * - clientX/Y coordinates are relative to the top left corner of the visible part of the page, \"seen\" through browser window.\n * - offsetX and offsetY are relative to the parent container,\n */\nexport const ellipseMovementAfterMouse = (\n mouse: Vector2,\n center: Vector2,\n radii: Vector2\n): Vector2 => {\n\n const vector = v2Sub(mouse, center);\n\n let angle = getV2Angle(vector);\n\n // convert the angle from the range [0, Math.PI*2] to the range [0, Math.PI]\n angle = convertRange(angle, 0, Math.PI*2, 0, Math.PI);\n\n return ellipseMovement(center, angle, radii[0], radii[1]);\n};\n\n/**\n * Sine Wave Equation (Sinusoid)\n * -----------------------------\n * const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n * amplitude = the peak deviation of the function from zero\n * frequency = number of cycles\n * phase = specifies (in radians) where in its cycle the oscillation is at t = 0.\n * think of it as \"shifting\" the starting point of the function to the right (positive p) or left (negative)\n */\nexport const sineWaveMovement = (x: number, amplitude: number, frequency: number, phase: number) : Vector2 => {\n /*\n example values:\n const amplitude = 50;\n const frequency = 0.005;\n const phase = 0;\n x: [0, 1000]\n */\n const y = amplitude * Math.sin(2 * Math.PI * frequency * x + phase);\n\n return [x, y];\n};\n\n/**\n * Lissajous curve (Lissajous figure or Bowditch curve)\n * Parametric equation #1\n * f(t) = A * sin(k * t + m)\n * f(t) = B * sin(n * t)\n * 0 <= m <= PI/2\n * k, n >= 1\n * -----------------------\n * Parametric equation #2\n * f(t) = A * cos(k * t - m)\n * f(t) = B * cos(n * t - p)\n * -----------------------------\n * Shapes:\n * k = 1, n = 1, m = 0, p = 0 ---> line\n * A = B, k = 1, n = 1, m = PI/2, p = PI/2 ----> circle\n * A != B, k = 1, n = 1, m = PI/2, p = PI/2 ----> ellipse\n * k = 2, n = 2, m = PI/2, p = PI/2 ----> section of a parabola\n */\nexport const lissajousCurve = (\n width: number,\n height: number,\n t: number,\n k: number,\n n: number,\n m: number,\n p: number\n) :Vector2 => {\n return [\n width * Math.cos(k * t - m),\n height * Math.cos(n * t - p),\n ];\n};\n", "import { getRandom } from './random';\nimport { HSLColor, LABColor, RGBColor } from '../types';\nimport { mod } from './other';\nimport { setDecimalPlaces } from './format';\n\n// ------------------------ RANDOM COLOR -------------------------------------\n\nexport const getRandomRGBColor = () : RGBColor => {\n const hslColor = getRandomHSLColor();\n return hslToRgb(hslColor);\n};\n\nexport const getRandomHexColor = () : string => {\n const hslColor = getRandomHSLColor();\n return hslToHex(hslColor);\n};\n\nexport const getRandomHSLColor = () : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given hue\n */\nexport const getRandomHSLColorWithHue = (h: number) : HSLColor => {\n const s = getRandom(0, 100);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given saturation\n */\nexport const getRandomHSLColorWithSaturation = (s: number) : HSLColor => {\n const h = getRandom(1, 360);\n const l = getRandom(0, 100);\n return [h, s, l];\n};\n\n/**\n * generate random color with the given lightness\n */\nexport const getRandomHSLColorWithLightness = (l: number) : HSLColor => {\n const h = getRandom(1, 360);\n const s = getRandom(0, 100);\n return [h, s, l];\n};\n\nexport const getRandomGrayscaleHSLColor = () : HSLColor => {\n const l = getRandom(0, 100);\n return [0, 0, l];\n};\n\nexport const getRandomHSLColorWithinRanges = (\n hueStart = 1, hueEnd = 360,\n saturationStart = 0, saturationEnd = 100,\n lightStart = 0, lightEnd = 100\n) : HSLColor => {\n const h = getRandom(hueStart, hueEnd);\n const s = getRandom(saturationStart, saturationEnd);\n const l = getRandom(lightStart, lightEnd);\n return [h, s, l];\n};\n\n// ----------------------- CONVERT COLORS --------------------------------------\n\n/**\n * helper: convert hue value to degrees.\n * @param {number} h\n * @return {number} [0, 360] degrees\n */\nconst convertHueToDegrees = (h : number) : number => {\n\n // the hue value needs to be multiplied by 60 to convert it to degrees\n h *= 60;\n\n // if hue becomes negative, you need to add 360 to, because a circle has 360 degrees\n if(h < 0){\n h += 360;\n }\n\n return h;\n // convert huw to %\n // return h * 100 / 360;\n};\n\n/**\n * get hue from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] % - we use here % instead of [0, 359] degrees\n */\nconst getHue = (r : number, g : number, b : number, min : number | undefined = undefined, max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (max === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no hue, as it's gray\n if(min === max) return 0;\n\n const diff = max - min;\n\n let h = 0;\n\n // if red is max\n if(max === r){\n h = (g - b) / diff + (g < b ? 6 : 0);\n }\n\n // if green is max\n if(max === g){\n h = 2 + (b - r) / diff;\n }\n\n // if blue is max\n if(max === b){\n h = 4 + (r - g) / diff;\n }\n\n return convertHueToDegrees(h);\n};\n\n/**\n * get luminance from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @return {number} [0, 100] %\n */\nconst getLuminance = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // calculate the luminance value\n // @ts-ignore\n const l = (min + max) / 2; // [0, 1]\n\n // return l value in %\n return l * 100;\n};\n\n/**\n * get saturation from RGB\n * @param {number} r [0, 255]\n * @param {number} g [0, 255]\n * @param {number} b [0, 255]\n * @param {number|undefined=} min - min number of [r, g, b]\n * @param {number|undefined=} max - max number of [r, g, b]\n * @param {number|undefined=} l - luminance in [0, 100] %\n * @return {number} [0, 100] %\n */\nconst getSaturation = (\n r : number,\n g : number,\n b : number,\n min : number | undefined = undefined,\n max : number | undefined = undefined,\n l : number | undefined = undefined) : number => {\n\n // find the minimum and maximum values of r, g, and b if they are not provided\n min = (min === undefined) ? Math.min(r, g, b) : min;\n max = (min === undefined) ? Math.max(r, g, b) : max;\n\n // if the min and max value are the same -> no saturation, as it's gray\n if(min === max) return 0;\n\n // calculate luminance if it's not provided\n l = (l === undefined) ? getLuminance(r, g, b) : l;\n\n // check the level of luminance\n const s = (l <= 50) ?\n // @ts-ignore\n ((max - min) / (max + min)) : // this formula is used when luminance <= 50%\n // @ts-ignore\n (max - min) / (2.0 - max - min); // this formula is used when luminance > 50%\n\n // return saturation in %\n return s * 100;\n};\n\nexport const rgbToHsl = (rgb: RGBColor, decimalPlaces = Infinity): HSLColor => {\n\n // convert rgb values to the range [0, 1]\n const r = rgb[0] / 255;\n const g = rgb[1] / 255;\n const b = rgb[2] / 255;\n\n // find the minimum and maximum values of r, g, and b\n const min = Math.min(r, g, b);\n const max = Math.max(r, g, b);\n\n // calculate the luminance value in %\n const l = getLuminance(r, g, b, min, max);\n\n // calculate the saturation in %\n const s = getSaturation(r, g, b, min, max, l);\n\n // calculate the hue in % (not in degrees!)\n const h = getHue(r, g, b, min, max);\n\n if(h > 360 || s > 100 || l > 100){\n return [0, 0, 100];\n }\n\n if(h < 0 || s < 0 || l < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(h, decimalPlaces),\n setDecimalPlaces(s, decimalPlaces),\n setDecimalPlaces(l, decimalPlaces),\n ];\n};\n\n/**\n * helper: HSL to RGB\n */\nconst hslToRgbHelper = (helper1 : number, helper2 : number, colorHelper : number) : number => {\n\n // all values need to be between 0 and 1\n // if you get a negative value you need to add 1 to it\n if(colorHelper < 0) colorHelper += 1;\n\n // if you get a value above 1 you need to subtract 1 from it.\n if(colorHelper > 1) colorHelper -= 1;\n\n if(colorHelper * 6 < 1) return helper2 + (helper1 - helper2) * 6 * colorHelper;\n\n if(colorHelper * 2 < 1) return helper1;\n\n if(colorHelper * 3 < 2){\n return helper2 + (helper1 - helper2) * (0.666 - colorHelper) * 6;\n }\n else{\n return helper2;\n }\n};\n\nexport const hslToRgb = (hsl: HSLColor, decimalPlaces = Infinity): RGBColor => {\n\n // convert all values to [0, 1] from %\n const h = hsl[0] / 100;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n // if there is no saturation -> it\u2019s grey\n if(s === 0){\n // convert the luminance from [0, 1] to [0, 255]\n const gray = l * 255;\n return [gray, gray, gray];\n }\n\n // check the level of luminance\n const helper1 = (l < 0.5) ?\n (l * (1.0 + s)) :\n (l + s - l * s);\n\n const helper2 = 2 * l - helper1;\n\n const rHelper = h + 0.333;\n const gHelper = h;\n const bHelper = h - 0.333;\n\n let r = hslToRgbHelper(helper1, helper2, rHelper);\n let g = hslToRgbHelper(helper1, helper2, gHelper);\n let b = hslToRgbHelper(helper1, helper2, bHelper);\n\n // convert rgb to [0, 255]\n r *= 255;\n g *= 255;\n b *= 255;\n\n if(r > 255 || g > 255 || b > 255){\n return [255, 255, 255];\n }\n\n if(r < 0 || g < 0 || b < 0){\n return [0, 0, 0];\n }\n\n return [\n setDecimalPlaces(r, decimalPlaces),\n setDecimalPlaces(g, decimalPlaces),\n setDecimalPlaces(b, decimalPlaces),\n ];\n};\n\n/**\n * HSL to hex\n * hslToHex(360, 100, 50) // [360, 100, 5] ==> \"#ff0000\" (red)\n */\nexport const hslToHex = (hsl: HSLColor) => {\n\n if(hsl[0] > 360 || hsl[1] > 100 || hsl[2] > 100){\n return '#ffffff';\n }\n\n if(hsl[0] < 0 || hsl[1] < 0 || hsl[2] < 0){\n return '#000000';\n }\n\n const h = hsl[0] / 360;\n const s = hsl[1] / 100;\n const l = hsl[2] / 100;\n\n let r, g, b;\n if (s === 0) {\n r = g = b = l; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n r = hue2rgb(p, q, h + 1 / 3);\n g = hue2rgb(p, q, h);\n b = hue2rgb(p, q, h - 1 / 3);\n }\n const toHex = (x: number) => {\n const hex = Math.round(x * 255).toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n};\n\n/**\n * RGB to HEX\n * rgbToHex([235, 64, 52]) // #eb4034\n */\nexport const rgbToHex = (rgb: RGBColor) => {\n const [r, g, b] = rgb;\n return '#' + (1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1);\n};\n\nexport const hexToRgb = (hex: string) : RGBColor | null => {\n\n const shorthandRegex = /^#?([a-f\\d])([a-f\\d])([a-f\\d])$/i;\n const _hex = hex.replace(shorthandRegex, (_m, r, g, b) => {\n return r + r + g + g + b + b;\n });\n\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(_hex);\n if(!result) return null;\n\n const r = parseInt(result[1], 16);\n const g = parseInt(result[2], 16);\n const b = parseInt(result[3], 16);\n\n return [r, g, b];\n};\n\nexport const rgbToLab = (rgb: RGBColor, decimalPlaces = Infinity) : LABColor => {\n\n let r = rgb[0] / 255;\n let g = rgb[1] / 255;\n let b = rgb[2] / 255;\n\n r = (r > 0.04045) ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;\n g = (g > 0.04045) ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;\n b = (b > 0.04045) ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;\n\n let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;\n let y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;\n let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;\n\n x = (x > 0.008856) ? Math.pow(x, 1/3) : (7.787 * x) + 16/116;\n y = (y > 0.008856) ? Math.pow(y, 1/3) : (7.787 * y) + 16/116;\n z = (z > 0.008856) ? Math.pow(z, 1/3) : (7.787 * z) + 16/116;\n\n return [\n setDecimalPlaces((116 * y) - 16, decimalPlaces),\n setDecimalPlaces(500 * (x - y), decimalPlaces),\n setDecimalPlaces(200 * (y - z), decimalPlaces),\n ];\n};\n\nexport const labToRgb = (lab: LABColor, decimalPlaces = Infinity) : RGBColor => {\n let y = (lab[0] + 16) / 116;\n let x = lab[1] / 500 + y;\n let z = y - lab[2] / 200;\n\n x = 0.95047 * ((x * x * x > 0.008856) ? x * x * x : (x - 16/116) / 7.787);\n y = 1.00000 * ((y * y * y > 0.008856) ? y * y * y : (y - 16/116) / 7.787);\n z = 1.08883 * ((z * z * z > 0.008856) ? z * z * z : (z - 16/116) / 7.787);\n\n let r = x * 3.2406 + y * -1.5372 + z * -0.4986;\n let g = x * -0.9689 + y * 1.8758 + z * 0.0415;\n let b = x * 0.0557 + y * -0.2040 + z * 1.0570;\n\n r = (r > 0.0031308) ? (1.055 * Math.pow(r, 1/2.4) - 0.055) : 12.92 * r;\n g = (g > 0.0031308) ? (1.055 * Math.pow(g, 1/2.4) - 0.055) : 12.92 * g;\n b = (b > 0.0031308) ? (1.055 * Math.pow(b, 1/2.4) - 0.055) : 12.92 * b;\n\n return [\n setDecimalPlaces(Math.max(0, Math.min(1, r)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, g)) * 255, decimalPlaces),\n setDecimalPlaces(Math.max(0, Math.min(1, b)) * 255, decimalPlaces),\n ];\n};\n\n// ----------------------- GET SHIFTED COLORS --------------------------------------\n\nexport const getShiftedHue = (color: HSLColor, shift = 180) : HSLColor => {\n let hue = color[0];\n hue += shift;\n\n if (hue > 360 || hue < 0) {\n hue = mod(hue, 360);\n }\n\n return [hue, color[1], color[2]];\n};\n\nexport const getShiftedLightness = (color: HSLColor, shift = 10) : HSLColor => {\n let lightness = color[2];\n lightness += shift;\n\n if (lightness > 100 || lightness < 0) {\n lightness = mod(lightness, 100);\n }\n\n return [color[0], color[1], lightness];\n};\n\nexport const getShiftedSaturation = (color: HSLColor, shift = 10) : HSLColor => {\n let saturation = color[1];\n saturation += shift;\n\n if (saturation > 100) {\n saturation -= 100;\n }\n\n if(saturation < 0){\n saturation += 100;\n }\n\n return [color[0], saturation, color[2]];\n};\n\n// ----------------------- SIMILAR COLORS --------------------------------------\n\n/**\n * Measure the perceptual difference between two RGB colors using the CIE76 color difference formula:\n * delta = Math.sqrt((L2 - L1)^2 + (a2 - a1)^2 + (b2 - b1)^2)\n * https://en.wikipedia.org/wiki/Color_difference\n * https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js\n * <= 1.0 Not perceptible by human eyes.\n * 1 - 2 Perceptible through close observation.\n * 2 - 10 Perceptible at a glance.\n * 11 - 49 Colors are more similar than opposite\n * 100 Colors are exact opposite\n */\nexport const getColorsDelta = (rgbA: RGBColor, rgbB: RGBColor, decimalPlaces = Infinity) => {\n const labA = rgbToLab(rgbA, decimalPlaces);\n const labB = rgbToLab(rgbB, decimalPlaces);\n\n // differences between the LAB components of the two colors\n const deltaL = labA[0] - labB[0];\n const deltaA = labA[1] - labB[1];\n const deltaB = labA[2] - labB[2];\n\n // chroma components\n const c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);\n const c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);\n const deltaC = c1 - c2;\n\n // difference in hue, deltaH, which takes into account both the differences\n // in the a* and b* components of LAB and the differences in chroma.\n let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;\n deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);\n\n const sc = 1.0 + 0.045 * c1;\n const sh = 1.0 + 0.015 * c1;\n\n // It applies weighting factors to the differences in lightness (deltaL),\n // chroma (deltaC), and hue (deltaH).\n const deltaLKlsl = deltaL / (1.0);\n const deltaCkcsc = deltaC / (sc);\n const deltaHkhsh = deltaH / (sh);\n\n // It computes the final color difference using the CIE76 formula:\n // deltaE = sqrt(deltaLKlsl^2 + deltaCkcsc^2 + deltaHkhsh^2),\n // where deltaLKlsl is the weighted lightness difference,\n // deltaCkcsc is the weighted chroma difference,\n // and deltaHkhsh is the weighted hue difference.\n const i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;\n\n // It returns the calculated color difference,\n // optionally rounded to the specified number of decimal places.\n return i < 0 ? 0 : Math.sqrt(i);\n};\n", "/**\n * guid like '932ade5e-c515-4807-ac01-73b20ab3fb66'\n */\nexport const guid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 | 0;\n return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);\n });\n};\n\n/**\n * id like 'df4unio1opulby2uqh4'\n */\nexport const newId = () => {\n return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);\n};\n", "import { ICircle, IPolygon, IRect, Matrix2, Vector2 } from '../types';\nimport { mod } from './other';\nimport { v2GetNormal, v2DotProduct } from './linear-algebra/vector';\n\n/**\n * Rectangles collision detection.\n * Rectangles should not be rotated.\n * The algorithm works by ensuring there is no gap between any of the 4 sides of the rectangles.\n * Any gap means a collision does not exist.\n * Returns true if collision is detected.\n */\nexport const rectCollide = (rect1: IRect, rect2: IRect) : boolean => {\n return rect1.x <= rect2.x + rect2.w &&\n rect1.x + rect1.w >= rect2.x &&\n rect1.y <= rect2.y + rect2.h &&\n rect1.h + rect1.y >= rect2.y;\n};\n\n/**\n * Circles collision detection.\n * This algorithm works by taking the center points of the two circles\n * and ensuring the distance between the center points\n * are less than the two radii added together.\n * Returns true if collision is detected.\n */\nexport const circleCollide = (circle1: ICircle, circle2: ICircle) => {\n const dx = Math.abs(circle1.cx - circle2.cx);\n const dy = Math.abs(circle1.cy - circle2.cy);\n const distance = Math.sqrt(dx * dx + dy * dy);\n return distance <= circle1.r + circle2.r;\n};\n\n//-------------------- Separating Axis Theorem (SAT) Collision detection -------------------------\n\nconst getEdges = (poly: IPolygon) : Matrix2[] => {\n const edges: Matrix2[] = [];\n\n for(let i= 0; i {\n const edges: Matrix2[] = [];\n\n // collect polygon edges, and combine then into a single array\n edges.push(...getEdges(poly1));\n edges.push(...getEdges(poly2));\n\n // for each edge, find the normal vector and project both polygons onto it\n for (const edge of edges) {\n const normal = v2GetNormal(edge[0], edge[1]);\n const p1Proj = projectPolygon(poly1, normal);\n const p2Proj = projectPolygon(poly2, normal);\n\n // Check if the projections overlap\n const isOverlap = p1Proj.max >= p2Proj.min && p2Proj.max >= p1Proj.min;\n\n // Check if the projections overlap; if not, the polygons do not collide\n if (!isOverlap) return false;\n }\n\n // If all tests pass, the polygons overlap and collide\n return true;\n};\n\n/**\n * Project every polygon point onto the normal.\n * Then find min and max.\n */\nconst projectPolygon = (polygon: IPolygon, normal: Vector2): { min: number, max: number } => {\n let min = Infinity;\n let max = -Infinity;\n\n // Project each vertex of the polygon onto the axis\n for (const vertex of polygon) {\n const projection = v2DotProduct(vertex, normal);\n min = Math.min(min, projection);\n max = Math.max(max, projection);\n }\n\n return { min, max };\n};", "export interface IAnimationProps {\n duration?: number;\n callback: (result: IAnimationResult) => void;\n restartOnResize?: boolean;\n resizeCallback?: (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => void;\n}\n\nexport interface IAnimationResult {\n start: () => void;\n stop: () => void;\n pause: () => void;\n resume: () => void;\n restart: () => void;\n isAnimating: () => boolean;\n getStartTime: () => number|undefined;\n getElapsedTime: () => number|undefined;\n getPercent: () => number|undefined;\n getResizeObserver: () => ResizeObserver|undefined;\n}\n\nexport const animate = (props: IAnimationProps) : IAnimationResult => {\n\n const _duration = props.duration !== undefined ? props.duration : Infinity;\n\n let startTime: number|undefined = undefined; // in milliseconds\n let animationId: number|undefined = undefined;\n\n // the time elapsed since the start of the animation (in milliseconds)\n let elapsed: number|undefined = undefined;\n let previousTimeStamp: number|undefined = undefined;\n\n let animating = false;\n let observer: ResizeObserver|undefined = undefined;\n\n // -------------------- COMMANDS ---------------------\n\n const stop = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = false;\n\n /*if(observer !== undefined){\n observer.disconnect();\n observer = undefined;\n }*/\n\n if(animationId === undefined) return;\n window.cancelAnimationFrame(animationId);\n };\n\n const restart = () => {\n stop();\n start();\n };\n\n const pause = () => {\n animating = false;\n };\n\n const resume = () => {\n animating = true;\n };\n\n /**\n * Animation Step.\n * @param {number} timeStamp in milliseconds\n */\n const step = (timeStamp: DOMHighResTimeStamp) => {\n\n if (startTime === undefined) {\n startTime = timeStamp;\n }\n\n // the time elapsed since the start of the animation (in milliseconds)\n elapsed = timeStamp - startTime;\n\n if (animating && previousTimeStamp !== timeStamp && typeof props.callback === 'function') {\n\n // do the rendering .............\n props.callback(getResult());\n }\n\n if(elapsed <= _duration){\n previousTimeStamp = timeStamp;\n animationId = window.requestAnimationFrame(step);\n }\n else{\n stop();\n }\n };\n\n const observerHandler = (_entries: ResizeObserverEntry[], _observer: ResizeObserver) => {\n restart();\n\n if(typeof props.resizeCallback === 'function'){\n props.resizeCallback(_entries, _observer);\n }\n };\n\n const start = () => {\n startTime = undefined;\n elapsed = undefined;\n previousTimeStamp = undefined;\n animating = true;\n\n if(props.restartOnResize && window.ResizeObserver && observer === undefined){\n observer = new ResizeObserver(observerHandler);\n observer.observe(document.body, { box: 'border-box' });\n }\n else{\n animationId = window.requestAnimationFrame(step);\n }\n };\n\n // --------------- GET INFO ----------------------\n\n /**\n * the time elapsed since the start of the animation (in milliseconds)\n */\n const getElapsedTime = () : number|undefined => {\n return elapsed;\n };\n\n const isAnimating = () => {\n return animating;\n };\n\n const getStartTime = () => {\n return startTime;\n };\n\n const getPercent = () => {\n if(_duration === Infinity || elapsed === undefined) return undefined;\n return elapsed * 100 / _duration;\n };\n\n const getResizeObserver = () => {\n return observer;\n };\n\n const getResult = () : IAnimationResult => {\n return {\n\n // commands --------------\n start,\n stop,\n pause,\n resume,\n restart,\n\n // information -------\n isAnimating,\n getElapsedTime,\n getStartTime,\n getPercent,\n getResizeObserver,\n };\n };\n\n return getResult();\n};\n", "import { setDecimalPlaces } from './format';\n\nexport const getCircleCircumference = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * radius, decimalPlaces);\n};\n\nexport const getEllipseCircumference = (radius1: number, radius2: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(2 * Math.PI * Math.sqrt((radius1 ** 2 + radius2 ** 2) / 2), decimalPlaces);\n};\n\nexport const isAngleInCircleArc = (startAngleDeg: number, endAngleDeg: number, currentDegrees: number) : boolean => {\n\n if(startAngleDeg > endAngleDeg) {\n endAngleDeg += 360;\n }\n\n return currentDegrees >= startAngleDeg && currentDegrees <= endAngleDeg ||\n (currentDegrees + 360) >= startAngleDeg && (currentDegrees + 360) <= endAngleDeg;\n};\n\n/**\n * get the side of a square inscribed in a circle\n */\nexport const getSquareInCircleSide = (radius: number, decimalPlaces = Infinity) => {\n return setDecimalPlaces(radius * 2 / Math.sqrt(2), decimalPlaces);\n};\n", "/**\n * 1 + 2 + ... + n = n * (n + 1) / 2\n */\nexport const naturalNumbersSequenceSum = (n: number) => {\n return n * (n + 1) / 2;\n};\n\n/**\n * n = the number of terms to be added\n * a = the first term in the sequence\n * d = the constant value between terms\n */\nexport const arithmeticSequenceSum = (n: number, a: number, d: number) => {\n return (n / 2) * (2 * a + (n - 1) * d);\n};", "import { setDecimalPlaces } from './format';\n\n// -------------------- CENTRAL TENDENCY ----------------------------\n\n/**\n * Central tendency: Calculate the Average (mean)\n * Sum of all numbers divided by the array length.\n */\nexport const getArithmeticMean = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const sum = data.reduce((acc, val) => acc + val, 0);\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};\n\n/**\n * Central tendency: What is the central number in the sorted array?\n * Good for lists like [3, 3, 3, 3, 3, 3, 100] - 100 here is called \"Outlier\"\n */\nexport const getMedian = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const copy = [...data].sort((num1, num2) => num1 - num2);\n const mid = Math.floor(copy.length / 2);\n\n if(copy.length % 2 === 0) {\n return setDecimalPlaces((copy[mid] + copy[mid - 1]) / 2, decimalPlaces);\n }\n else {\n return setDecimalPlaces(copy[mid], decimalPlaces);\n }\n};\n\n/**\n * Central tendency: What number is most common in the set.\n * If all numbers have the same frequency, there is no mode.\n */\nexport const getMode = (data: number[]) : number[]|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n // Count frequency of each number in the data array.\n const frequencyMap: Map = new Map();\n for (const num of data) {\n frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);\n }\n\n let maxFrequency = 0;\n let modes: number[] = [];\n\n // Find the maximum frequency\n for (const [num, frequency] of frequencyMap) {\n if (frequency > maxFrequency) {\n maxFrequency = frequency;\n modes = [num];\n }\n else if (frequency === maxFrequency) {\n modes.push(num);\n }\n }\n\n // If all numbers have the same frequency, there is no mode\n if (modes.length === data.length) {\n return undefined;\n }\n\n // Return the mode(s)\n return modes.length === 1 ? [modes[0]] : modes;\n};\n\n/*\nTODO:\n- geometric mean\n- harmonic mean\n */\n\n// -------------------- DISPERSION ----------------------------\n\n/**\n * Dispersion: the average square distance from the mean.\n */\nexport const getVariance = (data: number[], decimalPlaces = Infinity) : number|undefined => {\n if(!data || data.length <= 0) return undefined;\n\n const mean = getArithmeticMean(data);\n if(mean === undefined) return undefined;\n\n const sum = data.reduce((acc, val) => acc + ((val - mean) ** 2), 0);\n\n return setDecimalPlaces(sum / data.length, decimalPlaces);\n};", "import { setDecimalPlaces } from './format';\n\n/**\n * Returns a copy of array, where each value will be in the range [0, 1].\n * const newValue = (value - array_min) / (array_max - array_min)\n */\nexport const mlNormalize = (data: number[], decimalPlaces = Infinity): number[] => {\n const copy = [...data];\n\n const min = Math.min(...copy);\n const max = Math.max(...copy);\n\n const diff = max - min;\n if(diff === 0) return [0];\n\n for(let i=0; i { + const copy = [...data]; + + const min = Math.min(...copy); + const max = Math.max(...copy); + + const diff = max - min; + if(diff === 0) return [0]; + + for(let i=0; i { + + describe('mlNormalize()', () => { + + test('[]', () => { + expect(mlNormalize([])).toStrictEqual([]); + }); + + test('[2]', () => { + expect(mlNormalize([2])).toStrictEqual([0]); + }); + + test('[1, 2, 3]', () => { + expect(mlNormalize([1, 2, 3])).toStrictEqual([0, 0.5, 1]); + }); + + test('[-1, -2]', () => { + expect(mlNormalize([-1, -2])).toStrictEqual([1, 0]); + }); + + test('[1, 1, 2, 3, 4]', () => { + expect(mlNormalize([1, 1, 2, 3, 4], 2)).toStrictEqual([0, 0, 0.33, 0.67, 1]); + }); + }); +}); \ No newline at end of file