Comparing version 1.0.0-beta.25 to 1.0.1
@@ -65,2 +65,3 @@ import { vec2 } from 'gl-matrix'; | ||
}; | ||
clearCache(): void; | ||
applyFn(fn: PointFn): void; | ||
@@ -67,0 +68,0 @@ splitByCoord(coordData: CoordData): Curve[]; |
@@ -1,1 +0,1 @@ | ||
(function(P,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(P=typeof globalThis<"u"?globalThis:P||self,B(P.geometry={}))})(this,function(P){"use strict";var Wn=Object.defineProperty;var Jn=(P,B,O)=>B in P?Wn(P,B,{enumerable:!0,configurable:!0,writable:!0,value:O}):P[B]=O;var v=(P,B,O)=>Jn(P,typeof B!="symbol"?B+"":B,O);function B(){return{xMin:1/0,xMax:-1/0,yMin:1/0,yMax:-1/0}}function O(i,e){return i.xMin=Math.min(i.xMin,e.xMin),i.xMax=Math.max(i.xMax,e.xMax),i.yMin=Math.min(i.yMin,e.yMin),i.yMax=Math.max(i.yMax,e.yMax),i}function nn(i){return{width:i.xMax-i.xMin,height:i.yMax-i.yMin}}function Et(i,e){return i.xMin<=e.xMin&&i.xMax>=e.xMax&&i.yMin<=e.yMin&&i.yMax>=e.yMax}var bt=1e-6,et=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var i=0,e=arguments.length;e--;)i+=arguments[e]*arguments[e];return Math.sqrt(i)});function y(){var i=new et(2);return et!=Float32Array&&(i[0]=0,i[1]=0),i}function V(i){var e=new et(2);return e[0]=i[0],e[1]=i[1],e}function m(i,e){var t=new et(2);return t[0]=i,t[1]=e,t}function en(i,e){return i[0]=e[0],i[1]=e[1],i}function ht(i,e,t){return i[0]=e[0]+t[0],i[1]=e[1]+t[1],i}function on(i,e,t){return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i}function sn(i,e,t){return i[0]=e[0]*t,i[1]=e[1]*t,i}function it(i,e,t,n){return i[0]=e[0]+t[0]*n,i[1]=e[1]+t[1]*n,i}function E(i,e){var t=e[0]-i[0],n=e[1]-i[1];return Math.hypot(t,n)}function rn(i){var e=i[0],t=i[1];return Math.hypot(e,t)}function N(i,e){var t=e[0],n=e[1],s=t*t+n*n;return s>0&&(s=1/Math.sqrt(s)),i[0]=e[0]*s,i[1]=e[1]*s,i}function ft(i,e){return i[0]*e[0]+i[1]*e[1]}function D(i,e,t,n){var s=e[0],o=e[1];return i[0]=s+n*(t[0]-s),i[1]=o+n*(t[1]-o),i}function cn(i,e){var t=i[0],n=i[1],s=e[0],o=e[1],r=Math.sqrt(t*t+n*n)*Math.sqrt(s*s+o*o),c=r&&(t*s+n*o)/r;return Math.acos(Math.min(Math.max(c,-1),1))}function ot(i,e){return i[0]===e[0]&&i[1]===e[1]}function Dt(i,e){var t=i[0],n=i[1],s=e[0],o=e[1];return Math.abs(t-s)<=bt*Math.max(1,Math.abs(t),Math.abs(s))&&Math.abs(n-o)<=bt*Math.max(1,Math.abs(n),Math.abs(o))}var an=rn,A=on,H=E;(function(){var i=y();return function(e,t,n,s,o,r){var c,a;for(t||(t=2),n||(n=0),s?a=Math.min(s*t+n,e.length):a=e.length,c=n;c<a;c+=t)i[0]=e[c],i[1]=e[c+1],o(i,i,r),e[c]=i[0],e[c+1]=i[1];return e}})();function ln(i){return i*Math.PI/180}function st(i){return i*180/Math.PI}function un(i){return st(Math.atan2(i[1],i[0]))}function hn(i,e,t){const n=E(i,e),s=E(e,t),o=E(t,i),r=(n+s+o)/2,c=4*Math.sqrt(r*(r-n)*(r-s)*(r-o));return Math.abs(c)<1e-20?1/0:n*s*o/4/Math.sqrt(r*(r-n)*(r-s)*(r-o))}const tt=1e-12;function _(i){switch(i.length){case 0:return[];case 1:return[0];case 2:return Math.abs(i[0])<tt?[]:[-i[1]/i[0]];case 3:return Math.abs(i[0])<tt?_(i.slice(1)):fn(i);case 4:return Math.abs(i[0])<tt?_(i.slice(1)):Pn(i);default:throw new Error("Not implemented")}}function fn(i){const e=i[0],t=i[1],n=i[2],s=t*t-4*e*n;if(s<0)return[];{const o=Math.sqrt(s);return[(-t+o)/(2*e),(-t-o)/(2*e)]}}function Pn(i){const e=i[0],t=i[1],n=i[2],s=i[3],o=t/e,r=n/e,c=s/e,a=(3*r-o*o)/9,l=(9*o*r-27*c-2*o*o*o)/54,u=a*a*a+l*l;if(u>=0){const h=Math.sqrt(u),p=Math.cbrt(l+h),f=Math.cbrt(l-h),g=[-o/3+(p+f)];return u===0&&g.push(-p/2),g}else{const h=Math.acos(l/Math.sqrt(-a*a*a)),p=Math.sqrt(-a);return[2*p*Math.cos(h/3)-o/3,2*p*Math.cos((h+2*Math.PI)/3)-o/3,2*p*Math.cos((h+4*Math.PI)/3)-o/3]}}function pn(i,e,t){[i[e],i[t]]=[i[t],i[e]]}function gn(i){const{length:e}=i;for(let n=0;n<e;n++){let s=n;for(let o=n+1;o<e;o++)Math.abs(i[o][n])>Math.abs(i[s][n])&&(s=o);pn(i,n,s);for(let o=n+1;o<e;o++){if(Math.abs(i[n][n])<tt)continue;const r=i[o][n]/i[n][n];for(let c=n;c<e+1;c++)i[o][c]-=r*i[n][c]}}const t=new Array(e).fill(0);for(let n=e-1;n>=0;n--)if(!(Math.abs(i[n][n])<tt)){t[n]=i[n][e]/i[n][n];for(let s=n-1;s>=0;s--)i[s][e]-=i[s][n]*t[n]}return console.log(i),t}function yn(i){return new Array(i).fill(0).map(()=>new Array(i))}function dn(i){return i.map(e=>e.slice())}function mn(i){return Math.max(...i)}function xn(i){return Math.min(...i)}function $(i){return i.reduce((e,t)=>e+t,0)}function rt(i){return $(i)/i.length}function Cn(i){return rt(i),Math.sqrt(Bt(i))}function Bt(i){const e=rt(i);return rt(i.map(t=>Math.pow(t-e,2)))}function vn(i){const e=i.slice().sort((n,s)=>n-s),t=Math.floor(i.length/2);return i.length%2!==0?e[t]:(e[t-1]+e[t])/2}function Lt(i,e){const t=i.length,n=$(i),s=$(e),o=s/t,r=$(i.map((g,d)=>g*e[d])),c=$(i.map(g=>g*g)),a=1e-10;if(t*c-n*n<a)return{k:1/0,b:n/t,R2:1};const l=(t*r-n*s)/(t*c-n*n),u=(s-l*n)/t,h=Math.max(a,$(e.map(g=>Math.pow(g-o,2)))),f=Math.max(a,$(i.map(g=>Math.pow(l*g+u-o,2))))/h;return{k:l,b:u,R2:f}}function Mn(i,e,t){return Math.abs(U([i,e,t]))}function Sn(i,e){let[t,n]=i,[[s,o],[r,c]]=e;return(t-s)*(c-o)-(n-o)*(r-s)>0}function At(i,e){let[t,n]=i,s=!1;for(let o=0,r=e.length-1;o<e.length;r=o++){let[c,a]=e[o],[l,u]=e[r];a>n!=u>n&&t-c<(l-c)*(n-a)/(u-a)&&(s=!s)}return s}function wn(i,e,t){const n=E(i,e),s=E(e,t),o=E(t,i),r=n*s*o;return Math.abs(r)<1e-20?0:U([i,e,t])/(n*s*o)}function U(i){let e=0;const{length:t}=i;for(let n=0;n<t;n++){let[s,o]=i[n],[r,c]=i[(n+1)%t];e+=s*c-r*o}return e/2}function En(i,e){if(i.length!==e.length)return!1;for(let t=0;t<i.length;t++)if(i[t]!==e[t])return!1;return!0}function nt(i,e){return i[0]*e[1]-i[1]*e[0]}const Tt=1103515245,It=12345,Pt=2147483647;function Vt(i=.314){let e=(Tt*i+It)%Pt;return()=>(e=(Tt*e+It)%Pt,e/Pt)}function bn(i){return Math.pow(2,-10*i)*Math.sin((i-.2/4)*(2*Math.PI)/.2)+1}function Dn(i){return i<.5?.5*Math.pow(2,20*i-10)*Math.sin((20*i-11.125)*(2*Math.PI)/.9):.5*(2-Math.pow(2,-20*i+10)*Math.sin((20*i-11.125)*(2*Math.PI)/.9))}function Bn(i,e=4){return Math.max(e-Math.floor(Math.log10(i)),0)}function Ln(i){if(i.length<=1)return i;const e=new Map,t=new Map;for(const o of i){if(o.length<2)throw new Error("couple length must be greater than 1");const[r,c]=[o[0],o[o.length-1]];e.set(r,c),t.set(c,r)}const n=[];let s=i.length**2;for(;(e.size||t.size)&&s-- >0;){let o=e.keys().next().value;const r=[o];let c=e.get(o);for(;c!==void 0&&c!==o&&s-- >0;)r.push(c),e.delete(o),t.delete(c),o=c,c=e.get(c);for(o=r[0],c=t.get(o);c!==void 0&&c!==o&&s-- >0;)r.unshift(c),e.delete(c),t.delete(o),o=c,c=t.get(c);n.push(r)}return n}function An(i,e){return st(pt(i.outDir,e.inDir))}function pt(i,e){const t=i[0]*e[1]-i[1]*e[0],n=i[0]*e[0]+i[1]*e[1];return Math.atan2(t,n)}class _t{constructor(e,t){v(this,"type","curve");v(this,"_isDirty",!0);v(this,"_SPoint",y());v(this,"_EPoint",y());v(this,"_bbox2");v(this,"_len");v(this,"inDir",y());v(this,"outDir",y());this.SPoint=e,this.EPoint=t,this._isDirty=!1}set SPoint(e){this._isDirty||(this._isDirty=!ot(this._SPoint,e)),this._SPoint=e}get SPoint(){return this._SPoint}set EPoint(e){this._isDirty||(this._isDirty=!ot(this._EPoint,e)),this._EPoint=e}get EPoint(){return this._EPoint}get bbox(){const{xMin:e,yMin:t,xMax:n,yMax:s}=this.bbox2;return{x:e,y:t,width:n-e,height:s-t}}get bbox2(){return(this._isDirty||!this._bbox2)&&this.update(),this._bbox2}get len(){return(this._isDirty||!this._len&&this._len!==0)&&this.update(),this._len}get deflection(){const{inDir:e,outDir:t}=this;return pt(e,t)}update(){this._bbox2=this._getBBox2(),this._len=this._getLen(),this._isDirty=!1}splitAtArray(e){e.sort((o,r)=>o-r);let t=this;const n=new Array(e.length+1);let s=0;for(let o=0;o<e.length;o++){let r=e[o];r=(r-s)/(1-s),s=e[o];const c=t.splitAt(r);n[o]=c[0],t=c[1]}return n[e.length]=t,n}splitByCoord(e){const t=this.getSplitT(e);return this.splitAtArray(t)}}function Tn(i){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",i),e.appendChild(t),e}function qt(i,e=1){const t=i[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return i.forEach(s=>{n+=s.toPathString(e)+" "}),n+="Z",n}function In(i,e=1){const t=i[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return i.forEach(s=>{n+=s.toDebugPathString(e)+" "}),n}function ct(i){const e=/([MmLlHhVvCcSsQqTtAaZz])|([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/g,t=i.match(e);if(!t)throw new Error("Invalid path string");const n=[];let s=null,o=[];for(const r of t)isNaN(parseFloat(r))?(s&&(n.push({type:s,args:o}),o=[]),s=r):o.push(parseFloat(r));return s&&n.push({type:s,args:o}),n}function Vn(i,e,t){const n=[],s=i.length,o=e.length;for(let r=0;r<o;r++){const c=D(y(),i[r%s],e[r],t);n.push(c)}return n}function _n(i,e,t,n,s){const o=t.length+e,r=2;if(e<1)throw new Error("degree must be at least 1 (linear)");if(e>o-1)throw new Error("degree must be less than or equal to point count - 1");if(s||(s=new Array(o).fill(1)),n){if(n.length!==o+e+1)throw new Error("bad knot vector length")}else{n=[];for(let f=0;f<o+e+1;f++)n[f]=f}const c=[];for(let f=0;f<o;f++){c[f]=[];for(let g=0;g<r;g++)c[f][g]=t[f%(o-e)][g]*s[f];c[f][r]=s[f]}const a=n[e],l=n[o];if(i=i*(l-a)+a,i<a||i>l)throw new Error("out of bbox2");let u;for(u=e;u<o&&!(i>=n[u]&&i<=n[u+1]);u++);let h;for(let f=1;f<=e+1;f++)for(let g=u;g>u-e-1+f;g--){h=(i-n[g])/(n[g+e+1-f]-n[g]);for(let d=0;d<r+1;d++)c[g][d]=(1-h)*c[g-1][d]+h*c[g][d]}console.log("pointDataArr",c);let p=[];for(let f=0;f<r;f++)p[f]=c[u][f]/c[u][r];return m(p[0],p[1])}function kt(i,e){const{length:t}=i;if(e<1)throw new Error("degree must be at least 1 (linear)");if(e>t-1)throw new Error(`degree:${e} must be less than or equal to point count - 1(${t-1})`);const n=new Array(t),s=new Array(t);for(let o=0;o<t;o++)n[o]=i[o][0],s[o]=i[o][1];return o=>{if(o<0||o>1)throw new Error("out of bbox2");o=o*t+e;const r=Ft(n,e,o),c=Ft(s,e,o);return m(r,c)}}function Ft(i,e,t){const{length:n}=i,s=n+e,o=Math.floor(t),r=new Array(s);for(let c=0;c<s;c++)r[c]=i[c%n];for(let c=0;c<e;c++)for(let a=o;a>o-e+c;a--){const l=(t-a)/(e-c);r[a]=l*r[a]+(1-l)*r[a-1]}return r[o]}function Rt(i,e,t,n=0,s=0,o=.1){const r=[],c=i/2,a=e/2,l=Vt(o);let u=h=>{const f=l()*n+(1-n);let g=(f*Math.cos(h)+1)*c,d=(f*Math.sin(h)+1)*a;return m(g,d)};for(let h=0;h<t;h++){let p=u(2*Math.PI*(h/t+s));r.push(p)}return r}function zt(i){let e=1/0,t=1/0,n=-1/0,s=-1/0;for(const o of i){const{bbox:r}=o;e=Math.min(e,r.x),t=Math.min(t,r.y),n=Math.max(n,r.x+r.width),s=Math.max(s,r.y+r.height)}return{x:e,y:t,width:n-e,height:s-t}}function Nt(i,e){const t=zt(i),n=e.width/t.width,s=e.height/t.height;for(const o of i)o.applyFn(r=>{r[0]=(r[0]-t.x)*n+e.x,r[1]=(r[1]-t.y)*s+e.y})}function $t(i,e=3){const t=[],s=new Array(100),o=kt(i,Number(e)),r=performance.now();for(let a=0;a<100;a++)s[a]=o(a/100);performance.now()-r;const c=new Array(100);for(let a=0;a<100;a++){const l=m(s[a][0],s[a][1]),u=m(s[(a+1)%100][0],s[(a+1)%100][1]),h=D(y(),l,u,.5);c[a]=h}for(let a=0;a<100;a++){const l=V(c[a]),u=c[(a+1)%100],h=s[(a+1)%100];t.push(new k(l,h,u))}return t}function qn(i=100,e=100,t=6,n=.5,s=Math.random(),o=3){const r=Rt(i,e,t,n,s),c=$t(r,o);return Nt(c,{x:0,y:0,width:i,height:e}),qt(c)}function q(i,e){return`${(0+i[0]).toFixed(e)} ${(0+i[1]).toFixed(e)}`}const Qt="curve-line";class L extends _t{constructor(t,n){super(t,n);v(this,"tangent");v(this,"normal");this.type=Qt,this.tangent=N(y(),A(y(),n,t)),this.normal=m(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.outDir=this.tangent}update(){super.update(),this.tangent=N(y(),A(y(),this.EPoint,this.SPoint)),this.normal=m(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.outDir=this.tangent}_getBBox2(){const{SPoint:t,EPoint:n}=this,[s,o]=t[0]<n[0]?[t[0],n[0]]:[n[0],t[0]],[r,c]=t[1]<n[1]?[t[1],n[1]]:[n[1],t[1]];return{xMin:s,yMin:r,xMax:o,yMax:c}}_getLen(){return E(this.SPoint,this.EPoint)}getNormal(t){return this.normal}getTangent(t){return this.tangent}getCurvature(t){return 0}getMaxCurvature(){return 0}getPosition(t){return D(y(),this.SPoint,this.EPoint,t)}getPosDataByPer(t){const n=this.getPosition(t),s=this.tangent;return{pos:n,tan:s}}getSplitT(t){const{x:n,y:s,width:o,height:r}=this.bbox,{SPoint:c,EPoint:a}=this,{mode:l,val:u}=t,h=[];return l==="x"&&u>=n&&u<=n+o?h.push((u-c[0])/(a[0]-c[0])):l==="y"&&u>=s&&u<=s+r&&h.push((u-c[1])/(a[1]-c[1])),h}getLineIntersects(t){const[n,s]=this.SPoint,[o,r]=this.EPoint,[c,a]=t.SPoint,[l,u]=t.EPoint,h=[],p=(n-o)*(a-u)-(s-r)*(c-l);if(Math.abs(p)>1e-10){const f=n*r-s*o,g=c*u-a*l,d=(f*(c-l)-g*(n-o))/p,x=(f*(a-u)-g*(s-r))/p,{xMin:C,yMin:M,xMax:S,yMax:w}=this.bbox2;d>=C&&d<=S&&x>=M&&x<=w&&h.push(m(d,x))}return h}getDisToPos(t){const{SPoint:n,EPoint:s,tangent:o}=this,r=A(y(),t,n),c=ft(r,o);if(c<0)return E(n,t);const a=E(n,s);if(c>a)return E(s,t);const l=m(-o[1],o[0]);return Math.abs(ft(l,r))}applyFn(t){t(this.SPoint),t(this.EPoint)}applyFFDFn(t){this.applyFn(t)}reverse(){[this.SPoint,this.EPoint]=[this.EPoint,this.SPoint],this.update()}splitAt(t){const{SPoint:n,EPoint:s}=this,o=this.getPosition(t);return[new L(n,o),new L(V(o),s)]}isPointOnCurve(t){const{SPoint:n,EPoint:s}=this,o=E(n,t),r=E(s,t),c=E(n,s);return Math.abs(o+r-c)<1e-10}toPathString(t=0){return`L ${q(this.EPoint,t)}`}toDebugPathString(t){return this.toPathString(t)}clone(){return new L(V(this.SPoint),V(this.EPoint))}}function kn(i,e){return ft(i.tangent,e.tangent)>.982}function gt(i,e,t,n){const[s,o]=i,[r,c]=e,[a,l]=t,[u,h]=n,p=c-o,f=s-r,g=r*o-s*c,d=h-l,x=a-u,C=u*l-a*h,M=p*x-d*f,S=(f*C-x*g)/M,w=(d*g-p*C)/M;return m(S,w)}function yt(i,e){const[t,n]=i.SPoint,[s,o]=i.EPoint,[r,c]=e.SPoint,[a,l]=e.EPoint,u=(t-r)*(l-c)-(n-c)*(a-r),h=(s-r)*(l-c)-(o-c)*(a-r),p=(r-t)*(o-n)-(c-n)*(s-t),f=(a-t)*(o-n)-(l-n)*(s-t);return u*h<0&&p*f<0}const at=100,jt="curve-quadratic";class k extends L{constructor(t,n,s){super(t,s);v(this,"_CPoint1",y());v(this,"_lenArr",new Array(at).fill(0));this.type=jt,this.CPoint1=n;let o=A(y(),n,t);this.inDir=N(o,o),o=A(y(),s,n),this.outDir=N(o,o)}set CPoint1(t){this._isDirty||(this._isDirty=!ot(this._CPoint1,t)),this._CPoint1=t}get CPoint1(){return this._CPoint1}update(){super.update(),this.inDir=this.getTangent(0),this.outDir=this.getTangent(1)}_getBBox2(){const[t,n]=this.SPoint,[s,o]=this.CPoint1,[r,c]=this.EPoint,a=[2*(t-2*s+r),2*(s-r)],l=[2*(n-2*o+c),2*(o-c)],u=_(a),h=_(l),p=u.filter(w=>w>0&&w<1).concat([0,1]),f=h.filter(w=>w>0&&w<1).concat([0,1]),g=p.map(w=>this.getPosition(w)[0]),d=f.map(w=>this.getPosition(w)[1]),x=Math.min(...g),C=Math.max(...g),M=Math.min(...d),S=Math.max(...d);return{xMin:x,xMax:C,yMin:M,yMax:S}}_getLen(){let t=0,n=this.getPosition(0);for(let s=1;s<=at;s++){let o=this.getPosition(s/100);t+=E(n,o),n=o,this._lenArr[s-1]=t}return t}getPosition(t){const n=(1-t)**2,s=2*t*(1-t),o=t**2,r=n*this.SPoint[0]+s*this.CPoint1[0]+o*this.EPoint[0],c=n*this.SPoint[1]+s*this.CPoint1[1]+o*this.EPoint[1];return m(r,c)}getPosDataByPer(t){let n=0,s=this._lenArr.length-1,o;const r=this.len*t;for(;n<s;)o=Math.floor((n+s)/2),this._lenArr[o]<r?n=o+1:s=o;const c=this._lenArr[n-1]||0;let a=n/at;a+=(r-c)/(this._lenArr[n]-c)/at;const l=this.getPosition(a),u=this.getTangent(a);return{pos:l,tan:u}}getTangent(t){const n=this.getDerivative(t);return N(n,n)}getNormal(t){const[n,s]=this.getTangent(t);return m(s,-n)}getMaxCurvature(){const t=this.getCusps();let n=0;for(const s of t){const o=this.getCurvature(s);Math.abs(o)>Math.abs(n)&&(n=o)}return n}getSplitT(t){const{x:n,y:s,width:o,height:r}=this.bbox,{mode:c,val:a}=t;if(c==="x"){if(a>=n&&a<=n+o){const l=[this.SPoint[0]-2*this.CPoint1[0]+this.EPoint[0],2*(this.CPoint1[0]-this.EPoint[0]),this.EPoint[0]-a];return _(l).filter(h=>h>0&&h<1)}}else if(a>=s&&a<=s+r){const l=[this.SPoint[1]-2*this.CPoint1[1]+this.EPoint[1],2*(this.CPoint1[1]-this.EPoint[1]),this.EPoint[1]-a];return _(l).filter(h=>h>0&&h<1)}return[]}getLineIntersects(t){const{xMin:n,xMax:s,yMin:o,yMax:r}=this.bbox2,{SPoint:c,EPoint:a}=t,l=[m(n,o),m(s,o),m(s,r),m(n,r)];let u=0;for(const I of l)u+=nt(t.tangent,A(y(),I,c))>0?1:0;if(u===0||u===4)return[];const h=[],[p,f]=this.SPoint,[g,d]=this.CPoint1,[x,C]=this.EPoint,[M,S]=t.SPoint,w=p-2*g+x,T=f-2*d+C,b=2*(g-p),Z=2*(d-f),J=p,K=f,[R,Y]=A(y(),t.EPoint,t.SPoint),lt=R*T-Y*w,ut=R*Z-Y*b,X=R*K-Y*J-R*S+Y*M,G=_([lt,ut,X]);for(const I of G)if(I>=0&&I<=1){const St=(1-I)**2*p+2*I*(1-I)*g+I**2*x,wt=(1-I)**2*f+2*I*(1-I)*d+I**2*C;h.push(m(St,wt))}return h}getDisToPos(t){let n=100,s=1/0;for(let o=0;o<=n;o++){const r=o/n,c=this.getPosition(r),a=E(t,c);a<s&&(s=a)}return s}getDisToPos2(t){const[n,s]=this.SPoint,[o,r]=this.CPoint1,[c,a]=this.EPoint,[l,u]=t,h=[[-(n-2*o+c),-2*(o-n),l-n],[-(s-2*r+a),-2*(r-s),u-s]],p=[[2*(n-2*o+c),2*(o-n)],[2*(s-2*r+a),2*(r-s)]],f=new Array(4).fill(0);for(let C=0;C<2;C++)for(let M=0;M<2;M++)for(let S=0;S<3;S++)f[M+S]+=p[C][M]*h[C][S]+p[C][M]*h[C][S];const d=[..._(f).filter(C=>C*(C-1)<0),0,1];let x=1/0;for(let C of d){const M=this.getPosition(C),S=E(t,M);S<x&&(x=S)}return x}getDerivative(t){const n=2*(1-t)*(this.CPoint1[0]-this.SPoint[0])+2*t*(this.EPoint[0]-this.CPoint1[0]),s=2*(1-t)*(this.CPoint1[1]-this.SPoint[1])+2*t*(this.EPoint[1]-this.CPoint1[1]);return m(n,s)}getSecondDerivative(t){const n=2*(this.EPoint[0]-2*this.CPoint1[0]+this.SPoint[0]),s=2*(this.EPoint[1]-2*this.CPoint1[1]+this.SPoint[1]);return m(n,s)}getCurvature(t){const[n,s]=this.getDerivative(t),[o,r]=this.getSecondDerivative(t),c=n*r-s*o;if(Math.abs(c)<1e-20)return 0;const a=n**2+s**2;return a<1e-20?1/0:c/a**1.5}getCusps(t=20){const n=new Array(t+1);for(let o=0;o<=t;o++){const r=o/t,c=this.getCurvature(r);n[o]=c}const s=[];for(let o=1;o<t;o++)(n[o]-n[o-1])*(n[o]-n[o+1])>0&&s.push(o/t);return n[0]*(n[0]-n[1])>0&&s.unshift(0),n[t]*(n[t]-n[t-1])>0&&s.push(1),s}applyFn(t){t(this.SPoint),t(this.EPoint),t(this.CPoint1)}applyFFDFn(t){this.applyFn(t);const n=m(this.CPoint1[0]-.5*(this.SPoint[0]+this.EPoint[0]),this.CPoint1[1]-.5*(this.SPoint[1]+this.EPoint[1]));ht(this.CPoint1,this.CPoint1,n)}splitAt(t){const n=this.SPoint,s=this.EPoint,o=this.CPoint1,r=D(y(),n,o,t),c=D(y(),o,s,t),a=D(y(),r,c,t),l=new k(n,r,a),u=new k(V(a),c,s);return[l,u]}splitAtArray(t){return super.splitAtArray.call(this,t)}pathOffset(t){const s=[0,.5,1].map(c=>{const a=this.getPosition(c),l=this.getNormal(c);return it(y(),a,l,t)}),o=D(y(),s[0],s[2],.5),r=D(o,o,s[1],2);return new k(s[0],r,s[2])}splitByCoord(t){const n=this.getSplitT(t);return this.splitAtArray(n)}toPathString(t=0){return`Q ${q(this.CPoint1,t)} ${q(this.EPoint,t)}`}toDebugPathString(t){return`L ${q(this.CPoint1,t)}L ${q(this.EPoint,t)}`}toPoints(t=10){const n=new Array(t),s=1/t;for(let o=1;o<=t;o++){const r=this.getPosition(o*s);n[o-1]=r}return n.reverse()}clone(){return new k(V(this.SPoint),V(this.CPoint1),V(this.EPoint))}}function Fn(i){const e=i.SPoint,t=i.EPoint,n=m((e[0]+t[0])/2,(e[1]+t[1])/2);return new k(e,n,t)}const Ot="curve-bezier";class F extends k{constructor(t,n,s,o){super(t,n,o);v(this,"_CPoint2",y());this.type=Ot,this.CPoint2=s;let r=A(y(),n,t);this.inDir=N(r,r),r=A(y(),o,s),this.outDir=N(r,r)}set CPoint2(t){this._isDirty||(this._isDirty=!ot(this._CPoint2,t)),this._CPoint2=t}get CPoint2(){return this._CPoint2}_getBBox2(){const[t,n]=this.SPoint,[s,o]=this.CPoint1,[r,c]=this.CPoint2,[a,l]=this.EPoint,u=[-3*t+9*s-9*r+3*a,6*t-12*s+6*r,3*s-3*t],h=[-3*n+9*o-9*c+3*l,6*n-12*o+6*c,3*o-3*n],p=_(u),f=_(h),g=p.filter(b=>b>0&&b<1).concat([0,1]),d=f.filter(b=>b>0&&b<1).concat([0,1]),x=g.map(b=>this.getPosition(b)[0]),C=d.map(b=>this.getPosition(b)[1]),M=Math.min(...x),S=Math.max(...x),w=Math.min(...C),T=Math.max(...C);return{xMin:M,xMax:S,yMin:w,yMax:T}}getSplitT(t){const{x:n,y:s,width:o,height:r}=this.bbox,{mode:c,val:a}=t,l=c==="y"?1:0;if(a<[n,s][l]||a>[n+o,s+r][l])return[];{const u=[-this.SPoint[l]+3*this.CPoint1[l]-3*this.CPoint2[l]+this.EPoint[l],3*this.SPoint[l]-6*this.CPoint1[l]+3*this.CPoint2[l],-3*this.SPoint[l]+3*this.CPoint1[l],this.SPoint[l]-a],h=_(u),p=1e-8;return h.filter(f=>f>p&&f<1-p)}}getPosition(t){let n=(1-t)**3,s=3*t*(1-t)*(1-t),o=3*t*t*(1-t),r=t**3,c=n*this.SPoint[0]+s*this.CPoint1[0]+o*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+s*this.CPoint1[1]+o*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}getTangent(t){const n=this.getDerivative(t);return N(n,n)}getNormal(t){const[n,s]=this.getTangent(t);return m(s,-n)}getDisToPos2(t){return console.error("bezier has no analytical solution for getDisToPos2"),this.getDisToPos(t)}getDerivative(t){let n=-3*(1-t)**2,s=3*(1-4*t+3*t**2),o=3*(2*t-3*t**2),r=3*t**2,c=n*this.SPoint[0]+s*this.CPoint1[0]+o*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+s*this.CPoint1[1]+o*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}getSecondDerivative(t){let n=6*(1-t),s=6*(3*t-2),o=6*(1-3*t),r=6*t,c=n*this.SPoint[0]+s*this.CPoint1[0]+o*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+s*this.CPoint1[1]+o*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}applyFn(t){t(this.SPoint),t(this.EPoint),t(this.CPoint1),t(this.CPoint2)}applyFFDFn(t){const{SPoint:n,EPoint:s}=this,o=[.4,.6],r=o.map(T=>{const b=this.getPosition(T);return t(b),b});t(n),t(s);const c=(T,b)=>{const Z=(1-T)**3,J=3*T*(1-T)**2,K=3*T**2*(1-T),R=T**3;return[J,K,b[0]-R*s[0]-Z*n[0],b[1]-R*s[1]-Z*n[1]]},[a,l,u,h]=c(o[0],r[0]),[p,f,g,d]=c(o[1],r[1]),x=1/(l*p-a*f),C=(l*g-f*u)*x,M=(l*d-f*h)*x,S=(p*u-a*g)*x,w=(p*h-a*d)*x;this.CPoint1=m(C,M),this.CPoint2=m(S,w)}reverse(){[this.CPoint1,this.CPoint2]=[this.CPoint2,this.CPoint1],super.reverse()}getLineIntersects(t){const{xMin:n,xMax:s,yMin:o,yMax:r}=this.bbox2,{SPoint:c,EPoint:a}=t,l=[m(n,o),m(s,o),m(s,r),m(n,r)];let u=0;for(const z of l)u+=nt(A(y(),a,c),A(y(),z,c))>0?1:0;if(u===0||u===4)return[];const h=[],[p,f]=this.SPoint,[g,d]=this.CPoint1,[x,C]=this.CPoint2,[M,S]=this.EPoint,[w,T]=t.SPoint,b=-p+3*g-3*x+M,Z=-f+3*d-3*C+S,J=3*p-6*g+3*x,K=3*f-6*d+3*C,R=-3*p+3*g,Y=-3*f+3*d,lt=p,ut=f,[X,G]=A(y(),t.EPoint,t.SPoint),I=X*Z-G*b,St=X*K-G*J,wt=X*Y-G*R,Xn=X*ut-G*lt-(X*T-G*w),Gn=_([I,St,wt,Xn]);for(const z of Gn)if(z>=0&&z<=1){const Hn=b*z**3+J*z**2+R*z+lt,Un=Z*z**3+K*z**2+Y*z+ut;h.push(m(Hn,Un))}return h}splitAt(t){const n=this.SPoint,s=this.EPoint,o=this.CPoint1,r=this.CPoint2,c=D(y(),n,o,t),a=D(y(),o,r,t),l=D(y(),r,s,t),u=D(y(),c,a,t),h=D(y(),a,l,t),p=this.getPosition(t),f=new F(n,c,u,p),g=new F(V(p),h,l,s);return[f,g]}splitAtArray(t){return super.splitAtArray.call(this,t)}splitByCoord(t){const n=this.getSplitT(t);return this.splitAtArray(n)}toPathString(t=0){return`C ${q(this.CPoint1,t)} ${q(this.CPoint2,t)} ${q(this.EPoint,t)}`}toDebugPathString(t){return` L ${q(this.CPoint1,t)} L ${q(this.CPoint2,t)} L ${q(this.EPoint,t)}`}clone(){return new F(V(this.SPoint),V(this.CPoint1),V(this.CPoint2),V(this.EPoint))}}function Zt(i){if(i instanceof F)return i;if(i instanceof L)return Yt(i);if(i instanceof k)return Xt(i);throw new Error("Unsupported curve type.")}function Yt(i){const{SPoint:e,EPoint:t}=i,n=D(y(),e,t,1/3),s=D(y(),e,t,2/3);return new F(e,n,s,t)}function Xt(i){const{SPoint:e,CPoint1:t,EPoint:n}=i,s=D(y(),e,t,2/3),o=D(y(),n,t,2/3);return new F(e,s,o,n)}class Gt{constructor(e){v(this,"curves",[]);v(this,"points",[]);v(this,"_isClockwise");v(this,"_len");v(this,"_lenArr",[]);v(this,"_bbox2");this.curves=e,this.initPoints()}initPoints(){const{curves:e}=this,{length:t}=e;if(t!==0){this.points=new Array(t+1),this.points[0]=e[0].SPoint;for(let n=0;n<t;n++)this.points[n+1]=e[n].EPoint}}get isClockwise(){return this._isClockwise===void 0&&(this._isClockwise=this.getIsClockwise()),this._isClockwise}get isClosed(){return this.curves.length>0&&H(this.SPoint,this.EPoint)<.01}get bbox2(){return this._bbox2||(this._bbox2=this.getBBox2()),this._bbox2}get len(){return this._len||(this._len=this._getLen()),this._len}get SPoint(){return this.curves[0].SPoint}get EPoint(){return this.curves[this.curves.length-1].EPoint}get inDir(){return this.curves[0].inDir}get outDir(){return this.curves[this.curves.length-1].outDir}getMaxCurvature(){let e=0;for(const t of this.curves){const n=t.getMaxCurvature();e=Math.sign(n)*Math.max(e,Math.abs(n))}return e}getIsClockwise(){const{points:e}=this;return U(e)>0}_getLen(){this._lenArr=this.curves.map(t=>t.len);const{length:e}=this.curves;for(let t=1;t<e;t++)this._lenArr[t]+=this._lenArr[t-1];return this._lenArr[e-1]}getBBox2(e=B()){for(const{bbox2:t}of this.curves)O(e,t);return e}getLineIntersects(e){const{curves:t}=this,{length:n}=t,s=new Array(n);for(let o=0;o<n;o++){const c=t[o].getLineIntersects(e);s[o]=c}return s.flat()}getPosDataByPer(e){const{len:t}=this;this.isClosed&&(e=(e+1)%1);const n=e*t;if(e<=0){const u=this.curves[0],h=e*n/this.curves[0].len;return u.getPosDataByPer(h)}if(e>=1){const u=this.curves[this.curves.length-1],h=(e-1)*n/u.len+1;return u.getPosDataByPer(h)}let s=0,o=this._lenArr.length-1,r;for(;s<o;)r=Math.floor((s+o)/2),this._lenArr[r]<n?s=r+1:o=r;const c=this.curves[s],a=s===0?0:this._lenArr[s-1],l=(n-a)/c.len;return c.getPosDataByPer(l)}applyFn(e){for(const t of this.curves)t.applyFn(e)}splitByCoord(e){const t=[];for(const n of this.curves){const s=n.splitByCoord(e);t.push(...s)}return this.curves=t,this.curves}divideAtByNum(e=100){const t=new Array(e-1);for(let o=1;o<e;o++)t[o-1]=o/e;const{length:n}=this.curves,s=new Array(n*e);for(let o=0;o<n;o++){const c=this.curves[o].splitAtArray(t);s.splice(o*e,e,...c)}this.curves=s}reverse(){this.curves.reverse();for(const e of this.curves)e.reverse();this.points.reverse(),this._isClockwise=!this._isClockwise,this._len=this._getLen()}toPathString(e=0){let t=this.curves[0].SPoint,n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `,s=t;for(const r of this.curves){if(!(E(s,r.SPoint)<1)){const{SPoint:a}=r;n+=`M ${q(a)} `,t=a}n+=r.toPathString(e)+" ",s=r.EPoint}return E(s,t)<1&&(n+="Z"),n}toPoints(e=100){let t=new Array(e+1);for(let n=0;n<=e;n++){const s=n/e,{pos:o}=this.getPosDataByPer(s);t[n]=o}return t}}class Q extends Gt{constructor(t){super(t);v(this,"currentPos",y())}moveTo(t,n){this.currentPos=m(t,n)}lineTo(t,n){const s=new L(this.currentPos,m(t,n));this.curves.push(s),this.currentPos=m(t,n)}bezierCurveTo(t,n,s,o,r,c){const a=new F(this.currentPos,m(t,n),m(s,o),m(r,c));this.curves.push(a),this.currentPos=m(r,c)}quadraticCurveTo(t,n,s,o){const r=new k(this.currentPos,m(t,n),m(s,o));this.curves.push(r),this.currentPos=m(s,o)}closePath(){const t=this.curves[0].SPoint;if(Dt(this.currentPos,t))return;const n=new L(this.currentPos,this.curves[0].SPoint);this.curves.push(n)}static fromCommands(t){const n=new Q([]);let s=0;for(let o=0;o<t.length;o++){const r=t[o],{type:c,args:a=[]}=r,l=a.length,{x:u=a[l-2],y:h=a[l-1],x1:p=a[0],y1:f=a[1],x2:g=a[2],y2:d=a[3]}=r;switch(c){case"M":n.moveTo(u,h),s++,s>1&&console.error("SimpleShape can only have one start point");break;case"L":Dt(n.currentPos,m(u,h))||n.lineTo(u,h);break;case"H":n.lineTo(u,n.currentPos[1]);break;case"V":n.lineTo(n.currentPos[0],h);break;case"C":n.bezierCurveTo(p,f,g,d,u,h);break;case"Q":n.quadraticCurveTo(p,f,u,h);break;case"Z":n.closePath();break}}return n}static fromPathString(t){const n=ct(t);return Q.fromCommands(n)}}class Ht extends Q{constructor(t){super(t);v(this,"curves");this.curves=t}}function Rn(i){const e=i.curves.map(t=>Zt(t));return new Ht(e)}class j extends Q{constructor(e){super(e),this.curves=e;const{EPoint:t,SPoint:n}=this;E(t,n)>.1&&console.error("ClosedShape must be closed"),this.initPoints()}include(e){return Ut(e,this.bbox2)?At(e,this.points):!1}intersect(e){let t=!1;for(let n=0;n<this.curves.length;n++){const s=this.curves[n],o=new L(s.SPoint,s.EPoint);if(yt(o,e)){t=!0;break}}return t}static fromCommands(e){const{length:t}=e;(e[0].type!=="M"||e[t-1].type!=="Z")&&console.error("ClosedShape must start with M and end with Z");const n=super.fromCommands(e);return new j(n.curves)}static fromPathString(e){const t=ct(e);return j.fromCommands(t)}getArea(){return Math.abs(this.getSignArea())}getSignArea(){return U(this.points)}}function Ut(i,e){const{xMin:t,xMax:n,yMin:s,yMax:o}=e;return i[0]>=t&&i[0]<=n&&i[1]>=s&&i[1]<=o}function Wt(i){let e=i[0];for(let n=1;n<i.length;n++){const s=i[n],{bbox2:o}=s;o.xMin<e.bbox2.xMin&&(e=s)}e.isClockwise||i.forEach(n=>{n.reverse()});const t=[];for(let n=0;n<i.length;n++){const s=i[n],{isClockwise:o}=s;o&&t.push([s])}for(let n=0;n<i.length;n++){const s=i[n],{bbox2:o,isClockwise:r}=s;if(!r){const c=t.find(a=>{if(!a[0])return!1;const l=a[0].bbox2;return Et(l,o)});c?c.push(s):console.warn("can't find the path for shape:",s)}}return t}function Jt(i,e){const t=A(y(),e.SPoint,i.EPoint);let n;const s=nt(i.outDir,t)*nt(t,e.inDir)>0,o=st(cn(i.outDir,e.inDir));if(o>=10&&o<=60)if(s)n=dt(i,e);else{const r=i.EPoint,c=it(y(),i.EPoint,i.outDir,1),a=it(y(),e.SPoint,e.inDir,-1),l=e.SPoint;n=new F(r,c,a,l)}else n=new L(i.EPoint,e.SPoint);return n}function dt(i,e){const t=i.EPoint,n=ht(y(),i.EPoint,i.outDir),s=ht(y(),e.SPoint,e.inDir),o=e.SPoint,r=gt(t,n,s,o);return new k(i.EPoint,r,e.SPoint)}function zn(i,e){const t=A(y(),e.SPoint,i.EPoint),n=an(t);let s=i.curves;if(!(n<1)){const c=Jt(i,e);s.push(c)}return i===e||e.points.every((c,a)=>H(c,i.points[a])<1)||(s=s.concat(e.curves)),new Q(s)}function Nn(i,e,t=20,n=!0){const[s,o]=[i,e].map(p=>{const{len:f}=p,g=Math.ceil(f/t);return g||console.error("the count of points is 0"),p.toPoints(g)}),{length:r}=s,{length:c}=o,a={indexes:new Int16Array(0),min:1/0,max:1/0,mean:1/0,std:1/0};if(n){if(!(i.isClosed||e.isClosed)){const d=new L(i.EPoint,e.SPoint),x=new L(e.EPoint,i.SPoint);if(yt(d,x))return[a,a]}const f=[...s,...o];if(!(U(f)>0))return[a,a]}const l=[new Int16Array(r),new Int16Array(c)],u=[new Float32Array(r).fill(1/0),new Float32Array(c).fill(1/0)];for(let p=0;p<r;p++)for(let f=0;f<c;f++){const g=H(s[p],o[f]);g<u[0][p]&&(u[0][p]=g,l[0][p]=f),g<u[1][f]&&(u[1][f]=g,l[1][f]=p)}return u.map((p,f)=>{const g=Math.min(...p),d=Math.max(...p),x=p.reduce((M,S)=>M+S,0)/p.length,C=Math.sqrt(p.map(M=>Math.pow(M-x,2)).reduce((M,S)=>M+S,0)/p.length);return{indexes:l[f],min:g,max:d,mean:x,std:C}})}const $n=(i,e,t,n,s=20)=>{let o=m(t+i,n),r=m(0,1);const c=Math.PI*2/s,a=[];for(let u=1;u<=s;u++){const h=u*c,p=t+i*Math.cos(h),f=n+e*Math.sin(h),g=m(p,f),d=m(-Math.sin(h)*i,Math.cos(h)*e),x=dt({EPoint:o,outDir:r},{SPoint:g,inDir:d});a.push(x),o=g,r=d}return new j(a)};class mt extends j{constructor(e){super(e)}static fromPoints(e){let t=[];for(let n=0;n<=e.length;n++)t.push(new L(e[n],e[(n+1)%e.length]));return new mt(t)}getCentroid(){let e=this.getSignArea(),t=0,n=0;for(let s=0;s<this.points.length;s++){let[o,r]=this.points[s],[c,a]=this.points[(s+1)%this.points.length];t+=(o+c)*(o*a-c*r),n+=(r+a)*(o*a-c*r)}return[t/6/e,n/6/e]}includePolygon(e){const{xMin:t,xMax:n,yMin:s,yMax:o}=this.bbox2;if(e.bbox2.xMin<t||e.bbox2.xMax>n||e.bbox2.yMin<s||e.bbox2.yMax>o)return!1;for(let r of e.points)if(!this.include(r))return!1;return!0}intersectPolygon(e){for(let t of e.points)if(this.include(t))return!0;return!1}}class xt extends Q{constructor(t,n){super(t);v(this,"curves");v(this,"tanArr",[]);if(this.curves=t,n)this.tanArr=n;else{const{length:s}=t,o=new Array(s+1);for(let r=0;r<s;r++)o[r]=t[r].inDir;o[s]=t[s-1].outDir,this.tanArr=o}}static fromPoints(t,n){let s=[];for(let o=0;o<t.length-1;o++)s.push(new L(t[o],t[o+1]));return new xt(s,n)}getDistance(t){let n=1/0;for(let s of this.points)n=Math.min(n,H(s,t));return n}getClosestPoint(t){let n=1/0,s=y();for(let o of this.points){let r=H(o,t);r<n&&(n=r,s=o)}return s}getMaxDeflection(){let t=0;for(let n=0;n<this.curves.length;n++){const s=this.tanArr[n],o=H(y(),s);t=Math.max(t,o)}return t}getPosDataByPer(t){const{isClosed:n,len:s,curves:o}=this;n&&(t=(t+1)%1);const r=t*s;if(t<=0){const f=o[0],g=t*r/o[0].len;return f.getPosDataByPer(g)}if(t>=1){const f=o[o.length-1],g=(t-1)*r/f.len+1;return f.getPosDataByPer(g)}let c=0,a=this._lenArr.length-1,l;for(;c<a;)l=Math.floor((c+a)/2),this._lenArr[l]<r?c=l+1:a=l;const u=o[c],h=c===0?0:this._lenArr[c-1],p=(r-h)/u.len;return u.getPosDataByPer(p)}}function Qn(i){const{points:e}=i,t=e.length;for(let n=0;n<t;n++){const s=e[n],o=e[(n+1)%t];for(let r=n+2;r<t;r++){const c=e[r],a=e[(r+1)%t];if(gt(s,o,c,a))return!0}}return!1}function jn(i){const{points:e,bbox2:t}=i,n=Math.min(e.length,5),s=e.slice(-n),o=s.map(([u])=>u),r=s.map(([,u])=>u),{k:c,b:a,R2:l}=Lt(o,r);return{k:c,b:a,R2:l}}class W{constructor(e,t="NONZERO"){this.shapes=e,this.windingRule=t}static fromCommands(e){const t=[];let n=[];for(const o of e)o.type==="M"?(n.length>0&&t.push(n),n=[o]):n.push(o);n.length>0&&t.push(n);const s=t.map(o=>j.fromCommands(o));return new W(s)}static fromPathString(e){const t=ct(e);return W.fromCommands(t)}getBBox2(e=B()){for(const t of this.shapes)t.getBBox2(e);return e}include(e){let t=!0;for(const n of this.shapes){const{isClockwise:s}=n,o=n.include(e);if(t&&(t=s?o:!o),!t)return!1}return!0}intersect(e){return this.shapes.some(t=>t.intersect(e))}applyFn(e){for(const t of this.shapes)t.applyFn(e)}applyFFDFn(e){for(const t of this.shapes)for(const n of t.curves)n.applyFFDFn(e)}intersectLine(e){let t=[];for(const n of this.shapes)t=t.concat(n.getLineIntersects(e));return t}splitByBBox(){const e=Wt(this.shapes),t=[];for(const n of e)n.length>0&&t.push(new W(n));return t}splitByCoord(e){for(const t of this.shapes)t.splitByCoord(e)}toPathString(e=0){let t="";for(const n of this.shapes)t+=n.toPathString(e)+" ";return t=t.slice(0,-1),t}toPoints(e){let t=[];for(const n of this.shapes)t=t.concat(n.toPoints(e));return t}clone(){const e=this.shapes.map(t=>{const n=t.curves.map(s=>s.clone());return new j(n)});return new W(e,this.windingRule)}}const On=[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800],Ct=i=>On[i],Zn=(i,e)=>Ct(i)/(Ct(e)*Ct(i-e)),Kt=(i,e,t)=>Zn(e,i)*t**i*(1-t)**(e-i),tn=(i,e=0,t=1)=>Math.min(Math.max(i,e),t);function Yn(i,e,t=!0){return t?n=>{const[s,o]=n,r=e.length-1,c=e[0].length-1;let a=(s-i.x)/i.width,l=(o-i.y)/i.height,u=0,h=y();for(let p=0;p<=r;p++){const f=Kt(p,r,a);for(let g=0;g<=c;g++){const d=Kt(g,c,l),x=f*d;u+=x,it(h,h,e[p][g],x)}}sn(h,h,1/u),en(n,h)}:n=>{const[s,o]=n,r=e.length-1,c=e[0].length-1;let a=tn((s-i.x)/i.width),l=tn((o-i.y)/i.height);a=a*r,l=l*c;const u=Math.floor(a),h=Math.floor(l);a=a-u,l=l-h;const p=e[u][h],f=e[u+1][h],g=e[u][h+1],d=e[u+1][h+1],x=(1-a)*(1-l)*p[0]+a*(1-l)*f[0]+(1-a)*l*g[0]+a*l*d[0],C=(1-a)*(1-l)*p[1]+a*(1-l)*f[1]+(1-a)*l*g[1]+a*l*d[1];return n[0]=x,n[1]=C,n}}class vt{constructor(e){v(this,"value");v(this,"next",null);this.value=e}}class Mt{constructor(){v(this,"head",null);v(this,"tail",null);v(this,"size",0)}static fromArray(e){const t=new Mt;return e.forEach(n=>t.append(n)),t}toArray(){let e=this.head;const t=[];for(;e;)t.push(e.value),e=e.next;return t}append(e){const t=new vt(e);this.tail&&(this.tail.next=t),this.tail=t,this.head||(this.head=t),this.size++}prepend(e){const t=new vt(e);this.head&&(t.next=this.head),this.head=t,this.tail||(this.tail=t),this.size++}delete(e){var n;if(!this.head)return;for(;this.head&&this.head.value===e;)this.head=this.head.next,this.size--;let t=this.head;for(;t&&t.next;)t.next.value===e?(t.next=t.next.next,this.size--):t=t.next;((n=this.tail)==null?void 0:n.value)===e&&(this.tail=t)}find(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}return null}toString(){let e=this.head;const t=[];for(;e;)t.push(e.value),e=e.next;return t.join(" -> ")}getSize(){return this.size}clear(){this.head=null,this.tail=null,this.size=0}}P.BezierCurve=F,P.BezierCurveType=Ot,P.BezierShape=Ht,P.ClosedShape=j,P.Curve=_t,P.LineCurve=L,P.LineCurveType=Qt,P.LineToQuadratic=Fn,P.LinkedList=Mt,P.Node=vt,P.Path=W,P.Polygon=mt,P.Polyline=xt,P.QuadraticCurve=k,P.QuadraticCurveType=jt,P.Shape=Gt,P.SingleShape=Q,P.arrEquals=En,P.calDisData=Nn,P.calExtendCurve=jn,P.calPointsArea=U,P.calRadius=hn,P.checkLineCurveIntersect=yt,P.connectShape=zn,P.copyMatrix=dn,P.createBBox2=B,P.createMatrix=yn,P.createSvgByPath=Tn,P.cross=nt,P.gaussElimination=gn,P.getBBox2Size=nn,P.getBSpline=kt,P.getBezierCurvesBBox=zt,P.getBezierFromCurve=Zt,P.getBezierShapeFormSingleShape=Rn,P.getConnectCurve=Jt,P.getCurvature=wn,P.getCurveAngle=An,P.getCurvesByPolygon=$t,P.getDebugPathStr=In,P.getDigit=Bn,P.getEaseElasticInOut=Dn,P.getEaseElasticOut=bn,P.getEllipse=$n,P.getPathStr=qt,P.getPolygon=Rt,P.getQuadraticCurve=dt,P.getRadianChange=pt,P.getRandomGenerate=Vt,P.getRandomPathStr=qn,P.getRoots=_,P.getTriangleArea=Mn,P.includeBBox2=Et,P.interpolate=_n,P.interpolatePolygon=Vn,P.isInBBox2=Ut,P.isInLeft=Sn,P.isLineDirClose=kn,P.isPointInPoints=At,P.isSelfIntersect=Qn,P.lineInterSect=gt,P.lineToBezier=Yt,P.linearRegression=Lt,P.max=mn,P.mean=rt,P.median=vn,P.mergeBBox2=O,P.mergeCouple=Ln,P.min=xn,P.pathStringToPathCommands=ct,P.quadraticToBezier=Xt,P.resizeCurvesByBBox=Nt,P.splitByBBox=Wt,P.std=Cn,P.sum=$,P.toAngle=st,P.toRadian=ln,P.transformPoint=Yn,P.variance=Bt,P.vec2ToAngle=un,P.vec2ToStr=q,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}); | ||
(function(P,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(P=typeof globalThis<"u"?globalThis:P||self,B(P.geometry={}))})(this,function(P){"use strict";var Wn=Object.defineProperty;var Jn=(P,B,O)=>B in P?Wn(P,B,{enumerable:!0,configurable:!0,writable:!0,value:O}):P[B]=O;var v=(P,B,O)=>Jn(P,typeof B!="symbol"?B+"":B,O);function B(){return{xMin:1/0,xMax:-1/0,yMin:1/0,yMax:-1/0}}function O(i,e){return i.xMin=Math.min(i.xMin,e.xMin),i.xMax=Math.max(i.xMax,e.xMax),i.yMin=Math.min(i.yMin,e.yMin),i.yMax=Math.max(i.yMax,e.yMax),i}function nn(i){return{width:i.xMax-i.xMin,height:i.yMax-i.yMin}}function Et(i,e){return i.xMin<=e.xMin&&i.xMax>=e.xMax&&i.yMin<=e.yMin&&i.yMax>=e.yMax}var bt=1e-6,et=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var i=0,e=arguments.length;e--;)i+=arguments[e]*arguments[e];return Math.sqrt(i)});function y(){var i=new et(2);return et!=Float32Array&&(i[0]=0,i[1]=0),i}function _(i){var e=new et(2);return e[0]=i[0],e[1]=i[1],e}function m(i,e){var t=new et(2);return t[0]=i,t[1]=e,t}function en(i,e){return i[0]=e[0],i[1]=e[1],i}function ht(i,e,t){return i[0]=e[0]+t[0],i[1]=e[1]+t[1],i}function sn(i,e,t){return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i}function on(i,e,t){return i[0]=e[0]*t,i[1]=e[1]*t,i}function it(i,e,t,n){return i[0]=e[0]+t[0]*n,i[1]=e[1]+t[1]*n,i}function E(i,e){var t=e[0]-i[0],n=e[1]-i[1];return Math.hypot(t,n)}function rn(i){var e=i[0],t=i[1];return Math.hypot(e,t)}function N(i,e){var t=e[0],n=e[1],o=t*t+n*n;return o>0&&(o=1/Math.sqrt(o)),i[0]=e[0]*o,i[1]=e[1]*o,i}function ft(i,e){return i[0]*e[0]+i[1]*e[1]}function D(i,e,t,n){var o=e[0],s=e[1];return i[0]=o+n*(t[0]-o),i[1]=s+n*(t[1]-s),i}function cn(i,e){var t=i[0],n=i[1],o=e[0],s=e[1],r=Math.sqrt(t*t+n*n)*Math.sqrt(o*o+s*s),c=r&&(t*o+n*s)/r;return Math.acos(Math.min(Math.max(c,-1),1))}function st(i,e){return i[0]===e[0]&&i[1]===e[1]}function Dt(i,e){var t=i[0],n=i[1],o=e[0],s=e[1];return Math.abs(t-o)<=bt*Math.max(1,Math.abs(t),Math.abs(o))&&Math.abs(n-s)<=bt*Math.max(1,Math.abs(n),Math.abs(s))}var an=rn,A=sn,H=E;(function(){var i=y();return function(e,t,n,o,s,r){var c,a;for(t||(t=2),n||(n=0),o?a=Math.min(o*t+n,e.length):a=e.length,c=n;c<a;c+=t)i[0]=e[c],i[1]=e[c+1],s(i,i,r),e[c]=i[0],e[c+1]=i[1];return e}})();function ln(i){return i*Math.PI/180}function ot(i){return i*180/Math.PI}function un(i){return ot(Math.atan2(i[1],i[0]))}function hn(i,e,t){const n=E(i,e),o=E(e,t),s=E(t,i),r=(n+o+s)/2,c=4*Math.sqrt(r*(r-n)*(r-o)*(r-s));return Math.abs(c)<1e-20?1/0:n*o*s/4/Math.sqrt(r*(r-n)*(r-o)*(r-s))}const tt=1e-12;function V(i){switch(i.length){case 0:return[];case 1:return[0];case 2:return Math.abs(i[0])<tt?[]:[-i[1]/i[0]];case 3:return Math.abs(i[0])<tt?V(i.slice(1)):fn(i);case 4:return Math.abs(i[0])<tt?V(i.slice(1)):Pn(i);default:throw new Error("Not implemented")}}function fn(i){const e=i[0],t=i[1],n=i[2],o=t*t-4*e*n;if(o<0)return[];{const s=Math.sqrt(o);return[(-t+s)/(2*e),(-t-s)/(2*e)]}}function Pn(i){const e=i[0],t=i[1],n=i[2],o=i[3],s=t/e,r=n/e,c=o/e,a=(3*r-s*s)/9,l=(9*s*r-27*c-2*s*s*s)/54,u=a*a*a+l*l;if(u>=0){const h=Math.sqrt(u),p=Math.cbrt(l+h),f=Math.cbrt(l-h),g=[-s/3+(p+f)];return u===0&&g.push(-p/2),g}else{const h=Math.acos(l/Math.sqrt(-a*a*a)),p=Math.sqrt(-a);return[2*p*Math.cos(h/3)-s/3,2*p*Math.cos((h+2*Math.PI)/3)-s/3,2*p*Math.cos((h+4*Math.PI)/3)-s/3]}}function pn(i,e,t){[i[e],i[t]]=[i[t],i[e]]}function gn(i){const{length:e}=i;for(let n=0;n<e;n++){let o=n;for(let s=n+1;s<e;s++)Math.abs(i[s][n])>Math.abs(i[o][n])&&(o=s);pn(i,n,o);for(let s=n+1;s<e;s++){if(Math.abs(i[n][n])<tt)continue;const r=i[s][n]/i[n][n];for(let c=n;c<e+1;c++)i[s][c]-=r*i[n][c]}}const t=new Array(e).fill(0);for(let n=e-1;n>=0;n--)if(!(Math.abs(i[n][n])<tt)){t[n]=i[n][e]/i[n][n];for(let o=n-1;o>=0;o--)i[o][e]-=i[o][n]*t[n]}return console.log(i),t}function yn(i){return new Array(i).fill(0).map(()=>new Array(i))}function dn(i){return i.map(e=>e.slice())}function mn(i){return Math.max(...i)}function xn(i){return Math.min(...i)}function $(i){return i.reduce((e,t)=>e+t,0)}function rt(i){return $(i)/i.length}function Cn(i){return rt(i),Math.sqrt(Bt(i))}function Bt(i){const e=rt(i);return rt(i.map(t=>Math.pow(t-e,2)))}function vn(i){const e=i.slice().sort((n,o)=>n-o),t=Math.floor(i.length/2);return i.length%2!==0?e[t]:(e[t-1]+e[t])/2}function Lt(i,e){const t=i.length,n=$(i),o=$(e),s=o/t,r=$(i.map((g,d)=>g*e[d])),c=$(i.map(g=>g*g)),a=1e-10;if(t*c-n*n<a)return{k:1/0,b:n/t,R2:1};const l=(t*r-n*o)/(t*c-n*n),u=(o-l*n)/t,h=Math.max(a,$(e.map(g=>Math.pow(g-s,2)))),f=Math.max(a,$(i.map(g=>Math.pow(l*g+u-s,2))))/h;return{k:l,b:u,R2:f}}function Mn(i,e,t){return Math.abs(U([i,e,t]))}function Sn(i,e){let[t,n]=i,[[o,s],[r,c]]=e;return(t-o)*(c-s)-(n-s)*(r-o)>0}function At(i,e){let[t,n]=i,o=!1;for(let s=0,r=e.length-1;s<e.length;r=s++){let[c,a]=e[s],[l,u]=e[r];a>n!=u>n&&t-c<(l-c)*(n-a)/(u-a)&&(o=!o)}return o}function wn(i,e,t){const n=E(i,e),o=E(e,t),s=E(t,i),r=n*o*s;return Math.abs(r)<1e-20?0:U([i,e,t])/(n*o*s)}function U(i){let e=0;const{length:t}=i;for(let n=0;n<t;n++){let[o,s]=i[n],[r,c]=i[(n+1)%t];e+=o*c-r*s}return e/2}function En(i,e){if(i.length!==e.length)return!1;for(let t=0;t<i.length;t++)if(i[t]!==e[t])return!1;return!0}function nt(i,e){return i[0]*e[1]-i[1]*e[0]}const Tt=1103515245,It=12345,Pt=2147483647;function _t(i=.314){let e=(Tt*i+It)%Pt;return()=>(e=(Tt*e+It)%Pt,e/Pt)}function bn(i){return Math.pow(2,-10*i)*Math.sin((i-.2/4)*(2*Math.PI)/.2)+1}function Dn(i){return i<.5?.5*Math.pow(2,20*i-10)*Math.sin((20*i-11.125)*(2*Math.PI)/.9):.5*(2-Math.pow(2,-20*i+10)*Math.sin((20*i-11.125)*(2*Math.PI)/.9))}function Bn(i,e=4){return Math.max(e-Math.floor(Math.log10(i)),0)}function Ln(i){if(i.length<=1)return i;const e=new Map,t=new Map;for(const s of i){if(s.length<2)throw new Error("couple length must be greater than 1");const[r,c]=[s[0],s[s.length-1]];e.set(r,c),t.set(c,r)}const n=[];let o=i.length**2;for(;(e.size||t.size)&&o-- >0;){let s=e.keys().next().value;const r=[s];let c=e.get(s);for(;c!==void 0&&c!==s&&o-- >0;)r.push(c),e.delete(s),t.delete(c),s=c,c=e.get(c);for(s=r[0],c=t.get(s);c!==void 0&&c!==s&&o-- >0;)r.unshift(c),e.delete(c),t.delete(s),s=c,c=t.get(c);n.push(r)}return n}function An(i,e){return ot(pt(i.outDir,e.inDir))}function pt(i,e){const t=i[0]*e[1]-i[1]*e[0],n=i[0]*e[0]+i[1]*e[1];return Math.atan2(t,n)}class Vt{constructor(e,t){v(this,"type","curve");v(this,"_isDirty",!0);v(this,"_SPoint",y());v(this,"_EPoint",y());v(this,"_bbox2");v(this,"_len");v(this,"inDir",y());v(this,"outDir",y());this.SPoint=e,this.EPoint=t,this._isDirty=!1}set SPoint(e){this._isDirty||(this._isDirty=!st(this._SPoint,e)),this._SPoint=e}get SPoint(){return this._SPoint}set EPoint(e){this._isDirty||(this._isDirty=!st(this._EPoint,e)),this._EPoint=e}get EPoint(){return this._EPoint}get bbox(){const{xMin:e,yMin:t,xMax:n,yMax:o}=this.bbox2;return{x:e,y:t,width:n-e,height:o-t}}get bbox2(){return(this._isDirty||!this._bbox2)&&this.update(),this._bbox2}get len(){return(this._isDirty||!this._len&&this._len!==0)&&this.update(),this._len}get deflection(){const{inDir:e,outDir:t}=this;return pt(e,t)}update(){this._bbox2=this._getBBox2(),this._len=this._getLen(),this._isDirty=!1}splitAtArray(e){e.sort((s,r)=>s-r);let t=this;const n=new Array(e.length+1);let o=0;for(let s=0;s<e.length;s++){let r=e[s];r=(r-o)/(1-o),o=e[s];const c=t.splitAt(r);n[s]=c[0],t=c[1]}return n[e.length]=t,n}splitByCoord(e){const t=this.getSplitT(e);return this.splitAtArray(t)}}function Tn(i){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",i),e.appendChild(t),e}function qt(i,e=1){const t=i[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return i.forEach(o=>{n+=o.toPathString(e)+" "}),n+="Z",n}function In(i,e=1){const t=i[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return i.forEach(o=>{n+=o.toDebugPathString(e)+" "}),n}function ct(i){const e=/([MmLlHhVvCcSsQqTtAaZz])|([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/g,t=i.match(e);if(!t)throw new Error("Invalid path string");const n=[];let o=null,s=[];for(const r of t)isNaN(parseFloat(r))?(o&&(n.push({type:o,args:s}),s=[]),o=r):s.push(parseFloat(r));return o&&n.push({type:o,args:s}),n}function _n(i,e,t){const n=[],o=i.length,s=e.length;for(let r=0;r<s;r++){const c=D(y(),i[r%o],e[r],t);n.push(c)}return n}function Vn(i,e,t,n,o){const s=t.length+e,r=2;if(e<1)throw new Error("degree must be at least 1 (linear)");if(e>s-1)throw new Error("degree must be less than or equal to point count - 1");if(o||(o=new Array(s).fill(1)),n){if(n.length!==s+e+1)throw new Error("bad knot vector length")}else{n=[];for(let f=0;f<s+e+1;f++)n[f]=f}const c=[];for(let f=0;f<s;f++){c[f]=[];for(let g=0;g<r;g++)c[f][g]=t[f%(s-e)][g]*o[f];c[f][r]=o[f]}const a=n[e],l=n[s];if(i=i*(l-a)+a,i<a||i>l)throw new Error("out of bbox2");let u;for(u=e;u<s&&!(i>=n[u]&&i<=n[u+1]);u++);let h;for(let f=1;f<=e+1;f++)for(let g=u;g>u-e-1+f;g--){h=(i-n[g])/(n[g+e+1-f]-n[g]);for(let d=0;d<r+1;d++)c[g][d]=(1-h)*c[g-1][d]+h*c[g][d]}console.log("pointDataArr",c);let p=[];for(let f=0;f<r;f++)p[f]=c[u][f]/c[u][r];return m(p[0],p[1])}function kt(i,e){const{length:t}=i;if(e<1)throw new Error("degree must be at least 1 (linear)");if(e>t-1)throw new Error(`degree:${e} must be less than or equal to point count - 1(${t-1})`);const n=new Array(t),o=new Array(t);for(let s=0;s<t;s++)n[s]=i[s][0],o[s]=i[s][1];return s=>{if(s<0||s>1)throw new Error("out of bbox2");s=s*t+e;const r=Ft(n,e,s),c=Ft(o,e,s);return m(r,c)}}function Ft(i,e,t){const{length:n}=i,o=n+e,s=Math.floor(t),r=new Array(o);for(let c=0;c<o;c++)r[c]=i[c%n];for(let c=0;c<e;c++)for(let a=s;a>s-e+c;a--){const l=(t-a)/(e-c);r[a]=l*r[a]+(1-l)*r[a-1]}return r[s]}function Rt(i,e,t,n=0,o=0,s=.1){const r=[],c=i/2,a=e/2,l=_t(s);let u=h=>{const f=l()*n+(1-n);let g=(f*Math.cos(h)+1)*c,d=(f*Math.sin(h)+1)*a;return m(g,d)};for(let h=0;h<t;h++){let p=u(2*Math.PI*(h/t+o));r.push(p)}return r}function zt(i){let e=1/0,t=1/0,n=-1/0,o=-1/0;for(const s of i){const{bbox:r}=s;e=Math.min(e,r.x),t=Math.min(t,r.y),n=Math.max(n,r.x+r.width),o=Math.max(o,r.y+r.height)}return{x:e,y:t,width:n-e,height:o-t}}function Nt(i,e){const t=zt(i),n=e.width/t.width,o=e.height/t.height;for(const s of i)s.applyFn(r=>{r[0]=(r[0]-t.x)*n+e.x,r[1]=(r[1]-t.y)*o+e.y})}function $t(i,e=3){const t=[],o=new Array(100),s=kt(i,Number(e)),r=performance.now();for(let a=0;a<100;a++)o[a]=s(a/100);performance.now()-r;const c=new Array(100);for(let a=0;a<100;a++){const l=m(o[a][0],o[a][1]),u=m(o[(a+1)%100][0],o[(a+1)%100][1]),h=D(y(),l,u,.5);c[a]=h}for(let a=0;a<100;a++){const l=_(c[a]),u=c[(a+1)%100],h=o[(a+1)%100];t.push(new k(l,h,u))}return t}function qn(i=100,e=100,t=6,n=.5,o=Math.random(),s=3){const r=Rt(i,e,t,n,o),c=$t(r,s);return Nt(c,{x:0,y:0,width:i,height:e}),qt(c)}function q(i,e){return`${(0+i[0]).toFixed(e)} ${(0+i[1]).toFixed(e)}`}const Qt="curve-line";class L extends Vt{constructor(t,n){super(t,n);v(this,"tangent");v(this,"normal");this.type=Qt,this.tangent=N(y(),A(y(),n,t)),this.normal=m(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.outDir=this.tangent}update(){super.update(),this.tangent=N(y(),A(y(),this.EPoint,this.SPoint)),this.normal=m(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.outDir=this.tangent}_getBBox2(){const{SPoint:t,EPoint:n}=this,[o,s]=t[0]<n[0]?[t[0],n[0]]:[n[0],t[0]],[r,c]=t[1]<n[1]?[t[1],n[1]]:[n[1],t[1]];return{xMin:o,yMin:r,xMax:s,yMax:c}}_getLen(){return E(this.SPoint,this.EPoint)}getNormal(t){return this.normal}getTangent(t){return this.tangent}getCurvature(t){return 0}getMaxCurvature(){return 0}getPosition(t){return D(y(),this.SPoint,this.EPoint,t)}getPosDataByPer(t){const n=this.getPosition(t),o=this.tangent;return{pos:n,tan:o}}getSplitT(t){const{x:n,y:o,width:s,height:r}=this.bbox,{SPoint:c,EPoint:a}=this,{mode:l,val:u}=t,h=[];return l==="x"&&u>=n&&u<=n+s?h.push((u-c[0])/(a[0]-c[0])):l==="y"&&u>=o&&u<=o+r&&h.push((u-c[1])/(a[1]-c[1])),h}getLineIntersects(t){const[n,o]=this.SPoint,[s,r]=this.EPoint,[c,a]=t.SPoint,[l,u]=t.EPoint,h=[],p=(n-s)*(a-u)-(o-r)*(c-l);if(Math.abs(p)>1e-10){const f=n*r-o*s,g=c*u-a*l,d=(f*(c-l)-g*(n-s))/p,x=(f*(a-u)-g*(o-r))/p,{xMin:C,yMin:M,xMax:S,yMax:w}=this.bbox2;d>=C&&d<=S&&x>=M&&x<=w&&h.push(m(d,x))}return h}getDisToPos(t){const{SPoint:n,EPoint:o,tangent:s}=this,r=A(y(),t,n),c=ft(r,s);if(c<0)return E(n,t);const a=E(n,o);if(c>a)return E(o,t);const l=m(-s[1],s[0]);return Math.abs(ft(l,r))}applyFn(t){t(this.SPoint),t(this.EPoint),this._isDirty=!0}applyFFDFn(t){this.applyFn(t)}reverse(){[this.SPoint,this.EPoint]=[this.EPoint,this.SPoint],this.update()}splitAt(t){const{SPoint:n,EPoint:o}=this,s=this.getPosition(t);return[new L(n,s),new L(_(s),o)]}isPointOnCurve(t){const{SPoint:n,EPoint:o}=this,s=E(n,t),r=E(o,t),c=E(n,o);return Math.abs(s+r-c)<1e-10}toPathString(t=0){return`L ${q(this.EPoint,t)}`}toDebugPathString(t){return this.toPathString(t)}clone(){return new L(_(this.SPoint),_(this.EPoint))}}function kn(i,e){return ft(i.tangent,e.tangent)>.982}function gt(i,e,t,n){const[o,s]=i,[r,c]=e,[a,l]=t,[u,h]=n,p=c-s,f=o-r,g=r*s-o*c,d=h-l,x=a-u,C=u*l-a*h,M=p*x-d*f,S=(f*C-x*g)/M,w=(d*g-p*C)/M;return m(S,w)}function yt(i,e){const[t,n]=i.SPoint,[o,s]=i.EPoint,[r,c]=e.SPoint,[a,l]=e.EPoint,u=(t-r)*(l-c)-(n-c)*(a-r),h=(o-r)*(l-c)-(s-c)*(a-r),p=(r-t)*(s-n)-(c-n)*(o-t),f=(a-t)*(s-n)-(l-n)*(o-t);return u*h<0&&p*f<0}const at=100,jt="curve-quadratic";class k extends L{constructor(t,n,o){super(t,o);v(this,"_CPoint1",y());v(this,"_lenArr",new Array(at).fill(0));this.type=jt,this.CPoint1=n;let s=A(y(),n,t);this.inDir=N(s,s),s=A(y(),o,n),this.outDir=N(s,s)}set CPoint1(t){this._isDirty||(this._isDirty=!st(this._CPoint1,t)),this._CPoint1=t}get CPoint1(){return this._CPoint1}update(){super.update(),this.inDir=this.getTangent(0),this.outDir=this.getTangent(1)}_getBBox2(){const[t,n]=this.SPoint,[o,s]=this.CPoint1,[r,c]=this.EPoint,a=[2*(t-2*o+r),2*(o-r)],l=[2*(n-2*s+c),2*(s-c)],u=V(a),h=V(l),p=u.filter(w=>w>0&&w<1).concat([0,1]),f=h.filter(w=>w>0&&w<1).concat([0,1]),g=p.map(w=>this.getPosition(w)[0]),d=f.map(w=>this.getPosition(w)[1]),x=Math.min(...g),C=Math.max(...g),M=Math.min(...d),S=Math.max(...d);return{xMin:x,xMax:C,yMin:M,yMax:S}}_getLen(){let t=0,n=this.getPosition(0);for(let o=1;o<=at;o++){let s=this.getPosition(o/100);t+=E(n,s),n=s,this._lenArr[o-1]=t}return t}getPosition(t){const n=(1-t)**2,o=2*t*(1-t),s=t**2,r=n*this.SPoint[0]+o*this.CPoint1[0]+s*this.EPoint[0],c=n*this.SPoint[1]+o*this.CPoint1[1]+s*this.EPoint[1];return m(r,c)}getPosDataByPer(t){let n=0,o=this._lenArr.length-1,s;const r=this.len*t;for(;n<o;)s=Math.floor((n+o)/2),this._lenArr[s]<r?n=s+1:o=s;const c=this._lenArr[n-1]||0;let a=n/at;a+=(r-c)/(this._lenArr[n]-c)/at;const l=this.getPosition(a),u=this.getTangent(a);return{pos:l,tan:u}}getTangent(t){const n=this.getDerivative(t);return N(n,n)}getNormal(t){const[n,o]=this.getTangent(t);return m(o,-n)}getMaxCurvature(){const t=this.getCusps();let n=0;for(const o of t){const s=this.getCurvature(o);Math.abs(s)>Math.abs(n)&&(n=s)}return n}getSplitT(t){const{x:n,y:o,width:s,height:r}=this.bbox,{mode:c,val:a}=t;if(c==="x"){if(a>=n&&a<=n+s){const l=[this.SPoint[0]-2*this.CPoint1[0]+this.EPoint[0],2*(this.CPoint1[0]-this.EPoint[0]),this.EPoint[0]-a];return V(l).filter(h=>h>0&&h<1)}}else if(a>=o&&a<=o+r){const l=[this.SPoint[1]-2*this.CPoint1[1]+this.EPoint[1],2*(this.CPoint1[1]-this.EPoint[1]),this.EPoint[1]-a];return V(l).filter(h=>h>0&&h<1)}return[]}getLineIntersects(t){const{xMin:n,xMax:o,yMin:s,yMax:r}=this.bbox2,{SPoint:c,EPoint:a}=t,l=[m(n,s),m(o,s),m(o,r),m(n,r)];let u=0;for(const I of l)u+=nt(t.tangent,A(y(),I,c))>0?1:0;if(u===0||u===4)return[];const h=[],[p,f]=this.SPoint,[g,d]=this.CPoint1,[x,C]=this.EPoint,[M,S]=t.SPoint,w=p-2*g+x,T=f-2*d+C,b=2*(g-p),Z=2*(d-f),J=p,K=f,[R,Y]=A(y(),t.EPoint,t.SPoint),lt=R*T-Y*w,ut=R*Z-Y*b,X=R*K-Y*J-R*S+Y*M,G=V([lt,ut,X]);for(const I of G)if(I>=0&&I<=1){const St=(1-I)**2*p+2*I*(1-I)*g+I**2*x,wt=(1-I)**2*f+2*I*(1-I)*d+I**2*C;h.push(m(St,wt))}return h}getDisToPos(t){let n=100,o=1/0;for(let s=0;s<=n;s++){const r=s/n,c=this.getPosition(r),a=E(t,c);a<o&&(o=a)}return o}getDisToPos2(t){const[n,o]=this.SPoint,[s,r]=this.CPoint1,[c,a]=this.EPoint,[l,u]=t,h=[[-(n-2*s+c),-2*(s-n),l-n],[-(o-2*r+a),-2*(r-o),u-o]],p=[[2*(n-2*s+c),2*(s-n)],[2*(o-2*r+a),2*(r-o)]],f=new Array(4).fill(0);for(let C=0;C<2;C++)for(let M=0;M<2;M++)for(let S=0;S<3;S++)f[M+S]+=p[C][M]*h[C][S]+p[C][M]*h[C][S];const d=[...V(f).filter(C=>C*(C-1)<0),0,1];let x=1/0;for(let C of d){const M=this.getPosition(C),S=E(t,M);S<x&&(x=S)}return x}getDerivative(t){const n=2*(1-t)*(this.CPoint1[0]-this.SPoint[0])+2*t*(this.EPoint[0]-this.CPoint1[0]),o=2*(1-t)*(this.CPoint1[1]-this.SPoint[1])+2*t*(this.EPoint[1]-this.CPoint1[1]);return m(n,o)}getSecondDerivative(t){const n=2*(this.EPoint[0]-2*this.CPoint1[0]+this.SPoint[0]),o=2*(this.EPoint[1]-2*this.CPoint1[1]+this.SPoint[1]);return m(n,o)}getCurvature(t){const[n,o]=this.getDerivative(t),[s,r]=this.getSecondDerivative(t),c=n*r-o*s;if(Math.abs(c)<1e-20)return 0;const a=n**2+o**2;return a<1e-20?1/0:c/a**1.5}getCusps(t=20){const n=new Array(t+1);for(let s=0;s<=t;s++){const r=s/t,c=this.getCurvature(r);n[s]=c}const o=[];for(let s=1;s<t;s++)(n[s]-n[s-1])*(n[s]-n[s+1])>0&&o.push(s/t);return n[0]*(n[0]-n[1])>0&&o.unshift(0),n[t]*(n[t]-n[t-1])>0&&o.push(1),o}applyFn(t){t(this.SPoint),t(this.EPoint),t(this.CPoint1),this._isDirty=!0}applyFFDFn(t){this.applyFn(t);const n=m(this.CPoint1[0]-.5*(this.SPoint[0]+this.EPoint[0]),this.CPoint1[1]-.5*(this.SPoint[1]+this.EPoint[1]));ht(this.CPoint1,this.CPoint1,n)}splitAt(t){const n=this.SPoint,o=this.EPoint,s=this.CPoint1,r=D(y(),n,s,t),c=D(y(),s,o,t),a=D(y(),r,c,t),l=new k(n,r,a),u=new k(_(a),c,o);return[l,u]}splitAtArray(t){return super.splitAtArray.call(this,t)}pathOffset(t){const o=[0,.5,1].map(c=>{const a=this.getPosition(c),l=this.getNormal(c);return it(y(),a,l,t)}),s=D(y(),o[0],o[2],.5),r=D(s,s,o[1],2);return new k(o[0],r,o[2])}splitByCoord(t){const n=this.getSplitT(t);return this.splitAtArray(n)}toPathString(t=0){return`Q ${q(this.CPoint1,t)} ${q(this.EPoint,t)}`}toDebugPathString(t){return`L ${q(this.CPoint1,t)}L ${q(this.EPoint,t)}`}toPoints(t=10){const n=new Array(t),o=1/t;for(let s=1;s<=t;s++){const r=this.getPosition(s*o);n[s-1]=r}return n.reverse()}clone(){return new k(_(this.SPoint),_(this.CPoint1),_(this.EPoint))}}function Fn(i){const e=i.SPoint,t=i.EPoint,n=m((e[0]+t[0])/2,(e[1]+t[1])/2);return new k(e,n,t)}const Ot="curve-bezier";class F extends k{constructor(t,n,o,s){super(t,n,s);v(this,"_CPoint2",y());this.type=Ot,this.CPoint2=o;let r=A(y(),n,t);this.inDir=N(r,r),r=A(y(),s,o),this.outDir=N(r,r)}set CPoint2(t){this._isDirty||(this._isDirty=!st(this._CPoint2,t)),this._CPoint2=t}get CPoint2(){return this._CPoint2}_getBBox2(){const[t,n]=this.SPoint,[o,s]=this.CPoint1,[r,c]=this.CPoint2,[a,l]=this.EPoint,u=[-3*t+9*o-9*r+3*a,6*t-12*o+6*r,3*o-3*t],h=[-3*n+9*s-9*c+3*l,6*n-12*s+6*c,3*s-3*n],p=V(u),f=V(h),g=p.filter(b=>b>0&&b<1).concat([0,1]),d=f.filter(b=>b>0&&b<1).concat([0,1]),x=g.map(b=>this.getPosition(b)[0]),C=d.map(b=>this.getPosition(b)[1]),M=Math.min(...x),S=Math.max(...x),w=Math.min(...C),T=Math.max(...C);return{xMin:M,xMax:S,yMin:w,yMax:T}}getSplitT(t){const{x:n,y:o,width:s,height:r}=this.bbox,{mode:c,val:a}=t,l=c==="y"?1:0;if(a<[n,o][l]||a>[n+s,o+r][l])return[];{const u=[-this.SPoint[l]+3*this.CPoint1[l]-3*this.CPoint2[l]+this.EPoint[l],3*this.SPoint[l]-6*this.CPoint1[l]+3*this.CPoint2[l],-3*this.SPoint[l]+3*this.CPoint1[l],this.SPoint[l]-a],h=V(u),p=1e-8;return h.filter(f=>f>p&&f<1-p)}}getPosition(t){let n=(1-t)**3,o=3*t*(1-t)*(1-t),s=3*t*t*(1-t),r=t**3,c=n*this.SPoint[0]+o*this.CPoint1[0]+s*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+o*this.CPoint1[1]+s*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}getTangent(t){const n=this.getDerivative(t);return N(n,n)}getNormal(t){const[n,o]=this.getTangent(t);return m(o,-n)}getDisToPos2(t){return console.error("bezier has no analytical solution for getDisToPos2"),this.getDisToPos(t)}getDerivative(t){let n=-3*(1-t)**2,o=3*(1-4*t+3*t**2),s=3*(2*t-3*t**2),r=3*t**2,c=n*this.SPoint[0]+o*this.CPoint1[0]+s*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+o*this.CPoint1[1]+s*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}getSecondDerivative(t){let n=6*(1-t),o=6*(3*t-2),s=6*(1-3*t),r=6*t,c=n*this.SPoint[0]+o*this.CPoint1[0]+s*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+o*this.CPoint1[1]+s*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}applyFn(t){t(this.SPoint),t(this.EPoint),t(this.CPoint1),t(this.CPoint2)}applyFFDFn(t){const{SPoint:n,EPoint:o}=this,s=[.4,.6],r=s.map(T=>{const b=this.getPosition(T);return t(b),b});t(n),t(o);const c=(T,b)=>{const Z=(1-T)**3,J=3*T*(1-T)**2,K=3*T**2*(1-T),R=T**3;return[J,K,b[0]-R*o[0]-Z*n[0],b[1]-R*o[1]-Z*n[1]]},[a,l,u,h]=c(s[0],r[0]),[p,f,g,d]=c(s[1],r[1]),x=1/(l*p-a*f),C=(l*g-f*u)*x,M=(l*d-f*h)*x,S=(p*u-a*g)*x,w=(p*h-a*d)*x;this.CPoint1=m(C,M),this.CPoint2=m(S,w),this._isDirty=!0}reverse(){[this.CPoint1,this.CPoint2]=[this.CPoint2,this.CPoint1],super.reverse()}getLineIntersects(t){const{xMin:n,xMax:o,yMin:s,yMax:r}=this.bbox2,{SPoint:c,EPoint:a}=t,l=[m(n,s),m(o,s),m(o,r),m(n,r)];let u=0;for(const z of l)u+=nt(A(y(),a,c),A(y(),z,c))>0?1:0;if(u===0||u===4)return[];const h=[],[p,f]=this.SPoint,[g,d]=this.CPoint1,[x,C]=this.CPoint2,[M,S]=this.EPoint,[w,T]=t.SPoint,b=-p+3*g-3*x+M,Z=-f+3*d-3*C+S,J=3*p-6*g+3*x,K=3*f-6*d+3*C,R=-3*p+3*g,Y=-3*f+3*d,lt=p,ut=f,[X,G]=A(y(),t.EPoint,t.SPoint),I=X*Z-G*b,St=X*K-G*J,wt=X*Y-G*R,Xn=X*ut-G*lt-(X*T-G*w),Gn=V([I,St,wt,Xn]);for(const z of Gn)if(z>=0&&z<=1){const Hn=b*z**3+J*z**2+R*z+lt,Un=Z*z**3+K*z**2+Y*z+ut;h.push(m(Hn,Un))}return h}splitAt(t){const n=this.SPoint,o=this.EPoint,s=this.CPoint1,r=this.CPoint2,c=D(y(),n,s,t),a=D(y(),s,r,t),l=D(y(),r,o,t),u=D(y(),c,a,t),h=D(y(),a,l,t),p=this.getPosition(t),f=new F(n,c,u,p),g=new F(_(p),h,l,o);return[f,g]}splitAtArray(t){return super.splitAtArray.call(this,t)}splitByCoord(t){const n=this.getSplitT(t);return this.splitAtArray(n)}toPathString(t=0){return`C ${q(this.CPoint1,t)} ${q(this.CPoint2,t)} ${q(this.EPoint,t)}`}toDebugPathString(t){return` L ${q(this.CPoint1,t)} L ${q(this.CPoint2,t)} L ${q(this.EPoint,t)}`}clone(){return new F(_(this.SPoint),_(this.CPoint1),_(this.CPoint2),_(this.EPoint))}}function Zt(i){if(i instanceof F)return i;if(i instanceof L)return Yt(i);if(i instanceof k)return Xt(i);throw new Error("Unsupported curve type.")}function Yt(i){const{SPoint:e,EPoint:t}=i,n=D(y(),e,t,1/3),o=D(y(),e,t,2/3);return new F(e,n,o,t)}function Xt(i){const{SPoint:e,CPoint1:t,EPoint:n}=i,o=D(y(),e,t,2/3),s=D(y(),n,t,2/3);return new F(e,o,s,n)}class Gt{constructor(e){v(this,"curves",[]);v(this,"points",[]);v(this,"_isClockwise");v(this,"_len");v(this,"_lenArr",[]);v(this,"_bbox2");this.curves=e,this.initPoints()}initPoints(){const{curves:e}=this,{length:t}=e;if(t!==0){this.points=new Array(t+1),this.points[0]=e[0].SPoint;for(let n=0;n<t;n++)this.points[n+1]=e[n].EPoint}}get isClockwise(){return this._isClockwise===void 0&&(this._isClockwise=this.getIsClockwise()),this._isClockwise}get isClosed(){return this.curves.length>0&&H(this.SPoint,this.EPoint)<.01}get bbox2(){return this._bbox2||(this._bbox2=this.getBBox2()),this._bbox2}get len(){return this._len||(this._len=this._getLen()),this._len}get SPoint(){return this.curves[0].SPoint}get EPoint(){return this.curves[this.curves.length-1].EPoint}get inDir(){return this.curves[0].inDir}get outDir(){return this.curves[this.curves.length-1].outDir}getMaxCurvature(){let e=0;for(const t of this.curves){const n=t.getMaxCurvature();e=Math.sign(n)*Math.max(e,Math.abs(n))}return e}getIsClockwise(){const{points:e}=this;return U(e)>0}_getLen(){this._lenArr=this.curves.map(t=>t.len);const{length:e}=this.curves;for(let t=1;t<e;t++)this._lenArr[t]+=this._lenArr[t-1];return this._lenArr[e-1]}getBBox2(e=B()){for(const{bbox2:t}of this.curves)O(e,t);return e}getLineIntersects(e){const{curves:t}=this,{length:n}=t,o=new Array(n);for(let s=0;s<n;s++){const c=t[s].getLineIntersects(e);o[s]=c}return o.flat()}getPosDataByPer(e){const{len:t}=this;this.isClosed&&(e=(e+1)%1);const n=e*t;if(e<=0){const u=this.curves[0],h=e*n/this.curves[0].len;return u.getPosDataByPer(h)}if(e>=1){const u=this.curves[this.curves.length-1],h=(e-1)*n/u.len+1;return u.getPosDataByPer(h)}let o=0,s=this._lenArr.length-1,r;for(;o<s;)r=Math.floor((o+s)/2),this._lenArr[r]<n?o=r+1:s=r;const c=this.curves[o],a=o===0?0:this._lenArr[o-1],l=(n-a)/c.len;return c.getPosDataByPer(l)}clearCache(){this._len=void 0,this._lenArr=[],this._bbox2=void 0,this._isClockwise=void 0}applyFn(e){for(const t of this.curves)t.applyFn(e);this.clearCache()}splitByCoord(e){const t=[];for(const n of this.curves){const o=n.splitByCoord(e);t.push(...o)}return this.curves=t,this.curves}divideAtByNum(e=100){const t=new Array(e-1);for(let s=1;s<e;s++)t[s-1]=s/e;const{length:n}=this.curves,o=new Array(n*e);for(let s=0;s<n;s++){const c=this.curves[s].splitAtArray(t);o.splice(s*e,e,...c)}this.curves=o}reverse(){this.curves.reverse();for(const e of this.curves)e.reverse();this.points.reverse(),this._isClockwise=!this._isClockwise,this._len=this._getLen()}toPathString(e=0){let t=this.curves[0].SPoint,n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `,o=t;for(const r of this.curves){if(!(E(o,r.SPoint)<1)){const{SPoint:a}=r;n+=`M ${q(a)} `,t=a}n+=r.toPathString(e)+" ",o=r.EPoint}return E(o,t)<1&&(n+="Z"),n}toPoints(e=100){let t=new Array(e+1);for(let n=0;n<=e;n++){const o=n/e,{pos:s}=this.getPosDataByPer(o);t[n]=s}return t}}class Q extends Gt{constructor(t){super(t);v(this,"currentPos",y())}moveTo(t,n){this.currentPos=m(t,n)}lineTo(t,n){const o=new L(this.currentPos,m(t,n));this.curves.push(o),this.currentPos=m(t,n)}bezierCurveTo(t,n,o,s,r,c){const a=new F(this.currentPos,m(t,n),m(o,s),m(r,c));this.curves.push(a),this.currentPos=m(r,c)}quadraticCurveTo(t,n,o,s){const r=new k(this.currentPos,m(t,n),m(o,s));this.curves.push(r),this.currentPos=m(o,s)}closePath(){const t=this.curves[0].SPoint;if(Dt(this.currentPos,t))return;const n=new L(this.currentPos,this.curves[0].SPoint);this.curves.push(n)}static fromCommands(t){const n=new Q([]);let o=0;for(let s=0;s<t.length;s++){const r=t[s],{type:c,args:a=[]}=r,l=a.length,{x:u=a[l-2],y:h=a[l-1],x1:p=a[0],y1:f=a[1],x2:g=a[2],y2:d=a[3]}=r;switch(c){case"M":n.moveTo(u,h),o++,o>1&&console.error("SimpleShape can only have one start point");break;case"L":Dt(n.currentPos,m(u,h))||n.lineTo(u,h);break;case"H":n.lineTo(u,n.currentPos[1]);break;case"V":n.lineTo(n.currentPos[0],h);break;case"C":n.bezierCurveTo(p,f,g,d,u,h);break;case"Q":n.quadraticCurveTo(p,f,u,h);break;case"Z":n.closePath();break}}return n}static fromPathString(t){const n=ct(t);return Q.fromCommands(n)}}class Ht extends Q{constructor(t){super(t);v(this,"curves");this.curves=t}}function Rn(i){const e=i.curves.map(t=>Zt(t));return new Ht(e)}class j extends Q{constructor(e){super(e),this.curves=e;const{EPoint:t,SPoint:n}=this;E(t,n)>.1&&console.error("ClosedShape must be closed"),this.initPoints()}include(e){return Ut(e,this.bbox2)?At(e,this.points):!1}intersect(e){let t=!1;for(let n=0;n<this.curves.length;n++){const o=this.curves[n],s=new L(o.SPoint,o.EPoint);if(yt(s,e)){t=!0;break}}return t}static fromCommands(e){const{length:t}=e;(e[0].type!=="M"||e[t-1].type!=="Z")&&console.error("ClosedShape must start with M and end with Z");const n=super.fromCommands(e);return new j(n.curves)}static fromPathString(e){const t=ct(e);return j.fromCommands(t)}getArea(){return Math.abs(this.getSignArea())}getSignArea(){return U(this.points)}}function Ut(i,e){const{xMin:t,xMax:n,yMin:o,yMax:s}=e;return i[0]>=t&&i[0]<=n&&i[1]>=o&&i[1]<=s}function Wt(i){let e=i[0];for(let n=1;n<i.length;n++){const o=i[n],{bbox2:s}=o;s.xMin<e.bbox2.xMin&&(e=o)}e.isClockwise||i.forEach(n=>{n.reverse()});const t=[];for(let n=0;n<i.length;n++){const o=i[n],{isClockwise:s}=o;s&&t.push([o])}for(let n=0;n<i.length;n++){const o=i[n],{bbox2:s,isClockwise:r}=o;if(!r){const c=t.find(a=>{if(!a[0])return!1;const l=a[0].bbox2;return Et(l,s)});c?c.push(o):console.warn("can't find the path for shape:",o)}}return t}function Jt(i,e){const t=A(y(),e.SPoint,i.EPoint);let n;const o=nt(i.outDir,t)*nt(t,e.inDir)>0,s=ot(cn(i.outDir,e.inDir));if(s>=10&&s<=60)if(o)n=dt(i,e);else{const r=i.EPoint,c=it(y(),i.EPoint,i.outDir,1),a=it(y(),e.SPoint,e.inDir,-1),l=e.SPoint;n=new F(r,c,a,l)}else n=new L(i.EPoint,e.SPoint);return n}function dt(i,e){const t=i.EPoint,n=ht(y(),i.EPoint,i.outDir),o=ht(y(),e.SPoint,e.inDir),s=e.SPoint,r=gt(t,n,o,s);return new k(i.EPoint,r,e.SPoint)}function zn(i,e){const t=A(y(),e.SPoint,i.EPoint),n=an(t);let o=i.curves;if(!(n<1)){const c=Jt(i,e);o.push(c)}return i===e||e.points.every((c,a)=>H(c,i.points[a])<1)||(o=o.concat(e.curves)),new Q(o)}function Nn(i,e,t=20,n=!0){const[o,s]=[i,e].map(p=>{const{len:f}=p,g=Math.ceil(f/t);return g||console.error("the count of points is 0"),p.toPoints(g)}),{length:r}=o,{length:c}=s,a={indexes:new Int16Array(0),min:1/0,max:1/0,mean:1/0,std:1/0};if(n){if(!(i.isClosed||e.isClosed)){const d=new L(i.EPoint,e.SPoint),x=new L(e.EPoint,i.SPoint);if(yt(d,x))return[a,a]}const f=[...o,...s];if(!(U(f)>0))return[a,a]}const l=[new Int16Array(r),new Int16Array(c)],u=[new Float32Array(r).fill(1/0),new Float32Array(c).fill(1/0)];for(let p=0;p<r;p++)for(let f=0;f<c;f++){const g=H(o[p],s[f]);g<u[0][p]&&(u[0][p]=g,l[0][p]=f),g<u[1][f]&&(u[1][f]=g,l[1][f]=p)}return u.map((p,f)=>{const g=Math.min(...p),d=Math.max(...p),x=p.reduce((M,S)=>M+S,0)/p.length,C=Math.sqrt(p.map(M=>Math.pow(M-x,2)).reduce((M,S)=>M+S,0)/p.length);return{indexes:l[f],min:g,max:d,mean:x,std:C}})}const $n=(i,e,t,n,o=20)=>{let s=m(t+i,n),r=m(0,1);const c=Math.PI*2/o,a=[];for(let u=1;u<=o;u++){const h=u*c,p=t+i*Math.cos(h),f=n+e*Math.sin(h),g=m(p,f),d=m(-Math.sin(h)*i,Math.cos(h)*e),x=dt({EPoint:s,outDir:r},{SPoint:g,inDir:d});a.push(x),s=g,r=d}return new j(a)};class mt extends j{constructor(e){super(e)}static fromPoints(e){let t=[];for(let n=0;n<=e.length;n++)t.push(new L(e[n],e[(n+1)%e.length]));return new mt(t)}getCentroid(){let e=this.getSignArea(),t=0,n=0;for(let o=0;o<this.points.length;o++){let[s,r]=this.points[o],[c,a]=this.points[(o+1)%this.points.length];t+=(s+c)*(s*a-c*r),n+=(r+a)*(s*a-c*r)}return[t/6/e,n/6/e]}includePolygon(e){const{xMin:t,xMax:n,yMin:o,yMax:s}=this.bbox2;if(e.bbox2.xMin<t||e.bbox2.xMax>n||e.bbox2.yMin<o||e.bbox2.yMax>s)return!1;for(let r of e.points)if(!this.include(r))return!1;return!0}intersectPolygon(e){for(let t of e.points)if(this.include(t))return!0;return!1}}class xt extends Q{constructor(t,n){super(t);v(this,"curves");v(this,"tanArr",[]);if(this.curves=t,n)this.tanArr=n;else{const{length:o}=t,s=new Array(o+1);for(let r=0;r<o;r++)s[r]=t[r].inDir;s[o]=t[o-1].outDir,this.tanArr=s}}static fromPoints(t,n){let o=[];for(let s=0;s<t.length-1;s++)o.push(new L(t[s],t[s+1]));return new xt(o,n)}getDistance(t){let n=1/0;for(let o of this.points)n=Math.min(n,H(o,t));return n}getClosestPoint(t){let n=1/0,o=y();for(let s of this.points){let r=H(s,t);r<n&&(n=r,o=s)}return o}getMaxDeflection(){let t=0;for(let n=0;n<this.curves.length;n++){const o=this.tanArr[n],s=H(y(),o);t=Math.max(t,s)}return t}getPosDataByPer(t){const{isClosed:n,len:o,curves:s}=this;n&&(t=(t+1)%1);const r=t*o;if(t<=0){const f=s[0],g=t*r/s[0].len;return f.getPosDataByPer(g)}if(t>=1){const f=s[s.length-1],g=(t-1)*r/f.len+1;return f.getPosDataByPer(g)}let c=0,a=this._lenArr.length-1,l;for(;c<a;)l=Math.floor((c+a)/2),this._lenArr[l]<r?c=l+1:a=l;const u=s[c],h=c===0?0:this._lenArr[c-1],p=(r-h)/u.len;return u.getPosDataByPer(p)}}function Qn(i){const{points:e}=i,t=e.length;for(let n=0;n<t;n++){const o=e[n],s=e[(n+1)%t];for(let r=n+2;r<t;r++){const c=e[r],a=e[(r+1)%t];if(gt(o,s,c,a))return!0}}return!1}function jn(i){const{points:e,bbox2:t}=i,n=Math.min(e.length,5),o=e.slice(-n),s=o.map(([u])=>u),r=o.map(([,u])=>u),{k:c,b:a,R2:l}=Lt(s,r);return{k:c,b:a,R2:l}}class W{constructor(e,t="NONZERO"){this.shapes=e,this.windingRule=t}static fromCommands(e){const t=[];let n=[];for(const s of e)s.type==="M"?(n.length>0&&t.push(n),n=[s]):n.push(s);n.length>0&&t.push(n);const o=t.map(s=>j.fromCommands(s));return new W(o)}static fromPathString(e){const t=ct(e);return W.fromCommands(t)}getBBox2(e=B()){for(const t of this.shapes)t.getBBox2(e);return e}include(e){let t=!0;for(const n of this.shapes){const{isClockwise:o}=n,s=n.include(e);if(t&&(t=o?s:!s),!t)return!1}return!0}intersect(e){return this.shapes.some(t=>t.intersect(e))}applyFn(e){for(const t of this.shapes)t.applyFn(e)}applyFFDFn(e){for(const t of this.shapes)for(const n of t.curves)n.applyFFDFn(e)}intersectLine(e){let t=[];for(const n of this.shapes)t=t.concat(n.getLineIntersects(e));return t}splitByBBox(){const e=Wt(this.shapes),t=[];for(const n of e)n.length>0&&t.push(new W(n));return t}splitByCoord(e){for(const t of this.shapes)t.splitByCoord(e)}toPathString(e=0){let t="";for(const n of this.shapes)t+=n.toPathString(e)+" ";return t=t.slice(0,-1),t}toPoints(e){let t=[];for(const n of this.shapes)t=t.concat(n.toPoints(e));return t}clone(){const e=this.shapes.map(t=>{const n=t.curves.map(o=>o.clone());return new j(n)});return new W(e,this.windingRule)}}const On=[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800],Ct=i=>On[i],Zn=(i,e)=>Ct(i)/(Ct(e)*Ct(i-e)),Kt=(i,e,t)=>Zn(e,i)*t**i*(1-t)**(e-i),tn=(i,e=0,t=1)=>Math.min(Math.max(i,e),t);function Yn(i,e,t=!0){return t?n=>{const[o,s]=n,r=e.length-1,c=e[0].length-1;let a=(o-i.x)/i.width,l=(s-i.y)/i.height,u=0,h=y();for(let p=0;p<=r;p++){const f=Kt(p,r,a);for(let g=0;g<=c;g++){const d=Kt(g,c,l),x=f*d;u+=x,it(h,h,e[p][g],x)}}on(h,h,1/u),en(n,h)}:n=>{const[o,s]=n,r=e.length-1,c=e[0].length-1;let a=tn((o-i.x)/i.width),l=tn((s-i.y)/i.height);a=a*r,l=l*c;const u=Math.floor(a),h=Math.floor(l);a=a-u,l=l-h;const p=e[u][h],f=e[u+1][h],g=e[u][h+1],d=e[u+1][h+1],x=(1-a)*(1-l)*p[0]+a*(1-l)*f[0]+(1-a)*l*g[0]+a*l*d[0],C=(1-a)*(1-l)*p[1]+a*(1-l)*f[1]+(1-a)*l*g[1]+a*l*d[1];return n[0]=x,n[1]=C,n}}class vt{constructor(e){v(this,"value");v(this,"next",null);this.value=e}}class Mt{constructor(){v(this,"head",null);v(this,"tail",null);v(this,"size",0)}static fromArray(e){const t=new Mt;return e.forEach(n=>t.append(n)),t}toArray(){let e=this.head;const t=[];for(;e;)t.push(e.value),e=e.next;return t}append(e){const t=new vt(e);this.tail&&(this.tail.next=t),this.tail=t,this.head||(this.head=t),this.size++}prepend(e){const t=new vt(e);this.head&&(t.next=this.head),this.head=t,this.tail||(this.tail=t),this.size++}delete(e){var n;if(!this.head)return;for(;this.head&&this.head.value===e;)this.head=this.head.next,this.size--;let t=this.head;for(;t&&t.next;)t.next.value===e?(t.next=t.next.next,this.size--):t=t.next;((n=this.tail)==null?void 0:n.value)===e&&(this.tail=t)}find(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}return null}toString(){let e=this.head;const t=[];for(;e;)t.push(e.value),e=e.next;return t.join(" -> ")}getSize(){return this.size}clear(){this.head=null,this.tail=null,this.size=0}}P.BezierCurve=F,P.BezierCurveType=Ot,P.BezierShape=Ht,P.ClosedShape=j,P.Curve=Vt,P.LineCurve=L,P.LineCurveType=Qt,P.LineToQuadratic=Fn,P.LinkedList=Mt,P.Node=vt,P.Path=W,P.Polygon=mt,P.Polyline=xt,P.QuadraticCurve=k,P.QuadraticCurveType=jt,P.Shape=Gt,P.SingleShape=Q,P.arrEquals=En,P.calDisData=Nn,P.calExtendCurve=jn,P.calPointsArea=U,P.calRadius=hn,P.checkLineCurveIntersect=yt,P.connectShape=zn,P.copyMatrix=dn,P.createBBox2=B,P.createMatrix=yn,P.createSvgByPath=Tn,P.cross=nt,P.gaussElimination=gn,P.getBBox2Size=nn,P.getBSpline=kt,P.getBezierCurvesBBox=zt,P.getBezierFromCurve=Zt,P.getBezierShapeFormSingleShape=Rn,P.getConnectCurve=Jt,P.getCurvature=wn,P.getCurveAngle=An,P.getCurvesByPolygon=$t,P.getDebugPathStr=In,P.getDigit=Bn,P.getEaseElasticInOut=Dn,P.getEaseElasticOut=bn,P.getEllipse=$n,P.getPathStr=qt,P.getPolygon=Rt,P.getQuadraticCurve=dt,P.getRadianChange=pt,P.getRandomGenerate=_t,P.getRandomPathStr=qn,P.getRoots=V,P.getTriangleArea=Mn,P.includeBBox2=Et,P.interpolate=Vn,P.interpolatePolygon=_n,P.isInBBox2=Ut,P.isInLeft=Sn,P.isLineDirClose=kn,P.isPointInPoints=At,P.isSelfIntersect=Qn,P.lineInterSect=gt,P.lineToBezier=Yt,P.linearRegression=Lt,P.max=mn,P.mean=rt,P.median=vn,P.mergeBBox2=O,P.mergeCouple=Ln,P.min=xn,P.pathStringToPathCommands=ct,P.quadraticToBezier=Xt,P.resizeCurvesByBBox=Nt,P.splitByBBox=Wt,P.std=Cn,P.sum=$,P.toAngle=ot,P.toRadian=ln,P.transformPoint=Yn,P.variance=Bt,P.vec2ToAngle=un,P.vec2ToStr=q,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "geo-2d", | ||
"version": "1.0.0-beta.25", | ||
"version": "1.0.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
144658
3637
1