pantograph2d 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{QuadraticBezier-B2g_Iyyl.js → QuadraticBezier-BeY2TXKH.js} +464 -433
- package/dist/QuadraticBezier-BeY2TXKH.js.map +1 -0
- package/dist/{QuadraticBezier-CuRsIP_D.cjs → QuadraticBezier-eSR75IzC.cjs} +9 -9
- package/dist/QuadraticBezier-eSR75IzC.cjs.map +1 -0
- package/dist/draw-BmJ8wIc9.cjs +2 -0
- package/dist/draw-BmJ8wIc9.cjs.map +1 -0
- package/dist/{draw-BJW5kfm9.js → draw-DzKVhurb.js} +94 -89
- package/dist/draw-DzKVhurb.js.map +1 -0
- package/dist/{models-DdZq-waE.js → models-BHeLX0dj.js} +544 -527
- package/dist/models-BHeLX0dj.js.map +1 -0
- package/dist/models-Fv9xfQBT.cjs +4 -0
- package/dist/models-Fv9xfQBT.cjs.map +1 -0
- package/dist/pantograph/drawShape.cjs +1 -1
- package/dist/pantograph/drawShape.js +2 -2
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +2 -2
- package/dist/pantograph/svg.cjs +1 -1
- package/dist/pantograph/svg.js +1 -1
- package/dist/pantograph.cjs +2 -2
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.js +83 -83
- package/dist/pantograph.js.map +1 -1
- package/dist/svg-BTO7h1ix.js +62 -0
- package/dist/svg-BTO7h1ix.js.map +1 -0
- package/dist/svg-b6SOnbda.cjs +8 -0
- package/dist/svg-b6SOnbda.cjs.map +1 -0
- package/dist/types/src/algorithms/offsets/offsetSegment.d.ts +1 -0
- package/dist/types/src/models/BoundingBox.d.ts +1 -0
- package/dist/types/src/models/Diagram.d.ts +1 -0
- package/dist/types/src/models/Figure.d.ts +1 -0
- package/dist/types/src/models/Loop.d.ts +1 -0
- package/dist/types/src/models/Strand.d.ts +5 -0
- package/dist/types/src/models/TransformationMatrix.d.ts +1 -0
- package/dist/types/src/models/segments/Arc.d.ts +1 -0
- package/dist/types/src/models/segments/CubicBezier.d.ts +1 -0
- package/dist/types/src/models/segments/EllipseArc.d.ts +1 -0
- package/dist/types/src/models/segments/Line.d.ts +2 -0
- package/dist/types/src/models/segments/QuadraticBezier.d.ts +1 -0
- package/dist/types/src/tesselationOperations.d.ts +4 -4
- package/package.json +2 -2
- package/dist/QuadraticBezier-B2g_Iyyl.js.map +0 -1
- package/dist/QuadraticBezier-CuRsIP_D.cjs.map +0 -1
- package/dist/draw-9Elv4xz6.cjs +0 -2
- package/dist/draw-9Elv4xz6.cjs.map +0 -1
- package/dist/draw-BJW5kfm9.js.map +0 -1
- package/dist/models-DdZq-waE.js.map +0 -1
- package/dist/models-LHGiMarC.cjs +0 -4
- package/dist/models-LHGiMarC.cjs.map +0 -1
- package/dist/svg-BzloQ9l1.cjs +0 -8
- package/dist/svg-BzloQ9l1.cjs.map +0 -1
- package/dist/svg-D8vwkQf7.js +0 -62
- package/dist/svg-D8vwkQf7.js.map +0 -1
package/dist/models-LHGiMarC.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";var Rt=Object.defineProperty;var Nt=(t,n,e)=>n in t?Rt(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var b=(t,n,e)=>Nt(t,typeof n!="symbol"?n+"":n,e);const l=require("./QuadraticBezier-CuRsIP_D.cjs");function yt(t,n){const e=l.subtract(n,t.firstPoint),i=l.dotProduct(e,t.V)/t.squareLength;return t.paramPoint(i)}function D(t,n,e){const i=e||t.precision,s=yt(t,n.center),r=l.distance(s,n.center);if(r>n.radius+i)return[];if(Math.abs(r-n.radius)<i){const a=s;return t.isOnSegment(a)&&n.isOnSegment(a)?[a]:[]}const c=[],o=Math.sqrt(n.radius*n.radius-r*r),u=t.tangentAtFirstPoint,f=l.add(s,l.scalarMultiply(u,o));t.isOnSegment(f)&&n.isOnSegment(f)&&c.push(f);const h=l.add(s,l.scalarMultiply(u,-o));return t.isOnSegment(h)&&n.isOnSegment(h)&&c.push(h),c}const Qt=t=>{const{firstPoint:n,lastPoint:e,center:i,clockwise:s}=t;return new l.Arc(e,n,i,s,{ignoreChecks:!0})},Ut=(t,n)=>{if(t.isSame(n))return[t];const e=l.removeDuplicatePoints([n.isOnSegment(t.firstPoint)?t.firstPoint:null,n.isOnSegment(t.lastPoint)?t.lastPoint:null,t.isOnSegment(n.firstPoint)?n.firstPoint:null,t.isOnSegment(n.lastPoint)?n.lastPoint:null].filter(i=>i!==null)).sort((i,s)=>t.pointToParam(i)-t.pointToParam(s));if(e.length===0)return[];if(e.length===1)return[];if(e.length===2)return t.isSame(Qt(n))?[]:[new l.Arc(e[0],e[1],t.center,t.clockwise)];if(e.length===3){const i=l.sameVector(e[0],n.lastPoint)||l.sameVector(e[0],n.firstPoint)?1:0;return[new l.Arc(e[0+i],e[1+i],t.center,t.clockwise)]}else if(e.length===4)return[new l.Arc(e[0],e[1],t.center,t.clockwise),new l.Arc(e[2],e[3],t.center,t.clockwise)];throw new Error("Bug in the arc arc overlap algorithm")};function Z(t,n,e=!1,i){const s=i||t.precision,r=l.distance(t.center,n.center),c=t.radius+n.radius;if(r>c+s)return[];const o=Math.abs(t.radius-n.radius);if(r<o-s)return[];if(r<s)return o>s?[]:e?Ut(t,n):[];const u=l.normalize(l.subtract(n.center,t.center)),f=r>c-s;if(f||Math.abs(r-o)<s){const P=f||t.radius>n.radius?1:-1,w=l.add(t.center,l.scalarMultiply(u,P*t.radius));return t.isOnSegment(w)&&n.isOnSegment(w)?[w]:[]}const h=t.radius*t.radius/(2*r)-n.radius*n.radius/(2*r)+r/2,a=l.add(t.center,l.scalarMultiply(u,h)),p=Math.sqrt(t.radius*t.radius-h*h),d=l.perpendicular(u),m=l.add(a,l.scalarMultiply(d,p)),g=l.add(a,l.scalarMultiply(d,-p)),x=[];return t.isOnSegment(m)&&n.isOnSegment(m)&&x.push(m),t.isOnSegment(g)&&n.isOnSegment(g)&&x.push(g),x}function Y(t,n,e=1e-9){const i=t.transform(n.ellipseReferenceFrameTransform),s=i.slope,r=i.yIntercept,c=n.majorRadius*n.majorRadius,o=n.minorRadius*n.minorRadius,u=n.majorRadius*n.minorRadius,f=i.slope*i.slope,h=i.yIntercept*i.yIntercept,a=P=>P.map(w=>n.reverseEllipseReferenceFrameTransform.transform(w)).filter(w=>t.isOnSegment(w)&&n.isOnSegment(w));if(!Number.isFinite(s)){const P=i.firstPoint[0];if(Math.abs(P)-n.majorRadius>e)return[];if(Math.abs(Math.abs(P)-n.majorRadius)<e)return a([[P,0]]);const w=n.minorRadius*Math.sqrt(1-P*P/c),y=[P,w],A=[P,-w];return a([y,A])}const p=c*f+o-h;if(p<-e)return[];const d=c*f+o;if(Math.abs(p)<e){const P=-(c*s*r)/d,w=o*r/d;return a([[P,w]])}const m=Math.sqrt(p),g=[-(c*s*r+u*m)/d,(o*r-u*s*m)/d],x=[-(c*s*r-u*m)/d,(o*r+u*s*m)/d];return a([g,x])}function Ct(t,n){const e=Math.max(t.precision,n.precision),i=t.coefficients,s=i.x2,r=i.xy,c=i.y2,o=i.x,u=i.y,f=i.c,h=n.coefficients,a=h.x2,p=h.xy,d=h.y2,m=h.x,g=h.y,x=h.c,P={z0:f*s*m*m+s*s*x*x-o*s*m*x+a*a*f*f-2*s*x*a*f-o*m*a*f+a*o*o*x,z1:g*o*o*a-x*m*s*r-2*s*x*a*u-f*a*p*o+2*m*p*s*f+2*g*x*s*s+m*m*s*u-g*m*s*o-2*s*g*a*f-f*a*m*r+2*f*u*a*a-x*p*s*o-u*a*m*o+2*x*r*a*o,z2:g*g*s*s+2*d*x*s*s-u*a*m*r+x*a*r*r-u*a*p*o-x*p*s*r-2*s*g*a*u+2*m*p*s*u-d*m*s*o-2*s*d*a*f+p*p*s*f+2*g*r*a*o+u*u*a*a-c*a*m*o-g*p*s*o+2*f*c*a*a-f*a*p*r+d*o*o*a+m*m*s*c-g*m*s*r-2*s*x*a*c,z3:-2*s*a*c*g+g*a*r*r+2*d*r*a*o-c*a*p*o+p*p*s*u-g*p*s*r-2*s*d*a*u-u*a*p*r-d*p*s*o+2*g*d*s*s+2*u*c*a*a-c*a*m*r+2*m*p*s*c-d*m*s*r,z4:s*s*d*d-2*s*d*a*c+a*a*c*c-r*s*p*d-r*p*a*c+r*r*a*d+c*s*p*p},y=l.solveGenericPolynomial([P.z0,P.z1,P.z2,P.z3,P.z4],e).flatMap(A=>{const z=s*p*A+s*m-a*r*A-a*o;if(z)return[[-(s*x+s*d*A*A-a*c*A*A+s*g*A-a*u*A-a*f)/z,A]];const E=r*A+o,v=-E/(2*s),V=c*A*A+u*A+f,F=E*E/(4*s*s)-V/s;if(Math.abs(F)<e)return[[v,A]];if(F>0){const _=Math.sqrt(F);return[[v+_,A],[v-_,A]]}return[]});return l.removeDuplicatePoints(y,e)}function ct(t,n){return Ct(t,n).filter(i=>t.isOnSegment(i)&&n.isOnSegment(i))}const jt=t=>{const{firstPoint:n,lastPoint:e,center:i,majorRadius:s,minorRadius:r,tiltAngle:c,clockwise:o}=t;return new l.EllipseArc(e,n,i,s,r,c,o,{ignoreChecks:!0,angleUnits:"rad"})},$t=(t,n)=>{if(t.isSame(n))return[t];const e=(s,r)=>new l.EllipseArc(s,r,t.center,t.majorRadius,t.minorRadius,t.tiltAngle,t.clockwise,{ignoreChecks:!0,angleUnits:"rad"}),i=l.removeDuplicatePoints([n.isOnSegment(t.firstPoint)?t.firstPoint:null,n.isOnSegment(t.lastPoint)?t.lastPoint:null,t.isOnSegment(n.firstPoint)?n.firstPoint:null,t.isOnSegment(n.lastPoint)?n.lastPoint:null].filter(s=>s!==null)).sort((s,r)=>t.pointToParam(s)-t.pointToParam(r));if(i.length===0)return[];if(i.length===1)return[];if(i.length===2)return t.isSame(jt(n))?[]:[e(i[0],i[1])];if(i.length===3){const s=l.sameVector(i[0],n.lastPoint)||l.sameVector(i[0],n.firstPoint)?1:0;return[e(i[0+s],i[1+s])]}else if(i.length===4)return[e(i[0],i[1]),e(i[2],i[3])];throw new Error("Bug in the ellipse arc ellipse arc overlap algorithm")};function Ht(t,n,e=!1){const i=Math.max(t.precision,n.precision);return l.sameVector(t.center,n.center)&&Math.abs(t.majorRadius-n.majorRadius)<i&&Math.abs(t.minorRadius-n.minorRadius)<i&&(Math.abs(t.tiltAngle-n.tiltAngle)<i||Math.abs(Math.abs(t.tiltAngle-n.tiltAngle)-Math.PI)<i)?e?$t(t,n):[]:Ct(t,n).filter(c=>t.isOnSegment(c)&&n.isOnSegment(c))}function lt(t,n){const[e,i]=t.firstPoint,[s,r]=t.lastPoint,c=new l.TransformationMatrix().translate(-e,-i).rotate(-Math.atan2(r-i,s-e)),o=c.clone().inverse(),u=n.transform(c);return u.paramsAtY(0).map(f=>u.paramPoint(f)).map(f=>o.transform(f)).filter(f=>t.isOnSegment(f))}const Yt=(t,n=1e-9)=>{let e=t;return Math.abs(t)<n&&(e=0),e.toFixed(-Math.log10(n))};function Mt(t,n=1e-9){return Array.from(new Map(t.map(e=>[Yt(e,n),e])).values())}const Xt=(t,n)=>{const[[e,i,s,r],[c,o,u,f]]=n.polynomialCoefficients,h=t.coefficients,a=h.x2,p=h.xy,d=h.y2,m=h.x,g=h.y,x=h.c,P=e*e,w=i*i,y=s*s,A=r*r,z=c*c,E=o*o,v=u*u,V=f*f,F=x+m*e+a*P+g*c+p*e*c+d*z,_=m*i+2*a*e*i+p*i*c+g*o+p*e*o+2*d*c*o,Vt=a*w+m*s+2*a*e*s+p*s*c+p*i*o+d*E+g*u+p*e*u+2*d*c*u,_t=2*a*i*s+m*r+2*a*e*r+p*r*c+p*s*o+p*i*u+2*d*o*u+g*f+p*e*f+2*d*c*f,Tt=a*y+2*a*i*r+p*r*o+p*s*u+d*v+p*i*f+2*d*o*f,qt=2*a*s*r+p*r*u+p*s*f+2*d*u*f,Dt=a*A+p*r*f+d*V;return[F,_,Vt,_t,Tt,qt,Dt]};function ut(t,n){const e=Math.max(t.precision,n.precision),i=Xt(t,n),s=l.solveGenericPolynomial(i,e).filter(r=>r>=-n.precision&&r<=1+n.precision);return Mt(s,e).map(r=>n.paramPoint(r)).filter(r=>t.isOnSegment(r))}const Gt=(t,n)=>{const[[e,i,s],[r,c,o]]=n.polynomialCoefficients,u=t.coefficients,f=u.x2,h=u.xy,a=u.y2,p=u.x,d=u.y,m=u.c,g=e*e,x=i*i,P=s*s,w=r*r,y=c*c,A=o*o,z=f*g+h*e*r+a*w+p*e+d*r+m,E=2*f*e*i+h*e*c+h*i*r+2*a*r*c+p*i+d*c,v=2*f*e*s+f*x+h*e*o+h*i*c+h*s*r+2*a*r*o+a*y+p*s+d*o,V=2*f*i*s+h*i*o+h*s*c+2*a*c*o,F=f*P+h*s*o+a*A;return[z,E,v,V,F]};function at(t,n){const e=Math.max(t.precision,n.precision),i=Gt(t,n),s=l.solveQuartic(...i).filter(r=>r>=-n.precision&&r<=1+n.precision);return Mt(s,e).map(r=>n.paramPoint(r)).filter(r=>t.isOnSegment(r))}function S(t,{firstPoint:n,lastPoint:e},i=1e-9){const s=l.subtract(e,n);return Math.abs(s[0])<i?s[1]>0?n[0]-t[0]:t[0]-n[0]:Math.abs(s[1])<i?s[0]>0?t[1]-n[1]:n[1]-t[1]:l.crossProduct(s,l.subtract(t,n))/l.length(s)}class tt{constructor(n,e,i,s){this.firstPoint=n,this.lastPoint=e,this.negativeThickness=i,this.positiveThickness=s}get width(){return this.positiveThickness-this.negativeThickness}}const Wt=3/4,Jt=4/9;function Kt(t){const n=S(t.firstControlPoint,t),e=S(t.lastControlPoint,t),i=n*e>0?Wt:Jt;return new tt(t.firstPoint,t.lastPoint,i*Math.min(0,n,e),i*Math.max(0,n,e))}function Zt(t){const n=S(t.controlPoint,t);return new tt(t.firstPoint,t.lastPoint,Math.min(0,n/2),Math.max(0,n/2))}function tn(t){if(t instanceof l.CubicBezier)return Kt(t);if(t instanceof l.QuadraticBezier)return Zt(t);throw new Error("Not implemented")}function nn(t){const n=t.paramPoint(.5),e=l.perpendicular(l.subtract(n,t.firstPoint)),i=l.add(n,e),s={firstPoint:n,lastPoint:i},r=[S(t.firstPoint,s),S(t.lastPoint,s)];return t instanceof l.CubicBezier?r.push(S(t.firstControlPoint,s),S(t.lastControlPoint,s)):t instanceof l.QuadraticBezier&&r.push(S(t.controlPoint,s)),new tt(n,i,Math.min(...r),Math.max(...r))}function ft(t,n){const e=[];for(let i=1;i<t.length;i++){const s=t[i];if(s[1]===n){e.push(s[0]);continue}const r=t[i-1],c=n-r[1],o=n-s[1];if(c*o<0){e.push(r[0]+(n-r[1])*(s[0]-r[0])/(s[1]-r[1]));continue}}return e}class T{constructor(n,e){this.from=n,this.to=e}get size(){return this.from==="start"?this.to==="end"?1:this.to:this.to==="end"?1-this.from:Math.abs(this.from-this.to)}clipCurve(n){return this.from==="start"?this.to==="end"?n:n.splitAtParameters([this.to])[0]:this.to==="end"?n.splitAtParameters([this.from])[1]:n.splitAtParameters([this.from,this.to])[1]}}function en(t,n){if(t instanceof l.CubicBezier)return new rn([S(t.firstPoint,n),S(t.firstControlPoint,n),S(t.lastControlPoint,n),S(t.lastPoint,n)]);if(t instanceof l.QuadraticBezier)return new sn([S(t.firstPoint,n),S(t.controlPoint,n),S(t.lastPoint,n)]);throw new Error("Not implemented")}class sn{constructor(n){b(this,"topHull",[]);b(this,"bottomHull",[]);this.distances=n;const[e,i,s]=n,r=[0,e],c=[1/2,i],o=[1,s],u=s-e,f=e;i-(u*(1/2)+f)>0?(this.topHull=[r,c,o],this.bottomHull=[r,o]):(this.topHull=[r,o],this.bottomHull=[r,c,o])}get startDistance(){return this.distances[0]}get endDistance(){return this.distances[2]}}class rn{constructor(n){b(this,"topHull",[]);b(this,"bottomHull",[]);this.distances=n;const[e,i,s,r]=n,c=[0,e],o=[1/3,i],u=[2/3,s],f=[1,r],h=r-e,a=e,p=i-(h*(1/3)+a),d=s-(h*(2/3)+a);let m=null,g=null;if(p*d<0)m=[c,o,f],g=[c,u,f];else{const P=p/d;P>=2?(m=[c,o,f],g=[c,f]):P<=.5?(m=[c,u,f],g=[c,f]):(m=[c,o,u,f],g=[c,f])}p<0&&([m,g]=[g,m]),this.topHull=m,this.bottomHull=g}get startDistance(){return this.distances[0]}get endDistance(){return this.distances[3]}}function ht(t,n){const e=en(n,t),i=ft(e.topHull,t.negativeThickness),s=ft(e.bottomHull,t.positiveThickness),r=e.endDistance>=t.negativeThickness&&e.endDistance<=t.positiveThickness;if(!i.length&&!s.length)return r?new T("start","end"):null;if(i.length===1&&s.length===1)return new T(i[0],s[0]);if(i.length===2&&s.length===2)throw new Error("Bug in the clipping algorithm, unexpected number of crossing points");const c=i.length?i:s;return c.length===2?new T(c[0],c[1]):r?new T(c[0],"end"):new T("start",c[0])}function pt(t,n){const e=tn(t),i=ht(e,n);if(!i)return null;const s=nn(t),r=ht(s,n);return r?i.size>r.size?r.clipCurve(n):i.clipCurve(n):null}const N=t=>t instanceof l.QuadraticBezier?l.squareLength(l.subtract(t.controlPoint,t.firstPoint))+l.squareLength(l.subtract(t.controlPoint,t.lastPoint)):l.squareLength(l.subtract(t.firstControlPoint,t.firstPoint))+l.squareLength(l.subtract(t.lastControlPoint,t.firstControlPoint))+l.squareLength(l.subtract(t.lastControlPoint,t.lastPoint));function L(t,n,e=1e-9,{maxIterations:i=100}={}){const s=Math.max(e*e,Number.EPSILON*10);let r=t,c=n,o=N(r),u=N(c);for(let f=0;f<i;f++){const h=o>s?pt(c,r):r;if(!h)return[];const a=N(h),p=u>s?pt(h,c):c;if(!p)return[];const d=N(p);if(a<=s&&d<=s)return[h.boundingBox.intersection(p.boundingBox).center];if(l.sameVector(h.firstPoint,h.lastPoint)&&p.isOnSegment(h.firstPoint))return[h.firstPoint];if(l.sameVector(p.firstPoint,p.lastPoint)&&h.isOnSegment(p.firstPoint))return[p.firstPoint];if(a>.8*o&&d>.8*u)if(a/o>d/u){const[m,g]=h.splitAtParameters([.5]);return l.removeDuplicatePoints([...L(m,p,e,{maxIterations:i-f}),...L(g,p,e,{maxIterations:i-f})],e)}else{const[m,g]=p.splitAtParameters([.5]);return l.removeDuplicatePoints([...L(h,m,e,{maxIterations:i-f}),...L(h,g,e,{maxIterations:i-f})],e)}r=h,c=p,o=a,u=d}throw new Error("Bézier clip: Maximum number of iterations reached")}function on(t,n){const e=[];if([[t.firstPoint,n],[t.lastPoint,n],[n.firstPoint,t],[n.lastPoint,t]].forEach(([s,r])=>{r.isOnSegment(s)&&e.push(s)}),e.length<2)return null;if(e.length===2)return[t.splitAt(e)[1]];if(e.length===3)return l.sameVector(e[0],t.firstPoint)&&l.sameVector(e[1],t.lastPoint)?[t]:[n];if(e.length===4)return[t]}function cn(t,n,e=!1){const i=Math.max(t.precision,n.precision);if(e){const s=on(t,n);if(s)return s}return L(t,n,i)}function ln(t,n){const e=[];if([[t.firstPoint,n],[t.lastPoint,n],[n.firstPoint,t],[n.lastPoint,t]].forEach(([s,r])=>{r.isOnSegment(s)&&e.push(s)}),e.length<2)return null;if(e.length===2)return[t.splitAt(e)[1]];if(e.length===3)return l.sameVector(e[0],t.firstPoint)&&l.sameVector(e[1],t.lastPoint)?[t]:[n];if(e.length===4)return[t]}function un(t,n,e=!1){const i=Math.max(t.precision,n.precision);if(e){const s=ln(t,n);if(s)return s}return L(t,n,i)}function an(t,n,e){if(t instanceof l.Line&&n instanceof l.Line){const i=l.lineLineIntersection(t,n,!1,e);return i===null?[]:[i]}if(t instanceof l.Line&&n instanceof l.Arc)return D(t,n,e);if(t instanceof l.Arc&&n instanceof l.Line)return D(n,t,e);if(t instanceof l.Arc&&n instanceof l.Arc)return Z(t,n,!1,e);throw new Error("Not implemented")}function R(t,n,e){if(t instanceof l.Line&&n instanceof l.Line){const i=l.lineLineIntersection(t,n,!0,e);return i===null?{intersections:[],overlaps:[],count:0}:i instanceof l.Line?{intersections:[],overlaps:[i],count:1}:{intersections:[i],overlaps:[],count:1}}if(!t.boundingBox.overlaps(n.boundingBox))return{intersections:[],overlaps:[],count:0};if(t instanceof l.Line&&n instanceof l.Arc){const i=D(t,n,e);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof l.Arc&&n instanceof l.Line){const i=D(n,t,e);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof l.Arc&&n instanceof l.Arc){const i=Z(t,n,!0,e);return i.length?i[0]instanceof l.Arc?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}if(t instanceof l.Line&&n instanceof l.EllipseArc){const i=Y(t,n,e);return{intersections:i,overlaps:[],count:i.length}}if(n instanceof l.Line&&t instanceof l.EllipseArc){const i=Y(n,t,e);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof l.Arc&&n instanceof l.EllipseArc){const i=ct(t,n);return{intersections:i,overlaps:[],count:i.length}}if(n instanceof l.Arc&&t instanceof l.EllipseArc){const i=ct(n,t);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof l.EllipseArc&&n instanceof l.EllipseArc){const i=Ht(t,n,!0);return i.length?i[0]instanceof l.EllipseArc?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}if(t instanceof l.Line&&(n instanceof l.CubicBezier||n instanceof l.QuadraticBezier)){const i=lt(t,n);return{intersections:i,overlaps:[],count:i.length}}if(n instanceof l.Line&&(t instanceof l.CubicBezier||t instanceof l.QuadraticBezier)){const i=lt(n,t);return{intersections:i,overlaps:[],count:i.length}}if((t instanceof l.Arc||t instanceof l.EllipseArc)&&n instanceof l.QuadraticBezier){const i=at(t,n);return{intersections:i,overlaps:[],count:i.length}}if((n instanceof l.Arc||n instanceof l.EllipseArc)&&t instanceof l.QuadraticBezier){const i=at(n,t);return{intersections:i,overlaps:[],count:i.length}}if((t instanceof l.Arc||t instanceof l.EllipseArc)&&n instanceof l.CubicBezier){const i=ut(t,n);return{intersections:i,overlaps:[],count:i.length}}if((n instanceof l.Arc||n instanceof l.EllipseArc)&&t instanceof l.CubicBezier){const i=ut(n,t);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof l.QuadraticBezier&&n instanceof l.QuadraticBezier){const i=un(t,n);return i.length?i[0]instanceof l.QuadraticBezier?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}if(t instanceof l.QuadraticBezier&&n instanceof l.CubicBezier||n instanceof l.QuadraticBezier&&t instanceof l.CubicBezier){const i=L(t,n);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof l.CubicBezier&&n instanceof l.CubicBezier){const i=cn(t,n);return i.length?i[0]instanceof l.CubicBezier?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}throw new Error("Not implemented")}function It(t){const n=[];for(let e=0;e<t;e++)for(let i=0;i<=e;i++)n.push([e,i]);return n}function*X(t){for(const[n,e]of It(t.length))n!==e&&(yield[t[n],t[e]])}class Bt extends l.Transformable{constructor(e,{ignoreChecks:i=!1}={}){super();b(this,"segments");b(this,"_boundingBox",null);i||Et(e),this.segments=e}get repr(){return this.segments.map(e=>e.repr).join(`
|
|
2
|
-
`)+`
|
|
3
|
-
`}get info(){return this.repr}get firstPoint(){return this.segments[0].firstPoint}get lastPoint(){return this.segments[this.segments.length-1].lastPoint}get segmentsCount(){return this.segments.length}onStroke(e){return this.segments.some(i=>i.isOnSegment(e))}intersects(e){return this.boundingBox.overlaps(e.boundingBox)?this.segments.some(i=>e.segments.some(s=>R(i,s).count>0)):!1}overlappingSegments(e){return this.segments.flatMap(i=>e.segments.flatMap(s=>i.boundingBox.overlaps(s.boundingBox)?R(i,s).overlaps:[]))}get boundingBox(){if(this._boundingBox===null){let e=this.segments[0].boundingBox;this.segments.slice(1).forEach(i=>{e=e.merge(i.boundingBox)}),this._boundingBox=e}return this._boundingBox}[Symbol.for("nodejs.util.inspect.custom")](){return this.repr}}function fn(t,n="Stroke"){It(t.length).forEach(([e,i])=>{if(e===i)return;const s=t[e],r=t[i],c=R(s,r),o=Math.max(s.precision,r.precision);if(c.count!==0){if(c.count===1&&!c.overlaps.length){const u=e-i,f=c.intersections[0];if(u===1&&l.sameVector(s.firstPoint,f,o)||u===-1&&l.sameVector(s.lastPoint,f,o)||u===t.length-1&&l.sameVector(s.lastPoint,f,o)&&l.sameVector(r.firstPoint,f,o)||-u===t.length-1&&l.sameVector(s.firstPoint,f,o)&&l.sameVector(r.lastPoint,f,o))return}if(!(c.count===2&&t.length===2&&(l.sameVector(s.firstPoint,c.intersections[0],o)&&l.sameVector(s.lastPoint,c.intersections[1],o)||l.sameVector(s.firstPoint,c.intersections[1],o)&&l.sameVector(s.lastPoint,c.intersections[0],o))))throw new Error(`${n} segments must not intersect, but segments ${s.info} and ${r.info} do at ${JSON.stringify(c.intersections)}`)}})}function Et(t,n="Stroke"){if(t.length===0)throw new Error(`${n} must have at least one segment`);l.zip([t.slice(0,-1),t.slice(1)]).forEach(([e,i])=>{if(!l.sameVector(e.lastPoint,i.firstPoint))throw new Error(`${n} segments must be connected, but ${e.info} and ${i.info} are not`)}),fn(t,n)}function dt(t,n){return!!(t instanceof l.Line&&n instanceof l.Line&&l.parallel(t.V,n.V)||t instanceof l.Arc&&n instanceof l.Arc&&l.sameVector(t.center,n.center)&&t.radius-n.radius<t.precision)}function mt(t,n){if(t instanceof l.Line&&n instanceof l.Line)return new l.Line(t.firstPoint,n.lastPoint);if(t instanceof l.Arc&&n instanceof l.Arc)return new l.Arc(t.firstPoint,n.lastPoint,t.center,t.clockwise);throw new Error("Not implemented")}function vt(t){let n=!1;const e=[];for(const i of t.segments){if(e.length===0){e.push(i);continue}const s=e[e.length-1];dt(s,i)?(n=!0,e.pop(),e.push(mt(s,i))):e.push(i)}if(l.sameVector(t.firstPoint,t.lastPoint)&&dt(e[0],e[e.length-1])){n=!0;const i=e.pop();e[0]=mt(i,e[0])}return n?e:null}class M extends Bt{constructor(){super(...arguments);b(this,"strokeType","STRAND")}reverse(){const e=this.segments.map(i=>i.reverse());return e.reverse(),new M(e,{ignoreChecks:!0})}clone(){return new M(this.segments.map(e=>e.clone()),{ignoreChecks:!0})}extend(e){if(!l.sameVector(this.lastPoint,e.firstPoint))throw console.error(this.repr,e.repr),new Error("Cannot extend strand: connection point is not the same");return new M([...this.segments,...e.segments])}simplify(){const e=vt(this);return e?new M(e,{ignoreChecks:!0}):this}transform(e){return new M(this.segments.map(i=>i.transform(e)),{ignoreChecks:!0})}}const hn=(t,n)=>{const e=l.lineLineParams(n,{V:[1,0],firstPoint:t,precision:n.precision});if(e==="parallel")return 0;const{intersectionParam1:i,intersectionParam2:s}=e;if(!n.isValidParameter(i)||s<=-n.precision)return 0;if(Math.abs(i)<n.precision||Math.abs(i-1)<n.precision){const[,r]=n.midPoint;return t[1]-r<0?1:0}return 1};class nt{constructor(n){b(this,"_count",0);b(this,"segment");this.segment=n}update(n,e=!1){!e&&!this.segment.isOnSegment(n)||(l.sameVector(n,this.segment.firstPoint)?this._count+=this.segment.tangentAtFirstPoint[1]>0?1:0:l.sameVector(n,this.segment.lastPoint)?this._count+=this.segment.tangentAtLastPoint[1]>0?0:1:this._count+=1)}get count(){return this._count}}const pn=(t,n)=>{const e=n.precision,i=Math.abs(t[1]-n.center[1]);if(i>n.radius+e)return 0;const s=l.squareDistance(t,n.center),r=n.radius*n.radius,c=e*e;if(Math.abs(s-r)<c&&n.isOnSegment(t))return 0;const o=s-r>c;if(o&&n.center[0]<t[0])return 0;const u=Math.sqrt(n.radius*n.radius-i*i),f=new nt(n);return f.update([n.center[0]+u,t[1]]),o&&f.update([n.center[0]-u,t[1]]),f.count},dn=(t,n)=>{const e=n.boundingBox.xMax+n.boundingBox.width/2,i=new l.Line(t,[e,t[1]]),s=new nt(n);return Y(i,n).forEach(r=>{s.update(r,!0)}),s.count},mn=(t,n)=>{const e=new nt(n);return n.paramsAtY(t[1]).map(i=>{try{return n.paramPoint(i)}catch{return null}}).filter(i=>i!==null).filter(i=>{const[s]=i;return s>=t[0]}).forEach(i=>{e.update(i,!0)}),e.count};function gn(t,n){if(n instanceof l.Line)return hn(t,n);if(n instanceof l.Arc)return pn(t,n);if(n instanceof l.EllipseArc)return dn(t,n);if(n instanceof l.CubicBezier||n instanceof l.QuadraticBezier)return mn(t,n);throw new Error("Not implemented")}class B extends Bt{constructor(e,{ignoreChecks:i=!1}={}){super(e,{ignoreChecks:!0});b(this,"strokeType","LOOP");b(this,"_clockwise",null);i||Pn(e)}get clockwise(){if(this._clockwise===null){const e=this.segments.flatMap(s=>s instanceof l.Line?[s.firstPoint]:[s.firstPoint,s.paramPoint(.5)]),i=e.map((s,r)=>{const c=e[(r+1)%e.length];return(c[0]-s[0])*(c[1]+s[1])}).reduce((s,r)=>s+r,0);this._clockwise=i>0}return this._clockwise}clone(){return new B(this.segments.map(e=>e.clone()),{ignoreChecks:!0})}reverse(){const e=this.segments.map(i=>i.reverse());return e.reverse(),new B(e,{ignoreChecks:!0})}transform(e){return new B(this.segments.map(i=>i.transform(e)),{ignoreChecks:!0})}contains(e,{strokeIsInside:i=!1}={}){return this.onStroke(e)?i:this.boundingBox.contains(e)?this.segments.reduce((r,c)=>r+gn(e,c),0)%2===1:!1}simplify(){const e=vt(this);return e?new B(e,{ignoreChecks:!0}):this}}function Pn(t){if(Et(t,"Loop"),!l.sameVector(t[0].firstPoint,t[t.length-1].lastPoint))throw new Error("Loop segment must be closed")}const wn=[l.Line,l.Arc,l.EllipseArc,l.QuadraticBezier,l.CubicBezier];function Ft(t){return wn.some(n=>t instanceof n)}function Lt(t){if(t instanceof l.Line)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint};if(t instanceof l.Arc)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint,center:t.center,clockwise:t.clockwise};if(t instanceof l.EllipseArc)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint,center:t.center,clockwise:t.clockwise,majorRadius:t.majorRadius,minorRadius:t.minorRadius,tiltAngle:t.tiltAngle};if(t instanceof l.QuadraticBezier)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint,controlPoint:t.controlPoint};if(t instanceof l.CubicBezier)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint,firstControlPoint:t.firstControlPoint,lastControlPoint:t.lastControlPoint};throw new Error("Unknown segment type")}function G(t){return{type:"LOOP",segments:t.segments.map(Lt)}}function zt(t){return{type:"FIGURE",contour:G(t.contour),holes:t.holes.map(G)}}function xn(t){return{type:"DIAGRAM",figures:t.figures.map(zt)}}function W(t){if(t instanceof I)return xn(t);if(t instanceof C)return zt(t);if(t instanceof B)return G(t);if(Ft(t))return Lt(t);throw new Error("Unknown shape type")}class An{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(n,e){let i=this.length++;for(;i>0;){const s=i-1>>1,r=this.values[s];if(e>=r)break;this.ids[i]=this.ids[s],this.values[i]=r,i=s}this.ids[i]=n,this.values[i]=e}pop(){if(this.length===0)return;const n=this.ids[0];if(this.length--,this.length>0){const e=this.ids[0]=this.ids[this.length],i=this.values[0]=this.values[this.length],s=this.length>>1;let r=0;for(;r<s;){let c=(r<<1)+1;const o=c+1;let u=this.ids[c],f=this.values[c];const h=this.values[o];if(o<this.length&&h<f&&(c=o,u=this.ids[o],f=h),f>=i)break;this.ids[r]=u,this.values[r]=f,r=c}this.ids[r]=e,this.values[r]=i}return n}peek(){if(this.length!==0)return this.ids[0]}peekValue(){if(this.length!==0)return this.values[0]}shrink(){this.ids.length=this.values.length=this.length}}const gt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],H=3;class et{static from(n,e=0){if(e%8!==0)throw new Error("byteOffset must be 8-byte aligned.");if(!n||n.byteLength===void 0||n.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");const[i,s]=new Uint8Array(n,e+0,2);if(i!==251)throw new Error("Data does not appear to be in a Flatbush format.");const r=s>>4;if(r!==H)throw new Error(`Got v${r} data when expected v${H}.`);const c=gt[s&15];if(!c)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(n,e+2,1),[u]=new Uint32Array(n,e+4,1);return new et(u,o,c,void 0,n,e)}constructor(n,e=16,i=Float64Array,s=ArrayBuffer,r,c=0){if(n===void 0)throw new Error("Missing required argument: numItems.");if(isNaN(n)||n<=0)throw new Error(`Unexpected numItems value: ${n}.`);this.numItems=+n,this.nodeSize=Math.min(Math.max(+e,2),65535),this.byteOffset=c;let o=n,u=o;this._levelBounds=[o*4];do o=Math.ceil(o/this.nodeSize),u+=o,this._levelBounds.push(u*4);while(o!==1);this.ArrayType=i,this.IndexArrayType=u<16384?Uint16Array:Uint32Array;const f=gt.indexOf(this.ArrayType),h=u*4*this.ArrayType.BYTES_PER_ELEMENT;if(f<0)throw new Error(`Unexpected typed array class: ${i}.`);r&&r.byteLength!==void 0&&!r.buffer?(this.data=r,this._boxes=new this.ArrayType(this.data,c+8,u*4),this._indices=new this.IndexArrayType(this.data,c+8+h,u),this._pos=u*4,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1]):(this.data=new s(8+h+u*this.IndexArrayType.BYTES_PER_ELEMENT),this._boxes=new this.ArrayType(this.data,8,u*4),this._indices=new this.IndexArrayType(this.data,8+h,u),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(this.data,0,2).set([251,(H<<4)+f]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=n),this._queue=new An}add(n,e,i=n,s=e){const r=this._pos>>2,c=this._boxes;return this._indices[r]=r,c[this._pos++]=n,c[this._pos++]=e,c[this._pos++]=i,c[this._pos++]=s,n<this.minX&&(this.minX=n),e<this.minY&&(this.minY=e),i>this.maxX&&(this.maxX=i),s>this.maxY&&(this.maxY=s),r}finish(){if(this._pos>>2!==this.numItems)throw new Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);const n=this._boxes;if(this.numItems<=this.nodeSize){n[this._pos++]=this.minX,n[this._pos++]=this.minY,n[this._pos++]=this.maxX,n[this._pos++]=this.maxY;return}const e=this.maxX-this.minX||1,i=this.maxY-this.minY||1,s=new Uint32Array(this.numItems),r=65535;for(let c=0,o=0;c<this.numItems;c++){const u=n[o++],f=n[o++],h=n[o++],a=n[o++],p=Math.floor(r*((u+h)/2-this.minX)/e),d=Math.floor(r*((f+a)/2-this.minY)/i);s[c]=Sn(p,d)}J(s,n,this._indices,0,this.numItems-1,this.nodeSize);for(let c=0,o=0;c<this._levelBounds.length-1;c++){const u=this._levelBounds[c];for(;o<u;){const f=o;let h=n[o++],a=n[o++],p=n[o++],d=n[o++];for(let m=1;m<this.nodeSize&&o<u;m++)h=Math.min(h,n[o++]),a=Math.min(a,n[o++]),p=Math.max(p,n[o++]),d=Math.max(d,n[o++]);this._indices[this._pos>>2]=f,n[this._pos++]=h,n[this._pos++]=a,n[this._pos++]=p,n[this._pos++]=d}}}search(n,e,i,s,r){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let c=this._boxes.length-4;const o=[],u=[];for(;c!==void 0;){const f=Math.min(c+this.nodeSize*4,wt(c,this._levelBounds));for(let h=c;h<f;h+=4){if(i<this._boxes[h]||s<this._boxes[h+1]||n>this._boxes[h+2]||e>this._boxes[h+3])continue;const a=this._indices[h>>2]|0;c>=this.numItems*4?o.push(a):(r===void 0||r(a))&&u.push(a)}c=o.pop()}return u}neighbors(n,e,i=1/0,s=1/0,r){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let c=this._boxes.length-4;const o=this._queue,u=[],f=s*s;t:for(;c!==void 0;){const h=Math.min(c+this.nodeSize*4,wt(c,this._levelBounds));for(let a=c;a<h;a+=4){const p=this._indices[a>>2]|0,d=Pt(n,this._boxes[a],this._boxes[a+2]),m=Pt(e,this._boxes[a+1],this._boxes[a+3]),g=d*d+m*m;g>f||(c>=this.numItems*4?o.push(p<<1,g):(r===void 0||r(p))&&o.push((p<<1)+1,g))}for(;o.length&&o.peek()&1;)if(o.peekValue()>f||(u.push(o.pop()>>1),u.length===i))break t;c=o.length?o.pop()>>1:void 0}return o.clear(),u}}function Pt(t,n,e){return t<n?n-t:t<=e?0:t-e}function wt(t,n){let e=0,i=n.length-1;for(;e<i;){const s=e+i>>1;n[s]>t?i=s:e=s+1}return n[e]}function J(t,n,e,i,s,r){if(Math.floor(i/r)>=Math.floor(s/r))return;const c=t[i+s>>1];let o=i-1,u=s+1;for(;;){do o++;while(t[o]<c);do u--;while(t[u]>c);if(o>=u)break;bn(t,n,e,o,u)}J(t,n,e,i,u,r),J(t,n,e,u+1,s,r)}function bn(t,n,e,i,s){const r=t[i];t[i]=t[s],t[s]=r;const c=4*i,o=4*s,u=n[c],f=n[c+1],h=n[c+2],a=n[c+3];n[c]=n[o],n[c+1]=n[o+1],n[c+2]=n[o+2],n[c+3]=n[o+3],n[o]=u,n[o+1]=f,n[o+2]=h,n[o+3]=a;const p=e[i];e[i]=e[s],e[s]=p}function Sn(t,n){let e=t^n,i=65535^e,s=65535^(t|n),r=t&(n^65535),c=e|i>>1,o=e>>1^e,u=s>>1^i&r>>1^s,f=e&s>>1^r>>1^r;e=c,i=o,s=u,r=f,c=e&e>>2^i&i>>2,o=e&i>>2^i&(e^i)>>2,u^=e&s>>2^i&r>>2,f^=i&s>>2^(e^i)&r>>2,e=c,i=o,s=u,r=f,c=e&e>>4^i&i>>4,o=e&i>>4^i&(e^i)>>4,u^=e&s>>4^i&r>>4,f^=i&s>>4^(e^i)&r>>4,e=c,i=o,s=u,r=f,u^=e&s>>8^i&r>>8,f^=i&s>>8^(e^i)&r>>8,e=u^u>>1,i=f^f>>1;let h=t^n,a=i|65535^(h|e);return h=(h|h<<8)&16711935,h=(h|h<<4)&252645135,h=(h|h<<2)&858993459,h=(h|h<<1)&1431655765,a=(a|a<<8)&16711935,a=(a|a<<4)&252645135,a=(a|a<<2)&858993459,a=(a|a<<1)&1431655765,(a<<1|h)>>>0}function it(t,n=1e-7){if(t.length===0)return[];if(t.length===1)return[t];const e=new et(t.length);t.forEach(r=>{const[c,o]=r.firstPoint;e.add(c-n,o-n,c+n,o+n)}),e.finish();const i=[],s=new Set;return t.forEach((r,c)=>{if(s.has(c))return;const o=[r];let u=c;s.add(c);let f=t.length;for(;;){if(f--<0)throw new Error("Infinite loop detected");const h=o[o.length-1].lastPoint,[a,p]=h,d=e.search(a-n,p-n,a+n,p+n),m=w=>Math.abs((u-w)%t.length),g=d.filter(w=>!s.has(w)).map(w=>[t[w],w,m(w)]).sort(([,,w],[,,y])=>m(w)-m(y));if(g.length===0){i.push(o);break}const[x,P]=g[0];o.push(x),s.add(P),u=P}}),i}class C extends l.Transformable{constructor(e,i=[],{ignoreChecks:s=!1}={}){super();b(this,"contour");b(this,"holes");s||yn(e,i),this.contour=e,this.holes=i}get boundingBox(){return this.contour.boundingBox}get isFull(){return this.holes.length===0}get allLoops(){return[this.contour,...this.holes]}clone(){return new C(this.contour.clone(),this.holes.map(e=>e.clone()))}transform(e){return new C(this.contour.transform(e),this.holes.map(i=>i.transform(e)))}contains(e,{strokeIsInside:i=!1}={}){return this.contour.contains(e,{strokeIsInside:i})&&!this.holes.some(s=>s.contains(e,{strokeIsInside:i}))}intersects(e){return this.allLoops.some(i=>e.allLoops.some(s=>i.intersects(s)))}overlappingStrands(e){const i=e instanceof C?e.allLoops:[e],s=this.allLoops.flatMap(r=>i.flatMap(c=>r.overlappingSegments(c)));return it(s).map(r=>new M(r))}}function yn(t,n=[]){if(!t)throw new Error("Figure must have a contour");for(const[e,i]of X([t,...n]))if(e.intersects(i))throw new Error("Loops in a figure must not intersect");if(n.some(e=>!t.contains(e.firstPoint)&&!t.onStroke(e.firstPoint)))throw new Error("Holes must be inside the contour");for(const[e,i]of X(n))if(e.contains(i.firstPoint))throw console.error(W(e),W(i)),new Error("Holes must not be inside other holes")}const Q=(t,n,e=1e-7)=>Math.abs(t-n)<=e,Cn=(t,n)=>{const e=t.boundingBox,i=n.boundingBox;return Q(e.xMin,i.xMin)&&Q(e.yMin,i.yMin)&&Q(e.xMax,i.xMax)&&Q(e.yMax,i.yMax)},Mn=(t,n)=>{if(t.segmentsCount!==n.segmentsCount||!Cn(t,n))return!1;const e=t.segments,i=n.segments,s=e.length,r=(c,o)=>{for(let u=0;u<s;u+=1){const f=(c+o*u+s)%s;if(!e[u].isSame(i[f]))return!1}return!0};for(let c=0;c<s;c+=1)if(e[0].isSame(i[c])&&(r(c,1)||r(c,-1)))return!0;return!1},In=t=>{const n=[];return t.forEach(e=>{n.some(i=>Mn(e,i))||n.push(e)}),n},Bn=t=>{const n=t.map((s,r)=>t.slice(r+1).map((c,o)=>[o+r+1,c]).filter(([,c])=>s.boundingBox.overlaps(c.boundingBox)).map(([c])=>c)),e=[],i=Array(n.length);return n.forEach((s,r)=>{let c=i[r];c||(c=[],e.push(c)),c.push(t[r]),s.length&&s.forEach(o=>{i[o]=c})}),e},kt=t=>t.map((n,e)=>{const s=n.segments[0].midPoint,r=t.filter((c,o)=>e===o?!1:c.contains(s));return{loop:n,isIn:r}}),En=(t,n)=>t.flatMap(({loop:e})=>st(n.filter(({loop:i,isIn:s})=>i===e||s.indexOf(e)!==-1))),vn=(t,n)=>{const e=n.filter(({isIn:s})=>s.length<=1),i=st(kt(t.map(({loop:s})=>s)));return[e,...i]},st=t=>{if(!t.length)return[];const n=t.filter(({isIn:i})=>!i.length),e=t.filter(({isIn:i})=>i.length>1);return n.length===1&&e.length===0?[t]:n.length>1?En(n,t):vn(e,t)};function q(t){const n=In(t);return Bn(n).map(kt).flatMap(st).map(i=>{if(i.length===1)return new C(i[0].loop);i.sort((c,o)=>c.isIn.length-o.isIn.length);const[s,...r]=i.map(({loop:c})=>c);return new C(s,r)})}function Fn(t,n){const e=[];for(const i of t)for(const s of n)e.push([i,s]);return e}function*K(t,n,e){const i=o=>n.some(u=>l.sameVector(u,o.lastPoint)),s=(o,u)=>o.segmentType!==u.segmentType||!u.isOnSegment(o.firstPoint)||!u.isOnSegment(o.lastPoint)?!1:o.segmentType!=="LINE"?u.isOnSegment(o.midPoint):!0,r=o=>e.some(u=>o.isSame(u)||s(o,u));let c=[];for(const o of t)i(o)?(c.push(o),yield new M(c,{ignoreChecks:!0}),c=[]):r(o)?(c.length&&(yield new M(c,{ignoreChecks:!0}),c=[]),yield new M([o],{ignoreChecks:!0})):c.push(o);c.length&&(yield new M(c,{ignoreChecks:!0}))}const xt=(t,n)=>{const e=t.findIndex(r=>l.sameVector(n,r.firstPoint)),i=t.slice(0,e);return t.slice(e).concat(i)},At=(t,n)=>{let e=t;const i=o=>l.sameVector(o.firstPoint,n.firstPoint)&&l.sameVector(o.lastPoint,n.lastPoint);let s=t.findIndex(i);if(s===-1){const o=t.map(u=>u.reverse());if(o.reverse(),s=o.findIndex(i),s===-1)throw console.error(o.map(u=>u.repr),n.repr),new Error("Failed to rotate to segment start");e=o}const r=e.slice(0,s);return e.slice(s).concat(r)};function Ln(t,n,e){return t.filter(i=>{const s=n.filter(o=>l.sameVector(o.firstPoint,i)||l.sameVector(o.lastPoint,i));if(s.length%2)throw new Error("Bug in the intersection algo on non crossing point");const r=s.map(o=>e.contains(o.midPoint));return!(r.every(o=>o)||!r.some(o=>o))})}function zn(t,n,e,i=!1){let s=[];const r=[],c=new Array(t.segments.length).fill(0).map(()=>[]),o=new Array(n.segments.length).fill(0).map(()=>[]);if(t.segments.forEach((d,m)=>{n.segments.forEach((g,x)=>{const{intersections:P,overlaps:w}=R(d,g,e);s.push(...P),c[m].push(...P),o[x].push(...P),r.push(...w);const y=w.flatMap(A=>[A.firstPoint,A.lastPoint]);s.push(...y),c[m].push(...y),o[x].push(...y)})}),s=l.removeDuplicatePoints(s,e),!s.length||s.length===1)return null;const u=([d,m])=>m.length?d.splitAt(m):[d];let f=l.zip([t.segments,c]).flatMap(u),h=l.zip([n.segments,o]).flatMap(u);if(s=Ln(s,f,n),!s.length&&!r.length)return null;if(r.length){const d=r[0];f=At(f,d),h=At(h,d)}else{const d=s[0];f=xt(f,d),h=xt(h,d)}let a=Array.from(K(f,s,r)),p=Array.from(K(h,s,r));return(!l.sameVector(p[0].lastPoint,a[0].lastPoint)||r.length>0&&p[0].segmentsCount!==1)&&(p=p.map(d=>d.reverse()).reverse(),l.sameVector(p[0].lastPoint,a[0].lastPoint)||(a=a.map(d=>d.reverse()).reverse())),l.zip([a,p]).map(([d,m])=>{if(i){if((x=>x.segments.every(P=>r.some(w=>P.isSame(w)||P.segmentType===w.segmentType&&w.isOnSegment(P.firstPoint)&&w.isOnSegment(P.lastPoint)&&(P.segmentType==="LINE"||w.isOnSegment(P.midPoint)))))(d))return[d,"same"]}else if(d.segmentsCount===1&&r.some(g=>d.segments[0].isSame(g)))return[d,"same"];return[d,m]})}function bt(t){let n=t[0];for(const e of t.slice(1))n=n.extend(e);if(!l.sameVector(n.firstPoint,n.lastPoint))throw console.error(l.reprVector(n.firstPoint),l.reprVector(n.lastPoint)),new Error("Bug in the intersection algo on non closing strand");return new B(n.segments)}function kn(t,n){const e=l.zip([n.slice(0,-1),n.slice(1)]).map(([s,r])=>bt(t.slice(s,r)));let i=t.slice(n[n.length-1]);return n[0]!==0&&(i=i.concat(t.slice(0,n[0]))),e.push(bt(i)),e}function On(t){if(!t.length)return[];const n=t.map(s=>s.firstPoint);let e=t.map(s=>s.lastPoint);e=e.slice(-1).concat(e.slice(0,-1));const i=l.zip([n,e]).flatMap(([s,r],c)=>l.sameVector(s,r)?[]:c);try{return kn(t,i)}catch{return it(t.flatMap(r=>r.segments)).filter(r=>r.length>1).filter(r=>l.sameVector(r[0].firstPoint,r.at(-1).lastPoint)).map(r=>new B(r))}}const St=(t,n)=>{if(t.length===0)return[n];const e=t.at(-1);return l.sameVector(e.lastPoint,n.firstPoint)?t.slice(0,-1).concat([e.extend(n)]):l.sameVector(e.lastPoint,n.lastPoint)?t.slice(0,-1).concat([e.extend(n.reverse())]):t.concat([n])},Vn=(t,n)=>t.length===0?[n]:l.sameVector(t[0].firstPoint,n.lastPoint)?[n.extend(t[0])].concat(t.slice(1)):[n].concat(t);function rt(t,n,{firstInside:e,secondInside:i,firstBoundaryInside:s=!1,secondBoundaryInside:r=!1}){const c=zn(t,n,void 0,s||r);if(!c){const h=t.segments[0].midPoint,a=n.contains(h,{strokeIsInside:r}),p=n.segments[0].midPoint,d=t.contains(p,{strokeIsInside:s});return{identical:!1,firstCurveInSecond:a,secondCurveInFirst:d}}if(c.every(([,h])=>h==="same"))return{identical:!0};let o=null,u=null;const f=c.flatMap(([h,a])=>{let p=[],d=0;if(a==="same")return u===1?(u=1,h):u===2||u===0?(u=null,[]):u===null?(o?o=o.extend(h):o=h,[]):(console.error("weird situation"),[]);const m=h.segments[0].midPoint,g=n.contains(m,{strokeIsInside:r});(e==="keep"&&g||e==="remove"&&!g)&&(d+=1,p=St(p,h));const x=a.segments[0].midPoint,P=t.contains(x,{strokeIsInside:s});if(i==="keep"&&P||i==="remove"&&!P){const w=a;d+=1,d===2&&p.length?(p=St(p,w),o=null):p=[w]}return u===null&&d===1&&o&&(p=Vn(p,o)),d===1&&(u=d,o=null),p.length?p:(o=null,[])});return On(f)}const _n=(t,n,e)=>{const i=rt(t,n,{firstInside:"remove",secondInside:"remove",...e});return Array.isArray(i)?i:i.identical?[t]:i.firstCurveInSecond?[n]:i.secondCurveInFirst?[t]:[t,n]},U=(t,n,e)=>{const i=rt(t,n,{firstInside:"remove",secondInside:"keep",...e});return Array.isArray(i)?i:i.identical?[]:i.firstCurveInSecond?[]:i.secondCurveInFirst?[t,n]:[t]},ot=(t,n,e)=>{const i=(e==null?void 0:e.firstBoundaryInside)??!1,s=(e==null?void 0:e.secondBoundaryInside)??!1,r=i||s,c=(u,f,h)=>u.segments.every(a=>f.contains(a.midPoint,{strokeIsInside:h}));if(r){if(c(t,n,s))return[t];if(c(n,t,i))return[n]}const o=rt(t,n,{firstInside:"keep",secondInside:"keep",...e});return Array.isArray(o)?o:o.identical?[t]:o.firstCurveInSecond?[t]:o.secondCurveInFirst?[n]:[]};function Tn(t){const n=new Map,e=[];return t.forEach((i,s)=>{let r;n.has(s)?r=n.get(s):(r={current:[i],fusedWith:new Set([s])},e.push(r)),t.slice(s+1).forEach((c,o)=>{const u=r.current,f=s+o+1;if(r.fusedWith.has(f))return;let h=[c],a=!1;if(n.has(f)&&(h=n.get(f).current,a=!0),!u.some(m=>h.some(g=>m.intersects(g))))return;let d;u.length>1||h.length>1?d=k(u,h):d=Ot(u[0],h[0]),r.fusedWith.add(f),r.current=d,a||n.set(f,r)})}),e.flatMap(({current:i})=>i)}function Ot(t,n){const e=_n(t.contour,n.contour),i=n.holes.flatMap(c=>U(c,t.contour)),s=t.holes.flatMap(c=>U(c,n.contour)),r=Fn(t.holes,n.holes).flatMap(([c,o])=>ot(c,o));return q([...e,...i,...s,...r])}function j(t,n){if(t.isFull&&n.isFull)return q(U(t.contour,n.contour));if(t.isFull){const i=U(t.contour,n.contour),s=n.holes.flatMap(r=>ot(r,t.contour,{firstBoundaryInside:!0}));return q([...i,...s])}else if(n.isFull&&!t.contour.intersects(n.contour))if(t.contour.contains(n.contour.firstPoint)){const i=k(t.holes.map(s=>new C(s)),[n]);return q([t.contour,...i.flatMap(s=>s.allLoops)])}else return[t];let e=j(new C(t.contour),n);return t.holes.forEach(i=>{e=e.flatMap(s=>j(s,new C(i)))}),e}function qn(t,n){const e=ot(t.contour,n.contour);if(!e.length)return[];let i=q(e);return i=O(i,t.holes.map(s=>new C(s))),O(i,n.holes.map(s=>new C(s)))}function k(t,n){if(!t.length)return n;if(!n.length)return t;if(t.length===1&&n.length>1||n.length===1&&t.length>1)return Tn([...t,...n]);if(t.length>1&&n.length>1){let e=k([t[0]],n);return t.slice(1).forEach(i=>{e=k([i],e)}),e}return t.length===1&&n.length===1?Ot(t[0],n[0]):[]}function O(t,n){if(!t.length)return[];if(!n.length)return t;if(t.length===1&&n.length===1)return j(t[0],n[0]);if(t.length>1)return t.flatMap(i=>O([i],n));let e=j(t[0],n[0]);return n.slice(1).forEach(i=>{e=O(e,[i])}),e}function $(t,n){return!t.length||!n.length?[]:t.length===1&&n.length===1?qn(t[0],n[0]):t.length>1?t.flatMap(e=>$([e],n)):n.flatMap(e=>$(t,[e]))}class I extends l.Transformable{constructor(e=[],{ignoreChecks:i=!1}={}){super();b(this,"figures");b(this,"_boundingBox",null);i||Dn(e),this.figures=e}get isEmpty(){return this.figures.length===0}get boundingBox(){if(this.isEmpty)return new l.BoundingBox;if(this._boundingBox===null){let e=this.figures[0].boundingBox;for(const i of this.figures.slice(1))e=e.merge(i.boundingBox);this._boundingBox=e}return this._boundingBox}clone(){return new I(this.figures.map(e=>e.clone()))}transform(e){return new I(this.figures.map(i=>i.transform(e)))}contains(e,{strokeIsInside:i=!1}={}){return this.figures.some(s=>s.contains(e,{strokeIsInside:i}))}intersects(e){return this.figures.some(i=>e.figures.some(s=>i.intersects(s)))}overlappingStrands(e){return this.figures.flatMap(i=>e instanceof I?e.figures.flatMap(s=>i.overlappingStrands(s)):i.overlappingStrands(e))}fuse(e){return new I(k(this.figures,e.figures))}cut(e){return new I(O(this.figures,e.figures))}intersect(e){return new I($(this.figures,e.figures))}}function Dn(t){for(const[n,e]of X(t))if(n.intersects(e))throw new Error("Diagram figures must not intersect")}exports.Diagram=I;exports.Figure=C;exports.Loop=B;exports.Strand=M;exports.arcArcIntersection=Z;exports.cutFiguresLists=O;exports.exportJSON=W;exports.findIntersections=an;exports.findIntersectionsAndOverlaps=R;exports.fuseFiguresLists=k;exports.intersectFiguresLists=$;exports.isSegment=Ft;exports.lineArcIntersection=D;exports.projectPointOnLine=yt;exports.stitchSegments=it;exports.strandsBetweenIntersections=K;
|
|
4
|
-
//# sourceMappingURL=models-LHGiMarC.cjs.map
|