@tscircuit/schematic-trace-solver 0.0.16 → 0.0.18
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
|
@@ -6677,13 +6677,23 @@ var SchematicTraceSingleLineSolver = class extends BaseSolver {
|
|
|
6677
6677
|
overshoot: 0.2
|
|
6678
6678
|
}
|
|
6679
6679
|
);
|
|
6680
|
-
console.log("baseElbow", this.baseElbow);
|
|
6681
6680
|
const { elbowVariants, movableSegments } = generateElbowVariants({
|
|
6682
6681
|
baseElbow: this.baseElbow,
|
|
6683
6682
|
guidelines: this.guidelines
|
|
6684
6683
|
});
|
|
6685
6684
|
this.movableSegments = movableSegments;
|
|
6686
|
-
|
|
6685
|
+
const getPathLength = (pts) => {
|
|
6686
|
+
let len = 0;
|
|
6687
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
6688
|
+
const dx = pts[i + 1].x - pts[i].x;
|
|
6689
|
+
const dy = pts[i + 1].y - pts[i].y;
|
|
6690
|
+
len += Math.sqrt(dx * dx + dy * dy);
|
|
6691
|
+
}
|
|
6692
|
+
return len;
|
|
6693
|
+
};
|
|
6694
|
+
this.queuedCandidatePaths = [this.baseElbow, ...elbowVariants].sort(
|
|
6695
|
+
(a, b) => getPathLength(a) - getPathLength(b)
|
|
6696
|
+
);
|
|
6687
6697
|
}
|
|
6688
6698
|
getConstructorParams() {
|
|
6689
6699
|
return {
|
|
@@ -73,7 +73,6 @@ export class SchematicTraceSingleLineSolver extends BaseSolver {
|
|
|
73
73
|
overshoot: 0.2,
|
|
74
74
|
},
|
|
75
75
|
)
|
|
76
|
-
console.log("baseElbow", this.baseElbow)
|
|
77
76
|
|
|
78
77
|
const { elbowVariants, movableSegments } = generateElbowVariants({
|
|
79
78
|
baseElbow: this.baseElbow,
|
|
@@ -82,7 +81,19 @@ export class SchematicTraceSingleLineSolver extends BaseSolver {
|
|
|
82
81
|
|
|
83
82
|
this.movableSegments = movableSegments
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
const getPathLength = (pts: Point[]) => {
|
|
85
|
+
let len = 0
|
|
86
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
87
|
+
const dx = pts[i + 1].x - pts[i].x
|
|
88
|
+
const dy = pts[i + 1].y - pts[i].y
|
|
89
|
+
len += Math.sqrt(dx * dx + dy * dy)
|
|
90
|
+
}
|
|
91
|
+
return len
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.queuedCandidatePaths = [this.baseElbow, ...elbowVariants].sort(
|
|
95
|
+
(a, b) => getPathLength(a) - getPathLength(b),
|
|
96
|
+
)
|
|
86
97
|
}
|
|
87
98
|
|
|
88
99
|
override getConstructorParams(): ConstructorParameters<
|
package/package.json
CHANGED
package/tests/solvers/SchematicTraceSingleLineSolver/SchematicTraceSingleLineSolver_shortest.test.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { test, expect } from "bun:test"
|
|
2
|
+
import { SchematicTraceSingleLineSolver } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/SchematicTraceSingleLineSolver"
|
|
3
|
+
import { calculateElbow } from "calculate-elbow"
|
|
4
|
+
import { generateElbowVariants } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/generateElbowVariants"
|
|
5
|
+
import type { InputChip, InputProblem } from "lib/types/InputProblem"
|
|
6
|
+
import type { Guideline } from "lib/solvers/GuidelinesSolver/GuidelinesSolver"
|
|
7
|
+
|
|
8
|
+
const pathLength = (pts: { x: number; y: number }[]) => {
|
|
9
|
+
let len = 0
|
|
10
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
11
|
+
const dx = pts[i + 1].x - pts[i].x
|
|
12
|
+
const dy = pts[i + 1].y - pts[i].y
|
|
13
|
+
len += Math.sqrt(dx * dx + dy * dy)
|
|
14
|
+
}
|
|
15
|
+
return len
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test("SchematicTraceSingleLineSolver chooses shortest candidate path", () => {
|
|
19
|
+
const chipA: InputChip = {
|
|
20
|
+
chipId: "A",
|
|
21
|
+
center: { x: 0, y: 0 },
|
|
22
|
+
width: 0.2,
|
|
23
|
+
height: 0.2,
|
|
24
|
+
pins: [{ pinId: "A1", x: 0, y: 0 }],
|
|
25
|
+
}
|
|
26
|
+
const chipB: InputChip = {
|
|
27
|
+
chipId: "B",
|
|
28
|
+
center: { x: 4, y: 2 },
|
|
29
|
+
width: 0.2,
|
|
30
|
+
height: 0.2,
|
|
31
|
+
pins: [{ pinId: "B1", x: 4, y: 2 }],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const pins = [
|
|
35
|
+
{ pinId: "A1", x: 0, y: 0, _facingDirection: "x+" as const, chipId: "A" },
|
|
36
|
+
{ pinId: "B1", x: 4, y: 2, _facingDirection: "x+" as const, chipId: "B" },
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
const guidelines: Guideline[] = [
|
|
40
|
+
{ orientation: "vertical", x: 4, y: undefined },
|
|
41
|
+
{ orientation: "vertical", x: 6, y: undefined },
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const inputProblem: InputProblem = {
|
|
45
|
+
chips: [chipA, chipB],
|
|
46
|
+
directConnections: [],
|
|
47
|
+
netConnections: [],
|
|
48
|
+
availableNetLabelOrientations: {},
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const solver = new SchematicTraceSingleLineSolver({
|
|
52
|
+
pins: pins as any,
|
|
53
|
+
guidelines,
|
|
54
|
+
inputProblem,
|
|
55
|
+
chipMap: { A: chipA, B: chipB },
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
solver.solve()
|
|
59
|
+
expect(solver.solved).toBe(true)
|
|
60
|
+
|
|
61
|
+
const baseElbow = calculateElbow(
|
|
62
|
+
{ x: pins[0].x, y: pins[0].y, facingDirection: pins[0]._facingDirection },
|
|
63
|
+
{ x: pins[1].x, y: pins[1].y, facingDirection: pins[1]._facingDirection },
|
|
64
|
+
{ overshoot: 0.2 },
|
|
65
|
+
)
|
|
66
|
+
const { elbowVariants } = generateElbowVariants({ baseElbow, guidelines })
|
|
67
|
+
const candidates = [baseElbow, ...elbowVariants]
|
|
68
|
+
const shortestLength = Math.min(...candidates.map(pathLength))
|
|
69
|
+
|
|
70
|
+
expect(pathLength(solver.solvedTracePath!)).toBe(shortestLength)
|
|
71
|
+
})
|