@tscircuit/checks 0.0.149 → 0.0.151

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
@@ -80,6 +80,8 @@ declare function checkViaTraceClearance(circuitJson: AnyCircuitElement[], { conn
80
80
  minClearance?: number;
81
81
  }): PcbViaTraceClearanceError[];
82
82
 
83
+ declare function checkViasInPads(circuitJson: AnyCircuitElement[]): PcbPlacementError[];
84
+
83
85
  /**
84
86
  * Removes generic pcb_trace_error records when a more specific pad-trace or
85
87
  * via-trace clearance error describes the same physical pair.
@@ -159,4 +161,4 @@ declare function checkConnectorAccessibleOrientation(circuitJson: AnyCircuitElem
159
161
  */
160
162
  declare function checkTestPointAccessibility(circuitJson: AnyCircuitElement[]): PcbPlacementError[];
161
163
 
162
- export { NetManager, checkAllPinsInComponentAreUnderspecified, checkConnectorAccessibleOrientation, checkDifferentNetViaSpacing, checkEachPcbPortConnectedToPcbTraces, checkEachPcbTraceNonOverlapping, checkNoGroundPinDefined, checkNoPowerPinDefined, checkPadPadClearance, checkPadTraceClearance, checkPcbComponentOverlap, checkPcbComponentsOutOfBoard, checkPcbTraceLengths, checkPcbTracesOutOfBoard, checkPinMustBeConnected, checkSameNetViaSpacing, checkSourceTracesHavePcbTraces, checkSourceTracesMatchPcbTraceThickness, checkTestPointAccessibility, checkTracesAreContiguous, checkViaTraceClearance, checkViasOffBoard, dedupePcbDrcErrors, runAllChecks, runAllNetlistChecks, runAllPinSpecificationChecks, runAllPlacementChecks, runAllRoutingChecks };
164
+ export { NetManager, checkAllPinsInComponentAreUnderspecified, checkConnectorAccessibleOrientation, checkDifferentNetViaSpacing, checkEachPcbPortConnectedToPcbTraces, checkEachPcbTraceNonOverlapping, checkNoGroundPinDefined, checkNoPowerPinDefined, checkPadPadClearance, checkPadTraceClearance, checkPcbComponentOverlap, checkPcbComponentsOutOfBoard, checkPcbTraceLengths, checkPcbTracesOutOfBoard, checkPinMustBeConnected, checkSameNetViaSpacing, checkSourceTracesHavePcbTraces, checkSourceTracesMatchPcbTraceThickness, checkTestPointAccessibility, checkTracesAreContiguous, checkViaTraceClearance, checkViasInPads, checkViasOffBoard, dedupePcbDrcErrors, runAllChecks, runAllNetlistChecks, runAllPinSpecificationChecks, runAllPlacementChecks, runAllRoutingChecks };
package/dist/index.js CHANGED
@@ -448,6 +448,16 @@ var getReadableNameForElementId = (circuitJson, elementId) => sanitizeReadableNa
448
448
  "element"
449
449
  );
450
450
  var containsCircuitJsonId = (message) => CIRCUIT_JSON_ID_PATTERN.test(message);
451
+ function getReadableNameForFootprintPad(circuitJson, pad, ordinal) {
452
+ const padKind = pad.type === "pcb_smtpad" ? "SMD pad" : "through-hole pad";
453
+ const portRef = pad.pcb_port_id ? getReadableNameForPort(circuitJson, pad.pcb_port_id) : null;
454
+ const bounds = getBoundsOfPcbElements([pad]);
455
+ const centerX = (bounds.minX + bounds.maxX) / 2;
456
+ const centerY = (bounds.minY + bounds.maxY) / 2;
457
+ const location = `(${centerX.toFixed(2)}mm, ${centerY.toFixed(2)}mm)`;
458
+ if (portRef) return `${padKind} ${portRef} at ${location}`;
459
+ return `${padKind} #${ordinal + 1} at ${location}`;
460
+ }
451
461
 
452
462
  // lib/check-each-pcb-port-connected-to-pcb-trace.ts
453
463
  function checkEachPcbPortConnectedToPcbTraces(circuitJson) {
@@ -2760,6 +2770,58 @@ function checkViaTraceClearance(circuitJson, {
2760
2770
  return Array.from(errors.values()).map(({ error }) => error);
2761
2771
  }
2762
2772
 
2773
+ // lib/check-vias-in-pads.ts
2774
+ import { getPrimaryId as getPrimaryId5 } from "@tscircuit/circuit-json-util";
2775
+ function checkViasInPads(circuitJson) {
2776
+ const board = getPcbBoard(circuitJson);
2777
+ if (board && "is_via_in_pad_allowed" in board && board.is_via_in_pad_allowed === true) {
2778
+ return [];
2779
+ }
2780
+ const vias = circuitJson.filter(
2781
+ (element) => element.type === "pcb_via"
2782
+ );
2783
+ const pads = getPads(circuitJson);
2784
+ if (vias.length === 0 || pads.length === 0) return [];
2785
+ const padOrdinals = new Map(
2786
+ pads.map((pad, index) => [getPrimaryId5(pad), index])
2787
+ );
2788
+ const padIndex = new SpatialObjectIndex({
2789
+ objects: pads,
2790
+ getBounds: getPadBounds,
2791
+ getId: getPrimaryId5
2792
+ });
2793
+ const errors = [];
2794
+ for (const via of vias) {
2795
+ const nearbyPads = padIndex.getObjectsInBounds({
2796
+ minX: via.x,
2797
+ minY: via.y,
2798
+ maxX: via.x,
2799
+ maxY: via.y
2800
+ });
2801
+ for (const pad of nearbyPads) {
2802
+ const viaLayers = getLayersOfPcbElement(via);
2803
+ const padLayers = getLayersOfPcbElement(pad);
2804
+ if (!viaLayers.some((layer) => padLayers.includes(layer))) continue;
2805
+ if (!isPointInPad(via, pad)) continue;
2806
+ const padId = getPrimaryId5(pad);
2807
+ const padOrdinal = padOrdinals.get(padId) ?? 0;
2808
+ const padName = getReadableNameForFootprintPad(
2809
+ circuitJson,
2810
+ pad,
2811
+ padOrdinal
2812
+ );
2813
+ errors.push({
2814
+ type: "pcb_placement_error",
2815
+ pcb_placement_error_id: `via_in_pad_${via.pcb_via_id}_${padId}`,
2816
+ error_type: "pcb_placement_error",
2817
+ message: `Via at (${via.x.toFixed(2)}mm, ${via.y.toFixed(2)}mm) is inside ${padName}`,
2818
+ subcircuit_id: via.subcircuit_id ?? pad.subcircuit_id
2819
+ });
2820
+ }
2821
+ }
2822
+ return errors;
2823
+ }
2824
+
2763
2825
  // lib/dedupe-pcb-drc-errors.ts
2764
2826
  var dedupePcbDrcErrors = (errors) => {
2765
2827
  const specificallyReportedPairIds = /* @__PURE__ */ new Set();
@@ -2994,11 +3056,12 @@ function getFacingDirectionFromInsertionDirection(component) {
2994
3056
  return "x-";
2995
3057
  case "from_right":
2996
3058
  return "x+";
2997
- case "from_front":
3059
+ case "from_top":
2998
3060
  return "y+";
2999
- case "from_back":
3061
+ case "from_bottom":
3000
3062
  return "y-";
3001
3063
  case "from_above":
3064
+ case "from_below":
3002
3065
  return null;
3003
3066
  default:
3004
3067
  return null;
@@ -3256,6 +3319,7 @@ function checkTestPointAccessibility(circuitJson) {
3256
3319
  async function runAllPlacementChecks(circuitJson) {
3257
3320
  return [
3258
3321
  ...checkViasOffBoard(circuitJson),
3322
+ ...checkViasInPads(circuitJson),
3259
3323
  ...checkPcbComponentsOutOfBoard(circuitJson),
3260
3324
  ...checkPcbComponentOverlap(circuitJson),
3261
3325
  ...checkPadPadClearance(circuitJson),
@@ -3318,6 +3382,7 @@ export {
3318
3382
  checkTestPointAccessibility,
3319
3383
  checkTracesAreContiguous,
3320
3384
  checkViaTraceClearance,
3385
+ checkViasInPads,
3321
3386
  checkViasOffBoard,
3322
3387
  dedupePcbDrcErrors,
3323
3388
  runAllChecks,