pantograph2d 0.9.0 → 0.10.0

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.
Files changed (42) hide show
  1. package/dist/{QuadraticBezier-BKElJOgn.cjs → QuadraticBezier--UZr_xcV.cjs} +2 -2
  2. package/dist/QuadraticBezier--UZr_xcV.cjs.map +1 -0
  3. package/dist/{QuadraticBezier-PcRS9HZK.js → QuadraticBezier-DxieHk9z.js} +4 -2
  4. package/dist/QuadraticBezier-DxieHk9z.js.map +1 -0
  5. package/dist/{draw-L71G180-.cjs → draw-BUUNobTS.cjs} +2 -2
  6. package/dist/{draw-L71G180-.cjs.map → draw-BUUNobTS.cjs.map} +1 -1
  7. package/dist/{draw-N2ntigsw.js → draw-lOWnIN1o.js} +5 -3
  8. package/dist/{draw-N2ntigsw.js.map → draw-lOWnIN1o.js.map} +1 -1
  9. package/dist/models-CCo90hZc.cjs +4 -0
  10. package/dist/models-CCo90hZc.cjs.map +1 -0
  11. package/dist/{models-BjaFYsN2.js → models-DCkOI0hV.js} +643 -581
  12. package/dist/models-DCkOI0hV.js.map +1 -0
  13. package/dist/pantograph/drawShape.cjs +1 -1
  14. package/dist/pantograph/drawShape.js +1 -1
  15. package/dist/pantograph/models.cjs +1 -1
  16. package/dist/pantograph/models.js +2 -2
  17. package/dist/pantograph/svg.cjs +1 -1
  18. package/dist/pantograph/svg.js +1 -1
  19. package/dist/pantograph.cjs +2 -2
  20. package/dist/pantograph.cjs.map +1 -1
  21. package/dist/pantograph.js +621 -425
  22. package/dist/pantograph.js.map +1 -1
  23. package/dist/{svg-hNHYuj_r.js → svg-BIphc_zE.js} +3 -3
  24. package/dist/{svg-hNHYuj_r.js.map → svg-BIphc_zE.js.map} +1 -1
  25. package/dist/{svg-ZTvNxsWu.cjs → svg-BY5h3CDD.cjs} +3 -3
  26. package/dist/{svg-ZTvNxsWu.cjs.map → svg-BY5h3CDD.cjs.map} +1 -1
  27. package/dist/types/src/algorithms/boolean/loopBooleans.d.ts +10 -5
  28. package/dist/types/src/drawShape/drawPolysides.d.ts +1 -0
  29. package/dist/types/src/drawShape/index.d.ts +1 -0
  30. package/dist/types/src/featureOperations.d.ts +88 -0
  31. package/dist/types/src/main.d.ts +2 -2
  32. package/dist/types/src/models/Diagram.d.ts +3 -1
  33. package/dist/types/src/models/Figure.d.ts +3 -1
  34. package/dist/types/src/models/Loop.d.ts +3 -1
  35. package/dist/types/src/operations.d.ts +1 -0
  36. package/dist/types/src/vectorOperations.d.ts +1 -1
  37. package/package.json +3 -2
  38. package/dist/QuadraticBezier-BKElJOgn.cjs.map +0 -1
  39. package/dist/QuadraticBezier-PcRS9HZK.js.map +0 -1
  40. package/dist/models-BXU-Gx3U.cjs +0 -4
  41. package/dist/models-BXU-Gx3U.cjs.map +0 -1
  42. package/dist/models-BjaFYsN2.js.map +0 -1
@@ -1,4 +0,0 @@
1
- "use strict";var Dt=Object.defineProperty;var Rt=(t,n,e)=>n in t?Dt(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var b=(t,n,e)=>Rt(t,typeof n!="symbol"?n+"":n,e);const c=require("./QuadraticBezier-BKElJOgn.cjs");function yt(t,n){const e=c.subtract(n,t.firstPoint),i=c.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=c.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 o=[],l=Math.sqrt(n.radius*n.radius-r*r),u=t.tangentAtFirstPoint,f=c.add(s,c.scalarMultiply(u,l));t.isOnSegment(f)&&n.isOnSegment(f)&&o.push(f);const h=c.add(s,c.scalarMultiply(u,-l));return t.isOnSegment(h)&&n.isOnSegment(h)&&o.push(h),o}const Nt=t=>{const{firstPoint:n,lastPoint:e,center:i,clockwise:s}=t;return new c.Arc(e,n,i,s,{ignoreChecks:!0})},Qt=(t,n)=>{if(t.isSame(n))return[t];const e=c.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(Nt(n))?[]:[new c.Arc(e[0],e[1],t.center,t.clockwise)];if(e.length===3){const i=c.sameVector(e[0],n.lastPoint)||c.sameVector(e[0],n.firstPoint)?1:0;return[new c.Arc(e[0+i],e[1+i],t.center,t.clockwise)]}else if(e.length===4)return[new c.Arc(e[0],e[1],t.center,t.clockwise),new c.Arc(e[2],e[3],t.center,t.clockwise)];throw new Error("Bug in the arc arc overlap algorithm")};function K(t,n,e=!1,i){const s=i||t.precision,r=c.distance(t.center,n.center),o=t.radius+n.radius;if(r>o+s)return[];const l=Math.abs(t.radius-n.radius);if(r<l-s)return[];if(r<s)return l>s?[]:e?Qt(t,n):[];const u=c.normalize(c.subtract(n.center,t.center)),f=r>o-s;if(f||Math.abs(r-l)<s){const w=f||t.radius>n.radius?1:-1,x=c.add(t.center,c.scalarMultiply(u,w*t.radius));return t.isOnSegment(x)&&n.isOnSegment(x)?[x]:[]}const h=t.radius*t.radius/(2*r)-n.radius*n.radius/(2*r)+r/2,a=c.add(t.center,c.scalarMultiply(u,h)),p=Math.sqrt(t.radius*t.radius-h*h),d=c.perpendicular(u),m=c.add(a,c.scalarMultiply(d,p)),g=c.add(a,c.scalarMultiply(d,-p)),P=[];return t.isOnSegment(m)&&n.isOnSegment(m)&&P.push(m),t.isOnSegment(g)&&n.isOnSegment(g)&&P.push(g),P}function H(t,n,e=1e-9){const i=t.transform(n.ellipseReferenceFrameTransform),s=i.slope,r=i.yIntercept,o=n.majorRadius*n.majorRadius,l=n.minorRadius*n.minorRadius,u=n.majorRadius*n.minorRadius,f=i.slope*i.slope,h=i.yIntercept*i.yIntercept,a=w=>w.map(x=>n.reverseEllipseReferenceFrameTransform.transform(x)).filter(x=>t.isOnSegment(x)&&n.isOnSegment(x));if(!Number.isFinite(s)){const w=i.firstPoint[0];if(Math.abs(w)-n.majorRadius>e)return[];if(Math.abs(Math.abs(w)-n.majorRadius)<e)return a([[w,0]]);const x=n.minorRadius*Math.sqrt(1-w*w/o),C=[w,x],A=[w,-x];return a([C,A])}const p=o*f+l-h;if(p<-e)return[];const d=o*f+l;if(Math.abs(p)<e){const w=-(o*s*r)/d,x=l*r/d;return a([[w,x]])}const m=Math.sqrt(p),g=[-(o*s*r+u*m)/d,(l*r-u*s*m)/d],P=[-(o*s*r-u*m)/d,(l*r+u*s*m)/d];return a([g,P])}function St(t,n){const e=Math.max(t.precision,n.precision),i=t.coefficients,s=i.x2,r=i.xy,o=i.y2,l=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,P=h.c,w={z0:f*s*m*m+s*s*P*P-l*s*m*P+a*a*f*f-2*s*P*a*f-l*m*a*f+a*l*l*P,z1:g*l*l*a-P*m*s*r-2*s*P*a*u-f*a*p*l+2*m*p*s*f+2*g*P*s*s+m*m*s*u-g*m*s*l-2*s*g*a*f-f*a*m*r+2*f*u*a*a-P*p*s*l-u*a*m*l+2*P*r*a*l,z2:g*g*s*s+2*d*P*s*s-u*a*m*r+P*a*r*r-u*a*p*l-P*p*s*r-2*s*g*a*u+2*m*p*s*u-d*m*s*l-2*s*d*a*f+p*p*s*f+2*g*r*a*l+u*u*a*a-o*a*m*l-g*p*s*l+2*f*o*a*a-f*a*p*r+d*l*l*a+m*m*s*o-g*m*s*r-2*s*P*a*o,z3:-2*s*a*o*g+g*a*r*r+2*d*r*a*l-o*a*p*l+p*p*s*u-g*p*s*r-2*s*d*a*u-u*a*p*r-d*p*s*l+2*g*d*s*s+2*u*o*a*a-o*a*m*r+2*m*p*s*o-d*m*s*r,z4:s*s*d*d-2*s*d*a*o+a*a*o*o-r*s*p*d-r*p*a*o+r*r*a*d+o*s*p*p},C=c.solveGenericPolynomial([w.z0,w.z1,w.z2,w.z3,w.z4],e).flatMap(A=>{const z=s*p*A+s*m-a*r*A-a*l;if(z)return[[-(s*P+s*d*A*A-a*o*A*A+s*g*A-a*u*A-a*f)/z,A]];const E=r*A+l,F=-E/(2*s),_=o*A*A+u*A+f,v=E*E/(4*s*s)-_/s;if(Math.abs(v)<e)return[[F,A]];if(v>0){const O=Math.sqrt(v);return[[F+O,A],[F-O,A]]}return[]});return c.removeDuplicatePoints(C,e)}function ot(t,n){return St(t,n).filter(i=>t.isOnSegment(i)&&n.isOnSegment(i))}const Ut=t=>{const{firstPoint:n,lastPoint:e,center:i,majorRadius:s,minorRadius:r,tiltAngle:o,clockwise:l}=t;return new c.EllipseArc(e,n,i,s,r,o,l,{ignoreChecks:!0,angleUnits:"rad"})},jt=(t,n)=>{if(t.isSame(n))return[t];const e=(s,r)=>new c.EllipseArc(s,r,t.center,t.majorRadius,t.minorRadius,t.tiltAngle,t.clockwise,{ignoreChecks:!0,angleUnits:"rad"}),i=c.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(Ut(n))?[]:[e(i[0],i[1])];if(i.length===3){const s=c.sameVector(i[0],n.lastPoint)||c.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 $t(t,n,e=!1){const i=Math.max(t.precision,n.precision);return c.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?jt(t,n):[]:St(t,n).filter(o=>t.isOnSegment(o)&&n.isOnSegment(o))}function ct(t,n){const[e,i]=t.firstPoint,[s,r]=t.lastPoint,o=new c.TransformationMatrix().translate(-e,-i).rotate(-Math.atan2(r-i,s-e)),l=o.clone().inverse(),u=n.transform(o);return u.paramsAtY(0).map(f=>u.paramPoint(f)).map(f=>l.transform(f)).filter(f=>t.isOnSegment(f))}const Ht=(t,n=1e-9)=>{let e=t;return Math.abs(t)<n&&(e=0),e.toFixed(-Math.log10(n))};function Ct(t,n=1e-9){return Array.from(new Map(t.map(e=>[Ht(e,n),e])).values())}const Yt=(t,n)=>{const[[e,i,s,r],[o,l,u,f]]=n.polynomialCoefficients,h=t.coefficients,a=h.x2,p=h.xy,d=h.y2,m=h.x,g=h.y,P=h.c,w=e*e,x=i*i,C=s*s,A=r*r,z=o*o,E=l*l,F=u*u,_=f*f,v=P+m*e+a*w+g*o+p*e*o+d*z,O=m*i+2*a*e*i+p*i*o+g*l+p*e*l+2*d*o*l,Vt=a*x+m*s+2*a*e*s+p*s*o+p*i*l+d*E+g*u+p*e*u+2*d*o*u,_t=2*a*i*s+m*r+2*a*e*r+p*r*o+p*s*l+p*i*u+2*d*l*u+g*f+p*e*f+2*d*o*f,Ot=a*C+2*a*i*r+p*r*l+p*s*u+d*F+p*i*f+2*d*l*f,Tt=2*a*s*r+p*r*u+p*s*f+2*d*u*f,qt=a*A+p*r*f+d*_;return[v,O,Vt,_t,Ot,Tt,qt]};function lt(t,n){const e=Math.max(t.precision,n.precision),i=Yt(t,n),s=c.solveGenericPolynomial(i,e).filter(r=>r>=-n.precision&&r<=1+n.precision);return Ct(s,e).map(r=>n.paramPoint(r)).filter(r=>t.isOnSegment(r))}const Xt=(t,n)=>{const[[e,i,s],[r,o,l]]=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,P=i*i,w=s*s,x=r*r,C=o*o,A=l*l,z=f*g+h*e*r+a*x+p*e+d*r+m,E=2*f*e*i+h*e*o+h*i*r+2*a*r*o+p*i+d*o,F=2*f*e*s+f*P+h*e*l+h*i*o+h*s*r+2*a*r*l+a*C+p*s+d*l,_=2*f*i*s+h*i*l+h*s*o+2*a*o*l,v=f*w+h*s*l+a*A;return[z,E,F,_,v]};function ut(t,n){const e=Math.max(t.precision,n.precision),i=Xt(t,n),s=c.solveQuartic(...i).filter(r=>r>=-n.precision&&r<=1+n.precision);return Ct(s,e).map(r=>n.paramPoint(r)).filter(r=>t.isOnSegment(r))}function y(t,{firstPoint:n,lastPoint:e},i=1e-9){const s=c.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]:c.crossProduct(s,c.subtract(t,n))/c.length(s)}class Z{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 Gt=3/4,Wt=4/9;function Jt(t){const n=y(t.firstControlPoint,t),e=y(t.lastControlPoint,t),i=n*e>0?Gt:Wt;return new Z(t.firstPoint,t.lastPoint,i*Math.min(0,n,e),i*Math.max(0,n,e))}function Kt(t){const n=y(t.controlPoint,t);return new Z(t.firstPoint,t.lastPoint,Math.min(0,n/2),Math.max(0,n/2))}function Zt(t){if(t instanceof c.CubicBezier)return Jt(t);if(t instanceof c.QuadraticBezier)return Kt(t);throw new Error("Not implemented")}function tn(t){const n=t.paramPoint(.5),e=c.perpendicular(c.subtract(n,t.firstPoint)),i=c.add(n,e),s={firstPoint:n,lastPoint:i},r=[y(t.firstPoint,s),y(t.lastPoint,s)];return t instanceof c.CubicBezier?r.push(y(t.firstControlPoint,s),y(t.lastControlPoint,s)):t instanceof c.QuadraticBezier&&r.push(y(t.controlPoint,s)),new Z(n,i,Math.min(...r),Math.max(...r))}function at(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],o=n-r[1],l=n-s[1];if(o*l<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 nn(t,n){if(t instanceof c.CubicBezier)return new sn([y(t.firstPoint,n),y(t.firstControlPoint,n),y(t.lastControlPoint,n),y(t.lastPoint,n)]);if(t instanceof c.QuadraticBezier)return new en([y(t.firstPoint,n),y(t.controlPoint,n),y(t.lastPoint,n)]);throw new Error("Not implemented")}class en{constructor(n){b(this,"topHull",[]);b(this,"bottomHull",[]);this.distances=n;const[e,i,s]=n,r=[0,e],o=[1/2,i],l=[1,s],u=s-e,f=e;i-(u*(1/2)+f)>0?(this.topHull=[r,o,l],this.bottomHull=[r,l]):(this.topHull=[r,l],this.bottomHull=[r,o,l])}get startDistance(){return this.distances[0]}get endDistance(){return this.distances[2]}}class sn{constructor(n){b(this,"topHull",[]);b(this,"bottomHull",[]);this.distances=n;const[e,i,s,r]=n,o=[0,e],l=[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=[o,l,f],g=[o,u,f];else{const w=p/d;w>=2?(m=[o,l,f],g=[o,f]):w<=.5?(m=[o,u,f],g=[o,f]):(m=[o,l,u,f],g=[o,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 ft(t,n){const e=nn(n,t),i=at(e.topHull,t.negativeThickness),s=at(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 o=i.length?i:s;return o.length===2?new T(o[0],o[1]):r?new T(o[0],"end"):new T("start",o[0])}function ht(t,n){const e=Zt(t),i=ft(e,n);if(!i)return null;const s=tn(t),r=ft(s,n);return r?i.size>r.size?r.clipCurve(n):i.clipCurve(n):null}const N=t=>t instanceof c.QuadraticBezier?c.squareLength(c.subtract(t.controlPoint,t.firstPoint))+c.squareLength(c.subtract(t.controlPoint,t.lastPoint)):c.squareLength(c.subtract(t.firstControlPoint,t.firstPoint))+c.squareLength(c.subtract(t.lastControlPoint,t.firstControlPoint))+c.squareLength(c.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,o=n,l=N(r),u=N(o);for(let f=0;f<i;f++){const h=l>s?ht(o,r):r;if(!h)return[];const a=N(h),p=u>s?ht(h,o):o;if(!p)return[];const d=N(p);if(a<=s&&d<=s)return[h.boundingBox.intersection(p.boundingBox).center];if(c.sameVector(h.firstPoint,h.lastPoint)&&p.isOnSegment(h.firstPoint))return[h.firstPoint];if(c.sameVector(p.firstPoint,p.lastPoint)&&h.isOnSegment(p.firstPoint))return[p.firstPoint];if(a>.8*l&&d>.8*u)if(a/l>d/u){const[m,g]=h.splitAtParameters([.5]);return c.removeDuplicatePoints([...L(m,p,e,{maxIterations:i-f}),...L(g,p,e,{maxIterations:i-f})],e)}else{const[m,g]=p.splitAtParameters([.5]);return c.removeDuplicatePoints([...L(h,m,e,{maxIterations:i-f}),...L(h,g,e,{maxIterations:i-f})],e)}r=h,o=p,l=a,u=d}throw new Error("Bézier clip: Maximum number of iterations reached")}function rn(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 c.sameVector(e[0],t.firstPoint)&&c.sameVector(e[1],t.lastPoint)?[t]:[n];if(e.length===4)return[t]}function on(t,n,e=!1){const i=Math.max(t.precision,n.precision);if(e){const s=rn(t,n);if(s)return s}return L(t,n,i)}function cn(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 c.sameVector(e[0],t.firstPoint)&&c.sameVector(e[1],t.lastPoint)?[t]:[n];if(e.length===4)return[t]}function ln(t,n,e=!1){const i=Math.max(t.precision,n.precision);if(e){const s=cn(t,n);if(s)return s}return L(t,n,i)}function un(t,n,e){if(t instanceof c.Line&&n instanceof c.Line){const i=c.lineLineIntersection(t,n,!1,e);return i===null?[]:[i]}if(t instanceof c.Line&&n instanceof c.Arc)return D(t,n,e);if(t instanceof c.Arc&&n instanceof c.Line)return D(n,t,e);if(t instanceof c.Arc&&n instanceof c.Arc)return K(t,n,!1,e);throw new Error("Not implemented")}function R(t,n,e){if(t instanceof c.Line&&n instanceof c.Line){const i=c.lineLineIntersection(t,n,!0,e);return i===null?{intersections:[],overlaps:[],count:0}:i instanceof c.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 c.Line&&n instanceof c.Arc){const i=D(t,n,e);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof c.Arc&&n instanceof c.Line){const i=D(n,t,e);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof c.Arc&&n instanceof c.Arc){const i=K(t,n,!0,e);return i.length?i[0]instanceof c.Arc?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}if(t instanceof c.Line&&n instanceof c.EllipseArc){const i=H(t,n,e);return{intersections:i,overlaps:[],count:i.length}}if(n instanceof c.Line&&t instanceof c.EllipseArc){const i=H(n,t,e);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof c.Arc&&n instanceof c.EllipseArc){const i=ot(t,n);return{intersections:i,overlaps:[],count:i.length}}if(n instanceof c.Arc&&t instanceof c.EllipseArc){const i=ot(n,t);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof c.EllipseArc&&n instanceof c.EllipseArc){const i=$t(t,n,!0);return i.length?i[0]instanceof c.EllipseArc?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}if(t instanceof c.Line&&(n instanceof c.CubicBezier||n instanceof c.QuadraticBezier)){const i=ct(t,n);return{intersections:i,overlaps:[],count:i.length}}if(n instanceof c.Line&&(t instanceof c.CubicBezier||t instanceof c.QuadraticBezier)){const i=ct(n,t);return{intersections:i,overlaps:[],count:i.length}}if((t instanceof c.Arc||t instanceof c.EllipseArc)&&n instanceof c.QuadraticBezier){const i=ut(t,n);return{intersections:i,overlaps:[],count:i.length}}if((n instanceof c.Arc||n instanceof c.EllipseArc)&&t instanceof c.QuadraticBezier){const i=ut(n,t);return{intersections:i,overlaps:[],count:i.length}}if((t instanceof c.Arc||t instanceof c.EllipseArc)&&n instanceof c.CubicBezier){const i=lt(t,n);return{intersections:i,overlaps:[],count:i.length}}if((n instanceof c.Arc||n instanceof c.EllipseArc)&&t instanceof c.CubicBezier){const i=lt(n,t);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof c.QuadraticBezier&&n instanceof c.QuadraticBezier){const i=ln(t,n);return i.length?i[0]instanceof c.QuadraticBezier?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}if(t instanceof c.QuadraticBezier&&n instanceof c.CubicBezier||n instanceof c.QuadraticBezier&&t instanceof c.CubicBezier){const i=L(t,n);return{intersections:i,overlaps:[],count:i.length}}if(t instanceof c.CubicBezier&&n instanceof c.CubicBezier){const i=on(t,n);return i.length?i[0]instanceof c.CubicBezier?{intersections:[],overlaps:i,count:i.length}:{intersections:i,overlaps:[],count:i.length}:{intersections:[],overlaps:[],count:0}}throw new Error("Not implemented")}function Mt(t){const n=[];for(let e=0;e<t;e++)for(let i=0;i<=e;i++)n.push([e,i]);return n}function*Y(t){for(const[n,e]of Mt(t.length))n!==e&&(yield[t[n],t[e]])}class Bt extends c.Transformable{constructor(e,{ignoreChecks:i=!1}={}){super();b(this,"segments");b(this,"_boundingBox",null);i||It(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 an(t,n="Stroke"){Mt(t.length).forEach(([e,i])=>{if(e===i)return;const s=t[e],r=t[i],o=R(s,r),l=Math.max(s.precision,r.precision);if(o.count!==0){if(o.count===1&&!o.overlaps.length){const u=e-i,f=o.intersections[0];if(u===1&&c.sameVector(s.firstPoint,f,l)||u===-1&&c.sameVector(s.lastPoint,f,l)||u===t.length-1&&c.sameVector(s.lastPoint,f,l)&&c.sameVector(r.firstPoint,f,l)||-u===t.length-1&&c.sameVector(s.firstPoint,f,l)&&c.sameVector(r.lastPoint,f,l))return}if(!(o.count===2&&t.length===2&&(c.sameVector(s.firstPoint,o.intersections[0],l)&&c.sameVector(s.lastPoint,o.intersections[1],l)||c.sameVector(s.firstPoint,o.intersections[1],l)&&c.sameVector(s.lastPoint,o.intersections[0],l))))throw new Error(`${n} segments must not intersect, but segments ${s.info} and ${r.info} do at ${JSON.stringify(o.intersections)}`)}})}function It(t,n="Stroke"){if(t.length===0)throw new Error(`${n} must have at least one segment`);c.zip([t.slice(0,-1),t.slice(1)]).forEach(([e,i])=>{if(!c.sameVector(e.lastPoint,i.firstPoint))throw new Error(`${n} segments must be connected, but ${e.info} and ${i.info} are not`)}),an(t,n)}function pt(t,n){return!!(t instanceof c.Line&&n instanceof c.Line&&c.parallel(t.V,n.V)||t instanceof c.Arc&&n instanceof c.Arc&&c.sameVector(t.center,n.center)&&t.radius-n.radius<t.precision)}function dt(t,n){if(t instanceof c.Line&&n instanceof c.Line)return new c.Line(t.firstPoint,n.lastPoint);if(t instanceof c.Arc&&n instanceof c.Arc)return new c.Arc(t.firstPoint,n.lastPoint,t.center,t.clockwise);throw new Error("Not implemented")}function Et(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];pt(s,i)?(n=!0,e.pop(),e.push(dt(s,i))):e.push(i)}if(c.sameVector(t.firstPoint,t.lastPoint)&&pt(e[0],e[e.length-1])){n=!0;const i=e.pop();e[0]=dt(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(!c.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=Et(this);return e?new M(e,{ignoreChecks:!0}):this}transform(e){return new M(this.segments.map(i=>i.transform(e)),{ignoreChecks:!0})}}const fn=(t,n)=>{const e=c.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 tt{constructor(n){b(this,"_count",0);b(this,"segment");this.segment=n}update(n,e=!1){!e&&!this.segment.isOnSegment(n)||(c.sameVector(n,this.segment.firstPoint)?this._count+=this.segment.tangentAtFirstPoint[1]>0?1:0:c.sameVector(n,this.segment.lastPoint)?this._count+=this.segment.tangentAtLastPoint[1]>0?0:1:this._count+=1)}get count(){return this._count}}const hn=(t,n)=>{const e=n.precision,i=Math.abs(t[1]-n.center[1]);if(i>n.radius+e)return 0;const s=c.squareDistance(t,n.center),r=n.radius*n.radius,o=e*e;if(Math.abs(s-r)<o&&n.isOnSegment(t))return 0;const l=s-r>o;if(l&&n.center[0]<t[0])return 0;const u=Math.sqrt(n.radius*n.radius-i*i),f=new tt(n);return f.update([n.center[0]+u,t[1]]),l&&f.update([n.center[0]-u,t[1]]),f.count},pn=(t,n)=>{const e=n.boundingBox.xMax+n.boundingBox.width/2,i=new c.Line(t,[e,t[1]]),s=new tt(n);return H(i,n).forEach(r=>{s.update(r,!0)}),s.count},dn=(t,n)=>{const e=new tt(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 mn(t,n){if(n instanceof c.Line)return fn(t,n);if(n instanceof c.Arc)return hn(t,n);if(n instanceof c.EllipseArc)return pn(t,n);if(n instanceof c.CubicBezier||n instanceof c.QuadraticBezier)return dn(t,n);throw new Error("Not implemented")}class I extends Bt{constructor(e,{ignoreChecks:i=!1}={}){super(e,{ignoreChecks:!0});b(this,"strokeType","LOOP");b(this,"_clockwise",null);i||gn(e)}get clockwise(){if(this._clockwise===null){const e=this.segments.flatMap(s=>s instanceof c.Line?[s.firstPoint]:[s.firstPoint,s.paramPoint(.5)]),i=e.map((s,r)=>{const o=e[(r+1)%e.length];return(o[0]-s[0])*(o[1]+s[1])}).reduce((s,r)=>s+r,0);this._clockwise=i>0}return this._clockwise}clone(){return new I(this.segments.map(e=>e.clone()),{ignoreChecks:!0})}reverse(){const e=this.segments.map(i=>i.reverse());return e.reverse(),new I(e,{ignoreChecks:!0})}transform(e){return new I(this.segments.map(i=>i.transform(e)),{ignoreChecks:!0})}contains(e){return this.onStroke(e)||!this.boundingBox.contains(e)?!1:this.segments.reduce((s,r)=>s+mn(e,r),0)%2===1}simplify(){const e=Et(this);return e?new I(e,{ignoreChecks:!0}):this}}function gn(t){if(It(t,"Loop"),!c.sameVector(t[0].firstPoint,t[t.length-1].lastPoint))throw new Error("Loop segment must be closed")}const Pn=[c.Line,c.Arc,c.EllipseArc,c.QuadraticBezier,c.CubicBezier];function Ft(t){return Pn.some(n=>t instanceof n)}function vt(t){if(t instanceof c.Line)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint};if(t instanceof c.Arc)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint,center:t.center,clockwise:t.clockwise};if(t instanceof c.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 c.QuadraticBezier)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint,controlPoint:t.controlPoint};if(t instanceof c.CubicBezier)return{type:t.segmentType,firstPoint:t.firstPoint,lastPoint:t.lastPoint,firstControlPoint:t.firstControlPoint,lastControlPoint:t.lastControlPoint};throw new Error("Unknown segment type")}function X(t){return{type:"LOOP",segments:t.segments.map(vt)}}function Lt(t){return{type:"FIGURE",contour:X(t.contour),holes:t.holes.map(X)}}function wn(t){return{type:"DIAGRAM",figures:t.figures.map(Lt)}}function G(t){if(t instanceof B)return wn(t);if(t instanceof S)return Lt(t);if(t instanceof I)return X(t);if(Ft(t))return vt(t);throw new Error("Unknown shape type")}class xn{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 o=(r<<1)+1;const l=o+1;let u=this.ids[o],f=this.values[o];const h=this.values[l];if(l<this.length&&h<f&&(o=l,u=this.ids[l],f=h),f>=i)break;this.ids[r]=u,this.values[r]=f,r=o}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 mt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],$=3;class nt{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!==$)throw new Error(`Got v${r} data when expected v${$}.`);const o=mt[s&15];if(!o)throw new Error("Unrecognized array type.");const[l]=new Uint16Array(n,e+2,1),[u]=new Uint32Array(n,e+4,1);return new nt(u,l,o,void 0,n,e)}constructor(n,e=16,i=Float64Array,s=ArrayBuffer,r,o=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=o;let l=n,u=l;this._levelBounds=[l*4];do l=Math.ceil(l/this.nodeSize),u+=l,this._levelBounds.push(u*4);while(l!==1);this.ArrayType=i,this.IndexArrayType=u<16384?Uint16Array:Uint32Array;const f=mt.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,o+8,u*4),this._indices=new this.IndexArrayType(this.data,o+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,($<<4)+f]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=n),this._queue=new xn}add(n,e,i=n,s=e){const r=this._pos>>2,o=this._boxes;return this._indices[r]=r,o[this._pos++]=n,o[this._pos++]=e,o[this._pos++]=i,o[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 o=0,l=0;o<this.numItems;o++){const u=n[l++],f=n[l++],h=n[l++],a=n[l++],p=Math.floor(r*((u+h)/2-this.minX)/e),d=Math.floor(r*((f+a)/2-this.minY)/i);s[o]=bn(p,d)}W(s,n,this._indices,0,this.numItems-1,this.nodeSize);for(let o=0,l=0;o<this._levelBounds.length-1;o++){const u=this._levelBounds[o];for(;l<u;){const f=l;let h=n[l++],a=n[l++],p=n[l++],d=n[l++];for(let m=1;m<this.nodeSize&&l<u;m++)h=Math.min(h,n[l++]),a=Math.min(a,n[l++]),p=Math.max(p,n[l++]),d=Math.max(d,n[l++]);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 o=this._boxes.length-4;const l=[],u=[];for(;o!==void 0;){const f=Math.min(o+this.nodeSize*4,Pt(o,this._levelBounds));for(let h=o;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;o>=this.numItems*4?l.push(a):(r===void 0||r(a))&&u.push(a)}o=l.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 o=this._boxes.length-4;const l=this._queue,u=[],f=s*s;t:for(;o!==void 0;){const h=Math.min(o+this.nodeSize*4,Pt(o,this._levelBounds));for(let a=o;a<h;a+=4){const p=this._indices[a>>2]|0,d=gt(n,this._boxes[a],this._boxes[a+2]),m=gt(e,this._boxes[a+1],this._boxes[a+3]),g=d*d+m*m;g>f||(o>=this.numItems*4?l.push(p<<1,g):(r===void 0||r(p))&&l.push((p<<1)+1,g))}for(;l.length&&l.peek()&1;)if(l.peekValue()>f||(u.push(l.pop()>>1),u.length===i))break t;o=l.length?l.pop()>>1:void 0}return l.clear(),u}}function gt(t,n,e){return t<n?n-t:t<=e?0:t-e}function Pt(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 W(t,n,e,i,s,r){if(Math.floor(i/r)>=Math.floor(s/r))return;const o=t[i+s>>1];let l=i-1,u=s+1;for(;;){do l++;while(t[l]<o);do u--;while(t[u]>o);if(l>=u)break;An(t,n,e,l,u)}W(t,n,e,i,u,r),W(t,n,e,u+1,s,r)}function An(t,n,e,i,s){const r=t[i];t[i]=t[s],t[s]=r;const o=4*i,l=4*s,u=n[o],f=n[o+1],h=n[o+2],a=n[o+3];n[o]=n[l],n[o+1]=n[l+1],n[o+2]=n[l+2],n[o+3]=n[l+3],n[l]=u,n[l+1]=f,n[l+2]=h,n[l+3]=a;const p=e[i];e[i]=e[s],e[s]=p}function bn(t,n){let e=t^n,i=65535^e,s=65535^(t|n),r=t&(n^65535),o=e|i>>1,l=e>>1^e,u=s>>1^i&r>>1^s,f=e&s>>1^r>>1^r;e=o,i=l,s=u,r=f,o=e&e>>2^i&i>>2,l=e&i>>2^i&(e^i)>>2,u^=e&s>>2^i&r>>2,f^=i&s>>2^(e^i)&r>>2,e=o,i=l,s=u,r=f,o=e&e>>4^i&i>>4,l=e&i>>4^i&(e^i)>>4,u^=e&s>>4^i&r>>4,f^=i&s>>4^(e^i)&r>>4,e=o,i=l,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 et(t,n=1e-7){if(t.length===0)return[];if(t.length===1)return[t];const e=new nt(t.length);t.forEach(r=>{const[o,l]=r.firstPoint;e.add(o-n,l-n,o+n,l+n)}),e.finish();const i=[],s=new Set;return t.forEach((r,o)=>{if(s.has(o))return;const l=[r];let u=o;s.add(o);let f=t.length;for(;;){if(f--<0)throw new Error("Infinite loop detected");const h=l[l.length-1].lastPoint,[a,p]=h,d=e.search(a-n,p-n,a+n,p+n),m=x=>Math.abs((u-x)%t.length),g=d.filter(x=>!s.has(x)).map(x=>[t[x],x,m(x)]).sort(([,,x],[,,C])=>m(x)-m(C));if(g.length===0){i.push(l);break}const[P,w]=g[0];l.push(P),s.add(w),u=w}}),i}class S extends c.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 S(this.contour.clone(),this.holes.map(e=>e.clone()))}transform(e){return new S(this.contour.transform(e),this.holes.map(i=>i.transform(e)))}contains(e){return this.contour.contains(e)&&!this.holes.some(i=>i.contains(e))}intersects(e){return this.allLoops.some(i=>e.allLoops.some(s=>i.intersects(s)))}overlappingStrands(e){const i=e instanceof S?e.allLoops:[e],s=this.allLoops.flatMap(r=>i.flatMap(o=>r.overlappingSegments(o)));return et(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 Y([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 Y(n))if(e.contains(i.firstPoint))throw console.error(G(e),G(i)),new Error("Holes must not be inside other holes")}const Sn=t=>{const n=t.map((s,r)=>t.slice(r+1).map((o,l)=>[l+r+1,o]).filter(([,o])=>s.boundingBox.overlaps(o.boundingBox)).map(([o])=>o)),e=[],i=Array(n.length);return n.forEach((s,r)=>{let o=i[r];o||(o=[],e.push(o)),o.push(t[r]),s.length&&s.forEach(l=>{i[l]=o})}),e},zt=t=>t.map((n,e)=>{const s=n.segments[0].midPoint,r=t.filter((o,l)=>e===l?!1:o.contains(s));return{loop:n,isIn:r}}),Cn=(t,n)=>t.flatMap(({loop:e})=>it(n.filter(({loop:i,isIn:s})=>i===e||s.indexOf(e)!==-1))),Mn=(t,n)=>{const e=n.filter(({isIn:s})=>s.length<=1),i=it(zt(t.map(({loop:s})=>s)));return[e,...i]},it=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?Cn(n,t):Mn(e,t)};function q(t){return Sn(t).map(zt).flatMap(it).map(e=>{if(e.length===1)return new S(e[0].loop);e.sort((r,o)=>r.isIn.length-o.isIn.length);const[i,...s]=e.map(({loop:r})=>r);return new S(i,s)})}function Bn(t,n){const e=[];for(const i of t)for(const s of n)e.push([i,s]);return e}function*J(t,n,e){const i=o=>n.some(l=>c.sameVector(l,o.lastPoint)),s=o=>e.some(l=>o.isSame(l));let r=[];for(const o of t)i(o)?(r.push(o),yield new M(r,{ignoreChecks:!0}),r=[]):s(o)?(r.length&&(yield new M(r,{ignoreChecks:!0}),r=[]),yield new M([o],{ignoreChecks:!0})):r.push(o);r.length&&(yield new M(r,{ignoreChecks:!0}))}const wt=(t,n)=>{const e=t.findIndex(r=>c.sameVector(n,r.firstPoint)),i=t.slice(0,e);return t.slice(e).concat(i)},xt=(t,n)=>{let e=t;const i=l=>c.sameVector(l.firstPoint,n.firstPoint)&&c.sameVector(l.lastPoint,n.lastPoint);let s=t.findIndex(i);if(s===-1){const l=t.map(u=>u.reverse());if(l.reverse(),s=l.findIndex(i),s===-1)throw console.error(l.map(u=>u.repr),n.repr),new Error("Failed to rotate to segment start");e=l}const r=e.slice(0,s);return e.slice(s).concat(r)};function In(t,n,e){return t.filter(i=>{const s=n.filter(l=>c.sameVector(l.firstPoint,i)||c.sameVector(l.lastPoint,i));if(s.length%2)throw new Error("Bug in the intersection algo on non crossing point");const r=s.map(l=>e.contains(l.midPoint));return!(r.every(l=>l)||!r.some(l=>l))})}function En(t,n,e){let i=[];const s=[],r=new Array(t.segments.length).fill(0).map(()=>[]),o=new Array(n.segments.length).fill(0).map(()=>[]);if(t.segments.forEach((p,d)=>{n.segments.forEach((m,g)=>{const{intersections:P,overlaps:w}=R(p,m,e);i.push(...P),r[d].push(...P),o[g].push(...P),s.push(...w);const x=w.flatMap(C=>[C.firstPoint,C.lastPoint]);i.push(...x),r[d].push(...x),o[g].push(...x)})}),i=c.removeDuplicatePoints(i,e),!i.length||i.length===1)return null;const l=([p,d])=>d.length?p.splitAt(d):[p];let u=c.zip([t.segments,r]).flatMap(l),f=c.zip([n.segments,o]).flatMap(l);if(i=In(i,u,n),!i.length&&!s.length)return null;if(s.length){const p=s[0];u=xt(u,p),f=xt(f,p)}else{const p=i[0];u=wt(u,p),f=wt(f,p)}let h=Array.from(J(u,i,s)),a=Array.from(J(f,i,s));return(!c.sameVector(a[0].lastPoint,h[0].lastPoint)||s.length>0&&a[0].segmentsCount!==1)&&(a=a.map(p=>p.reverse()).reverse(),c.sameVector(a[0].lastPoint,h[0].lastPoint)||(h=h.map(p=>p.reverse()).reverse())),c.zip([h,a]).map(([p,d])=>p.segmentsCount===1&&s.some(m=>p.segments[0].isSame(m))?[p,"same"]:[p,d])}function At(t){let n=t[0];for(const e of t.slice(1))n=n.extend(e);if(!c.sameVector(n.firstPoint,n.lastPoint))throw console.error(c.reprVector(n.firstPoint),c.reprVector(n.lastPoint)),new Error("Bug in the intersection algo on non closing strand");return new I(n.segments)}function Fn(t,n){const e=c.zip([n.slice(0,-1),n.slice(1)]).map(([s,r])=>At(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(At(i)),e}function vn(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=c.zip([n,e]).flatMap(([s,r],o)=>c.sameVector(s,r)?[]:o);try{return Fn(t,i)}catch{return et(t.flatMap(r=>r.segments)).filter(r=>r.length>1).filter(r=>c.sameVector(r[0].firstPoint,r.at(-1).lastPoint)).map(r=>new I(r))}}const bt=(t,n)=>{if(t.length===0)return[n];const e=t.at(-1);return c.sameVector(e.lastPoint,n.firstPoint)?t.slice(0,-1).concat([e.extend(n)]):c.sameVector(e.lastPoint,n.lastPoint)?t.slice(0,-1).concat([e.extend(n.reverse())]):t.concat([n])},Ln=(t,n)=>t.length===0?[n]:c.sameVector(t[0].firstPoint,n.lastPoint)?[n.extend(t[0])].concat(t.slice(1)):[n].concat(t);function st(t,n,{firstInside:e,secondInside:i}){const s=En(t,n);if(!s){const u=t.segments[0].midPoint,f=n.contains(u),h=n.segments[0].midPoint,a=t.contains(h);return{identical:!1,firstCurveInSecond:f,secondCurveInFirst:a}}if(s.every(([,u])=>u==="same"))return{identical:!0};let r=null,o=null;const l=s.flatMap(([u,f])=>{let h=[],a=0;if(f==="same")return o===1?(o=1,u):o===2||o===0?(o=null,[]):o===null?(r?r=r.extend(u):r=u,[]):(console.error("weird situation"),[]);const p=u.segments[0].midPoint,d=n.contains(p);(e==="keep"&&d||e==="remove"&&!d)&&(a+=1,h=bt(h,u));const m=f.segments[0].midPoint,g=t.contains(m);if(i==="keep"&&g||i==="remove"&&!g){const P=f;a+=1,a===2&&h.length?(h=bt(h,P),r=null):h=[P]}return o===null&&a===1&&r&&(h=Ln(h,r)),a===1&&(o=a,r=null),h.length?h:(r=null,[])});return vn(l)}const zn=(t,n)=>{const e=st(t,n,{firstInside:"remove",secondInside:"remove"});return Array.isArray(e)?e:e.identical?[t]:e.firstCurveInSecond?[n]:e.secondCurveInFirst?[t]:[t,n]},Q=(t,n)=>{const e=st(t,n,{firstInside:"remove",secondInside:"keep"});return Array.isArray(e)?e:e.identical?[]:e.firstCurveInSecond?[]:e.secondCurveInFirst?[t,n]:[t]},rt=(t,n)=>{const e=st(t,n,{firstInside:"keep",secondInside:"keep"});return Array.isArray(e)?e:e.identical?[t]:e.firstCurveInSecond?[t]:e.secondCurveInFirst?[n]:[]};function kn(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((o,l)=>{const u=r.current,f=s+l+1;if(r.fusedWith.has(f))return;let h=[o],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=kt(u[0],h[0]),r.fusedWith.add(f),r.current=d,a||n.set(f,r)})}),e.flatMap(({current:i})=>i)}function kt(t,n){const e=zn(t.contour,n.contour),i=n.holes.flatMap(o=>Q(o,t.contour)),s=t.holes.flatMap(o=>Q(o,n.contour)),r=Bn(t.holes,n.holes).flatMap(([o,l])=>rt(o,l));return q([...e,...i,...s,...r])}function U(t,n){if(t.isFull&&n.isFull)return q(Q(t.contour,n.contour));if(t.isFull){const i=Q(t.contour,n.contour),s=n.holes.flatMap(r=>rt(r,t.contour));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 S(s)),[n]);return q([t.contour,...i.flatMap(s=>s.allLoops)])}else return[t];let e=U(new S(t.contour),n);return t.holes.forEach(i=>{e=e.flatMap(s=>U(s,new S(i)))}),e}function Vn(t,n){const e=rt(t.contour,n.contour);if(!e.length)return[];let i=q(e);return i=V(i,t.holes.map(s=>new S(s))),V(i,n.holes.map(s=>new S(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 kn([...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?kt(t[0],n[0]):[]}function V(t,n){if(!t.length)return[];if(!n.length)return t;if(t.length===1&&n.length===1)return U(t[0],n[0]);if(t.length>1)return t.flatMap(i=>V([i],n));let e=U(t[0],n[0]);return n.slice(1).forEach(i=>{e=V(e,[i])}),e}function j(t,n){return!t.length||!n.length?[]:t.length===1&&n.length===1?Vn(t[0],n[0]):t.length>1?t.flatMap(e=>j([e],n)):n.flatMap(e=>j(t,[e]))}class B extends c.Transformable{constructor(e=[],{ignoreChecks:i=!1}={}){super();b(this,"figures");b(this,"_boundingBox",null);i||_n(e),this.figures=e}get isEmpty(){return this.figures.length===0}get boundingBox(){if(this.isEmpty)return new c.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 B(this.figures.map(e=>e.clone()))}transform(e){return new B(this.figures.map(i=>i.transform(e)))}contains(e){return this.figures.some(i=>i.contains(e))}intersects(e){return this.figures.some(i=>e.figures.some(s=>i.intersects(s)))}overlappingStrands(e){return this.figures.flatMap(i=>e instanceof B?e.figures.flatMap(s=>i.overlappingStrands(s)):i.overlappingStrands(e))}fuse(e){return new B(k(this.figures,e.figures))}cut(e){return new B(V(this.figures,e.figures))}intersect(e){return new B(j(this.figures,e.figures))}}function _n(t){for(const[n,e]of Y(t))if(n.intersects(e))throw new Error("Diagram figures must not intersect")}exports.Diagram=B;exports.Figure=S;exports.Loop=I;exports.Strand=M;exports.arcArcIntersection=K;exports.cutFiguresLists=V;exports.exportJSON=G;exports.findIntersections=un;exports.findIntersectionsAndOverlaps=R;exports.fuseFiguresLists=k;exports.intersectFiguresLists=j;exports.isSegment=Ft;exports.lineArcIntersection=D;exports.projectPointOnLine=yt;exports.stitchSegments=et;exports.strandsBetweenIntersections=J;
4
- //# sourceMappingURL=models-BXU-Gx3U.cjs.map