Comparing version 1.0.0-beta.18 to 1.0.0-beta.19
@@ -0,1 +1,4 @@ | ||
/** | ||
* ### Classic Bounding Box | ||
*/ | ||
export interface BBox { | ||
@@ -7,2 +10,5 @@ x: number; | ||
} | ||
/** | ||
* ### Efficient Bounding Box | ||
*/ | ||
export interface BBox2 { | ||
@@ -9,0 +15,0 @@ xMin: number; |
@@ -5,3 +5,3 @@ import { vec2 } from 'gl-matrix'; | ||
import { LineCurve } from './line'; | ||
import { BBox } from '../base'; | ||
import { BBox2 } from '../base'; | ||
export declare const BezierCurveType = "curve-bezier"; | ||
@@ -29,3 +29,3 @@ /** | ||
*/ | ||
protected _getBBox(): BBox; | ||
protected _getBBox2(): BBox2; | ||
getSplitT(data: CoordData): number[]; | ||
@@ -32,0 +32,0 @@ getPosition(t: number): vec2; |
import { vec2 } from 'gl-matrix'; | ||
import { BBox } from '../base'; | ||
import { BBox, BBox2 } from '../base'; | ||
import { LineCurve } from './line'; | ||
@@ -22,10 +22,10 @@ export type PointFn = (vec: vec2) => void; | ||
protected _EPoint: vec2; | ||
protected _bbox?: BBox; | ||
protected _bbox2?: BBox2; | ||
protected _len?: number; | ||
/** | ||
* The direction of the curve at the start point. | ||
* The normal vector to represent direction of the curve at the start point. | ||
*/ | ||
inDir: vec2; | ||
/** | ||
* The direction of the curve at the end point. | ||
* The normal vector to represent direction of the curve at the end point. | ||
*/ | ||
@@ -44,3 +44,10 @@ ouDir: vec2; | ||
get bbox(): BBox; | ||
get bbox2(): BBox2; | ||
get len(): number; | ||
/** | ||
* Gets the deflection angle of the curve. | ||
* @remarks this is the angle between the inDir and ouDir, | ||
* it is correct for most of the time, but it not correct for bezier curve sometimes. | ||
*/ | ||
get deflection(): number; | ||
protected update(): void; | ||
@@ -51,3 +58,3 @@ /** | ||
*/ | ||
protected abstract _getBBox(): BBox; | ||
protected abstract _getBBox2(): BBox2; | ||
/** | ||
@@ -65,3 +72,3 @@ * Gets the length of the curve. | ||
/** | ||
* Gets the position on the curve at the given parameter value. | ||
* ### Gets the position on the curve at the given parameter value. | ||
* @param t - The parameter value. | ||
@@ -68,0 +75,0 @@ * @returns The position on the curve. |
import { vec2 } from 'gl-matrix'; | ||
import { Curve, PointFn, CoordData } from './curve'; | ||
import { BBox } from '../base'; | ||
import { BBox2 } from '../base'; | ||
export declare const LineCurveType = "curve-line"; | ||
@@ -19,3 +19,3 @@ /** | ||
protected update(): void; | ||
protected _getBBox(): BBox; | ||
protected _getBBox2(): BBox2; | ||
protected _getLen(): number; | ||
@@ -22,0 +22,0 @@ /** |
import { vec2 } from 'gl-matrix'; | ||
import { LineCurve } from './line'; | ||
import { PointFn, CoordData } from './curve'; | ||
import { BBox } from '../base'; | ||
import { BBox2 } from '../base'; | ||
export declare const QuadraticCurveType = "curve-quadratic"; | ||
@@ -21,4 +21,3 @@ /** | ||
protected update(): void; | ||
getRoughBBox(): BBox; | ||
protected _getBBox(): BBox; | ||
protected _getBBox2(): BBox2; | ||
protected _getLen(): number; | ||
@@ -55,5 +54,6 @@ getPosition(t: number): vec2; | ||
*### 数值法计算曲率极值点对应的参数,可以是多个 | ||
* @param count 分割点数量(数值越大精度越高) | ||
* @returns 曲率半径极值点对应的参数 | ||
*/ | ||
getCusps(): number[]; | ||
getCusps(count?: number): number[]; | ||
applyFn(fn: PointFn): void; | ||
@@ -60,0 +60,0 @@ applyFFDFn(fn: PointFn): void; |
import { vec2 } from 'gl-matrix'; | ||
/** | ||
* convert angle to radian | ||
* @param angle | ||
* @returns | ||
*/ | ||
export declare function toRadian(angle: number): number; | ||
/** | ||
* convert radian to angle | ||
* @param radian | ||
* @returns | ||
*/ | ||
export declare function toAngle(radian: number): number; | ||
/** | ||
* convert vec2 to angle(not radian) | ||
* @param vec | ||
* @returns | ||
*/ | ||
export declare function vec2ToAngle(vec: vec2): number; | ||
/** | ||
* ### calculate the radius of a circle | ||
@@ -4,0 +22,0 @@ * @param pointA |
@@ -0,1 +1,3 @@ | ||
import { vec2 } from 'gl-matrix'; | ||
export declare function cross(v0: vec2, v1: vec2): number; | ||
export declare function getRandomGenerate(x?: number): () => number; | ||
@@ -21,1 +23,8 @@ export declare function getEaseElasticOut(t: number): number; | ||
export declare function mergeCouple<T>(couples: T[][]): T[][]; | ||
/** | ||
* get the angle change between two vectors | ||
* @param v1 - the first vector | ||
* @param v2 - the second vector | ||
* @returns - the angle change from v1 to v2 | ||
*/ | ||
export declare function getAngleChange(v1: vec2, v2: vec2): number; |
@@ -22,7 +22,2 @@ import { vec2 } from 'gl-matrix'; | ||
intersectLine(line: LineCurve): vec2[]; | ||
/** | ||
* ### split path | ||
* - if a path is consists by multiple closed shapes, then split the path into multiple paths | ||
* - such as we could split a "吕" into two "口" | ||
*/ | ||
splitByBBox(): Path[]; | ||
@@ -29,0 +24,0 @@ splitByCoord(splitData: CoordData): void; |
@@ -43,2 +43,3 @@ import { vec2 } from 'gl-matrix'; | ||
get outDir(): vec2; | ||
getMaxCurvature(): number; | ||
/** | ||
@@ -45,0 +46,0 @@ * ### get the direction of a shape |
@@ -5,22 +5,13 @@ import { vec2 } from 'gl-matrix'; | ||
import { PathCommand } from '../utils'; | ||
export declare class PointNode { | ||
point: vec2; | ||
inVec: vec2; | ||
outVec: vec2; | ||
angle: number; | ||
constructor(point: vec2, inVec: vec2, outVec: vec2); | ||
} | ||
export declare class ClosedShape extends SingleShape { | ||
curves: Curve[]; | ||
nodes: PointNode[]; | ||
constructor(curves: Curve[]); | ||
initNodes(): void; | ||
includePoint(point: vec2): boolean; | ||
/** | ||
* ### split the shape by node angle | ||
* @param angleThreshold the angle threshold to split | ||
* @returns | ||
*/ | ||
splitByAngle(angleThreshold?: number): SingleShape[]; | ||
static fromCommands(commands: PathCommand[]): ClosedShape; | ||
} | ||
/** | ||
* ### split path | ||
* - if a path is consists by multiple closed shapes, then split the path into multiple paths | ||
* - such as we could split a "吕" into two "口" | ||
*/ | ||
export declare function splitByBBox(shapes: ClosedShape[]): ClosedShape[][]; |
@@ -7,1 +7,2 @@ export * from './base-shape'; | ||
export * from './polygon'; | ||
export * from './utils'; |
@@ -6,10 +6,18 @@ import { vec2 } from 'gl-matrix'; | ||
curves: LineCurve[]; | ||
constructor(curves: LineCurve[]); | ||
static fromPoints(points: vec2[]): Polyline; | ||
/** | ||
* the tangent array | ||
* @remarks the polyline with tangent array is actually a curve, because it easy to calculate | ||
* the quadratic curve by the polyline with tangent array which control point is the intersection of two tangent | ||
*/ | ||
tanArr: vec2[]; | ||
constructor(curves: LineCurve[], tanArr?: vec2[]); | ||
static fromPoints(points: vec2[], tanArr?: vec2[]): Polyline; | ||
getDistance(point: vec2): number; | ||
getClosestPoint(point: vec2): vec2; | ||
/** | ||
* 通过曲率来切割 | ||
*/ | ||
split(radiusLimit?: number): Polyline[]; | ||
/**### get max angle deflection */ | ||
getMaxDeflection(): number; | ||
getPosDataByPer(percent: number): { | ||
pos: vec2; | ||
tan: vec2; | ||
}; | ||
} | ||
@@ -28,7 +36,11 @@ export interface DisData { | ||
* ### calculate distance data between two polyline | ||
* @param polyline0 | ||
* @param polyline1 | ||
* @param shape0 | ||
* @param shape1 | ||
* @returns | ||
*/ | ||
export declare function calDisData(polyline0: Polyline, polyline1: Polyline): DisData[]; | ||
export declare function calDisData(shape0: SingleShape, shape1: SingleShape): DisData[]; | ||
/** | ||
* 多段线自交检测 | ||
*/ | ||
export declare function isSelfIntersect(polyline: Polyline): boolean; | ||
export declare function calExtendCurve(polyline: Polyline): { | ||
@@ -39,2 +51,1 @@ k: number; | ||
}; | ||
export declare function connectPolyline(polyline0: Polyline, polyline1: Polyline): Polyline; |
import { vec2 } from 'gl-matrix'; | ||
import { Shape } from './base-shape'; | ||
import { SingleShape } from './single-shape'; | ||
export declare function findRayIntersection(point1: vec2, direction1: vec2, point2: vec2, direction2: vec2): vec2 | null; | ||
export declare function isVec2DirectionClose(a: vec2, normalVec: vec2): boolean; | ||
export declare function connectShape(l0: Shape, l1: Shape): SingleShape; |
@@ -1,1 +0,1 @@ | ||
(function(f,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(f=typeof globalThis<"u"?globalThis:f||self,A(f.geometry={}))})(this,function(f){"use strict";var Tn=Object.defineProperty;var In=(f,A,N)=>A in f?Tn(f,A,{enumerable:!0,configurable:!0,writable:!0,value:N}):f[A]=N;var C=(f,A,N)=>In(f,typeof A!="symbol"?A+"":A,N);function A(){return{xMin:1/0,xMax:-1/0,yMin:1/0,yMax:-1/0}}function N(o,e){return o.xMin=Math.min(o.xMin,e.xMin),o.xMax=Math.max(o.xMax,e.xMax),o.yMin=Math.min(o.yMin,e.yMin),o.yMax=Math.max(o.yMax,e.yMax),o}function ft(o,e){return o.xMin<=e.xMin&&o.xMax>=e.xMax&&o.yMin<=e.yMin&&o.yMax>=e.yMax}var Pt=1e-6,J=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var o=0,e=arguments.length;e--;)o+=arguments[e]*arguments[e];return Math.sqrt(o)});function y(){var o=new J(2);return J!=Float32Array&&(o[0]=0,o[1]=0),o}function T(o){var e=new J(2);return e[0]=o[0],e[1]=o[1],e}function v(o,e){var t=new J(2);return t[0]=o,t[1]=e,t}function Qt(o,e){return o[0]=e[0],o[1]=e[1],o}function st(o,e,t){return o[0]=e[0]+t[0],o[1]=e[1]+t[1],o}function jt(o,e,t){return o[0]=e[0]-t[0],o[1]=e[1]-t[1],o}function Ot(o,e,t){return o[0]=e[0]*t,o[1]=e[1]*t,o}function dt(o,e,t,n){return o[0]=e[0]+t[0]*n,o[1]=e[1]+t[1]*n,o}function E(o,e){var t=e[0]-o[0],n=e[1]-o[1];return Math.hypot(t,n)}function Q(o,e){var t=e[0],n=e[1],i=t*t+n*n;return i>0&&(i=1/Math.sqrt(i)),o[0]=e[0]*i,o[1]=e[1]*i,o}function it(o,e){return o[0]*e[0]+o[1]*e[1]}function L(o,e,t,n){var i=e[0],s=e[1];return o[0]=i+n*(t[0]-i),o[1]=s+n*(t[1]-s),o}function H(o,e){var t=o[0],n=o[1],i=e[0],s=e[1],r=Math.sqrt(t*t+n*n)*Math.sqrt(i*i+s*s),c=r&&(t*i+n*s)/r;return Math.acos(Math.min(Math.max(c,-1),1))}function K(o,e){return o[0]===e[0]&&o[1]===e[1]}function pt(o,e){var t=o[0],n=o[1],i=e[0],s=e[1];return Math.abs(t-i)<=Pt*Math.max(1,Math.abs(t),Math.abs(i))&&Math.abs(n-s)<=Pt*Math.max(1,Math.abs(n),Math.abs(s))}var V=jt,j=E;(function(){var o=y();return function(e,t,n,i,s,r){var c,a;for(t||(t=2),n||(n=0),i?a=Math.min(i*t+n,e.length):a=e.length,c=n;c<a;c+=t)o[0]=e[c],o[1]=e[c+1],s(o,o,r),e[c]=o[0],e[c+1]=o[1];return e}})();class gt{constructor(e,t){C(this,"type","curve");C(this,"_isDirty",!0);C(this,"_SPoint",y());C(this,"_EPoint",y());C(this,"_bbox");C(this,"_len");C(this,"inDir",y());C(this,"ouDir",y());this.SPoint=e,this.EPoint=t,this._isDirty=!1}set SPoint(e){this._isDirty||(this._isDirty=!K(this._SPoint,e)),this._SPoint=e}get SPoint(){return this._SPoint}set EPoint(e){this._isDirty||(this._isDirty=!K(this._EPoint,e)),this._EPoint=e}get EPoint(){return this._EPoint}get bbox(){return(this._isDirty||!this._bbox)&&this.update(),this._bbox}get len(){return(this._isDirty||!this._len&&this._len!==0)&&this.update(),this._len}update(){this._bbox=this._getBBox(),this._len=this._getLen(),this._isDirty=!1}divideAtArray(e){e.sort((s,r)=>s-r);let t=this;const n=new Array(e.length+1);let i=0;for(let s=0;s<e.length;s++){let r=e[s];r=(r-i)/(1-i),i=e[s];const c=t.divideAt(r);n[s]=c[0],t=c[1]}return n[e.length]=t,n}splitByCoord(e){const t=this.getSplitT(e);return this.divideAtArray(t)}}const tt="curve-line";class I extends gt{constructor(t,n){super(t,n);C(this,"tangent");C(this,"normal");this.type=tt,this.tangent=Q(y(),V(y(),n,t)),this.normal=v(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.ouDir=this.tangent}update(){super.update(),this.tangent=Q(y(),V(y(),this.EPoint,this.SPoint)),this.normal=v(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.ouDir=this.tangent}_getBBox(){const{SPoint:t,EPoint:n}=this,i=Math.min(t[0],n[0]),s=Math.min(t[1],n[1]),r=Math.abs(t[0]-n[0]),c=Math.abs(t[1]-n[1]);return{x:i,y:s,width:r,height:c}}_getLen(){return E(this.SPoint,this.EPoint)}getNormal(t){return this.normal}getTangent(t){return this.tangent}getMaxCurvature(){return 0}getPosition(t){return L(y(),this.SPoint,this.EPoint,t)}getPosDataByPer(t){const n=this.getPosition(t),i=this.tangent;return{pos:n,tan:i}}getSplitT(t){const{x:n,y:i,width:s,height:r}=this.bbox,{SPoint:c,EPoint:a}=this,{mode:h,val:l}=t,u=[];return h==="x"&&l>=n&&l<=n+s?u.push((l-c[0])/(a[0]-c[0])):h==="y"&&l>=i&&l<=i+r&&u.push((l-c[1])/(a[1]-c[1])),u}getLineIntersects(t){const[n,i]=this.SPoint,[s,r]=this.EPoint,[c,a]=t.SPoint,[h,l]=t.EPoint,u=[],d=(n-s)*(a-l)-(i-r)*(c-h);if(Math.abs(d)>1e-10){const p=n*r-i*s,P=c*l-a*h,g=(p*(c-h)-P*(n-s))/d,x=(p*(a-l)-P*(i-r))/d,{x:M,y:S,width:m,height:w}=this.bbox;g>=M&&g<=g+m&&x>=S&&x<=S+w&&u.push(v(g,x))}return u}getDisToPos(t){const{SPoint:n,EPoint:i,tangent:s}=this,r=V(y(),t,n),c=it(r,s);if(c<0)return E(n,t);const a=E(n,i);if(c>a)return E(i,t);const h=v(-s[1],s[0]);return Math.abs(it(h,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()}divideAt(t){const{SPoint:n,EPoint:i}=this,s=this.getPosition(t);return[new I(n,s),new I(T(s),i)]}isPointOnCurve(t){const{SPoint:n,EPoint:i}=this,s=E(n,t),r=E(i,t),c=E(n,i);return Math.abs(s+r-c)<1e-10}toPathString(t=0){const[n,i]=this.EPoint;return`L ${n.toFixed(t)} ${i.toFixed(t)}`}toDebugPathString(t){return this.toPathString(t)}clone(){return new I(T(this.SPoint),T(this.EPoint))}}function yt(o,e,t,n){const[i,s]=o,[r,c]=e,[a,h]=t,[l,u]=n,d=c-s,p=i-r,P=r*s-i*c,g=u-h,x=a-l,M=l*h-a*u,S=d*x-g*p,m=(p*M-x*P)/S,w=(g*P-d*M)/S;return v(m,w)}function xt(o,e){const[t,n]=o.SPoint,[i,s]=o.EPoint,[r,c]=e.SPoint,[a,h]=e.EPoint,{x:l,y:u,width:d,height:p}=o.bbox,{x:P,y:g,width:x,height:M}=e.bbox;if(l+d<P||P+x<l||u+p<g||g+M<u)return!1;const S=(t-r)*(h-c)-(n-c)*(a-r),m=(i-r)*(h-c)-(s-c)*(a-r);if(S*m>0)return!1;const w=(r-t)*(s-n)-(c-n)*(i-t),B=(a-t)*(s-n)-(h-n)*(i-t);return!(w*B>0)}const Y=1e-12;function F(o){switch(o.length){case 0:return[];case 1:return[0];case 2:return Math.abs(o[0])<Y?[]:[-o[1]/o[0]];case 3:return Math.abs(o[0])<Y?F(o.slice(1)):Zt(o);case 4:return Math.abs(o[0])<Y?F(o.slice(1)):Ht(o);default:throw new Error("Not implemented")}}function Zt(o){const e=o[0],t=o[1],n=o[2],i=t*t-4*e*n;if(i<0)return[];{const s=Math.sqrt(i);return[(-t+s)/(2*e),(-t-s)/(2*e)]}}function Ht(o){const e=o[0],t=o[1],n=o[2],i=o[3],s=t/e,r=n/e,c=i/e,a=(3*r-s*s)/9,h=(9*s*r-27*c-2*s*s*s)/54,l=a*a*a+h*h;if(l>=0){const u=Math.sqrt(l),d=Math.cbrt(h+u),p=Math.cbrt(h-u),P=[-s/3+(d+p)];return l===0&&P.push(-d/2),P}else{const u=Math.acos(h/Math.sqrt(-a*a*a)),d=Math.sqrt(-a);return[2*d*Math.cos(u/3)-s/3,2*d*Math.cos((u+2*Math.PI)/3)-s/3,2*d*Math.cos((u+4*Math.PI)/3)-s/3]}}function Yt(o,e,t){[o[e],o[t]]=[o[t],o[e]]}function Xt(o){const{length:e}=o;for(let n=0;n<e;n++){let i=n;for(let s=n+1;s<e;s++)Math.abs(o[s][n])>Math.abs(o[i][n])&&(i=s);Yt(o,n,i);for(let s=n+1;s<e;s++){if(Math.abs(o[n][n])<Y)continue;const r=o[s][n]/o[n][n];for(let c=n;c<e+1;c++)o[s][c]-=r*o[n][c]}}const t=new Array(e).fill(0);for(let n=e-1;n>=0;n--)if(!(Math.abs(o[n][n])<Y)){t[n]=o[n][e]/o[n][n];for(let i=n-1;i>=0;i--)o[i][e]-=o[i][n]*t[n]}return console.log(o),t}const nt=100,mt="curve-quadratic";class _ extends I{constructor(t,n,i){super(t,i);C(this,"_CPoint1",y());C(this,"_lenArr",new Array(nt).fill(0));this.type=mt,this.CPoint1=n,this.inDir=Q(y(),V(y(),n,t)),this.ouDir=Q(y(),V(y(),i,n))}set CPoint1(t){this._isDirty||(this._isDirty=!K(this._CPoint1,t)),this._CPoint1=t}get CPoint1(){return this._CPoint1}update(){super.update(),this.inDir=this.getTangent(0),this.ouDir=this.getTangent(1)}getRoughBBox(){const[t,n]=this.SPoint,[i,s]=this.CPoint1,[r,c]=this.EPoint,a=Math.min(t,i,r),h=Math.max(t,i,r),l=Math.min(n,s,c),u=Math.max(n,s,c);return{x:a,y:l,width:h-a,height:u-l}}_getBBox(){const t=this.SPoint[0],n=this.SPoint[1],i=this.CPoint1[0],s=this.CPoint1[1],r=this.EPoint[0],c=this.EPoint[1],a=[2*(t-2*i+r),2*(i-r)],h=[2*(n-2*s+c),2*(s-c)],l=F(a),u=F(h),d=l.filter(w=>w>0&&w<1).concat([0,1]),p=u.filter(w=>w>0&&w<1).concat([0,1]),P=d.map(w=>this.getPosition(w)[0]),g=p.map(w=>this.getPosition(w)[1]),x=Math.min(...P),M=Math.max(...P),S=Math.min(...g),m=Math.max(...g);return{x,y:S,width:M-x,height:m-S}}_getLen(){let t=0,n=this.getPosition(0);for(let i=1;i<=nt;i++){let s=this.getPosition(i/100);t+=E(n,s),n=s,this._lenArr[i-1]=t}return t}getPosition(t){const n=(1-t)**2,i=2*t*(1-t),s=t**2,r=n*this.SPoint[0]+i*this.CPoint1[0]+s*this.EPoint[0],c=n*this.SPoint[1]+i*this.CPoint1[1]+s*this.EPoint[1];return v(r,c)}getPosDataByPer(t){let n=0,i=this._lenArr.length-1,s;const r=this.len*t;for(;n<i;)s=Math.floor((n+i)/2),this._lenArr[s]<r?n=s+1:i=s;const c=this._lenArr[n-1]||0;let a=n/nt;a+=(r-c)/(this._lenArr[n]-c)/nt;const h=this.getPosition(a),l=this.getTangent(a);return{pos:h,tan:l}}getTangent(t){const n=this.getDerivative(t);return Q(n,n)}getNormal(t){const[n,i]=this.getTangent(t);return v(i,-n)}getMaxCurvature(){const t=this.getCusps();let n=0;for(const i of t){const s=this.getCurvature(i);Math.abs(s)>Math.abs(n)&&(n=s)}return n}getSplitT(t){const{x:n,y:i,width:s,height:r}=this.bbox,{mode:c,val:a}=t;if(c==="x"){if(a>=n&&a<=n+s){const h=[this.SPoint[0]-2*this.CPoint1[0]+this.EPoint[0],2*(this.CPoint1[0]-this.EPoint[0]),this.EPoint[0]-a];return F(h).filter(u=>u>0&&u<1)}}else if(a>=i&&a<=i+r){const h=[this.SPoint[1]-2*this.CPoint1[1]+this.EPoint[1],2*(this.CPoint1[1]-this.EPoint[1]),this.EPoint[1]-a];return F(h).filter(u=>u>0&&u<1)}return[]}getLineIntersects(t){const n=[],[i,s]=this.SPoint,[r,c]=this.CPoint1,[a,h]=this.EPoint,[l,u]=t.SPoint,d=i-2*r+a,p=s-2*c+h,P=2*(r-i),g=2*(c-s),x=i,M=s,[S,m]=V(y(),t.EPoint,t.SPoint),w=S*p-m*d,B=S*g-m*P,b=S*M-m*x-S*u+m*l,R=F([w,B,b]);for(const D of R)if(D>=0&&D<=1){const W=(1-D)**2*i+2*D*(1-D)*r+D**2*a,Z=(1-D)**2*s+2*D*(1-D)*c+D**2*h;n.push(v(W,Z))}return n}getDisToPos(t){let n=100,i=1/0;for(let s=0;s<=n;s++){const r=s/n,c=this.getPosition(r),a=E(t,c);a<i&&(i=a)}return i}getDisToPos2(t){const[n,i]=this.SPoint,[s,r]=this.CPoint1,[c,a]=this.EPoint,[h,l]=t,u=[[-(n-2*s+c),-2*(s-n),h-n],[-(i-2*r+a),-2*(r-i),l-i]],d=[[2*(n-2*s+c),2*(s-n)],[2*(i-2*r+a),2*(r-i)]],p=new Array(4).fill(0);for(let M=0;M<2;M++)for(let S=0;S<2;S++)for(let m=0;m<3;m++)p[S+m]+=d[M][S]*u[M][m]+d[M][S]*u[M][m];const g=[...F(p).filter(M=>M*(M-1)<0),0,1];let x=1/0;for(let M of g){const S=this.getPosition(M),m=E(t,S);m<x&&(x=m)}return x}getDerivative(t){const n=2*(1-t)*(this.CPoint1[0]-this.SPoint[0])+2*t*(this.EPoint[0]-this.CPoint1[0]),i=2*(1-t)*(this.CPoint1[1]-this.SPoint[1])+2*t*(this.EPoint[1]-this.CPoint1[1]);return v(n,i)}getSecondDerivative(t){const n=2*(this.EPoint[0]-2*this.CPoint1[0]+this.SPoint[0]),i=2*(this.EPoint[1]-2*this.CPoint1[1]+this.SPoint[1]);return v(n,i)}getCurvature(t){const[n,i]=this.getDerivative(t),[s,r]=this.getSecondDerivative(t),c=n*r-i*s;if(c<1e-20)return 0;const a=n**2+i**2;return a<1e-20?1/0:c/a**1.5}getCusps(){const n=new Array(21);for(let s=0;s<=20;s++){const r=s/20,c=this.getCurvature(r);n[s]=c}const i=[];for(let s=1;s<20;s++)(n[s]-n[s-1])*(n[s]-n[s+1])>0&&i.push(s/20);return n[0]*(n[0]-n[1])>0&&i.unshift(0),n[20]*(n[20]-n[19])>0&&i.push(1),i}applyFn(t){t(this.SPoint),t(this.EPoint),t(this.CPoint1)}applyFFDFn(t){this.applyFn(t);const n=v(this.CPoint1[0]-.5*(this.SPoint[0]+this.EPoint[0]),this.CPoint1[1]-.5*(this.SPoint[1]+this.EPoint[1]));st(this.CPoint1,this.CPoint1,n)}divideAt(t){const n=this.SPoint,i=this.EPoint,s=this.CPoint1,r=L(y(),n,s,t),c=L(y(),s,i,t),a=L(y(),r,c,t),h=new _(n,r,a),l=new _(T(a),c,i);return[h,l]}divideAtArray(t){return super.divideAtArray.call(this,t)}pathOffset(t){const i=[0,.5,1].map(c=>{const a=this.getPosition(c),h=this.getNormal(c);return dt(y(),a,h,t)}),s=L(y(),i[0],i[2],.5),r=L(s,s,i[1],2);return new _(i[0],r,i[2])}splitByCoord(t){const n=this.getSplitT(t);return this.divideAtArray(n)}toPathString(t=0){return`Q ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}toDebugPathString(t){return`L ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} L ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}toPoints(t=10){const n=new Array(t),i=1/t;for(let s=1;s<=t;s++){const r=this.getPosition(s*i);n[s-1]=r}return n.reverse()}clone(){return new _(T(this.SPoint),T(this.CPoint1),T(this.EPoint))}}function Gt(o){const e=o.SPoint,t=o.EPoint,n=v((e[0]+t[0])/2,(e[1]+t[1])/2);return new _(e,n,t)}const Mt="curve-bezier";class q extends _{constructor(t,n,i,s){super(t,n,s);C(this,"_CPoint2",y());this.type=Mt,this.CPoint2=i}set CPoint2(t){this._isDirty||(this._isDirty=!K(this._CPoint2,t)),this._CPoint2=t}get CPoint2(){return this._CPoint2}_getBBox(){const[t,n]=this.SPoint,[i,s]=this.CPoint1,[r,c]=this.CPoint2,[a,h]=this.EPoint,l=[-3*t+9*i-9*r+3*a,6*t-12*i+6*r,3*i-3*t],u=[-3*n+9*s-9*c+3*h,6*n-12*s+6*c,3*s-3*n],d=F(l),p=F(u),P=d.filter(b=>b>0&&b<1).concat([0,1]),g=p.filter(b=>b>0&&b<1).concat([0,1]),x=P.map(b=>this.getPosition(b)[0]),M=g.map(b=>this.getPosition(b)[1]),S=Math.min(...x),m=Math.max(...x),w=Math.min(...M),B=Math.max(...M);return{x:S,y:w,width:m-S,height:B-w}}getSplitT(t){const{x:n,y:i,width:s,height:r}=this.bbox,{mode:c,val:a}=t,h=c==="y"?1:0;if(a<[n,i][h]||a>[n+s,i+r][h])return[];{const l=[-this.SPoint[h]+3*this.CPoint1[h]-3*this.CPoint2[h]+this.EPoint[h],3*this.SPoint[h]-6*this.CPoint1[h]+3*this.CPoint2[h],-3*this.SPoint[h]+3*this.CPoint1[h],this.SPoint[h]-a],u=F(l),d=1e-8;return u.filter(p=>p>d&&p<1-d)}}getPosition(t){let n=(1-t)**3,i=3*t*(1-t)*(1-t),s=3*t*t*(1-t),r=t**3,c=n*this.SPoint[0]+i*this.CPoint1[0]+s*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+i*this.CPoint1[1]+s*this.CPoint2[1]+r*this.EPoint[1];return v(c,a)}getTangent(t){const n=this.getDerivative(t);return Q(n,n)}getNormal(t){const[n,i]=this.getTangent(t);return v(i,-n)}getDisToPos2(t){return console.error("bezier has no analytical solution for getDisToPos2"),this.getDisToPos(t)}getDerivative(t){let n=-3*(1-t)**2,i=3*(1-4*t+3*t**2),s=3*(2*t-3*t**2),r=3*t**2,c=n*this.SPoint[0]+i*this.CPoint1[0]+s*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+i*this.CPoint1[1]+s*this.CPoint2[1]+r*this.EPoint[1];return v(c,a)}getSecondDerivative(t){let n=6*(1-t),i=6*(3*t-2),s=6*(1-3*t),r=6*t,c=n*this.SPoint[0]+i*this.CPoint1[0]+s*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+i*this.CPoint1[1]+s*this.CPoint2[1]+r*this.EPoint[1];return v(c,a)}applyFn(t){t(this.SPoint),t(this.EPoint),t(this.CPoint1),t(this.CPoint2)}applyFFDFn(t){const{SPoint:n,EPoint:i}=this,s=[.4,.6],r=s.map(B=>{const b=this.getPosition(B);return t(b),b});t(n),t(i);const c=(B,b)=>{const R=(1-B)**3,D=3*B*(1-B)**2,W=3*B**2*(1-B),Z=B**3;return[D,W,b[0]-Z*i[0]-R*n[0],b[1]-Z*i[1]-R*n[1]]},[a,h,l,u]=c(s[0],r[0]),[d,p,P,g]=c(s[1],r[1]),x=1/(h*d-a*p),M=(h*P-p*l)*x,S=(h*g-p*u)*x,m=(d*l-a*P)*x,w=(d*u-a*g)*x;this.CPoint1=v(M,S),this.CPoint2=v(m,w)}reverse(){[this.CPoint1,this.CPoint2]=[this.CPoint2,this.CPoint1],super.reverse()}getLineIntersects(t){const{bbox:n}=this;if(n.x>t.bbox.x+t.bbox.width||n.x+n.width<t.bbox.x||n.y>t.bbox.y+t.bbox.height||n.y+n.height<t.bbox.y)return[];const i=[],[s,r]=this.SPoint,[c,a]=this.CPoint1,[h,l]=this.CPoint2,[u,d]=this.EPoint,[p,P]=t.SPoint,g=-s+3*c-3*h+u,x=-r+3*a-3*l+d,M=3*s-6*c+3*h,S=3*r-6*a+3*l,m=-3*s+3*c,w=-3*r+3*a,B=s,b=r,[R,D]=V(y(),t.EPoint,t.SPoint),W=R*x-D*g,Z=R*S-D*M,bn=R*w-D*m,Dn=R*b-D*B-(R*P-D*p),Ln=F([W,Z,bn,Dn]);for(const z of Ln)if(z>=0&&z<=1){const Bn=g*z**3+M*z**2+m*z+B,An=x*z**3+S*z**2+w*z+b;i.push(v(Bn,An))}return i}divideAt(t){const n=this.SPoint,i=this.EPoint,s=this.CPoint1,r=this.CPoint2,c=L(y(),n,s,t),a=L(y(),s,r,t),h=L(y(),r,i,t),l=L(y(),c,a,t),u=L(y(),a,h,t),d=this.getPosition(t),p=new q(n,c,l,d),P=new q(T(d),u,h,i);return[p,P]}divideAtArray(t){return super.divideAtArray.call(this,t)}splitByCoord(t){const n=this.getSplitT(t);return this.divideAtArray(n)}toPathString(t=0){return`C ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} ${this.CPoint2[0].toFixed(t)} ${this.CPoint2[1].toFixed(t)} ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}toDebugPathString(t){return` L ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} L ${this.CPoint2[0].toFixed(t)} ${this.CPoint2[1].toFixed(t)} L ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}clone(){return new q(T(this.SPoint),T(this.CPoint1),T(this.CPoint2),T(this.EPoint))}}function vt(o){if(o instanceof q)return o;if(o instanceof I)return St(o);if(o instanceof _)return Ct(o);throw new Error("Unsupported curve type.")}function St(o){const{SPoint:e,EPoint:t}=o,n=L(y(),e,t,1/3),i=L(y(),e,t,2/3);return new q(e,n,i,t)}function Ct(o){const{SPoint:e,CPoint1:t,EPoint:n}=o,i=L(y(),e,t,2/3),s=L(y(),n,t,2/3);return new q(e,i,s,n)}class Ut{constructor(e){C(this,"points");C(this,"bbox");this.points=e,this.bbox={xMin:1/0,xMax:-1/0,yMin:1/0,yMax:-1/0};for(let t of this.points)this.bbox.xMin=Math.min(this.bbox.xMin,t[0]),this.bbox.xMax=Math.max(this.bbox.xMax,t[0]),this.bbox.yMin=Math.min(this.bbox.yMin,t[1]),this.bbox.yMax=Math.max(this.bbox.yMax,t[1])}getArea(){return Math.abs(this.getSignArea())}getSignArea(){return X(this.points)}getCentroid(){let e=this.getSignArea(),t=0,n=0;for(let i=0;i<this.points.length;i++){let[s,r]=this.points[i],[c,a]=this.points[(i+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]}includePoint(e){return e[0]<this.bbox.xMin||e[0]>this.bbox.xMax||e[1]<this.bbox.yMin||e[1]>this.bbox.yMax?!1:rt(e,this.points)}includePolygon(e){if(e.bbox.xMin<this.bbox.xMin||e.bbox.xMax>this.bbox.xMax||e.bbox.yMin<this.bbox.yMin||e.bbox.yMax>this.bbox.yMax)return!1;for(let t of e.points)if(!this.includePoint(t))return!1;return!0}intersectPolygon(e){for(let t of e.points)if(this.includePoint(t))return!0;return!1}}function X(o){let e=0;const{length:t}=o;for(let n=0;n<t;n++){let[i,s]=o[n],[r,c]=o[(n+1)%t];e+=i*c-r*s}return e/2}function ot(o){return X(o)>0}function Wt(o,e){let[t,n]=o,[[i,s],[r,c]]=e;return(t-i)*(c-s)-(n-s)*(r-i)>0}function rt(o,e){let[t,n]=o,i=!1;for(let s=0,r=e.length-1;s<e.length;r=s++){let[c,a]=e[s],[h,l]=e[r];a>n!=l>n&&t-c<(h-c)*(n-a)/(l-a)&&(i=!i)}return i}class wt{constructor(e){C(this,"curves",[]);C(this,"points",[]);C(this,"_isRightHand");C(this,"_len");C(this,"_lenArr",[]);C(this,"_bbox2");this.curves=e,this.initPoints()}initPoints(){const{length:e}=this.curves;if(e!==0){this.points=new Array(e),this.points[0]=this.curves[0].SPoint;for(let t=0;t<e;t++)this.points[t+1]=this.curves[t].EPoint}}get isRightHand(){return this._isRightHand===void 0&&(this._isRightHand=this.getIsClockwise()),this._isRightHand}get isClosed(){return this.curves.length>0&&j(this.SPoint,this.EPoint)<.001}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].ouDir}getIsClockwise(){const{points:e}=this;return ot(e)}_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=A()){for(const{bbox:t}of this.curves){const{x:n,y:i,width:s,height:r}=t;e.xMin=Math.min(e.xMin,n),e.xMax=Math.max(e.xMax,n+s),e.yMin=Math.min(e.yMin,i),e.yMax=Math.max(e.yMax,i+r)}return e}getLineIntersects(e){const{curves:t}=this,{length:n}=t,i=new Array(n);for(let s=0;s<n;s++){const c=t[s].getLineIntersects(e);i[s]=c}return i.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],u=e*n/this.curves[0].len;return l.getPosDataByPer(u)}if(e>=1){const l=this.curves[this.curves.length-1],u=(e-1)*n/l.len+1;return l.getPosDataByPer(u)}let i=0,s=this._lenArr.length-1,r;for(;i<s;)r=Math.floor((i+s)/2),this._lenArr[r]<n?i=r+1:s=r;const c=this.curves[i],a=i===0?0:this._lenArr[i-1],h=(n-a)/c.len;return c.getPosDataByPer(h)}splitByCoord(e){const t=[];for(const n of this.curves){const i=n.splitByCoord(e);t.push(...i)}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,i=new Array(n*e);for(let s=0;s<n;s++){const c=this.curves[s].divideAtArray(t);i.splice(s*e,e,...c)}this.curves=i}reverse(){this.curves.reverse();for(const e of this.curves)e.reverse();this.points.reverse(),this._getLen()}toPathString(e=0){let t=this.curves[0].SPoint,n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `,i=t;for(const r of this.curves){if(!(E(i,r.SPoint)<1)){const{SPoint:a}=r;n+=`M ${a[0].toFixed(e)} ${a[1].toFixed(e)} `,t=a}n+=r.toPathString(e)+" ",i=r.EPoint}return E(i,t)<1&&(n+="Z"),n}toPoints(e=100){let t=new Array(e+1);for(let n=0;n<=e;n++){const i=n/e,{pos:s}=this.getPosDataByPer(i);t[n]=s}return t}}function Jt(o){const e=E(o[0].SPoint,o[o.length-1].EPoint)<1;let t=0;if(e){let s=0;for(let r=0;r<o.length;r++){const a=o[r].len;a>s&&(s=a,t=r)}}let n=[o[t]];for(let s=1;s<o.length;s++){const r=(s+t)%o.length,c=o[r],a=n[n.length-1];c.type===tt&&a.type===tt&&it(c.inDir,a.ouDir)>.99?a.EPoint=c.EPoint:n.push(c)}o=n,n=[o[0]];const i=(s,r,c)=>{const{len:a}=s,{len:h}=r,{len:l}=c,u=20;if(a>u*h&&l>u*h){const p=H(s.ouDir,r.inDir),P=H(r.ouDir,c.inDir);if(p<P)s.EPoint=r.EPoint;else return c.SPoint=r.SPoint,!0}else n.push(r)};for(let s=1;s<o.length-1;s++){const r=n[n.length-1],c=o[s],a=o[s+1];i(r,c,a)&&(n.push(a),s++)}return e?i(n[n.length-1],o[o.length-1],o[0]):n.push(o[o.length-1]),n}function Kt(o){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",o),e.appendChild(t),e}function Et(o,e=1){const t=o[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return o.forEach(i=>{n+=i.toPathString(e)+" "}),n+="Z",n}function tn(o,e=1){const t=o[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return o.forEach(i=>{n+=i.toDebugPathString(e)+" "}),n}function ct(o){const e=/([MmLlHhVvCcSsQqTtAaZz])|([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/g,t=o.match(e);if(!t)throw new Error("Invalid path string");const n=[];let i=null,s=[];for(const r of t)isNaN(parseFloat(r))?(i&&(n.push({type:i,args:s}),s=[]),i=r):s.push(parseFloat(r));return i&&n.push({type:i,args:s}),n}function nn(o,e,t){const n=[],i=o.length,s=e.length;for(let r=0;r<s;r++){const c=L(y(),o[r%i],e[r],t);n.push(c)}return n}function en(o,e){const{length:t}=o;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),i=new Array(t);for(let s=0;s<t;s++)n[s]=o[s][0],i[s]=o[s][1];return s=>{if(s<0||s>1)throw new Error("out of bbox2");s=s*t+e;const r=bt(n,e,s),c=bt(i,e,s);return v(r,c)}}function bt(o,e,t){const{length:n}=o,i=n+e,s=Math.floor(t),r=new Array(i);for(let c=0;c<i;c++)r[c]=o[c%n];for(let c=0;c<e;c++)for(let a=s;a>s-e+c;a--){const h=(t-a)/(e-c);r[a]=h*r[a]+(1-h)*r[a-1]}return r[s]}function Dt(o,e,t,n=0,i=0,s=.1){const r=[],c=o/2,a=e/2,h=$t(s);let l=u=>{const p=h()*n+(1-n);let P=(p*Math.cos(u)+1)*c,g=(p*Math.sin(u)+1)*a;return v(P,g)};for(let u=0;u<t;u++){let d=l(2*Math.PI*(u/t+i));r.push(d)}return r}function Lt(o){let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const s of o){const{bbox:r}=s;e=Math.min(e,r.x),t=Math.min(t,r.y),n=Math.max(n,r.x+r.width),i=Math.max(i,r.y+r.height)}return{x:e,y:t,width:n-e,height:i-t}}function Bt(o,e){const t=Lt(o),n=e.width/t.width,i=e.height/t.height;for(const s of o)s.applyFn(r=>{r[0]=(r[0]-t.x)*n+e.x,r[1]=(r[1]-t.y)*i+e.y})}function At(o,e=3){const t=[],i=new Array(100),s=en(o,Number(e)),r=performance.now();for(let a=0;a<100;a++)i[a]=s(a/100);performance.now()-r;const c=new Array(100);for(let a=0;a<100;a++){const h=v(i[a][0],i[a][1]),l=v(i[(a+1)%100][0],i[(a+1)%100][1]),u=L(y(),h,l,.5);c[a]=u}for(let a=0;a<100;a++){const h=T(c[a]),l=c[(a+1)%100],u=i[(a+1)%100];t.push(new _(h,u,l))}return t}function sn(o=100,e=100,t=6,n=.5,i=Math.random(),s=3){const r=Dt(o,e,t,n,i),c=At(r,s);return Bt(c,{x:0,y:0,width:o,height:e}),Et(c)}class k extends wt{constructor(t){super(t);C(this,"currentPos",y())}moveTo(t,n){this.currentPos=v(t,n)}lineTo(t,n){const i=new I(this.currentPos,v(t,n));this.curves.push(i),this.currentPos=v(t,n)}bezierCurveTo(t,n,i,s,r,c){const a=new q(this.currentPos,v(t,n),v(i,s),v(r,c));this.curves.push(a),this.currentPos=v(r,c)}quadraticCurveTo(t,n,i,s){const r=new _(this.currentPos,v(t,n),v(i,s));this.curves.push(r),this.currentPos=v(i,s)}closePath(){const t=this.curves[0].SPoint;if(pt(this.currentPos,t))return;const n=new I(this.currentPos,this.curves[0].SPoint);this.curves.push(n)}static fromCommands(t){const n=new k([]);let i=0;for(let s=0;s<t.length;s++){const r=t[s],{type:c,args:a=[]}=r,h=a.length,{x:l=a[h-2],y:u=a[h-1],x1:d=a[0],y1:p=a[1],x2:P=a[2],y2:g=a[3]}=r;switch(c){case"M":n.moveTo(l,u),i++,i>1&&console.error("SimpleShape can only have one start point");break;case"L":pt(n.currentPos,v(l,u))||n.lineTo(l,u);break;case"H":n.lineTo(l,n.currentPos[1]);break;case"V":n.lineTo(n.currentPos[0],u);break;case"C":n.bezierCurveTo(d,p,P,g,l,u);break;case"Q":n.quadraticCurveTo(d,p,l,u);break;case"Z":n.closePath();break}}return n}static fromPathString(t){const n=ct(t);return k.fromCommands(n)}}class Tt extends k{constructor(t){super(t);C(this,"curves");this.curves=t}}function on(o){const e=o.curves.map(t=>vt(t));return new Tt(e)}class It{constructor(e,t,n){C(this,"angle");this.point=e,this.inVec=t,this.outVec=n,this.angle=H(this.inVec,this.outVec)}}class G extends k{constructor(t){super(t);C(this,"nodes",[]);this.curves=t,this.initNodes()}initNodes(){let{curves:t}=this;const{length:n}=t;for(let i=0;i<n;i++){const s=t[i],r=t[(i-1+n)%n],c=s.SPoint;this.nodes[i]=new It(c,r.ouDir,s.inDir)}this.curves=t,this.initPoints()}includePoint(t){const{xMin:n,xMax:i,yMin:s,yMax:r}=this.bbox2;return t[0]<n||t[0]>i||t[1]<s||t[1]>r?!1:rt(t,this.points)}splitByAngle(t=60){t*=Math.PI/180;const{curves:n,nodes:i}=this,{length:s}=n,r=[];let c=[];n[0];for(let h=0;h<s;h++){const l=n[h],{angle:u}=i[h];u>t?(c.length&&r.push(c),c=[l]):c.push(l)}if(c.length){const{angle:h}=i[0];h<=t&&r.length?r[0]=c.concat(r[0]):r.push(c)}return r.map(h=>new k(h))}static fromCommands(t){const{length:n}=t;(t[0].type!=="M"||t[n-1].type!=="Z")&&console.error("ClosedShape must start with M and end with Z");const i=super.fromCommands(t);return new G(i.curves)}}class U extends k{constructor(t){super(t);C(this,"curves");this.curves=t}static fromPoints(t){let n=[];for(let i=0;i<t.length-1;i++)n.push(new I(t[i],t[i+1]));return new U(n)}getDistance(t){let n=1/0;for(let i of this.points)n=Math.min(n,j(i,t));return n}getClosestPoint(t){let n=1/0,i=y();for(let s of this.points){let r=j(s,t);r<n&&(n=r,i=s)}return i}split(t=100){const{points:n}=this,i=cn(n,t),s=Ft(n,i);let r=[];return s.forEach(c=>{const a=rn(c),h=Ft(c,a);r.push(...h)}),r.filter(c=>c.length>=2).map(c=>U.fromPoints(c))}}function rn(o,e=[2,4,8,16,32]){const{length:t}=o;let n=0,i=0,s=new Set;for(let a=0;a<e.length;a++){const h=e[a];if(t<2*h)break;for(let l=h;l<t-h;l++){const u=o[l-h],d=o[l],p=o[l+h],P=V(y(),d,u),g=V(y(),p,d),x=Math.max(H(P,g)*180/Math.PI,0);n<x&&(n=x,i=l),x>120&&s.add(l)}}const r=Array.from(s).sort((a,h)=>a-h);return r.length<=1?r:[i]}function cn(o,e=100){const{length:t}=o,n=new Array(t-2);for(let s=1;s<t-1;s++){const r=o[s-1],c=o[s],a=o[s+1];n[s-1]=_t(r,c,a)}const i=[];for(let s=1;s<n.length-1;s++){const[r,c,a]=[n[s-1],n[s],n[s+1]];Math.abs(c)<Math.abs(r)&&Math.abs(c)<Math.abs(a)&&(c>1/e||c<-1/(2*e))&&i.push(s+1)}return i}function Ft(o,e){const{length:t}=e,n=new Array(t+1);let i=0;for(let s=0;s<t;s++){const r=e[s],c=o.slice(i,r+1);n[s]=c,i=r}return i<o.length&&(n[t]=o.slice(i)),n}function an(o,e){const{points:t}=o,{points:n}=e,{length:i}=t,{length:s}=n,r={datas:[],min:1/0,max:1/0,mean:1/0,std:1/0};if(!(o.isClosed||e.isClosed)){const p=new I(o.EPoint,e.SPoint),P=new I(e.EPoint,o.SPoint);if(xt(p,P))return[r,r]}const a=[...t,...n];if(!ot(a))return[r,r];const l=new Array(i).fill({dis:1/0,index:-1}),u=new Array(s).fill({dis:1/0,index:-1});for(let p=0;p<i;p++)for(let P=0;P<s;P++){const g=j(t[p],n[P]);g<l[p].dis&&(l[p]={dis:g,index:P}),g<u[P].dis&&(u[P]={dis:g,index:p})}return[l,u].map(p=>{const P=p.map(({dis:m})=>m),g=Math.min(...P),x=Math.max(...P),M=P.reduce((m,w)=>m+w,0)/P.length,S=Math.sqrt(P.map(m=>Math.pow(m-M,2)).reduce((m,w)=>m+w,0)/P.length);return{datas:p,min:g,max:x,mean:M,std:S}})}function hn(o){const{points:e,bbox2:t}=o,n=Math.min(e.length,5),i=e.slice(-n),s=i.map(([l])=>l),r=i.map(([,l])=>l),{k:c,b:a,R2:h}=Vt(s,r);return{k:c,b:a,R2:h}}function ln(o,e){const t=j(o.EPoint,e.SPoint);let n=[...o.points];if(t<.1)n=n.concat(e.points.slice(1));else{const i=H(o.outDir,e.inDir),s=j(o.points[0],o.points[1]);if(t>s){let r;if(i<Math.PI/36)r=new I(o.EPoint,e.SPoint);else{const a=o.EPoint,h=st(y(),o.EPoint,o.outDir),l=st(y(),e.SPoint,e.inDir),u=e.SPoint,d=yt(a,h,l,u);r=new _(o.EPoint,d,e.SPoint)}const{len:c}=r;for(let a=1;a*s<c;a++){const h=a*s/c;n.push(r.getPosDataByPer(h).pos)}}n=n.concat(e.points)}return U.fromPoints(n)}function un(o,e,t){const n=E(o,e),i=E(e,t),s=E(t,o),r=(n+i+s)/2;return n*i*s/4/Math.sqrt(r*(r-n)*(r-i)*(r-s))}function _t(o,e,t){const n=E(o,e),i=E(e,t),s=E(t,o);return X([o,e,t])/(n*i*s)}function fn(o){return new Array(o).fill(0).map(()=>new Array(o))}function Pn(o){return o.map(e=>e.slice())}function dn(o){return Math.max(...o)}function pn(o){return Math.min(...o)}function $(o){return o.reduce((e,t)=>e+t,0)}function et(o){return $(o)/o.length}function gn(o){return et(o),Math.sqrt(Rt(o))}function Rt(o){const e=et(o);return et(o.map(t=>Math.pow(t-e,2)))}function yn(o){const e=o.slice().sort((n,i)=>n-i),t=Math.floor(o.length/2);return o.length%2!==0?e[t]:(e[t-1]+e[t])/2}function Vt(o,e){const t=o.length,n=$(o),i=$(e),s=i/t,r=$(o.map((P,g)=>P*e[g])),c=$(o.map(P=>P*P)),a=1e-10;if(t*c-n*n<a)return{k:1/0,b:n/t,R2:1};const h=(t*r-n*i)/(t*c-n*n),l=(i-h*n)/t,u=Math.max(a,$(e.map(P=>Math.pow(P-s,2)))),p=Math.max(a,$(o.map(P=>Math.pow(h*P+l-s,2))))/u;return{k:h,b:l,R2:p}}function xn(o,e,t){return Math.abs(X([o,e,t]))}const qt=1103515245,kt=12345,at=2147483647;function $t(o=.314){let e=(qt*o+kt)%at;return()=>(e=(qt*e+kt)%at,e/at)}function mn(o){return Math.pow(2,-10*o)*Math.sin((o-.2/4)*(2*Math.PI)/.2)+1}function Mn(o){return o<.5?.5*Math.pow(2,20*o-10)*Math.sin((20*o-11.125)*(2*Math.PI)/.9):.5*(2-Math.pow(2,-20*o+10)*Math.sin((20*o-11.125)*(2*Math.PI)/.9))}function vn(o,e=4){return Math.max(e-Math.floor(Math.log10(o)),0)}function Sn(o){if(o.length<=1)return o;const e=new Map,t=new Map;for(const s of o){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 i=o.length**2;for(;(e.size||t.size)&&i-- >0;){let s=e.keys().next().value;const r=[s];let c=e.get(s);for(;c!==void 0&&c!==s&&i-- >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&&i-- >0;)r.unshift(c),e.delete(c),t.delete(s),s=c,c=t.get(c);n.push(r)}return n}class O{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 i=t.map(s=>G.fromCommands(s));return new O(i)}static fromPathString(e){const t=ct(e);return O.fromCommands(t)}getBBox2(e=A()){for(const t of this.shapes)t.getBBox2(e);return e}includePoint(e){let t=!0;for(const n of this.shapes){const{isRightHand:i}=n,s=n.includePoint(e);if(t&&(t=i?s:!s),!t)return!1}return t}applyFn(e){for(const t of this.shapes)for(const n of t.curves)n.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{shapes:e}=this,t=[];for(let i=0;i<e.length;i++){const s=e[i],{bbox2:r,isRightHand:c}=s;if(c)t.push([s]);else{const a=t.find(h=>{const l=h[0].bbox2;return ft(l,r)});a?a.push(s):console.error("can't find the path for the shape",s)}}return t.map(i=>new O(i))}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(i=>i.clone());return new G(n)});return new O(e,this.windingRule)}}const Cn=[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800],ht=o=>Cn[o],wn=(o,e)=>ht(o)/(ht(e)*ht(o-e)),zt=(o,e,t)=>wn(e,o)*t**o*(1-t)**(e-o),Nt=(o,e=0,t=1)=>Math.min(Math.max(o,e),t);function En(o,e,t=!0){return t?n=>{const[i,s]=n,r=e.length-1,c=e[0].length-1;let a=(i-o.x)/o.width,h=(s-o.y)/o.height,l=0,u=y();for(let d=0;d<=r;d++){const p=zt(d,r,a);for(let P=0;P<=c;P++){const g=zt(P,c,h),x=p*g;l+=x,dt(u,u,e[d][P],x)}}Ot(u,u,1/l),Qt(n,u)}:n=>{const[i,s]=n,r=e.length-1,c=e[0].length-1;let a=Nt((i-o.x)/o.width),h=Nt((s-o.y)/o.height);a=a*r,h=h*c;const l=Math.floor(a),u=Math.floor(h);a=a-l,h=h-u;const d=e[l][u],p=e[l+1][u],P=e[l][u+1],g=e[l+1][u+1],x=(1-a)*(1-h)*d[0]+a*(1-h)*p[0]+(1-a)*h*P[0]+a*h*g[0],M=(1-a)*(1-h)*d[1]+a*(1-h)*p[1]+(1-a)*h*P[1]+a*h*g[1];return n[0]=x,n[1]=M,n}}class lt{constructor(e){C(this,"value");C(this,"next",null);this.value=e}}class ut{constructor(){C(this,"head",null);C(this,"tail",null);C(this,"size",0)}static fromArray(e){const t=new ut;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 lt(e);this.tail&&(this.tail.next=t),this.tail=t,this.head||(this.head=t),this.size++}prepend(e){const t=new lt(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}}f.BezierCurve=q,f.BezierCurveType=Mt,f.BezierShape=Tt,f.ClosedShape=G,f.Curve=gt,f.LineCurve=I,f.LineCurveType=tt,f.LineToQuadratic=Gt,f.LinkedList=ut,f.Node=lt,f.Path=O,f.PointNode=It,f.Polygon=Ut,f.Polyline=U,f.QuadraticCurve=_,f.QuadraticCurveType=mt,f.Shape=wt,f.SingleShape=k,f.calDisData=an,f.calExtendCurve=hn,f.calPointsArea=X,f.calRadius=un,f.checkLineCurveIntersect=xt,f.connectPolyline=ln,f.copyMatrix=Pn,f.createBBox2=A,f.createMatrix=fn,f.createSvgByPath=Kt,f.gaussElimination=Xt,f.getBezierCurvesBBox=Lt,f.getBezierFromCurve=vt,f.getBezierShapeFormSingleShape=on,f.getCurvature=_t,f.getCurvesByPolygon=At,f.getDebugPathStr=tn,f.getDigit=vn,f.getEaseElasticInOut=Mn,f.getEaseElasticOut=mn,f.getPathStr=Et,f.getPointsRightHandRule=ot,f.getPolygon=Dt,f.getRandomGenerate=$t,f.getRandomPathStr=sn,f.getRoots=F,f.getTriangleArea=xn,f.includeBBox2=ft,f.interpolatePolygon=nn,f.isInLeft=Wt,f.isPointInPoints=rt,f.lineInterSect=yt,f.lineToBezier=St,f.linearRegression=Vt,f.max=dn,f.mean=et,f.median=yn,f.mergeBBox2=N,f.mergeCouple=Sn,f.min=pn,f.pathStringToPathCommands=ct,f.quadraticToBezier=Ct,f.resizeCurvesByBBox=Bt,f.simplyCurves=Jt,f.std=gn,f.sum=$,f.transformPoint=En,f.variance=Rt,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}); | ||
(function(f,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(f=typeof globalThis<"u"?globalThis:f||self,A(f.geometry={}))})(this,function(f){"use strict";var zn=Object.defineProperty;var Nn=(f,A,Q)=>A in f?zn(f,A,{enumerable:!0,configurable:!0,writable:!0,value:Q}):f[A]=Q;var C=(f,A,Q)=>Nn(f,typeof A!="symbol"?A+"":A,Q);function A(){return{xMin:1/0,xMax:-1/0,yMin:1/0,yMax:-1/0}}function Q(s,e){return s.xMin=Math.min(s.xMin,e.xMin),s.xMax=Math.max(s.xMax,e.xMax),s.yMin=Math.min(s.yMin,e.yMin),s.yMax=Math.max(s.yMax,e.yMax),s}function pt(s,e){return s.xMin<=e.xMin&&s.xMax>=e.xMax&&s.yMin<=e.yMin&&s.yMax>=e.yMax}var gt=1e-6,W=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var s=0,e=arguments.length;e--;)s+=arguments[e]*arguments[e];return Math.sqrt(s)});function y(){var s=new W(2);return W!=Float32Array&&(s[0]=0,s[1]=0),s}function T(s){var e=new W(2);return e[0]=s[0],e[1]=s[1],e}function m(s,e){var t=new W(2);return t[0]=s,t[1]=e,t}function Ot(s,e){return s[0]=e[0],s[1]=e[1],s}function et(s,e,t){return s[0]=e[0]+t[0],s[1]=e[1]+t[1],s}function jt(s,e,t){return s[0]=e[0]-t[0],s[1]=e[1]-t[1],s}function Zt(s,e,t){return s[0]=e[0]*t,s[1]=e[1]*t,s}function it(s,e,t,n){return s[0]=e[0]+t[0]*n,s[1]=e[1]+t[1]*n,s}function E(s,e){var t=e[0]-s[0],n=e[1]-s[1];return Math.hypot(t,n)}function yt(s){var e=s[0],t=s[1];return Math.hypot(e,t)}function $(s,e){var t=e[0],n=e[1],o=t*t+n*n;return o>0&&(o=1/Math.sqrt(o)),s[0]=e[0]*o,s[1]=e[1]*o,s}function Z(s,e){return s[0]*e[0]+s[1]*e[1]}function B(s,e,t,n){var o=e[0],i=e[1];return s[0]=o+n*(t[0]-o),s[1]=i+n*(t[1]-i),s}function st(s,e){var t=s[0],n=s[1],o=e[0],i=e[1],r=Math.sqrt(t*t+n*n)*Math.sqrt(o*o+i*i),c=r&&(t*o+n*i)/r;return Math.acos(Math.min(Math.max(c,-1),1))}function J(s,e){return s[0]===e[0]&&s[1]===e[1]}function xt(s,e){var t=s[0],n=s[1],o=e[0],i=e[1];return Math.abs(t-o)<=gt*Math.max(1,Math.abs(t),Math.abs(o))&&Math.abs(n-i)<=gt*Math.max(1,Math.abs(n),Math.abs(i))}var Yt=yt,R=jt,H=E;(function(){var s=y();return function(e,t,n,o,i,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)s[0]=e[c],s[1]=e[c+1],i(s,s,r),e[c]=s[0],e[c+1]=s[1];return e}})();class mt{constructor(e,t){C(this,"type","curve");C(this,"_isDirty",!0);C(this,"_SPoint",y());C(this,"_EPoint",y());C(this,"_bbox2");C(this,"_len");C(this,"inDir",y());C(this,"ouDir",y());this.SPoint=e,this.EPoint=t,this._isDirty=!1}set SPoint(e){this._isDirty||(this._isDirty=!J(this._SPoint,e)),this._SPoint=e}get SPoint(){return this._SPoint}set EPoint(e){this._isDirty||(this._isDirty=!J(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,ouDir:t}=this,n=e[0]*t[1]-e[1]*t[0],o=e[0]*t[0]+e[1]*t[1];return Math.atan2(n,o)}update(){this._bbox2=this._getBBox2(),this._len=this._getLen(),this._isDirty=!1}divideAtArray(e){e.sort((i,r)=>i-r);let t=this;const n=new Array(e.length+1);let o=0;for(let i=0;i<e.length;i++){let r=e[i];r=(r-o)/(1-o),o=e[i];const c=t.divideAt(r);n[i]=c[0],t=c[1]}return n[e.length]=t,n}splitByCoord(e){const t=this.getSplitT(e);return this.divideAtArray(t)}}const K="curve-line";class I extends mt{constructor(t,n){super(t,n);C(this,"tangent");C(this,"normal");this.type=K,this.tangent=$(y(),R(y(),n,t)),this.normal=m(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.ouDir=this.tangent}update(){super.update(),this.tangent=$(y(),R(y(),this.EPoint,this.SPoint)),this.normal=m(-this.tangent[1],this.tangent[0]),this.inDir=this.tangent,this.ouDir=this.tangent}_getBBox2(){const{SPoint:t,EPoint:n}=this,[o,i]=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:i,yMax:c}}_getLen(){return E(this.SPoint,this.EPoint)}getNormal(t){return this.normal}getTangent(t){return this.tangent}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:i,height:r}=this.bbox,{SPoint:c,EPoint:a}=this,{mode:h,val:l}=t,u=[];return h==="x"&&l>=n&&l<=n+i?u.push((l-c[0])/(a[0]-c[0])):h==="y"&&l>=o&&l<=o+r&&u.push((l-c[1])/(a[1]-c[1])),u}getLineIntersects(t){const[n,o]=this.SPoint,[i,r]=this.EPoint,[c,a]=t.SPoint,[h,l]=t.EPoint,u=[],d=(n-i)*(a-l)-(o-r)*(c-h);if(Math.abs(d)>1e-10){const p=n*r-o*i,P=c*l-a*h,g=(p*(c-h)-P*(n-i))/d,x=(p*(a-l)-P*(o-r))/d,{x:M,y:v,width:w,height:S}=this.bbox;g>=M&&g<=g+w&&x>=v&&x<=v+S&&u.push(m(g,x))}return u}getDisToPos(t){const{SPoint:n,EPoint:o,tangent:i}=this,r=R(y(),t,n),c=Z(r,i);if(c<0)return E(n,t);const a=E(n,o);if(c>a)return E(o,t);const h=m(-i[1],i[0]);return Math.abs(Z(h,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()}divideAt(t){const{SPoint:n,EPoint:o}=this,i=this.getPosition(t);return[new I(n,i),new I(T(i),o)]}isPointOnCurve(t){const{SPoint:n,EPoint:o}=this,i=E(n,t),r=E(o,t),c=E(n,o);return Math.abs(i+r-c)<1e-10}toPathString(t=0){const[n,o]=this.EPoint;return`L ${n.toFixed(t)} ${o.toFixed(t)}`}toDebugPathString(t){return this.toPathString(t)}clone(){return new I(T(this.SPoint),T(this.EPoint))}}function ot(s,e,t,n){const[o,i]=s,[r,c]=e,[a,h]=t,[l,u]=n,d=c-i,p=o-r,P=r*i-o*c,g=u-h,x=a-l,M=l*h-a*u,v=d*x-g*p,w=(p*M-x*P)/v,S=(g*P-d*M)/v;return m(w,S)}function Mt(s,e){const[t,n]=s.SPoint,[o,i]=s.EPoint,[r,c]=e.SPoint,[a,h]=e.EPoint,{x:l,y:u,width:d,height:p}=s.bbox,{x:P,y:g,width:x,height:M}=e.bbox;if(l+d<P||P+x<l||u+p<g||g+M<u)return!1;const v=(t-r)*(h-c)-(n-c)*(a-r),w=(o-r)*(h-c)-(i-c)*(a-r);if(v*w>0)return!1;const S=(r-t)*(i-n)-(c-n)*(o-t),b=(a-t)*(i-n)-(h-n)*(o-t);return!(S*b>0)}const Y=1e-12;function F(s){switch(s.length){case 0:return[];case 1:return[0];case 2:return Math.abs(s[0])<Y?[]:[-s[1]/s[0]];case 3:return Math.abs(s[0])<Y?F(s.slice(1)):Xt(s);case 4:return Math.abs(s[0])<Y?F(s.slice(1)):Gt(s);default:throw new Error("Not implemented")}}function Xt(s){const e=s[0],t=s[1],n=s[2],o=t*t-4*e*n;if(o<0)return[];{const i=Math.sqrt(o);return[(-t+i)/(2*e),(-t-i)/(2*e)]}}function Gt(s){const e=s[0],t=s[1],n=s[2],o=s[3],i=t/e,r=n/e,c=o/e,a=(3*r-i*i)/9,h=(9*i*r-27*c-2*i*i*i)/54,l=a*a*a+h*h;if(l>=0){const u=Math.sqrt(l),d=Math.cbrt(h+u),p=Math.cbrt(h-u),P=[-i/3+(d+p)];return l===0&&P.push(-d/2),P}else{const u=Math.acos(h/Math.sqrt(-a*a*a)),d=Math.sqrt(-a);return[2*d*Math.cos(u/3)-i/3,2*d*Math.cos((u+2*Math.PI)/3)-i/3,2*d*Math.cos((u+4*Math.PI)/3)-i/3]}}function Ut(s,e,t){[s[e],s[t]]=[s[t],s[e]]}function Wt(s){const{length:e}=s;for(let n=0;n<e;n++){let o=n;for(let i=n+1;i<e;i++)Math.abs(s[i][n])>Math.abs(s[o][n])&&(o=i);Ut(s,n,o);for(let i=n+1;i<e;i++){if(Math.abs(s[n][n])<Y)continue;const r=s[i][n]/s[n][n];for(let c=n;c<e+1;c++)s[i][c]-=r*s[n][c]}}const t=new Array(e).fill(0);for(let n=e-1;n>=0;n--)if(!(Math.abs(s[n][n])<Y)){t[n]=s[n][e]/s[n][n];for(let o=n-1;o>=0;o--)s[o][e]-=s[o][n]*t[n]}return console.log(s),t}const tt=100,vt="curve-quadratic";class _ extends I{constructor(t,n,o){super(t,o);C(this,"_CPoint1",y());C(this,"_lenArr",new Array(tt).fill(0));this.type=vt,this.CPoint1=n;let i=R(y(),n,t);this.inDir=$(i,i),i=R(y(),o,n),this.ouDir=$(i,i)}set CPoint1(t){this._isDirty||(this._isDirty=!J(this._CPoint1,t)),this._CPoint1=t}get CPoint1(){return this._CPoint1}update(){super.update(),this.inDir=this.getTangent(0),this.ouDir=this.getTangent(1)}_getBBox2(){const[t,n]=this.SPoint,[o,i]=this.CPoint1,[r,c]=this.EPoint,a=[2*(t-2*o+r),2*(o-r)],h=[2*(n-2*i+c),2*(i-c)],l=F(a),u=F(h),d=l.filter(S=>S>0&&S<1).concat([0,1]),p=u.filter(S=>S>0&&S<1).concat([0,1]),P=d.map(S=>this.getPosition(S)[0]),g=p.map(S=>this.getPosition(S)[1]),x=Math.min(...P),M=Math.max(...P),v=Math.min(...g),w=Math.max(...g);return{xMin:x,xMax:M,yMin:v,yMax:w}}_getLen(){let t=0,n=this.getPosition(0);for(let o=1;o<=tt;o++){let i=this.getPosition(o/100);t+=E(n,i),n=i,this._lenArr[o-1]=t}return t}getPosition(t){const n=(1-t)**2,o=2*t*(1-t),i=t**2,r=n*this.SPoint[0]+o*this.CPoint1[0]+i*this.EPoint[0],c=n*this.SPoint[1]+o*this.CPoint1[1]+i*this.EPoint[1];return m(r,c)}getPosDataByPer(t){let n=0,o=this._lenArr.length-1,i;const r=this.len*t;for(;n<o;)i=Math.floor((n+o)/2),this._lenArr[i]<r?n=i+1:o=i;const c=this._lenArr[n-1]||0;let a=n/tt;a+=(r-c)/(this._lenArr[n]-c)/tt;const h=this.getPosition(a),l=this.getTangent(a);return{pos:h,tan:l}}getTangent(t){const n=this.getDerivative(t);return $(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 i=this.getCurvature(o);Math.abs(i)>Math.abs(n)&&(n=i)}return n}getSplitT(t){const{x:n,y:o,width:i,height:r}=this.bbox,{mode:c,val:a}=t;if(c==="x"){if(a>=n&&a<=n+i){const h=[this.SPoint[0]-2*this.CPoint1[0]+this.EPoint[0],2*(this.CPoint1[0]-this.EPoint[0]),this.EPoint[0]-a];return F(h).filter(u=>u>0&&u<1)}}else if(a>=o&&a<=o+r){const h=[this.SPoint[1]-2*this.CPoint1[1]+this.EPoint[1],2*(this.CPoint1[1]-this.EPoint[1]),this.EPoint[1]-a];return F(h).filter(u=>u>0&&u<1)}return[]}getLineIntersects(t){const n=[],[o,i]=this.SPoint,[r,c]=this.CPoint1,[a,h]=this.EPoint,[l,u]=t.SPoint,d=o-2*r+a,p=i-2*c+h,P=2*(r-o),g=2*(c-i),x=o,M=i,[v,w]=R(y(),t.EPoint,t.SPoint),S=v*p-w*d,b=v*g-w*P,D=v*M-w*x-v*u+w*l,V=F([S,b,D]);for(const L of V)if(L>=0&&L<=1){const U=(1-L)**2*o+2*L*(1-L)*r+L**2*a,j=(1-L)**2*i+2*L*(1-L)*c+L**2*h;n.push(m(U,j))}return n}getDisToPos(t){let n=100,o=1/0;for(let i=0;i<=n;i++){const r=i/n,c=this.getPosition(r),a=E(t,c);a<o&&(o=a)}return o}getDisToPos2(t){const[n,o]=this.SPoint,[i,r]=this.CPoint1,[c,a]=this.EPoint,[h,l]=t,u=[[-(n-2*i+c),-2*(i-n),h-n],[-(o-2*r+a),-2*(r-o),l-o]],d=[[2*(n-2*i+c),2*(i-n)],[2*(o-2*r+a),2*(r-o)]],p=new Array(4).fill(0);for(let M=0;M<2;M++)for(let v=0;v<2;v++)for(let w=0;w<3;w++)p[v+w]+=d[M][v]*u[M][w]+d[M][v]*u[M][w];const g=[...F(p).filter(M=>M*(M-1)<0),0,1];let x=1/0;for(let M of g){const v=this.getPosition(M),w=E(t,v);w<x&&(x=w)}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),[i,r]=this.getSecondDerivative(t),c=n*r-o*i;if(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 i=0;i<=t;i++){const r=i/t,c=this.getCurvature(r);n[i]=c}const o=[];for(let i=1;i<t;i++)(n[i]-n[i-1])*(n[i]-n[i+1])>0&&o.push(i/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)}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]));et(this.CPoint1,this.CPoint1,n)}divideAt(t){const n=this.SPoint,o=this.EPoint,i=this.CPoint1,r=B(y(),n,i,t),c=B(y(),i,o,t),a=B(y(),r,c,t),h=new _(n,r,a),l=new _(T(a),c,o);return[h,l]}divideAtArray(t){return super.divideAtArray.call(this,t)}pathOffset(t){const o=[0,.5,1].map(c=>{const a=this.getPosition(c),h=this.getNormal(c);return it(y(),a,h,t)}),i=B(y(),o[0],o[2],.5),r=B(i,i,o[1],2);return new _(o[0],r,o[2])}splitByCoord(t){const n=this.getSplitT(t);return this.divideAtArray(n)}toPathString(t=0){return`Q ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}toDebugPathString(t){return`L ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} L ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}toPoints(t=10){const n=new Array(t),o=1/t;for(let i=1;i<=t;i++){const r=this.getPosition(i*o);n[i-1]=r}return n.reverse()}clone(){return new _(T(this.SPoint),T(this.CPoint1),T(this.EPoint))}}function Jt(s){const e=s.SPoint,t=s.EPoint,n=m((e[0]+t[0])/2,(e[1]+t[1])/2);return new _(e,n,t)}const St="curve-bezier";class q extends _{constructor(t,n,o,i){super(t,n,i);C(this,"_CPoint2",y());this.type=St,this.CPoint2=o;let r=R(y(),n,t);this.inDir=$(r,r),r=R(y(),i,o),this.ouDir=$(r,r)}set CPoint2(t){this._isDirty||(this._isDirty=!J(this._CPoint2,t)),this._CPoint2=t}get CPoint2(){return this._CPoint2}_getBBox2(){const[t,n]=this.SPoint,[o,i]=this.CPoint1,[r,c]=this.CPoint2,[a,h]=this.EPoint,l=[-3*t+9*o-9*r+3*a,6*t-12*o+6*r,3*o-3*t],u=[-3*n+9*i-9*c+3*h,6*n-12*i+6*c,3*i-3*n],d=F(l),p=F(u),P=d.filter(D=>D>0&&D<1).concat([0,1]),g=p.filter(D=>D>0&&D<1).concat([0,1]),x=P.map(D=>this.getPosition(D)[0]),M=g.map(D=>this.getPosition(D)[1]),v=Math.min(...x),w=Math.max(...x),S=Math.min(...M),b=Math.max(...M);return{xMin:v,xMax:w,yMin:S,yMax:b}}getSplitT(t){const{x:n,y:o,width:i,height:r}=this.bbox,{mode:c,val:a}=t,h=c==="y"?1:0;if(a<[n,o][h]||a>[n+i,o+r][h])return[];{const l=[-this.SPoint[h]+3*this.CPoint1[h]-3*this.CPoint2[h]+this.EPoint[h],3*this.SPoint[h]-6*this.CPoint1[h]+3*this.CPoint2[h],-3*this.SPoint[h]+3*this.CPoint1[h],this.SPoint[h]-a],u=F(l),d=1e-8;return u.filter(p=>p>d&&p<1-d)}}getPosition(t){let n=(1-t)**3,o=3*t*(1-t)*(1-t),i=3*t*t*(1-t),r=t**3,c=n*this.SPoint[0]+o*this.CPoint1[0]+i*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+o*this.CPoint1[1]+i*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}getTangent(t){const n=this.getDerivative(t);return $(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),i=3*(2*t-3*t**2),r=3*t**2,c=n*this.SPoint[0]+o*this.CPoint1[0]+i*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+o*this.CPoint1[1]+i*this.CPoint2[1]+r*this.EPoint[1];return m(c,a)}getSecondDerivative(t){let n=6*(1-t),o=6*(3*t-2),i=6*(1-3*t),r=6*t,c=n*this.SPoint[0]+o*this.CPoint1[0]+i*this.CPoint2[0]+r*this.EPoint[0],a=n*this.SPoint[1]+o*this.CPoint1[1]+i*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,i=[.4,.6],r=i.map(b=>{const D=this.getPosition(b);return t(D),D});t(n),t(o);const c=(b,D)=>{const V=(1-b)**3,L=3*b*(1-b)**2,U=3*b**2*(1-b),j=b**3;return[L,U,D[0]-j*o[0]-V*n[0],D[1]-j*o[1]-V*n[1]]},[a,h,l,u]=c(i[0],r[0]),[d,p,P,g]=c(i[1],r[1]),x=1/(h*d-a*p),M=(h*P-p*l)*x,v=(h*g-p*u)*x,w=(d*l-a*P)*x,S=(d*u-a*g)*x;this.CPoint1=m(M,v),this.CPoint2=m(w,S)}reverse(){[this.CPoint1,this.CPoint2]=[this.CPoint2,this.CPoint1],super.reverse()}getLineIntersects(t){const{bbox:n}=this;if(n.x>t.bbox.x+t.bbox.width||n.x+n.width<t.bbox.x||n.y>t.bbox.y+t.bbox.height||n.y+n.height<t.bbox.y)return[];const o=[],[i,r]=this.SPoint,[c,a]=this.CPoint1,[h,l]=this.CPoint2,[u,d]=this.EPoint,[p,P]=t.SPoint,g=-i+3*c-3*h+u,x=-r+3*a-3*l+d,M=3*i-6*c+3*h,v=3*r-6*a+3*l,w=-3*i+3*c,S=-3*r+3*a,b=i,D=r,[V,L]=R(y(),t.EPoint,t.SPoint),U=V*x-L*g,j=V*v-L*M,Rn=V*S-L*w,Vn=V*D-L*b-(V*P-L*p),qn=F([U,j,Rn,Vn]);for(const N of qn)if(N>=0&&N<=1){const $n=g*N**3+M*N**2+w*N+b,kn=x*N**3+v*N**2+S*N+D;o.push(m($n,kn))}return o}divideAt(t){const n=this.SPoint,o=this.EPoint,i=this.CPoint1,r=this.CPoint2,c=B(y(),n,i,t),a=B(y(),i,r,t),h=B(y(),r,o,t),l=B(y(),c,a,t),u=B(y(),a,h,t),d=this.getPosition(t),p=new q(n,c,l,d),P=new q(T(d),u,h,o);return[p,P]}divideAtArray(t){return super.divideAtArray.call(this,t)}splitByCoord(t){const n=this.getSplitT(t);return this.divideAtArray(n)}toPathString(t=0){return`C ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} ${this.CPoint2[0].toFixed(t)} ${this.CPoint2[1].toFixed(t)} ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}toDebugPathString(t){return` L ${this.CPoint1[0].toFixed(t)} ${this.CPoint1[1].toFixed(t)} L ${this.CPoint2[0].toFixed(t)} ${this.CPoint2[1].toFixed(t)} L ${this.EPoint[0].toFixed(t)} ${this.EPoint[1].toFixed(t)}`}clone(){return new q(T(this.SPoint),T(this.CPoint1),T(this.CPoint2),T(this.EPoint))}}function Ct(s){if(s instanceof q)return s;if(s instanceof I)return wt(s);if(s instanceof _)return bt(s);throw new Error("Unsupported curve type.")}function wt(s){const{SPoint:e,EPoint:t}=s,n=B(y(),e,t,1/3),o=B(y(),e,t,2/3);return new q(e,n,o,t)}function bt(s){const{SPoint:e,CPoint1:t,EPoint:n}=s,o=B(y(),e,t,2/3),i=B(y(),n,t,2/3);return new q(e,o,i,n)}class Kt{constructor(e){C(this,"points");C(this,"bbox");this.points=e,this.bbox={xMin:1/0,xMax:-1/0,yMin:1/0,yMax:-1/0};for(let t of this.points)this.bbox.xMin=Math.min(this.bbox.xMin,t[0]),this.bbox.xMax=Math.max(this.bbox.xMax,t[0]),this.bbox.yMin=Math.min(this.bbox.yMin,t[1]),this.bbox.yMax=Math.max(this.bbox.yMax,t[1])}getArea(){return Math.abs(this.getSignArea())}getSignArea(){return X(this.points)}getCentroid(){let e=this.getSignArea(),t=0,n=0;for(let o=0;o<this.points.length;o++){let[i,r]=this.points[o],[c,a]=this.points[(o+1)%this.points.length];t+=(i+c)*(i*a-c*r),n+=(r+a)*(i*a-c*r)}return[t/6/e,n/6/e]}includePoint(e){return e[0]<this.bbox.xMin||e[0]>this.bbox.xMax||e[1]<this.bbox.yMin||e[1]>this.bbox.yMax?!1:ct(e,this.points)}includePolygon(e){if(e.bbox.xMin<this.bbox.xMin||e.bbox.xMax>this.bbox.xMax||e.bbox.yMin<this.bbox.yMin||e.bbox.yMax>this.bbox.yMax)return!1;for(let t of e.points)if(!this.includePoint(t))return!1;return!0}intersectPolygon(e){for(let t of e.points)if(this.includePoint(t))return!0;return!1}}function X(s){let e=0;const{length:t}=s;for(let n=0;n<t;n++){let[o,i]=s[n],[r,c]=s[(n+1)%t];e+=o*c-r*i}return e/2}function rt(s){return X(s)>0}function tn(s,e){let[t,n]=s,[[o,i],[r,c]]=e;return(t-o)*(c-i)-(n-i)*(r-o)>0}function ct(s,e){let[t,n]=s,o=!1;for(let i=0,r=e.length-1;i<e.length;r=i++){let[c,a]=e[i],[h,l]=e[r];a>n!=l>n&&t-c<(h-c)*(n-a)/(l-a)&&(o=!o)}return o}class Et{constructor(e){C(this,"curves",[]);C(this,"points",[]);C(this,"_isRightHand");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 isRightHand(){return this._isRightHand===void 0&&(this._isRightHand=this.getIsClockwise()),this._isRightHand}get isClosed(){return this.curves.length>0&&H(this.SPoint,this.EPoint)<.001}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].ouDir}getMaxCurvature(){let e=0;for(const t of this.curves)e=Math.max(e,t.getMaxCurvature());return e}getIsClockwise(){const{points:e}=this;return rt(e)}_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=A()){for(const{bbox:t}of this.curves){const{x:n,y:o,width:i,height:r}=t;e.xMin=Math.min(e.xMin,n),e.xMax=Math.max(e.xMax,n+i),e.yMin=Math.min(e.yMin,o),e.yMax=Math.max(e.yMax,o+r)}return e}getLineIntersects(e){const{curves:t}=this,{length:n}=t,o=new Array(n);for(let i=0;i<n;i++){const c=t[i].getLineIntersects(e);o[i]=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],u=e*n/this.curves[0].len;return l.getPosDataByPer(u)}if(e>=1){const l=this.curves[this.curves.length-1],u=(e-1)*n/l.len+1;return l.getPosDataByPer(u)}let o=0,i=this._lenArr.length-1,r;for(;o<i;)r=Math.floor((o+i)/2),this._lenArr[r]<n?o=r+1:i=r;const c=this.curves[o],a=o===0?0:this._lenArr[o-1],h=(n-a)/c.len;return c.getPosDataByPer(h)}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 i=1;i<e;i++)t[i-1]=i/e;const{length:n}=this.curves,o=new Array(n*e);for(let i=0;i<n;i++){const c=this.curves[i].divideAtArray(t);o.splice(i*e,e,...c)}this.curves=o}reverse(){this.curves.reverse();for(const e of this.curves)e.reverse();this.points.reverse(),this._isRightHand=!this._isRightHand,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 ${a[0].toFixed(e)} ${a[1].toFixed(e)} `,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:i}=this.getPosDataByPer(o);t[n]=i}return t}}function nn(s){const e=E(s[0].SPoint,s[s.length-1].EPoint)<1;let t=0;if(e){let i=0;for(let r=0;r<s.length;r++){const a=s[r].len;a>i&&(i=a,t=r)}}let n=[s[t]];for(let i=1;i<s.length;i++){const r=(i+t)%s.length,c=s[r],a=n[n.length-1];c.type===K&&a.type===K&&Z(c.inDir,a.ouDir)>.99?a.EPoint=c.EPoint:n.push(c)}s=n,n=[s[0]];const o=(i,r,c)=>{const{len:a}=i,{len:h}=r,{len:l}=c,u=20;if(a>u*h&&l>u*h){const p=st(i.ouDir,r.inDir),P=st(r.ouDir,c.inDir);if(p<P)i.EPoint=r.EPoint;else return c.SPoint=r.SPoint,!0}else n.push(r)};for(let i=1;i<s.length-1;i++){const r=n[n.length-1],c=s[i],a=s[i+1];o(r,c,a)&&(n.push(a),i++)}return e?o(n[n.length-1],s[s.length-1],s[0]):n.push(s[s.length-1]),n}function en(s){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",s),e.appendChild(t),e}function Dt(s,e=1){const t=s[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return s.forEach(o=>{n+=o.toPathString(e)+" "}),n+="Z",n}function sn(s,e=1){const t=s[0].SPoint;let n=`M ${t[0].toFixed(e)} ${t[1].toFixed(e)} `;return s.forEach(o=>{n+=o.toDebugPathString(e)+" "}),n}function at(s){const e=/([MmLlHhVvCcSsQqTtAaZz])|([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/g,t=s.match(e);if(!t)throw new Error("Invalid path string");const n=[];let o=null,i=[];for(const r of t)isNaN(parseFloat(r))?(o&&(n.push({type:o,args:i}),i=[]),o=r):i.push(parseFloat(r));return o&&n.push({type:o,args:i}),n}function on(s,e,t){const n=[],o=s.length,i=e.length;for(let r=0;r<i;r++){const c=B(y(),s[r%o],e[r],t);n.push(c)}return n}function rn(s,e){const{length:t}=s;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 i=0;i<t;i++)n[i]=s[i][0],o[i]=s[i][1];return i=>{if(i<0||i>1)throw new Error("out of bbox2");i=i*t+e;const r=Lt(n,e,i),c=Lt(o,e,i);return m(r,c)}}function Lt(s,e,t){const{length:n}=s,o=n+e,i=Math.floor(t),r=new Array(o);for(let c=0;c<o;c++)r[c]=s[c%n];for(let c=0;c<e;c++)for(let a=i;a>i-e+c;a--){const h=(t-a)/(e-c);r[a]=h*r[a]+(1-h)*r[a-1]}return r[i]}function Bt(s,e,t,n=0,o=0,i=.1){const r=[],c=s/2,a=e/2,h=Nt(i);let l=u=>{const p=h()*n+(1-n);let P=(p*Math.cos(u)+1)*c,g=(p*Math.sin(u)+1)*a;return m(P,g)};for(let u=0;u<t;u++){let d=l(2*Math.PI*(u/t+o));r.push(d)}return r}function At(s){let e=1/0,t=1/0,n=-1/0,o=-1/0;for(const i of s){const{bbox:r}=i;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 Tt(s,e){const t=At(s),n=e.width/t.width,o=e.height/t.height;for(const i of s)i.applyFn(r=>{r[0]=(r[0]-t.x)*n+e.x,r[1]=(r[1]-t.y)*o+e.y})}function It(s,e=3){const t=[],o=new Array(100),i=rn(s,Number(e)),r=performance.now();for(let a=0;a<100;a++)o[a]=i(a/100);performance.now()-r;const c=new Array(100);for(let a=0;a<100;a++){const h=m(o[a][0],o[a][1]),l=m(o[(a+1)%100][0],o[(a+1)%100][1]),u=B(y(),h,l,.5);c[a]=u}for(let a=0;a<100;a++){const h=T(c[a]),l=c[(a+1)%100],u=o[(a+1)%100];t.push(new _(h,u,l))}return t}function cn(s=100,e=100,t=6,n=.5,o=Math.random(),i=3){const r=Bt(s,e,t,n,o),c=It(r,i);return Tt(c,{x:0,y:0,width:s,height:e}),Dt(c)}class k extends Et{constructor(t){super(t);C(this,"currentPos",y())}moveTo(t,n){this.currentPos=m(t,n)}lineTo(t,n){const o=new I(this.currentPos,m(t,n));this.curves.push(o),this.currentPos=m(t,n)}bezierCurveTo(t,n,o,i,r,c){const a=new q(this.currentPos,m(t,n),m(o,i),m(r,c));this.curves.push(a),this.currentPos=m(r,c)}quadraticCurveTo(t,n,o,i){const r=new _(this.currentPos,m(t,n),m(o,i));this.curves.push(r),this.currentPos=m(o,i)}closePath(){const t=this.curves[0].SPoint;if(xt(this.currentPos,t))return;const n=new I(this.currentPos,this.curves[0].SPoint);this.curves.push(n)}static fromCommands(t){const n=new k([]);let o=0;for(let i=0;i<t.length;i++){const r=t[i],{type:c,args:a=[]}=r,h=a.length,{x:l=a[h-2],y:u=a[h-1],x1:d=a[0],y1:p=a[1],x2:P=a[2],y2:g=a[3]}=r;switch(c){case"M":n.moveTo(l,u),o++,o>1&&console.error("SimpleShape can only have one start point");break;case"L":xt(n.currentPos,m(l,u))||n.lineTo(l,u);break;case"H":n.lineTo(l,n.currentPos[1]);break;case"V":n.lineTo(n.currentPos[0],u);break;case"C":n.bezierCurveTo(d,p,P,g,l,u);break;case"Q":n.quadraticCurveTo(d,p,l,u);break;case"Z":n.closePath();break}}return n}static fromPathString(t){const n=at(t);return k.fromCommands(n)}}class Ft extends k{constructor(t){super(t);C(this,"curves");this.curves=t}}function an(s){const e=s.curves.map(t=>Ct(t));return new Ft(e)}class G extends k{constructor(e){super(e),this.curves=e,this.initPoints()}includePoint(e){const{xMin:t,xMax:n,yMin:o,yMax:i}=this.bbox2;return e[0]<t||e[0]>n||e[1]<o||e[1]>i?!1:ct(e,this.points)}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 G(n.curves)}}function _t(s){let e=s[0];for(let n=1;n<s.length;n++){const o=s[n],{bbox2:i}=o;i.xMin<e.bbox2.xMin&&(e=o)}e.isRightHand||s.forEach(n=>{n.reverse()});const t=[];for(let n=0;n<s.length;n++){const o=s[n],{isRightHand:i}=o;i&&t.push([o])}for(let n=0;n<s.length;n++){const o=s[n],{bbox2:i,isRightHand:r}=o;if(!r){const c=t.find(a=>{if(!a[0])return!1;const h=a[0].bbox2;return pt(h,i)});c?c.push(o):console.warn("can't find the path for shape:",o)}}return t}const Rt=1e-6,hn=Math.cos(30/Math.PI);function ln(s,e,t,n){if(Z(e,n)<hn)return null;const[i,r]=s,[c,a]=e,[h,l]=t,[u,d]=n,p=u*a-c*d;if(p<Rt&&p>-Rt)return null;const P=((i-h)*d-(r-l)*u)/p;return it(y(),s,e,P)}function un(s,e){return Z(s,e)>yt(s)*.9}function fn(s,e){const t=R(y(),e.SPoint,s.EPoint),n=Yt(t);let o=s.curves;if(!(n<1)){let c;if(!(lt(s.outDir,t)*lt(t,e.inDir)>0)||st(s.outDir,e.inDir)<Math.PI/36)c=new I(s.EPoint,e.SPoint);else{const h=s.EPoint,l=et(y(),s.EPoint,s.outDir),u=et(y(),e.SPoint,e.inDir),d=e.SPoint,p=ot(h,l,u,d);c=new _(s.EPoint,p,e.SPoint)}o.push(c)}return s===e||e.points.every((c,a)=>H(c,s.points[a])<1)||(o=o.concat(e.curves)),new k(o)}class ht extends k{constructor(t,n){super(t);C(this,"curves");C(this,"tanArr",[]);if(this.curves=t,n)this.tanArr=n;else{const{length:o}=t,i=new Array(o+1);for(let r=0;r<o;r++)i[r]=t[r].inDir;i[o]=t[o-1].ouDir,this.tanArr=i}}static fromPoints(t,n){let o=[];for(let i=0;i<t.length-1;i++)o.push(new I(t[i],t[i+1]));return new ht(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 i of this.points){let r=H(i,t);r<n&&(n=r,o=i)}return o}getMaxDeflection(){let t=0;for(let n=0;n<this.curves.length;n++){const o=this.tanArr[n],i=H(y(),o);t=Math.max(t,i)}return t}getPosDataByPer(t){const{isClosed:n,len:o,curves:i}=this;n&&(t=(t+1)%1);const r=t*o;if(t<=0){const p=i[0],P=t*r/i[0].len;return p.getPosDataByPer(P)}if(t>=1){const p=i[i.length-1],P=(t-1)*r/p.len+1;return p.getPosDataByPer(P)}let c=0,a=this._lenArr.length-1,h;for(;c<a;)h=Math.floor((c+a)/2),this._lenArr[h]<r?c=h+1:a=h;const l=i[c],u=c===0?0:this._lenArr[c-1],d=(r-u)/l.len;return l.getPosDataByPer(d)}}function Pn(s,e){const n=s.toPoints(20),o=e.toPoints(20),{length:i}=n,{length:r}=o,c={datas:[],min:1/0,max:1/0,mean:1/0,std:1/0};if(!(s.isClosed||e.isClosed)){const P=new I(s.EPoint,e.SPoint),g=new I(e.EPoint,s.SPoint);if(Mt(P,g))return[c,c]}const h=[...n,...o];if(!rt(h))return[c,c];const u=new Array(i).fill({dis:1/0,index:-1}),d=new Array(r).fill({dis:1/0,index:-1});for(let P=0;P<i;P++)for(let g=0;g<r;g++){const x=H(n[P],o[g]);x<u[P].dis&&(u[P]={dis:x,index:g}),x<d[g].dis&&(d[g]={dis:x,index:P})}return[u,d].map(P=>{const g=P.map(({dis:S})=>S),x=Math.min(...g),M=Math.max(...g),v=g.reduce((S,b)=>S+b,0)/g.length,w=Math.sqrt(g.map(S=>Math.pow(S-v,2)).reduce((S,b)=>S+b,0)/g.length);return{datas:P,min:x,max:M,mean:v,std:w}})}function dn(s){const{points:e}=s,t=e.length;for(let n=0;n<t;n++){const o=e[n],i=e[(n+1)%t];for(let r=n+2;r<t;r++){const c=e[r],a=e[(r+1)%t];if(ot(o,i,c,a))return!0}}return!1}function pn(s){const{points:e,bbox2:t}=s,n=Math.min(e.length,5),o=e.slice(-n),i=o.map(([l])=>l),r=o.map(([,l])=>l),{k:c,b:a,R2:h}=$t(i,r);return{k:c,b:a,R2:h}}function gn(s){return s*Math.PI/180}function Vt(s){return s*180/Math.PI}function yn(s){return Vt(Math.atan2(s[1],s[0]))}function xn(s,e,t){const n=E(s,e),o=E(e,t),i=E(t,s),r=(n+o+i)/2,c=4*Math.sqrt(r*(r-n)*(r-o)*(r-i));return Math.abs(c)<1e-20?1/0:n*o*i/4/Math.sqrt(r*(r-n)*(r-o)*(r-i))}function mn(s,e,t){const n=E(s,e),o=E(e,t),i=E(t,s),r=n*o*i;return Math.abs(r)<1e-20?0:X([s,e,t])/(n*o*i)}function Mn(s){return new Array(s).fill(0).map(()=>new Array(s))}function vn(s){return s.map(e=>e.slice())}function Sn(s){return Math.max(...s)}function Cn(s){return Math.min(...s)}function z(s){return s.reduce((e,t)=>e+t,0)}function nt(s){return z(s)/s.length}function wn(s){return nt(s),Math.sqrt(qt(s))}function qt(s){const e=nt(s);return nt(s.map(t=>Math.pow(t-e,2)))}function bn(s){const e=s.slice().sort((n,o)=>n-o),t=Math.floor(s.length/2);return s.length%2!==0?e[t]:(e[t-1]+e[t])/2}function $t(s,e){const t=s.length,n=z(s),o=z(e),i=o/t,r=z(s.map((P,g)=>P*e[g])),c=z(s.map(P=>P*P)),a=1e-10;if(t*c-n*n<a)return{k:1/0,b:n/t,R2:1};const h=(t*r-n*o)/(t*c-n*n),l=(o-h*n)/t,u=Math.max(a,z(e.map(P=>Math.pow(P-i,2)))),p=Math.max(a,z(s.map(P=>Math.pow(h*P+l-i,2))))/u;return{k:h,b:l,R2:p}}function En(s,e,t){return Math.abs(X([s,e,t]))}function lt(s,e){return s[0]*e[1]-s[1]*e[0]}const kt=1103515245,zt=12345,ut=2147483647;function Nt(s=.314){let e=(kt*s+zt)%ut;return()=>(e=(kt*e+zt)%ut,e/ut)}function Dn(s){return Math.pow(2,-10*s)*Math.sin((s-.2/4)*(2*Math.PI)/.2)+1}function Ln(s){return s<.5?.5*Math.pow(2,20*s-10)*Math.sin((20*s-11.125)*(2*Math.PI)/.9):.5*(2-Math.pow(2,-20*s+10)*Math.sin((20*s-11.125)*(2*Math.PI)/.9))}function Bn(s,e=4){return Math.max(e-Math.floor(Math.log10(s)),0)}function An(s){if(s.length<=1)return s;const e=new Map,t=new Map;for(const i of s){if(i.length<2)throw new Error("couple length must be greater than 1");const[r,c]=[i[0],i[i.length-1]];e.set(r,c),t.set(c,r)}const n=[];let o=s.length**2;for(;(e.size||t.size)&&o-- >0;){let i=e.keys().next().value;const r=[i];let c=e.get(i);for(;c!==void 0&&c!==i&&o-- >0;)r.push(c),e.delete(i),t.delete(c),i=c,c=e.get(c);for(i=r[0],c=t.get(i);c!==void 0&&c!==i&&o-- >0;)r.unshift(c),e.delete(c),t.delete(i),i=c,c=t.get(c);n.push(r)}return n}function Tn(s,e){const t=s[0]*e[1]-s[1]*e[0],n=s[0]*e[0]+s[1]*e[1];return Math.atan2(t,n)}class O{constructor(e,t="NONZERO"){this.shapes=e,this.windingRule=t}static fromCommands(e){const t=[];let n=[];for(const i of e)i.type==="M"?(n.length>0&&t.push(n),n=[i]):n.push(i);n.length>0&&t.push(n);const o=t.map(i=>G.fromCommands(i));return new O(o)}static fromPathString(e){const t=at(e);return O.fromCommands(t)}getBBox2(e=A()){for(const t of this.shapes)t.getBBox2(e);return e}includePoint(e){let t=!0;for(const n of this.shapes){const{isRightHand:o}=n,i=n.includePoint(e);if(t&&(t=o?i:!i),!t)return!1}return t}applyFn(e){for(const t of this.shapes)for(const n of t.curves)n.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=_t(this.shapes),t=[];for(const n of e)n.length>0&&t.push(new O(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 G(n)});return new O(e,this.windingRule)}}const In=[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800],ft=s=>In[s],Fn=(s,e)=>ft(s)/(ft(e)*ft(s-e)),Qt=(s,e,t)=>Fn(e,s)*t**s*(1-t)**(e-s),Ht=(s,e=0,t=1)=>Math.min(Math.max(s,e),t);function _n(s,e,t=!0){return t?n=>{const[o,i]=n,r=e.length-1,c=e[0].length-1;let a=(o-s.x)/s.width,h=(i-s.y)/s.height,l=0,u=y();for(let d=0;d<=r;d++){const p=Qt(d,r,a);for(let P=0;P<=c;P++){const g=Qt(P,c,h),x=p*g;l+=x,it(u,u,e[d][P],x)}}Zt(u,u,1/l),Ot(n,u)}:n=>{const[o,i]=n,r=e.length-1,c=e[0].length-1;let a=Ht((o-s.x)/s.width),h=Ht((i-s.y)/s.height);a=a*r,h=h*c;const l=Math.floor(a),u=Math.floor(h);a=a-l,h=h-u;const d=e[l][u],p=e[l+1][u],P=e[l][u+1],g=e[l+1][u+1],x=(1-a)*(1-h)*d[0]+a*(1-h)*p[0]+(1-a)*h*P[0]+a*h*g[0],M=(1-a)*(1-h)*d[1]+a*(1-h)*p[1]+(1-a)*h*P[1]+a*h*g[1];return n[0]=x,n[1]=M,n}}class Pt{constructor(e){C(this,"value");C(this,"next",null);this.value=e}}class dt{constructor(){C(this,"head",null);C(this,"tail",null);C(this,"size",0)}static fromArray(e){const t=new dt;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 Pt(e);this.tail&&(this.tail.next=t),this.tail=t,this.head||(this.head=t),this.size++}prepend(e){const t=new Pt(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}}f.BezierCurve=q,f.BezierCurveType=St,f.BezierShape=Ft,f.ClosedShape=G,f.Curve=mt,f.LineCurve=I,f.LineCurveType=K,f.LineToQuadratic=Jt,f.LinkedList=dt,f.Node=Pt,f.Path=O,f.Polygon=Kt,f.Polyline=ht,f.QuadraticCurve=_,f.QuadraticCurveType=vt,f.Shape=Et,f.SingleShape=k,f.calDisData=Pn,f.calExtendCurve=pn,f.calPointsArea=X,f.calRadius=xn,f.checkLineCurveIntersect=Mt,f.connectShape=fn,f.copyMatrix=vn,f.createBBox2=A,f.createMatrix=Mn,f.createSvgByPath=en,f.cross=lt,f.findRayIntersection=ln,f.gaussElimination=Wt,f.getAngleChange=Tn,f.getBezierCurvesBBox=At,f.getBezierFromCurve=Ct,f.getBezierShapeFormSingleShape=an,f.getCurvature=mn,f.getCurvesByPolygon=It,f.getDebugPathStr=sn,f.getDigit=Bn,f.getEaseElasticInOut=Ln,f.getEaseElasticOut=Dn,f.getPathStr=Dt,f.getPointsRightHandRule=rt,f.getPolygon=Bt,f.getRandomGenerate=Nt,f.getRandomPathStr=cn,f.getRoots=F,f.getTriangleArea=En,f.includeBBox2=pt,f.interpolatePolygon=on,f.isInLeft=tn,f.isPointInPoints=ct,f.isSelfIntersect=dn,f.isVec2DirectionClose=un,f.lineInterSect=ot,f.lineToBezier=wt,f.linearRegression=$t,f.max=Sn,f.mean=nt,f.median=bn,f.mergeBBox2=Q,f.mergeCouple=An,f.min=Cn,f.pathStringToPathCommands=at,f.quadraticToBezier=bt,f.resizeCurvesByBBox=Tt,f.simplyCurves=nn,f.splitByBBox=_t,f.std=wn,f.sum=z,f.toAngle=Vt,f.toRadian=gn,f.transformPoint=_n,f.variance=qt,f.vec2ToAngle=yn,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "geo-2d", | ||
"version": "1.0.0-beta.18", | ||
"version": "1.0.0-beta.19", | ||
"type": "module", | ||
@@ -17,3 +17,6 @@ "files": [ | ||
], | ||
"default": "./dist/geometry.es.js" | ||
"default": [ | ||
"./src/index.ts", | ||
"./dist/geometry.es.js" | ||
] | ||
}, | ||
@@ -20,0 +23,0 @@ "require": "./dist/geometry.umd.js" |
Sorry, the diff of this file is too big to display
140308
3478