@tscircuit/schematic-trace-solver 0.0.6 → 0.0.7

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
@@ -7891,6 +7891,31 @@ var correctPinsInsideChips = (problem) => {
7891
7891
  }
7892
7892
  };
7893
7893
 
7894
+ // lib/solvers/SchematicTracePipelineSolver/expandChipsToFitPins.ts
7895
+ var expandChipsToFitPins = (problem) => {
7896
+ for (const chip of problem.chips) {
7897
+ const halfWidth = chip.width / 2;
7898
+ const halfHeight = chip.height / 2;
7899
+ let maxDx = 0;
7900
+ let maxDy = 0;
7901
+ for (const pin of chip.pins) {
7902
+ const dx = Math.abs(pin.x - chip.center.x);
7903
+ const dy = Math.abs(pin.y - chip.center.y);
7904
+ if (dx > maxDx) maxDx = dx;
7905
+ if (dy > maxDy) maxDy = dy;
7906
+ }
7907
+ const newHalfWidth = Math.max(halfWidth, maxDx);
7908
+ const newHalfHeight = Math.max(halfHeight, maxDy);
7909
+ if (newHalfWidth > halfWidth || newHalfHeight > halfHeight) {
7910
+ chip.width = newHalfWidth * 2;
7911
+ chip.height = newHalfHeight * 2;
7912
+ for (const pin of chip.pins) {
7913
+ pin._facingDirection = void 0;
7914
+ }
7915
+ }
7916
+ }
7917
+ };
7918
+
7894
7919
  // lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts
7895
7920
  function definePipelineStep(solverName, solverClass, getConstructorParams, opts = {}) {
7896
7921
  return {
@@ -8002,6 +8027,7 @@ var SchematicTracePipelineSolver = class extends BaseSolver {
8002
8027
  ...original,
8003
8028
  _chipObstacleSpatialIndex: void 0
8004
8029
  });
8030
+ expandChipsToFitPins(cloned);
8005
8031
  correctPinsInsideChips(cloned);
8006
8032
  return cloned;
8007
8033
  }
@@ -14,6 +14,7 @@ import { visualizeInputProblem } from "./visualizeInputProblem"
14
14
  import { GuidelinesSolver } from "../GuidelinesSolver/GuidelinesSolver"
15
15
  import { getInputChipBounds } from "../GuidelinesSolver/getInputChipBounds"
16
16
  import { correctPinsInsideChips } from "./correctPinsInsideChip"
17
+ import { expandChipsToFitPins } from "./expandChipsToFitPins"
17
18
 
18
19
  type PipelineStep<T extends new (...args: any[]) => BaseSolver> = {
19
20
  solverName: string
@@ -153,6 +154,9 @@ export class SchematicTracePipelineSolver extends BaseSolver {
153
154
  _chipObstacleSpatialIndex: undefined,
154
155
  })
155
156
 
157
+ // First, expand chips so existing pin coordinates sit on or within their edges without shrinking.
158
+ expandChipsToFitPins(cloned)
159
+ // Then, for any remaining pins that are still inside due to mixed extremes, snap them to the nearest edge.
156
160
  correctPinsInsideChips(cloned)
157
161
 
158
162
  return cloned
@@ -0,0 +1,41 @@
1
+ import type { InputProblem } from "lib/types/InputProblem"
2
+
3
+ /**
4
+ * Expands chip width/height (never shrinks) so that all existing pin coordinates
5
+ * are inside or on the chip boundary, and any pin at the furthest extent in X/Y
6
+ * lies exactly on an edge.
7
+ *
8
+ * Notes:
9
+ * - Center is preserved.
10
+ * - Only increases dimensions as needed.
11
+ * - Clears cached _facingDirection on pins since geometry changed.
12
+ */
13
+ export const expandChipsToFitPins = (problem: InputProblem) => {
14
+ for (const chip of problem.chips) {
15
+ const halfWidth = chip.width / 2
16
+ const halfHeight = chip.height / 2
17
+
18
+ let maxDx = 0
19
+ let maxDy = 0
20
+
21
+ for (const pin of chip.pins) {
22
+ const dx = Math.abs(pin.x - chip.center.x)
23
+ const dy = Math.abs(pin.y - chip.center.y)
24
+ if (dx > maxDx) maxDx = dx
25
+ if (dy > maxDy) maxDy = dy
26
+ }
27
+
28
+ const newHalfWidth = Math.max(halfWidth, maxDx)
29
+ const newHalfHeight = Math.max(halfHeight, maxDy)
30
+
31
+ if (newHalfWidth > halfWidth || newHalfHeight > halfHeight) {
32
+ chip.width = newHalfWidth * 2
33
+ chip.height = newHalfHeight * 2
34
+
35
+ // Clear any cached facing direction since geometry changed.
36
+ for (const pin of chip.pins) {
37
+ pin._facingDirection = undefined
38
+ }
39
+ }
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/schematic-trace-solver",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",