@tscircuit/circuit-json-util 0.0.92 → 0.0.94
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 +403 -29
- package/dist/index.js +64 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -877,6 +877,47 @@ var oppositeSide = (sideOrDir) => {
|
|
|
877
877
|
};
|
|
878
878
|
|
|
879
879
|
// lib/transform-soup-elements.ts
|
|
880
|
+
var getQuarterTurns = (angleRadians) => Math.round(angleRadians / (Math.PI / 2));
|
|
881
|
+
var insertionDirectionToVec = (direction) => {
|
|
882
|
+
switch (direction) {
|
|
883
|
+
case "from_left":
|
|
884
|
+
return { x: -1, y: 0 };
|
|
885
|
+
case "from_right":
|
|
886
|
+
return { x: 1, y: 0 };
|
|
887
|
+
case "from_front":
|
|
888
|
+
return { x: 0, y: 1 };
|
|
889
|
+
case "from_back":
|
|
890
|
+
return { x: 0, y: -1 };
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
var vecToInsertionDirection = ({
|
|
894
|
+
x,
|
|
895
|
+
y
|
|
896
|
+
}) => {
|
|
897
|
+
if (x > 0) return "from_right";
|
|
898
|
+
if (x < 0) return "from_left";
|
|
899
|
+
if (y > 0) return "from_front";
|
|
900
|
+
return "from_back";
|
|
901
|
+
};
|
|
902
|
+
var transformInsertionDirection = (direction, opts) => {
|
|
903
|
+
if (!direction || direction === "from_above") return direction;
|
|
904
|
+
let { x, y } = insertionDirectionToVec(direction);
|
|
905
|
+
let quarterTurns = Math.round(opts.rotationDegrees / 90);
|
|
906
|
+
while (quarterTurns > 0) {
|
|
907
|
+
;
|
|
908
|
+
[x, y] = [-y, x];
|
|
909
|
+
quarterTurns--;
|
|
910
|
+
}
|
|
911
|
+
while (quarterTurns < 0) {
|
|
912
|
+
;
|
|
913
|
+
[x, y] = [y, -x];
|
|
914
|
+
quarterTurns++;
|
|
915
|
+
}
|
|
916
|
+
if (opts.isFlipped) {
|
|
917
|
+
y = -y;
|
|
918
|
+
}
|
|
919
|
+
return vecToInsertionDirection({ x, y });
|
|
920
|
+
};
|
|
880
921
|
var transformSchematicElement = (elm, matrix) => {
|
|
881
922
|
if (elm.type === "schematic_component") {
|
|
882
923
|
elm.center = applyToPoint(matrix, elm.center);
|
|
@@ -932,7 +973,9 @@ var transformSchematicElements = (elms, matrix) => {
|
|
|
932
973
|
};
|
|
933
974
|
var transformPCBElement = (elm, matrix) => {
|
|
934
975
|
const tsr = decomposeTSR(matrix);
|
|
935
|
-
const flipPadWidthHeight = Math.
|
|
976
|
+
const flipPadWidthHeight = Math.abs(getQuarterTurns(tsr.rotation.angle)) % 2 === 1;
|
|
977
|
+
const rotationDegrees = tsr.rotation.angle / Math.PI * 180;
|
|
978
|
+
const isFlipped = tsr.scale.sy < 0;
|
|
936
979
|
if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_port") {
|
|
937
980
|
const { x, y } = applyToPoint(matrix, {
|
|
938
981
|
x: Number(elm.x),
|
|
@@ -957,8 +1000,21 @@ var transformPCBElement = (elm, matrix) => {
|
|
|
957
1000
|
elm.center = applyToPoint(matrix, elm.center);
|
|
958
1001
|
} else if (elm.type === "pcb_component") {
|
|
959
1002
|
elm.center = applyToPoint(matrix, elm.center);
|
|
960
|
-
elm.rotation = elm.rotation +
|
|
1003
|
+
elm.rotation = elm.rotation + rotationDegrees;
|
|
961
1004
|
elm.rotation = elm.rotation % 360;
|
|
1005
|
+
if (elm.cable_insertion_center) {
|
|
1006
|
+
elm.cable_insertion_center = applyToPoint(
|
|
1007
|
+
matrix,
|
|
1008
|
+
elm.cable_insertion_center
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
elm.insertion_direction = transformInsertionDirection(
|
|
1012
|
+
elm.insertion_direction,
|
|
1013
|
+
{
|
|
1014
|
+
rotationDegrees,
|
|
1015
|
+
isFlipped
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
962
1018
|
if (flipPadWidthHeight) {
|
|
963
1019
|
;
|
|
964
1020
|
[elm.width, elm.height] = [elm.height, elm.width];
|
|
@@ -1005,7 +1061,7 @@ var transformPCBElement = (elm, matrix) => {
|
|
|
1005
1061
|
};
|
|
1006
1062
|
var transformPCBElements = (elms, matrix) => {
|
|
1007
1063
|
const tsr = decomposeTSR(matrix);
|
|
1008
|
-
const quarterTurns =
|
|
1064
|
+
const quarterTurns = getQuarterTurns(tsr.rotation.angle);
|
|
1009
1065
|
const flipPadWidthHeight = Math.abs(quarterTurns) % 2 === 1;
|
|
1010
1066
|
let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
|
|
1011
1067
|
if (flipPadWidthHeight) {
|
|
@@ -2417,6 +2473,10 @@ export {
|
|
|
2417
2473
|
computeClearanceBetweenElements,
|
|
2418
2474
|
computeGapBetweenCopper,
|
|
2419
2475
|
directionToVec,
|
|
2476
|
+
distanceBetweenCircleAndCircle,
|
|
2477
|
+
distanceBetweenCircleAndPolygon,
|
|
2478
|
+
distanceBetweenPolygonAndPolygon,
|
|
2479
|
+
distanceBetweenShapes,
|
|
2420
2480
|
findBoundsAndCenter,
|
|
2421
2481
|
getBoardBounds,
|
|
2422
2482
|
getBoundsOfPcbElements,
|
|
@@ -2441,6 +2501,7 @@ export {
|
|
|
2441
2501
|
rotateCounterClockwise,
|
|
2442
2502
|
rotateDirection,
|
|
2443
2503
|
su,
|
|
2504
|
+
transformInsertionDirection,
|
|
2444
2505
|
transformPCBElement,
|
|
2445
2506
|
transformPCBElements,
|
|
2446
2507
|
transformPCBElement as transformPcbElement,
|