pantograph2d 0.3.1 → 0.4.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/{exportJSON-26bb92ef.js → Diagram-1c56996e.js} +544 -515
- package/dist/Diagram-1c56996e.js.map +1 -0
- package/dist/Diagram-4fa55d2b.cjs +4 -0
- package/dist/Diagram-4fa55d2b.cjs.map +1 -0
- package/dist/draw-44dd36a9.js +256 -0
- package/dist/draw-44dd36a9.js.map +1 -0
- package/dist/draw-8c69c65f.cjs +2 -0
- package/dist/draw-8c69c65f.cjs.map +1 -0
- package/dist/drawShape.d.ts +153 -0
- package/dist/models.d.ts +7 -1
- package/dist/pantograph/drawShape.cjs +2 -0
- package/dist/pantograph/drawShape.cjs.map +1 -0
- package/dist/pantograph/drawShape.d.ts +1 -0
- package/dist/pantograph/drawShape.js +24 -0
- package/dist/pantograph/drawShape.js.map +1 -0
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +7 -6
- package/dist/pantograph.cjs +5 -5
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +13 -2
- package/dist/pantograph.js +292 -449
- package/dist/pantograph.js.map +1 -1
- package/package.json +6 -2
- package/dist/exportJSON-26bb92ef.js.map +0 -1
- package/dist/exportJSON-3b325312.cjs +0 -4
- package/dist/exportJSON-3b325312.cjs.map +0 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { m as c, A as L, g as a, h, x as p, y as x, u as R, C as M, E as I, o as w, G as N, d as Y, e as O, T as V, S as W, D as B, F as G, L as H, H as P, I as A } from "./Diagram-1c56996e.js";
|
|
2
|
+
class m {
|
|
3
|
+
constructor(t, n) {
|
|
4
|
+
this.firstPoint = t, this.lastPoint = n;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function S(r, t) {
|
|
8
|
+
if (r instanceof c)
|
|
9
|
+
return $(r, t);
|
|
10
|
+
if (r instanceof L)
|
|
11
|
+
return j(r, t);
|
|
12
|
+
throw new Error("Not implemented");
|
|
13
|
+
}
|
|
14
|
+
function $(r, t) {
|
|
15
|
+
const { firstPoint: n, lastPoint: e } = r, i = r.normalVector;
|
|
16
|
+
return new c(
|
|
17
|
+
a(n, h(i, t)),
|
|
18
|
+
a(e, h(i, t))
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function j(r, t) {
|
|
22
|
+
const n = a(
|
|
23
|
+
r.firstPoint,
|
|
24
|
+
h(p(r.tangentAtFirstPoint), t)
|
|
25
|
+
), e = a(
|
|
26
|
+
r.lastPoint,
|
|
27
|
+
h(p(r.tangentAtLastPoint), t)
|
|
28
|
+
), i = t * (r.clockwise ? 1 : -1);
|
|
29
|
+
return r.radius + i < r.precision ? new m(n, e) : new L(n, e, r.center, r.clockwise);
|
|
30
|
+
}
|
|
31
|
+
function E(r, t, n) {
|
|
32
|
+
const e = R(
|
|
33
|
+
r.tangentAtLastPoint,
|
|
34
|
+
t.tangentAtFirstPoint
|
|
35
|
+
);
|
|
36
|
+
if (Math.abs(e) < 1e-10)
|
|
37
|
+
return null;
|
|
38
|
+
const i = e > 0 ? 1 : -1, s = Math.abs(n) * i, o = S(r, s), u = S(t, s);
|
|
39
|
+
if (o instanceof m || u instanceof m)
|
|
40
|
+
return null;
|
|
41
|
+
let l;
|
|
42
|
+
try {
|
|
43
|
+
l = M(o, u, 1e-9).at(-1);
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (!l)
|
|
48
|
+
return null;
|
|
49
|
+
const g = l, d = (f, D) => {
|
|
50
|
+
const y = D.tangentAt(g), F = I(y), k = a(g, h(F, s));
|
|
51
|
+
return f.splitAt(k);
|
|
52
|
+
}, [_] = d(r, o), [, b] = d(t, u);
|
|
53
|
+
return { first: _, second: b, center: g };
|
|
54
|
+
}
|
|
55
|
+
function T(r, t, n) {
|
|
56
|
+
const e = E(r, t, n);
|
|
57
|
+
if (!e)
|
|
58
|
+
return console.warn(
|
|
59
|
+
"Cannot fillet between segments",
|
|
60
|
+
r.repr,
|
|
61
|
+
t.repr
|
|
62
|
+
), [r, t];
|
|
63
|
+
const { first: i, second: s } = e;
|
|
64
|
+
return [
|
|
65
|
+
i,
|
|
66
|
+
x(i.lastPoint, s.firstPoint, i.tangentAtLastPoint),
|
|
67
|
+
s
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
function C(r, t, n) {
|
|
71
|
+
const e = E(r, t, n);
|
|
72
|
+
if (!e)
|
|
73
|
+
return console.warn(
|
|
74
|
+
"Cannot chamfer between segments",
|
|
75
|
+
r.repr,
|
|
76
|
+
t.repr
|
|
77
|
+
), [r, t];
|
|
78
|
+
const { first: i, second: s } = e;
|
|
79
|
+
return [i, new c(i.lastPoint, s.firstPoint), s];
|
|
80
|
+
}
|
|
81
|
+
function v(r) {
|
|
82
|
+
return new B([new G(new H([...r]))]);
|
|
83
|
+
}
|
|
84
|
+
class q {
|
|
85
|
+
constructor(t = [0, 0]) {
|
|
86
|
+
this.pointer = t, this.firstPoint = t, this.pendingSegments = [], this._nextCorner = null;
|
|
87
|
+
}
|
|
88
|
+
movePointerTo(t) {
|
|
89
|
+
if (this.pendingSegments.length)
|
|
90
|
+
throw new Error(
|
|
91
|
+
"You can only move the pointer if there is no segment defined"
|
|
92
|
+
);
|
|
93
|
+
return this.pointer = t, this.firstPoint = t, this;
|
|
94
|
+
}
|
|
95
|
+
saveSegment(t) {
|
|
96
|
+
if (w(t.firstPoint, t.lastPoint))
|
|
97
|
+
throw new Error(`Segment has no length, ${t.repr}`);
|
|
98
|
+
if (!this._nextCorner)
|
|
99
|
+
return this.pendingSegments.push(t), this;
|
|
100
|
+
const n = this.pendingSegments.pop();
|
|
101
|
+
if (!n)
|
|
102
|
+
throw new Error("bug in the custom corner algorithm");
|
|
103
|
+
const e = this._nextCorner.mode === "chamfer" ? C : T;
|
|
104
|
+
return this.pendingSegments.push(
|
|
105
|
+
...e(n, t, this._nextCorner.radius)
|
|
106
|
+
), this._nextCorner = null, this;
|
|
107
|
+
}
|
|
108
|
+
lineTo(t) {
|
|
109
|
+
const n = new c(this.pointer, t);
|
|
110
|
+
return this.pointer = t, this.saveSegment(n);
|
|
111
|
+
}
|
|
112
|
+
line(t, n) {
|
|
113
|
+
return this.lineTo([this.pointer[0] + t, this.pointer[1] + n]);
|
|
114
|
+
}
|
|
115
|
+
vLine(t) {
|
|
116
|
+
return this.line(0, t);
|
|
117
|
+
}
|
|
118
|
+
hLine(t) {
|
|
119
|
+
return this.line(t, 0);
|
|
120
|
+
}
|
|
121
|
+
vLineTo(t) {
|
|
122
|
+
return this.lineTo([this.pointer[0], t]);
|
|
123
|
+
}
|
|
124
|
+
hLineTo(t) {
|
|
125
|
+
return this.lineTo([t, this.pointer[1]]);
|
|
126
|
+
}
|
|
127
|
+
polarLineTo([t, n]) {
|
|
128
|
+
const e = n * A, i = P(t, e);
|
|
129
|
+
return this.lineTo(i);
|
|
130
|
+
}
|
|
131
|
+
polarLine(t, n) {
|
|
132
|
+
const e = n * A, [i, s] = P(t, e);
|
|
133
|
+
return this.line(i, s);
|
|
134
|
+
}
|
|
135
|
+
tangentLine(t) {
|
|
136
|
+
const n = this.pendingSegments.at(-1);
|
|
137
|
+
if (!n)
|
|
138
|
+
throw new Error("You need a previous segment to sketch a tangent line");
|
|
139
|
+
const [e, i] = n.tangentAtLastPoint;
|
|
140
|
+
return this.line(e * t, i * t);
|
|
141
|
+
}
|
|
142
|
+
threePointsArcTo(t, n) {
|
|
143
|
+
return this.saveSegment(N(this.pointer, n, t)), this.pointer = t, this;
|
|
144
|
+
}
|
|
145
|
+
threePointsArc(t, n, e, i) {
|
|
146
|
+
const [s, o] = this.pointer;
|
|
147
|
+
return this.threePointsArcTo(
|
|
148
|
+
[s + t, o + n],
|
|
149
|
+
[s + e, o + i]
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
sagittaArcTo(t, n) {
|
|
153
|
+
if (!n)
|
|
154
|
+
return this.lineTo(t);
|
|
155
|
+
const e = new c(this.pointer, t), i = p(e.tangentAtFirstPoint), s = a(e.midPoint, h(i, n));
|
|
156
|
+
return this.threePointsArcTo(t, s);
|
|
157
|
+
}
|
|
158
|
+
sagittaArc(t, n, e) {
|
|
159
|
+
return this.sagittaArcTo(
|
|
160
|
+
[t + this.pointer[0], n + this.pointer[1]],
|
|
161
|
+
e
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
vSagittaArc(t, n) {
|
|
165
|
+
return this.sagittaArc(0, t, n);
|
|
166
|
+
}
|
|
167
|
+
hSagittaArc(t, n) {
|
|
168
|
+
return this.sagittaArc(t, 0, n);
|
|
169
|
+
}
|
|
170
|
+
bulgeArcTo(t, n) {
|
|
171
|
+
if (!n)
|
|
172
|
+
return this.lineTo(t);
|
|
173
|
+
const e = Y(this.pointer, t) / 2, i = -n * e;
|
|
174
|
+
return this.sagittaArcTo(t, i);
|
|
175
|
+
}
|
|
176
|
+
bulgeArc(t, n, e) {
|
|
177
|
+
return this.bulgeArcTo(
|
|
178
|
+
[t + this.pointer[0], n + this.pointer[1]],
|
|
179
|
+
e
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
vBulgeArc(t, n) {
|
|
183
|
+
return this.bulgeArc(0, t, n);
|
|
184
|
+
}
|
|
185
|
+
hBulgeArc(t, n) {
|
|
186
|
+
return this.bulgeArc(t, 0, n);
|
|
187
|
+
}
|
|
188
|
+
tangentArcTo(t, n) {
|
|
189
|
+
const e = this.pendingSegments.at(-1);
|
|
190
|
+
if (!e)
|
|
191
|
+
throw new Error("You need a previous curve to sketch a tangent arc");
|
|
192
|
+
return this.saveSegment(
|
|
193
|
+
x(
|
|
194
|
+
this.pointer,
|
|
195
|
+
t,
|
|
196
|
+
n ?? e.tangentAtLastPoint
|
|
197
|
+
)
|
|
198
|
+
), this.pointer = t, this;
|
|
199
|
+
}
|
|
200
|
+
tangentArc(t, n, e) {
|
|
201
|
+
const [i, s] = this.pointer;
|
|
202
|
+
return this.tangentArcTo([t + i, n + s], e);
|
|
203
|
+
}
|
|
204
|
+
customCorner(t, n = "fillet") {
|
|
205
|
+
if (!this.pendingSegments.length)
|
|
206
|
+
throw new Error("You need a segment defined to fillet the angle");
|
|
207
|
+
return t ? (this._nextCorner = { mode: n, radius: t }, this) : this;
|
|
208
|
+
}
|
|
209
|
+
_customCornerLastWithFirst(t, n = "fillet") {
|
|
210
|
+
if (!t)
|
|
211
|
+
return;
|
|
212
|
+
const e = this.pendingSegments.pop(), i = this.pendingSegments.shift();
|
|
213
|
+
if (!e || !i)
|
|
214
|
+
throw new Error("Not enough curves to close and fillet");
|
|
215
|
+
const s = n === "chamfer" ? C : T;
|
|
216
|
+
this.pendingSegments.push(...s(e, i, t));
|
|
217
|
+
}
|
|
218
|
+
close() {
|
|
219
|
+
if (!this.pendingSegments.length)
|
|
220
|
+
throw new Error("No segments to close");
|
|
221
|
+
const t = this.pendingSegments[0], n = this.pendingSegments.at(-1);
|
|
222
|
+
return w(t.firstPoint, n.lastPoint) || this.lineTo(t.firstPoint), this._nextCorner !== null && (this._customCornerLastWithFirst(
|
|
223
|
+
this._nextCorner.radius,
|
|
224
|
+
this._nextCorner.mode
|
|
225
|
+
), this._nextCorner = null), v(this.pendingSegments);
|
|
226
|
+
}
|
|
227
|
+
closeWithMirror() {
|
|
228
|
+
if (!this.pendingSegments.length)
|
|
229
|
+
throw new Error("No segments to close");
|
|
230
|
+
const t = this.pendingSegments[0], n = this.pendingSegments.at(-1), e = O(
|
|
231
|
+
n.lastPoint,
|
|
232
|
+
t.firstPoint
|
|
233
|
+
), i = new V().mirrorLine(
|
|
234
|
+
e,
|
|
235
|
+
t.firstPoint
|
|
236
|
+
), s = this.pendingSegments.map(
|
|
237
|
+
(o) => o.transform(i).reverse()
|
|
238
|
+
);
|
|
239
|
+
return s.reverse(), v([
|
|
240
|
+
...this.pendingSegments,
|
|
241
|
+
...s
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
244
|
+
asStrand() {
|
|
245
|
+
return new W([...this.pendingSegments]);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function J(r = [0, 0]) {
|
|
249
|
+
return new q(r);
|
|
250
|
+
}
|
|
251
|
+
export {
|
|
252
|
+
m as D,
|
|
253
|
+
J as d,
|
|
254
|
+
S as o
|
|
255
|
+
};
|
|
256
|
+
//# sourceMappingURL=draw-44dd36a9.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw-44dd36a9.js","sources":["../src/algorithms/offsets/offsetSegment.ts","../src/algorithms/filletSegments.ts","../src/draw.ts"],"sourcesContent":["import { Line } from \"../../models/segments/Line\";\nimport { Arc } from \"../../models/segments/Arc\";\nimport { Segment } from \"../../models/segments/Segment\";\nimport {\n add,\n normalize,\n perpendicular,\n scalarMultiply,\n subtract,\n} from \"../../vectorOperations\";\nimport { Vector } from \"../../definitions\";\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\";\nimport { Line } from \"../models/segments/Line\";\nimport { tangentArc } from \"../models/segments/Arc\";\nimport type { Segment } from \"../models/segments/Segment\";\nimport {\n add,\n crossProduct,\n perpendicular,\n perpendicularClockwise,\n scalarMultiply,\n} from \"../vectorOperations\";\nimport { findIntersections } from \"./intersections\";\nimport { DegenerateSegment, offsetSegment } from \"./offsets/offsetSegment\";\nimport { exportJSON } from \"../main\";\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 { chamferSegments, filletSegments } from \"./algorithms/filletSegments\";\nimport { Vector } from \"./definitions\";\nimport { Strand } from \"./models/Strand\";\nimport { Diagram } from \"./models/Diagram\";\nimport { Figure } from \"./models/Figure\";\nimport { Loop } from \"./models/Loop\";\nimport { tangentArc, threePointsArc } from \"./models/segments/Arc\";\nimport { Line } from \"./models/segments/Line\";\nimport { Segment } from \"./models/segments/Segment\";\nimport { TransformationMatrix } from \"./models/TransformationMatrix\";\nimport {\n polarToCartesian,\n DEG2RAD,\n subtract,\n sameVector,\n perpendicular,\n add,\n scalarMultiply,\n distance,\n} from \"./vectorOperations\";\n\nfunction loopySegmentsToDiagram(segments: Segment[]) {\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]))]);\n}\n\nexport class DrawingPen {\n protected 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 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(): 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);\n }\n\n closeWithMirror(): 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,\n ...mirroredSegments,\n ]);\n }\n\n asStrand(): Strand {\n return new Strand([...this.pendingSegments]);\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","loopySegmentsToDiagram","segments","Diagram","Figure","Loop","DrawingPen","origin","point","sameVector","previousSegment","makeCorner","xDist","yDist","distance","yPos","xPos","r","theta","angleInRads","DEG2RAD","polarToCartesian","angle","x","y","previousCurve","xDir","yDir","end","midPoint","threePointsArc","viaXDist","viaYDist","x0","y0","sagitta","chord","norm","sagPoint","bulge","halfChord","bulgeAsSagitta","tangentAtStart","mode","lastSegment","mirrorVector","subtract","mirrorTranform","TransformationMatrix","mirroredSegments","Strand","draw"],"mappings":";AAYO,MAAMA,EAAkB;AAAA,EAC7B,YACkBC,GACAC,GAChB;AAFgB,SAAA,aAAAD,GACA,KAAA,YAAAC;AAAA,EACf;AACL;AAEgB,SAAAC,EACdC,GACAC,GAC6B;AAC7B,MAAID,aAAmBE;AACd,WAAAC,EAAWH,GAASC,CAAM;AAGnC,MAAID,aAAmBI;AACd,WAAAC,EAAUL,GAASC,CAAM;AAG5B,QAAA,IAAI,MAAM,iBAAiB;AACnC;AAEgB,SAAAE,EAAWG,GAAYL,GAAsB;AACrD,QAAA,EAAE,YAAAJ,GAAY,WAAAC,EAAc,IAAAQ,GAE5BC,IAASD,EAAK;AACpB,SAAO,IAAIJ;AAAA,IACTM,EAAIX,GAAYY,EAAeF,GAAQN,CAAM,CAAC;AAAA,IAC9CO,EAAIV,GAAWW,EAAeF,GAAQN,CAAM,CAAC;AAAA,EAAA;AAEjD;AAEgB,SAAAI,EAAUK,GAAUT,GAAy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ACnBF,EAAY;AAAA,MACZhE,EAAa;AAAA,IAAA,GAETmE,IAAiB,IAAIC,EAAA,EAAuB;AAAA,MAChDH;AAAA,MACAjE,EAAa;AAAA,IAAA,GAGTqE,IAAmB,KAAK,gBAAgB;AAAA,MAAI,CAACrF,MACjDA,EAAQ,UAAUmF,CAAc,EAAE,QAAQ;AAAA,IAAA;AAE5C,WAAAE,EAAiB,QAAQ,GAElBhD,EAAuB;AAAA,MAC5B,GAAG,KAAK;AAAA,MACR,GAAGgD;AAAA,IAAA,CACJ;AAAA,EACH;AAAA,EAEA,WAAmB;AACjB,WAAO,IAAIC,EAAO,CAAC,GAAG,KAAK,eAAe,CAAC;AAAA,EAC7C;AACF;AAEO,SAASC,EAAK5C,IAAiB,CAAC,GAAG,CAAC,GAAe;AACjD,SAAA,IAAID,EAAWC,CAAM;AAC9B;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const r=require("./Diagram-4fa55d2b.cjs");class c{constructor(t,n){this.firstPoint=t,this.lastPoint=n}}function p(i,t){if(i instanceof r.Line)return x(i,t);if(i instanceof r.Arc)return y(i,t);throw new Error("Not implemented")}function x(i,t){const{firstPoint:n,lastPoint:e}=i,s=i.normalVector;return new r.Line(r.add(n,r.scalarMultiply(s,t)),r.add(e,r.scalarMultiply(s,t)))}function y(i,t){const n=r.add(i.firstPoint,r.scalarMultiply(r.perpendicular(i.tangentAtFirstPoint),t)),e=r.add(i.lastPoint,r.scalarMultiply(r.perpendicular(i.tangentAtLastPoint),t)),s=t*(i.clockwise?1:-1);return i.radius+s<i.precision?new c(n,e):new r.Arc(n,e,i.center,i.clockwise)}function A(i,t,n){const e=r.crossProduct(i.tangentAtLastPoint,t.tangentAtFirstPoint);if(Math.abs(e)<1e-10)return null;const s=e>0?1:-1,o=Math.abs(n)*s,a=p(i,o),h=p(t,o);if(a instanceof c||h instanceof c)return null;let l;try{l=r.findIntersections(a,h,1e-9).at(-1)}catch{return null}if(!l)return null;const u=l,f=(g,T)=>{const C=T.tangentAt(u),v=r.perpendicularClockwise(C),L=r.add(u,r.scalarMultiply(v,o));return g.splitAt(L)},[P]=f(i,a),[,S]=f(t,h);return{first:P,second:S,center:u}}function m(i,t,n){const e=A(i,t,n);if(!e)return console.warn("Cannot fillet between segments",i.repr,t.repr),[i,t];const{first:s,second:o}=e;return[s,r.tangentArc(s.lastPoint,o.firstPoint,s.tangentAtLastPoint),o]}function d(i,t,n){const e=A(i,t,n);if(!e)return console.warn("Cannot chamfer between segments",i.repr,t.repr),[i,t];const{first:s,second:o}=e;return[s,new r.Line(s.lastPoint,o.firstPoint),o]}function w(i){return new r.Diagram([new r.Figure(new r.Loop([...i]))])}class E{constructor(t=[0,0]){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 n=this.pendingSegments.pop();if(!n)throw new Error("bug in the custom corner algorithm");const e=this._nextCorner.mode==="chamfer"?d:m;return this.pendingSegments.push(...e(n,t,this._nextCorner.radius)),this._nextCorner=null,this}lineTo(t){const n=new r.Line(this.pointer,t);return this.pointer=t,this.saveSegment(n)}line(t,n){return this.lineTo([this.pointer[0]+t,this.pointer[1]+n])}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,n]){const e=n*r.DEG2RAD,s=r.polarToCartesian(t,e);return this.lineTo(s)}polarLine(t,n){const e=n*r.DEG2RAD,[s,o]=r.polarToCartesian(t,e);return this.line(s,o)}tangentLine(t){const n=this.pendingSegments.at(-1);if(!n)throw new Error("You need a previous segment to sketch a tangent line");const[e,s]=n.tangentAtLastPoint;return this.line(e*t,s*t)}threePointsArcTo(t,n){return this.saveSegment(r.threePointsArc(this.pointer,n,t)),this.pointer=t,this}threePointsArc(t,n,e,s){const[o,a]=this.pointer;return this.threePointsArcTo([o+t,a+n],[o+e,a+s])}sagittaArcTo(t,n){if(!n)return this.lineTo(t);const e=new r.Line(this.pointer,t),s=r.perpendicular(e.tangentAtFirstPoint),o=r.add(e.midPoint,r.scalarMultiply(s,n));return this.threePointsArcTo(t,o)}sagittaArc(t,n,e){return this.sagittaArcTo([t+this.pointer[0],n+this.pointer[1]],e)}vSagittaArc(t,n){return this.sagittaArc(0,t,n)}hSagittaArc(t,n){return this.sagittaArc(t,0,n)}bulgeArcTo(t,n){if(!n)return this.lineTo(t);const e=r.distance(this.pointer,t)/2,s=-n*e;return this.sagittaArcTo(t,s)}bulgeArc(t,n,e){return this.bulgeArcTo([t+this.pointer[0],n+this.pointer[1]],e)}vBulgeArc(t,n){return this.bulgeArc(0,t,n)}hBulgeArc(t,n){return this.bulgeArc(t,0,n)}tangentArcTo(t,n){const e=this.pendingSegments.at(-1);if(!e)throw new Error("You need a previous curve to sketch a tangent arc");return this.saveSegment(r.tangentArc(this.pointer,t,n??e.tangentAtLastPoint)),this.pointer=t,this}tangentArc(t,n,e){const[s,o]=this.pointer;return this.tangentArcTo([t+s,n+o],e)}customCorner(t,n="fillet"){if(!this.pendingSegments.length)throw new Error("You need a segment defined to fillet the angle");return t?(this._nextCorner={mode:n,radius:t},this):this}_customCornerLastWithFirst(t,n="fillet"){if(!t)return;const e=this.pendingSegments.pop(),s=this.pendingSegments.shift();if(!e||!s)throw new Error("Not enough curves to close and fillet");const o=n==="chamfer"?d:m;this.pendingSegments.push(...o(e,s,t))}close(){if(!this.pendingSegments.length)throw new Error("No segments to close");const t=this.pendingSegments[0],n=this.pendingSegments.at(-1);return r.sameVector(t.firstPoint,n.lastPoint)||this.lineTo(t.firstPoint),this._nextCorner!==null&&(this._customCornerLastWithFirst(this._nextCorner.radius,this._nextCorner.mode),this._nextCorner=null),w(this.pendingSegments)}closeWithMirror(){if(!this.pendingSegments.length)throw new Error("No segments to close");const t=this.pendingSegments[0],n=this.pendingSegments.at(-1),e=r.subtract(n.lastPoint,t.firstPoint),s=new r.TransformationMatrix().mirrorLine(e,t.firstPoint),o=this.pendingSegments.map(a=>a.transform(s).reverse());return o.reverse(),w([...this.pendingSegments,...o])}asStrand(){return new r.Strand([...this.pendingSegments])}}function D(i=[0,0]){return new E(i)}exports.DegenerateSegment=c;exports.draw=D;exports.offsetSegment=p;
|
|
2
|
+
//# sourceMappingURL=draw-8c69c65f.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw-8c69c65f.cjs","sources":["../src/algorithms/offsets/offsetSegment.ts","../src/algorithms/filletSegments.ts","../src/draw.ts"],"sourcesContent":["import { Line } from \"../../models/segments/Line\";\nimport { Arc } from \"../../models/segments/Arc\";\nimport { Segment } from \"../../models/segments/Segment\";\nimport {\n add,\n normalize,\n perpendicular,\n scalarMultiply,\n subtract,\n} from \"../../vectorOperations\";\nimport { Vector } from \"../../definitions\";\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\";\nimport { Line } from \"../models/segments/Line\";\nimport { tangentArc } from \"../models/segments/Arc\";\nimport type { Segment } from \"../models/segments/Segment\";\nimport {\n add,\n crossProduct,\n perpendicular,\n perpendicularClockwise,\n scalarMultiply,\n} from \"../vectorOperations\";\nimport { findIntersections } from \"./intersections\";\nimport { DegenerateSegment, offsetSegment } from \"./offsets/offsetSegment\";\nimport { exportJSON } from \"../main\";\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 { chamferSegments, filletSegments } from \"./algorithms/filletSegments\";\nimport { Vector } from \"./definitions\";\nimport { Strand } from \"./models/Strand\";\nimport { Diagram } from \"./models/Diagram\";\nimport { Figure } from \"./models/Figure\";\nimport { Loop } from \"./models/Loop\";\nimport { tangentArc, threePointsArc } from \"./models/segments/Arc\";\nimport { Line } from \"./models/segments/Line\";\nimport { Segment } from \"./models/segments/Segment\";\nimport { TransformationMatrix } from \"./models/TransformationMatrix\";\nimport {\n polarToCartesian,\n DEG2RAD,\n subtract,\n sameVector,\n perpendicular,\n add,\n scalarMultiply,\n distance,\n} from \"./vectorOperations\";\n\nfunction loopySegmentsToDiagram(segments: Segment[]) {\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]))]);\n}\n\nexport class DrawingPen {\n protected 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 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(): 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);\n }\n\n closeWithMirror(): 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,\n ...mirroredSegments,\n ]);\n }\n\n asStrand(): Strand {\n return new Strand([...this.pendingSegments]);\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","loopySegmentsToDiagram","segments","Diagram","Figure","Loop","DrawingPen","origin","point","sameVector","previousSegment","makeCorner","xDist","yDist","distance","yPos","xPos","r","theta","angleInRads","DEG2RAD","polarToCartesian","angle","x","y","previousCurve","xDir","yDir","end","midPoint","threePointsArc","viaXDist","viaYDist","x0","y0","sagitta","chord","norm","sagPoint","bulge","halfChord","bulgeAsSagitta","tangentAtStart","mode","lastSegment","mirrorVector","subtract","mirrorTranform","TransformationMatrix","mirroredSegments","Strand","draw"],"mappings":"uDAYO,MAAMA,CAAkB,CAC7B,YACkBC,EACAC,EAChB,CAFgB,KAAA,WAAAD,EACA,KAAA,UAAAC,CACf,CACL,CAEgB,SAAAC,EACdC,EACAC,EAC6B,CAC7B,GAAID,aAAmBE,EAAAA,KACd,OAAAC,EAAWH,EAASC,CAAM,EAGnC,GAAID,aAAmBI,EAAAA,IACd,OAAAC,EAAUL,EAASC,CAAM,EAG5B,MAAA,IAAI,MAAM,iBAAiB,CACnC,CAEgB,SAAAE,EAAWG,EAAYL,EAAsB,CACrD,KAAA,CAAE,WAAAJ,EAAY,UAAAC,CAAc,EAAAQ,EAE5BC,EAASD,EAAK,aACpB,OAAO,IAAIJ,EAAA,KACTM,EAAAA,IAAIX,EAAYY,EAAAA,eAAeF,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AA,OAAO,CAAC,GAAG,KAAK,eAAe,CAAC,CAC7C,CACF,CAEO,SAASC,EAAK5C,EAAiB,CAAC,EAAG,CAAC,EAAe,CACjD,OAAA,IAAID,EAAWC,CAAM,CAC9B"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
declare abstract class AbstractSegment<T extends AbstractSegment<T>> extends Transformable<T> {
|
|
2
|
+
firstPoint: Vector;
|
|
3
|
+
lastPoint: Vector;
|
|
4
|
+
constructor(firstPoint: Vector, lastPoint: Vector);
|
|
5
|
+
readonly precision: number;
|
|
6
|
+
abstract segmentType: string;
|
|
7
|
+
get repr(): string;
|
|
8
|
+
get info(): string;
|
|
9
|
+
abstract get midPoint(): Vector;
|
|
10
|
+
abstract get boundingBox(): BoundingBox;
|
|
11
|
+
abstract clone(): T;
|
|
12
|
+
abstract reverse(): T;
|
|
13
|
+
abstract isSame(other: AbstractSegment<any>): boolean;
|
|
14
|
+
abstract distanceFrom(element: Vector): number;
|
|
15
|
+
abstract isOnSegment(point: Vector): boolean;
|
|
16
|
+
abstract tangentAt(point: Vector): Vector;
|
|
17
|
+
abstract get tangentAtFirstPoint(): Vector;
|
|
18
|
+
abstract get tangentAtLastPoint(): Vector;
|
|
19
|
+
abstract splitAt(points: Vector[] | number[]): T[];
|
|
20
|
+
abstract transform(matrix: TransformationMatrix): T;
|
|
21
|
+
abstract paramPoint(t: number): Vector;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare abstract class AbstractStroke<T extends AbstractStroke<T>> extends Transformable<T> {
|
|
25
|
+
readonly segments: Segment[];
|
|
26
|
+
abstract strokeType: string;
|
|
27
|
+
get repr(): string;
|
|
28
|
+
get info(): string;
|
|
29
|
+
constructor(segments: Segment[], { ignoreChecks }?: {
|
|
30
|
+
ignoreChecks?: boolean | undefined;
|
|
31
|
+
});
|
|
32
|
+
get firstPoint(): Vector;
|
|
33
|
+
get lastPoint(): Vector;
|
|
34
|
+
get segmentsCount(): number;
|
|
35
|
+
onStroke(point: Vector): boolean;
|
|
36
|
+
intersects(other: Stroke): boolean;
|
|
37
|
+
overlappingSegments(other: Stroke): Segment[];
|
|
38
|
+
private _boundingBox;
|
|
39
|
+
get boundingBox(): BoundingBox;
|
|
40
|
+
abstract reverse(): T;
|
|
41
|
+
abstract clone(): T;
|
|
42
|
+
abstract transform(matrix: TransformationMatrix): T;
|
|
43
|
+
abstract simplify(): T;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare class BoundingBox {
|
|
47
|
+
readonly xMin: number;
|
|
48
|
+
readonly yMin: number;
|
|
49
|
+
readonly xMax: number;
|
|
50
|
+
readonly yMax: number;
|
|
51
|
+
constructor(xMin?: number, yMin?: number, xMax?: number, yMax?: number);
|
|
52
|
+
get width(): number;
|
|
53
|
+
get height(): number;
|
|
54
|
+
contains(point: Vector): boolean;
|
|
55
|
+
overlaps(other: BoundingBox): boolean;
|
|
56
|
+
addPoint(point: Vector): BoundingBox;
|
|
57
|
+
merge(other: BoundingBox): BoundingBox;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare class Diagram extends Transformable<Diagram> {
|
|
61
|
+
figures: Figure[];
|
|
62
|
+
constructor(figures?: Figure[], { ignoreChecks }?: {
|
|
63
|
+
ignoreChecks?: boolean | undefined;
|
|
64
|
+
});
|
|
65
|
+
private _boundingBox;
|
|
66
|
+
get isEmpty(): boolean;
|
|
67
|
+
get boundingBox(): BoundingBox;
|
|
68
|
+
clone(): Diagram;
|
|
69
|
+
transform(matrix: TransformationMatrix): Diagram;
|
|
70
|
+
contains(point: Vector): boolean;
|
|
71
|
+
intersects(other: Diagram): boolean;
|
|
72
|
+
overlappingStrands(other: Diagram | Figure | Stroke): Strand[];
|
|
73
|
+
fuse(other: Diagram): Diagram;
|
|
74
|
+
cut(other: Diagram): Diagram;
|
|
75
|
+
intersect(other: Diagram): Diagram;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export declare function drawCircle(radius: number): Diagram;
|
|
79
|
+
|
|
80
|
+
export declare function drawRect(width: number, height: number, r?: number): Diagram;
|
|
81
|
+
|
|
82
|
+
declare class Figure extends Transformable<Figure> {
|
|
83
|
+
readonly contour: Loop;
|
|
84
|
+
readonly holes: Loop[];
|
|
85
|
+
constructor(contour: Loop, holes?: Loop[], { ignoreChecks }?: {
|
|
86
|
+
ignoreChecks?: boolean | undefined;
|
|
87
|
+
});
|
|
88
|
+
get boundingBox(): BoundingBox;
|
|
89
|
+
get isFull(): boolean;
|
|
90
|
+
get allLoops(): Loop[];
|
|
91
|
+
clone(): Figure;
|
|
92
|
+
transform(matrix: TransformationMatrix): Figure;
|
|
93
|
+
contains(point: Vector): boolean;
|
|
94
|
+
intersects(other: Figure): boolean;
|
|
95
|
+
overlappingStrands(other: Figure | Stroke): Strand[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
declare class Loop extends AbstractStroke<Loop> {
|
|
99
|
+
strokeType: string;
|
|
100
|
+
constructor(segments: Segment[], { ignoreChecks }?: {
|
|
101
|
+
ignoreChecks?: boolean | undefined;
|
|
102
|
+
});
|
|
103
|
+
private _clockwise;
|
|
104
|
+
get clockwise(): boolean;
|
|
105
|
+
clone(): Loop;
|
|
106
|
+
reverse(): Loop;
|
|
107
|
+
transform(matrix: TransformationMatrix): Loop;
|
|
108
|
+
contains(point: Vector): boolean;
|
|
109
|
+
simplify(): Loop;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
declare type Segment = AbstractSegment<any>;
|
|
113
|
+
|
|
114
|
+
declare class Strand extends AbstractStroke<Strand> {
|
|
115
|
+
strokeType: string;
|
|
116
|
+
reverse(): Strand;
|
|
117
|
+
clone(): Strand;
|
|
118
|
+
extend(strand: Strand): Strand;
|
|
119
|
+
simplify(): Strand;
|
|
120
|
+
transform(matrix: TransformationMatrix): Strand;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare type Stroke = AbstractStroke<any>;
|
|
124
|
+
|
|
125
|
+
declare abstract class Transformable<T> {
|
|
126
|
+
abstract transform(matrix: TransformationMatrix): T;
|
|
127
|
+
translateX(x: number): T;
|
|
128
|
+
translateY(y: number): T;
|
|
129
|
+
translate(x: number, y: number): T;
|
|
130
|
+
translateTo([x, y]: Vector): T;
|
|
131
|
+
rotate(angle: number, center?: Vector): T;
|
|
132
|
+
scale(factor: number, center?: Vector): T;
|
|
133
|
+
mirrorCenter(center?: Vector): T;
|
|
134
|
+
mirror(axis?: "x" | "y"): T;
|
|
135
|
+
mirror(direction: Vector, center?: Vector): T;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare class TransformationMatrix {
|
|
139
|
+
private _matrix;
|
|
140
|
+
translate(x: number, y: number): TransformationMatrix;
|
|
141
|
+
rotate(angle: number, center?: Vector): TransformationMatrix;
|
|
142
|
+
mirrorX(): TransformationMatrix;
|
|
143
|
+
mirrorY(): TransformationMatrix;
|
|
144
|
+
mirrorLine(normal: Vector, point?: Vector): TransformationMatrix;
|
|
145
|
+
mirrorCenter(center?: Vector): TransformationMatrix;
|
|
146
|
+
scale(scalar: number, center?: Vector): TransformationMatrix;
|
|
147
|
+
transform(point: Vector): Vector;
|
|
148
|
+
keepsOrientation(): boolean;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
declare type Vector = [number, number];
|
|
152
|
+
|
|
153
|
+
export { }
|
package/dist/models.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare abstract class AbstractSegment<T extends AbstractSegment<T>> extends Tra
|
|
|
5
5
|
readonly precision: number;
|
|
6
6
|
abstract segmentType: string;
|
|
7
7
|
get repr(): string;
|
|
8
|
+
get info(): string;
|
|
8
9
|
abstract get midPoint(): Vector;
|
|
9
10
|
abstract get boundingBox(): BoundingBox;
|
|
10
11
|
abstract clone(): T;
|
|
@@ -24,6 +25,7 @@ declare abstract class AbstractStroke<T extends AbstractStroke<T>> extends Trans
|
|
|
24
25
|
readonly segments: Segment[];
|
|
25
26
|
abstract strokeType: string;
|
|
26
27
|
get repr(): string;
|
|
28
|
+
get info(): string;
|
|
27
29
|
constructor(segments: Segment[], { ignoreChecks }?: {
|
|
28
30
|
ignoreChecks?: boolean | undefined;
|
|
29
31
|
});
|
|
@@ -32,6 +34,7 @@ declare abstract class AbstractStroke<T extends AbstractStroke<T>> extends Trans
|
|
|
32
34
|
get segmentsCount(): number;
|
|
33
35
|
onStroke(point: Vector): boolean;
|
|
34
36
|
intersects(other: Stroke): boolean;
|
|
37
|
+
overlappingSegments(other: Stroke): Segment[];
|
|
35
38
|
private _boundingBox;
|
|
36
39
|
get boundingBox(): BoundingBox;
|
|
37
40
|
abstract reverse(): T;
|
|
@@ -47,6 +50,7 @@ export declare class Arc extends AbstractSegment<Arc> {
|
|
|
47
50
|
constructor(firstPoint: Vector, lastPoint: Vector, center: Vector, clockwise?: boolean, { ignoreChecks }?: {
|
|
48
51
|
ignoreChecks?: boolean | undefined;
|
|
49
52
|
});
|
|
53
|
+
get info(): string;
|
|
50
54
|
isValidParameter(t: number): boolean;
|
|
51
55
|
angleToParam(angle: number): number;
|
|
52
56
|
private _angularLength;
|
|
@@ -102,6 +106,7 @@ export declare class Diagram extends Transformable<Diagram> {
|
|
|
102
106
|
transform(matrix: TransformationMatrix): Diagram;
|
|
103
107
|
contains(point: Vector): boolean;
|
|
104
108
|
intersects(other: Diagram): boolean;
|
|
109
|
+
overlappingStrands(other: Diagram | Figure | Stroke): Strand[];
|
|
105
110
|
fuse(other: Diagram): Diagram;
|
|
106
111
|
cut(other: Diagram): Diagram;
|
|
107
112
|
intersect(other: Diagram): Diagram;
|
|
@@ -120,6 +125,7 @@ export declare class Figure extends Transformable<Figure> {
|
|
|
120
125
|
transform(matrix: TransformationMatrix): Figure;
|
|
121
126
|
contains(point: Vector): boolean;
|
|
122
127
|
intersects(other: Figure): boolean;
|
|
128
|
+
overlappingStrands(other: Figure | Stroke): Strand[];
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
export declare class Line extends AbstractSegment<Line> {
|
|
@@ -173,7 +179,7 @@ export declare class Strand extends AbstractStroke<Strand> {
|
|
|
173
179
|
|
|
174
180
|
export declare type Stroke = AbstractStroke<any>;
|
|
175
181
|
|
|
176
|
-
declare abstract class Transformable<T> {
|
|
182
|
+
export declare abstract class Transformable<T> {
|
|
177
183
|
abstract transform(matrix: TransformationMatrix): T;
|
|
178
184
|
translateX(x: number): T;
|
|
179
185
|
translateY(y: number): T;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../draw-8c69c65f.cjs");require("../Diagram-4fa55d2b.cjs");function d(r){return s.draw([-r,0]).sagittaArc(2*r,0,r).sagittaArc(-2*r,0,r).close()}function R(r,n,a){const{rx:l=0,ry:f=0}={ry:a,rx:a};let e=Math.min(l,r/2),t=Math.min(f,n/2);const o=e&&t;o||(e=0,t=0);const m=e===t,i=s.draw([Math.min(0,-(r/2-e)),-n/2]),c=(u,y)=>{if(o)if(m)i.tangentArc(u,y);else throw new Error("disymmetric radius not implemented yet")};return e<r/2&&i.hLine(r-2*e),c(e,t),t<n/2&&i.vLine(n-2*t),c(-e,t),e<r/2&&i.hLine(-(r-2*e)),c(-e,-t),t<n/2&&i.vLine(-(n-2*t)),c(e,-t),i.close()}exports.drawCircle=d;exports.drawRect=R;
|
|
2
|
+
//# sourceMappingURL=drawShape.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawShape.cjs","sources":["../../src/drawShape/drawCircle.ts","../../src/drawShape/drawRect.ts"],"sourcesContent":["import { draw } from \"../draw\";\nimport type { Diagram } from \"../models/Diagram\";\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\";\nimport type { Diagram } from \"../models/Diagram\";\n\nexport function drawRect(width: number, height: number, r?: number): Diagram {\n // This will be changed once we support arc of ellipses\n const { rx: inputRx = 0, ry: inputRy = 0 } = { ry: r, rx: r };\n\n let rx = Math.min(inputRx, width / 2);\n let ry = Math.min(inputRy, 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 throw new Error(\"disymmetric radius not implemented yet\");\n //sk.ellipse(xDist, yDist, rx, ry, 0, false, true);\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":"2JAGO,SAASA,EAAWC,EAAyB,CAClD,OAAOC,OAAK,CAAC,CAACD,EAAQ,CAAC,CAAC,EACrB,WAAW,EAAIA,EAAQ,EAAGA,CAAM,EAChC,WAAW,GAAKA,EAAQ,EAAGA,CAAM,EACjC,OACL,CCLgB,SAAAE,EAASC,EAAeC,EAAgBC,EAAqB,CAE3E,KAAM,CAAE,GAAIC,EAAU,EAAG,GAAIC,EAAU,CAAE,EAAI,CAAE,GAAIF,EAAG,GAAIA,CAAE,EAE5D,IAAIG,EAAK,KAAK,IAAIF,EAASH,EAAQ,CAAC,EAChCM,EAAK,KAAK,IAAIF,EAASH,EAAS,CAAC,EAErC,MAAMM,EAAaF,GAAMC,EACpBC,IACEF,EAAA,EACAC,EAAA,GAEP,MAAME,EAAkBH,IAAOC,EAEzBG,EAAKX,EAAA,KAAK,CAAC,KAAK,IAAI,EAAG,EAAEE,EAAQ,EAAIK,EAAG,EAAG,CAACJ,EAAS,CAAC,CAAC,EAEvDS,EAAY,CAACC,EAAeC,IAAkB,CAClD,GAAIL,EACE,GAAAC,EAAoBC,EAAA,WAAWE,EAAOC,CAAK,MAEvC,OAAA,IAAI,MAAM,wCAAwC,CAG5D,EAGE,OAAAP,EAAKL,EAAQ,GACZS,EAAA,MAAMT,EAAQ,EAAIK,CAAE,EAEzBK,EAAUL,EAAIC,CAAE,EACZA,EAAKL,EAAS,GACbQ,EAAA,MAAMR,EAAS,EAAIK,CAAE,EAEhBI,EAAA,CAACL,EAAIC,CAAE,EACbD,EAAKL,EAAQ,GACfS,EAAG,MAAM,EAAET,EAAQ,EAAIK,EAAG,EAElBK,EAAA,CAACL,EAAI,CAACC,CAAE,EACdA,EAAKL,EAAS,GAChBQ,EAAG,MAAM,EAAER,EAAS,EAAIK,EAAG,EAEnBI,EAAAL,EAAI,CAACC,CAAE,EACVG,EAAG,OACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../drawShape/index'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { d as a } from "../draw-44dd36a9.js";
|
|
2
|
+
import "../Diagram-1c56996e.js";
|
|
3
|
+
function R(n) {
|
|
4
|
+
return a([-n, 0]).sagittaArc(2 * n, 0, n).sagittaArc(-2 * n, 0, n).close();
|
|
5
|
+
}
|
|
6
|
+
function L(n, e, o) {
|
|
7
|
+
const { rx: m = 0, ry: f = 0 } = { ry: o, rx: o };
|
|
8
|
+
let t = Math.min(m, n / 2), r = Math.min(f, e / 2);
|
|
9
|
+
const s = t && r;
|
|
10
|
+
s || (t = 0, r = 0);
|
|
11
|
+
const l = t === r, i = a([Math.min(0, -(n / 2 - t)), -e / 2]), c = (y, p) => {
|
|
12
|
+
if (s)
|
|
13
|
+
if (l)
|
|
14
|
+
i.tangentArc(y, p);
|
|
15
|
+
else
|
|
16
|
+
throw new Error("disymmetric radius not implemented yet");
|
|
17
|
+
};
|
|
18
|
+
return t < n / 2 && i.hLine(n - 2 * t), c(t, r), r < e / 2 && i.vLine(e - 2 * r), c(-t, r), t < n / 2 && i.hLine(-(n - 2 * t)), c(-t, -r), r < e / 2 && i.vLine(-(e - 2 * r)), c(t, -r), i.close();
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
R as drawCircle,
|
|
22
|
+
L as drawRect
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=drawShape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawShape.js","sources":["../../src/drawShape/drawCircle.ts","../../src/drawShape/drawRect.ts"],"sourcesContent":["import { draw } from \"../draw\";\nimport type { Diagram } from \"../models/Diagram\";\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\";\nimport type { Diagram } from \"../models/Diagram\";\n\nexport function drawRect(width: number, height: number, r?: number): Diagram {\n // This will be changed once we support arc of ellipses\n const { rx: inputRx = 0, ry: inputRy = 0 } = { ry: r, rx: r };\n\n let rx = Math.min(inputRx, width / 2);\n let ry = Math.min(inputRy, 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 throw new Error(\"disymmetric radius not implemented yet\");\n //sk.ellipse(xDist, yDist, rx, ry, 0, false, true);\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":";;AAGO,SAASA,EAAWC,GAAyB;AAClD,SAAOC,EAAK,CAAC,CAACD,GAAQ,CAAC,CAAC,EACrB,WAAW,IAAIA,GAAQ,GAAGA,CAAM,EAChC,WAAW,KAAKA,GAAQ,GAAGA,CAAM,EACjC;AACL;ACLgB,SAAAE,EAASC,GAAeC,GAAgBC,GAAqB;AAE3E,QAAM,EAAE,IAAIC,IAAU,GAAG,IAAIC,IAAU,EAAE,IAAI,EAAE,IAAIF,GAAG,IAAIA,EAAE;AAE5D,MAAIG,IAAK,KAAK,IAAIF,GAASH,IAAQ,CAAC,GAChCM,IAAK,KAAK,IAAIF,GAASH,IAAS,CAAC;AAErC,QAAMM,IAAaF,KAAMC;AACzB,EAAKC,MACEF,IAAA,GACAC,IAAA;AAEP,QAAME,IAAkBH,MAAOC,GAEzBG,IAAKX,EAAK,CAAC,KAAK,IAAI,GAAG,EAAEE,IAAQ,IAAIK,EAAG,GAAG,CAACJ,IAAS,CAAC,CAAC,GAEvDS,IAAY,CAACC,GAAeC,MAAkB;AAClD,QAAIL;AACE,UAAAC;AAAoB,QAAAC,EAAA,WAAWE,GAAOC,CAAK;AAAA;AAEvC,cAAA,IAAI,MAAM,wCAAwC;AAAA,EAG5D;AAGE,SAAAP,IAAKL,IAAQ,KACZS,EAAA,MAAMT,IAAQ,IAAIK,CAAE,GAEzBK,EAAUL,GAAIC,CAAE,GACZA,IAAKL,IAAS,KACbQ,EAAA,MAAMR,IAAS,IAAIK,CAAE,GAEhBI,EAAA,CAACL,GAAIC,CAAE,GACbD,IAAKL,IAAQ,KACfS,EAAG,MAAM,EAAET,IAAQ,IAAIK,EAAG,GAElBK,EAAA,CAACL,GAAI,CAACC,CAAE,GACdA,IAAKL,IAAS,KAChBQ,EAAG,MAAM,EAAER,IAAS,IAAIK,EAAG,GAEnBI,EAAAL,GAAI,CAACC,CAAE,GACVG,EAAG;AACZ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../Diagram-4fa55d2b.cjs");exports.Arc=r.Arc;exports.BoundingBox=r.BoundingBox;exports.Diagram=r.Diagram;exports.Figure=r.Figure;exports.Line=r.Line;exports.Loop=r.Loop;exports.Strand=r.Strand;exports.Transformable=r.Transformable;exports.TransformationMatrix=r.TransformationMatrix;
|
|
2
2
|
//# sourceMappingURL=models.cjs.map
|