@tscircuit/schematic-trace-solver 0.0.32 → 0.0.34
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.d.ts +24 -53
- package/dist/index.js +526 -847
- package/lib/index.ts +1 -0
- package/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts +54 -3
- package/lib/solvers/MspConnectionPairSolver/doesPairCrossRestrictedCenterLines.ts +62 -0
- package/lib/solvers/MspConnectionPairSolver/getMspConnectionPairsFromPins.ts +7 -2
- package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +25 -4
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver.ts +3 -10
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2.ts +239 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/collisions.ts +57 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/mid.ts +97 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/pathOps.ts +65 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/rect.ts +19 -0
- package/lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts +14 -14
- package/package.json +1 -1
- package/site/examples/example09.page.tsx +1 -1
- package/site/examples/example15-rp2040-caps.page.tsx +623 -0
- package/site/examples/example16-core-repro51.page.tsx +107 -0
- package/site/examples/example17-straight-line-trace.page.tsx +165 -0
- package/site/examples/example18.page.tsx +181 -0
- package/site/examples/example19.page.tsx +169 -0
- package/tests/examples/__snapshots__/example01.snap.svg +29 -29
- package/tests/examples/__snapshots__/example02.snap.svg +13 -10
- package/tests/examples/__snapshots__/example04.snap.svg +12 -12
- package/tests/examples/__snapshots__/example05.snap.svg +38 -38
- package/tests/examples/__snapshots__/example06.snap.svg +14 -14
- package/tests/examples/__snapshots__/example08.snap.svg +29 -23
- package/tests/examples/__snapshots__/example09.snap.svg +119 -149
- package/tests/examples/__snapshots__/example11.snap.svg +39 -33
- package/tests/examples/__snapshots__/example12.snap.svg +32 -29
- package/tests/examples/__snapshots__/example13.snap.svg +87 -84
- package/tests/examples/__snapshots__/example15.snap.svg +800 -71
- package/tests/examples/__snapshots__/example16.snap.svg +40 -86
- package/tests/examples/__snapshots__/example17.snap.svg +190 -0
- package/tests/examples/__snapshots__/example18.snap.svg +235 -0
- package/tests/examples/__snapshots__/example19.snap.svg +195 -0
- package/tests/examples/example15.test.tsx +524 -82
- package/tests/examples/example16.test.tsx +56 -118
- package/tests/examples/example17.test.tsx +171 -0
- package/tests/examples/example18.test.tsx +187 -0
- package/tests/examples/example19.test.tsx +175 -0
- package/tests/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver_repro03.test.ts +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Point } from "@tscircuit/math-utils"
|
|
2
|
+
import { isHorizontal, isVertical } from "./collisions"
|
|
3
|
+
|
|
4
|
+
const EPS = 1e-9
|
|
5
|
+
|
|
6
|
+
export type Axis = "x" | "y"
|
|
7
|
+
|
|
8
|
+
export const shiftSegmentOrth = (
|
|
9
|
+
pts: Point[],
|
|
10
|
+
segIndex: number,
|
|
11
|
+
axis: Axis,
|
|
12
|
+
newCoord: number,
|
|
13
|
+
eps = EPS,
|
|
14
|
+
): Point[] | null => {
|
|
15
|
+
if (segIndex < 0 || segIndex >= pts.length - 1) return null
|
|
16
|
+
const a = pts[segIndex]!
|
|
17
|
+
const b = pts[segIndex + 1]!
|
|
18
|
+
const vert = isVertical(a, b, eps)
|
|
19
|
+
const horz = isHorizontal(a, b, eps)
|
|
20
|
+
if (!vert && !horz) return null
|
|
21
|
+
|
|
22
|
+
// Ensure axis matches orthogonal shift
|
|
23
|
+
if (vert && axis !== "x") return null
|
|
24
|
+
if (horz && axis !== "y") return null
|
|
25
|
+
|
|
26
|
+
const out = pts.map((p) => ({ ...p }))
|
|
27
|
+
|
|
28
|
+
if (axis === "x") {
|
|
29
|
+
if (Math.abs(a.x - newCoord) < eps && Math.abs(b.x - newCoord) < eps)
|
|
30
|
+
return null
|
|
31
|
+
out[segIndex] = { ...out[segIndex], x: newCoord }
|
|
32
|
+
out[segIndex + 1] = { ...out[segIndex + 1], x: newCoord }
|
|
33
|
+
} else {
|
|
34
|
+
if (Math.abs(a.y - newCoord) < eps && Math.abs(b.y - newCoord) < eps)
|
|
35
|
+
return null
|
|
36
|
+
out[segIndex] = { ...out[segIndex], y: newCoord }
|
|
37
|
+
out[segIndex + 1] = { ...out[segIndex + 1], y: newCoord }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Prevent collapsing adjacent segments
|
|
41
|
+
if (segIndex - 1 >= 0) {
|
|
42
|
+
const p = out[segIndex - 1]!
|
|
43
|
+
const q = out[segIndex]!
|
|
44
|
+
const manhattan = Math.abs(p.x - q.x) + Math.abs(p.y - q.y)
|
|
45
|
+
if (manhattan < eps) return null
|
|
46
|
+
}
|
|
47
|
+
if (segIndex + 2 <= out.length - 1) {
|
|
48
|
+
const p = out[segIndex + 1]!
|
|
49
|
+
const q = out[segIndex + 2]!
|
|
50
|
+
const manhattan = Math.abs(p.x - q.x) + Math.abs(p.y - q.y)
|
|
51
|
+
if (manhattan < eps) return null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Sanity: still orthogonal
|
|
55
|
+
for (let i = 0; i < out.length - 1; i++) {
|
|
56
|
+
const u = out[i]!
|
|
57
|
+
const v = out[i + 1]!
|
|
58
|
+
if (!isHorizontal(u, v, eps) && !isVertical(u, v, eps)) return null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const pathKey = (pts: Point[], decimals = 6) =>
|
|
65
|
+
pts.map((p) => `${p.x.toFixed(decimals)},${p.y.toFixed(decimals)}`).join("|")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InputChip, InputProblem } from "lib/types/InputProblem"
|
|
2
|
+
import { getInputChipBounds } from "lib/solvers/GuidelinesSolver/getInputChipBounds"
|
|
3
|
+
|
|
4
|
+
export type ChipWithBounds = {
|
|
5
|
+
chipId: string
|
|
6
|
+
minX: number
|
|
7
|
+
minY: number
|
|
8
|
+
maxX: number
|
|
9
|
+
maxY: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const chipToRect = (chip: InputChip): ChipWithBounds => {
|
|
13
|
+
const b = getInputChipBounds(chip)
|
|
14
|
+
return { chipId: chip.chipId, ...b }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getObstacleRects = (problem: InputProblem): ChipWithBounds[] => {
|
|
18
|
+
return problem.chips.map(chipToRect)
|
|
19
|
+
}
|
|
@@ -48,7 +48,7 @@ function definePipelineStep<
|
|
|
48
48
|
|
|
49
49
|
export class SchematicTracePipelineSolver extends BaseSolver {
|
|
50
50
|
mspConnectionPairSolver?: MspConnectionPairSolver
|
|
51
|
-
guidelinesSolver?: GuidelinesSolver
|
|
51
|
+
// guidelinesSolver?: GuidelinesSolver
|
|
52
52
|
schematicTraceLinesSolver?: SchematicTraceLinesSolver
|
|
53
53
|
traceOverlapShiftSolver?: TraceOverlapShiftSolver
|
|
54
54
|
netLabelPlacementSolver?: NetLabelPlacementSolver
|
|
@@ -69,18 +69,18 @@ export class SchematicTracePipelineSolver extends BaseSolver {
|
|
|
69
69
|
onSolved: (mspSolver) => {},
|
|
70
70
|
},
|
|
71
71
|
),
|
|
72
|
-
definePipelineStep(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
),
|
|
72
|
+
// definePipelineStep(
|
|
73
|
+
// "guidelinesSolver",
|
|
74
|
+
// GuidelinesSolver,
|
|
75
|
+
// () => [
|
|
76
|
+
// {
|
|
77
|
+
// inputProblem: this.inputProblem,
|
|
78
|
+
// },
|
|
79
|
+
// ],
|
|
80
|
+
// {
|
|
81
|
+
// onSolved: (guidelinesSolver) => {},
|
|
82
|
+
// },
|
|
83
|
+
// ),
|
|
84
84
|
definePipelineStep(
|
|
85
85
|
"schematicTraceLinesSolver",
|
|
86
86
|
SchematicTraceLinesSolver,
|
|
@@ -90,7 +90,7 @@ export class SchematicTracePipelineSolver extends BaseSolver {
|
|
|
90
90
|
dcConnMap: this.mspConnectionPairSolver!.dcConnMap,
|
|
91
91
|
globalConnMap: this.mspConnectionPairSolver!.globalConnMap,
|
|
92
92
|
inputProblem: this.inputProblem,
|
|
93
|
-
guidelines: this.guidelinesSolver!.guidelines,
|
|
93
|
+
// guidelines: this.guidelinesSolver!.guidelines,
|
|
94
94
|
chipMap: this.mspConnectionPairSolver!.chipMap,
|
|
95
95
|
},
|
|
96
96
|
],
|
package/package.json
CHANGED