@tscircuit/circuit-json-util 0.0.116 → 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 +3 -3
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19460,9 +19460,9 @@ interface PcbPin1LocationElement {
|
|
|
19460
19460
|
}
|
|
19461
19461
|
/**
|
|
19462
19462
|
* Infers the semantic pin 1 location from PCB pad positions and numeric port
|
|
19463
|
-
* hints.
|
|
19464
|
-
* direction. Otherwise returns null when pin 1 is missing or the
|
|
19465
|
-
* 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.
|
|
19466
19466
|
*/
|
|
19467
19467
|
declare const analyzePcbPin1Location: (elements: readonly PcbPin1LocationElement[]) => PcbPin1Location | null;
|
|
19468
19468
|
|
package/dist/index.js
CHANGED
|
@@ -2766,6 +2766,17 @@ var getPinNumber = (pad) => {
|
|
|
2766
2766
|
}
|
|
2767
2767
|
return null;
|
|
2768
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
|
+
};
|
|
2769
2780
|
var pinMatchesLocation = (padCenters, pin1Center, pin1Location) => {
|
|
2770
2781
|
const xs = padCenters.map((point) => point.x);
|
|
2771
2782
|
const ys = padCenters.map((point) => point.y);
|
|
@@ -2816,13 +2827,31 @@ var analyzePcbPin1Location = (elements) => {
|
|
|
2816
2827
|
);
|
|
2817
2828
|
const tolerance = span * 1e-6;
|
|
2818
2829
|
if (numberedPads.length === 2 && nextNumberedPad.pinNumber === 2) {
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
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
|
+
}
|
|
2826
2855
|
}
|
|
2827
2856
|
}
|
|
2828
2857
|
const topologyCandidates = candidates.filter((pin1Location) => {
|