@tscircuit/circuit-json-util 0.0.93 → 0.0.95

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.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.round(tsr.rotation.angle / (Math.PI / 2)) % 2 === 1;
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 + tsr.rotation.angle / Math.PI * 180;
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 = Math.round(tsr.rotation.angle / (Math.PI / 2));
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) {
@@ -1589,6 +1645,16 @@ var getDebugLayoutObject = (lo) => {
1589
1645
  if ("outer_diameter" in lo) {
1590
1646
  width = lo.outer_diameter;
1591
1647
  height = lo.outer_diameter;
1648
+ } else if ("rect_pad_width" in lo && "rect_pad_height" in lo) {
1649
+ width = lo.rect_pad_width;
1650
+ height = lo.rect_pad_height;
1651
+ if ("hole_diameter" in lo) {
1652
+ width = Math.max(width, lo.hole_diameter);
1653
+ height = Math.max(height, lo.hole_diameter);
1654
+ }
1655
+ } else if ("hole_diameter" in lo) {
1656
+ width = lo.hole_diameter;
1657
+ height = lo.hole_diameter;
1592
1658
  }
1593
1659
  }
1594
1660
  if (width === void 0 || height === void 0) {
@@ -2445,6 +2511,7 @@ export {
2445
2511
  rotateCounterClockwise,
2446
2512
  rotateDirection,
2447
2513
  su,
2514
+ transformInsertionDirection,
2448
2515
  transformPCBElement,
2449
2516
  transformPCBElements,
2450
2517
  transformPCBElement as transformPcbElement,