@tscircuit/circuit-json-util 0.0.130 → 0.0.132

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as circuit_json from 'circuit-json';
2
- import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbSolderPasteRect, PcbSolderPasteRotatedRect, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbVia, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad } from 'circuit-json';
2
+ import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbSolderPasteRect, PcbSolderPasteRotatedRect, PcbSolderPastePill, PcbSolderPasteRotatedPill, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbVia, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad } from 'circuit-json';
3
3
  import * as zod from 'zod';
4
4
  import { Matrix } from 'transformation-matrix';
5
5
  import * as parsel from 'parsel-js';
@@ -13231,35 +13231,6 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
13231
13231
  subcircuit_id?: string | undefined;
13232
13232
  pcb_group_id?: string | undefined;
13233
13233
  pcb_smtpad_id?: string | undefined;
13234
- } | {
13235
- type: "pcb_solder_paste";
13236
- x: number;
13237
- y: number;
13238
- width: number;
13239
- height: number;
13240
- shape: "pill";
13241
- radius: number;
13242
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
13243
- pcb_solder_paste_id: string;
13244
- pcb_component_id?: string | undefined;
13245
- subcircuit_id?: string | undefined;
13246
- pcb_group_id?: string | undefined;
13247
- pcb_smtpad_id?: string | undefined;
13248
- } | {
13249
- type: "pcb_solder_paste";
13250
- x: number;
13251
- y: number;
13252
- width: number;
13253
- height: number;
13254
- shape: "rotated_pill";
13255
- radius: number;
13256
- ccw_rotation: number;
13257
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
13258
- pcb_solder_paste_id: string;
13259
- pcb_component_id?: string | undefined;
13260
- subcircuit_id?: string | undefined;
13261
- pcb_group_id?: string | undefined;
13262
- pcb_smtpad_id?: string | undefined;
13263
13234
  } | {
13264
13235
  type: "pcb_solder_paste";
13265
13236
  x: number;
@@ -16810,7 +16781,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
16810
16781
  simulation_spice_subcircuit_id: string;
16811
16782
  spice_pin_to_source_port_map: Record<string, string>;
16812
16783
  subcircuit_source: string;
16813
- } | PcbSolderPasteRect | PcbSolderPasteRotatedRect | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon;
16784
+ } | PcbSolderPasteRect | PcbSolderPasteRotatedRect | PcbSolderPastePill | PcbSolderPasteRotatedPill | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon;
16814
16785
  declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix) => ({
16815
16786
  message: string;
16816
16787
  type: "source_runtime_error";
@@ -18517,35 +18488,6 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
18517
18488
  subcircuit_id?: string | undefined;
18518
18489
  pcb_group_id?: string | undefined;
18519
18490
  pcb_smtpad_id?: string | undefined;
18520
- } | {
18521
- type: "pcb_solder_paste";
18522
- x: number;
18523
- y: number;
18524
- width: number;
18525
- height: number;
18526
- shape: "pill";
18527
- radius: number;
18528
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
18529
- pcb_solder_paste_id: string;
18530
- pcb_component_id?: string | undefined;
18531
- subcircuit_id?: string | undefined;
18532
- pcb_group_id?: string | undefined;
18533
- pcb_smtpad_id?: string | undefined;
18534
- } | {
18535
- type: "pcb_solder_paste";
18536
- x: number;
18537
- y: number;
18538
- width: number;
18539
- height: number;
18540
- shape: "rotated_pill";
18541
- radius: number;
18542
- ccw_rotation: number;
18543
- layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
18544
- pcb_solder_paste_id: string;
18545
- pcb_component_id?: string | undefined;
18546
- subcircuit_id?: string | undefined;
18547
- pcb_group_id?: string | undefined;
18548
- pcb_smtpad_id?: string | undefined;
18549
18491
  } | {
18550
18492
  type: "pcb_solder_paste";
18551
18493
  x: number;
@@ -22096,7 +22038,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
22096
22038
  simulation_spice_subcircuit_id: string;
22097
22039
  spice_pin_to_source_port_map: Record<string, string>;
22098
22040
  subcircuit_source: string;
22099
- } | PcbSolderPasteRect | PcbSolderPasteRotatedRect | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon)[];
22041
+ } | PcbSolderPasteRect | PcbSolderPasteRotatedRect | PcbSolderPastePill | PcbSolderPasteRotatedPill | circuit_json.PcbSoldermaskOpeningCircle | circuit_json.PcbSoldermaskOpeningRect | circuit_json.PcbSoldermaskOpeningRotatedRect | circuit_json.PcbSoldermaskOpeningPolygon)[];
22100
22042
 
22101
22043
  declare const directionToVec: (direction: "up" | "down" | "left" | "right") => {
22102
22044
  x: number;
@@ -22263,18 +22205,29 @@ declare function getMinimumFlexContainer(children: Array<{
22263
22205
  declare function getElementRenderLayers(element: AnyCircuitElement): PcbRenderLayer[];
22264
22206
 
22265
22207
  type ViaGeometry = Pick<PcbVia, "x" | "y"> & Partial<Pick<PcbVia, "outer_diameter" | "hole_diameter">>;
22266
- /**
22267
- * Checks whether a physical via covers a route transition at the same position
22268
- * with compatible dimensions. Callers must check electrical connectivity
22269
- * separately. Missing route dimensions use the physical via's dimensions;
22270
- * missing or unknown layers cannot establish coverage.
22271
- */
22272
- declare function isRouteViaCoveredByPhysicalVia(physicalVia: ViaGeometry & {
22208
+ type ViaWithLayers = ViaGeometry & {
22273
22209
  layers?: readonly string[];
22274
- }, routeVia: ViaGeometry & {
22210
+ };
22211
+ type RouteViaGeometry = ViaGeometry & {
22275
22212
  from_layer?: string;
22276
22213
  to_layer?: string;
22277
- }): boolean;
22214
+ };
22215
+ type RouteViaCoverageOptions = {
22216
+ viaWithLayers: ViaWithLayers;
22217
+ routeVia: RouteViaGeometry;
22218
+ positionTolerance?: number;
22219
+ };
22220
+ /**
22221
+ * Checks whether a via with explicit layers covers a route transition at the
22222
+ * same position with compatible dimensions. Callers must check electrical
22223
+ * connectivity separately. Missing route dimensions use the layered via's dimensions;
22224
+ * missing or unknown layers cannot establish coverage.
22225
+ * Position tolerance is an inclusive limit per axis in mm, defaulting to zero.
22226
+ * Use the named options object to opt in; two-argument calls remain exact.
22227
+ * Neither input is modified.
22228
+ */
22229
+ declare function isRouteViaCoveredByPhysicalVia(options: RouteViaCoverageOptions): boolean;
22230
+ declare function isRouteViaCoveredByPhysicalVia(viaWithLayers: ViaWithLayers, routeVia: RouteViaGeometry): boolean;
22278
22231
 
22279
22232
  declare const computeGapBetweenCopper: (elm1: AnyCircuitElement, elm2: AnyCircuitElement) => number;
22280
22233
 
package/dist/index.js CHANGED
@@ -1025,12 +1025,13 @@ var getTransformedRectRotation = (rotation, matrix) => {
1025
1025
  const isReflected = matrix.a * matrix.d - matrix.b * matrix.c < 0;
1026
1026
  return decomposeTSR(compose(matrix, rotateDEG(rotation)), false, isReflected).rotation.angle * 180 / Math.PI;
1027
1027
  };
1028
- var transformPcbSolderPasteRectangle = (paste, matrix) => {
1028
+ var transformPcbSolderPasteRectOrPill = (paste, matrix) => {
1029
1029
  const center = applyToPoint2(matrix, { x: paste.x, y: paste.y });
1030
1030
  paste.x = center.x;
1031
1031
  paste.y = center.y;
1032
+ const isPill = paste.shape === "pill" || paste.shape === "rotated_pill";
1032
1033
  const rotation = getTransformedRectRotation(
1033
- paste.shape === "rotated_rect" ? paste.ccw_rotation : 0,
1034
+ "ccw_rotation" in paste ? paste.ccw_rotation : 0,
1034
1035
  matrix
1035
1036
  );
1036
1037
  const quarterTurns = Math.round(rotation / 90);
@@ -1039,10 +1040,13 @@ var transformPcbSolderPasteRectangle = (paste, matrix) => {
1039
1040
  ;
1040
1041
  [paste.width, paste.height] = [paste.height, paste.width];
1041
1042
  }
1042
- Object.assign(paste, { shape: "rect" });
1043
+ Object.assign(paste, { shape: isPill ? "pill" : "rect" });
1043
1044
  Reflect.deleteProperty(paste, "ccw_rotation");
1044
1045
  } else {
1045
- Object.assign(paste, { shape: "rotated_rect", ccw_rotation: rotation });
1046
+ Object.assign(paste, {
1047
+ shape: isPill ? "rotated_pill" : "rotated_rect",
1048
+ ccw_rotation: rotation
1049
+ });
1046
1050
  }
1047
1051
  return paste;
1048
1052
  };
@@ -1089,8 +1093,8 @@ var transformPCBElement = (elm, matrix) => {
1089
1093
  if (elm.type === "pcb_soldermask_opening") {
1090
1094
  return transformPcbSoldermaskOpening(elm, matrix);
1091
1095
  }
1092
- if (elm.type === "pcb_solder_paste" && (elm.shape === "rect" || elm.shape === "rotated_rect")) {
1093
- return transformPcbSolderPasteRectangle(elm, matrix);
1096
+ if (elm.type === "pcb_solder_paste" && (elm.shape === "rect" || elm.shape === "rotated_rect" || elm.shape === "pill" || elm.shape === "rotated_pill")) {
1097
+ return transformPcbSolderPasteRectOrPill(elm, matrix);
1094
1098
  }
1095
1099
  if ((elm.type === "pcb_smtpad" || elm.type === "pcb_solder_paste") && elm.shape === "polygon") {
1096
1100
  elm.points = elm.points.map((point) => applyToPoint2(matrix, point));
@@ -1112,8 +1116,11 @@ var transformPCBElement = (elm, matrix) => {
1112
1116
  });
1113
1117
  elm.x = x;
1114
1118
  elm.y = y;
1115
- if (elm.type === "pcb_smtpad" && (elm.shape === "rotated_rect" || elm.shape === "rotated_pill")) {
1116
- elm.ccw_rotation = getTransformedRectRotation(elm.ccw_rotation, matrix);
1119
+ if (elm.type === "pcb_smtpad" && (elm.shape === "rotated_rect" || elm.shape === "rotated_pill") || elm.type === "pcb_plated_hole" && (elm.shape === "pill" || elm.shape === "oval")) {
1120
+ elm.ccw_rotation = getTransformedRectRotation(
1121
+ elm.ccw_rotation ?? 0,
1122
+ matrix
1123
+ );
1117
1124
  }
1118
1125
  } else if (elm.type === "pcb_keepout" && elm.shape === "outline") {
1119
1126
  elm.outline = elm.outline.map((point) => applyToPoint2(matrix, point));
@@ -1121,7 +1128,7 @@ var transformPCBElement = (elm, matrix) => {
1121
1128
  elm.center = applyToPoint2(matrix, elm.center);
1122
1129
  } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text" || elm.type === "pcb_note_text") {
1123
1130
  elm.anchor_position = applyToPoint2(matrix, elm.anchor_position);
1124
- if (elm.type === "pcb_silkscreen_text") {
1131
+ if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text") {
1125
1132
  const textTransform = compose(matrix, rotateDEG(elm.ccw_rotation ?? 0));
1126
1133
  elm.ccw_rotation = Math.atan2(textTransform.b, textTransform.a) * 180 / Math.PI;
1127
1134
  }
@@ -1217,7 +1224,7 @@ var transformPCBElements = (elms, matrix) => {
1217
1224
  let transformedElms = elms.map((elm) => transformPCBElement(elm, matrix));
1218
1225
  if (flipPadWidthHeight) {
1219
1226
  transformedElms = transformedElms.map((elm) => {
1220
- if (elm.type === "pcb_smtpad" && (elm.shape === "rect" || elm.shape === "pill") || elm.type === "pcb_solder_paste" && elm.shape === "pill") {
1227
+ if (elm.type === "pcb_smtpad" && (elm.shape === "rect" || elm.shape === "pill")) {
1221
1228
  ;
1222
1229
  [elm.width, elm.height] = [elm.height, elm.width];
1223
1230
  }
@@ -2501,18 +2508,31 @@ var getLayerDepth = (layer) => {
2501
2508
  const match = layer?.match(/^inner([1-9]\d*)$/);
2502
2509
  return match ? Number(match[1]) : Number.NaN;
2503
2510
  };
2504
- function isRouteViaCoveredByPhysicalVia(physicalVia, routeVia) {
2505
- if (physicalVia.x !== routeVia.x || physicalVia.y !== routeVia.y) return false;
2506
- if (routeVia.outer_diameter !== void 0 && routeVia.outer_diameter !== physicalVia.outer_diameter || routeVia.hole_diameter !== void 0 && routeVia.hole_diameter !== physicalVia.hole_diameter) {
2511
+ function isRouteViaCoveredByPhysicalVia(viaWithLayersOrOptions, legacyRouteVia) {
2512
+ if (!("viaWithLayers" in viaWithLayersOrOptions)) {
2513
+ if (!legacyRouteVia) return false;
2514
+ return isRouteViaCoveredByPhysicalVia({
2515
+ viaWithLayers: viaWithLayersOrOptions,
2516
+ routeVia: legacyRouteVia
2517
+ });
2518
+ }
2519
+ const {
2520
+ viaWithLayers,
2521
+ routeVia,
2522
+ positionTolerance = 0
2523
+ } = viaWithLayersOrOptions;
2524
+ const samePosition = Math.abs(viaWithLayers.x - routeVia.x) <= positionTolerance && Math.abs(viaWithLayers.y - routeVia.y) <= positionTolerance;
2525
+ if (!samePosition) return false;
2526
+ if (routeVia.outer_diameter !== void 0 && routeVia.outer_diameter !== viaWithLayers.outer_diameter || routeVia.hole_diameter !== void 0 && routeVia.hole_diameter !== viaWithLayers.hole_diameter) {
2507
2527
  return false;
2508
2528
  }
2509
- const physicalLayers = physicalVia.layers?.map(getLayerDepth);
2510
- if (!physicalLayers?.length || physicalLayers.some(Number.isNaN)) return false;
2511
- const physicalTop = Math.min(...physicalLayers);
2512
- const physicalBottom = Math.max(...physicalLayers);
2513
- const from = getLayerDepth(routeVia.from_layer);
2514
- const to = getLayerDepth(routeVia.to_layer);
2515
- return physicalTop < physicalBottom && from !== to && physicalTop <= Math.min(from, to) && physicalBottom >= Math.max(from, to);
2529
+ const viaLayerDepths = viaWithLayers.layers?.map(getLayerDepth);
2530
+ if (!viaLayerDepths?.length || viaLayerDepths.some(Number.isNaN)) return false;
2531
+ const viaTopDepth = Math.min(...viaLayerDepths);
2532
+ const viaBottomDepth = Math.max(...viaLayerDepths);
2533
+ const fromLayerDepth = getLayerDepth(routeVia.from_layer);
2534
+ const toLayerDepth = getLayerDepth(routeVia.to_layer);
2535
+ return viaTopDepth < viaBottomDepth && fromLayerDepth !== toLayerDepth && viaTopDepth <= Math.min(fromLayerDepth, toLayerDepth) && viaBottomDepth >= Math.max(fromLayerDepth, toLayerDepth);
2516
2536
  }
2517
2537
 
2518
2538
  // lib/shape-distances/geometry.ts