@tscircuit/schematic-trace-solver 0.0.120 → 0.0.121

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.
@@ -0,0 +1,75 @@
1
+ import { expect, test } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
4
+ import { SCHEMATIC_TRACE_MIN_VISUAL_CENTERLINE_CLEARANCE } from "lib/utils/doesPathCoincideWithTraces"
5
+ import "tests/fixtures/matcher"
6
+ import inputProblem from "./assets/repro-bq25895-cross-net-trace-overlap.input.json"
7
+
8
+ const EPSILON = 1e-6
9
+
10
+ const tracesHaveInsufficientParallelClearance = (
11
+ firstTrace: SolvedTracePath,
12
+ secondTrace: SolvedTracePath,
13
+ ) => {
14
+ for (
15
+ let firstPointIndex = 0;
16
+ firstPointIndex < firstTrace.tracePath.length - 1;
17
+ firstPointIndex++
18
+ ) {
19
+ const firstStart = firstTrace.tracePath[firstPointIndex]!
20
+ const firstEnd = firstTrace.tracePath[firstPointIndex + 1]!
21
+ const firstIsVertical = Math.abs(firstStart.x - firstEnd.x) < EPSILON
22
+ if (!firstIsVertical) continue
23
+
24
+ for (
25
+ let secondPointIndex = 0;
26
+ secondPointIndex < secondTrace.tracePath.length - 1;
27
+ secondPointIndex++
28
+ ) {
29
+ const secondStart = secondTrace.tracePath[secondPointIndex]!
30
+ const secondEnd = secondTrace.tracePath[secondPointIndex + 1]!
31
+ const secondIsVertical = Math.abs(secondStart.x - secondEnd.x) < EPSILON
32
+ if (!secondIsVertical) continue
33
+
34
+ const xSeparation = Math.abs(firstStart.x - secondStart.x)
35
+ const verticalOverlap =
36
+ Math.min(
37
+ Math.max(firstStart.y, firstEnd.y),
38
+ Math.max(secondStart.y, secondEnd.y),
39
+ ) -
40
+ Math.max(
41
+ Math.min(firstStart.y, firstEnd.y),
42
+ Math.min(secondStart.y, secondEnd.y),
43
+ )
44
+
45
+ if (
46
+ xSeparation + EPSILON <
47
+ SCHEMATIC_TRACE_MIN_VISUAL_CENTERLINE_CLEARANCE &&
48
+ verticalOverlap > EPSILON
49
+ ) {
50
+ return true
51
+ }
52
+ }
53
+ }
54
+
55
+ return false
56
+ }
57
+
58
+ test("BQ25895 CE and GND traces keep visible parallel clearance", () => {
59
+ const solver = new SchematicTracePipelineSolver(inputProblem as any)
60
+ solver.solve()
61
+
62
+ const traces = solver.netLabelTraceCollisionSolver!.getOutput().traces
63
+ const ceTraces = traces.filter(
64
+ (trace) => trace.userNetId === "J3.pin6 to U1.CE",
65
+ )
66
+ const groundTraces = traces.filter((trace) => trace.userNetId === "GND")
67
+ const hasInsufficientCeAndGroundClearance = ceTraces.some((ceTrace) =>
68
+ groundTraces.some((groundTrace) =>
69
+ tracesHaveInsufficientParallelClearance(ceTrace, groundTrace),
70
+ ),
71
+ )
72
+
73
+ expect(hasInsufficientCeAndGroundClearance).toBe(false)
74
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
75
+ })
@@ -0,0 +1,68 @@
1
+ import { expect, test } from "bun:test"
2
+ import {
3
+ SCHEMATIC_TRACE_MIN_VISUAL_CENTERLINE_CLEARANCE,
4
+ SCHEMATIC_TRACE_STROKE_WIDTH,
5
+ } from "lib/utils/doesPathCoincideWithTraces"
6
+ import {
7
+ align,
8
+ createTrace,
9
+ getVerticalRailTraces,
10
+ } from "./fixtures/alignSameNetRails"
11
+
12
+ test("aligns same-net rails at a safe coordinate beside different-net traces", () => {
13
+ const rails = getVerticalRailTraces()
14
+ const foreignLowerTrace = createTrace(
15
+ "foreign-lower",
16
+ [
17
+ { x: -2.02, y: -2 },
18
+ { x: -2.02, y: -0.2 },
19
+ ],
20
+ [
21
+ { pinId: "X1.1", chipId: "X1", x: -2.02, y: -2 },
22
+ { pinId: "X2.1", chipId: "X2", x: -2.02, y: -0.2 },
23
+ ],
24
+ "foreign-lower-net",
25
+ )
26
+ const foreignUpperTrace = createTrace(
27
+ "foreign-upper",
28
+ [
29
+ { x: -3.02, y: 0.2 },
30
+ { x: -3.02, y: 2 },
31
+ ],
32
+ [
33
+ { pinId: "X3.1", chipId: "X3", x: -3.02, y: 0.2 },
34
+ { pinId: "X4.1", chipId: "X4", x: -3.02, y: 2 },
35
+ ],
36
+ "foreign-upper-net",
37
+ )
38
+ const traces = [...rails, foreignLowerTrace, foreignUpperTrace]
39
+
40
+ const result = align(traces, {
41
+ eligibleTraceIds: new Set(rails.map((trace) => trace.mspPairId)),
42
+ })
43
+
44
+ expect(result.alignedRailGroupCount).toBe(1)
45
+
46
+ const alignedUpper = result.traces.find(
47
+ (trace) => trace.mspPairId === "upper",
48
+ )!
49
+ const alignedLower = result.traces.find(
50
+ (trace) => trace.mspPairId === "lower",
51
+ )!
52
+ const upperRailX = alignedUpper.tracePath[1]!.x
53
+ const lowerRailX = alignedLower.tracePath[1]!.x
54
+
55
+ expect(upperRailX).toBe(lowerRailX)
56
+ expect(
57
+ Math.abs(upperRailX - foreignLowerTrace.tracePath[0]!.x),
58
+ ).toBeGreaterThan(SCHEMATIC_TRACE_STROKE_WIDTH)
59
+ expect(
60
+ Math.abs(upperRailX - foreignUpperTrace.tracePath[0]!.x),
61
+ ).toBeGreaterThan(SCHEMATIC_TRACE_STROKE_WIDTH)
62
+ expect(
63
+ Math.min(
64
+ Math.abs(upperRailX - foreignLowerTrace.tracePath[0]!.x),
65
+ Math.abs(upperRailX - foreignUpperTrace.tracePath[0]!.x),
66
+ ),
67
+ ).toBeCloseTo(SCHEMATIC_TRACE_MIN_VISUAL_CENTERLINE_CLEARANCE, 6)
68
+ })