@tscircuit/schematic-trace-solver 0.0.119 → 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,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
+ })