@tscircuit/circuit-json-util 0.0.128 → 0.0.130

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
@@ -832,7 +832,7 @@ var cju_indexed_default = cjuIndexed;
832
832
 
833
833
  // lib/transform-soup-elements.ts
834
834
  import {
835
- applyToPoint,
835
+ applyToPoint as applyToPoint2,
836
836
  compose,
837
837
  decomposeTSR,
838
838
  rotateDEG
@@ -895,6 +895,33 @@ var oppositeSide = (sideOrDir) => {
895
895
  throw new Error(`Invalid sideOrDir: ${sideOrDir}`);
896
896
  };
897
897
 
898
+ // lib/transform-brep-shape.ts
899
+ import { applyToPoint } from "transformation-matrix";
900
+ var transformBrepRing = (ring, matrix) => {
901
+ const vertices = ring.vertices.map((vertex) => ({
902
+ ...vertex,
903
+ ...applyToPoint(matrix, vertex)
904
+ }));
905
+ if (matrix.a * matrix.d - matrix.b * matrix.c < 0) {
906
+ vertices.reverse();
907
+ const vertexCount = vertices.length;
908
+ for (const [index, vertex] of vertices.entries()) {
909
+ const precedingIndex = (2 * vertexCount - index - 2) % vertexCount;
910
+ const precedingBulge = ring.vertices[precedingIndex].bulge;
911
+ delete vertex.bulge;
912
+ if (precedingBulge !== void 0) vertex.bulge = precedingBulge;
913
+ }
914
+ }
915
+ return { ...ring, vertices };
916
+ };
917
+ var transformBrepShape = (brepShape, matrix) => ({
918
+ ...brepShape,
919
+ outer_ring: transformBrepRing(brepShape.outer_ring, matrix),
920
+ inner_rings: brepShape.inner_rings.map(
921
+ (ring) => transformBrepRing(ring, matrix)
922
+ )
923
+ });
924
+
898
925
  // lib/transform-soup-elements.ts
899
926
  var getQuarterTurns = (angleRadians) => Math.round(angleRadians / (Math.PI / 2));
900
927
  var insertionDirectionToVec = (direction) => {
@@ -943,9 +970,9 @@ var transformInsertionDirection = (direction, opts) => {
943
970
  };
944
971
  var transformSchematicElement = (elm, matrix) => {
945
972
  if (elm.type === "schematic_component") {
946
- elm.center = applyToPoint(matrix, elm.center);
973
+ elm.center = applyToPoint2(matrix, elm.center);
947
974
  } else if (elm.type === "schematic_port") {
948
- elm.center = applyToPoint(matrix, elm.center);
975
+ elm.center = applyToPoint2(matrix, elm.center);
949
976
  if (elm.facing_direction) {
950
977
  elm.facing_direction = rotateDirection(
951
978
  elm.facing_direction,
@@ -953,18 +980,18 @@ var transformSchematicElement = (elm, matrix) => {
953
980
  );
954
981
  }
955
982
  } else if (elm.type === "schematic_text") {
956
- elm.position = applyToPoint(matrix, elm.position);
983
+ elm.position = applyToPoint2(matrix, elm.position);
957
984
  } else if (elm.type === "schematic_trace") {
958
985
  const anyElm = elm;
959
986
  anyElm.route = (anyElm.route ?? []).map((rp) => {
960
- const tp = applyToPoint(matrix, rp);
987
+ const tp = applyToPoint2(matrix, rp);
961
988
  rp.x = tp.x;
962
989
  rp.y = tp.y;
963
990
  return rp;
964
991
  });
965
992
  if (Array.isArray(anyElm.junctions)) {
966
993
  anyElm.junctions = anyElm.junctions.map((j) => {
967
- const tp = applyToPoint(matrix, j);
994
+ const tp = applyToPoint2(matrix, j);
968
995
  j.x = tp.x;
969
996
  j.y = tp.y;
970
997
  return j;
@@ -972,18 +999,18 @@ var transformSchematicElement = (elm, matrix) => {
972
999
  }
973
1000
  if (Array.isArray(anyElm.edges)) {
974
1001
  anyElm.edges = anyElm.edges.map((e) => {
975
- e.from = applyToPoint(matrix, e.from);
976
- e.to = applyToPoint(matrix, e.to);
1002
+ e.from = applyToPoint2(matrix, e.from);
1003
+ e.to = applyToPoint2(matrix, e.to);
977
1004
  return e;
978
1005
  });
979
1006
  }
980
1007
  } else if (elm.type === "schematic_box") {
981
- const { x, y } = applyToPoint(matrix, { x: elm.x, y: elm.y });
1008
+ const { x, y } = applyToPoint2(matrix, { x: elm.x, y: elm.y });
982
1009
  elm.x = x;
983
1010
  elm.y = y;
984
1011
  } else if (elm.type === "schematic_line") {
985
- const { x: x1, y: y1 } = applyToPoint(matrix, { x: elm.x1, y: elm.y1 });
986
- const { x: x2, y: y2 } = applyToPoint(matrix, { x: elm.x2, y: elm.y2 });
1012
+ const { x: x1, y: y1 } = applyToPoint2(matrix, { x: elm.x1, y: elm.y1 });
1013
+ const { x: x2, y: y2 } = applyToPoint2(matrix, { x: elm.x2, y: elm.y2 });
987
1014
  elm.x1 = x1;
988
1015
  elm.y1 = y1;
989
1016
  elm.x2 = x2;
@@ -999,7 +1026,7 @@ var getTransformedRectRotation = (rotation, matrix) => {
999
1026
  return decomposeTSR(compose(matrix, rotateDEG(rotation)), false, isReflected).rotation.angle * 180 / Math.PI;
1000
1027
  };
1001
1028
  var transformPcbSolderPasteRectangle = (paste, matrix) => {
1002
- const center = applyToPoint(matrix, { x: paste.x, y: paste.y });
1029
+ const center = applyToPoint2(matrix, { x: paste.x, y: paste.y });
1003
1030
  paste.x = center.x;
1004
1031
  paste.y = center.y;
1005
1032
  const rotation = getTransformedRectRotation(
@@ -1021,10 +1048,10 @@ var transformPcbSolderPasteRectangle = (paste, matrix) => {
1021
1048
  };
1022
1049
  var transformPcbSoldermaskOpening = (opening, matrix) => {
1023
1050
  if (opening.shape === "polygon") {
1024
- opening.points = opening.points.map((point) => applyToPoint(matrix, point));
1051
+ opening.points = opening.points.map((point) => applyToPoint2(matrix, point));
1025
1052
  return opening;
1026
1053
  }
1027
- const center = applyToPoint(matrix, { x: opening.x, y: opening.y });
1054
+ const center = applyToPoint2(matrix, { x: opening.x, y: opening.y });
1028
1055
  opening.x = center.x;
1029
1056
  opening.y = center.y;
1030
1057
  if (opening.shape === "circle") return opening;
@@ -1042,13 +1069,17 @@ var transformPcbSoldermaskOpening = (opening, matrix) => {
1042
1069
  return opening;
1043
1070
  };
1044
1071
  var transformPCBElement = (elm, matrix) => {
1072
+ if (elm.type === "pcb_copper_pour" && elm.shape === "brep") {
1073
+ elm.brep_shape = transformBrepShape(elm.brep_shape, matrix);
1074
+ return elm;
1075
+ }
1045
1076
  if (elm.type === "pcb_cutout") {
1046
1077
  if (elm.shape === "polygon") {
1047
- elm.points = elm.points.map((point) => applyToPoint(matrix, point));
1078
+ elm.points = elm.points.map((point) => applyToPoint2(matrix, point));
1048
1079
  } else if (elm.shape === "path") {
1049
- elm.route = elm.route.map((point) => applyToPoint(matrix, point));
1080
+ elm.route = elm.route.map((point) => applyToPoint2(matrix, point));
1050
1081
  } else {
1051
- elm.center = applyToPoint(matrix, elm.center);
1082
+ elm.center = applyToPoint2(matrix, elm.center);
1052
1083
  if (elm.shape === "rect") {
1053
1084
  elm.rotation = getTransformedRectRotation(elm.rotation ?? 0, matrix);
1054
1085
  }
@@ -1062,10 +1093,10 @@ var transformPCBElement = (elm, matrix) => {
1062
1093
  return transformPcbSolderPasteRectangle(elm, matrix);
1063
1094
  }
1064
1095
  if ((elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste") && elm.shape === "polygon") {
1065
- elm.points = elm.points.map((point) => applyToPoint(matrix, point));
1096
+ elm.points = elm.points.map((point) => applyToPoint2(matrix, point));
1066
1097
  if (elm.type === "pcb_solder_paste" && elm.holes) {
1067
1098
  elm.holes = elm.holes.map(
1068
- (hole) => hole.map((point) => applyToPoint(matrix, point))
1099
+ (hole) => hole.map((point) => applyToPoint2(matrix, point))
1069
1100
  );
1070
1101
  }
1071
1102
  return elm;
@@ -1075,7 +1106,7 @@ var transformPCBElement = (elm, matrix) => {
1075
1106
  const rotationDegrees = tsr.rotation.angle / Math.PI * 180;
1076
1107
  const isFlipped = tsr.scale.sy < 0;
1077
1108
  if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste" || elm.type === "pcb_port") {
1078
- const { x, y } = applyToPoint(matrix, {
1109
+ const { x, y } = applyToPoint2(matrix, {
1079
1110
  x: elm.x,
1080
1111
  y: elm.y
1081
1112
  });
@@ -1085,33 +1116,33 @@ var transformPCBElement = (elm, matrix) => {
1085
1116
  elm.ccw_rotation = getTransformedRectRotation(elm.ccw_rotation, matrix);
1086
1117
  }
1087
1118
  } else if (elm.type === "pcb_keepout" && elm.shape === "outline") {
1088
- elm.outline = elm.outline.map((point) => applyToPoint(matrix, point));
1119
+ elm.outline = elm.outline.map((point) => applyToPoint2(matrix, point));
1089
1120
  } else if (elm.type === "pcb_keepout" || elm.type === "pcb_board") {
1090
- elm.center = applyToPoint(matrix, elm.center);
1121
+ elm.center = applyToPoint2(matrix, elm.center);
1091
1122
  } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text" || elm.type === "pcb_note_text") {
1092
- elm.anchor_position = applyToPoint(matrix, elm.anchor_position);
1123
+ elm.anchor_position = applyToPoint2(matrix, elm.anchor_position);
1093
1124
  if (elm.type === "pcb_silkscreen_text") {
1094
1125
  const textTransform = compose(matrix, rotateDEG(elm.ccw_rotation ?? 0));
1095
1126
  elm.ccw_rotation = Math.atan2(textTransform.b, textTransform.a) * 180 / Math.PI;
1096
1127
  }
1097
1128
  } else if (elm.type === "pcb_copper_text") {
1098
1129
  if (elm.anchor_position) {
1099
- elm.anchor_position = applyToPoint(matrix, elm.anchor_position);
1130
+ elm.anchor_position = applyToPoint2(matrix, elm.anchor_position);
1100
1131
  }
1101
1132
  } else if (elm.type === "pcb_courtyard_rect") {
1102
- elm.center = applyToPoint(matrix, elm.center);
1133
+ elm.center = applyToPoint2(matrix, elm.center);
1103
1134
  elm.ccw_rotation = getTransformedRectRotation(elm.ccw_rotation ?? 0, matrix);
1104
1135
  } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_silkscreen_pill" || elm.type === "pcb_silkscreen_oval" || elm.type === "pcb_note_rect" || elm.type === "pcb_courtyard_circle") {
1105
- elm.center = applyToPoint(matrix, elm.center);
1136
+ elm.center = applyToPoint2(matrix, elm.center);
1106
1137
  } else if (elm.type === "pcb_component") {
1107
- elm.center = applyToPoint(matrix, elm.center);
1138
+ elm.center = applyToPoint2(matrix, elm.center);
1108
1139
  if (elm.footprint_origin) {
1109
- elm.footprint_origin = applyToPoint(matrix, elm.footprint_origin);
1140
+ elm.footprint_origin = applyToPoint2(matrix, elm.footprint_origin);
1110
1141
  }
1111
1142
  elm.rotation = elm.rotation + rotationDegrees;
1112
1143
  elm.rotation = elm.rotation % 360;
1113
1144
  if (elm.cable_insertion_center) {
1114
- elm.cable_insertion_center = applyToPoint(
1145
+ elm.cable_insertion_center = applyToPoint2(
1115
1146
  matrix,
1116
1147
  elm.cable_insertion_center
1117
1148
  );
@@ -1129,14 +1160,14 @@ var transformPCBElement = (elm, matrix) => {
1129
1160
  }
1130
1161
  } else if (elm.type === "pcb_courtyard_outline") {
1131
1162
  elm.outline = elm.outline.map((p) => {
1132
- const tp = applyToPoint(matrix, p);
1163
+ const tp = applyToPoint2(matrix, p);
1133
1164
  p.x = tp.x;
1134
1165
  p.y = tp.y;
1135
1166
  return p;
1136
1167
  });
1137
1168
  } else if (elm.type === "pcb_courtyard_polygon") {
1138
1169
  elm.points = elm.points.map((p) => {
1139
- const tp = applyToPoint(matrix, p);
1170
+ const tp = applyToPoint2(matrix, p);
1140
1171
  p.x = tp.x;
1141
1172
  p.y = tp.y;
1142
1173
  return p;
@@ -1144,18 +1175,18 @@ var transformPCBElement = (elm, matrix) => {
1144
1175
  } else if (elm.type === "pcb_trace") {
1145
1176
  elm.route = elm.route.map((rp) => {
1146
1177
  if (!("x" in rp)) {
1147
- rp.start = applyToPoint(matrix, rp.start);
1148
- rp.end = applyToPoint(matrix, rp.end);
1178
+ rp.start = applyToPoint2(matrix, rp.start);
1179
+ rp.end = applyToPoint2(matrix, rp.end);
1149
1180
  return rp;
1150
1181
  }
1151
- const tp = applyToPoint(matrix, rp);
1182
+ const tp = applyToPoint2(matrix, rp);
1152
1183
  rp.x = tp.x;
1153
1184
  rp.y = tp.y;
1154
1185
  return rp;
1155
1186
  });
1156
1187
  } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace_hint" || elm.type === "pcb_fabrication_note_path" || elm.type === "pcb_note_path") {
1157
1188
  elm.route = elm.route.map((rp) => {
1158
- const tp = applyToPoint(matrix, rp);
1189
+ const tp = applyToPoint2(matrix, rp);
1159
1190
  rp.x = tp.x;
1160
1191
  rp.y = tp.y;
1161
1192
  return rp;
@@ -1163,14 +1194,14 @@ var transformPCBElement = (elm, matrix) => {
1163
1194
  } else if (elm.type === "pcb_silkscreen_line" || elm.type === "pcb_note_line") {
1164
1195
  const p1 = { x: elm.x1, y: elm.y1 };
1165
1196
  const p2 = { x: elm.x2, y: elm.y2 };
1166
- const p1t = applyToPoint(matrix, p1);
1167
- const p2t = applyToPoint(matrix, p2);
1197
+ const p1t = applyToPoint2(matrix, p1);
1198
+ const p2t = applyToPoint2(matrix, p2);
1168
1199
  elm.x1 = p1t.x;
1169
1200
  elm.y1 = p1t.y;
1170
1201
  elm.x2 = p2t.x;
1171
1202
  elm.y2 = p2t.y;
1172
1203
  } else if (elm.type === "cad_component") {
1173
- const newPos = applyToPoint(matrix, {
1204
+ const newPos = applyToPoint2(matrix, {
1174
1205
  x: elm.position.x,
1175
1206
  y: elm.position.y
1176
1207
  });
@@ -1405,6 +1436,12 @@ var getReadableNameForElement = (soup, elm) => {
1405
1436
  };
1406
1437
 
1407
1438
  // lib/get-bounds-of-pcb-elements.ts
1439
+ import {
1440
+ applyToPoint as applyToPoint3,
1441
+ compose as compose2,
1442
+ rotateDEG as rotateDEG2,
1443
+ translate
1444
+ } from "transformation-matrix";
1408
1445
  var mergeBounds = (currentBounds, nextBounds) => ({
1409
1446
  minX: Math.min(currentBounds.minX, nextBounds.minX),
1410
1447
  minY: Math.min(currentBounds.minY, nextBounds.minY),
@@ -1545,6 +1582,22 @@ var getPcbElementBounds = (elm) => {
1545
1582
  );
1546
1583
  platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
1547
1584
  }
1585
+ if (elm.shape === "hole_with_polygon_pad") {
1586
+ const matrix = compose2(
1587
+ translate(elm.x, elm.y),
1588
+ rotateDEG2(elm.ccw_rotation ?? 0)
1589
+ );
1590
+ const outlineBounds2 = getBoundsFromPoints(
1591
+ elm.pad_outline.map((point) => applyToPoint3(matrix, point))
1592
+ );
1593
+ if (outlineBounds2) {
1594
+ if (platedHoleBounds) {
1595
+ platedHoleBounds = mergeBounds(platedHoleBounds, outlineBounds2);
1596
+ } else {
1597
+ platedHoleBounds = outlineBounds2;
1598
+ }
1599
+ }
1600
+ }
1548
1601
  if (platedHoleBounds) return platedHoleBounds;
1549
1602
  }
1550
1603
  const elementRecord = elm;
@@ -2080,7 +2133,7 @@ var getPrimaryId = (element) => {
2080
2133
  };
2081
2134
 
2082
2135
  // lib/reposition-pcb-component.ts
2083
- import { translate } from "transformation-matrix";
2136
+ import { translate as translate2 } from "transformation-matrix";
2084
2137
  var repositionPcbComponentTo = (circuitJson, pcb_component_id, newCenter) => {
2085
2138
  const pcbComponent = circuitJson.find(
2086
2139
  (e) => e.type === "pcb_component" && e.pcb_component_id === pcb_component_id
@@ -2111,12 +2164,12 @@ var repositionPcbComponentTo = (circuitJson, pcb_component_id, newCenter) => {
2111
2164
  return true;
2112
2165
  return false;
2113
2166
  });
2114
- const matrix = translate(dx, dy);
2167
+ const matrix = translate2(dx, dy);
2115
2168
  transformPCBElements(elementsToMove, matrix);
2116
2169
  };
2117
2170
 
2118
2171
  // lib/reposition-pcb-group.ts
2119
- import { translate as translate2 } from "transformation-matrix";
2172
+ import { translate as translate3 } from "transformation-matrix";
2120
2173
  var findAllDescendantGroupIds = (circuitJson, parentGroupId) => {
2121
2174
  const childGroupIds = [];
2122
2175
  const directChildren = circuitJson.filter(
@@ -2163,12 +2216,12 @@ var repositionPcbGroupTo = (circuitJson, source_group_id, newCenter) => {
2163
2216
  const { center: currentCenter } = findBoundsAndCenter(pcbElements);
2164
2217
  const dx = newCenter.x - currentCenter.x;
2165
2218
  const dy = newCenter.y - currentCenter.y;
2166
- const matrix = translate2(dx, dy);
2219
+ const matrix = translate3(dx, dy);
2167
2220
  transformPCBElements(pcbElements, matrix);
2168
2221
  };
2169
2222
 
2170
2223
  // lib/reposition-schematic-component.ts
2171
- import { translate as translate3 } from "transformation-matrix";
2224
+ import { translate as translate4 } from "transformation-matrix";
2172
2225
  var repositionSchematicComponentTo = (circuitJson, schematic_component_id, newCenter) => {
2173
2226
  const schematicComponent = circuitJson.find(
2174
2227
  (e) => e.type === "schematic_component" && e.schematic_component_id === schematic_component_id
@@ -2200,12 +2253,12 @@ var repositionSchematicComponentTo = (circuitJson, schematic_component_id, newCe
2200
2253
  return true;
2201
2254
  return false;
2202
2255
  });
2203
- const matrix = translate3(dx, dy);
2256
+ const matrix = translate4(dx, dy);
2204
2257
  transformSchematicElements(elementsToMove, matrix);
2205
2258
  };
2206
2259
 
2207
2260
  // lib/reposition-schematic-group.ts
2208
- import { translate as translate4 } from "transformation-matrix";
2261
+ import { translate as translate5 } from "transformation-matrix";
2209
2262
  var findAllDescendantGroupIds2 = (circuitJson, parentGroupId) => {
2210
2263
  const childGroupIds = [];
2211
2264
  const directChildren = circuitJson.filter(
@@ -2252,7 +2305,7 @@ var repositionSchematicGroupTo = (circuitJson, source_group_id, newCenter) => {
2252
2305
  const { center: currentCenter } = findBoundsAndCenter(schematicElements);
2253
2306
  const dx = newCenter.x - currentCenter.x;
2254
2307
  const dy = newCenter.y - currentCenter.y;
2255
- const matrix = translate4(dx, dy);
2308
+ const matrix = translate5(dx, dy);
2256
2309
  transformSchematicElements(schematicElements, matrix);
2257
2310
  };
2258
2311
 
@@ -3028,10 +3081,10 @@ import {
3028
3081
  Segment,
3029
3082
  Utils
3030
3083
  } from "@flatten-js/core";
3031
- import { compose as compose2, rotate, translate as translate5 } from "transformation-matrix";
3084
+ import { compose as compose3, rotate, translate as translate6 } from "transformation-matrix";
3032
3085
  var placePolygon = (polygon, center, degrees = 0) => {
3033
- const { a, b, c, d, e, f } = compose2(
3034
- translate5(center.x, center.y),
3086
+ const { a, b, c, d, e, f } = compose3(
3087
+ translate6(center.x, center.y),
3035
3088
  rotate(degrees * Math.PI / 180)
3036
3089
  );
3037
3090
  return polygon.transform(new Matrix(a, b, c, d, e, f));