Comparing version 1.0.3 to 1.0.4
@@ -66,3 +66,3 @@ import { vec2 } from 'gl-matrix'; | ||
* curvature = 1 / r, curvature > 0 means the curve is turning right, otherwise, turning left | ||
* @returns | ||
* @returns range from (-Infinity, Infinity) | ||
*/ | ||
@@ -69,0 +69,0 @@ abstract getMaxCurvature(): number; |
@@ -36,4 +36,4 @@ import { vec2 } from 'gl-matrix'; | ||
* @param v2 - the second vector | ||
* @returns - the angle change from v1 to v2 | ||
* @returns - the angle change from v1 to v2, range ``` (-PI, PI] 前开后闭 ``` | ||
*/ | ||
export declare function getRadianChange(v1: vec2, v2: vec2): number; | ||
export declare function getRadianChange(v1: vec2, v2: vec2, tol?: number): number; |
@@ -1,1 +0,1 @@ | ||
(function(P,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(P=typeof globalThis<"u"?globalThis:P||self,L(P.geometry={}))})(this,function(P){"use strict";var Wn=Object.defineProperty;var Jn=(P,L,O)=>L in P?Wn(P,L,{enumerable:!0,configurable:!0,writable:!0,value:O}):P[L]=O;var M=(P,L,O)=>Jn(P,typeof L!="symbol"?L+"":L,O);function L(){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 D(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 B(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,T=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 dn(i){return new Array(i).fill(0).map(()=>new Array(i))}function yn(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 vn(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 Mn(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 Cn(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){M(this,"type","curve");M(this,"_isDirty",!0);M(this,"_SPoint",y());M(this,"_EPoint",y());M(this,"_bbox2");M(this,"_len");M(this,"inDir",y());M(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=B(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=B(y(),l,u,.5);c[a]=h}for(let a=0;a<100;a++){const l=D(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 A extends Vt{constructor(t,n){super(t,n);M(this,"tangent");M(this,"normal");this.type=Qt,this.tangent=N(y(),T(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(),T(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 B(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:v,yMin:C,xMax:S,yMax:w}=this.bbox2;d>=v&&d<=S&&x>=C&&x<=w&&h.push(m(d,x))}return h}getDisToPos(t){const{SPoint:n,EPoint:o,tangent:s}=this,r=T(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 A(n,s),new A(D(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 A(D(this.SPoint),D(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,v=u*l-a*h,C=p*x-d*f,S=(f*v-x*g)/C,w=(d*g-p*v)/C;return m(S,w)}function dt(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 A{constructor(t,n,o){super(t,o);M(this,"_CPoint1",y());M(this,"_lenArr",new Array(at).fill(0));this.type=jt,this.CPoint1=n;let s=T(y(),n,t);this.inDir=N(s,s),s=T(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),v=Math.max(...g),C=Math.min(...d),S=Math.max(...d);return{xMin:x,xMax:v,yMin:C,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 _ of l)u+=nt(t.tangent,T(y(),_,c))>0?1:0;if(u===0||u===4)return[];const h=[],[p,f]=this.SPoint,[g,d]=this.CPoint1,[x,v]=this.EPoint,[C,S]=t.SPoint,w=p-2*g+x,I=f-2*d+v,b=2*(g-p),Z=2*(d-f),J=p,K=f,[R,Y]=T(y(),t.EPoint,t.SPoint),lt=R*I-Y*w,ut=R*Z-Y*b,X=R*K-Y*J-R*S+Y*C,G=V([lt,ut,X]);for(const _ of G)if(_>=0&&_<=1){const St=(1-_)**2*p+2*_*(1-_)*g+_**2*x,wt=(1-_)**2*f+2*_*(1-_)*d+_**2*v;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 v=0;v<2;v++)for(let C=0;C<2;C++)for(let S=0;S<3;S++)f[C+S]+=p[v][C]*h[v][S]+p[v][C]*h[v][S];const d=[...V(f).filter(v=>v*(v-1)<0),0,1];let x=1/0;for(let v of d){const C=this.getPosition(v),S=E(t,C);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=B(y(),n,s,t),c=B(y(),s,o,t),a=B(y(),r,c,t),l=new k(n,r,a),u=new k(D(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=B(y(),o[0],o[2],.5),r=B(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(D(this.SPoint),D(this.CPoint1),D(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);M(this,"_CPoint2",y());this.type=Ot,this.CPoint2=o;let r=T(y(),n,t);this.inDir=N(r,r),r=T(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]),v=d.map(b=>this.getPosition(b)[1]),C=Math.min(...x),S=Math.max(...x),w=Math.min(...v),I=Math.max(...v);return{xMin:C,xMax:S,yMin:w,yMax:I}}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(I=>{const b=this.getPosition(I);return t(b),b});t(n),t(o);const c=(I,b)=>{const Z=(1-I)**3,J=3*I*(1-I)**2,K=3*I**2*(1-I),R=I**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),v=(l*g-f*u)*x,C=(l*d-f*h)*x,S=(p*u-a*g)*x,w=(p*h-a*d)*x;this.CPoint1=m(v,C),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(T(y(),a,c),T(y(),z,c))>0?1:0;if(u===0||u===4)return[];const h=[],[p,f]=this.SPoint,[g,d]=this.CPoint1,[x,v]=this.CPoint2,[C,S]=this.EPoint,[w,I]=t.SPoint,b=-p+3*g-3*x+C,Z=-f+3*d-3*v+S,J=3*p-6*g+3*x,K=3*f-6*d+3*v,R=-3*p+3*g,Y=-3*f+3*d,lt=p,ut=f,[X,G]=T(y(),t.EPoint,t.SPoint),_=X*Z-G*b,St=X*K-G*J,wt=X*Y-G*R,Xn=X*ut-G*lt-(X*I-G*w),Gn=V([_,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=B(y(),n,s,t),a=B(y(),s,r,t),l=B(y(),r,o,t),u=B(y(),c,a,t),h=B(y(),a,l,t),p=this.getPosition(t),f=new F(n,c,u,p),g=new F(D(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(D(this.SPoint),D(this.CPoint1),D(this.CPoint2),D(this.EPoint))}}function Zt(i){if(i instanceof F)return i;if(i instanceof A)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=B(y(),e,t,1/3),o=B(y(),e,t,2/3);return new F(e,n,o,t)}function Xt(i){const{SPoint:e,CPoint1:t,EPoint:n}=i,o=B(y(),e,t,2/3),s=B(y(),n,t,2/3);return new F(e,o,s,n)}class Gt{constructor(e){M(this,"curves",[]);M(this,"points",[]);M(this,"_isClockwise");M(this,"_len");M(this,"_lenArr",[]);M(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=L()){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!==void 0&&(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);M(this,"currentPos",y())}moveTo(t,n){this.currentPos=m(t,n)}lineTo(t,n){const o=new A(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 A(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);M(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 A(o.SPoint,o.EPoint);if(dt(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 c=1;c<i.length;c++){const a=i[c],{bbox2:l}=a;l.xMin<e.bbox2.xMin&&(e=a)}e.isClockwise||(console.warn("outShape should be right hand, and now I will reverse it"),i.forEach(c=>{c.reverse()}));const t=[],n=[];for(let c=0;c<i.length;c++){const a=i[c],{isClockwise:l}=a;l?t.push(a):n.push(a)}const o=c=>t.findIndex(l=>Et(l.bbox2,c.bbox2)),s=new Array(t.length).fill(0).map(()=>[]);for(let c=0;c<n.length;c++){const a=i[c],l=o(a);l!==-1?s[l].push(c):console.warn("can't find the path for shape:",a)}const r=new Array(t.length).fill(0).map(()=>[]);for(let c=0;c<s.length;c++)r[c].push(t[c]),s[c].forEach(l=>{r[c].push(n[l])});return r}function Jt(i,e){const t=T(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=yt(i,e);else{const r=D(i.EPoint),c=it(y(),i.EPoint,i.outDir,1),a=it(y(),e.SPoint,e.inDir,-1),l=D(e.SPoint);n=new F(r,c,a,l)}else n=new A(D(i.EPoint),D(e.SPoint));return n}function yt(i,e){const t=D(i.EPoint),n=D(e.SPoint),o=ht(y(),t,i.outDir),s=ht(y(),n,e.inDir),r=gt(t,o,s,n);return new k(t,r,n)}function zn(i,e){const t=T(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)}),r={mean:1/0,std:1/0};if(n){const p=new A(i.EPoint,e.SPoint),f=new A(e.EPoint,i.SPoint);if(dt(p,f))return r;const d=[...o,...s];if(!(U(d)>0))return r}const{length:c}=o,{length:a}=s,l=[new Int16Array(c),new Int16Array(a)],u=[new Float32Array(c).fill(1/0),new Float32Array(a).fill(1/0)];for(let p=0;p<c;p++)for(let f=0;f<a;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)}const h=u.map(p=>{const f=p.reduce((d,x)=>d+x,0)/p.length,g=Math.sqrt(p.map(d=>Math.pow(d-f,2)).reduce((d,x)=>d+x,0)/p.length);return{mean:f,std:g}});return h[0].std<h[1].std?h[1]:h[0]}const $n=(i,e,t,n,o=20)=>{let s=m(i+t,e),r=m(0,1);const c=Math.PI*2/o,a=[];for(let u=1;u<=o;u++){const h=u*c,p=i+t*Math.cos(h),f=e+n*Math.sin(h),g=m(p,f),d=m(-Math.sin(h)*t,Math.cos(h)*n),x=yt({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 A(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);M(this,"curves");M(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 A(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=L()){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],vt=i=>On[i],Zn=(i,e)=>vt(i)/(vt(e)*vt(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],v=(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]=v,n}}class Mt{constructor(e){M(this,"value");M(this,"next",null);this.value=e}}class Ct{constructor(){M(this,"head",null);M(this,"tail",null);M(this,"size",0)}static fromArray(e){const t=new Ct;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 Mt(e);this.tail&&(this.tail.next=t),this.tail=t,this.head||(this.head=t),this.size++}prepend(e){const t=new Mt(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=A,P.LineCurveType=Qt,P.LineToQuadratic=Fn,P.LinkedList=Ct,P.Node=Mt,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=dt,P.connectShape=zn,P.copyMatrix=yn,P.createBBox2=L,P.createMatrix=dn,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=yt,P.getRadianChange=pt,P.getRandomGenerate=_t,P.getRandomPathStr=qn,P.getRoots=V,P.getTriangleArea=Cn,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=Mn,P.mergeBBox2=O,P.mergeCouple=Ln,P.min=xn,P.pathStringToPathCommands=ct,P.quadraticToBezier=Xt,P.resizeCurvesByBBox=Nt,P.splitByBBox=Wt,P.std=vn,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"})}); | ||
(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 C=(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 wt(i,e){return i.xMin<=e.xMin&&i.xMax>=e.xMax&&i.yMin<=e.yMin&&i.yMax>=e.yMax}var Et=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 m(){var i=new et(2);return et!=Float32Array&&(i[0]=0,i[1]=0),i}function D(i){var e=new et(2);return e[0]=i[0],e[1]=i[1],e}function y(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 lt(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 bt(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 ht(i,e){return i[0]*e[0]+i[1]*e[1]}function L(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)<=Et*Math.max(1,Math.abs(t),Math.abs(o))&&Math.abs(n-s)<=Et*Math.max(1,Math.abs(n),Math.abs(s))}var an=rn,T=sn,H=E;(function(){var i=m();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 un(i){return i*Math.PI/180}function it(i){return i*180/Math.PI}function ln(i){return it(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 _(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],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,u=(9*s*r-27*c-2*s*s*s)/54,l=a*a*a+u*u;if(l>=0){const h=Math.sqrt(l),P=Math.cbrt(u+h),f=Math.cbrt(u-h),g=[-s/3+(P+f)];return l===0&&g.push(-P/2),g}else{const h=Math.acos(u/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 dn(i){return new Array(i).fill(0).map(()=>new Array(i))}function yn(i){return i.map(e=>e.slice())}function mn(i){return Math.max(...i)}function xn(i){return Math.min(...i)}function Q(i){return i.reduce((e,t)=>e+t,0)}function ot(i){return Q(i)/i.length}function vn(i){return ot(i),Math.sqrt(Lt(i))}function Lt(i){const e=ot(i);return ot(i.map(t=>Math.pow(t-e,2)))}function Cn(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 Bt(i,e){const t=i.length,n=Q(i),o=Q(e),s=o/t,r=Q(i.map((g,d)=>g*e[d])),c=Q(i.map(g=>g*g)),a=1e-10;if(t*c-n*n<a)return{k:1/0,b:n/t,R2:1};const u=(t*r-n*o)/(t*c-n*n),l=(o-u*n)/t,h=Math.max(a,Q(e.map(g=>Math.pow(g-s,2)))),f=Math.max(a,Q(i.map(g=>Math.pow(u*g+l-s,2))))/h;return{k:u,b:l,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],[u,l]=e[r];a>n!=l>n&&t-c<(u-c)*(n-a)/(l-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,Vt=12345,ft=2147483647;function It(i=.314){let e=(Tt*i+Vt)%ft;return()=>(e=(Tt*e+Vt)%ft,e/ft)}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 Ln(i,e=4){return Math.max(e-Math.floor(Math.log10(i)),0)}function Bn(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){const t=pt(i.outDir,e.inDir);return it(t)}function pt(i,e,t=Math.PI/180){const n=i[0]*e[1]-i[1]*e[0],o=i[0]*e[0]+i[1]*e[1];let s=Math.atan2(n,o);return s<-Math.PI+t&&(s=Math.PI),s}class _t{constructor(e,t){C(this,"type","curve");C(this,"_isDirty",!0);C(this,"_SPoint",m());C(this,"_EPoint",m());C(this,"_bbox2");C(this,"_len");C(this,"inDir",m());C(this,"outDir",m());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 Vn(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 rt(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 In(i,e,t){const n=[],o=i.length,s=e.length;for(let r=0;r<s;r++){const c=L(m(),i[r%o],e[r],t);n.push(c)}return n}function _n(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],u=n[s];if(i=i*(u-a)+a,i<a||i>u)throw new Error("out of bbox2");let l;for(l=e;l<s&&!(i>=n[l]&&i<=n[l+1]);l++);let h;for(let f=1;f<=e+1;f++)for(let g=l;g>l-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[l][f]/c[l][r];return y(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 y(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 u=(t-a)/(e-c);r[a]=u*r[a]+(1-u)*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,u=It(s);let l=h=>{const f=u()*n+(1-n);let g=(f*Math.cos(h)+1)*c,d=(f*Math.sin(h)+1)*a;return y(g,d)};for(let h=0;h<t;h++){let P=l(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 Qt(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 u=y(o[a][0],o[a][1]),l=y(o[(a+1)%100][0],o[(a+1)%100][1]),h=L(m(),u,l,.5);c[a]=h}for(let a=0;a<100;a++){const u=D(c[a]),l=c[(a+1)%100],h=o[(a+1)%100];t.push(new k(u,h,l))}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=Qt(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 $t="curve-line";class A extends _t{constructor(t,n){super(t,n);C(this,"tangent");C(this,"normal");this.type=$t,this.tangent=N(m(),T(m(),n,t)),this.normal=y(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.outDir=this.tangent}update(){super.update(),this.tangent=N(m(),T(m(),this.EPoint,this.SPoint)),this.normal=y(-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 L(m(),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:u,val:l}=t,h=[];return u==="x"&&l>=n&&l<=n+s?h.push((l-c[0])/(a[0]-c[0])):u==="y"&&l>=o&&l<=o+r&&h.push((l-c[1])/(a[1]-c[1])),h}getLineIntersects(t){const[n,o]=this.SPoint,[s,r]=this.EPoint,[c,a]=t.SPoint,[u,l]=t.EPoint,h=[],P=(n-s)*(a-l)-(o-r)*(c-u);if(Math.abs(P)>1e-10){const f=n*r-o*s,g=c*l-a*u,d=(f*(c-u)-g*(n-s))/P,x=(f*(a-l)-g*(o-r))/P,{xMin:v,yMin:M,xMax:S,yMax:w}=this.bbox2;d>=v&&d<=S&&x>=M&&x<=w&&h.push(y(d,x))}return h}getDisToPos(t){const{SPoint:n,EPoint:o,tangent:s}=this,r=T(m(),t,n),c=ht(r,s);if(c<0)return E(n,t);const a=E(n,o);if(c>a)return E(o,t);const u=y(-s[1],s[0]);return Math.abs(ht(u,r))}applyFn(t){t(this.SPoint),t(this.EPoint),this._isDirty=!0,this.update()}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 A(n,s),new A(D(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 A(D(this.SPoint),D(this.EPoint))}}function kn(i,e){return ht(i.tangent,e.tangent)>.982}function Pt(i,e,t,n){const[o,s]=i,[r,c]=e,[a,u]=t,[l,h]=n,P=c-s,f=o-r,g=r*s-o*c,d=h-u,x=a-l,v=l*u-a*h,M=P*x-d*f,S=(f*v-x*g)/M,w=(d*g-P*v)/M;return y(S,w)}function gt(i,e){const[t,n]=i.SPoint,[o,s]=i.EPoint,[r,c]=e.SPoint,[a,u]=e.EPoint,l=(t-r)*(u-c)-(n-c)*(a-r),h=(o-r)*(u-c)-(s-c)*(a-r),P=(r-t)*(s-n)-(c-n)*(o-t),f=(a-t)*(s-n)-(u-n)*(o-t);return l*h<0&&P*f<0}const ct=100,jt="curve-quadratic";class k extends A{constructor(t,n,o){super(t,o);C(this,"_CPoint1",m());C(this,"_lenArr",new Array(ct).fill(0));this.type=jt,this.CPoint1=n;let s=T(m(),n,t);this.inDir=N(s,s),s=T(m(),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)],u=[2*(n-2*s+c),2*(s-c)],l=_(a),h=_(u),P=l.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),v=Math.max(...g),M=Math.min(...d),S=Math.max(...d);return{xMin:x,xMax:v,yMin:M,yMax:S}}_getLen(){let t=0,n=this.getPosition(0);for(let o=1;o<=ct;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 y(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/ct;a+=(r-c)/(this._lenArr[n]-c)/ct;const u=this.getPosition(a),l=this.getTangent(a);return{pos:u,tan:l}}getTangent(t){const n=this.getDerivative(t);return N(n,n)}getNormal(t){const[n,o]=this.getTangent(t);return y(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 u=[this.SPoint[0]-2*this.CPoint1[0]+this.EPoint[0],2*(this.CPoint1[0]-this.EPoint[0]),this.EPoint[0]-a];return _(u).filter(h=>h>0&&h<1)}}else if(a>=o&&a<=o+r){const u=[this.SPoint[1]-2*this.CPoint1[1]+this.EPoint[1],2*(this.CPoint1[1]-this.EPoint[1]),this.EPoint[1]-a];return _(u).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,u=[y(n,s),y(o,s),y(o,r),y(n,r)];let l=0;for(const I of u)l+=nt(t.tangent,T(m(),I,c))>0?1:0;if(l===0||l===4)return[];const h=[],[P,f]=this.SPoint,[g,d]=this.CPoint1,[x,v]=this.EPoint,[M,S]=t.SPoint,w=P-2*g+x,V=f-2*d+v,b=2*(g-P),Z=2*(d-f),J=P,K=f,[F,Y]=T(m(),t.EPoint,t.SPoint),at=F*V-Y*w,ut=F*Z-Y*b,X=F*K-Y*J-F*S+Y*M,G=_([at,ut,X]);for(const I of G)if(I>=0&&I<=1){const Mt=(1-I)**2*P+2*I*(1-I)*g+I**2*x,St=(1-I)**2*f+2*I*(1-I)*d+I**2*v;h.push(y(Mt,St))}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,[u,l]=t,h=[[-(n-2*s+c),-2*(s-n),u-n],[-(o-2*r+a),-2*(r-o),l-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 v=0;v<2;v++)for(let M=0;M<2;M++)for(let S=0;S<3;S++)f[M+S]+=P[v][M]*h[v][S]+P[v][M]*h[v][S];const d=[..._(f).filter(v=>v*(v-1)<0),0,1];let x=1/0;for(let v of d){const M=this.getPosition(v),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 y(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 y(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,this.update()}applyFFDFn(t){this.applyFn(t);const n=y(this.CPoint1[0]-.5*(this.SPoint[0]+this.EPoint[0]),this.CPoint1[1]-.5*(this.SPoint[1]+this.EPoint[1]));lt(this.CPoint1,this.CPoint1,n)}splitAt(t){const n=this.SPoint,o=this.EPoint,s=this.CPoint1,r=L(m(),n,s,t),c=L(m(),s,o,t),a=L(m(),r,c,t),u=new k(n,r,a),l=new k(D(a),c,o);return[u,l]}splitAtArray(t){return super.splitAtArray.call(this,t)}pathOffset(t){const o=[0,.5,1].map(c=>{const a=this.getPosition(c),u=this.getNormal(c);return bt(m(),a,u,t)}),s=L(m(),o[0],o[2],.5),r=L(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(D(this.SPoint),D(this.CPoint1),D(this.EPoint))}}function Fn(i){const e=i.SPoint,t=i.EPoint,n=y((e[0]+t[0])/2,(e[1]+t[1])/2);return new k(e,n,t)}const Ot="curve-bezier";class z extends k{constructor(t,n,o,s){super(t,n,s);C(this,"_CPoint2",m());this.type=Ot,this.CPoint2=o;let r=T(m(),n,t);this.inDir=N(r,r),r=T(m(),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,u]=this.EPoint,l=[-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*u,6*n-12*s+6*c,3*s-3*n],P=_(l),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]),v=d.map(b=>this.getPosition(b)[1]),M=Math.min(...x),S=Math.max(...x),w=Math.min(...v),V=Math.max(...v);return{xMin:M,xMax:S,yMin:w,yMax:V}}getSplitT(t){const{x:n,y:o,width:s,height:r}=this.bbox,{mode:c,val:a}=t,u=c==="y"?1:0;if(a<[n,o][u]||a>[n+s,o+r][u])return[];{const l=[-this.SPoint[u]+3*this.CPoint1[u]-3*this.CPoint2[u]+this.EPoint[u],3*this.SPoint[u]-6*this.CPoint1[u]+3*this.CPoint2[u],-3*this.SPoint[u]+3*this.CPoint1[u],this.SPoint[u]-a],h=_(l),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 y(c,a)}getTangent(t){const n=this.getDerivative(t);return N(n,n)}getNormal(t){const[n,o]=this.getTangent(t);return y(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 y(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 y(c,a)}applyFn(t){t(this.SPoint),t(this.EPoint),t(this.CPoint1),t(this.CPoint2),this._isDirty=!0,this.update()}applyFFDFn(t){const{SPoint:n,EPoint:o}=this,s=[.4,.6],r=s.map(V=>{const b=this.getPosition(V);return t(b),b});t(n),t(o);const c=(V,b)=>{const Z=(1-V)**3,J=3*V*(1-V)**2,K=3*V**2*(1-V),F=V**3;return[J,K,b[0]-F*o[0]-Z*n[0],b[1]-F*o[1]-Z*n[1]]},[a,u,l,h]=c(s[0],r[0]),[P,f,g,d]=c(s[1],r[1]),x=1/(u*P-a*f),v=(u*g-f*l)*x,M=(u*d-f*h)*x,S=(P*l-a*g)*x,w=(P*h-a*d)*x;this.CPoint1=y(v,M),this.CPoint2=y(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,u=[y(n,s),y(o,s),y(o,r),y(n,r)];let l=0;for(const R of u)l+=nt(T(m(),a,c),T(m(),R,c))>0?1:0;if(l===0||l===4)return[];const h=[],[P,f]=this.SPoint,[g,d]=this.CPoint1,[x,v]=this.CPoint2,[M,S]=this.EPoint,[w,V]=t.SPoint,b=-P+3*g-3*x+M,Z=-f+3*d-3*v+S,J=3*P-6*g+3*x,K=3*f-6*d+3*v,F=-3*P+3*g,Y=-3*f+3*d,at=P,ut=f,[X,G]=T(m(),t.EPoint,t.SPoint),I=X*Z-G*b,Mt=X*K-G*J,St=X*Y-G*F,Xn=X*ut-G*at-(X*V-G*w),Gn=_([I,Mt,St,Xn]);for(const R of Gn)if(R>=0&&R<=1){const Hn=b*R**3+J*R**2+F*R+at,Un=Z*R**3+K*R**2+Y*R+ut;h.push(y(Hn,Un))}return h}splitAt(t){const n=this.SPoint,o=this.EPoint,s=this.CPoint1,r=this.CPoint2,c=L(m(),n,s,t),a=L(m(),s,r,t),u=L(m(),r,o,t),l=L(m(),c,a,t),h=L(m(),a,u,t),P=this.getPosition(t),f=new z(n,c,l,P),g=new z(D(P),h,u,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 z(D(this.SPoint),D(this.CPoint1),D(this.CPoint2),D(this.EPoint))}}function Zt(i){if(i instanceof z)return i;if(i instanceof A)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=L(m(),e,t,1/3),o=L(m(),e,t,2/3);return new z(e,n,o,t)}function Xt(i){const{SPoint:e,CPoint1:t,EPoint:n}=i,o=L(m(),e,t,2/3),s=L(m(),n,t,2/3);return new z(e,o,s,n)}class Gt{constructor(e){C(this,"curves",[]);C(this,"points",[]);C(this,"_isClockwise");C(this,"_len");C(this,"_lenArr",[]);C(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 l=this.curves[0],h=e*n/this.curves[0].len;return l.getPosDataByPer(h)}if(e>=1){const l=this.curves[this.curves.length-1],h=(e-1)*n/l.len+1;return l.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],u=(n-a)/c.len;return c.getPosDataByPer(u)}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!==void 0&&(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 $ extends Gt{constructor(t){super(t);C(this,"currentPos",m())}moveTo(t,n){this.currentPos=y(t,n)}lineTo(t,n){const o=new A(this.currentPos,y(t,n));this.curves.push(o),this.currentPos=y(t,n)}bezierCurveTo(t,n,o,s,r,c){const a=new z(this.currentPos,y(t,n),y(o,s),y(r,c));this.curves.push(a),this.currentPos=y(r,c)}quadraticCurveTo(t,n,o,s){const r=new k(this.currentPos,y(t,n),y(o,s));this.curves.push(r),this.currentPos=y(o,s)}closePath(){const t=this.curves[0].SPoint;if(Dt(this.currentPos,t))return;const n=new A(this.currentPos,this.curves[0].SPoint);this.curves.push(n)}static fromCommands(t){const n=new $([]);let o=0;for(let s=0;s<t.length;s++){const r=t[s],{type:c,args:a=[]}=r,u=a.length,{x:l=a[u-2],y:h=a[u-1],x1:P=a[0],y1:f=a[1],x2:g=a[2],y2:d=a[3]}=r;switch(c){case"M":n.moveTo(l,h),o++,o>1&&console.error("SimpleShape can only have one start point");break;case"L":Dt(n.currentPos,y(l,h))||n.lineTo(l,h);break;case"H":n.lineTo(l,n.currentPos[1]);break;case"V":n.lineTo(n.currentPos[0],h);break;case"C":n.bezierCurveTo(P,f,g,d,l,h);break;case"Q":n.quadraticCurveTo(P,f,l,h);break;case"Z":n.closePath();break}}return n}static fromPathString(t){const n=rt(t);return $.fromCommands(n)}}class Ht extends ${constructor(t){super(t);C(this,"curves");this.curves=t}}function Rn(i){const e=i.curves.map(t=>Zt(t));return new Ht(e)}class j extends ${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 A(o.SPoint,o.EPoint);if(gt(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=rt(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 c=1;c<i.length;c++){const a=i[c],{bbox2:u}=a;u.xMin<e.bbox2.xMin&&(e=a)}e.isClockwise||(console.warn("outShape should be right hand, and now I will reverse it"),i.forEach(c=>{c.reverse()}));const t=[],n=[];for(let c=0;c<i.length;c++){const a=i[c],{isClockwise:u}=a;u?t.push(a):n.push(a)}const o=c=>t.findIndex(u=>wt(u.bbox2,c.bbox2)),s=new Array(t.length).fill(0).map(()=>[]);for(let c=0;c<n.length;c++){const a=i[c],u=o(a);u!==-1?s[u].push(c):console.warn("can't find the path for shape:",a)}const r=new Array(t.length).fill(0).map(()=>[]);for(let c=0;c<s.length;c++)r[c].push(t[c]),s[c].forEach(u=>{r[c].push(n[u])});return r}function Jt(i,e){const t=T(m(),e.SPoint,i.EPoint);let n;const o=nt(i.outDir,t)*nt(t,e.inDir)>0,s=it(cn(i.outDir,e.inDir));return o&&s>1&&s<60?n=dt(i,e):n=new A(D(i.EPoint),D(e.SPoint)),n}function dt(i,e){const t=D(i.EPoint),n=D(e.SPoint),o=lt(m(),t,i.outDir),s=lt(m(),n,e.inDir),r=Pt(t,o,s,n);return new k(t,r,n)}function zn(i,e){const t=T(m(),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 $(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)}),r={mean:1/0,std:1/0};if(n){const P=new A(i.EPoint,e.SPoint),f=new A(e.EPoint,i.SPoint);if(gt(P,f))return r;const d=[...o,...s];if(!(U(d)>0))return r}const{length:c}=o,{length:a}=s,u=[new Int16Array(c),new Int16Array(a)],l=[new Float32Array(c).fill(1/0),new Float32Array(a).fill(1/0)];for(let P=0;P<c;P++)for(let f=0;f<a;f++){const g=H(o[P],s[f]);g<l[0][P]&&(l[0][P]=g,u[0][P]=f),g<l[1][f]&&(l[1][f]=g,u[1][f]=P)}const h=l.map(P=>{const f=P.reduce((d,x)=>d+x,0)/P.length,g=Math.sqrt(P.map(d=>Math.pow(d-f,2)).reduce((d,x)=>d+x,0)/P.length);return{mean:f,std:g}});return h[0].std<h[1].std?h[1]:h[0]}const Qn=(i,e,t,n,o=20)=>{let s=y(i+t,e),r=y(0,1);const c=Math.PI*2/o,a=[];for(let l=1;l<=o;l++){const h=l*c,P=i+t*Math.cos(h),f=e+n*Math.sin(h),g=y(P,f),d=y(-Math.sin(h)*t,Math.cos(h)*n),x=dt({EPoint:s,outDir:r},{SPoint:g,inDir:d});a.push(x),s=g,r=d}return new j(a)};class yt extends j{constructor(e){super(e)}static fromPoints(e){let t=[];for(let n=0;n<=e.length;n++)t.push(new A(e[n],e[(n+1)%e.length]));return new yt(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 mt extends ${constructor(t,n){super(t);C(this,"curves");C(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 A(t[s],t[s+1]));return new mt(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=m();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(m(),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,u;for(;c<a;)u=Math.floor((c+a)/2),this._lenArr[u]<r?c=u+1:a=u;const l=s[c],h=c===0?0:this._lenArr[c-1],P=(r-h)/l.len;return l.getPosDataByPer(P)}}function $n(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(Pt(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(([l])=>l),r=o.map(([,l])=>l),{k:c,b:a,R2:u}=Bt(s,r);return{k:c,b:a,R2:u}}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=rt(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],xt=i=>On[i],Zn=(i,e)=>xt(i)/(xt(e)*xt(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,u=(s-i.y)/i.height,l=0,h=m();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,u),x=f*d;l+=x,bt(h,h,e[P][g],x)}}on(h,h,1/l),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),u=tn((s-i.y)/i.height);a=a*r,u=u*c;const l=Math.floor(a),h=Math.floor(u);a=a-l,u=u-h;const P=e[l][h],f=e[l+1][h],g=e[l][h+1],d=e[l+1][h+1],x=(1-a)*(1-u)*P[0]+a*(1-u)*f[0]+(1-a)*u*g[0]+a*u*d[0],v=(1-a)*(1-u)*P[1]+a*(1-u)*f[1]+(1-a)*u*g[1]+a*u*d[1];return n[0]=x,n[1]=v,n}}class vt{constructor(e){C(this,"value");C(this,"next",null);this.value=e}}class Ct{constructor(){C(this,"head",null);C(this,"tail",null);C(this,"size",0)}static fromArray(e){const t=new Ct;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=z,p.BezierCurveType=Ot,p.BezierShape=Ht,p.ClosedShape=j,p.Curve=_t,p.LineCurve=A,p.LineCurveType=$t,p.LineToQuadratic=Fn,p.LinkedList=Ct,p.Node=vt,p.Path=W,p.Polygon=yt,p.Polyline=mt,p.QuadraticCurve=k,p.QuadraticCurveType=jt,p.Shape=Gt,p.SingleShape=$,p.arrEquals=En,p.calDisData=Nn,p.calExtendCurve=jn,p.calPointsArea=U,p.calRadius=hn,p.checkLineCurveIntersect=gt,p.connectShape=zn,p.copyMatrix=yn,p.createBBox2=B,p.createMatrix=dn,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=Qt,p.getDebugPathStr=Vn,p.getDigit=Ln,p.getEaseElasticInOut=Dn,p.getEaseElasticOut=bn,p.getEllipse=Qn,p.getPathStr=qt,p.getPolygon=Rt,p.getQuadraticCurve=dt,p.getRadianChange=pt,p.getRandomGenerate=It,p.getRandomPathStr=qn,p.getRoots=_,p.getTriangleArea=Mn,p.includeBBox2=wt,p.interpolate=_n,p.interpolatePolygon=In,p.isInBBox2=Ut,p.isInLeft=Sn,p.isLineDirClose=kn,p.isPointInPoints=At,p.isSelfIntersect=$n,p.lineInterSect=Pt,p.lineToBezier=Yt,p.linearRegression=Bt,p.max=mn,p.mean=ot,p.median=Cn,p.mergeBBox2=O,p.mergeCouple=Bn,p.min=xn,p.pathStringToPathCommands=rt,p.quadraticToBezier=Xt,p.resizeCurvesByBBox=Nt,p.splitByBBox=Wt,p.std=vn,p.sum=Q,p.toAngle=it,p.toRadian=un,p.transformPoint=Yn,p.variance=Lt,p.vec2ToAngle=ln,p.vec2ToStr=q,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "geo-2d", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is too big to display
145756
3649