@tscircuit/circuit-json-util 0.0.115 → 0.0.117
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 +7 -4
- package/dist/index.js +119 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19309,6 +19309,9 @@ interface BoardBounds {
|
|
|
19309
19309
|
}
|
|
19310
19310
|
declare const getBoardBounds: (board: PcbBoard) => BoardBounds;
|
|
19311
19311
|
|
|
19312
|
+
type AnyCircuitJsonId = string;
|
|
19313
|
+
declare function createBoardOwnerMap(circuitJson: AnyCircuitElement[]): Map<AnyCircuitJsonId, PcbBoard | undefined>;
|
|
19314
|
+
|
|
19312
19315
|
type SchematicElementWithBounds = SchematicComponent | SchematicNetLabel | SchematicTrace;
|
|
19313
19316
|
interface SchematicElementBounds {
|
|
19314
19317
|
minX: number;
|
|
@@ -19457,9 +19460,9 @@ interface PcbPin1LocationElement {
|
|
|
19457
19460
|
}
|
|
19458
19461
|
/**
|
|
19459
19462
|
* Infers the semantic pin 1 location from PCB pad positions and numeric port
|
|
19460
|
-
* hints.
|
|
19461
|
-
* direction. Otherwise returns null when pin 1 is missing or the
|
|
19462
|
-
* cannot distinguish a rotation from a reflection.
|
|
19463
|
+
* hints. Numbered straight rows use a canonical frame based on the pin 1 ->
|
|
19464
|
+
* pin 2 direction. Otherwise returns null when pin 1 is missing or the
|
|
19465
|
+
* geometry cannot distinguish a rotation from a reflection.
|
|
19463
19466
|
*/
|
|
19464
19467
|
declare const analyzePcbPin1Location: (elements: readonly PcbPin1LocationElement[]) => PcbPin1Location | null;
|
|
19465
19468
|
|
|
@@ -19496,4 +19499,4 @@ declare const getTraceSegmentPolygon: (start: Point$2, end: Point$2, startWidth:
|
|
|
19496
19499
|
*/
|
|
19497
19500
|
declare const copperPolygonsTouch: (a: Polygon$1, b: Polygon$1, tolerance?: number) => boolean;
|
|
19498
19501
|
|
|
19499
|
-
export { type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbBounds, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, circlePolygon, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, copperPolygonsTouch, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPlatedHolePolygon, getPourPolygon, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getSmtPadPolygon, getStringFromCircuitJsonTree, getTraceSegmentPolygon, getViaPolygon, oppositeDirection, oppositeSide, placePolygon, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, roundedRectangle, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
|
|
19502
|
+
export { type AnyCircuitJsonId, type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbBounds, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, circlePolygon, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, copperPolygonsTouch, createBoardOwnerMap, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPlatedHolePolygon, getPourPolygon, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getSmtPadPolygon, getStringFromCircuitJsonTree, getTraceSegmentPolygon, getViaPolygon, oppositeDirection, oppositeSide, placePolygon, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, roundedRectangle, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
|
package/dist/index.js
CHANGED
|
@@ -1596,6 +1596,88 @@ var getBoardBounds = (board) => {
|
|
|
1596
1596
|
};
|
|
1597
1597
|
};
|
|
1598
1598
|
|
|
1599
|
+
// lib/create-board-owner-map.ts
|
|
1600
|
+
function createBoardOwnerMap(circuitJson) {
|
|
1601
|
+
const boardOwnerMap = /* @__PURE__ */ new Map();
|
|
1602
|
+
const parentById = /* @__PURE__ */ new Map();
|
|
1603
|
+
const boardsById = /* @__PURE__ */ new Map();
|
|
1604
|
+
for (const element of circuitJson) {
|
|
1605
|
+
switch (element.type) {
|
|
1606
|
+
case "pcb_board":
|
|
1607
|
+
boardsById.set(element.pcb_board_id, element);
|
|
1608
|
+
break;
|
|
1609
|
+
case "source_group": {
|
|
1610
|
+
const parentGroupId = element.parent_subcircuit_id ?? element.parent_source_group_id;
|
|
1611
|
+
parentById.set(
|
|
1612
|
+
element.source_group_id,
|
|
1613
|
+
element.subcircuit_id ?? parentGroupId
|
|
1614
|
+
);
|
|
1615
|
+
if (element.is_subcircuit && element.subcircuit_id) {
|
|
1616
|
+
parentById.set(element.subcircuit_id, parentGroupId);
|
|
1617
|
+
}
|
|
1618
|
+
break;
|
|
1619
|
+
}
|
|
1620
|
+
case "pcb_group":
|
|
1621
|
+
parentById.set(
|
|
1622
|
+
element.pcb_group_id,
|
|
1623
|
+
element.subcircuit_id ?? element.source_group_id
|
|
1624
|
+
);
|
|
1625
|
+
break;
|
|
1626
|
+
case "pcb_component":
|
|
1627
|
+
parentById.set(
|
|
1628
|
+
element.pcb_component_id,
|
|
1629
|
+
element.subcircuit_id ?? element.pcb_group_id
|
|
1630
|
+
);
|
|
1631
|
+
break;
|
|
1632
|
+
case "pcb_trace":
|
|
1633
|
+
parentById.set(
|
|
1634
|
+
element.pcb_trace_id,
|
|
1635
|
+
element.subcircuit_id ?? element.pcb_group_id ?? element.pcb_component_id
|
|
1636
|
+
);
|
|
1637
|
+
break;
|
|
1638
|
+
case "pcb_via":
|
|
1639
|
+
parentById.set(
|
|
1640
|
+
element.pcb_via_id,
|
|
1641
|
+
element.subcircuit_id ?? element.pcb_group_id ?? element.pcb_trace_id
|
|
1642
|
+
);
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
const boards = [...boardsById.values()];
|
|
1647
|
+
for (const board of boards) {
|
|
1648
|
+
boardOwnerMap.set(board.pcb_board_id, board);
|
|
1649
|
+
if (board.subcircuit_id) {
|
|
1650
|
+
boardOwnerMap.set(board.subcircuit_id, board);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
const singleBoard = boards.length === 1 ? boards[0] : void 0;
|
|
1654
|
+
const resolvingIds = /* @__PURE__ */ new Set();
|
|
1655
|
+
function resolveBoard(id) {
|
|
1656
|
+
if (boardOwnerMap.has(id)) {
|
|
1657
|
+
return boardOwnerMap.get(id);
|
|
1658
|
+
}
|
|
1659
|
+
if (!parentById.has(id)) {
|
|
1660
|
+
return void 0;
|
|
1661
|
+
}
|
|
1662
|
+
if (resolvingIds.has(id)) {
|
|
1663
|
+
return void 0;
|
|
1664
|
+
}
|
|
1665
|
+
resolvingIds.add(id);
|
|
1666
|
+
const parentId = parentById.get(id);
|
|
1667
|
+
let board = singleBoard;
|
|
1668
|
+
if (parentId) {
|
|
1669
|
+
board = resolveBoard(parentId);
|
|
1670
|
+
}
|
|
1671
|
+
resolvingIds.delete(id);
|
|
1672
|
+
boardOwnerMap.set(id, board);
|
|
1673
|
+
return board;
|
|
1674
|
+
}
|
|
1675
|
+
for (const id of parentById.keys()) {
|
|
1676
|
+
resolveBoard(id);
|
|
1677
|
+
}
|
|
1678
|
+
return boardOwnerMap;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1599
1681
|
// lib/get-schematic-element-bounds.ts
|
|
1600
1682
|
var SCHEMATIC_TRACE_WIDTH = 0.1;
|
|
1601
1683
|
var SCHEMATIC_NET_LABEL_FONT_SIZE = 0.18;
|
|
@@ -2684,6 +2766,17 @@ var getPinNumber = (pad) => {
|
|
|
2684
2766
|
}
|
|
2685
2767
|
return null;
|
|
2686
2768
|
};
|
|
2769
|
+
var getCanonicalRowLocation = (pin1, pin2, tolerance) => {
|
|
2770
|
+
const dx = pin2.x - pin1.x;
|
|
2771
|
+
const dy = pin2.y - pin1.y;
|
|
2772
|
+
if (Math.abs(dy) <= tolerance && Math.abs(dx) > tolerance) {
|
|
2773
|
+
return dx > 0 ? "topside_left" : "bottomside_right";
|
|
2774
|
+
}
|
|
2775
|
+
if (Math.abs(dx) <= tolerance && Math.abs(dy) > tolerance) {
|
|
2776
|
+
return dy > 0 ? "leftside_bottom" : "rightside_top";
|
|
2777
|
+
}
|
|
2778
|
+
return null;
|
|
2779
|
+
};
|
|
2687
2780
|
var pinMatchesLocation = (padCenters, pin1Center, pin1Location) => {
|
|
2688
2781
|
const xs = padCenters.map((point) => point.x);
|
|
2689
2782
|
const ys = padCenters.map((point) => point.y);
|
|
@@ -2734,13 +2827,31 @@ var analyzePcbPin1Location = (elements) => {
|
|
|
2734
2827
|
);
|
|
2735
2828
|
const tolerance = span * 1e-6;
|
|
2736
2829
|
if (numberedPads.length === 2 && nextNumberedPad.pinNumber === 2) {
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2830
|
+
return getCanonicalRowLocation(
|
|
2831
|
+
pin1Center,
|
|
2832
|
+
nextNumberedPad.center,
|
|
2833
|
+
tolerance
|
|
2834
|
+
);
|
|
2835
|
+
}
|
|
2836
|
+
if (numberedPads.length > 2) {
|
|
2837
|
+
const row = [...numberedPads].sort(
|
|
2838
|
+
(a, b) => (a.pinNumber ?? Number.POSITIVE_INFINITY) - (b.pinNumber ?? Number.POSITIVE_INFINITY)
|
|
2839
|
+
);
|
|
2840
|
+
if (row.every(
|
|
2841
|
+
({ center, pinNumber }, index) => pinNumber === index + 1 && center !== null && Number.isFinite(center.x) && Number.isFinite(center.y)
|
|
2842
|
+
)) {
|
|
2843
|
+
const first = row[0].center;
|
|
2844
|
+
const last = row[row.length - 1].center;
|
|
2845
|
+
const dx = last.x - first.x;
|
|
2846
|
+
const dy = last.y - first.y;
|
|
2847
|
+
const horizontal = Math.abs(dy) <= tolerance && Math.abs(dx) > tolerance;
|
|
2848
|
+
const vertical = Math.abs(dx) <= tolerance && Math.abs(dy) > tolerance;
|
|
2849
|
+
if ((horizontal || vertical) && row.slice(1).every(({ center }, index) => {
|
|
2850
|
+
const previous = row[index].center;
|
|
2851
|
+
return horizontal ? Math.abs(center.y - first.y) <= tolerance && (center.x - previous.x) * Math.sign(dx) > tolerance : Math.abs(center.x - first.x) <= tolerance && (center.y - previous.y) * Math.sign(dy) > tolerance;
|
|
2852
|
+
})) {
|
|
2853
|
+
return getCanonicalRowLocation(first, row[1].center, tolerance);
|
|
2854
|
+
}
|
|
2744
2855
|
}
|
|
2745
2856
|
}
|
|
2746
2857
|
const topologyCandidates = candidates.filter((pin1Location) => {
|
|
@@ -2996,6 +3107,7 @@ export {
|
|
|
2996
3107
|
computeClearanceBetweenElements,
|
|
2997
3108
|
computeGapBetweenCopper,
|
|
2998
3109
|
copperPolygonsTouch,
|
|
3110
|
+
createBoardOwnerMap,
|
|
2999
3111
|
directionToVec,
|
|
3000
3112
|
distanceBetweenCircleAndCircle,
|
|
3001
3113
|
distanceBetweenCircleAndPolygon,
|