pantograph2d 0.1.0 → 0.2.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-b3e1c256.js +1388 -0
- package/dist/exportJSON-b3e1c256.js.map +1 -0
- package/dist/exportJSON-d9965e73.cjs +4 -0
- package/dist/exportJSON-d9965e73.cjs.map +1 -0
- package/dist/models.d.ts +40 -0
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +8 -7
- package/dist/pantograph.cjs +7 -7
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +166 -2
- package/dist/pantograph.js +224 -110
- package/dist/pantograph.js.map +1 -1
- package/package.json +2 -2
- package/dist/Diagram-81a7df15.cjs +0 -4
- package/dist/Diagram-81a7df15.cjs.map +0 -1
- package/dist/Diagram-8b41118e.js +0 -944
- package/dist/Diagram-8b41118e.js.map +0 -1
package/dist/pantograph.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare abstract class AbstractSegment<T extends AbstractSegment<T>> extends Tra
|
|
|
21
21
|
|
|
22
22
|
declare abstract class AbstractStroke<T extends AbstractStroke<T>> extends Transformable<T> {
|
|
23
23
|
readonly segments: Segment[];
|
|
24
|
+
abstract strokeType: string;
|
|
24
25
|
get repr(): string;
|
|
25
26
|
constructor(segments: Segment[], { ignoreChecks }?: {
|
|
26
27
|
ignoreChecks?: boolean | undefined;
|
|
@@ -38,6 +39,42 @@ declare abstract class AbstractStroke<T extends AbstractStroke<T>> extends Trans
|
|
|
38
39
|
abstract simplify(): T;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
export declare class Arc extends AbstractSegment<Arc> {
|
|
43
|
+
segmentType: string;
|
|
44
|
+
readonly center: Vector;
|
|
45
|
+
readonly clockwise: boolean;
|
|
46
|
+
constructor(firstPoint: Vector, lastPoint: Vector, center: Vector, clockwise?: boolean, { ignoreChecks }?: {
|
|
47
|
+
ignoreChecks?: boolean | undefined;
|
|
48
|
+
});
|
|
49
|
+
isValidParameter(t: number): boolean;
|
|
50
|
+
angleToParam(angle: number): number;
|
|
51
|
+
private _angularLength;
|
|
52
|
+
get angularLength(): number;
|
|
53
|
+
paramPoint(t: number): Vector;
|
|
54
|
+
pointToParam(point: Vector): number;
|
|
55
|
+
private _radius;
|
|
56
|
+
get radius(): number;
|
|
57
|
+
private _firstAngle;
|
|
58
|
+
get firstAngle(): number;
|
|
59
|
+
private _lastAngle;
|
|
60
|
+
get lastAngle(): number;
|
|
61
|
+
get length(): number;
|
|
62
|
+
get squareLength(): number;
|
|
63
|
+
get midPoint(): Vector;
|
|
64
|
+
isSame(other: Segment): boolean;
|
|
65
|
+
clone(): Arc;
|
|
66
|
+
reverse(): Arc;
|
|
67
|
+
private _boundingBox;
|
|
68
|
+
get boundingBox(): BoundingBox;
|
|
69
|
+
distanceFrom(point: Vector): number;
|
|
70
|
+
isOnSegment(point: Vector): boolean;
|
|
71
|
+
tangentAt(point: Vector): Vector;
|
|
72
|
+
get tangentAtFirstPoint(): Vector;
|
|
73
|
+
get tangentAtLastPoint(): Vector;
|
|
74
|
+
splitAt(points: Vector | Vector[]): Arc[];
|
|
75
|
+
transform(matrix: TransformationMatrix): Arc;
|
|
76
|
+
}
|
|
77
|
+
|
|
41
78
|
export declare class BoundingBox {
|
|
42
79
|
readonly xMin: number;
|
|
43
80
|
readonly yMin: number;
|
|
@@ -52,8 +89,12 @@ export declare class BoundingBox {
|
|
|
52
89
|
merge(other: BoundingBox): BoundingBox;
|
|
53
90
|
}
|
|
54
91
|
|
|
92
|
+
export declare function cartesianToPolar([x, y]: Vector): [number, number];
|
|
93
|
+
|
|
55
94
|
export declare function cut(first: Diagram | Figure | Loop, second: Diagram | Figure | Loop): Diagram;
|
|
56
95
|
|
|
96
|
+
export declare const DEG2RAD: number;
|
|
97
|
+
|
|
57
98
|
export declare class Diagram extends Transformable<Diagram> {
|
|
58
99
|
figures: Figure[];
|
|
59
100
|
constructor(figures?: Figure[], { ignoreChecks }?: {
|
|
@@ -89,10 +130,122 @@ declare class DrawingPen {
|
|
|
89
130
|
polarLineTo([r, theta]: Vector): this;
|
|
90
131
|
polarLine(distance: number, angle: number): this;
|
|
91
132
|
tangentLine(distance: number): this;
|
|
133
|
+
threePointsArcTo(end: Vector, midPoint: Vector): this;
|
|
134
|
+
threePointsArc(xDist: number, yDist: number, viaXDist: number, viaYDist: number): this;
|
|
135
|
+
sagittaArcTo(end: Vector, sagitta: number): this;
|
|
136
|
+
sagittaArc(xDist: number, yDist: number, sagitta: number): this;
|
|
137
|
+
vSagittaArc(distance: number, sagitta: number): this;
|
|
138
|
+
hSagittaArc(distance: number, sagitta: number): this;
|
|
139
|
+
bulgeArcTo(end: Vector, bulge: number): this;
|
|
140
|
+
bulgeArc(xDist: number, yDist: number, bulge: number): this;
|
|
141
|
+
vBulgeArc(distance: number, bulge: number): this;
|
|
142
|
+
hBulgeArc(distance: number, bulge: number): this;
|
|
143
|
+
tangentArcTo(end: Vector): this;
|
|
144
|
+
tangentArc(xDist: number, yDist: number): this;
|
|
92
145
|
close(): Diagram;
|
|
93
146
|
closeWithMirror(): Diagram;
|
|
94
147
|
}
|
|
95
148
|
|
|
149
|
+
export declare function exportJSON(shape: Shape_2): {
|
|
150
|
+
type: string;
|
|
151
|
+
firstPoint: Vector;
|
|
152
|
+
lastPoint: Vector;
|
|
153
|
+
center?: undefined;
|
|
154
|
+
clockwise?: undefined;
|
|
155
|
+
} | {
|
|
156
|
+
type: string;
|
|
157
|
+
firstPoint: Vector;
|
|
158
|
+
lastPoint: Vector;
|
|
159
|
+
center: Vector;
|
|
160
|
+
clockwise: boolean;
|
|
161
|
+
} | {
|
|
162
|
+
type: string;
|
|
163
|
+
segments: ({
|
|
164
|
+
type: string;
|
|
165
|
+
firstPoint: Vector;
|
|
166
|
+
lastPoint: Vector;
|
|
167
|
+
center?: undefined;
|
|
168
|
+
clockwise?: undefined;
|
|
169
|
+
} | {
|
|
170
|
+
type: string;
|
|
171
|
+
firstPoint: Vector;
|
|
172
|
+
lastPoint: Vector;
|
|
173
|
+
center: Vector;
|
|
174
|
+
clockwise: boolean;
|
|
175
|
+
})[];
|
|
176
|
+
} | {
|
|
177
|
+
type: string;
|
|
178
|
+
contour: {
|
|
179
|
+
type: string;
|
|
180
|
+
segments: ({
|
|
181
|
+
type: string;
|
|
182
|
+
firstPoint: Vector;
|
|
183
|
+
lastPoint: Vector;
|
|
184
|
+
center?: undefined;
|
|
185
|
+
clockwise?: undefined;
|
|
186
|
+
} | {
|
|
187
|
+
type: string;
|
|
188
|
+
firstPoint: Vector;
|
|
189
|
+
lastPoint: Vector;
|
|
190
|
+
center: Vector;
|
|
191
|
+
clockwise: boolean;
|
|
192
|
+
})[];
|
|
193
|
+
};
|
|
194
|
+
holes: {
|
|
195
|
+
type: string;
|
|
196
|
+
segments: ({
|
|
197
|
+
type: string;
|
|
198
|
+
firstPoint: Vector;
|
|
199
|
+
lastPoint: Vector;
|
|
200
|
+
center?: undefined;
|
|
201
|
+
clockwise?: undefined;
|
|
202
|
+
} | {
|
|
203
|
+
type: string;
|
|
204
|
+
firstPoint: Vector;
|
|
205
|
+
lastPoint: Vector;
|
|
206
|
+
center: Vector;
|
|
207
|
+
clockwise: boolean;
|
|
208
|
+
})[];
|
|
209
|
+
}[];
|
|
210
|
+
} | {
|
|
211
|
+
type: string;
|
|
212
|
+
figures: {
|
|
213
|
+
type: string;
|
|
214
|
+
contour: {
|
|
215
|
+
type: string;
|
|
216
|
+
segments: ({
|
|
217
|
+
type: string;
|
|
218
|
+
firstPoint: Vector;
|
|
219
|
+
lastPoint: Vector;
|
|
220
|
+
center?: undefined;
|
|
221
|
+
clockwise?: undefined;
|
|
222
|
+
} | {
|
|
223
|
+
type: string;
|
|
224
|
+
firstPoint: Vector;
|
|
225
|
+
lastPoint: Vector;
|
|
226
|
+
center: Vector;
|
|
227
|
+
clockwise: boolean;
|
|
228
|
+
})[];
|
|
229
|
+
};
|
|
230
|
+
holes: {
|
|
231
|
+
type: string;
|
|
232
|
+
segments: ({
|
|
233
|
+
type: string;
|
|
234
|
+
firstPoint: Vector;
|
|
235
|
+
lastPoint: Vector;
|
|
236
|
+
center?: undefined;
|
|
237
|
+
clockwise?: undefined;
|
|
238
|
+
} | {
|
|
239
|
+
type: string;
|
|
240
|
+
firstPoint: Vector;
|
|
241
|
+
lastPoint: Vector;
|
|
242
|
+
center: Vector;
|
|
243
|
+
clockwise: boolean;
|
|
244
|
+
})[];
|
|
245
|
+
}[];
|
|
246
|
+
}[];
|
|
247
|
+
};
|
|
248
|
+
|
|
96
249
|
export declare function exportSVG(shape: Shape | Shape[], margin?: number): string;
|
|
97
250
|
|
|
98
251
|
export declare class Figure extends Transformable<Figure> {
|
|
@@ -114,6 +267,8 @@ export declare function fuse(first: Diagram | Figure | Loop, second: Diagram | F
|
|
|
114
267
|
|
|
115
268
|
export declare function fuseAll(shapes: (Diagram | Figure | Loop)[]): Diagram;
|
|
116
269
|
|
|
270
|
+
export declare function importJSON(json: any): Line | Diagram | Figure | Loop | Arc;
|
|
271
|
+
|
|
117
272
|
export declare function intersect(first: Diagram | Figure | Loop, second: Diagram | Figure | Loop): Diagram;
|
|
118
273
|
|
|
119
274
|
export declare class Line extends AbstractSegment<Line> {
|
|
@@ -140,6 +295,7 @@ export declare class Line extends AbstractSegment<Line> {
|
|
|
140
295
|
}
|
|
141
296
|
|
|
142
297
|
export declare class Loop extends AbstractStroke<Loop> {
|
|
298
|
+
strokeType: string;
|
|
143
299
|
constructor(segments: Segment[], { ignoreChecks }?: {
|
|
144
300
|
ignoreChecks?: boolean | undefined;
|
|
145
301
|
});
|
|
@@ -150,11 +306,18 @@ export declare class Loop extends AbstractStroke<Loop> {
|
|
|
150
306
|
simplify(): Loop;
|
|
151
307
|
}
|
|
152
308
|
|
|
309
|
+
export declare function polarToCartesian(r: number, theta: number): Vector;
|
|
310
|
+
|
|
311
|
+
export declare const RAD2DEG: number;
|
|
312
|
+
|
|
153
313
|
export declare type Segment = AbstractSegment<any>;
|
|
154
314
|
|
|
155
|
-
declare type Shape = Loop | Figure | Diagram;
|
|
315
|
+
declare type Shape = Loop | Figure | Diagram | Arc | Line;
|
|
316
|
+
|
|
317
|
+
declare type Shape_2 = Loop | Figure | Diagram | Arc | Line;
|
|
156
318
|
|
|
157
319
|
export declare class Strand extends AbstractStroke<Strand> {
|
|
320
|
+
strokeType: string;
|
|
158
321
|
reverse(): Strand;
|
|
159
322
|
clone(): Strand;
|
|
160
323
|
extend(strand: Strand): Strand;
|
|
@@ -189,8 +352,9 @@ export declare class TransformationMatrix {
|
|
|
189
352
|
mirrorCenter(center?: Vector): TransformationMatrix;
|
|
190
353
|
scale(scalar: number, center?: Vector): TransformationMatrix;
|
|
191
354
|
transform(point: Vector): Vector;
|
|
355
|
+
keepsOrientation(): boolean;
|
|
192
356
|
}
|
|
193
357
|
|
|
194
|
-
declare type Vector = [number, number];
|
|
358
|
+
export declare type Vector = [number, number];
|
|
195
359
|
|
|
196
360
|
export { }
|
package/dist/pantograph.js
CHANGED
|
@@ -1,172 +1,286 @@
|
|
|
1
|
-
import { L as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { s as v, L as c, t as x, p as D, a as M, b as k, d as b, c as F, e as I, T as R, D as a, F as h, f as g, g as p, h as m, i as G, j as B, k as C, A as l } from "./exportJSON-b3e1c256.js";
|
|
2
|
+
import { l as rt } from "./exportJSON-b3e1c256.js";
|
|
3
|
+
function U(n) {
|
|
4
|
+
if (!n.length)
|
|
4
5
|
throw new Error("No segments to close");
|
|
5
|
-
const
|
|
6
|
-
return
|
|
7
|
-
...
|
|
8
|
-
new
|
|
6
|
+
const t = n[0], r = n.at(-1);
|
|
7
|
+
return v(t.firstPoint, r.lastPoint) ? n : [
|
|
8
|
+
...n,
|
|
9
|
+
new c(r.lastPoint, t.firstPoint)
|
|
9
10
|
];
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return new
|
|
12
|
+
function w(n) {
|
|
13
|
+
return new a([new h(new g(n))]);
|
|
13
14
|
}
|
|
14
|
-
class
|
|
15
|
-
constructor(
|
|
16
|
-
this.pointer =
|
|
15
|
+
class N {
|
|
16
|
+
constructor(t = [0, 0]) {
|
|
17
|
+
this.pointer = t, this.firstPoint = t, this.pendingSegments = [];
|
|
17
18
|
}
|
|
18
|
-
movePointerTo(
|
|
19
|
+
movePointerTo(t) {
|
|
19
20
|
if (this.pendingSegments.length)
|
|
20
21
|
throw new Error(
|
|
21
22
|
"You can only move the pointer if there is no segment defined"
|
|
22
23
|
);
|
|
23
|
-
return this.pointer =
|
|
24
|
+
return this.pointer = t, this.firstPoint = t, this;
|
|
24
25
|
}
|
|
25
|
-
saveSegment(
|
|
26
|
-
|
|
26
|
+
saveSegment(t) {
|
|
27
|
+
if (v(t.firstPoint, t.lastPoint))
|
|
28
|
+
throw new Error(`Segment has no length, ${t.repr}`);
|
|
29
|
+
return this.pendingSegments.push(t), this;
|
|
27
30
|
}
|
|
28
|
-
lineTo(
|
|
29
|
-
const
|
|
30
|
-
return this.pointer =
|
|
31
|
+
lineTo(t) {
|
|
32
|
+
const r = new c(this.pointer, t);
|
|
33
|
+
return this.pointer = t, this.saveSegment(r);
|
|
31
34
|
}
|
|
32
|
-
line(
|
|
33
|
-
return this.lineTo([this.pointer[0] +
|
|
35
|
+
line(t, r) {
|
|
36
|
+
return this.lineTo([this.pointer[0] + t, this.pointer[1] + r]);
|
|
34
37
|
}
|
|
35
|
-
vLine(
|
|
36
|
-
return this.line(0,
|
|
38
|
+
vLine(t) {
|
|
39
|
+
return this.line(0, t);
|
|
37
40
|
}
|
|
38
|
-
hLine(
|
|
39
|
-
return this.line(
|
|
41
|
+
hLine(t) {
|
|
42
|
+
return this.line(t, 0);
|
|
40
43
|
}
|
|
41
|
-
vLineTo(
|
|
42
|
-
return this.lineTo([this.pointer[0],
|
|
44
|
+
vLineTo(t) {
|
|
45
|
+
return this.lineTo([this.pointer[0], t]);
|
|
43
46
|
}
|
|
44
|
-
hLineTo(
|
|
45
|
-
return this.lineTo([
|
|
47
|
+
hLineTo(t) {
|
|
48
|
+
return this.lineTo([t, this.pointer[1]]);
|
|
46
49
|
}
|
|
47
|
-
polarLineTo([
|
|
48
|
-
const
|
|
50
|
+
polarLineTo([t, r]) {
|
|
51
|
+
const e = r * m, i = p(t, e);
|
|
49
52
|
return this.lineTo(i);
|
|
50
53
|
}
|
|
51
|
-
polarLine(
|
|
52
|
-
const
|
|
53
|
-
return this.line(i,
|
|
54
|
+
polarLine(t, r) {
|
|
55
|
+
const e = r * m, [i, o] = p(t, e);
|
|
56
|
+
return this.line(i, o);
|
|
54
57
|
}
|
|
55
|
-
tangentLine(
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
58
|
+
tangentLine(t) {
|
|
59
|
+
const r = this.pendingSegments.at(-1);
|
|
60
|
+
if (!r)
|
|
58
61
|
throw new Error("You need a previous segment to sketch a tangent line");
|
|
59
|
-
const [
|
|
60
|
-
return this.line(
|
|
62
|
+
const [e, i] = r.tangentAtLastPoint;
|
|
63
|
+
return this.line(e * t, i * t);
|
|
64
|
+
}
|
|
65
|
+
threePointsArcTo(t, r) {
|
|
66
|
+
return this.saveSegment(x(this.pointer, r, t)), this.pointer = t, this;
|
|
67
|
+
}
|
|
68
|
+
threePointsArc(t, r, e, i) {
|
|
69
|
+
const [o, s] = this.pointer;
|
|
70
|
+
return this.threePointsArcTo(
|
|
71
|
+
[o + t, s + r],
|
|
72
|
+
[o + e, s + i]
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
sagittaArcTo(t, r) {
|
|
76
|
+
if (!r)
|
|
77
|
+
return this.lineTo(t);
|
|
78
|
+
const e = new c(this.pointer, t), i = D(e.tangentAtFirstPoint), o = M(e.midPoint, k(i, r));
|
|
79
|
+
return this.threePointsArcTo(t, o);
|
|
80
|
+
}
|
|
81
|
+
sagittaArc(t, r, e) {
|
|
82
|
+
return this.sagittaArcTo(
|
|
83
|
+
[t + this.pointer[0], r + this.pointer[1]],
|
|
84
|
+
e
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
vSagittaArc(t, r) {
|
|
88
|
+
return this.sagittaArc(0, t, r);
|
|
89
|
+
}
|
|
90
|
+
hSagittaArc(t, r) {
|
|
91
|
+
return this.sagittaArc(t, 0, r);
|
|
92
|
+
}
|
|
93
|
+
bulgeArcTo(t, r) {
|
|
94
|
+
if (!r)
|
|
95
|
+
return this.lineTo(t);
|
|
96
|
+
const e = b(this.pointer, t) / 2, i = -r * e;
|
|
97
|
+
return this.sagittaArcTo(t, i);
|
|
98
|
+
}
|
|
99
|
+
bulgeArc(t, r, e) {
|
|
100
|
+
return this.bulgeArcTo(
|
|
101
|
+
[t + this.pointer[0], r + this.pointer[1]],
|
|
102
|
+
e
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
vBulgeArc(t, r) {
|
|
106
|
+
return this.bulgeArc(0, t, r);
|
|
107
|
+
}
|
|
108
|
+
hBulgeArc(t, r) {
|
|
109
|
+
return this.bulgeArc(t, 0, r);
|
|
110
|
+
}
|
|
111
|
+
tangentArcTo(t) {
|
|
112
|
+
const r = this.pendingSegments.at(-1);
|
|
113
|
+
if (!r)
|
|
114
|
+
throw new Error("You need a previous curve to sketch a tangent arc");
|
|
115
|
+
return this.saveSegment(
|
|
116
|
+
F(this.pointer, t, r.tangentAtLastPoint)
|
|
117
|
+
), this.pointer = t, this;
|
|
118
|
+
}
|
|
119
|
+
tangentArc(t, r) {
|
|
120
|
+
const [e, i] = this.pointer;
|
|
121
|
+
return this.tangentArcTo([t + e, r + i]);
|
|
61
122
|
}
|
|
62
123
|
close() {
|
|
63
|
-
const
|
|
64
|
-
return
|
|
124
|
+
const t = U(this.pendingSegments);
|
|
125
|
+
return w(t);
|
|
65
126
|
}
|
|
66
127
|
closeWithMirror() {
|
|
67
128
|
if (!this.pendingSegments.length)
|
|
68
129
|
throw new Error("No segments to close");
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
), i = new
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
),
|
|
76
|
-
(
|
|
130
|
+
const t = this.pendingSegments[0], r = this.pendingSegments.at(-1), e = I(
|
|
131
|
+
r.lastPoint,
|
|
132
|
+
t.firstPoint
|
|
133
|
+
), i = new R().mirrorLine(
|
|
134
|
+
e,
|
|
135
|
+
t.firstPoint
|
|
136
|
+
), o = this.pendingSegments.map(
|
|
137
|
+
(s) => s.transform(i).reverse()
|
|
77
138
|
);
|
|
78
|
-
return
|
|
139
|
+
return o.reverse(), w([
|
|
79
140
|
...this.pendingSegments,
|
|
80
|
-
...
|
|
141
|
+
...o
|
|
81
142
|
]);
|
|
82
143
|
}
|
|
83
144
|
}
|
|
84
|
-
function
|
|
85
|
-
return new
|
|
145
|
+
function X(n = [0, 0]) {
|
|
146
|
+
return new N(n);
|
|
86
147
|
}
|
|
87
|
-
function
|
|
88
|
-
if (
|
|
89
|
-
return [
|
|
90
|
-
if (
|
|
91
|
-
return [new
|
|
92
|
-
if (
|
|
93
|
-
return
|
|
148
|
+
function u(n) {
|
|
149
|
+
if (n instanceof h)
|
|
150
|
+
return [n];
|
|
151
|
+
if (n instanceof g)
|
|
152
|
+
return [new h(n)];
|
|
153
|
+
if (n instanceof a)
|
|
154
|
+
return n.figures;
|
|
94
155
|
throw new Error("Unknown shape");
|
|
95
156
|
}
|
|
96
|
-
function
|
|
97
|
-
return new
|
|
98
|
-
|
|
157
|
+
function V(n, t) {
|
|
158
|
+
return new a(
|
|
159
|
+
G(u(n), u(t))
|
|
99
160
|
);
|
|
100
161
|
}
|
|
101
|
-
function
|
|
102
|
-
return
|
|
103
|
-
(
|
|
104
|
-
new
|
|
162
|
+
function Z(n) {
|
|
163
|
+
return n.reduce(
|
|
164
|
+
(t, r) => V(t, r),
|
|
165
|
+
new a()
|
|
105
166
|
);
|
|
106
167
|
}
|
|
107
|
-
function
|
|
108
|
-
return new
|
|
109
|
-
|
|
168
|
+
function z(n, t) {
|
|
169
|
+
return new a(
|
|
170
|
+
B(u(n), u(t))
|
|
110
171
|
);
|
|
111
172
|
}
|
|
112
|
-
function
|
|
113
|
-
return new
|
|
114
|
-
|
|
173
|
+
function H(n, t) {
|
|
174
|
+
return new a(
|
|
175
|
+
C(u(n), u(t))
|
|
115
176
|
);
|
|
116
177
|
}
|
|
117
|
-
function
|
|
118
|
-
if (
|
|
119
|
-
return `L ${
|
|
178
|
+
function S(n) {
|
|
179
|
+
if (n instanceof c)
|
|
180
|
+
return `L ${n.lastPoint.join(" ")}`;
|
|
181
|
+
if (n instanceof l)
|
|
182
|
+
return `A ${n.radius} ${n.radius} 0 ${n.angularLength > Math.PI ? "1" : "0"} ${n.clockwise ? "0" : "1"} ${n.lastPoint.join(" ")}`;
|
|
120
183
|
throw new Error("Unknown segment type");
|
|
121
184
|
}
|
|
122
|
-
function
|
|
123
|
-
const
|
|
124
|
-
return `${
|
|
185
|
+
function T(n) {
|
|
186
|
+
const t = `M ${n.firstPoint.join(" ")}`, r = n.segments.map(S).join(" ");
|
|
187
|
+
return `${t} ${r} Z`;
|
|
125
188
|
}
|
|
126
|
-
function
|
|
127
|
-
return `<path d="${
|
|
189
|
+
function L(n) {
|
|
190
|
+
return `<path d="${n.allLoops.map(T).join(" ")}" />`;
|
|
128
191
|
}
|
|
129
|
-
function
|
|
192
|
+
function O(n) {
|
|
130
193
|
return `<g>
|
|
131
|
-
${
|
|
194
|
+
${n.figures.map(L).join(`
|
|
132
195
|
`)}
|
|
133
196
|
</g>`;
|
|
134
197
|
}
|
|
135
|
-
function
|
|
136
|
-
const
|
|
137
|
-
return `${
|
|
198
|
+
function Y(n, t = 1) {
|
|
199
|
+
const r = n.xMin - t, e = n.yMin - t;
|
|
200
|
+
return `${r} ${e} ${n.width + 2 * t} ${n.height + 2 * t}`;
|
|
138
201
|
}
|
|
139
|
-
function
|
|
202
|
+
function A(n, t, r = 1) {
|
|
140
203
|
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
141
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${
|
|
142
|
-
${
|
|
204
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${Y(t, r)}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke">
|
|
205
|
+
${n}
|
|
143
206
|
</svg>`;
|
|
144
207
|
}
|
|
145
|
-
function
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
148
|
-
if (
|
|
149
|
-
return
|
|
150
|
-
if (
|
|
151
|
-
return `<path d="${
|
|
208
|
+
function d(n) {
|
|
209
|
+
if (n instanceof a)
|
|
210
|
+
return O(n);
|
|
211
|
+
if (n instanceof h)
|
|
212
|
+
return L(n);
|
|
213
|
+
if (n instanceof g)
|
|
214
|
+
return `<path d="${T(n)}" />`;
|
|
215
|
+
if (n instanceof l || n instanceof c)
|
|
216
|
+
return `<path d="${`M ${n.firstPoint.join(" ")}`} ${S(
|
|
217
|
+
n
|
|
218
|
+
)}" />`;
|
|
152
219
|
throw new Error("Unknown shape type");
|
|
153
220
|
}
|
|
154
|
-
function
|
|
155
|
-
if (Array.isArray(
|
|
156
|
-
const
|
|
157
|
-
`),
|
|
158
|
-
return
|
|
221
|
+
function K(n, t = 1) {
|
|
222
|
+
if (Array.isArray(n)) {
|
|
223
|
+
const e = n.map((s) => s.mirror()), i = e.map((s) => d(s)).join(`
|
|
224
|
+
`), o = e.slice(1).reduce((s, E) => s.merge(E.boundingBox), e[0].boundingBox);
|
|
225
|
+
return A(i, o);
|
|
159
226
|
}
|
|
160
|
-
const
|
|
161
|
-
return
|
|
227
|
+
const r = n.mirror();
|
|
228
|
+
return A(d(r), r.boundingBox, t);
|
|
229
|
+
}
|
|
230
|
+
const $ = (n) => {
|
|
231
|
+
if (n.type === "LINE")
|
|
232
|
+
return new c(n.firstPoint, n.lastPoint);
|
|
233
|
+
if (n.type === "ARC")
|
|
234
|
+
return new l(
|
|
235
|
+
n.firstPoint,
|
|
236
|
+
n.lastPoint,
|
|
237
|
+
n.center,
|
|
238
|
+
n.clockwise
|
|
239
|
+
);
|
|
240
|
+
throw new Error("Unknown segment type");
|
|
241
|
+
}, f = (n) => {
|
|
242
|
+
const t = n.segments.map($);
|
|
243
|
+
return new g(t);
|
|
244
|
+
}, y = (n) => {
|
|
245
|
+
const t = f(n.contour), r = n.holes.map(f);
|
|
246
|
+
return new h(t, r);
|
|
247
|
+
}, J = (n) => {
|
|
248
|
+
const t = n.figures.map(y);
|
|
249
|
+
return new a(t);
|
|
250
|
+
};
|
|
251
|
+
function Q(n) {
|
|
252
|
+
if (n.type === "DIAGRAM")
|
|
253
|
+
return J(n);
|
|
254
|
+
if (n.type === "FIGURE")
|
|
255
|
+
return y(n);
|
|
256
|
+
if (n.type === "LOOP")
|
|
257
|
+
return f(n);
|
|
258
|
+
if (n.type === "LINE" || n.type === "ARC")
|
|
259
|
+
return $(n);
|
|
260
|
+
throw new Error("Unknown shape type");
|
|
261
|
+
}
|
|
262
|
+
const P = Math.PI / 180, q = 180 / Math.PI;
|
|
263
|
+
function _(n, t) {
|
|
264
|
+
const r = Math.cos(t * P) * n, e = Math.sin(t * P) * n;
|
|
265
|
+
return [r, e];
|
|
266
|
+
}
|
|
267
|
+
function j([n, t]) {
|
|
268
|
+
const r = Math.sqrt(n * n + t * t), e = Math.atan2(t, n) * q;
|
|
269
|
+
return [r, e];
|
|
162
270
|
}
|
|
163
271
|
export {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
272
|
+
P as DEG2RAD,
|
|
273
|
+
q as RAD2DEG,
|
|
274
|
+
j as cartesianToPolar,
|
|
275
|
+
z as cut,
|
|
276
|
+
X as draw,
|
|
277
|
+
rt as exportJSON,
|
|
278
|
+
K as exportSVG,
|
|
279
|
+
V as fuse,
|
|
280
|
+
Z as fuseAll,
|
|
281
|
+
Q as importJSON,
|
|
282
|
+
H as intersect,
|
|
283
|
+
_ as polarToCartesian,
|
|
284
|
+
d as svgBody
|
|
171
285
|
};
|
|
172
286
|
//# sourceMappingURL=pantograph.js.map
|