@tscircuit/circuit-json-util 0.0.127 → 0.0.129

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
@@ -1405,6 +1405,12 @@ var getReadableNameForElement = (soup, elm) => {
1405
1405
  };
1406
1406
 
1407
1407
  // lib/get-bounds-of-pcb-elements.ts
1408
+ import {
1409
+ applyToPoint as applyToPoint2,
1410
+ compose as compose2,
1411
+ rotateDEG as rotateDEG2,
1412
+ translate
1413
+ } from "transformation-matrix";
1408
1414
  var mergeBounds = (currentBounds, nextBounds) => ({
1409
1415
  minX: Math.min(currentBounds.minX, nextBounds.minX),
1410
1416
  minY: Math.min(currentBounds.minY, nextBounds.minY),
@@ -1545,6 +1551,22 @@ var getPcbElementBounds = (elm) => {
1545
1551
  );
1546
1552
  platedHoleBounds = platedHoleBounds ? mergeBounds(platedHoleBounds, drillBounds) : drillBounds;
1547
1553
  }
1554
+ if (elm.shape === "hole_with_polygon_pad") {
1555
+ const matrix = compose2(
1556
+ translate(elm.x, elm.y),
1557
+ rotateDEG2(elm.ccw_rotation ?? 0)
1558
+ );
1559
+ const outlineBounds2 = getBoundsFromPoints(
1560
+ elm.pad_outline.map((point) => applyToPoint2(matrix, point))
1561
+ );
1562
+ if (outlineBounds2) {
1563
+ if (platedHoleBounds) {
1564
+ platedHoleBounds = mergeBounds(platedHoleBounds, outlineBounds2);
1565
+ } else {
1566
+ platedHoleBounds = outlineBounds2;
1567
+ }
1568
+ }
1569
+ }
1548
1570
  if (platedHoleBounds) return platedHoleBounds;
1549
1571
  }
1550
1572
  const elementRecord = elm;
@@ -2080,7 +2102,7 @@ var getPrimaryId = (element) => {
2080
2102
  };
2081
2103
 
2082
2104
  // lib/reposition-pcb-component.ts
2083
- import { translate } from "transformation-matrix";
2105
+ import { translate as translate2 } from "transformation-matrix";
2084
2106
  var repositionPcbComponentTo = (circuitJson, pcb_component_id, newCenter) => {
2085
2107
  const pcbComponent = circuitJson.find(
2086
2108
  (e) => e.type === "pcb_component" && e.pcb_component_id === pcb_component_id
@@ -2111,12 +2133,12 @@ var repositionPcbComponentTo = (circuitJson, pcb_component_id, newCenter) => {
2111
2133
  return true;
2112
2134
  return false;
2113
2135
  });
2114
- const matrix = translate(dx, dy);
2136
+ const matrix = translate2(dx, dy);
2115
2137
  transformPCBElements(elementsToMove, matrix);
2116
2138
  };
2117
2139
 
2118
2140
  // lib/reposition-pcb-group.ts
2119
- import { translate as translate2 } from "transformation-matrix";
2141
+ import { translate as translate3 } from "transformation-matrix";
2120
2142
  var findAllDescendantGroupIds = (circuitJson, parentGroupId) => {
2121
2143
  const childGroupIds = [];
2122
2144
  const directChildren = circuitJson.filter(
@@ -2163,12 +2185,12 @@ var repositionPcbGroupTo = (circuitJson, source_group_id, newCenter) => {
2163
2185
  const { center: currentCenter } = findBoundsAndCenter(pcbElements);
2164
2186
  const dx = newCenter.x - currentCenter.x;
2165
2187
  const dy = newCenter.y - currentCenter.y;
2166
- const matrix = translate2(dx, dy);
2188
+ const matrix = translate3(dx, dy);
2167
2189
  transformPCBElements(pcbElements, matrix);
2168
2190
  };
2169
2191
 
2170
2192
  // lib/reposition-schematic-component.ts
2171
- import { translate as translate3 } from "transformation-matrix";
2193
+ import { translate as translate4 } from "transformation-matrix";
2172
2194
  var repositionSchematicComponentTo = (circuitJson, schematic_component_id, newCenter) => {
2173
2195
  const schematicComponent = circuitJson.find(
2174
2196
  (e) => e.type === "schematic_component" && e.schematic_component_id === schematic_component_id
@@ -2200,12 +2222,12 @@ var repositionSchematicComponentTo = (circuitJson, schematic_component_id, newCe
2200
2222
  return true;
2201
2223
  return false;
2202
2224
  });
2203
- const matrix = translate3(dx, dy);
2225
+ const matrix = translate4(dx, dy);
2204
2226
  transformSchematicElements(elementsToMove, matrix);
2205
2227
  };
2206
2228
 
2207
2229
  // lib/reposition-schematic-group.ts
2208
- import { translate as translate4 } from "transformation-matrix";
2230
+ import { translate as translate5 } from "transformation-matrix";
2209
2231
  var findAllDescendantGroupIds2 = (circuitJson, parentGroupId) => {
2210
2232
  const childGroupIds = [];
2211
2233
  const directChildren = circuitJson.filter(
@@ -2252,7 +2274,7 @@ var repositionSchematicGroupTo = (circuitJson, source_group_id, newCenter) => {
2252
2274
  const { center: currentCenter } = findBoundsAndCenter(schematicElements);
2253
2275
  const dx = newCenter.x - currentCenter.x;
2254
2276
  const dy = newCenter.y - currentCenter.y;
2255
- const matrix = translate4(dx, dy);
2277
+ const matrix = translate5(dx, dy);
2256
2278
  transformSchematicElements(schematicElements, matrix);
2257
2279
  };
2258
2280
 
@@ -2838,6 +2860,7 @@ var computeClearanceBetweenElements = (elm1, elm2) => {
2838
2860
  };
2839
2861
 
2840
2862
  // lib/analyze-pcb-pin1-location.ts
2863
+ var MAX_TWO_PAD_ROW_SKEW_RATIO = 0.01;
2841
2864
  var PIN1_LOCATION_PARTS = {
2842
2865
  leftside_top: { side: "leftside", alignment: "top" },
2843
2866
  leftside_bottom: { side: "leftside", alignment: "bottom" },
@@ -2870,13 +2893,23 @@ var getPinNumber = (pad) => {
2870
2893
  }
2871
2894
  return null;
2872
2895
  };
2873
- var getCanonicalRowLocation = (pin1, pin2, tolerance) => {
2896
+ var getCanonicalRowLocation = ({
2897
+ pin1,
2898
+ pin2,
2899
+ tolerance,
2900
+ maxSkewRatio = 0
2901
+ }) => {
2874
2902
  const dx = pin2.x - pin1.x;
2875
2903
  const dy = pin2.y - pin1.y;
2876
- if (Math.abs(dy) <= tolerance && Math.abs(dx) > tolerance) {
2904
+ const horizontalSkewTolerance = Math.max(
2905
+ tolerance,
2906
+ Math.abs(dx) * maxSkewRatio
2907
+ );
2908
+ const verticalSkewTolerance = Math.max(tolerance, Math.abs(dy) * maxSkewRatio);
2909
+ if (Math.abs(dy) <= horizontalSkewTolerance && Math.abs(dx) > tolerance) {
2877
2910
  return dx > 0 ? "topside_left" : "bottomside_right";
2878
2911
  }
2879
- if (Math.abs(dx) <= tolerance && Math.abs(dy) > tolerance) {
2912
+ if (Math.abs(dx) <= verticalSkewTolerance && Math.abs(dy) > tolerance) {
2880
2913
  return dy > 0 ? "leftside_bottom" : "rightside_top";
2881
2914
  }
2882
2915
  return null;
@@ -2931,11 +2964,12 @@ var analyzePcbPin1Location = (elements) => {
2931
2964
  );
2932
2965
  const tolerance = span * 1e-6;
2933
2966
  if (numberedPads.length === 2 && nextNumberedPad.pinNumber === 2) {
2934
- return getCanonicalRowLocation(
2935
- pin1Center,
2936
- nextNumberedPad.center,
2937
- tolerance
2938
- );
2967
+ return getCanonicalRowLocation({
2968
+ pin1: pin1Center,
2969
+ pin2: nextNumberedPad.center,
2970
+ tolerance,
2971
+ maxSkewRatio: MAX_TWO_PAD_ROW_SKEW_RATIO
2972
+ });
2939
2973
  }
2940
2974
  if (numberedPads.length > 2) {
2941
2975
  const row = [...numberedPads].sort(
@@ -2954,7 +2988,11 @@ var analyzePcbPin1Location = (elements) => {
2954
2988
  const previous = row[index].center;
2955
2989
  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;
2956
2990
  })) {
2957
- return getCanonicalRowLocation(first, row[1].center, tolerance);
2991
+ return getCanonicalRowLocation({
2992
+ pin1: first,
2993
+ pin2: row[1].center,
2994
+ tolerance
2995
+ });
2958
2996
  }
2959
2997
  }
2960
2998
  }
@@ -3012,10 +3050,10 @@ import {
3012
3050
  Segment,
3013
3051
  Utils
3014
3052
  } from "@flatten-js/core";
3015
- import { compose as compose2, rotate, translate as translate5 } from "transformation-matrix";
3053
+ import { compose as compose3, rotate, translate as translate6 } from "transformation-matrix";
3016
3054
  var placePolygon = (polygon, center, degrees = 0) => {
3017
- const { a, b, c, d, e, f } = compose2(
3018
- translate5(center.x, center.y),
3055
+ const { a, b, c, d, e, f } = compose3(
3056
+ translate6(center.x, center.y),
3019
3057
  rotate(degrees * Math.PI / 180)
3020
3058
  );
3021
3059
  return polygon.transform(new Matrix(a, b, c, d, e, f));