pantograph2d 0.10.0 → 0.11.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 (35) hide show
  1. package/dist/{QuadraticBezier-DxieHk9z.js → QuadraticBezier-B2g_Iyyl.js} +15 -14
  2. package/dist/{QuadraticBezier-DxieHk9z.js.map → QuadraticBezier-B2g_Iyyl.js.map} +1 -1
  3. package/dist/{QuadraticBezier--UZr_xcV.cjs → QuadraticBezier-CuRsIP_D.cjs} +4 -4
  4. package/dist/{QuadraticBezier--UZr_xcV.cjs.map → QuadraticBezier-CuRsIP_D.cjs.map} +1 -1
  5. package/dist/{draw-BUUNobTS.cjs → draw-9Elv4xz6.cjs} +2 -2
  6. package/dist/{draw-BUUNobTS.cjs.map → draw-9Elv4xz6.cjs.map} +1 -1
  7. package/dist/{draw-lOWnIN1o.js → draw-BJW5kfm9.js} +3 -3
  8. package/dist/{draw-lOWnIN1o.js.map → draw-BJW5kfm9.js.map} +1 -1
  9. package/dist/{models-DCkOI0hV.js → models-DdZq-waE.js} +2 -2
  10. package/dist/{models-DCkOI0hV.js.map → models-DdZq-waE.js.map} +1 -1
  11. package/dist/{models-CCo90hZc.cjs → models-LHGiMarC.cjs} +2 -2
  12. package/dist/{models-CCo90hZc.cjs.map → models-LHGiMarC.cjs.map} +1 -1
  13. package/dist/pantograph/drawShape.cjs +1 -1
  14. package/dist/pantograph/drawShape.cjs.map +1 -1
  15. package/dist/pantograph/drawShape.js +374 -14
  16. package/dist/pantograph/drawShape.js.map +1 -1
  17. package/dist/pantograph/models.cjs +1 -1
  18. package/dist/pantograph/models.js +2 -2
  19. package/dist/pantograph/svg.cjs +1 -1
  20. package/dist/pantograph/svg.js +1 -1
  21. package/dist/pantograph.cjs +2 -2
  22. package/dist/pantograph.cjs.map +1 -1
  23. package/dist/pantograph.js +674 -568
  24. package/dist/pantograph.js.map +1 -1
  25. package/dist/{svg-BY5h3CDD.cjs → svg-BzloQ9l1.cjs} +2 -2
  26. package/dist/{svg-BY5h3CDD.cjs.map → svg-BzloQ9l1.cjs.map} +1 -1
  27. package/dist/{svg-BIphc_zE.js → svg-D8vwkQf7.js} +2 -2
  28. package/dist/{svg-BIphc_zE.js.map → svg-D8vwkQf7.js.map} +1 -1
  29. package/dist/types/src/algorithms/tesselate/tesselateSegment.d.ts +7 -0
  30. package/dist/types/src/api/drawShape.d.ts +3 -0
  31. package/dist/types/src/drawShape/index.d.ts +1 -1
  32. package/dist/types/src/main.d.ts +1 -1
  33. package/dist/types/src/operations.d.ts +1 -0
  34. package/dist/types/src/tesselationOperations.d.ts +15 -0
  35. package/package.json +3 -3
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../models-CCo90hZc.cjs"),r=require("../QuadraticBezier--UZr_xcV.cjs");exports.Diagram=e.Diagram;exports.Figure=e.Figure;exports.Loop=e.Loop;exports.Strand=e.Strand;exports.isSegment=e.isSegment;exports.Arc=r.Arc;exports.BoundingBox=r.BoundingBox;exports.CubicBezier=r.CubicBezier;exports.EllipseArc=r.EllipseArc;exports.Line=r.Line;exports.QuadraticBezier=r.QuadraticBezier;exports.Transformable=r.Transformable;exports.TransformationMatrix=r.TransformationMatrix;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../models-LHGiMarC.cjs"),r=require("../QuadraticBezier-CuRsIP_D.cjs");exports.Diagram=e.Diagram;exports.Figure=e.Figure;exports.Loop=e.Loop;exports.Strand=e.Strand;exports.isSegment=e.isSegment;exports.Arc=r.Arc;exports.BoundingBox=r.BoundingBox;exports.CubicBezier=r.CubicBezier;exports.EllipseArc=r.EllipseArc;exports.Line=r.Line;exports.QuadraticBezier=r.QuadraticBezier;exports.Transformable=r.Transformable;exports.TransformationMatrix=r.TransformationMatrix;
2
2
  //# sourceMappingURL=models.cjs.map
@@ -1,5 +1,5 @@
1
- import { D as s, F as e, L as i, S as o, g as n } from "../models-DCkOI0hV.js";
2
- import { A as m, B as g, C as B, E as c, L as f, Q as p, F as u, T as x } from "../QuadraticBezier-DxieHk9z.js";
1
+ import { D as s, F as e, L as i, S as o, g as n } from "../models-DdZq-waE.js";
2
+ import { A as m, B as g, C as B, E as c, L as f, Q as p, G as u, T as x } from "../QuadraticBezier-B2g_Iyyl.js";
3
3
  export {
4
4
  m as Arc,
5
5
  g as BoundingBox,
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../svg-BY5h3CDD.cjs");exports.svgDiagram=g.svgDiagram;exports.svgFigure=g.svgFigure;exports.svgLoop=g.svgLoop;exports.svgSegmentToPath=g.svgSegmentToPath;exports.svgStrand=g.svgStrand;exports.svgViewbox=g.svgViewbox;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../svg-BzloQ9l1.cjs");exports.svgDiagram=g.svgDiagram;exports.svgFigure=g.svgFigure;exports.svgLoop=g.svgLoop;exports.svgSegmentToPath=g.svgSegmentToPath;exports.svgStrand=g.svgStrand;exports.svgViewbox=g.svgViewbox;
2
2
  //# sourceMappingURL=svg.cjs.map
@@ -1,4 +1,4 @@
1
- import { s as g, a as e, b as o, d as v, c as r, e as t } from "../svg-BIphc_zE.js";
1
+ import { s as g, a as e, b as o, d as v, c as r, e as t } from "../svg-D8vwkQf7.js";
2
2
  export {
3
3
  g as svgDiagram,
4
4
  e as svgFigure,
@@ -1,3 +1,3 @@
1
- "use strict";var pt=Object.defineProperty;var dt=(n,t,e)=>t in n?pt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var P=(n,t,e)=>dt(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./draw-BUUNobTS.cjs"),c=require("./models-CCo90hZc.cjs"),a=require("./QuadraticBezier--UZr_xcV.cjs"),A=require("./svg-BY5h3CDD.cjs");function b(n){if(n instanceof c.Figure)return[n];if(n instanceof c.Loop)return[new c.Figure(n)];if(n instanceof c.Diagram)return n.figures;throw new Error("Unknown shape")}function tt(n,t,e=1e-9){let r=[];const i=[],s=new Array(t.segments.length).fill(0).map(()=>[]);t.segments.forEach((f,l)=>{n.segments.forEach(u=>{const{intersections:h,overlaps:d}=c.findIntersectionsAndOverlaps(f,u,e);r.push(...h),s[l].push(...h),i.push(...d);const p=d.flatMap(m=>[m.firstPoint,m.lastPoint]);r.push(...p),s[l].push(...p)})}),r=a.removeDuplicatePoints(r,e);const o=a.zip([t.segments,s]).flatMap(([f,l])=>l.length?f.splitAt(l):[f]);return Array.from(c.strandsBetweenIntersections(o,r,i))}function _(n,t,e=!1){return tt(t,n).filter(i=>{const s=i.segments[0].midPoint;return t.onStroke(s)?!e:!t.contains(s)})}function $(n,t,e=!1){return tt(t,n).filter(i=>{const s=i.segments[0].midPoint;return t.onStroke(s)?!e:t.contains(s)})}function N(n,t,e=!1){const r=_(n,t.contour,e),i=t.holes.flatMap(s=>$(n,s,e));return[...r,...i]}function K(n,t,e=!1){let r=$(n,t.contour,e);return t.holes.forEach(i=>{r=r.flatMap(s=>_(s,i,e))}),r}function nt(n,t){return new c.Diagram(c.fuseFiguresLists(b(n),b(t)))}function E(n){return n.reduce((t,e)=>nt(t,e),new c.Diagram)}function q(n,t){return new c.Diagram(c.cutFiguresLists(b(n),b(t)))}function mt(n,t){return new c.Diagram(c.intersectFiguresLists(b(n),b(t)))}function Pt(n,t,e=!0){if(t instanceof c.Loop)return _(n,t,e);if(t instanceof c.Figure)return N(n,t,e);let r=[new c.Strand([...n.segments])];return t.figures.forEach(i=>{r=r.flatMap(s=>N(s,i,e))}),r}function wt(n,t,e=!1){if(t instanceof c.Loop)return $(n,t,e);if(t instanceof c.Figure)return K(n,t,e);let r=[new c.Strand([...n.segments])];return t.figures.forEach(i=>{r=r.flatMap(s=>K(s,i,e))}),r}function H(n){return n<0?"before":n>1?"after":"between"}const J=(n,t,e)=>{if(e==="before")return n.distanceFrom(t.firstPoint);if(e==="after")return n.distanceFrom(t.lastPoint);throw new Error("Invalid position")};function Mt(n,t){const e=a.lineLineParams(n,t);if(e==="parallel")return Math.min(n.distanceFrom(t.firstPoint),n.distanceFrom(t.lastPoint));const{intersectionParam1:r,intersectionParam2:i}=e,s=H(r),o=H(i);if(s==="between"&&o==="between")return 0;if(s==="between"&&o!=="between")return J(n,t,o);if(o==="between"&&s!=="between")return J(t,n,s);if(s==="before"&&o==="before")return a.distance(n.firstPoint,t.firstPoint);if(s==="after"&&o==="after")return a.distance(n.lastPoint,t.lastPoint);if(s==="before"&&o==="after")return a.distance(n.firstPoint,t.lastPoint);if(s==="after"&&o==="before")return a.distance(n.lastPoint,t.firstPoint);throw new Error("Invalid position")}function Q(n,t){if(c.lineArcIntersection(n,t).length>0)return 0;const e=c.projectPointOnLine(n,t.center);if(n.isOnSegment(e)){const r=a.distance(e,t.center);if(Math.abs(r-t.radius)<n.precision&&t.isOnSegment(e))return 0;if(r-t.radius>n.precision){const i=a.normalize(a.subtract(e,t.center)),s=a.add(t.center,a.scalarMultiply(i,t.radius));if(t.isOnSegment(s))return a.distance(s,e)}}return Math.min(t.distanceFrom(n.firstPoint),t.distanceFrom(n.lastPoint),n.distanceFrom(t.firstPoint),n.distanceFrom(t.lastPoint))}const St=(n,t)=>{const e=n.angleToParam(t.firstAngle);if(n.isValidParameter(e))return!0;const r=n.angleToParam(t.lastAngle);return!!n.isValidParameter(r)};function Lt(n,t){if(c.arcArcIntersection(n,t,!0).length>0)return 0;const e=a.distance(n.center,t.center);if(e<n.precision&&St(n,t))return Math.abs(n.radius-t.radius);const r=a.normalize(a.subtract(t.center,n.center)),i=e-Math.abs(n.radius-t.radius)<n.precision;let s=a.polarAngle(r);i&&t.radius>n.radius&&(s+=Math.PI);const o=i?s:s+Math.PI,f=n.angleToParam(s),l=t.angleToParam(o);return n.isValidParameter(f)&&t.isValidParameter(l)?a.distance(n.paramPoint(f),t.paramPoint(l)):Math.min(n.distanceFrom(t.firstPoint),n.distanceFrom(t.lastPoint),t.distanceFrom(n.firstPoint),t.distanceFrom(n.lastPoint))}function bt(n,t,e){let r=0,i=n.length-1;for(;r<=i;){const s=Math.floor((r+i)/2),o=e(n[s],t);if(o<0)r=s+1;else if(o>0)i=s-1;else return s}return-(r+1)}function It(n,t,e){const r=bt(n,t,e);r<0?n.splice(-(r+1),0,t):n.splice(r,0,t)}class At{constructor(){P(this,"buckets");this.buckets=[]}addInterval(t){const e=this.buckets[t.rectangle.diagonalBucketIndex];e===void 0?this.buckets[t.rectangle.diagonalBucketIndex]=[t]:It(e,t,(r,i)=>r.value-i.value)}removeInterval(t){const e=this.buckets[t.rectangle.diagonalBucketIndex];if(e===void 0)throw new Error("Interval not found");e.shift()}getBottomRightHullIntervals(){const t=[];for(let e=this.buckets.length-1;e>=0;e--){const r=this.buckets[e];if(!r===void 0)continue;const i=r[0];if(i!==void 0){if(!t.length){t.push(i);continue}for(;t.length&&t[t.length-1].value>=i.value;)t.pop();for(;t.length>=2;){const s=t[t.length-1],o=t[t.length-2],f=(i.value-o.value)/((i.rectangle.diagonal-o.rectangle.diagonal)*2);if(o.value+(s.rectangle.diagonal-o.rectangle.diagonal)/2*f<s.value)t.pop();else break}t.push(i)}}return t}}class Ft{constructor(t,e){P(this,"diagonal");P(this,"diagonalBucketIndex");P(this,"xLength");P(this,"yLength");P(this,"index");this.x=t,this.y=e,this.xLength=Math.pow(3,-t),this.yLength=Math.pow(3,-e),this.diagonal=Math.sqrt(this.xLength*this.xLength+this.yLength*this.yLength),this.diagonalBucketIndex=t+e,this.index=`${t},${e}`}}class vt{constructor(t,e=1e-8,r=1e3,i=1e-6){P(this,"rectangles");P(this,"buckets");P(this,"fMin");P(this,"argMin");P(this,"tol");this.fcn=t,this.endTolerance=e,this.maxIterations=r,this.epsilon=i,this.fcn=t,this.epsilon=i,this.endTolerance=e,this.maxIterations=r,this.rectangles=new Map,this.buckets=new At;const s=[.5,.5],o=this.rect(0,0),f=this.fcn(s);this.buckets.addInterval(new C(s,f,o)),this.fMin=f,this.argMin=s,this.tol=o.diagonal}registerInterval(t){this.buckets.addInterval(t),t.value<=this.fMin&&(this.fMin=t.value,this.argMin=t.center,this.tol=t.rectangle.diagonal)}rect(t,e){const r=`${t},${e}`;return this.rectangles.has(r)||this.rectangles.set(r,new Ft(t,e)),this.rectangles.get(r)}splitInterval(t){let e,r,i;const[s,o]=t.center;return t.rectangle.x<=t.rectangle.y?(e=this.rect(t.rectangle.x+1,t.rectangle.y),r=[s-e.xLength,o],i=[s+e.xLength,o]):(e=this.rect(t.rectangle.x,t.rectangle.y+1),r=[s,o-e.yLength],i=[s,o+e.yLength]),[new C(r,this.fcn(r),e),new C(t.center,t.value,e),new C(i,this.fcn(i),e)]}single_iteration(){const t=this.buckets.getBottomRightHullIntervals();for(;t.length>=2;){const e=t[0],r=t[1],i=(r.value-e.value)/((r.rectangle.diagonal-e.rectangle.diagonal)/2),s=e.value-i*r.value/2;if((this.fMin-s)/Math.abs(this.fMin)<this.epsilon)t.shift();else break}t.forEach(e=>{this.buckets.removeInterval(e)});for(const e of t){const[r,i,s]=this.splitInterval(e);this.registerInterval(r),this.registerInterval(i),this.registerInterval(s)}}run(){let t=0;for(;this.tol>this.endTolerance/2&&(this.single_iteration(),t++,!(t>this.maxIterations)););return{fMin:this.fMin,argMin:this.argMin,tol:this.tol,iterations:t}}}class C{constructor(t,e,r){this.center=t,this.value=e,this.rectangle=r}}function Dt(n,t=1e-8,e=1e3,r=1e-6){return new vt(n,t,e,r).run()}function Et(n,t,e=1e-9){const r=Dt(i=>{const s=n.paramPoint(i[0]),o=t.paramPoint(i[1]);return a.squareDistance(s,o)},e);return Math.sqrt(r.fMin)}function kt(n,t){return n instanceof a.Line&&t instanceof a.Line?Mt(n,t):n instanceof a.Line&&t instanceof a.Arc?Q(n,t):n instanceof a.Arc&&t instanceof a.Line?Q(t,n):n instanceof a.Arc&&t instanceof a.Arc?Lt(n,t):Et(n,t)}function et(n){if(n instanceof a.CubicBezier){const i=a.subtract(n.lastPoint,n.firstPoint),s=a.subtract(n.firstControlPoint,n.firstPoint),o=a.subtract(n.lastControlPoint,n.firstPoint),f=a.angle(i,s),l=a.angle(i,o);if(f>0&&l<0||f<0&&l>0)return!1}const t=a.perpendicular(n.tangentAtFirstPoint),e=a.perpendicular(n.tangentAtLastPoint);let r=a.dotProduct(t,e);return Math.abs(Math.acos(r))<Math.PI/3}function R(n){if(et(n))return[n];const[t,e]=n.splitAtParameters([.5]);return[...R(t),...R(e)]}function X(n){return et(n)?[n]:n.splitAtParameters(n.getParametersOfExtrema()).flatMap(R)}function yt(n){const t=n.deltaAngle,e=Math.ceil(Math.abs(t)/(Math.PI/2)),r=t/e,i=4*Math.tan(r/4)/3,s=n.clockwise?-1:1,o=Array.from({length:e+1},(l,u)=>n.firstAngle+u*r*s);return o.slice(0,-1).map((l,u)=>[l,o[u+1]]).map(([l,u])=>{const h=Math.cos(l),d=Math.sin(l),p=Math.cos(u),m=Math.sin(u),[g,M]=n.center,w=n.minorRadius,S=n.majorRadius,I=new a.TransformationMatrix().rotate(n.tiltAngle,n.center),F=gt=>I.transform(gt),y=F([g+S*h,M+w*d]),O=F([g+S*(h-i*d*s),M+w*(d+i*h*s)]),lt=F([g+S*(p+i*m*s),M+w*(m-i*p*s)]),ht=F([g+S*p,M+w*m]);return new a.CubicBezier(y,ht,O,lt)})}const U=1e-8,rt=n=>n.flatMap(t=>t instanceof a.Line?[t]:t instanceof a.Arc?[t]:t instanceof a.EllipseArc?yt(t).flatMap(e=>X(e)):t instanceof a.QuadraticBezier||t instanceof a.CubicBezier?X(t):[new a.Line(t.firstPoint,t.lastPoint)]);function z(n,t,e=!0){const r=n.map(u=>({offset:L.offsetSegment(u,t),original:u})),i=[];let s=e?null:r.at(-1),o=e?r.at(-1):null;if(i.length===1)return i;const f=u=>{s?u.offset instanceof L.DegenerateSegment?a.sameVector(u.offset.firstPoint,u.offset.lastPoint)||i.push(new a.Line(u.offset.firstPoint,u.offset.lastPoint)):i.push(u.offset):s=u},l=function*(){for(const u of r.slice(0,-1))yield u;if(!s)throw new Error("Bug in the offset algorithm");yield s};for(const u of l()){if(!o){o=u;continue}const h=o.offset.lastPoint,d=u.offset.firstPoint;if(a.sameVector(h,d)){f(o),o=u;continue}let p=[];if(!(o.offset instanceof L.DegenerateSegment)&&!(u.offset instanceof L.DegenerateSegment)){const{intersections:w,overlaps:S}=c.findIntersectionsAndOverlaps(o.offset,u.offset,U/100);p=[...w,...S.flatMap(I=>[I.firstPoint,I.lastPoint])]}if(p.length>0){let w=p[0];if(p.length>1){const F=o==null?void 0:o.original.lastPoint,y=p.map(O=>a.squareDistance(O,F));w=p[y.indexOf(Math.min(...y))]}const S=o.offset.splitAt([w])[0],I=u.offset.splitAt([w]).at(-1);if(!I)throw new Error("Bug in the splitting algo in offset");f({offset:S,original:o.original}),o={offset:I,original:u.original};continue}const m=o.original.lastPoint,g=a.crossProduct(a.subtract(d,m),a.subtract(h,m))>0,M=new a.Arc(h,d,m,g);f(o),i.push(M),o=u}return o&&f(o),i}function it(n){const t=new Map,e=(r,i)=>{const s=t.get(r)||[];t.set(r,[...s,...i])};return n.forEach((r,i)=>{n.slice(i+1).forEach((s,o)=>{const{intersections:f,overlaps:l}=c.findIntersectionsAndOverlaps(r,s,U),u=[...f,...l.flatMap(h=>[h.firstPoint,h.lastPoint])].filter(h=>{const d=a.sameVector(h,r.firstPoint)||a.sameVector(h,r.lastPoint),p=a.sameVector(h,s.firstPoint)||a.sameVector(h,s.lastPoint);return!(d&&p)});u.length&&(e(i,u),e(o+i+1,u))})}),t}function st(n,t){return t.flatMap((e,r)=>{if(!n.has(r))return e;const i=n.get(r);return i?e.splitAt(i):e})}function ot(n,t,e){return n.filter(r=>!t.segments.some(s=>kt(s,r)<Math.abs(e)-U))}function x(n,t){const e=n.clockwise?t:-t,r=rt(n.segments),i=z(r,e);if(i.length<2)return new c.Diagram;const s=it(i);if(!s.size){const h=new c.Loop(i);return new c.Diagram([new c.Figure(h)])}const o=st(s,i),f=ot(o,n,t);if(!f.length)return new c.Diagram;const u=c.stitchSegments(f).filter(h=>h.length>1).filter(h=>a.sameVector(h[0].firstPoint,h.at(-1).lastPoint)).map(h=>new c.Loop(h));return u.length?new c.Diagram(u.map(h=>new c.Figure(h))):new c.Diagram}function Ct(n,t,e="round"){const r=t/2,i=rt(n.segments),s=z(i,r,!1),o=z(i,-r,!1).map(g=>g.reverse());o.reverse();const f=(g,M)=>e==="round"?a.tangentArc(g.lastPoint,M.firstPoint,g.tangentAtLastPoint):new a.Line(g.lastPoint,M.firstPoint),l=[...s,f(s[s.length-1],o[0]),...o,f(o[o.length-1],s[0])],u=it(l);if(!u.size){const g=new c.Loop(l);return new c.Diagram([new c.Figure(g)])}const h=st(u,l),d=ot(h,n,r);if(!d.length)return new c.Diagram;const m=c.stitchSegments(d).filter(g=>g.length>1).filter(g=>a.sameVector(g[0].firstPoint,g.at(-1).lastPoint)).map(g=>new c.Loop(g));return m.length?new c.Diagram(m.map(g=>new c.Figure(g))):new c.Diagram}function xt(n,t){const e=n.map(r=>{const i=E(r.holes.map(s=>x(s,t)));return q(x(r.contour,t),i)});return E(e)}function Ot(n,t){const e=Math.abs(t/2),r=n.map(i=>E(i.allLoops.map(s=>q(x(s,e),x(s,-e)))));return E(r)}function Bt(n,t){return xt(b(n),t)}function Rt(n,t,{endCap:e="round"}={}){return n instanceof c.Strand?Ct(n,t,e):Ot(b(n),t)}class zt{constructor(){P(this,"filters");this.filters=[]}delete(){this.filters=[]}and(t){return t.forEach(e=>e(this)),this}not(t){const e=new this.constructor;t(e);const r=({element:i})=>!e.shouldKeep(i);return this.filters.push(r),this}either(t){const e=t.map(i=>{const s=new this.constructor;return i(s),s}),r=({element:i})=>e.some(s=>s.shouldKeep(i));return this.filters.push(r),this}}const B=2*Math.PI,Y=n=>{const t=n%B,e=t<0?t+B:t;return e<Math.PI?e:e===Math.PI?0:Math.abs(e-B)};class k extends zt{clone(){const t=new k;return t.filters=[...this.filters],t}inList(t){const e=({element:r})=>!!t.find(i=>a.sameVector(i,r.point));return this.filters.push(e),this}atDistance(t,e=[0,0]){function r({element:i}){return Math.abs(a.distance(e,i.point)-t)<1e-9}return this.filters.push(r),this}atPoint(t){function e({element:r}){return a.sameVector(t,r.point)}return this.filters.push(e),this}inBox(t,e){const[r,i]=t,[s,o]=e,f=Math.min(r,s),l=Math.max(r,s),u=Math.min(i,o),h=Math.max(i,o);function d({element:p}){const[m,g]=p.point;return m>=f&&m<=l&&g>=u&&g<=h}return this.filters.push(d),this}ofAngle(t){function e({element:r}){const i=r.firstCurve.tangentAtLastPoint,s=r.secondCurve.tangentAtFirstPoint;return Math.abs(Y(a.angle(i,s))-Y(a.DEG2RAD*t))<1e-9}return this.filters.push(e),this}above(t=0){function e({element:r}){return r.point[1]>t}return this.filters.push(e),this}below(t=0){function e({element:r}){return r.point[1]<t}return this.filters.push(e),this}leftOf(t=0){function e({element:r}){return r.point[0]<t}return this.filters.push(e),this}rightOf(t=0){function e({element:r}){return r.point[0]>t}return this.filters.push(e),this}shouldKeep(t){return this.filters.every(r=>r({element:t}))}asFilterFun(){return this.shouldKeep.bind(this)}}function at(n,t,e,r=()=>!0){const i=[t.segments[0]],s=(f,l)=>{r({firstCurve:f,secondCurve:l,point:f.lastPoint})?i.push(...n(f,l,e)):i.push(f,l)};if(t.segments.slice(1).forEach(f=>{const l=i.pop();if(!l)throw new Error("Bug in the stroke filletting algo");s(l,f)}),!i.at(-1))throw new Error("Bug in the stroke corner algo");if(t instanceof c.Loop){const f=i.pop(),l=i.shift();if(!f||!l)throw new Error("Bug in the filletting algo");return s(f,l),new c.Loop(i,{ignoreChecks:!0})}else return new c.Strand(i,{ignoreChecks:!0})}function v(n,t,e){const r=typeof e=="function"?e(new k):e,i=r&&r.asFilterFun();if(n instanceof c.Loop||n instanceof c.Strand)return at(L.filletSegments,n,t,i);if(n instanceof c.Figure){const s=v(n.contour,t,r),o=n.holes.map(f=>v(f,t,r));return new c.Figure(s,o,{ignoreChecks:!0})}if(n instanceof c.Diagram){const s=n.figures.map(o=>v(o,t,r));return new c.Diagram(s,{ignoreChecks:!0})}throw new Error("invalid shape to fillet")}function D(n,t,e){const r=typeof e=="function"?e(new k):e,i=r&&r.asFilterFun();if(n instanceof c.Loop||n instanceof c.Strand)return at(L.filletSegments,n,t,i);if(n instanceof c.Figure){const s=D(n.contour,t,r),o=n.holes.map(f=>D(f,t,r));return new c.Figure(s,o,{ignoreChecks:!0})}if(n instanceof c.Diagram){const s=n.figures.map(o=>D(o,t,r));return new c.Diagram(s,{ignoreChecks:!0})}throw new Error("invalid shape to chamfer")}class Vt extends k{constructor(t){super(),this.shape=t}fillet(t){return v(this.shape,t,this.clone())}chamfer(t){return D(this.shape,t,this.clone())}}function Gt(n){return new Vt(n)}function V(n){if(n instanceof c.Diagram)return A.svgDiagram(n);if(n instanceof c.Figure)return A.svgFigure(n);if(n instanceof c.Loop)return`<path d="${A.svgLoop(n)}" />`;if(n instanceof c.Strand)return`<path d="${A.svgStrand(n)}" />`;if(c.isSegment(n))return`<path d="${`M ${n.firstPoint.join(" ")}`} ${A.svgSegmentToPath(n)}" />`;throw new Error("Unknown shape type")}const Z=n=>"shape"in n?n.shape:n,W=(n,t)=>{if(!("shape"in n))return t;const{color:e}=n;return e?`<g stroke="${e}">${t}</g>`:t},j=n=>new a.BoundingBox(n.xMin,-n.yMax,n.xMax,-n.yMin);function Tt(n,{margin:t=1,unit:e=null,viewBox:r}={}){if(Array.isArray(n)){const s=n.map(l=>Z(l).mirror()),o=s.map((l,u)=>W(n[u],V(l))).join(`
2
- `),f=s.slice(1).reduce((l,u)=>l.merge(u.boundingBox),s[0].boundingBox);return A.wrapSVG(o,r?j(r):f,t,e)}const i=Z(n).mirror();return A.wrapSVG(W(n,V(i)),r?j(r):i.boundingBox,t,e)}const ct=n=>{if(n.type==="LINE")return new a.Line(n.firstPoint,n.lastPoint);if(n.type==="ARC")return new a.Arc(n.firstPoint,n.lastPoint,n.center,n.clockwise);if(n.type==="ELLIPSE_ARC")return new a.EllipseArc(n.firstPoint,n.lastPoint,n.center,n.majorRadius,n.minorRadius,n.tiltAngle,n.clockwise,{angleUnits:"rad"});if(n.type==="QUADRATIC_BEZIER")return new a.QuadraticBezier(n.firstPoint,n.lastPoint,n.controlPoint);if(n.type==="CUBIC_BEZIER")return new a.CubicBezier(n.firstPoint,n.lastPoint,n.firstControlPoint,n.lastControlPoint);throw new Error("Unknown segment type")},G=n=>{const t=n.segments.map(ct);return new c.Loop(t)},ft=n=>{const t=G(n.contour),e=n.holes.map(G);return new c.Figure(t,e)},_t=n=>{const t=n.figures.map(ft);return new c.Diagram(t)};function $t(n){if(n.type==="DIAGRAM")return _t(n);if(n.type==="FIGURE")return ft(n);if(n.type==="LOOP")return G(n);if(n.type==="LINE"||n.type==="ARC"||n.type==="ELLIPSE_ARC"||n.type==="CUBIC_BEZIER")return ct(n);throw new Error("Unknown shape type")}const T=Math.PI/180,ut=180/Math.PI;function qt(n,t){const e=Math.cos(t*T)*n,r=Math.sin(t*T)*n;return[e,r]}function Ut([n,t]){const e=Math.sqrt(n*n+t*t),r=Math.atan2(t,n)*ut;return[e,r]}exports.DrawingPen=L.DrawingPen;exports.draw=L.draw;exports.exportJSON=c.exportJSON;exports.DEG2RAD=T;exports.RAD2DEG=ut;exports.cartesianToPolar=Ut;exports.chamfer=D;exports.confineStrand=wt;exports.cut=q;exports.eraseStrand=Pt;exports.exportSVG=Tt;exports.fillet=v;exports.fuse=nt;exports.fuseAll=E;exports.importJSON=$t;exports.intersect=mt;exports.offset=Bt;exports.outlineStroke=Rt;exports.polarToCartesian=qt;exports.selectCorners=Gt;exports.svgBody=V;
1
+ "use strict";var bt=Object.defineProperty;var It=(t,n,e)=>n in t?bt(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var w=(t,n,e)=>It(t,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./draw-9Elv4xz6.cjs"),c=require("./models-LHGiMarC.cjs"),a=require("./QuadraticBezier-CuRsIP_D.cjs"),D=require("./svg-BzloQ9l1.cjs");function I(t){if(t instanceof c.Figure)return[t];if(t instanceof c.Loop)return[new c.Figure(t)];if(t instanceof c.Diagram)return t.figures;throw new Error("Unknown shape")}function ct(t,n,e=1e-9){let r=[];const i=[],s=new Array(n.segments.length).fill(0).map(()=>[]);n.segments.forEach((f,l)=>{t.segments.forEach(u=>{const{intersections:h,overlaps:p}=c.findIntersectionsAndOverlaps(f,u,e);r.push(...h),s[l].push(...h),i.push(...p);const d=p.flatMap(m=>[m.firstPoint,m.lastPoint]);r.push(...d),s[l].push(...d)})}),r=a.removeDuplicatePoints(r,e);const o=a.zip([n.segments,s]).flatMap(([f,l])=>l.length?f.splitAt(l):[f]);return Array.from(c.strandsBetweenIntersections(o,r,i))}function H(t,n,e=!1){return ct(n,t).filter(i=>{const s=i.segments[0].midPoint;return n.onStroke(s)?!e:!n.contains(s)})}function K(t,n,e=!1){return ct(n,t).filter(i=>{const s=i.segments[0].midPoint;return n.onStroke(s)?!e:n.contains(s)})}function Z(t,n,e=!1){const r=H(t,n.contour,e),i=n.holes.flatMap(s=>K(t,s,e));return[...r,...i]}function W(t,n,e=!1){let r=K(t,n.contour,e);return n.holes.forEach(i=>{r=r.flatMap(s=>H(s,i,e))}),r}function at(t,n){return new c.Diagram(c.fuseFiguresLists(I(t),I(n)))}function E(t){return t.reduce((n,e)=>at(n,e),new c.Diagram)}function J(t,n){return new c.Diagram(c.cutFiguresLists(I(t),I(n)))}function Dt(t,n){return new c.Diagram(c.intersectFiguresLists(I(t),I(n)))}function vt(t,n,e=!0){if(n instanceof c.Loop)return H(t,n,e);if(n instanceof c.Figure)return Z(t,n,e);let r=[new c.Strand([...t.segments])];return n.figures.forEach(i=>{r=r.flatMap(s=>Z(s,i,e))}),r}function Ft(t,n,e=!1){if(n instanceof c.Loop)return K(t,n,e);if(n instanceof c.Figure)return W(t,n,e);let r=[new c.Strand([...t.segments])];return n.figures.forEach(i=>{r=r.flatMap(s=>W(s,i,e))}),r}function j(t){return t<0?"before":t>1?"after":"between"}const tt=(t,n,e)=>{if(e==="before")return t.distanceFrom(n.firstPoint);if(e==="after")return t.distanceFrom(n.lastPoint);throw new Error("Invalid position")};function Et(t,n){const e=a.lineLineParams(t,n);if(e==="parallel")return Math.min(t.distanceFrom(n.firstPoint),t.distanceFrom(n.lastPoint));const{intersectionParam1:r,intersectionParam2:i}=e,s=j(r),o=j(i);if(s==="between"&&o==="between")return 0;if(s==="between"&&o!=="between")return tt(t,n,o);if(o==="between"&&s!=="between")return tt(n,t,s);if(s==="before"&&o==="before")return a.distance(t.firstPoint,n.firstPoint);if(s==="after"&&o==="after")return a.distance(t.lastPoint,n.lastPoint);if(s==="before"&&o==="after")return a.distance(t.firstPoint,n.lastPoint);if(s==="after"&&o==="before")return a.distance(t.lastPoint,n.firstPoint);throw new Error("Invalid position")}function nt(t,n){if(c.lineArcIntersection(t,n).length>0)return 0;const e=c.projectPointOnLine(t,n.center);if(t.isOnSegment(e)){const r=a.distance(e,n.center);if(Math.abs(r-n.radius)<t.precision&&n.isOnSegment(e))return 0;if(r-n.radius>t.precision){const i=a.normalize(a.subtract(e,n.center)),s=a.add(n.center,a.scalarMultiply(i,n.radius));if(n.isOnSegment(s))return a.distance(s,e)}}return Math.min(n.distanceFrom(t.firstPoint),n.distanceFrom(t.lastPoint),t.distanceFrom(n.firstPoint),t.distanceFrom(n.lastPoint))}const kt=(t,n)=>{const e=t.angleToParam(n.firstAngle);if(t.isValidParameter(e))return!0;const r=t.angleToParam(n.lastAngle);return!!t.isValidParameter(r)};function Ct(t,n){if(c.arcArcIntersection(t,n,!0).length>0)return 0;const e=a.distance(t.center,n.center);if(e<t.precision&&kt(t,n))return Math.abs(t.radius-n.radius);const r=a.normalize(a.subtract(n.center,t.center)),i=e-Math.abs(t.radius-n.radius)<t.precision;let s=a.polarAngle(r);i&&n.radius>t.radius&&(s+=Math.PI);const o=i?s:s+Math.PI,f=t.angleToParam(s),l=n.angleToParam(o);return t.isValidParameter(f)&&n.isValidParameter(l)?a.distance(t.paramPoint(f),n.paramPoint(l)):Math.min(t.distanceFrom(n.firstPoint),t.distanceFrom(n.lastPoint),n.distanceFrom(t.firstPoint),n.distanceFrom(t.lastPoint))}function yt(t,n,e){let r=0,i=t.length-1;for(;r<=i;){const s=Math.floor((r+i)/2),o=e(t[s],n);if(o<0)r=s+1;else if(o>0)i=s-1;else return s}return-(r+1)}function xt(t,n,e){const r=yt(t,n,e);r<0?t.splice(-(r+1),0,n):t.splice(r,0,n)}class Ot{constructor(){w(this,"buckets");this.buckets=[]}addInterval(n){const e=this.buckets[n.rectangle.diagonalBucketIndex];e===void 0?this.buckets[n.rectangle.diagonalBucketIndex]=[n]:xt(e,n,(r,i)=>r.value-i.value)}removeInterval(n){const e=this.buckets[n.rectangle.diagonalBucketIndex];if(e===void 0)throw new Error("Interval not found");e.shift()}getBottomRightHullIntervals(){const n=[];for(let e=this.buckets.length-1;e>=0;e--){const r=this.buckets[e];if(!r===void 0)continue;const i=r[0];if(i!==void 0){if(!n.length){n.push(i);continue}for(;n.length&&n[n.length-1].value>=i.value;)n.pop();for(;n.length>=2;){const s=n[n.length-1],o=n[n.length-2],f=(i.value-o.value)/((i.rectangle.diagonal-o.rectangle.diagonal)*2);if(o.value+(s.rectangle.diagonal-o.rectangle.diagonal)/2*f<s.value)n.pop();else break}n.push(i)}}return n}}class Bt{constructor(n,e){w(this,"diagonal");w(this,"diagonalBucketIndex");w(this,"xLength");w(this,"yLength");w(this,"index");this.x=n,this.y=e,this.xLength=Math.pow(3,-n),this.yLength=Math.pow(3,-e),this.diagonal=Math.sqrt(this.xLength*this.xLength+this.yLength*this.yLength),this.diagonalBucketIndex=n+e,this.index=`${n},${e}`}}class Rt{constructor(n,e=1e-8,r=1e3,i=1e-6){w(this,"rectangles");w(this,"buckets");w(this,"fMin");w(this,"argMin");w(this,"tol");this.fcn=n,this.endTolerance=e,this.maxIterations=r,this.epsilon=i,this.fcn=n,this.epsilon=i,this.endTolerance=e,this.maxIterations=r,this.rectangles=new Map,this.buckets=new Ot;const s=[.5,.5],o=this.rect(0,0),f=this.fcn(s);this.buckets.addInterval(new y(s,f,o)),this.fMin=f,this.argMin=s,this.tol=o.diagonal}registerInterval(n){this.buckets.addInterval(n),n.value<=this.fMin&&(this.fMin=n.value,this.argMin=n.center,this.tol=n.rectangle.diagonal)}rect(n,e){const r=`${n},${e}`;return this.rectangles.has(r)||this.rectangles.set(r,new Bt(n,e)),this.rectangles.get(r)}splitInterval(n){let e,r,i;const[s,o]=n.center;return n.rectangle.x<=n.rectangle.y?(e=this.rect(n.rectangle.x+1,n.rectangle.y),r=[s-e.xLength,o],i=[s+e.xLength,o]):(e=this.rect(n.rectangle.x,n.rectangle.y+1),r=[s,o-e.yLength],i=[s,o+e.yLength]),[new y(r,this.fcn(r),e),new y(n.center,n.value,e),new y(i,this.fcn(i),e)]}single_iteration(){const n=this.buckets.getBottomRightHullIntervals();for(;n.length>=2;){const e=n[0],r=n[1],i=(r.value-e.value)/((r.rectangle.diagonal-e.rectangle.diagonal)/2),s=e.value-i*r.value/2;if((this.fMin-s)/Math.abs(this.fMin)<this.epsilon)n.shift();else break}n.forEach(e=>{this.buckets.removeInterval(e)});for(const e of n){const[r,i,s]=this.splitInterval(e);this.registerInterval(r),this.registerInterval(i),this.registerInterval(s)}}run(){let n=0;for(;this.tol>this.endTolerance/2&&(this.single_iteration(),n++,!(n>this.maxIterations)););return{fMin:this.fMin,argMin:this.argMin,tol:this.tol,iterations:n}}}class y{constructor(n,e,r){this.center=n,this.value=e,this.rectangle=r}}function Tt(t,n=1e-8,e=1e3,r=1e-6){return new Rt(t,n,e,r).run()}function zt(t,n,e=1e-9){const r=Tt(i=>{const s=t.paramPoint(i[0]),o=n.paramPoint(i[1]);return a.squareDistance(s,o)},e);return Math.sqrt(r.fMin)}function Vt(t,n){return t instanceof a.Line&&n instanceof a.Line?Et(t,n):t instanceof a.Line&&n instanceof a.Arc?nt(t,n):t instanceof a.Arc&&n instanceof a.Line?nt(n,t):t instanceof a.Arc&&n instanceof a.Arc?Ct(t,n):zt(t,n)}function ft(t){if(t instanceof a.CubicBezier){const i=a.subtract(t.lastPoint,t.firstPoint),s=a.subtract(t.firstControlPoint,t.firstPoint),o=a.subtract(t.lastControlPoint,t.firstPoint),f=a.angle(i,s),l=a.angle(i,o);if(f>0&&l<0||f<0&&l>0)return!1}const n=a.perpendicular(t.tangentAtFirstPoint),e=a.perpendicular(t.tangentAtLastPoint);let r=a.dotProduct(n,e);return Math.abs(Math.acos(r))<Math.PI/3}function V(t){if(ft(t))return[t];const[n,e]=t.splitAtParameters([.5]);return[...V(n),...V(e)]}function et(t){return ft(t)?[t]:t.splitAtParameters(t.getParametersOfExtrema()).flatMap(V)}function Gt(t){const n=t.deltaAngle,e=Math.ceil(Math.abs(n)/(Math.PI/2)),r=n/e,i=4*Math.tan(r/4)/3,s=t.clockwise?-1:1,o=Array.from({length:e+1},(l,u)=>t.firstAngle+u*r*s);return o.slice(0,-1).map((l,u)=>[l,o[u+1]]).map(([l,u])=>{const h=Math.cos(l),p=Math.sin(l),d=Math.cos(u),m=Math.sin(u),[g,S]=t.center,P=t.minorRadius,M=t.majorRadius,L=new a.TransformationMatrix().rotate(t.tiltAngle,t.center),A=At=>L.transform(At),C=A([g+M*h,S+P*p]),B=A([g+M*(h-i*p*s),S+P*(p+i*h*s)]),Mt=A([g+M*(d+i*m*s),S+P*(m-i*d*s)]),Lt=A([g+M*d,S+P*m]);return new a.CubicBezier(C,Lt,B,Mt)})}const X=1e-8,ut=t=>t.flatMap(n=>n instanceof a.Line?[n]:n instanceof a.Arc?[n]:n instanceof a.EllipseArc?Gt(n).flatMap(e=>et(e)):n instanceof a.QuadraticBezier||n instanceof a.CubicBezier?et(n):[new a.Line(n.firstPoint,n.lastPoint)]);function G(t,n,e=!0){const r=t.map(u=>({offset:b.offsetSegment(u,n),original:u})),i=[];let s=e?null:r.at(-1),o=e?r.at(-1):null;if(i.length===1)return i;const f=u=>{s?u.offset instanceof b.DegenerateSegment?a.sameVector(u.offset.firstPoint,u.offset.lastPoint)||i.push(new a.Line(u.offset.firstPoint,u.offset.lastPoint)):i.push(u.offset):s=u},l=function*(){for(const u of r.slice(0,-1))yield u;if(!s)throw new Error("Bug in the offset algorithm");yield s};for(const u of l()){if(!o){o=u;continue}const h=o.offset.lastPoint,p=u.offset.firstPoint;if(a.sameVector(h,p)){f(o),o=u;continue}let d=[];if(!(o.offset instanceof b.DegenerateSegment)&&!(u.offset instanceof b.DegenerateSegment)){const{intersections:P,overlaps:M}=c.findIntersectionsAndOverlaps(o.offset,u.offset,X/100);d=[...P,...M.flatMap(L=>[L.firstPoint,L.lastPoint])]}if(d.length>0){let P=d[0];if(d.length>1){const A=o==null?void 0:o.original.lastPoint,C=d.map(B=>a.squareDistance(B,A));P=d[C.indexOf(Math.min(...C))]}const M=o.offset.splitAt([P])[0],L=u.offset.splitAt([P]).at(-1);if(!L)throw new Error("Bug in the splitting algo in offset");f({offset:M,original:o.original}),o={offset:L,original:u.original};continue}const m=o.original.lastPoint,g=a.crossProduct(a.subtract(p,m),a.subtract(h,m))>0,S=new a.Arc(h,p,m,g);f(o),i.push(S),o=u}return o&&f(o),i}function lt(t){const n=new Map,e=(r,i)=>{const s=n.get(r)||[];n.set(r,[...s,...i])};return t.forEach((r,i)=>{t.slice(i+1).forEach((s,o)=>{const{intersections:f,overlaps:l}=c.findIntersectionsAndOverlaps(r,s,X),u=[...f,...l.flatMap(h=>[h.firstPoint,h.lastPoint])].filter(h=>{const p=a.sameVector(h,r.firstPoint)||a.sameVector(h,r.lastPoint),d=a.sameVector(h,s.firstPoint)||a.sameVector(h,s.lastPoint);return!(p&&d)});u.length&&(e(i,u),e(o+i+1,u))})}),n}function ht(t,n){return n.flatMap((e,r)=>{if(!t.has(r))return e;const i=t.get(r);return i?e.splitAt(i):e})}function gt(t,n,e){return t.filter(r=>!n.segments.some(s=>Vt(s,r)<Math.abs(e)-X))}function O(t,n){const e=t.clockwise?n:-n,r=ut(t.segments),i=G(r,e);if(i.length<2)return new c.Diagram;const s=lt(i);if(!s.size){const h=new c.Loop(i);return new c.Diagram([new c.Figure(h)])}const o=ht(s,i),f=gt(o,t,n);if(!f.length)return new c.Diagram;const u=c.stitchSegments(f).filter(h=>h.length>1).filter(h=>a.sameVector(h[0].firstPoint,h.at(-1).lastPoint)).map(h=>new c.Loop(h));return u.length?new c.Diagram(u.map(h=>new c.Figure(h))):new c.Diagram}function _t(t,n,e="round"){const r=n/2,i=ut(t.segments),s=G(i,r,!1),o=G(i,-r,!1).map(g=>g.reverse());o.reverse();const f=(g,S)=>e==="round"?a.tangentArc(g.lastPoint,S.firstPoint,g.tangentAtLastPoint):new a.Line(g.lastPoint,S.firstPoint),l=[...s,f(s[s.length-1],o[0]),...o,f(o[o.length-1],s[0])],u=lt(l);if(!u.size){const g=new c.Loop(l);return new c.Diagram([new c.Figure(g)])}const h=ht(u,l),p=gt(h,t,r);if(!p.length)return new c.Diagram;const m=c.stitchSegments(p).filter(g=>g.length>1).filter(g=>a.sameVector(g[0].firstPoint,g.at(-1).lastPoint)).map(g=>new c.Loop(g));return m.length?new c.Diagram(m.map(g=>new c.Figure(g))):new c.Diagram}function Ut(t,n){const e=t.map(r=>{const i=E(r.holes.map(s=>O(s,n)));return J(O(r.contour,n),i)});return E(e)}function $t(t,n){const e=Math.abs(n/2),r=t.map(i=>E(i.allLoops.map(s=>J(O(s,e),O(s,-e)))));return E(r)}function qt(t,n){return Ut(I(t),n)}function Nt(t,n,{endCap:e="round"}={}){return t instanceof c.Strand?_t(t,n,e):$t(I(t),n)}class Ht{constructor(){w(this,"filters");this.filters=[]}delete(){this.filters=[]}and(n){return n.forEach(e=>e(this)),this}not(n){const e=new this.constructor;n(e);const r=({element:i})=>!e.shouldKeep(i);return this.filters.push(r),this}either(n){const e=n.map(i=>{const s=new this.constructor;return i(s),s}),r=({element:i})=>e.some(s=>s.shouldKeep(i));return this.filters.push(r),this}}const R=2*Math.PI,rt=t=>{const n=t%R,e=n<0?n+R:n;return e<Math.PI?e:e===Math.PI?0:Math.abs(e-R)};class k extends Ht{clone(){const n=new k;return n.filters=[...this.filters],n}inList(n){const e=({element:r})=>!!n.find(i=>a.sameVector(i,r.point));return this.filters.push(e),this}atDistance(n,e=[0,0]){function r({element:i}){return Math.abs(a.distance(e,i.point)-n)<1e-9}return this.filters.push(r),this}atPoint(n){function e({element:r}){return a.sameVector(n,r.point)}return this.filters.push(e),this}inBox(n,e){const[r,i]=n,[s,o]=e,f=Math.min(r,s),l=Math.max(r,s),u=Math.min(i,o),h=Math.max(i,o);function p({element:d}){const[m,g]=d.point;return m>=f&&m<=l&&g>=u&&g<=h}return this.filters.push(p),this}ofAngle(n){function e({element:r}){const i=r.firstCurve.tangentAtLastPoint,s=r.secondCurve.tangentAtFirstPoint;return Math.abs(rt(a.angle(i,s))-rt(a.DEG2RAD*n))<1e-9}return this.filters.push(e),this}above(n=0){function e({element:r}){return r.point[1]>n}return this.filters.push(e),this}below(n=0){function e({element:r}){return r.point[1]<n}return this.filters.push(e),this}leftOf(n=0){function e({element:r}){return r.point[0]<n}return this.filters.push(e),this}rightOf(n=0){function e({element:r}){return r.point[0]>n}return this.filters.push(e),this}shouldKeep(n){return this.filters.every(r=>r({element:n}))}asFilterFun(){return this.shouldKeep.bind(this)}}function pt(t,n,e,r=()=>!0){const i=[n.segments[0]],s=(f,l)=>{r({firstCurve:f,secondCurve:l,point:f.lastPoint})?i.push(...t(f,l,e)):i.push(f,l)};if(n.segments.slice(1).forEach(f=>{const l=i.pop();if(!l)throw new Error("Bug in the stroke filletting algo");s(l,f)}),!i.at(-1))throw new Error("Bug in the stroke corner algo");if(n instanceof c.Loop){const f=i.pop(),l=i.shift();if(!f||!l)throw new Error("Bug in the filletting algo");return s(f,l),new c.Loop(i,{ignoreChecks:!0})}else return new c.Strand(i,{ignoreChecks:!0})}function v(t,n,e){const r=typeof e=="function"?e(new k):e,i=r&&r.asFilterFun();if(t instanceof c.Loop||t instanceof c.Strand)return pt(b.filletSegments,t,n,i);if(t instanceof c.Figure){const s=v(t.contour,n,r),o=t.holes.map(f=>v(f,n,r));return new c.Figure(s,o,{ignoreChecks:!0})}if(t instanceof c.Diagram){const s=t.figures.map(o=>v(o,n,r));return new c.Diagram(s,{ignoreChecks:!0})}throw new Error("invalid shape to fillet")}function F(t,n,e){const r=typeof e=="function"?e(new k):e,i=r&&r.asFilterFun();if(t instanceof c.Loop||t instanceof c.Strand)return pt(b.filletSegments,t,n,i);if(t instanceof c.Figure){const s=F(t.contour,n,r),o=t.holes.map(f=>F(f,n,r));return new c.Figure(s,o,{ignoreChecks:!0})}if(t instanceof c.Diagram){const s=t.figures.map(o=>F(o,n,r));return new c.Diagram(s,{ignoreChecks:!0})}throw new Error("invalid shape to chamfer")}class Kt extends k{constructor(n){super(),this.shape=n}fillet(n){return v(this.shape,n,this.clone())}chamfer(n){return F(this.shape,n,this.clone())}}function Jt(t){return new Kt(t)}const Xt=1*a.DEG2RAD,Qt=24;function T(t,n,e,r){const i=t.gradientAt(n);return a.length(i)<=r?e:a.normalize(i)}function _(t,n,e,r,i,s){const o=t.paramPoint(n),f=t.paramPoint(e),l=a.subtract(f,o),u=a.length(l);if(u<=t.precision||s>=r.maxDepth)return[o,f];const h=[l[0]/u,l[1]/u],p=(n+e)*.5,d=T(t,n,h,t.precision),m=T(t,p,h,t.precision),g=T(t,e,h,t.precision),S=a.dotProduct(d,m),P=a.dotProduct(m,g);if(S>=i&&P>=i)return[o,f];const M=t.paramPoint(p),L=S>=i?[o,M]:_(t,n,p,r,i,s+1),A=P>=i?[M,f]:_(t,p,e,r,i,s+1);return[...L.slice(0,-1),...A]}function Q(t,n={}){const e={maxAngle:n.maxAngle??Xt,maxDepth:n.maxDepth??Qt},r=Math.cos(e.maxAngle);return _(t,0,1,e,r,0)}function Yt(t,n){return new c.Diagram(t.figures.map(e=>dt(e,n)))}function dt(t,n){return new c.Figure(U(t.contour,n),t.holes.map(e=>U(e,n)))}function U(t,n){return new c.Loop(Y(t.segments,n))}function Zt(t,n){return new c.Strand(Y(t.segments,n))}function Y(t,n){return t.flatMap(n)}function Wt(t,n){if(t instanceof c.Diagram)return Yt(t,n);if(t instanceof c.Figure)return dt(t,n);if(t instanceof c.Loop)return U(t,n);if(t instanceof c.Strand)return Zt(t,n);if(c.isSegment(t))return Y([t],n);throw new Error("Unsupported shape type")}function jt(t){if(t.length<2)return[];const n=[];for(let e=0;e<t.length-1;e+=1)n.push(new a.Line(t[e],t[e+1]));return n}function tn(t,n){return jt(Q(t,n))}function x(t,n){const e=[];return t.forEach((r,i)=>{const s=Q(r,n);if(s.length!==0){if(i===0){e.push(...s);return}e.push(...s.slice(1))}}),e.length>1&&a.sameVector(e[0],e[e.length-1])&&e.pop(),e}function nn(t){return t.length<3?!1:t.map((e,r)=>{const i=t[(r+1)%t.length];return(i[0]-e[0])*(i[1]+e[1])}).reduce((e,r)=>e+r,0)>0}function z(t,n){return t.length<3||nn(t)===n?t:[...t].reverse()}function en(t,n={}){return Wt(t,r=>tn(r,n))}function mt(t,n={}){if(t instanceof c.Diagram)return t.figures.map(e=>mt(e,n));if(t instanceof c.Figure){const e=z(x(t.contour.segments,n),!1),r=t.holes.map(i=>z(x(i.segments,n),!0));return[e,...r]}return t instanceof c.Loop?z(x(t.segments,n),!1):t instanceof c.Strand?x(t.segments,n):Q(t,n)}function $(t){if(t instanceof c.Diagram)return D.svgDiagram(t);if(t instanceof c.Figure)return D.svgFigure(t);if(t instanceof c.Loop)return`<path d="${D.svgLoop(t)}" />`;if(t instanceof c.Strand)return`<path d="${D.svgStrand(t)}" />`;if(c.isSegment(t))return`<path d="${`M ${t.firstPoint.join(" ")}`} ${D.svgSegmentToPath(t)}" />`;throw new Error("Unknown shape type")}const it=t=>"shape"in t?t.shape:t,st=(t,n)=>{if(!("shape"in t))return n;const{color:e}=t;return e?`<g stroke="${e}">${n}</g>`:n},ot=t=>new a.BoundingBox(t.xMin,-t.yMax,t.xMax,-t.yMin);function rn(t,{margin:n=1,unit:e=null,viewBox:r}={}){if(Array.isArray(t)){const s=t.map(l=>it(l).mirror()),o=s.map((l,u)=>st(t[u],$(l))).join(`
2
+ `),f=s.slice(1).reduce((l,u)=>l.merge(u.boundingBox),s[0].boundingBox);return D.wrapSVG(o,r?ot(r):f,n,e)}const i=it(t).mirror();return D.wrapSVG(st(t,$(i)),r?ot(r):i.boundingBox,n,e)}const Pt=t=>{if(t.type==="LINE")return new a.Line(t.firstPoint,t.lastPoint);if(t.type==="ARC")return new a.Arc(t.firstPoint,t.lastPoint,t.center,t.clockwise);if(t.type==="ELLIPSE_ARC")return new a.EllipseArc(t.firstPoint,t.lastPoint,t.center,t.majorRadius,t.minorRadius,t.tiltAngle,t.clockwise,{angleUnits:"rad"});if(t.type==="QUADRATIC_BEZIER")return new a.QuadraticBezier(t.firstPoint,t.lastPoint,t.controlPoint);if(t.type==="CUBIC_BEZIER")return new a.CubicBezier(t.firstPoint,t.lastPoint,t.firstControlPoint,t.lastControlPoint);throw new Error("Unknown segment type")},q=t=>{const n=t.segments.map(Pt);return new c.Loop(n)},wt=t=>{const n=q(t.contour),e=t.holes.map(q);return new c.Figure(n,e)},sn=t=>{const n=t.figures.map(wt);return new c.Diagram(n)};function on(t){if(t.type==="DIAGRAM")return sn(t);if(t.type==="FIGURE")return wt(t);if(t.type==="LOOP")return q(t);if(t.type==="LINE"||t.type==="ARC"||t.type==="ELLIPSE_ARC"||t.type==="CUBIC_BEZIER")return Pt(t);throw new Error("Unknown shape type")}const N=Math.PI/180,St=180/Math.PI;function cn(t,n){const e=Math.cos(n*N)*t,r=Math.sin(n*N)*t;return[e,r]}function an([t,n]){const e=Math.sqrt(t*t+n*n),r=Math.atan2(n,t)*St;return[e,r]}exports.DrawingPen=b.DrawingPen;exports.draw=b.draw;exports.exportJSON=c.exportJSON;exports.DEG2RAD=N;exports.RAD2DEG=St;exports.cartesianToPolar=an;exports.chamfer=F;exports.confineStrand=Ft;exports.cut=J;exports.eraseStrand=vt;exports.exportSVG=rn;exports.fillet=v;exports.fuse=at;exports.fuseAll=E;exports.importJSON=on;exports.intersect=Dt;exports.offset=qt;exports.outlineStroke=Nt;exports.polarToCartesian=cn;exports.selectCorners=Jt;exports.svgBody=$;exports.tesselate=en;exports.tesselatePoints=mt;
3
3
  //# sourceMappingURL=pantograph.cjs.map