@tscircuit/core 0.0.791 → 0.0.792

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.
Files changed (2) hide show
  1. package/dist/index.js +121 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10743,7 +10743,9 @@ import {
10743
10743
  convertPackOutputToPackInput,
10744
10744
  getGraphicsFromPackOutput
10745
10745
  } from "calculate-packing";
10746
- import { length as length4 } from "circuit-json";
10746
+ import {
10747
+ length as length4
10748
+ } from "circuit-json";
10747
10749
  import Debug7 from "debug";
10748
10750
 
10749
10751
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutPack/applyComponentConstraintClusters.ts
@@ -11078,6 +11080,69 @@ var applyPackOutput = (group, packOutput, clusterMap) => {
11078
11080
  }
11079
11081
  };
11080
11082
 
11083
+ // lib/utils/packing/getObstacleDimensionsFromElement.ts
11084
+ function getObstacleDimensionsFromSmtPad(pad) {
11085
+ switch (pad.shape) {
11086
+ case "rect":
11087
+ case "rotated_rect":
11088
+ case "pill":
11089
+ case "rotated_pill":
11090
+ return {
11091
+ width: pad.width,
11092
+ height: pad.height
11093
+ };
11094
+ case "circle":
11095
+ return {
11096
+ width: pad.radius * 2,
11097
+ height: pad.radius * 2
11098
+ };
11099
+ case "polygon":
11100
+ if (!pad.points || pad.points.length === 0) {
11101
+ return null;
11102
+ }
11103
+ const xs = pad.points.map((p) => p.x);
11104
+ const ys = pad.points.map((p) => p.y);
11105
+ const minX = Math.min(...xs);
11106
+ const maxX = Math.max(...xs);
11107
+ const minY = Math.min(...ys);
11108
+ const maxY = Math.max(...ys);
11109
+ return {
11110
+ width: maxX - minX,
11111
+ height: maxY - minY
11112
+ };
11113
+ default:
11114
+ return null;
11115
+ }
11116
+ }
11117
+ function getObstacleDimensionsFromPlatedHole(hole) {
11118
+ switch (hole.shape) {
11119
+ case "circular_hole_with_rect_pad":
11120
+ case "pill_hole_with_rect_pad":
11121
+ case "rotated_pill_hole_with_rect_pad":
11122
+ return {
11123
+ width: hole.rect_pad_width,
11124
+ height: hole.rect_pad_height
11125
+ };
11126
+ case "circle":
11127
+ return {
11128
+ width: hole.outer_diameter,
11129
+ height: hole.outer_diameter
11130
+ };
11131
+ case "oval":
11132
+ return {
11133
+ width: hole.outer_width,
11134
+ height: hole.outer_height
11135
+ };
11136
+ case "pill":
11137
+ return {
11138
+ width: hole.outer_width,
11139
+ height: hole.outer_height
11140
+ };
11141
+ default:
11142
+ return null;
11143
+ }
11144
+ }
11145
+
11081
11146
  // lib/components/primitive-components/Group/Group_doInitialPcbLayoutPack/Group_doInitialPcbLayoutPack.ts
11082
11147
  var DEFAULT_MIN_GAP = "1mm";
11083
11148
  var debug6 = Debug7("Group_doInitialPcbLayoutPack");
@@ -11136,6 +11201,58 @@ var Group_doInitialPcbLayoutPack = (group) => {
11136
11201
  }
11137
11202
  return true;
11138
11203
  });
11204
+ const obstaclesFromRelativelyPositionedComponents = [];
11205
+ for (const pcb_component_id of excludedPcbComponentIds) {
11206
+ const component = db.toArray().find(
11207
+ (el) => el.type === "pcb_component" && el.pcb_component_id === pcb_component_id
11208
+ );
11209
+ if (!component) continue;
11210
+ const componentX = component.center.x;
11211
+ const componentY = component.center.y;
11212
+ const smtpads = db.toArray().filter(
11213
+ (el) => el.type === "pcb_smtpad" && el.pcb_component_id === pcb_component_id
11214
+ );
11215
+ for (const pad of smtpads) {
11216
+ const dimensions = getObstacleDimensionsFromSmtPad(pad);
11217
+ if (!dimensions || dimensions.width === 0 || dimensions.height === 0) {
11218
+ continue;
11219
+ }
11220
+ let centerX;
11221
+ let centerY;
11222
+ if (pad.shape === "polygon") {
11223
+ const xs = pad.points.map((p) => p.x);
11224
+ const ys = pad.points.map((p) => p.y);
11225
+ centerX = componentX + (Math.min(...xs) + Math.max(...xs)) / 2;
11226
+ centerY = componentY + (Math.min(...ys) + Math.max(...ys)) / 2;
11227
+ } else {
11228
+ centerX = componentX + pad.x;
11229
+ centerY = componentY + pad.y;
11230
+ }
11231
+ obstaclesFromRelativelyPositionedComponents.push({
11232
+ obstacleId: pad.pcb_smtpad_id,
11233
+ absoluteCenter: { x: centerX, y: centerY },
11234
+ width: dimensions.width,
11235
+ height: dimensions.height
11236
+ });
11237
+ }
11238
+ const platedHoles = db.toArray().filter(
11239
+ (el) => el.type === "pcb_plated_hole" && el.pcb_component_id === pcb_component_id
11240
+ );
11241
+ for (const hole of platedHoles) {
11242
+ const dimensions = getObstacleDimensionsFromPlatedHole(hole);
11243
+ if (!dimensions || dimensions.width === 0 || dimensions.height === 0) {
11244
+ continue;
11245
+ }
11246
+ const centerX = componentX + hole.x;
11247
+ const centerY = componentY + hole.y;
11248
+ obstaclesFromRelativelyPositionedComponents.push({
11249
+ obstacleId: hole.pcb_plated_hole_id,
11250
+ absoluteCenter: { x: centerX, y: centerY },
11251
+ width: dimensions.width,
11252
+ height: dimensions.height
11253
+ });
11254
+ }
11255
+ }
11139
11256
  const packInput = {
11140
11257
  ...convertPackOutputToPackInput(
11141
11258
  convertCircuitJsonToPackOutput(filteredCircuitJson, {
@@ -11147,7 +11264,8 @@ var Group_doInitialPcbLayoutPack = (group) => {
11147
11264
  // @ts-expect-error we're missing some pack order strategies
11148
11265
  orderStrategy: packOrderStrategy ?? "largest_to_smallest",
11149
11266
  placementStrategy: packPlacementStrategy ?? "minimum_sum_squared_distance_to_network",
11150
- minGap: gapMm
11267
+ minGap: gapMm,
11268
+ obstacles: obstaclesFromRelativelyPositionedComponents
11151
11269
  };
11152
11270
  const clusterMap = applyComponentConstraintClusters(group, packInput);
11153
11271
  if (debug6.enabled) {
@@ -16750,7 +16868,7 @@ import { identity as identity6 } from "transformation-matrix";
16750
16868
  var package_default = {
16751
16869
  name: "@tscircuit/core",
16752
16870
  type: "module",
16753
- version: "0.0.790",
16871
+ version: "0.0.791",
16754
16872
  types: "dist/index.d.ts",
16755
16873
  main: "dist/index.js",
16756
16874
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.791",
4
+ "version": "0.0.792",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",