circuit-to-svg 0.0.67 → 0.0.68
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/index.d.ts +1 -0
- package/dist/index.js +180 -72
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,21 +1,119 @@
|
|
|
1
1
|
// lib/pcb/convert-circuit-json-to-pcb-svg.ts
|
|
2
2
|
import { stringify } from "svgson";
|
|
3
3
|
import {
|
|
4
|
-
applyToPoint as
|
|
4
|
+
applyToPoint as applyToPoint12,
|
|
5
5
|
compose as compose3,
|
|
6
6
|
scale,
|
|
7
7
|
translate as translate3
|
|
8
8
|
} from "transformation-matrix";
|
|
9
9
|
|
|
10
|
-
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-
|
|
10
|
+
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-trace-error.ts
|
|
11
11
|
import { applyToPoint } from "transformation-matrix";
|
|
12
|
+
function createSvgObjectsFromPcbTraceError(pcbTraceError, transform, circuitJson, shouldDrawErrors) {
|
|
13
|
+
if (!shouldDrawErrors) return [];
|
|
14
|
+
const { pcb_port_ids } = pcbTraceError;
|
|
15
|
+
const port1 = circuitJson.find(
|
|
16
|
+
(el) => el.type === "pcb_port" && el.pcb_port_id === pcb_port_ids?.[0]
|
|
17
|
+
);
|
|
18
|
+
const port2 = circuitJson.find(
|
|
19
|
+
(el) => el.type === "pcb_port" && el.pcb_port_id === pcb_port_ids?.[1]
|
|
20
|
+
);
|
|
21
|
+
if (!port1 || !port2) return [];
|
|
22
|
+
const screenPort1 = applyToPoint(transform, {
|
|
23
|
+
x: port1.x,
|
|
24
|
+
y: port1.y
|
|
25
|
+
});
|
|
26
|
+
const screenPort2 = applyToPoint(transform, {
|
|
27
|
+
x: port2.x,
|
|
28
|
+
y: port2.y
|
|
29
|
+
});
|
|
30
|
+
const errorCenter = {
|
|
31
|
+
x: (screenPort1.x + screenPort2.x) / 2,
|
|
32
|
+
y: (screenPort1.y + screenPort2.y) / 2
|
|
33
|
+
};
|
|
34
|
+
if (isNaN(screenPort1.x) || isNaN(screenPort1.y) || isNaN(screenPort2.x) || isNaN(screenPort2.y) || isNaN(errorCenter.x) || isNaN(errorCenter.y)) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const svgObjects = [
|
|
38
|
+
{
|
|
39
|
+
name: "line",
|
|
40
|
+
type: "element",
|
|
41
|
+
attributes: {
|
|
42
|
+
x1: screenPort1.x.toString(),
|
|
43
|
+
y1: screenPort1.y.toString(),
|
|
44
|
+
x2: errorCenter.x.toString(),
|
|
45
|
+
y2: errorCenter.y.toString(),
|
|
46
|
+
stroke: "red",
|
|
47
|
+
"stroke-width": "1.5",
|
|
48
|
+
"stroke-dasharray": "2,2"
|
|
49
|
+
},
|
|
50
|
+
children: [],
|
|
51
|
+
value: ""
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "line",
|
|
55
|
+
type: "element",
|
|
56
|
+
attributes: {
|
|
57
|
+
x1: errorCenter.x.toString(),
|
|
58
|
+
y1: errorCenter.y.toString(),
|
|
59
|
+
x2: screenPort2.x.toString(),
|
|
60
|
+
y2: screenPort2.y.toString(),
|
|
61
|
+
stroke: "red",
|
|
62
|
+
"stroke-width": "1.5",
|
|
63
|
+
"stroke-dasharray": "2,2"
|
|
64
|
+
},
|
|
65
|
+
children: [],
|
|
66
|
+
value: ""
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "rect",
|
|
70
|
+
type: "element",
|
|
71
|
+
attributes: {
|
|
72
|
+
x: (errorCenter.x - 5).toString(),
|
|
73
|
+
y: (errorCenter.y - 5).toString(),
|
|
74
|
+
width: "10",
|
|
75
|
+
height: "10",
|
|
76
|
+
fill: "red",
|
|
77
|
+
transform: `rotate(45 ${errorCenter.x} ${errorCenter.y})`
|
|
78
|
+
},
|
|
79
|
+
children: [],
|
|
80
|
+
value: ""
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "text",
|
|
84
|
+
type: "element",
|
|
85
|
+
attributes: {
|
|
86
|
+
x: errorCenter.x.toString(),
|
|
87
|
+
y: (errorCenter.y - 15).toString(),
|
|
88
|
+
fill: "red",
|
|
89
|
+
"font-family": "sans-serif",
|
|
90
|
+
"font-size": "12",
|
|
91
|
+
"text-anchor": "middle"
|
|
92
|
+
},
|
|
93
|
+
children: [
|
|
94
|
+
{
|
|
95
|
+
type: "text",
|
|
96
|
+
value: pcbTraceError.message || "Pcb Trace Error",
|
|
97
|
+
name: "",
|
|
98
|
+
attributes: {},
|
|
99
|
+
children: []
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
value: ""
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
return svgObjects;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-fabrication-note-path.ts
|
|
109
|
+
import { applyToPoint as applyToPoint2 } from "transformation-matrix";
|
|
12
110
|
function createSvgObjectsFromPcbFabricationNotePath(fabNotePath, transform) {
|
|
13
111
|
if (!fabNotePath.route || !Array.isArray(fabNotePath.route)) return [];
|
|
14
112
|
const firstPoint = fabNotePath.route[0];
|
|
15
113
|
const lastPoint = fabNotePath.route[fabNotePath.route.length - 1];
|
|
16
114
|
const isClosed = firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y;
|
|
17
115
|
const path = fabNotePath.route.slice(0, isClosed ? -1 : void 0).map((point, index) => {
|
|
18
|
-
const [x, y] =
|
|
116
|
+
const [x, y] = applyToPoint2(transform, [point.x, point.y]);
|
|
19
117
|
return index === 0 ? `M ${x} ${y}` : `L ${x} ${y}`;
|
|
20
118
|
}).join(" ") + (isClosed ? " Z" : "");
|
|
21
119
|
return [
|
|
@@ -40,7 +138,7 @@ function createSvgObjectsFromPcbFabricationNotePath(fabNotePath, transform) {
|
|
|
40
138
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-fabrication-note-text.ts
|
|
41
139
|
import { toString as matrixToString } from "transformation-matrix";
|
|
42
140
|
import {
|
|
43
|
-
applyToPoint as
|
|
141
|
+
applyToPoint as applyToPoint3,
|
|
44
142
|
compose,
|
|
45
143
|
rotate,
|
|
46
144
|
translate
|
|
@@ -58,7 +156,7 @@ function createSvgObjectsFromPcbFabricationNoteText(pcbFabNoteText, transform) {
|
|
|
58
156
|
console.error("Invalid anchor_position:", anchor_position);
|
|
59
157
|
return [];
|
|
60
158
|
}
|
|
61
|
-
const [transformedX, transformedY] =
|
|
159
|
+
const [transformedX, transformedY] = applyToPoint3(transform, [
|
|
62
160
|
anchor_position.x,
|
|
63
161
|
anchor_position.y
|
|
64
162
|
]);
|
|
@@ -98,9 +196,9 @@ function createSvgObjectsFromPcbFabricationNoteText(pcbFabNoteText, transform) {
|
|
|
98
196
|
}
|
|
99
197
|
|
|
100
198
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-plated-hole.ts
|
|
101
|
-
import { applyToPoint as
|
|
199
|
+
import { applyToPoint as applyToPoint4 } from "transformation-matrix";
|
|
102
200
|
function createSvgObjectsFromPcbPlatedHole(hole, transform) {
|
|
103
|
-
const [x, y] =
|
|
201
|
+
const [x, y] = applyToPoint4(transform, [hole.x, hole.y]);
|
|
104
202
|
if (hole.shape === "pill") {
|
|
105
203
|
const scaledOuterWidth = hole.outer_width * Math.abs(transform.a);
|
|
106
204
|
const scaledOuterHeight = hole.outer_height * Math.abs(transform.a);
|
|
@@ -190,11 +288,11 @@ function createSvgObjectsFromPcbPlatedHole(hole, transform) {
|
|
|
190
288
|
}
|
|
191
289
|
|
|
192
290
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-path.ts
|
|
193
|
-
import { applyToPoint as
|
|
291
|
+
import { applyToPoint as applyToPoint5 } from "transformation-matrix";
|
|
194
292
|
function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath, transform) {
|
|
195
293
|
if (!silkscreenPath.route || !Array.isArray(silkscreenPath.route)) return [];
|
|
196
294
|
let path = silkscreenPath.route.map((point, index) => {
|
|
197
|
-
const [x, y] =
|
|
295
|
+
const [x, y] = applyToPoint5(transform, [point.x, point.y]);
|
|
198
296
|
return index === 0 ? `M ${x} ${y}` : `L ${x} ${y}`;
|
|
199
297
|
}).join(" ");
|
|
200
298
|
const firstPoint = silkscreenPath.route[0];
|
|
@@ -221,7 +319,7 @@ function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath, transform) {
|
|
|
221
319
|
|
|
222
320
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-silkscreen-text.ts
|
|
223
321
|
import {
|
|
224
|
-
applyToPoint as
|
|
322
|
+
applyToPoint as applyToPoint6,
|
|
225
323
|
compose as compose2,
|
|
226
324
|
rotate as rotate2,
|
|
227
325
|
translate as translate2,
|
|
@@ -238,7 +336,7 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
|
|
|
238
336
|
console.error("Invalid anchor_position:", anchor_position);
|
|
239
337
|
return [];
|
|
240
338
|
}
|
|
241
|
-
const [transformedX, transformedY] =
|
|
339
|
+
const [transformedX, transformedY] = applyToPoint6(transform, [
|
|
242
340
|
anchor_position.x,
|
|
243
341
|
anchor_position.y
|
|
244
342
|
]);
|
|
@@ -286,7 +384,7 @@ function pairs(arr) {
|
|
|
286
384
|
}
|
|
287
385
|
|
|
288
386
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-trace.ts
|
|
289
|
-
import { applyToPoint as
|
|
387
|
+
import { applyToPoint as applyToPoint7 } from "transformation-matrix";
|
|
290
388
|
|
|
291
389
|
// lib/pcb/layer-name-to-color.ts
|
|
292
390
|
var LAYER_NAME_TO_COLOR = {
|
|
@@ -304,8 +402,8 @@ function createSvgObjectsFromPcbTrace(trace, transform) {
|
|
|
304
402
|
const segments = pairs(trace.route);
|
|
305
403
|
const svgObjects = [];
|
|
306
404
|
for (const [start, end] of segments) {
|
|
307
|
-
const startPoint =
|
|
308
|
-
const endPoint =
|
|
405
|
+
const startPoint = applyToPoint7(transform, [start.x, start.y]);
|
|
406
|
+
const endPoint = applyToPoint7(transform, [end.x, end.y]);
|
|
309
407
|
const layer = "layer" in start ? start.layer : "layer" in end ? end.layer : null;
|
|
310
408
|
if (!layer) continue;
|
|
311
409
|
const layerColor = LAYER_NAME_TO_COLOR[layer] ?? "white";
|
|
@@ -330,9 +428,9 @@ function createSvgObjectsFromPcbTrace(trace, transform) {
|
|
|
330
428
|
}
|
|
331
429
|
|
|
332
430
|
// lib/pcb/svg-object-fns/create-svg-objects-from-smt-pads.ts
|
|
333
|
-
import { applyToPoint as
|
|
431
|
+
import { applyToPoint as applyToPoint8 } from "transformation-matrix";
|
|
334
432
|
function createSvgObjectsFromSmtPad(pad, transform) {
|
|
335
|
-
const [x, y] =
|
|
433
|
+
const [x, y] = applyToPoint8(transform, [pad.x, pad.y]);
|
|
336
434
|
if (pad.shape === "rect") {
|
|
337
435
|
const width = pad.width * Math.abs(transform.a);
|
|
338
436
|
const height = pad.height * Math.abs(transform.d);
|
|
@@ -355,31 +453,31 @@ function createSvgObjectsFromSmtPad(pad, transform) {
|
|
|
355
453
|
}
|
|
356
454
|
|
|
357
455
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-board.ts
|
|
358
|
-
import { applyToPoint as
|
|
456
|
+
import { applyToPoint as applyToPoint9 } from "transformation-matrix";
|
|
359
457
|
function createSvgObjectsFromPcbBoard(pcbBoard, transform) {
|
|
360
458
|
const { width, height, center, outline } = pcbBoard;
|
|
361
459
|
let path;
|
|
362
460
|
if (outline && Array.isArray(outline) && outline.length >= 3) {
|
|
363
461
|
path = outline.map((point, index) => {
|
|
364
|
-
const [x, y] =
|
|
462
|
+
const [x, y] = applyToPoint9(transform, [point.x, point.y]);
|
|
365
463
|
return index === 0 ? `M ${x} ${y}` : `L ${x} ${y}`;
|
|
366
464
|
}).join(" ");
|
|
367
465
|
} else {
|
|
368
466
|
const halfWidth = width / 2;
|
|
369
467
|
const halfHeight = height / 2;
|
|
370
|
-
const topLeft =
|
|
468
|
+
const topLeft = applyToPoint9(transform, [
|
|
371
469
|
center.x - halfWidth,
|
|
372
470
|
center.y - halfHeight
|
|
373
471
|
]);
|
|
374
|
-
const topRight =
|
|
472
|
+
const topRight = applyToPoint9(transform, [
|
|
375
473
|
center.x + halfWidth,
|
|
376
474
|
center.y - halfHeight
|
|
377
475
|
]);
|
|
378
|
-
const bottomRight =
|
|
476
|
+
const bottomRight = applyToPoint9(transform, [
|
|
379
477
|
center.x + halfWidth,
|
|
380
478
|
center.y + halfHeight
|
|
381
479
|
]);
|
|
382
|
-
const bottomLeft =
|
|
480
|
+
const bottomLeft = applyToPoint9(transform, [
|
|
383
481
|
center.x - halfWidth,
|
|
384
482
|
center.y + halfHeight
|
|
385
483
|
]);
|
|
@@ -403,9 +501,9 @@ function createSvgObjectsFromPcbBoard(pcbBoard, transform) {
|
|
|
403
501
|
}
|
|
404
502
|
|
|
405
503
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-via.ts
|
|
406
|
-
import { applyToPoint as
|
|
504
|
+
import { applyToPoint as applyToPoint10 } from "transformation-matrix";
|
|
407
505
|
function createSvgObjectsFromPcbVia(hole, transform) {
|
|
408
|
-
const [x, y] =
|
|
506
|
+
const [x, y] = applyToPoint10(transform, [hole.x, hole.y]);
|
|
409
507
|
const scaledOuterWidth = hole.outer_diameter * Math.abs(transform.a);
|
|
410
508
|
const scaledOuterHeight = hole.outer_diameter * Math.abs(transform.a);
|
|
411
509
|
const scaledHoleWidth = hole.hole_diameter * Math.abs(transform.a);
|
|
@@ -441,14 +539,14 @@ function createSvgObjectsFromPcbVia(hole, transform) {
|
|
|
441
539
|
}
|
|
442
540
|
|
|
443
541
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-hole.ts
|
|
444
|
-
import { applyToPoint as
|
|
542
|
+
import { applyToPoint as applyToPoint11 } from "transformation-matrix";
|
|
445
543
|
|
|
446
544
|
// lib/pcb/colors.ts
|
|
447
545
|
var HOLE_COLOR = "#FF26E2";
|
|
448
546
|
|
|
449
547
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-hole.ts
|
|
450
548
|
function createSvgObjectsFromPcbHole(hole, transform) {
|
|
451
|
-
const [x, y] =
|
|
549
|
+
const [x, y] = applyToPoint11(transform, [hole.x, hole.y]);
|
|
452
550
|
if (hole.hole_shape === "circle" || hole.hole_shape === "square") {
|
|
453
551
|
const scaledDiameter = hole.hole_diameter * Math.abs(transform.a);
|
|
454
552
|
const radius = scaledDiameter / 2;
|
|
@@ -513,6 +611,7 @@ function createSvgObjectsFromPcbHole(hole, transform) {
|
|
|
513
611
|
|
|
514
612
|
// lib/pcb/convert-circuit-json-to-pcb-svg.ts
|
|
515
613
|
var OBJECT_ORDER = [
|
|
614
|
+
"pcb_trace_error",
|
|
516
615
|
"pcb_plated_hole",
|
|
517
616
|
"pcb_fabrication_note_text",
|
|
518
617
|
"pcb_fabrication_note_path",
|
|
@@ -567,7 +666,9 @@ function convertCircuitJsonToPcbSvg(soup, options) {
|
|
|
567
666
|
);
|
|
568
667
|
const svgObjects = soup.sort(
|
|
569
668
|
(a, b) => (OBJECT_ORDER.indexOf(b.type) ?? 9999) - (OBJECT_ORDER.indexOf(a.type) ?? 9999)
|
|
570
|
-
).flatMap(
|
|
669
|
+
).flatMap(
|
|
670
|
+
(item) => createSvgObjects(item, transform, soup, options?.shouldDrawErrors)
|
|
671
|
+
);
|
|
571
672
|
let strokeWidth = String(0.05 * scaleFactor);
|
|
572
673
|
for (const element of soup) {
|
|
573
674
|
if ("stroke_width" in element) {
|
|
@@ -653,8 +754,15 @@ function convertCircuitJsonToPcbSvg(soup, options) {
|
|
|
653
754
|
}
|
|
654
755
|
}
|
|
655
756
|
}
|
|
656
|
-
function createSvgObjects(elm, transform) {
|
|
757
|
+
function createSvgObjects(elm, transform, soup, shouldDrawErrors) {
|
|
657
758
|
switch (elm.type) {
|
|
759
|
+
case "pcb_trace_error":
|
|
760
|
+
return createSvgObjectsFromPcbTraceError(
|
|
761
|
+
elm,
|
|
762
|
+
transform,
|
|
763
|
+
soup,
|
|
764
|
+
shouldDrawErrors
|
|
765
|
+
).filter(Boolean);
|
|
658
766
|
case "pcb_component":
|
|
659
767
|
return [createSvgObjectsFromPcbComponent(elm, transform)].filter(Boolean);
|
|
660
768
|
case "pcb_trace":
|
|
@@ -683,7 +791,7 @@ function createSvgObjects(elm, transform) {
|
|
|
683
791
|
}
|
|
684
792
|
function createSvgObjectsFromPcbComponent(component, transform) {
|
|
685
793
|
const { center, width, height, rotation = 0 } = component;
|
|
686
|
-
const [x, y] =
|
|
794
|
+
const [x, y] = applyToPoint12(transform, [center.x, center.y]);
|
|
687
795
|
const scaledWidth = width * Math.abs(transform.a);
|
|
688
796
|
const scaledHeight = height * Math.abs(transform.d);
|
|
689
797
|
const transformStr = `translate(${x}, ${y}) rotate(${-rotation}) scale(1, -1)`;
|
|
@@ -718,8 +826,8 @@ function createSvgObjectsFromPcbComponent(component, transform) {
|
|
|
718
826
|
};
|
|
719
827
|
}
|
|
720
828
|
function createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY) {
|
|
721
|
-
const [x1, y1] =
|
|
722
|
-
const [x2, y2] =
|
|
829
|
+
const [x1, y1] = applyToPoint12(transform, [minX, minY]);
|
|
830
|
+
const [x2, y2] = applyToPoint12(transform, [maxX, maxY]);
|
|
723
831
|
const width = Math.abs(x2 - x1);
|
|
724
832
|
const height = Math.abs(y2 - y1);
|
|
725
833
|
const x = Math.min(x1, x2);
|
|
@@ -984,14 +1092,14 @@ import {
|
|
|
984
1092
|
} from "transformation-matrix";
|
|
985
1093
|
|
|
986
1094
|
// lib/sch/draw-schematic-grid.ts
|
|
987
|
-
import { applyToPoint as
|
|
1095
|
+
import { applyToPoint as applyToPoint13 } from "transformation-matrix";
|
|
988
1096
|
function drawSchematicGrid(params) {
|
|
989
1097
|
const { minX, minY, maxX, maxY } = params.bounds;
|
|
990
1098
|
const cellSize = params.cellSize ?? 1;
|
|
991
1099
|
const labelCells = params.labelCells ?? false;
|
|
992
1100
|
const gridLines = [];
|
|
993
1101
|
const transformPoint = (x, y) => {
|
|
994
|
-
const [transformedX, transformedY] =
|
|
1102
|
+
const [transformedX, transformedY] = applyToPoint13(params.transform, [x, y]);
|
|
995
1103
|
return { x: transformedX, y: transformedY };
|
|
996
1104
|
};
|
|
997
1105
|
for (let x = Math.ceil(minX); x <= Math.floor(maxX); x += cellSize) {
|
|
@@ -1068,15 +1176,15 @@ function drawSchematicGrid(params) {
|
|
|
1068
1176
|
}
|
|
1069
1177
|
|
|
1070
1178
|
// lib/sch/draw-schematic-labeled-points.ts
|
|
1071
|
-
import { applyToPoint as
|
|
1179
|
+
import { applyToPoint as applyToPoint14 } from "transformation-matrix";
|
|
1072
1180
|
function drawSchematicLabeledPoints(params) {
|
|
1073
1181
|
const { points, transform } = params;
|
|
1074
1182
|
const labeledPointsGroup = [];
|
|
1075
1183
|
for (const point of points) {
|
|
1076
|
-
const [x1, y1] =
|
|
1077
|
-
const [x2, y2] =
|
|
1078
|
-
const [x3, y3] =
|
|
1079
|
-
const [x4, y4] =
|
|
1184
|
+
const [x1, y1] = applyToPoint14(transform, [point.x - 0.1, point.y - 0.1]);
|
|
1185
|
+
const [x2, y2] = applyToPoint14(transform, [point.x + 0.1, point.y + 0.1]);
|
|
1186
|
+
const [x3, y3] = applyToPoint14(transform, [point.x - 0.1, point.y + 0.1]);
|
|
1187
|
+
const [x4, y4] = applyToPoint14(transform, [point.x + 0.1, point.y - 0.1]);
|
|
1080
1188
|
labeledPointsGroup.push({
|
|
1081
1189
|
name: "path",
|
|
1082
1190
|
type: "element",
|
|
@@ -1087,7 +1195,7 @@ function drawSchematicLabeledPoints(params) {
|
|
|
1087
1195
|
"stroke-opacity": "0.7"
|
|
1088
1196
|
}
|
|
1089
1197
|
});
|
|
1090
|
-
const [labelX, labelY] =
|
|
1198
|
+
const [labelX, labelY] = applyToPoint14(transform, [
|
|
1091
1199
|
point.x + 0.15,
|
|
1092
1200
|
point.y - 0.15
|
|
1093
1201
|
]);
|
|
@@ -1175,7 +1283,7 @@ import { su } from "@tscircuit/soup-util";
|
|
|
1175
1283
|
import { symbols } from "schematic-symbols";
|
|
1176
1284
|
import "svgson";
|
|
1177
1285
|
import {
|
|
1178
|
-
applyToPoint as
|
|
1286
|
+
applyToPoint as applyToPoint16,
|
|
1179
1287
|
compose as compose5
|
|
1180
1288
|
} from "transformation-matrix";
|
|
1181
1289
|
|
|
@@ -1327,7 +1435,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1327
1435
|
name: "path",
|
|
1328
1436
|
attributes: {
|
|
1329
1437
|
d: points.map((p, i) => {
|
|
1330
|
-
const [x, y] =
|
|
1438
|
+
const [x, y] = applyToPoint16(
|
|
1331
1439
|
compose5(realToScreenTransform, transformFromSymbolToReal),
|
|
1332
1440
|
[p.x, p.y]
|
|
1333
1441
|
);
|
|
@@ -1342,7 +1450,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1342
1450
|
});
|
|
1343
1451
|
}
|
|
1344
1452
|
for (const text of texts) {
|
|
1345
|
-
const screenTextPos =
|
|
1453
|
+
const screenTextPos = applyToPoint16(
|
|
1346
1454
|
compose5(realToScreenTransform, transformFromSymbolToReal),
|
|
1347
1455
|
text
|
|
1348
1456
|
);
|
|
@@ -1376,7 +1484,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1376
1484
|
});
|
|
1377
1485
|
}
|
|
1378
1486
|
for (const box of boxes) {
|
|
1379
|
-
const screenBoxPos =
|
|
1487
|
+
const screenBoxPos = applyToPoint16(
|
|
1380
1488
|
compose5(realToScreenTransform, transformFromSymbolToReal),
|
|
1381
1489
|
box
|
|
1382
1490
|
);
|
|
@@ -1399,7 +1507,7 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1399
1507
|
});
|
|
1400
1508
|
}
|
|
1401
1509
|
for (const port of symbol.ports) {
|
|
1402
|
-
const screenPortPos =
|
|
1510
|
+
const screenPortPos = applyToPoint16(
|
|
1403
1511
|
compose5(realToScreenTransform, transformFromSymbolToReal),
|
|
1404
1512
|
port
|
|
1405
1513
|
);
|
|
@@ -1424,14 +1532,14 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1424
1532
|
import { su as su4 } from "@tscircuit/soup-util";
|
|
1425
1533
|
import "schematic-symbols";
|
|
1426
1534
|
import "svgson";
|
|
1427
|
-
import { applyToPoint as
|
|
1535
|
+
import { applyToPoint as applyToPoint21 } from "transformation-matrix";
|
|
1428
1536
|
|
|
1429
1537
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-port-on-box.ts
|
|
1430
1538
|
import "transformation-matrix";
|
|
1431
1539
|
import "@tscircuit/soup-util";
|
|
1432
1540
|
|
|
1433
1541
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-port-box-line.ts
|
|
1434
|
-
import { applyToPoint as
|
|
1542
|
+
import { applyToPoint as applyToPoint17 } from "transformation-matrix";
|
|
1435
1543
|
import { su as su2 } from "@tscircuit/soup-util";
|
|
1436
1544
|
var PIN_CIRCLE_RADIUS_MM = 0.02;
|
|
1437
1545
|
var createSvgObjectsForSchPortBoxLine = ({
|
|
@@ -1461,8 +1569,8 @@ var createSvgObjectsForSchPortBoxLine = ({
|
|
|
1461
1569
|
realEdgePos.y += realPinLineLength;
|
|
1462
1570
|
break;
|
|
1463
1571
|
}
|
|
1464
|
-
const screenSchPortPos =
|
|
1465
|
-
const screenRealEdgePos =
|
|
1572
|
+
const screenSchPortPos = applyToPoint17(transform, schPort.center);
|
|
1573
|
+
const screenRealEdgePos = applyToPoint17(transform, realEdgePos);
|
|
1466
1574
|
const realLineEnd = { ...schPort.center };
|
|
1467
1575
|
switch (schPort.side_of_component) {
|
|
1468
1576
|
case "left":
|
|
@@ -1478,7 +1586,7 @@ var createSvgObjectsForSchPortBoxLine = ({
|
|
|
1478
1586
|
realLineEnd.y += PIN_CIRCLE_RADIUS_MM;
|
|
1479
1587
|
break;
|
|
1480
1588
|
}
|
|
1481
|
-
const screenLineEnd =
|
|
1589
|
+
const screenLineEnd = applyToPoint17(transform, realLineEnd);
|
|
1482
1590
|
svgObjects.push({
|
|
1483
1591
|
name: "line",
|
|
1484
1592
|
type: "element",
|
|
@@ -1525,7 +1633,7 @@ var getUnitVectorFromOutsideToEdge = (side) => {
|
|
|
1525
1633
|
};
|
|
1526
1634
|
|
|
1527
1635
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-port-pin-number-text.ts
|
|
1528
|
-
import { applyToPoint as
|
|
1636
|
+
import { applyToPoint as applyToPoint18 } from "transformation-matrix";
|
|
1529
1637
|
var createSvgObjectsForSchPortPinNumberText = (params) => {
|
|
1530
1638
|
const svgObjects = [];
|
|
1531
1639
|
const { schPort, schComponent, transform, circuitJson } = params;
|
|
@@ -1538,7 +1646,7 @@ var createSvgObjectsForSchPortPinNumberText = (params) => {
|
|
|
1538
1646
|
const realPinEdgeDistance = schPort.distance_from_component_edge ?? 0.4;
|
|
1539
1647
|
realPinNumberPos.x += vecToEdge.x * realPinEdgeDistance / 2;
|
|
1540
1648
|
realPinNumberPos.y += vecToEdge.y * realPinEdgeDistance / 2;
|
|
1541
|
-
const screenPinNumberTextPos =
|
|
1649
|
+
const screenPinNumberTextPos = applyToPoint18(transform, realPinNumberPos);
|
|
1542
1650
|
if (schPort.side_of_component === "top" || schPort.side_of_component === "bottom") {
|
|
1543
1651
|
screenPinNumberTextPos.x -= 2;
|
|
1544
1652
|
} else {
|
|
@@ -1573,7 +1681,7 @@ var createSvgObjectsForSchPortPinNumberText = (params) => {
|
|
|
1573
1681
|
};
|
|
1574
1682
|
|
|
1575
1683
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-port-pin-label.ts
|
|
1576
|
-
import { applyToPoint as
|
|
1684
|
+
import { applyToPoint as applyToPoint19 } from "transformation-matrix";
|
|
1577
1685
|
var LABEL_DIST_FROM_EDGE_MM = 0.1;
|
|
1578
1686
|
var createSvgObjectsForSchPortPinLabel = (params) => {
|
|
1579
1687
|
const svgObjects = [];
|
|
@@ -1587,7 +1695,7 @@ var createSvgObjectsForSchPortPinLabel = (params) => {
|
|
|
1587
1695
|
const realPinEdgeDistance = schPort.distance_from_component_edge ?? 0.4;
|
|
1588
1696
|
realPinNumberPos.x += vecToEdge.x * (realPinEdgeDistance + LABEL_DIST_FROM_EDGE_MM);
|
|
1589
1697
|
realPinNumberPos.y += vecToEdge.y * (realPinEdgeDistance + LABEL_DIST_FROM_EDGE_MM);
|
|
1590
|
-
const screenPinNumberTextPos =
|
|
1698
|
+
const screenPinNumberTextPos = applyToPoint19(transform, realPinNumberPos);
|
|
1591
1699
|
const label = schPort.display_pin_label ?? schComponent.port_labels?.[`pin${schPort.pin_number}`];
|
|
1592
1700
|
if (!label) return [];
|
|
1593
1701
|
svgObjects.push({
|
|
@@ -1638,11 +1746,11 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
|
|
|
1638
1746
|
schComponent.source_component_id
|
|
1639
1747
|
);
|
|
1640
1748
|
const svgObjects = [];
|
|
1641
|
-
const componentScreenTopLeft =
|
|
1749
|
+
const componentScreenTopLeft = applyToPoint21(transform, {
|
|
1642
1750
|
x: schComponent.center.x - schComponent.size.width / 2,
|
|
1643
1751
|
y: schComponent.center.y + schComponent.size.height / 2
|
|
1644
1752
|
});
|
|
1645
|
-
const componentScreenBottomRight =
|
|
1753
|
+
const componentScreenBottomRight = applyToPoint21(transform, {
|
|
1646
1754
|
x: schComponent.center.x + schComponent.size.width / 2,
|
|
1647
1755
|
y: schComponent.center.y - schComponent.size.height / 2
|
|
1648
1756
|
});
|
|
@@ -1662,7 +1770,7 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
|
|
|
1662
1770
|
},
|
|
1663
1771
|
children: []
|
|
1664
1772
|
});
|
|
1665
|
-
const screenManufacturerNumberPos =
|
|
1773
|
+
const screenManufacturerNumberPos = applyToPoint21(transform, {
|
|
1666
1774
|
x: schComponent.center.x + schComponent.size.width / 2,
|
|
1667
1775
|
y: schComponent.center.y + schComponent.size.height / 2 + 0.5
|
|
1668
1776
|
// Above the component top edge
|
|
@@ -1746,14 +1854,14 @@ function createSvgObjectsFromSchematicComponent(params) {
|
|
|
1746
1854
|
}
|
|
1747
1855
|
|
|
1748
1856
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
|
|
1749
|
-
import { applyToPoint as
|
|
1857
|
+
import { applyToPoint as applyToPoint22 } from "transformation-matrix";
|
|
1750
1858
|
function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
1751
1859
|
if (debugObject.shape === "rect") {
|
|
1752
|
-
let [screenLeft, screenTop] =
|
|
1860
|
+
let [screenLeft, screenTop] = applyToPoint22(transform, [
|
|
1753
1861
|
debugObject.center.x - debugObject.size.width / 2,
|
|
1754
1862
|
debugObject.center.y - debugObject.size.height / 2
|
|
1755
1863
|
]);
|
|
1756
|
-
let [screenRight, screenBottom] =
|
|
1864
|
+
let [screenRight, screenBottom] = applyToPoint22(transform, [
|
|
1757
1865
|
debugObject.center.x + debugObject.size.width / 2,
|
|
1758
1866
|
debugObject.center.y + debugObject.size.height / 2
|
|
1759
1867
|
]);
|
|
@@ -1763,7 +1871,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1763
1871
|
];
|
|
1764
1872
|
const width = Math.abs(screenRight - screenLeft);
|
|
1765
1873
|
const height = Math.abs(screenBottom - screenTop);
|
|
1766
|
-
const [screenCenterX, screenCenterY] =
|
|
1874
|
+
const [screenCenterX, screenCenterY] = applyToPoint22(transform, [
|
|
1767
1875
|
debugObject.center.x,
|
|
1768
1876
|
debugObject.center.y
|
|
1769
1877
|
]);
|
|
@@ -1809,11 +1917,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1809
1917
|
];
|
|
1810
1918
|
}
|
|
1811
1919
|
if (debugObject.shape === "line") {
|
|
1812
|
-
const [screenStartX, screenStartY] =
|
|
1920
|
+
const [screenStartX, screenStartY] = applyToPoint22(transform, [
|
|
1813
1921
|
debugObject.start.x,
|
|
1814
1922
|
debugObject.start.y
|
|
1815
1923
|
]);
|
|
1816
|
-
const [screenEndX, screenEndY] =
|
|
1924
|
+
const [screenEndX, screenEndY] = applyToPoint22(transform, [
|
|
1817
1925
|
debugObject.end.x,
|
|
1818
1926
|
debugObject.end.y
|
|
1819
1927
|
]);
|
|
@@ -1863,7 +1971,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1863
1971
|
}
|
|
1864
1972
|
|
|
1865
1973
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
|
|
1866
|
-
import { applyToPoint as
|
|
1974
|
+
import { applyToPoint as applyToPoint23 } from "transformation-matrix";
|
|
1867
1975
|
function createSchematicTrace(trace, transform) {
|
|
1868
1976
|
const edges = trace.edges;
|
|
1869
1977
|
if (edges.length === 0) return [];
|
|
@@ -1872,11 +1980,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
1872
1980
|
for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
|
|
1873
1981
|
const edge = edges[edgeIndex];
|
|
1874
1982
|
if (edge.is_crossing) continue;
|
|
1875
|
-
const [screenFromX, screenFromY] =
|
|
1983
|
+
const [screenFromX, screenFromY] = applyToPoint23(transform, [
|
|
1876
1984
|
edge.from.x,
|
|
1877
1985
|
edge.from.y
|
|
1878
1986
|
]);
|
|
1879
|
-
const [screenToX, screenToY] =
|
|
1987
|
+
const [screenToX, screenToY] = applyToPoint23(transform, [
|
|
1880
1988
|
edge.to.x,
|
|
1881
1989
|
edge.to.y
|
|
1882
1990
|
]);
|
|
@@ -1888,11 +1996,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
1888
1996
|
}
|
|
1889
1997
|
for (const edge of edges) {
|
|
1890
1998
|
if (!edge.is_crossing) continue;
|
|
1891
|
-
const [screenFromX, screenFromY] =
|
|
1999
|
+
const [screenFromX, screenFromY] = applyToPoint23(transform, [
|
|
1892
2000
|
edge.from.x,
|
|
1893
2001
|
edge.from.y
|
|
1894
2002
|
]);
|
|
1895
|
-
const [screenToX, screenToY] =
|
|
2003
|
+
const [screenToX, screenToY] = applyToPoint23(transform, [
|
|
1896
2004
|
edge.to.x,
|
|
1897
2005
|
edge.to.y
|
|
1898
2006
|
]);
|
|
@@ -1951,7 +2059,7 @@ function createSchematicTrace(trace, transform) {
|
|
|
1951
2059
|
}
|
|
1952
2060
|
if (trace.junctions) {
|
|
1953
2061
|
for (const junction of trace.junctions) {
|
|
1954
|
-
const [screenX, screenY] =
|
|
2062
|
+
const [screenX, screenY] = applyToPoint23(transform, [
|
|
1955
2063
|
junction.x,
|
|
1956
2064
|
junction.y
|
|
1957
2065
|
]);
|
|
@@ -1974,7 +2082,7 @@ function createSchematicTrace(trace, transform) {
|
|
|
1974
2082
|
|
|
1975
2083
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
|
|
1976
2084
|
import {
|
|
1977
|
-
applyToPoint as
|
|
2085
|
+
applyToPoint as applyToPoint24,
|
|
1978
2086
|
compose as compose6,
|
|
1979
2087
|
rotate as rotate3,
|
|
1980
2088
|
scale as scale3,
|
|
@@ -2770,14 +2878,14 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
2770
2878
|
const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
|
|
2771
2879
|
const fontSizeMm = getSchMmFontSize("net_label");
|
|
2772
2880
|
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
2773
|
-
const screenCenter =
|
|
2881
|
+
const screenCenter = applyToPoint24(realToScreenTransform, schNetLabel.center);
|
|
2774
2882
|
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
2775
2883
|
schNetLabel.anchor_side
|
|
2776
2884
|
);
|
|
2777
2885
|
const screenTextGrowthVec = { ...realTextGrowthVec };
|
|
2778
2886
|
screenTextGrowthVec.y *= -1;
|
|
2779
2887
|
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
2780
|
-
const screenAnchorPosition = schNetLabel.anchor_position ?
|
|
2888
|
+
const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint24(realToScreenTransform, schNetLabel.anchor_position) : {
|
|
2781
2889
|
x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
|
|
2782
2890
|
y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
|
|
2783
2891
|
};
|
|
@@ -2818,7 +2926,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
2818
2926
|
y: -0.6
|
|
2819
2927
|
}
|
|
2820
2928
|
].map(
|
|
2821
|
-
(fontRelativePoint) =>
|
|
2929
|
+
(fontRelativePoint) => applyToPoint24(
|
|
2822
2930
|
compose6(
|
|
2823
2931
|
realToScreenTransform,
|
|
2824
2932
|
translate6(realAnchorPosition.x, realAnchorPosition.y),
|