pantograph2d 0.7.0 → 0.8.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.
- package/dist/Diagram-2450b2e6.js +1750 -0
- package/dist/Diagram-2450b2e6.js.map +1 -0
- package/dist/Diagram-57e17509.cjs +4 -0
- package/dist/Diagram-57e17509.cjs.map +1 -0
- package/dist/QuadraticBezier-e116a2d6.js +3647 -0
- package/dist/QuadraticBezier-e116a2d6.js.map +1 -0
- package/dist/QuadraticBezier-e3d7218b.cjs +9 -0
- package/dist/QuadraticBezier-e3d7218b.cjs.map +1 -0
- package/dist/api/svg.d.ts +1 -0
- package/dist/draw-27ac6dae.cjs +2 -0
- package/dist/draw-27ac6dae.cjs.map +1 -0
- package/dist/{draw-825692f1.js → draw-c7b2705c.js} +117 -109
- package/dist/draw-c7b2705c.js.map +1 -0
- package/dist/export/svg/api.d.ts +6 -0
- package/dist/{types/export → export}/svg/wrapSVG.d.ts +1 -1
- package/dist/{types/models → models}/exports.d.ts +2 -0
- package/dist/pantograph/drawShape.cjs +1 -1
- package/dist/pantograph/drawShape.cjs.map +1 -1
- package/dist/pantograph/drawShape.js +12 -11
- package/dist/pantograph/drawShape.js.map +1 -1
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +15 -12
- package/dist/pantograph/models.js.map +1 -1
- package/dist/pantograph/svg.cjs +2 -0
- package/dist/pantograph/svg.cjs.map +1 -0
- package/dist/pantograph/svg.js +11 -0
- package/dist/pantograph/svg.js.map +1 -0
- package/dist/pantograph.cjs +2 -8
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.js +405 -440
- package/dist/pantograph.js.map +1 -1
- package/dist/wrapSVG-02b823ac.cjs +8 -0
- package/dist/wrapSVG-02b823ac.cjs.map +1 -0
- package/dist/wrapSVG-0ec8a111.js +62 -0
- package/dist/wrapSVG-0ec8a111.js.map +1 -0
- package/package.json +31 -23
- package/dist/Diagram-8c3c5e1b.js +0 -5301
- package/dist/Diagram-8c3c5e1b.js.map +0 -1
- package/dist/Diagram-d8288579.cjs +0 -11
- package/dist/Diagram-d8288579.cjs.map +0 -1
- package/dist/draw-3ee546c3.cjs +0 -2
- package/dist/draw-3ee546c3.cjs.map +0 -1
- package/dist/draw-825692f1.js.map +0 -1
- /package/dist/{types/algorithms → algorithms}/boolean/figureBooleans.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/boolean/loopBooleans.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/boolean/strandBoolean.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/boolean/strandsBetweenIntersections.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/distances/arcArcDistance.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/distances/genericDistance.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/distances/index.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/distances/lineArcDistance.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/distances/lineLineDistance.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/filletSegments.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/arcArcIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/arcEllipseArcIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/arcsCubicBezierIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/arcsQuadraticBezierIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/bezierClip.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/cubicBezierCubicBezierIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/ellipseArcEllipseArcIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/ellipseEllipseIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/index.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/lineArcIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/lineBezierIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/lineEllipseArcIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/lineLineIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/quadraticBezierQuadraticBezierIntersection.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/intersections/rayIntersections.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/offsets/offsetFigure.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/offsets/offsetSegment.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/offsets/offsetStroke.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/optimisation/Brent.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/optimisation/DiRect.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/organiseLoops.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/simplify.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/solvers/solvePolynomials.d.ts +0 -0
- /package/dist/{types/algorithms → algorithms}/stitchSegments.d.ts +0 -0
- /package/dist/{types/api → api}/drawShape.d.ts +0 -0
- /package/dist/{types/api → api}/models.d.ts +0 -0
- /package/dist/{types/booleanOperations.d.ts → booleanOperations.d.ts} +0 -0
- /package/dist/{types/definitions.d.ts → definitions.d.ts} +0 -0
- /package/dist/{types/draw.d.ts → draw.d.ts} +0 -0
- /package/dist/{types/drawShape → drawShape}/drawCircle.d.ts +0 -0
- /package/dist/{types/drawShape → drawShape}/drawRect.d.ts +0 -0
- /package/dist/{types/export → export}/json/exportJSON.d.ts +0 -0
- /package/dist/{types/export → export}/json/jsonDiagram.d.ts +0 -0
- /package/dist/{types/export → export}/json/jsonFigure.d.ts +0 -0
- /package/dist/{types/export → export}/json/jsonLoop.d.ts +0 -0
- /package/dist/{types/export → export}/json/jsonSegment.d.ts +0 -0
- /package/dist/{types/export → export}/svg/exportSVG.d.ts +0 -0
- /package/dist/{types/export → export}/svg/svgDiagram.d.ts +0 -0
- /package/dist/{types/export → export}/svg/svgFigure.d.ts +0 -0
- /package/dist/{types/export → export}/svg/svgLoop.d.ts +0 -0
- /package/dist/{types/export → export}/svg/svgSegment.d.ts +0 -0
- /package/dist/{types/export → export}/svg/svgStrand.d.ts +0 -0
- /package/dist/{types/import → import}/json/importJSON.d.ts +0 -0
- /package/dist/{types/main.d.ts → main.d.ts} +0 -0
- /package/dist/{types/models → models}/BoundingBox.d.ts +0 -0
- /package/dist/{types/models → models}/Diagram.d.ts +0 -0
- /package/dist/{types/models → models}/Figure.d.ts +0 -0
- /package/dist/{types/models → models}/Loop.d.ts +0 -0
- /package/dist/{types/models → models}/Strand.d.ts +0 -0
- /package/dist/{types/models → models}/Stroke.d.ts +0 -0
- /package/dist/{types/models → models}/TransformationMatrix.d.ts +0 -0
- /package/dist/{types/models → models}/segments/Arc.d.ts +0 -0
- /package/dist/{types/models → models}/segments/CubicBezier.d.ts +0 -0
- /package/dist/{types/models → models}/segments/EllipseArc.d.ts +0 -0
- /package/dist/{types/models → models}/segments/Line.d.ts +0 -0
- /package/dist/{types/models → models}/segments/QuadraticBezier.d.ts +0 -0
- /package/dist/{types/models → models}/segments/Segment.d.ts +0 -0
- /package/dist/{types/models → models}/segments/utils/deCasteljau.d.ts +0 -0
- /package/dist/{types/models → models}/segments/utils/isSegment.d.ts +0 -0
- /package/dist/{types/models → models}/utils/Transformable.d.ts +0 -0
- /package/dist/{types/offsetOperations.d.ts → offsetOperations.d.ts} +0 -0
- /package/dist/{types/operations.d.ts → operations.d.ts} +0 -0
- /package/dist/{types/utils → utils}/allCombinations.d.ts +0 -0
- /package/dist/{types/utils → utils}/allPairs.d.ts +0 -0
- /package/dist/{types/utils → utils}/angularDistance.d.ts +0 -0
- /package/dist/{types/utils → utils}/listOfFigures.d.ts +0 -0
- /package/dist/{types/utils → utils}/projectPointOnLine.d.ts +0 -0
- /package/dist/{types/utils → utils}/range.d.ts +0 -0
- /package/dist/{types/utils → utils}/removeDuplicatePoints.d.ts +0 -0
- /package/dist/{types/utils → utils}/removeDuplicateValues.d.ts +0 -0
- /package/dist/{types/utils → utils}/unitAngle.d.ts +0 -0
- /package/dist/{types/utils → utils}/zip.d.ts +0 -0
- /package/dist/{types/vectorOperations.d.ts → vectorOperations.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../export/svg/api.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var b=Object.defineProperty;var y=(i,t,e)=>t in i?b(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var g=(i,t,e)=>(y(i,typeof t!="symbol"?t+"":t,e),e);const r=require("./QuadraticBezier-e3d7218b.cjs"),p=require("./Diagram-57e17509.cjs");class m{constructor(t,e){this.firstPoint=t,this.lastPoint=e}}function A(i,t){if(i instanceof r.Line)return x(i,t);if(i instanceof r.Arc)return _(i,t);throw new Error("Not implemented")}function x(i,t){const{firstPoint:e,lastPoint:n}=i,s=i.normalVector;return new r.Line(r.add(e,r.scalarMultiply(s,t)),r.add(n,r.scalarMultiply(s,t)))}function _(i,t){const e=r.add(i.firstPoint,r.scalarMultiply(r.perpendicular(i.tangentAtFirstPoint),t)),n=r.add(i.lastPoint,r.scalarMultiply(r.perpendicular(i.tangentAtLastPoint),t)),s=t*(i.clockwise?1:-1);return i.radius+s<i.precision?new m(e,n):new r.Arc(e,n,i.center,i.clockwise)}function C(i,t,e){const n=r.crossProduct(i.tangentAtLastPoint,t.tangentAtFirstPoint);if(Math.abs(n)<1e-10)return null;const s=n>0?1:-1,o=Math.abs(e)*s,a=A(i,o),h=A(t,o);if(a instanceof m||h instanceof m)return null;let c;try{c=p.findIntersections(a,h,1e-9).at(-1)}catch{return null}if(!c)return null;const l=c,f=(T,v)=>{const L=v.tangentAt(l),D=r.perpendicularClockwise(L),E=r.add(l,r.scalarMultiply(D,o));return T.splitAt(E)},[u]=f(i,a),[,d]=f(t,h);return{first:u,second:d,center:l}}function P(i,t,e){const n=C(i,t,e);if(!n)return console.warn("Cannot fillet between segments",i.repr,t.repr),[i,t];const{first:s,second:o}=n;return[s,r.tangentArc(s.lastPoint,o.firstPoint,s.tangentAtLastPoint),o]}function w(i,t,e){const n=C(i,t,e);if(!n)return console.warn("Cannot chamfer between segments",i.repr,t.repr),[i,t];const{first:s,second:o}=n;return[s,new r.Line(s.lastPoint,o.firstPoint),o]}const F=i=>{let t;i?typeof i=="number"||Array.isArray(i)&&i.length===2?t={endTangent:i}:t={endTangent:0,...i}:t={endTangent:[1,0]};const{endTangent:e,startFactor:n=1,endFactor:s=1,startTangent:o}=t;let a;typeof e=="number"?a=r.polarToCartesian(1,e*r.DEG2RAD):a=e;let h;return typeof o=="number"?h=r.polarToCartesian(1,o*r.DEG2RAD):h=o,{endTangent:a,startFactor:n,endFactor:s,startTangent:h}};function S(i,{ignoreChecks:t=!1}={}){return new p.Diagram([new p.Figure(new p.Loop([...i],{ignoreChecks:t}))])}class M{constructor(t=[0,0]){g(this,"pointer");g(this,"firstPoint");g(this,"pendingSegments");g(this,"_nextCorner");this.pointer=t,this.firstPoint=t,this.pendingSegments=[],this._nextCorner=null}movePointerTo(t){if(this.pendingSegments.length)throw new Error("You can only move the pointer if there is no segment defined");return this.pointer=t,this.firstPoint=t,this}saveSegment(t){if(r.sameVector(t.firstPoint,t.lastPoint))throw new Error(`Segment has no length, ${t.repr}`);if(!this._nextCorner)return this.pendingSegments.push(t),this;const e=this.pendingSegments.pop();if(!e)throw new Error("bug in the custom corner algorithm");const n=this._nextCorner.mode==="chamfer"?w:P;return this.pendingSegments.push(...n(e,t,this._nextCorner.radius)),this._nextCorner=null,this}lineTo(t){const e=new r.Line(this.pointer,t);return this.pointer=t,this.saveSegment(e)}line(t,e){return this.lineTo([this.pointer[0]+t,this.pointer[1]+e])}vLine(t){return this.line(0,t)}hLine(t){return this.line(t,0)}vLineTo(t){return this.lineTo([this.pointer[0],t])}hLineTo(t){return this.lineTo([t,this.pointer[1]])}polarLineTo([t,e]){const n=e*r.DEG2RAD,s=r.polarToCartesian(t,n);return this.lineTo(s)}polarLine(t,e){const n=e*r.DEG2RAD,[s,o]=r.polarToCartesian(t,n);return this.line(s,o)}tangentLine(t){const e=this.pendingSegments.at(-1);if(!e)throw new Error("You need a previous segment to sketch a tangent line");const[n,s]=e.tangentAtLastPoint;return this.line(n*t,s*t)}threePointsArcTo(t,e){return this.saveSegment(r.threePointsArc(this.pointer,e,t)),this.pointer=t,this}threePointsArc(t,e,n,s){const[o,a]=this.pointer;return this.threePointsArcTo([o+t,a+e],[o+n,a+s])}sagittaArcTo(t,e){if(!e)return this.lineTo(t);const n=new r.Line(this.pointer,t),s=r.perpendicular(n.tangentAtFirstPoint),o=r.add(n.midPoint,r.scalarMultiply(s,e));return this.threePointsArcTo(t,o)}sagittaArc(t,e,n){return this.sagittaArcTo([t+this.pointer[0],e+this.pointer[1]],n)}vSagittaArc(t,e){return this.sagittaArc(0,t,e)}hSagittaArc(t,e){return this.sagittaArc(t,0,e)}bulgeArcTo(t,e){if(!e)return this.lineTo(t);const n=r.distance(this.pointer,t)/2,s=-e*n;return this.sagittaArcTo(t,s)}bulgeArc(t,e,n){return this.bulgeArcTo([t+this.pointer[0],e+this.pointer[1]],n)}vBulgeArc(t,e){return this.bulgeArc(0,t,e)}hBulgeArc(t,e){return this.bulgeArc(t,0,e)}tangentArcTo(t,e){const n=this.pendingSegments.at(-1);if(!n)throw new Error("You need a previous curve to sketch a tangent arc");return this.saveSegment(r.tangentArc(this.pointer,t,e??n.tangentAtLastPoint)),this.pointer=t,this}tangentArc(t,e,n){const[s,o]=this.pointer;return this.tangentArcTo([t+s,e+o],n)}ellipseTo(t,e,n,s,o,a){return this.saveSegment(r.svgEllipse(this.pointer,t,e,n,s,o,a)),this.pointer=t,this}ellipse(t,e,n,s,o,a,h){return this.ellipseTo([t+this.pointer[0],e+this.pointer[1]],n,s,o,a,h)}halfEllipseTo(t,e){const[n,s]=r.cartesianToPolar(r.subtract(t,this.pointer));return this.ellipseTo(t,n/2,Math.abs(e),s*r.RAD2DEG,!0,e>0)}halfEllipse(t,e,n){return this.halfEllipseTo([t+this.pointer[0],e+this.pointer[1]],n)}cubicBezierCurveTo(t,e,n){return this.saveSegment(new r.CubicBezier(this.pointer,t,e,n)),this.pointer=t,this}quadraticBezierCurveTo(t,e){return this.saveSegment(new r.QuadraticBezier(this.pointer,t,e)),this.pointer=t,this}smoothCurveTo(t,e){const{endTangent:n,startTangent:s,startFactor:o,endFactor:a}=F(e),h=this.pendingSegments.length?this.pendingSegments[this.pendingSegments.length-1]:null,c=r.distance(this.pointer,t)/3;let l;s?l=s:h?l=h.tangentAtLastPoint:l=[1,0],l=r.normalize(l);const f=[this.pointer[0]+l[0]*o*c,this.pointer[1]+l[1]*o*c];let u=n;u=r.normalize(u);const d=[t[0]-u[0]*a*c,t[1]-u[1]*a*c];return this.cubicBezierCurveTo(t,f,d)}smoothCurve(t,e,n){return this.smoothCurveTo([t+this.pointer[0],e+this.pointer[1]],n)}customCorner(t,e="fillet"){if(!this.pendingSegments.length)throw new Error("You need a segment defined to fillet the angle");return t?(this._nextCorner={mode:e,radius:t},this):this}_customCornerLastWithFirst(t,e="fillet"){if(!t)return;const n=this.pendingSegments.pop(),s=this.pendingSegments.shift();if(!n||!s)throw new Error("Not enough curves to close and fillet");const o=e==="chamfer"?w:P;this.pendingSegments.push(...o(n,s,t))}close(t=!1){if(!this.pendingSegments.length)throw new Error("No segments to close");const e=this.pendingSegments[0],n=this.pendingSegments.at(-1);return r.sameVector(e.firstPoint,n.lastPoint)||this.lineTo(e.firstPoint),this._nextCorner!==null&&(this._customCornerLastWithFirst(this._nextCorner.radius,this._nextCorner.mode),this._nextCorner=null),S(this.pendingSegments,{ignoreChecks:t})}closeWithMirror(t=!1){if(!this.pendingSegments.length)throw new Error("No segments to close");const e=this.pendingSegments[0],n=this.pendingSegments.at(-1),s=r.subtract(n.lastPoint,e.firstPoint),o=new r.TransformationMatrix().mirrorLine(s,e.firstPoint),a=this.pendingSegments.map(h=>h.transform(o).reverse());return a.reverse(),S([...this.pendingSegments,...a],{ignoreChecks:t})}asStrand(){return new p.Strand([...this.pendingSegments])}get isClosed(){var t;return r.sameVector(this.pointer,(t=this.pendingSegments[0])==null?void 0:t.firstPoint)}}function R(i=[0,0]){return new M(i)}exports.DegenerateSegment=m;exports.draw=R;exports.offsetSegment=A;
|
|
2
|
+
//# sourceMappingURL=draw-27ac6dae.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw-27ac6dae.cjs","sources":["../src/algorithms/offsets/offsetSegment.ts","../src/algorithms/filletSegments.ts","../src/draw.ts"],"sourcesContent":["import { Line } from \"../../models/segments/Line.js\";\nimport { Arc } from \"../../models/segments/Arc.js\";\nimport { Segment } from \"../../models/segments/Segment.js\";\nimport {\n add,\n normalize,\n perpendicular,\n scalarMultiply,\n subtract,\n} from \"../../vectorOperations\";\nimport { Vector } from \"../../definitions.js\";\n\nexport class DegenerateSegment {\n constructor(\n public readonly firstPoint: Vector,\n public readonly lastPoint: Vector,\n ) {}\n}\n\nexport function offsetSegment(\n segment: Segment,\n offset: number,\n): Segment | DegenerateSegment {\n if (segment instanceof Line) {\n return offsetLine(segment, offset);\n }\n\n if (segment instanceof Arc) {\n return offsetArc(segment, offset);\n }\n\n throw new Error(\"Not implemented\");\n}\n\nexport function offsetLine(line: Line, offset: number): Line {\n const { firstPoint, lastPoint } = line;\n\n const normal = line.normalVector;\n return new Line(\n add(firstPoint, scalarMultiply(normal, offset)),\n add(lastPoint, scalarMultiply(normal, offset)),\n );\n}\n\nexport function offsetArc(arc: Arc, offset: number): Arc | DegenerateSegment {\n const offsetStartPoint = add(\n arc.firstPoint,\n scalarMultiply(perpendicular(arc.tangentAtFirstPoint), offset),\n );\n const offsetEndPoint = add(\n arc.lastPoint,\n scalarMultiply(perpendicular(arc.tangentAtLastPoint), offset),\n );\n\n const orientedOffset = offset * (arc.clockwise ? 1 : -1);\n const newRadius = arc.radius + orientedOffset;\n if (newRadius < arc.precision) {\n return new DegenerateSegment(offsetStartPoint, offsetEndPoint);\n }\n\n return new Arc(offsetStartPoint, offsetEndPoint, arc.center, arc.clockwise);\n}\n","import { Vector } from \"../definitions.js\";\nimport { Line } from \"../models/segments/Line.js\";\nimport { tangentArc } from \"../models/segments/Arc.js\";\nimport type { Segment } from \"../models/segments/Segment.js\";\nimport {\n add,\n crossProduct,\n perpendicular,\n perpendicularClockwise,\n scalarMultiply,\n} from \"../vectorOperations\";\nimport { findIntersections } from \"./intersections\";\nimport { DegenerateSegment, offsetSegment } from \"./offsets/offsetSegment.js\";\nimport { exportJSON } from \"../main.js\";\n\nfunction removeCorner(\n firstSegment: Segment,\n secondSegment: Segment,\n radius: number,\n) {\n const sinAngle = crossProduct(\n firstSegment.tangentAtLastPoint,\n secondSegment.tangentAtFirstPoint,\n );\n\n // This cover the case when the segments are colinear\n if (Math.abs(sinAngle) < 1e-10) return null;\n\n const orientationCorrection = sinAngle > 0 ? 1 : -1;\n const offset = Math.abs(radius) * orientationCorrection;\n\n const firstOffset = offsetSegment(firstSegment, offset);\n const secondOffset = offsetSegment(secondSegment, offset);\n\n if (\n firstOffset instanceof DegenerateSegment ||\n secondOffset instanceof DegenerateSegment\n ) {\n return null;\n }\n\n let potentialCenter: Vector | undefined;\n try {\n const intersections = findIntersections(firstOffset, secondOffset, 1e-9);\n\n // We need to work on the case where there are more than one intersections\n potentialCenter = intersections.at(-1);\n } catch (e) {\n return null;\n }\n\n if (!potentialCenter) {\n return null;\n }\n const center = potentialCenter;\n\n const splitForFillet = (segment: Segment, offsetSegment: Segment) => {\n const tgt = offsetSegment.tangentAt(center);\n const normal = perpendicularClockwise(tgt);\n const splitPoint = add(center, scalarMultiply(normal, offset));\n return segment.splitAt(splitPoint);\n };\n\n const [first] = splitForFillet(firstSegment, firstOffset);\n const [, second] = splitForFillet(secondSegment, secondOffset);\n\n return { first, second, center };\n}\n\nexport function filletSegments(\n firstSegment: Segment,\n secondSegment: Segment,\n radius: number,\n) {\n const cornerRemoved = removeCorner(firstSegment, secondSegment, radius);\n if (!cornerRemoved) {\n console.warn(\n \"Cannot fillet between segments\",\n firstSegment.repr,\n secondSegment.repr,\n );\n return [firstSegment, secondSegment];\n }\n\n const { first, second } = cornerRemoved;\n\n return [\n first,\n tangentArc(first.lastPoint, second.firstPoint, first.tangentAtLastPoint),\n second,\n ];\n}\n\nexport function chamferSegments(\n firstSegment: Segment,\n secondSegment: Segment,\n radius: number,\n) {\n const cornerRemoved = removeCorner(firstSegment, secondSegment, radius);\n if (!cornerRemoved) {\n console.warn(\n \"Cannot chamfer between segments\",\n firstSegment.repr,\n secondSegment.repr,\n );\n return [firstSegment, secondSegment];\n }\n\n const { first, second } = cornerRemoved;\n\n return [first, new Line(first.lastPoint, second.firstPoint), second];\n}\n","import {\n chamferSegments,\n filletSegments,\n} from \"./algorithms/filletSegments.js\";\nimport { Vector } from \"./definitions.js\";\nimport { Strand } from \"./models/Strand.js\";\nimport { Diagram } from \"./models/Diagram.js\";\nimport { Figure } from \"./models/Figure.js\";\nimport { Loop } from \"./models/Loop.js\";\nimport { tangentArc, threePointsArc } from \"./models/segments/Arc.js\";\nimport { Line } from \"./models/segments/Line.js\";\nimport { Segment } from \"./models/segments/Segment.js\";\nimport { TransformationMatrix } from \"./models/TransformationMatrix.js\";\nimport {\n polarToCartesian,\n DEG2RAD,\n subtract,\n sameVector,\n perpendicular,\n add,\n scalarMultiply,\n distance,\n cartesianToPolar,\n RAD2DEG,\n normalize,\n} from \"./vectorOperations.js\";\nimport { svgEllipse } from \"./models/segments/EllipseArc.js\";\nimport { QuadraticBezier } from \"./models/segments/QuadraticBezier.js\";\nimport { CubicBezier } from \"./models/segments/CubicBezier.js\";\n\nconst parseSmoothCurveConfig = (\n config?:\n | number\n | Vector\n | {\n endTangent?: number | Vector;\n startTangent?: number | Vector;\n startFactor?: number;\n endFactor?: number;\n },\n) => {\n let conf: {\n endTangent: number | Vector;\n startFactor?: number;\n endFactor?: number;\n startTangent?: number | Vector;\n };\n\n if (!config) conf = { endTangent: [1, 0] };\n else if (\n typeof config === \"number\" ||\n (Array.isArray(config) && config.length === 2)\n ) {\n conf = { endTangent: config };\n } else {\n conf = { endTangent: 0, ...config };\n }\n const {\n endTangent: endTgt,\n startFactor = 1,\n endFactor = 1,\n startTangent: startTgt,\n } = conf;\n\n let endTangent: Vector;\n if (typeof endTgt === \"number\") {\n endTangent = polarToCartesian(1, endTgt * DEG2RAD);\n } else {\n endTangent = endTgt;\n }\n\n let startTangent: Vector | undefined;\n if (typeof startTgt === \"number\") {\n startTangent = polarToCartesian(1, startTgt * DEG2RAD);\n } else {\n startTangent = startTgt;\n }\n\n return { endTangent, startFactor, endFactor, startTangent };\n};\n\nfunction loopySegmentsToDiagram(\n segments: Segment[],\n { ignoreChecks = false } = {},\n) {\n // Here we will need to do our best to fix cases where the drawing is\n // broken in some way (i.e. self-intersecting loops)\n\n return new Diagram([new Figure(new Loop([...segments], { ignoreChecks }))]);\n}\n\nexport class DrawingPen {\n pointer: Vector;\n protected firstPoint: Vector;\n protected pendingSegments: Segment[];\n\n protected _nextCorner: { radius: number; mode: \"fillet\" | \"chamfer\" } | null;\n\n constructor(origin: Vector = [0, 0]) {\n this.pointer = origin;\n this.firstPoint = origin;\n\n this.pendingSegments = [];\n this._nextCorner = null;\n }\n\n movePointerTo(point: Vector): this {\n if (this.pendingSegments.length)\n throw new Error(\n \"You can only move the pointer if there is no segment defined\",\n );\n\n this.pointer = point;\n this.firstPoint = point;\n return this;\n }\n\n protected saveSegment(segment: Segment) {\n if (sameVector(segment.firstPoint, segment.lastPoint)) {\n throw new Error(`Segment has no length, ${segment.repr}`);\n }\n\n if (!this._nextCorner) {\n this.pendingSegments.push(segment);\n return this;\n }\n\n const previousSegment = this.pendingSegments.pop();\n if (!previousSegment) throw new Error(\"bug in the custom corner algorithm\");\n\n const makeCorner =\n this._nextCorner.mode === \"chamfer\" ? chamferSegments : filletSegments;\n\n this.pendingSegments.push(\n ...makeCorner(previousSegment, segment, this._nextCorner.radius),\n );\n this._nextCorner = null;\n return this;\n }\n\n lineTo(point: Vector): this {\n const segment = new Line(this.pointer, point);\n this.pointer = point;\n return this.saveSegment(segment);\n }\n\n line(xDist: number, yDist: number): this {\n return this.lineTo([this.pointer[0] + xDist, this.pointer[1] + yDist]);\n }\n\n vLine(distance: number): this {\n return this.line(0, distance);\n }\n\n hLine(distance: number): this {\n return this.line(distance, 0);\n }\n\n vLineTo(yPos: number): this {\n return this.lineTo([this.pointer[0], yPos]);\n }\n\n hLineTo(xPos: number): this {\n return this.lineTo([xPos, this.pointer[1]]);\n }\n\n polarLineTo([r, theta]: Vector): this {\n const angleInRads = theta * DEG2RAD;\n const point = polarToCartesian(r, angleInRads);\n return this.lineTo(point);\n }\n\n polarLine(distance: number, angle: number): this {\n const angleInRads = angle * DEG2RAD;\n const [x, y] = polarToCartesian(distance, angleInRads);\n return this.line(x, y);\n }\n\n tangentLine(distance: number): this {\n const previousCurve = this.pendingSegments.at(-1);\n\n if (!previousCurve)\n throw new Error(\"You need a previous segment to sketch a tangent line\");\n\n const [xDir, yDir] = previousCurve.tangentAtLastPoint;\n return this.line(xDir * distance, yDir * distance);\n }\n\n threePointsArcTo(end: Vector, midPoint: Vector): this {\n this.saveSegment(threePointsArc(this.pointer, midPoint, end));\n this.pointer = end;\n return this;\n }\n\n threePointsArc(\n xDist: number,\n yDist: number,\n viaXDist: number,\n viaYDist: number,\n ): this {\n const [x0, y0] = this.pointer;\n return this.threePointsArcTo(\n [x0 + xDist, y0 + yDist],\n [x0 + viaXDist, y0 + viaYDist],\n );\n }\n\n sagittaArcTo(end: Vector, sagitta: number): this {\n if (!sagitta) return this.lineTo(end);\n const chord = new Line(this.pointer, end);\n const norm = perpendicular(chord.tangentAtFirstPoint);\n\n const sagPoint: Vector = add(chord.midPoint, scalarMultiply(norm, sagitta));\n\n return this.threePointsArcTo(end, sagPoint);\n }\n\n sagittaArc(xDist: number, yDist: number, sagitta: number): this {\n return this.sagittaArcTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n sagitta,\n );\n }\n\n vSagittaArc(distance: number, sagitta: number): this {\n return this.sagittaArc(0, distance, sagitta);\n }\n\n hSagittaArc(distance: number, sagitta: number): this {\n return this.sagittaArc(distance, 0, sagitta);\n }\n\n bulgeArcTo(end: Vector, bulge: number): this {\n if (!bulge) return this.lineTo(end);\n const halfChord = distance(this.pointer, end) / 2;\n const bulgeAsSagitta = -bulge * halfChord;\n\n return this.sagittaArcTo(end, bulgeAsSagitta);\n }\n\n bulgeArc(xDist: number, yDist: number, bulge: number): this {\n return this.bulgeArcTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n bulge,\n );\n }\n\n vBulgeArc(distance: number, bulge: number): this {\n return this.bulgeArc(0, distance, bulge);\n }\n\n hBulgeArc(distance: number, bulge: number): this {\n return this.bulgeArc(distance, 0, bulge);\n }\n\n tangentArcTo(end: Vector, tangentAtStart?: Vector): this {\n const previousCurve = this.pendingSegments.at(-1);\n\n if (!previousCurve)\n throw new Error(\"You need a previous curve to sketch a tangent arc\");\n\n this.saveSegment(\n tangentArc(\n this.pointer,\n end,\n tangentAtStart ?? previousCurve.tangentAtLastPoint,\n ),\n );\n\n this.pointer = end;\n return this;\n }\n\n tangentArc(xDist: number, yDist: number, tangentAtStart?: Vector): this {\n const [x0, y0] = this.pointer;\n return this.tangentArcTo([xDist + x0, yDist + y0], tangentAtStart);\n }\n\n ellipseTo(\n end: Vector,\n r0: number,\n r1: number,\n xAxisRotation: number,\n longArc: boolean,\n sweepFlag: boolean,\n ): this {\n this.saveSegment(\n svgEllipse(this.pointer, end, r0, r1, xAxisRotation, longArc, sweepFlag),\n );\n this.pointer = end;\n return this;\n }\n\n ellipse(\n xDist: number,\n yDist: number,\n r0: number,\n r1: number,\n xAxisRotation: number,\n longArc: boolean,\n sweepFlag: boolean,\n ): this {\n return this.ellipseTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n r0,\n r1,\n xAxisRotation,\n longArc,\n sweepFlag,\n );\n }\n\n halfEllipseTo(end: Vector, sagitta: number): this {\n const [distance, angle] = cartesianToPolar(subtract(end, this.pointer));\n\n return this.ellipseTo(\n end,\n distance / 2,\n Math.abs(sagitta),\n angle * RAD2DEG,\n true,\n sagitta > 0,\n );\n }\n\n halfEllipse(xDist: number, yDist: number, sagitta: number): this {\n return this.halfEllipseTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n sagitta,\n );\n }\n\n cubicBezierCurveTo(\n end: Vector,\n startControlPoint: Vector,\n endControlPoint: Vector,\n ): this {\n this.saveSegment(\n new CubicBezier(this.pointer, end, startControlPoint, endControlPoint),\n );\n this.pointer = end;\n return this;\n }\n\n quadraticBezierCurveTo(end: Vector, controlPoint: Vector): this {\n this.saveSegment(new QuadraticBezier(this.pointer, end, controlPoint));\n this.pointer = end;\n return this;\n }\n\n smoothCurveTo(\n end: Vector,\n config?:\n | number\n | Vector\n | {\n endTangent?: number | Vector;\n startTangent?: number | Vector;\n startFactor?: number;\n endFactor?: number;\n },\n ): this {\n const { endTangent, startTangent, startFactor, endFactor } =\n parseSmoothCurveConfig(config);\n\n const previousCurve = this.pendingSegments.length\n ? this.pendingSegments[this.pendingSegments.length - 1]\n : null;\n\n const defaultDistance = distance(this.pointer, end) / 3;\n\n let startPoleDirection: Vector;\n if (startTangent) {\n startPoleDirection = startTangent;\n } else if (!previousCurve) {\n startPoleDirection = [1, 0];\n } else {\n startPoleDirection = previousCurve.tangentAtLastPoint;\n }\n\n startPoleDirection = normalize(startPoleDirection);\n const startControl: Vector = [\n this.pointer[0] + startPoleDirection[0] * startFactor * defaultDistance,\n this.pointer[1] + startPoleDirection[1] * startFactor * defaultDistance,\n ];\n\n let endPoleDirection = endTangent;\n\n endPoleDirection = normalize(endPoleDirection);\n const endControl: Vector = [\n end[0] - endPoleDirection[0] * endFactor * defaultDistance,\n end[1] - endPoleDirection[1] * endFactor * defaultDistance,\n ];\n\n return this.cubicBezierCurveTo(end, startControl, endControl);\n }\n\n smoothCurve(\n xDist: number,\n yDist: number,\n config?:\n | number\n | Vector\n | {\n endTangent?: number | Vector;\n startTangent?: number | Vector;\n startFactor?: number;\n endFactor?: number;\n },\n ) {\n return this.smoothCurveTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n config,\n );\n }\n\n customCorner(radius: number, mode: \"fillet\" | \"chamfer\" = \"fillet\") {\n if (!this.pendingSegments.length)\n throw new Error(\"You need a segment defined to fillet the angle\");\n\n if (!radius) return this;\n\n this._nextCorner = { mode, radius };\n return this;\n }\n\n protected _customCornerLastWithFirst(\n radius: number,\n mode: \"fillet\" | \"chamfer\" = \"fillet\",\n ) {\n if (!radius) return;\n\n const lastSegment = this.pendingSegments.pop();\n const firstSegment = this.pendingSegments.shift();\n\n if (!lastSegment || !firstSegment)\n throw new Error(\"Not enough curves to close and fillet\");\n\n const makeCorner = mode === \"chamfer\" ? chamferSegments : filletSegments;\n\n this.pendingSegments.push(...makeCorner(lastSegment, firstSegment, radius));\n }\n\n close(ignoreChecks = false): Diagram {\n if (!this.pendingSegments.length) throw new Error(\"No segments to close\");\n const firstSegment = this.pendingSegments[0];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSegment = this.pendingSegments.at(-1)!;\n\n if (!sameVector(firstSegment.firstPoint, lastSegment.lastPoint)) {\n this.lineTo(firstSegment.firstPoint);\n }\n\n if (this._nextCorner !== null) {\n this._customCornerLastWithFirst(\n this._nextCorner.radius,\n this._nextCorner.mode,\n );\n this._nextCorner = null;\n }\n\n return loopySegmentsToDiagram(this.pendingSegments, { ignoreChecks });\n }\n\n closeWithMirror(ignoreChecks = false): Diagram {\n if (!this.pendingSegments.length) throw new Error(\"No segments to close\");\n\n const firstSegment = this.pendingSegments[0];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSegment = this.pendingSegments.at(-1)!;\n\n const mirrorVector = subtract(\n lastSegment.lastPoint,\n firstSegment.firstPoint,\n );\n const mirrorTranform = new TransformationMatrix().mirrorLine(\n mirrorVector,\n firstSegment.firstPoint,\n );\n\n const mirroredSegments = this.pendingSegments.map((segment) =>\n segment.transform(mirrorTranform).reverse(),\n );\n mirroredSegments.reverse();\n\n return loopySegmentsToDiagram(\n [...this.pendingSegments, ...mirroredSegments],\n { ignoreChecks },\n );\n }\n\n asStrand(): Strand {\n return new Strand([...this.pendingSegments]);\n }\n\n get isClosed(): boolean {\n return sameVector(this.pointer, this.pendingSegments[0]?.firstPoint);\n }\n}\n\nexport function draw(origin: Vector = [0, 0]): DrawingPen {\n return new DrawingPen(origin);\n}\n"],"names":["DegenerateSegment","firstPoint","lastPoint","offsetSegment","segment","offset","Line","offsetLine","Arc","offsetArc","line","normal","add","scalarMultiply","arc","offsetStartPoint","perpendicular","offsetEndPoint","orientedOffset","removeCorner","firstSegment","secondSegment","radius","sinAngle","crossProduct","orientationCorrection","firstOffset","secondOffset","potentialCenter","findIntersections","center","splitForFillet","tgt","perpendicularClockwise","splitPoint","first","second","filletSegments","cornerRemoved","tangentArc","chamferSegments","parseSmoothCurveConfig","config","conf","endTgt","startFactor","endFactor","startTgt","endTangent","polarToCartesian","DEG2RAD","startTangent","loopySegmentsToDiagram","segments","ignoreChecks","Diagram","Figure","Loop","DrawingPen","origin","__publicField","point","sameVector","previousSegment","makeCorner","xDist","yDist","distance","yPos","xPos","r","theta","angleInRads","angle","x","y","previousCurve","xDir","yDir","end","midPoint","threePointsArc","viaXDist","viaYDist","x0","y0","sagitta","chord","norm","sagPoint","bulge","halfChord","bulgeAsSagitta","tangentAtStart","r0","r1","xAxisRotation","longArc","sweepFlag","svgEllipse","cartesianToPolar","subtract","RAD2DEG","startControlPoint","endControlPoint","CubicBezier","controlPoint","QuadraticBezier","defaultDistance","startPoleDirection","normalize","startControl","endPoleDirection","endControl","mode","lastSegment","mirrorVector","mirrorTranform","TransformationMatrix","mirroredSegments","Strand","_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!0, value: e }) : r[t] = e;
|
|
3
|
+
var p = (r, t, e) => (Y(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
import { L as f, A as F, a as u, b as g, h as S, t as _, f as I, i as O, e as A, j as V, d as v, k as W, m as G, s as L, R as Q, C as j, Q as q, T as $, o as d, n as b, D as T } from "./QuadraticBezier-e116a2d6.js";
|
|
5
|
+
import { h as H, S as J, D as K, F as U, L as X } from "./Diagram-2450b2e6.js";
|
|
6
|
+
class C {
|
|
3
7
|
constructor(t, e) {
|
|
4
8
|
this.firstPoint = t, this.lastPoint = e;
|
|
5
9
|
}
|
|
6
10
|
}
|
|
7
|
-
function
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
10
|
-
if (
|
|
11
|
-
return
|
|
11
|
+
function x(r, t) {
|
|
12
|
+
if (r instanceof f)
|
|
13
|
+
return Z(r, t);
|
|
14
|
+
if (r instanceof F)
|
|
15
|
+
return tt(r, t);
|
|
12
16
|
throw new Error("Not implemented");
|
|
13
17
|
}
|
|
14
|
-
function
|
|
15
|
-
const { firstPoint: e, lastPoint: n } =
|
|
16
|
-
return new
|
|
17
|
-
u(e, g(
|
|
18
|
-
u(n, g(
|
|
18
|
+
function Z(r, t) {
|
|
19
|
+
const { firstPoint: e, lastPoint: n } = r, i = r.normalVector;
|
|
20
|
+
return new f(
|
|
21
|
+
u(e, g(i, t)),
|
|
22
|
+
u(n, g(i, t))
|
|
19
23
|
);
|
|
20
24
|
}
|
|
21
|
-
function
|
|
25
|
+
function tt(r, t) {
|
|
22
26
|
const e = u(
|
|
23
|
-
|
|
24
|
-
g(
|
|
27
|
+
r.firstPoint,
|
|
28
|
+
g(S(r.tangentAtFirstPoint), t)
|
|
25
29
|
), n = u(
|
|
26
|
-
|
|
27
|
-
g(
|
|
28
|
-
),
|
|
29
|
-
return
|
|
30
|
+
r.lastPoint,
|
|
31
|
+
g(S(r.tangentAtLastPoint), t)
|
|
32
|
+
), i = t * (r.clockwise ? 1 : -1);
|
|
33
|
+
return r.radius + i < r.precision ? new C(e, n) : new F(e, n, r.center, r.clockwise);
|
|
30
34
|
}
|
|
31
|
-
function
|
|
32
|
-
const n =
|
|
33
|
-
|
|
35
|
+
function R(r, t, e) {
|
|
36
|
+
const n = I(
|
|
37
|
+
r.tangentAtLastPoint,
|
|
34
38
|
t.tangentAtFirstPoint
|
|
35
39
|
);
|
|
36
40
|
if (Math.abs(n) < 1e-10)
|
|
37
41
|
return null;
|
|
38
|
-
const
|
|
39
|
-
if (o instanceof
|
|
42
|
+
const i = n > 0 ? 1 : -1, s = Math.abs(e) * i, o = x(r, s), a = x(t, s);
|
|
43
|
+
if (o instanceof C || a instanceof C)
|
|
40
44
|
return null;
|
|
41
45
|
let c;
|
|
42
46
|
try {
|
|
43
|
-
c =
|
|
47
|
+
c = H(o, a, 1e-9).at(-1);
|
|
44
48
|
} catch {
|
|
45
49
|
return null;
|
|
46
50
|
}
|
|
47
51
|
if (!c)
|
|
48
52
|
return null;
|
|
49
|
-
const h = c,
|
|
50
|
-
const
|
|
51
|
-
return
|
|
52
|
-
}, [l] =
|
|
53
|
-
return { first: l, second:
|
|
53
|
+
const h = c, m = (w, k) => {
|
|
54
|
+
const B = k.tangentAt(h), z = O(B), M = u(h, g(z, s));
|
|
55
|
+
return w.splitAt(M);
|
|
56
|
+
}, [l] = m(r, o), [, P] = m(t, a);
|
|
57
|
+
return { first: l, second: P, center: h };
|
|
54
58
|
}
|
|
55
|
-
function E(
|
|
56
|
-
const n =
|
|
59
|
+
function E(r, t, e) {
|
|
60
|
+
const n = R(r, t, e);
|
|
57
61
|
if (!n)
|
|
58
62
|
return console.warn(
|
|
59
63
|
"Cannot fillet between segments",
|
|
60
|
-
|
|
64
|
+
r.repr,
|
|
61
65
|
t.repr
|
|
62
|
-
), [
|
|
63
|
-
const { first:
|
|
66
|
+
), [r, t];
|
|
67
|
+
const { first: i, second: s } = n;
|
|
64
68
|
return [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
i,
|
|
70
|
+
_(i.lastPoint, s.firstPoint, i.tangentAtLastPoint),
|
|
71
|
+
s
|
|
68
72
|
];
|
|
69
73
|
}
|
|
70
|
-
function
|
|
71
|
-
const n =
|
|
74
|
+
function D(r, t, e) {
|
|
75
|
+
const n = R(r, t, e);
|
|
72
76
|
if (!n)
|
|
73
77
|
return console.warn(
|
|
74
78
|
"Cannot chamfer between segments",
|
|
75
|
-
|
|
79
|
+
r.repr,
|
|
76
80
|
t.repr
|
|
77
|
-
), [
|
|
78
|
-
const { first:
|
|
79
|
-
return [
|
|
81
|
+
), [r, t];
|
|
82
|
+
const { first: i, second: s } = n;
|
|
83
|
+
return [i, new f(i.lastPoint, s.firstPoint), s];
|
|
80
84
|
}
|
|
81
|
-
const
|
|
85
|
+
const et = (r) => {
|
|
82
86
|
let t;
|
|
83
|
-
|
|
87
|
+
r ? typeof r == "number" || Array.isArray(r) && r.length === 2 ? t = { endTangent: r } : t = { endTangent: 0, ...r } : t = { endTangent: [1, 0] };
|
|
84
88
|
const {
|
|
85
89
|
endTangent: e,
|
|
86
90
|
startFactor: n = 1,
|
|
87
|
-
endFactor:
|
|
88
|
-
startTangent:
|
|
91
|
+
endFactor: i = 1,
|
|
92
|
+
startTangent: s
|
|
89
93
|
} = t;
|
|
90
94
|
let o;
|
|
91
|
-
typeof e == "number" ? o =
|
|
95
|
+
typeof e == "number" ? o = d(1, e * T) : o = e;
|
|
92
96
|
let a;
|
|
93
|
-
return typeof
|
|
97
|
+
return typeof s == "number" ? a = d(1, s * T) : a = s, { endTangent: o, startFactor: n, endFactor: i, startTangent: a };
|
|
94
98
|
};
|
|
95
|
-
function
|
|
96
|
-
return new
|
|
99
|
+
function y(r, { ignoreChecks: t = !1 } = {}) {
|
|
100
|
+
return new K([new U(new X([...r], { ignoreChecks: t }))]);
|
|
97
101
|
}
|
|
98
|
-
class
|
|
102
|
+
class nt {
|
|
99
103
|
constructor(t = [0, 0]) {
|
|
104
|
+
p(this, "pointer");
|
|
105
|
+
p(this, "firstPoint");
|
|
106
|
+
p(this, "pendingSegments");
|
|
107
|
+
p(this, "_nextCorner");
|
|
100
108
|
this.pointer = t, this.firstPoint = t, this.pendingSegments = [], this._nextCorner = null;
|
|
101
109
|
}
|
|
102
110
|
movePointerTo(t) {
|
|
@@ -107,20 +115,20 @@ class Z {
|
|
|
107
115
|
return this.pointer = t, this.firstPoint = t, this;
|
|
108
116
|
}
|
|
109
117
|
saveSegment(t) {
|
|
110
|
-
if (
|
|
118
|
+
if (A(t.firstPoint, t.lastPoint))
|
|
111
119
|
throw new Error(`Segment has no length, ${t.repr}`);
|
|
112
120
|
if (!this._nextCorner)
|
|
113
121
|
return this.pendingSegments.push(t), this;
|
|
114
122
|
const e = this.pendingSegments.pop();
|
|
115
123
|
if (!e)
|
|
116
124
|
throw new Error("bug in the custom corner algorithm");
|
|
117
|
-
const n = this._nextCorner.mode === "chamfer" ?
|
|
125
|
+
const n = this._nextCorner.mode === "chamfer" ? D : E;
|
|
118
126
|
return this.pendingSegments.push(
|
|
119
127
|
...n(e, t, this._nextCorner.radius)
|
|
120
128
|
), this._nextCorner = null, this;
|
|
121
129
|
}
|
|
122
130
|
lineTo(t) {
|
|
123
|
-
const e = new
|
|
131
|
+
const e = new f(this.pointer, t);
|
|
124
132
|
return this.pointer = t, this.saveSegment(e);
|
|
125
133
|
}
|
|
126
134
|
line(t, e) {
|
|
@@ -139,35 +147,35 @@ class Z {
|
|
|
139
147
|
return this.lineTo([t, this.pointer[1]]);
|
|
140
148
|
}
|
|
141
149
|
polarLineTo([t, e]) {
|
|
142
|
-
const n = e *
|
|
143
|
-
return this.lineTo(
|
|
150
|
+
const n = e * T, i = d(t, n);
|
|
151
|
+
return this.lineTo(i);
|
|
144
152
|
}
|
|
145
153
|
polarLine(t, e) {
|
|
146
|
-
const n = e *
|
|
147
|
-
return this.line(
|
|
154
|
+
const n = e * T, [i, s] = d(t, n);
|
|
155
|
+
return this.line(i, s);
|
|
148
156
|
}
|
|
149
157
|
tangentLine(t) {
|
|
150
158
|
const e = this.pendingSegments.at(-1);
|
|
151
159
|
if (!e)
|
|
152
160
|
throw new Error("You need a previous segment to sketch a tangent line");
|
|
153
|
-
const [n,
|
|
154
|
-
return this.line(n * t,
|
|
161
|
+
const [n, i] = e.tangentAtLastPoint;
|
|
162
|
+
return this.line(n * t, i * t);
|
|
155
163
|
}
|
|
156
164
|
threePointsArcTo(t, e) {
|
|
157
|
-
return this.saveSegment(
|
|
165
|
+
return this.saveSegment(V(this.pointer, e, t)), this.pointer = t, this;
|
|
158
166
|
}
|
|
159
|
-
threePointsArc(t, e, n,
|
|
160
|
-
const [
|
|
167
|
+
threePointsArc(t, e, n, i) {
|
|
168
|
+
const [s, o] = this.pointer;
|
|
161
169
|
return this.threePointsArcTo(
|
|
162
|
-
[
|
|
163
|
-
[
|
|
170
|
+
[s + t, o + e],
|
|
171
|
+
[s + n, o + i]
|
|
164
172
|
);
|
|
165
173
|
}
|
|
166
174
|
sagittaArcTo(t, e) {
|
|
167
175
|
if (!e)
|
|
168
176
|
return this.lineTo(t);
|
|
169
|
-
const n = new
|
|
170
|
-
return this.threePointsArcTo(t,
|
|
177
|
+
const n = new f(this.pointer, t), i = S(n.tangentAtFirstPoint), s = u(n.midPoint, g(i, e));
|
|
178
|
+
return this.threePointsArcTo(t, s);
|
|
171
179
|
}
|
|
172
180
|
sagittaArc(t, e, n) {
|
|
173
181
|
return this.sagittaArcTo(
|
|
@@ -184,8 +192,8 @@ class Z {
|
|
|
184
192
|
bulgeArcTo(t, e) {
|
|
185
193
|
if (!e)
|
|
186
194
|
return this.lineTo(t);
|
|
187
|
-
const n =
|
|
188
|
-
return this.sagittaArcTo(t,
|
|
195
|
+
const n = v(this.pointer, t) / 2, i = -e * n;
|
|
196
|
+
return this.sagittaArcTo(t, i);
|
|
189
197
|
}
|
|
190
198
|
bulgeArc(t, e, n) {
|
|
191
199
|
return this.bulgeArcTo(
|
|
@@ -204,7 +212,7 @@ class Z {
|
|
|
204
212
|
if (!n)
|
|
205
213
|
throw new Error("You need a previous curve to sketch a tangent arc");
|
|
206
214
|
return this.saveSegment(
|
|
207
|
-
|
|
215
|
+
_(
|
|
208
216
|
this.pointer,
|
|
209
217
|
t,
|
|
210
218
|
e ?? n.tangentAtLastPoint
|
|
@@ -212,31 +220,31 @@ class Z {
|
|
|
212
220
|
), this.pointer = t, this;
|
|
213
221
|
}
|
|
214
222
|
tangentArc(t, e, n) {
|
|
215
|
-
const [
|
|
216
|
-
return this.tangentArcTo([t +
|
|
223
|
+
const [i, s] = this.pointer;
|
|
224
|
+
return this.tangentArcTo([t + i, e + s], n);
|
|
217
225
|
}
|
|
218
|
-
ellipseTo(t, e, n,
|
|
226
|
+
ellipseTo(t, e, n, i, s, o) {
|
|
219
227
|
return this.saveSegment(
|
|
220
|
-
|
|
228
|
+
W(this.pointer, t, e, n, i, s, o)
|
|
221
229
|
), this.pointer = t, this;
|
|
222
230
|
}
|
|
223
|
-
ellipse(t, e, n,
|
|
231
|
+
ellipse(t, e, n, i, s, o, a) {
|
|
224
232
|
return this.ellipseTo(
|
|
225
233
|
[t + this.pointer[0], e + this.pointer[1]],
|
|
226
234
|
n,
|
|
227
|
-
r,
|
|
228
235
|
i,
|
|
236
|
+
s,
|
|
229
237
|
o,
|
|
230
238
|
a
|
|
231
239
|
);
|
|
232
240
|
}
|
|
233
241
|
halfEllipseTo(t, e) {
|
|
234
|
-
const [n,
|
|
242
|
+
const [n, i] = G(L(t, this.pointer));
|
|
235
243
|
return this.ellipseTo(
|
|
236
244
|
t,
|
|
237
245
|
n / 2,
|
|
238
246
|
Math.abs(e),
|
|
239
|
-
|
|
247
|
+
i * Q,
|
|
240
248
|
!0,
|
|
241
249
|
e > 0
|
|
242
250
|
);
|
|
@@ -249,27 +257,27 @@ class Z {
|
|
|
249
257
|
}
|
|
250
258
|
cubicBezierCurveTo(t, e, n) {
|
|
251
259
|
return this.saveSegment(
|
|
252
|
-
new
|
|
260
|
+
new j(this.pointer, t, e, n)
|
|
253
261
|
), this.pointer = t, this;
|
|
254
262
|
}
|
|
255
263
|
quadraticBezierCurveTo(t, e) {
|
|
256
|
-
return this.saveSegment(new
|
|
264
|
+
return this.saveSegment(new q(this.pointer, t, e)), this.pointer = t, this;
|
|
257
265
|
}
|
|
258
266
|
smoothCurveTo(t, e) {
|
|
259
|
-
const { endTangent: n, startTangent:
|
|
267
|
+
const { endTangent: n, startTangent: i, startFactor: s, endFactor: o } = et(e), a = this.pendingSegments.length ? this.pendingSegments[this.pendingSegments.length - 1] : null, c = v(this.pointer, t) / 3;
|
|
260
268
|
let h;
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
this.pointer[0] + h[0] *
|
|
264
|
-
this.pointer[1] + h[1] *
|
|
269
|
+
i ? h = i : a ? h = a.tangentAtLastPoint : h = [1, 0], h = b(h);
|
|
270
|
+
const m = [
|
|
271
|
+
this.pointer[0] + h[0] * s * c,
|
|
272
|
+
this.pointer[1] + h[1] * s * c
|
|
265
273
|
];
|
|
266
274
|
let l = n;
|
|
267
|
-
l =
|
|
268
|
-
const
|
|
275
|
+
l = b(l);
|
|
276
|
+
const P = [
|
|
269
277
|
t[0] - l[0] * o * c,
|
|
270
278
|
t[1] - l[1] * o * c
|
|
271
279
|
];
|
|
272
|
-
return this.cubicBezierCurveTo(t,
|
|
280
|
+
return this.cubicBezierCurveTo(t, m, P);
|
|
273
281
|
}
|
|
274
282
|
smoothCurve(t, e, n) {
|
|
275
283
|
return this.smoothCurveTo(
|
|
@@ -285,52 +293,52 @@ class Z {
|
|
|
285
293
|
_customCornerLastWithFirst(t, e = "fillet") {
|
|
286
294
|
if (!t)
|
|
287
295
|
return;
|
|
288
|
-
const n = this.pendingSegments.pop(),
|
|
289
|
-
if (!n || !
|
|
296
|
+
const n = this.pendingSegments.pop(), i = this.pendingSegments.shift();
|
|
297
|
+
if (!n || !i)
|
|
290
298
|
throw new Error("Not enough curves to close and fillet");
|
|
291
|
-
const
|
|
292
|
-
this.pendingSegments.push(...
|
|
299
|
+
const s = e === "chamfer" ? D : E;
|
|
300
|
+
this.pendingSegments.push(...s(n, i, t));
|
|
293
301
|
}
|
|
294
302
|
close(t = !1) {
|
|
295
303
|
if (!this.pendingSegments.length)
|
|
296
304
|
throw new Error("No segments to close");
|
|
297
305
|
const e = this.pendingSegments[0], n = this.pendingSegments.at(-1);
|
|
298
|
-
return
|
|
306
|
+
return A(e.firstPoint, n.lastPoint) || this.lineTo(e.firstPoint), this._nextCorner !== null && (this._customCornerLastWithFirst(
|
|
299
307
|
this._nextCorner.radius,
|
|
300
308
|
this._nextCorner.mode
|
|
301
|
-
), this._nextCorner = null),
|
|
309
|
+
), this._nextCorner = null), y(this.pendingSegments, { ignoreChecks: t });
|
|
302
310
|
}
|
|
303
311
|
closeWithMirror(t = !1) {
|
|
304
312
|
if (!this.pendingSegments.length)
|
|
305
313
|
throw new Error("No segments to close");
|
|
306
|
-
const e = this.pendingSegments[0], n = this.pendingSegments.at(-1),
|
|
314
|
+
const e = this.pendingSegments[0], n = this.pendingSegments.at(-1), i = L(
|
|
307
315
|
n.lastPoint,
|
|
308
316
|
e.firstPoint
|
|
309
|
-
),
|
|
310
|
-
|
|
317
|
+
), s = new $().mirrorLine(
|
|
318
|
+
i,
|
|
311
319
|
e.firstPoint
|
|
312
320
|
), o = this.pendingSegments.map(
|
|
313
|
-
(a) => a.transform(
|
|
321
|
+
(a) => a.transform(s).reverse()
|
|
314
322
|
);
|
|
315
|
-
return o.reverse(),
|
|
323
|
+
return o.reverse(), y(
|
|
316
324
|
[...this.pendingSegments, ...o],
|
|
317
325
|
{ ignoreChecks: t }
|
|
318
326
|
);
|
|
319
327
|
}
|
|
320
328
|
asStrand() {
|
|
321
|
-
return new
|
|
329
|
+
return new J([...this.pendingSegments]);
|
|
322
330
|
}
|
|
323
331
|
get isClosed() {
|
|
324
332
|
var t;
|
|
325
|
-
return
|
|
333
|
+
return A(this.pointer, (t = this.pendingSegments[0]) == null ? void 0 : t.firstPoint);
|
|
326
334
|
}
|
|
327
335
|
}
|
|
328
|
-
function
|
|
329
|
-
return new
|
|
336
|
+
function ot(r = [0, 0]) {
|
|
337
|
+
return new nt(r);
|
|
330
338
|
}
|
|
331
339
|
export {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
340
|
+
C as D,
|
|
341
|
+
ot as d,
|
|
342
|
+
x as o
|
|
335
343
|
};
|
|
336
|
-
//# sourceMappingURL=draw-
|
|
344
|
+
//# sourceMappingURL=draw-c7b2705c.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw-c7b2705c.js","sources":["../src/algorithms/offsets/offsetSegment.ts","../src/algorithms/filletSegments.ts","../src/draw.ts"],"sourcesContent":["import { Line } from \"../../models/segments/Line.js\";\nimport { Arc } from \"../../models/segments/Arc.js\";\nimport { Segment } from \"../../models/segments/Segment.js\";\nimport {\n add,\n normalize,\n perpendicular,\n scalarMultiply,\n subtract,\n} from \"../../vectorOperations\";\nimport { Vector } from \"../../definitions.js\";\n\nexport class DegenerateSegment {\n constructor(\n public readonly firstPoint: Vector,\n public readonly lastPoint: Vector,\n ) {}\n}\n\nexport function offsetSegment(\n segment: Segment,\n offset: number,\n): Segment | DegenerateSegment {\n if (segment instanceof Line) {\n return offsetLine(segment, offset);\n }\n\n if (segment instanceof Arc) {\n return offsetArc(segment, offset);\n }\n\n throw new Error(\"Not implemented\");\n}\n\nexport function offsetLine(line: Line, offset: number): Line {\n const { firstPoint, lastPoint } = line;\n\n const normal = line.normalVector;\n return new Line(\n add(firstPoint, scalarMultiply(normal, offset)),\n add(lastPoint, scalarMultiply(normal, offset)),\n );\n}\n\nexport function offsetArc(arc: Arc, offset: number): Arc | DegenerateSegment {\n const offsetStartPoint = add(\n arc.firstPoint,\n scalarMultiply(perpendicular(arc.tangentAtFirstPoint), offset),\n );\n const offsetEndPoint = add(\n arc.lastPoint,\n scalarMultiply(perpendicular(arc.tangentAtLastPoint), offset),\n );\n\n const orientedOffset = offset * (arc.clockwise ? 1 : -1);\n const newRadius = arc.radius + orientedOffset;\n if (newRadius < arc.precision) {\n return new DegenerateSegment(offsetStartPoint, offsetEndPoint);\n }\n\n return new Arc(offsetStartPoint, offsetEndPoint, arc.center, arc.clockwise);\n}\n","import { Vector } from \"../definitions.js\";\nimport { Line } from \"../models/segments/Line.js\";\nimport { tangentArc } from \"../models/segments/Arc.js\";\nimport type { Segment } from \"../models/segments/Segment.js\";\nimport {\n add,\n crossProduct,\n perpendicular,\n perpendicularClockwise,\n scalarMultiply,\n} from \"../vectorOperations\";\nimport { findIntersections } from \"./intersections\";\nimport { DegenerateSegment, offsetSegment } from \"./offsets/offsetSegment.js\";\nimport { exportJSON } from \"../main.js\";\n\nfunction removeCorner(\n firstSegment: Segment,\n secondSegment: Segment,\n radius: number,\n) {\n const sinAngle = crossProduct(\n firstSegment.tangentAtLastPoint,\n secondSegment.tangentAtFirstPoint,\n );\n\n // This cover the case when the segments are colinear\n if (Math.abs(sinAngle) < 1e-10) return null;\n\n const orientationCorrection = sinAngle > 0 ? 1 : -1;\n const offset = Math.abs(radius) * orientationCorrection;\n\n const firstOffset = offsetSegment(firstSegment, offset);\n const secondOffset = offsetSegment(secondSegment, offset);\n\n if (\n firstOffset instanceof DegenerateSegment ||\n secondOffset instanceof DegenerateSegment\n ) {\n return null;\n }\n\n let potentialCenter: Vector | undefined;\n try {\n const intersections = findIntersections(firstOffset, secondOffset, 1e-9);\n\n // We need to work on the case where there are more than one intersections\n potentialCenter = intersections.at(-1);\n } catch (e) {\n return null;\n }\n\n if (!potentialCenter) {\n return null;\n }\n const center = potentialCenter;\n\n const splitForFillet = (segment: Segment, offsetSegment: Segment) => {\n const tgt = offsetSegment.tangentAt(center);\n const normal = perpendicularClockwise(tgt);\n const splitPoint = add(center, scalarMultiply(normal, offset));\n return segment.splitAt(splitPoint);\n };\n\n const [first] = splitForFillet(firstSegment, firstOffset);\n const [, second] = splitForFillet(secondSegment, secondOffset);\n\n return { first, second, center };\n}\n\nexport function filletSegments(\n firstSegment: Segment,\n secondSegment: Segment,\n radius: number,\n) {\n const cornerRemoved = removeCorner(firstSegment, secondSegment, radius);\n if (!cornerRemoved) {\n console.warn(\n \"Cannot fillet between segments\",\n firstSegment.repr,\n secondSegment.repr,\n );\n return [firstSegment, secondSegment];\n }\n\n const { first, second } = cornerRemoved;\n\n return [\n first,\n tangentArc(first.lastPoint, second.firstPoint, first.tangentAtLastPoint),\n second,\n ];\n}\n\nexport function chamferSegments(\n firstSegment: Segment,\n secondSegment: Segment,\n radius: number,\n) {\n const cornerRemoved = removeCorner(firstSegment, secondSegment, radius);\n if (!cornerRemoved) {\n console.warn(\n \"Cannot chamfer between segments\",\n firstSegment.repr,\n secondSegment.repr,\n );\n return [firstSegment, secondSegment];\n }\n\n const { first, second } = cornerRemoved;\n\n return [first, new Line(first.lastPoint, second.firstPoint), second];\n}\n","import {\n chamferSegments,\n filletSegments,\n} from \"./algorithms/filletSegments.js\";\nimport { Vector } from \"./definitions.js\";\nimport { Strand } from \"./models/Strand.js\";\nimport { Diagram } from \"./models/Diagram.js\";\nimport { Figure } from \"./models/Figure.js\";\nimport { Loop } from \"./models/Loop.js\";\nimport { tangentArc, threePointsArc } from \"./models/segments/Arc.js\";\nimport { Line } from \"./models/segments/Line.js\";\nimport { Segment } from \"./models/segments/Segment.js\";\nimport { TransformationMatrix } from \"./models/TransformationMatrix.js\";\nimport {\n polarToCartesian,\n DEG2RAD,\n subtract,\n sameVector,\n perpendicular,\n add,\n scalarMultiply,\n distance,\n cartesianToPolar,\n RAD2DEG,\n normalize,\n} from \"./vectorOperations.js\";\nimport { svgEllipse } from \"./models/segments/EllipseArc.js\";\nimport { QuadraticBezier } from \"./models/segments/QuadraticBezier.js\";\nimport { CubicBezier } from \"./models/segments/CubicBezier.js\";\n\nconst parseSmoothCurveConfig = (\n config?:\n | number\n | Vector\n | {\n endTangent?: number | Vector;\n startTangent?: number | Vector;\n startFactor?: number;\n endFactor?: number;\n },\n) => {\n let conf: {\n endTangent: number | Vector;\n startFactor?: number;\n endFactor?: number;\n startTangent?: number | Vector;\n };\n\n if (!config) conf = { endTangent: [1, 0] };\n else if (\n typeof config === \"number\" ||\n (Array.isArray(config) && config.length === 2)\n ) {\n conf = { endTangent: config };\n } else {\n conf = { endTangent: 0, ...config };\n }\n const {\n endTangent: endTgt,\n startFactor = 1,\n endFactor = 1,\n startTangent: startTgt,\n } = conf;\n\n let endTangent: Vector;\n if (typeof endTgt === \"number\") {\n endTangent = polarToCartesian(1, endTgt * DEG2RAD);\n } else {\n endTangent = endTgt;\n }\n\n let startTangent: Vector | undefined;\n if (typeof startTgt === \"number\") {\n startTangent = polarToCartesian(1, startTgt * DEG2RAD);\n } else {\n startTangent = startTgt;\n }\n\n return { endTangent, startFactor, endFactor, startTangent };\n};\n\nfunction loopySegmentsToDiagram(\n segments: Segment[],\n { ignoreChecks = false } = {},\n) {\n // Here we will need to do our best to fix cases where the drawing is\n // broken in some way (i.e. self-intersecting loops)\n\n return new Diagram([new Figure(new Loop([...segments], { ignoreChecks }))]);\n}\n\nexport class DrawingPen {\n pointer: Vector;\n protected firstPoint: Vector;\n protected pendingSegments: Segment[];\n\n protected _nextCorner: { radius: number; mode: \"fillet\" | \"chamfer\" } | null;\n\n constructor(origin: Vector = [0, 0]) {\n this.pointer = origin;\n this.firstPoint = origin;\n\n this.pendingSegments = [];\n this._nextCorner = null;\n }\n\n movePointerTo(point: Vector): this {\n if (this.pendingSegments.length)\n throw new Error(\n \"You can only move the pointer if there is no segment defined\",\n );\n\n this.pointer = point;\n this.firstPoint = point;\n return this;\n }\n\n protected saveSegment(segment: Segment) {\n if (sameVector(segment.firstPoint, segment.lastPoint)) {\n throw new Error(`Segment has no length, ${segment.repr}`);\n }\n\n if (!this._nextCorner) {\n this.pendingSegments.push(segment);\n return this;\n }\n\n const previousSegment = this.pendingSegments.pop();\n if (!previousSegment) throw new Error(\"bug in the custom corner algorithm\");\n\n const makeCorner =\n this._nextCorner.mode === \"chamfer\" ? chamferSegments : filletSegments;\n\n this.pendingSegments.push(\n ...makeCorner(previousSegment, segment, this._nextCorner.radius),\n );\n this._nextCorner = null;\n return this;\n }\n\n lineTo(point: Vector): this {\n const segment = new Line(this.pointer, point);\n this.pointer = point;\n return this.saveSegment(segment);\n }\n\n line(xDist: number, yDist: number): this {\n return this.lineTo([this.pointer[0] + xDist, this.pointer[1] + yDist]);\n }\n\n vLine(distance: number): this {\n return this.line(0, distance);\n }\n\n hLine(distance: number): this {\n return this.line(distance, 0);\n }\n\n vLineTo(yPos: number): this {\n return this.lineTo([this.pointer[0], yPos]);\n }\n\n hLineTo(xPos: number): this {\n return this.lineTo([xPos, this.pointer[1]]);\n }\n\n polarLineTo([r, theta]: Vector): this {\n const angleInRads = theta * DEG2RAD;\n const point = polarToCartesian(r, angleInRads);\n return this.lineTo(point);\n }\n\n polarLine(distance: number, angle: number): this {\n const angleInRads = angle * DEG2RAD;\n const [x, y] = polarToCartesian(distance, angleInRads);\n return this.line(x, y);\n }\n\n tangentLine(distance: number): this {\n const previousCurve = this.pendingSegments.at(-1);\n\n if (!previousCurve)\n throw new Error(\"You need a previous segment to sketch a tangent line\");\n\n const [xDir, yDir] = previousCurve.tangentAtLastPoint;\n return this.line(xDir * distance, yDir * distance);\n }\n\n threePointsArcTo(end: Vector, midPoint: Vector): this {\n this.saveSegment(threePointsArc(this.pointer, midPoint, end));\n this.pointer = end;\n return this;\n }\n\n threePointsArc(\n xDist: number,\n yDist: number,\n viaXDist: number,\n viaYDist: number,\n ): this {\n const [x0, y0] = this.pointer;\n return this.threePointsArcTo(\n [x0 + xDist, y0 + yDist],\n [x0 + viaXDist, y0 + viaYDist],\n );\n }\n\n sagittaArcTo(end: Vector, sagitta: number): this {\n if (!sagitta) return this.lineTo(end);\n const chord = new Line(this.pointer, end);\n const norm = perpendicular(chord.tangentAtFirstPoint);\n\n const sagPoint: Vector = add(chord.midPoint, scalarMultiply(norm, sagitta));\n\n return this.threePointsArcTo(end, sagPoint);\n }\n\n sagittaArc(xDist: number, yDist: number, sagitta: number): this {\n return this.sagittaArcTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n sagitta,\n );\n }\n\n vSagittaArc(distance: number, sagitta: number): this {\n return this.sagittaArc(0, distance, sagitta);\n }\n\n hSagittaArc(distance: number, sagitta: number): this {\n return this.sagittaArc(distance, 0, sagitta);\n }\n\n bulgeArcTo(end: Vector, bulge: number): this {\n if (!bulge) return this.lineTo(end);\n const halfChord = distance(this.pointer, end) / 2;\n const bulgeAsSagitta = -bulge * halfChord;\n\n return this.sagittaArcTo(end, bulgeAsSagitta);\n }\n\n bulgeArc(xDist: number, yDist: number, bulge: number): this {\n return this.bulgeArcTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n bulge,\n );\n }\n\n vBulgeArc(distance: number, bulge: number): this {\n return this.bulgeArc(0, distance, bulge);\n }\n\n hBulgeArc(distance: number, bulge: number): this {\n return this.bulgeArc(distance, 0, bulge);\n }\n\n tangentArcTo(end: Vector, tangentAtStart?: Vector): this {\n const previousCurve = this.pendingSegments.at(-1);\n\n if (!previousCurve)\n throw new Error(\"You need a previous curve to sketch a tangent arc\");\n\n this.saveSegment(\n tangentArc(\n this.pointer,\n end,\n tangentAtStart ?? previousCurve.tangentAtLastPoint,\n ),\n );\n\n this.pointer = end;\n return this;\n }\n\n tangentArc(xDist: number, yDist: number, tangentAtStart?: Vector): this {\n const [x0, y0] = this.pointer;\n return this.tangentArcTo([xDist + x0, yDist + y0], tangentAtStart);\n }\n\n ellipseTo(\n end: Vector,\n r0: number,\n r1: number,\n xAxisRotation: number,\n longArc: boolean,\n sweepFlag: boolean,\n ): this {\n this.saveSegment(\n svgEllipse(this.pointer, end, r0, r1, xAxisRotation, longArc, sweepFlag),\n );\n this.pointer = end;\n return this;\n }\n\n ellipse(\n xDist: number,\n yDist: number,\n r0: number,\n r1: number,\n xAxisRotation: number,\n longArc: boolean,\n sweepFlag: boolean,\n ): this {\n return this.ellipseTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n r0,\n r1,\n xAxisRotation,\n longArc,\n sweepFlag,\n );\n }\n\n halfEllipseTo(end: Vector, sagitta: number): this {\n const [distance, angle] = cartesianToPolar(subtract(end, this.pointer));\n\n return this.ellipseTo(\n end,\n distance / 2,\n Math.abs(sagitta),\n angle * RAD2DEG,\n true,\n sagitta > 0,\n );\n }\n\n halfEllipse(xDist: number, yDist: number, sagitta: number): this {\n return this.halfEllipseTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n sagitta,\n );\n }\n\n cubicBezierCurveTo(\n end: Vector,\n startControlPoint: Vector,\n endControlPoint: Vector,\n ): this {\n this.saveSegment(\n new CubicBezier(this.pointer, end, startControlPoint, endControlPoint),\n );\n this.pointer = end;\n return this;\n }\n\n quadraticBezierCurveTo(end: Vector, controlPoint: Vector): this {\n this.saveSegment(new QuadraticBezier(this.pointer, end, controlPoint));\n this.pointer = end;\n return this;\n }\n\n smoothCurveTo(\n end: Vector,\n config?:\n | number\n | Vector\n | {\n endTangent?: number | Vector;\n startTangent?: number | Vector;\n startFactor?: number;\n endFactor?: number;\n },\n ): this {\n const { endTangent, startTangent, startFactor, endFactor } =\n parseSmoothCurveConfig(config);\n\n const previousCurve = this.pendingSegments.length\n ? this.pendingSegments[this.pendingSegments.length - 1]\n : null;\n\n const defaultDistance = distance(this.pointer, end) / 3;\n\n let startPoleDirection: Vector;\n if (startTangent) {\n startPoleDirection = startTangent;\n } else if (!previousCurve) {\n startPoleDirection = [1, 0];\n } else {\n startPoleDirection = previousCurve.tangentAtLastPoint;\n }\n\n startPoleDirection = normalize(startPoleDirection);\n const startControl: Vector = [\n this.pointer[0] + startPoleDirection[0] * startFactor * defaultDistance,\n this.pointer[1] + startPoleDirection[1] * startFactor * defaultDistance,\n ];\n\n let endPoleDirection = endTangent;\n\n endPoleDirection = normalize(endPoleDirection);\n const endControl: Vector = [\n end[0] - endPoleDirection[0] * endFactor * defaultDistance,\n end[1] - endPoleDirection[1] * endFactor * defaultDistance,\n ];\n\n return this.cubicBezierCurveTo(end, startControl, endControl);\n }\n\n smoothCurve(\n xDist: number,\n yDist: number,\n config?:\n | number\n | Vector\n | {\n endTangent?: number | Vector;\n startTangent?: number | Vector;\n startFactor?: number;\n endFactor?: number;\n },\n ) {\n return this.smoothCurveTo(\n [xDist + this.pointer[0], yDist + this.pointer[1]],\n config,\n );\n }\n\n customCorner(radius: number, mode: \"fillet\" | \"chamfer\" = \"fillet\") {\n if (!this.pendingSegments.length)\n throw new Error(\"You need a segment defined to fillet the angle\");\n\n if (!radius) return this;\n\n this._nextCorner = { mode, radius };\n return this;\n }\n\n protected _customCornerLastWithFirst(\n radius: number,\n mode: \"fillet\" | \"chamfer\" = \"fillet\",\n ) {\n if (!radius) return;\n\n const lastSegment = this.pendingSegments.pop();\n const firstSegment = this.pendingSegments.shift();\n\n if (!lastSegment || !firstSegment)\n throw new Error(\"Not enough curves to close and fillet\");\n\n const makeCorner = mode === \"chamfer\" ? chamferSegments : filletSegments;\n\n this.pendingSegments.push(...makeCorner(lastSegment, firstSegment, radius));\n }\n\n close(ignoreChecks = false): Diagram {\n if (!this.pendingSegments.length) throw new Error(\"No segments to close\");\n const firstSegment = this.pendingSegments[0];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSegment = this.pendingSegments.at(-1)!;\n\n if (!sameVector(firstSegment.firstPoint, lastSegment.lastPoint)) {\n this.lineTo(firstSegment.firstPoint);\n }\n\n if (this._nextCorner !== null) {\n this._customCornerLastWithFirst(\n this._nextCorner.radius,\n this._nextCorner.mode,\n );\n this._nextCorner = null;\n }\n\n return loopySegmentsToDiagram(this.pendingSegments, { ignoreChecks });\n }\n\n closeWithMirror(ignoreChecks = false): Diagram {\n if (!this.pendingSegments.length) throw new Error(\"No segments to close\");\n\n const firstSegment = this.pendingSegments[0];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSegment = this.pendingSegments.at(-1)!;\n\n const mirrorVector = subtract(\n lastSegment.lastPoint,\n firstSegment.firstPoint,\n );\n const mirrorTranform = new TransformationMatrix().mirrorLine(\n mirrorVector,\n firstSegment.firstPoint,\n );\n\n const mirroredSegments = this.pendingSegments.map((segment) =>\n segment.transform(mirrorTranform).reverse(),\n );\n mirroredSegments.reverse();\n\n return loopySegmentsToDiagram(\n [...this.pendingSegments, ...mirroredSegments],\n { ignoreChecks },\n );\n }\n\n asStrand(): Strand {\n return new Strand([...this.pendingSegments]);\n }\n\n get isClosed(): boolean {\n return sameVector(this.pointer, this.pendingSegments[0]?.firstPoint);\n }\n}\n\nexport function draw(origin: Vector = [0, 0]): DrawingPen {\n return new DrawingPen(origin);\n}\n"],"names":["DegenerateSegment","firstPoint","lastPoint","offsetSegment","segment","offset","Line","offsetLine","Arc","offsetArc","line","normal","add","scalarMultiply","arc","offsetStartPoint","perpendicular","offsetEndPoint","orientedOffset","removeCorner","firstSegment","secondSegment","radius","sinAngle","crossProduct","orientationCorrection","firstOffset","secondOffset","potentialCenter","findIntersections","center","splitForFillet","tgt","perpendicularClockwise","splitPoint","first","second","filletSegments","cornerRemoved","tangentArc","chamferSegments","parseSmoothCurveConfig","config","conf","endTgt","startFactor","endFactor","startTgt","endTangent","polarToCartesian","DEG2RAD","startTangent","loopySegmentsToDiagram","segments","ignoreChecks","Diagram","Figure","Loop","DrawingPen","origin","__publicField","point","sameVector","previousSegment","makeCorner","xDist","yDist","distance","yPos","xPos","r","theta","angleInRads","angle","x","y","previousCurve","xDir","yDir","end","midPoint","threePointsArc","viaXDist","viaYDist","x0","y0","sagitta","chord","norm","sagPoint","bulge","halfChord","bulgeAsSagitta","tangentAtStart","r0","r1","xAxisRotation","longArc","sweepFlag","svgEllipse","cartesianToPolar","subtract","RAD2DEG","startControlPoint","endControlPoint","CubicBezier","controlPoint","QuadraticBezier","defaultDistance","startPoleDirection","normalize","startControl","endPoleDirection","endControl","mode","lastSegment","mirrorVector","mirrorTranform","TransformationMatrix","mirroredSegments","Strand","_a","draw"],"mappings":";;;;;AA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IAAIC,EAAA,EAAuB;AAAA,MAChDF;AAAA,MACAhG,EAAa;AAAA,IAAA,GAGTmG,IAAmB,KAAK,gBAAgB;AAAA,MAAI,CAACnH,MACjDA,EAAQ,UAAUiH,CAAc,EAAE,QAAQ;AAAA,IAAA;AAE5C,WAAAE,EAAiB,QAAQ,GAElBnE;AAAA,MACL,CAAC,GAAG,KAAK,iBAAiB,GAAGmE,CAAgB;AAAA,MAC7C,EAAE,cAAAjE,EAAa;AAAA,IAAA;AAAA,EAEnB;AAAA,EAEA,WAAmB;AACjB,WAAO,IAAIkE,EAAO,CAAC,GAAG,KAAK,eAAe,CAAC;AAAA,EAC7C;AAAA,EAEA,IAAI,WAAoB;;AACtB,WAAO1D,EAAW,KAAK,UAAS2D,IAAA,KAAK,gBAAgB,CAAC,MAAtB,gBAAAA,EAAyB,UAAU;AAAA,EACrE;AACF;AAEO,SAASC,GAAK/D,IAAiB,CAAC,GAAG,CAAC,GAAe;AACjD,SAAA,IAAID,GAAWC,CAAM;AAC9B;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { svgDiagram } from "./svgDiagram.js";
|
|
2
|
+
export { svgFigure } from "./svgFigure.js";
|
|
3
|
+
export { svgLoop } from "./svgLoop.js";
|
|
4
|
+
export { svgSegmentToPath } from "./svgSegment.js";
|
|
5
|
+
export { svgStrand } from "./svgStrand.js";
|
|
6
|
+
export { svgViewbox } from "./wrapSVG.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BoundingBox } from "../../models/BoundingBox.js";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function svgViewbox(bbox: BoundingBox, margin?: number): string;
|
|
3
3
|
export type SVGUnit = "mm" | "cm" | "in" | "pc" | "px" | "pt";
|
|
4
4
|
export declare function wrapSVG(body: string, boundingBox: BoundingBox, margin: number | undefined, unit: null | SVGUnit): string;
|
|
@@ -9,5 +9,7 @@ export { Line } from "./segments/Line.js";
|
|
|
9
9
|
export { Arc } from "./segments/Arc.js";
|
|
10
10
|
export { EllipseArc } from "./segments/EllipseArc.js";
|
|
11
11
|
export { CubicBezier } from "./segments/CubicBezier.js";
|
|
12
|
+
export { QuadraticBezier } from "./segments/QuadraticBezier.js";
|
|
12
13
|
export type { Segment } from "./segments/Segment.js";
|
|
14
|
+
export { isSegment } from "./segments/utils/isSegment.js";
|
|
13
15
|
export { Transformable } from "./utils/Transformable.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../draw-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../draw-27ac6dae.cjs");require("../QuadraticBezier-e3d7218b.cjs");require("../Diagram-57e17509.cjs");function R(n){return f.draw([-n,0]).sagittaArc(2*n,0,n).sagittaArc(-2*n,0,n).close()}function p(n,c,a=0){const{rx:u=0,ry:m=0}=typeof a=="number"?{ry:a,rx:a}:a;let e=Math.min(u??a??0,n/2),r=Math.min(m??a??0,c/2);const l=e&&r;l||(e=0,r=0);const y=e===r,t=f.draw([Math.min(0,-(n/2-e)),-c/2]),i=(o,s)=>{l&&(y?t.tangentArc(o,s):t.ellipse(o,s,e,r,0,!1,!1))};return e<n/2&&t.hLine(n-2*e),i(e,r),r<c/2&&t.vLine(c-2*r),i(-e,r),e<n/2&&t.hLine(-(n-2*e)),i(-e,-r),r<c/2&&t.vLine(-(c-2*r)),i(e,-r),t.close()}exports.drawCircle=R;exports.drawRect=p;
|
|
2
2
|
//# sourceMappingURL=drawShape.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawShape.cjs","sources":["../../src/drawShape/drawCircle.ts","../../src/drawShape/drawRect.ts"],"sourcesContent":["import { draw } from \"../draw.js\";\nimport type { Diagram } from \"../models/Diagram.js\";\n\nexport function drawCircle(radius: number): Diagram {\n return draw([-radius, 0])\n .sagittaArc(2 * radius, 0, radius)\n .sagittaArc(-2 * radius, 0, radius)\n .close();\n}\n","import { draw } from \"../draw.js\";\nimport type { Diagram } from \"../models/Diagram.js\";\n\nexport function drawRect(\n width: number,\n height: number,\n r: number | { rx?: number; ry?: number } = 0
|
|
1
|
+
{"version":3,"file":"drawShape.cjs","sources":["../../src/drawShape/drawCircle.ts","../../src/drawShape/drawRect.ts"],"sourcesContent":["import { draw } from \"../draw.js\";\nimport type { Diagram } from \"../models/Diagram.js\";\n\nexport function drawCircle(radius: number): Diagram {\n return draw([-radius, 0])\n .sagittaArc(2 * radius, 0, radius)\n .sagittaArc(-2 * radius, 0, radius)\n .close();\n}\n","import { draw } from \"../draw.js\";\nimport type { Diagram } from \"../models/Diagram.js\";\n\nexport function drawRect(\n width: number,\n height: number,\n r: number | { rx?: number; ry?: number } = 0,\n): Diagram {\n const { rx: inputRx = 0, ry: inputRy = 0 } =\n typeof r === \"number\" ? { ry: r, rx: r } : r;\n let rx = Math.min(inputRx ?? r ?? 0, width / 2);\n let ry = Math.min(inputRy ?? r ?? 0, height / 2);\n\n const withRadius = rx && ry;\n if (!withRadius) {\n rx = 0;\n ry = 0;\n }\n const symmetricRadius = rx === ry;\n\n const sk = draw([Math.min(0, -(width / 2 - rx)), -height / 2]);\n\n const addFillet = (xDist: number, yDist: number) => {\n if (withRadius) {\n if (symmetricRadius) sk.tangentArc(xDist, yDist);\n else {\n sk.ellipse(xDist, yDist, rx, ry, 0, false, false);\n }\n }\n };\n\n if (rx < width / 2) {\n sk.hLine(width - 2 * rx);\n }\n addFillet(rx, ry);\n if (ry < height / 2) {\n sk.vLine(height - 2 * ry);\n }\n addFillet(-rx, ry);\n if (rx < width / 2) {\n sk.hLine(-(width - 2 * rx));\n }\n addFillet(-rx, -ry);\n if (ry < height / 2) {\n sk.vLine(-(height - 2 * ry));\n }\n addFillet(rx, -ry);\n return sk.close();\n}\n"],"names":["drawCircle","radius","draw","drawRect","width","height","r","inputRx","inputRy","rx","ry","withRadius","symmetricRadius","sk","addFillet","xDist","yDist"],"mappings":"sMAGO,S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