@tscircuit/schematic-trace-solver 0.0.1
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/.claude/settings.local.json +6 -0
- package/.github/workflows/bun-formatcheck.yml +26 -0
- package/.github/workflows/bun-pver-release.yml +28 -0
- package/.github/workflows/bun-test.yml +28 -0
- package/.github/workflows/bun-typecheck.yml +26 -0
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/biome.json +93 -0
- package/bunfig.toml +5 -0
- package/cosmos.config.json +6 -0
- package/cosmos.decorator.tsx +21 -0
- package/dist/index.d.ts +420 -0
- package/dist/index.js +7863 -0
- package/index.html +17 -0
- package/lib/data-structures/ChipObstacleSpatialIndex.ts +70 -0
- package/lib/index.ts +2 -0
- package/lib/solvers/BaseSolver/BaseSolver.ts +83 -0
- package/lib/solvers/GuidelinesSolver/GuidelinesSolver.ts +138 -0
- package/lib/solvers/GuidelinesSolver/getGeneratorForAllChipPairs.ts +39 -0
- package/lib/solvers/GuidelinesSolver/getHorizontalGuidelineY.ts +18 -0
- package/lib/solvers/GuidelinesSolver/getInputChipBounds.ts +20 -0
- package/lib/solvers/GuidelinesSolver/getVerticalGuidelineX.ts +18 -0
- package/lib/solvers/GuidelinesSolver/visualizeGuidelines.ts +45 -0
- package/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts +156 -0
- package/lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem.ts +20 -0
- package/lib/solvers/MspConnectionPairSolver/getMspConnectionPairsFromPins.ts +96 -0
- package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +192 -0
- package/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/SingleNetLabelPlacementSolver.ts +479 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver.ts +127 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/SchematicTraceSingleLineSolver.ts +191 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/generateElbowVariants.ts +132 -0
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/getPinDirection.ts +42 -0
- package/lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts +244 -0
- package/lib/solvers/SchematicTracePipelineSolver/visualizeInputProblem.ts +89 -0
- package/lib/solvers/TraceOverlapShiftSolver/TraceOverlapIssueSolver/TraceOverlapIssueSolver.ts +180 -0
- package/lib/solvers/TraceOverlapShiftSolver/TraceOverlapShiftSolver.ts +264 -0
- package/lib/types/InputProblem.ts +40 -0
- package/lib/utils/dir.ts +16 -0
- package/lib/utils/getAllPossibleOrderingsGenerator.ts +47 -0
- package/lib/utils/getColorFromString.ts +7 -0
- package/package.json +29 -0
- package/site/components/GenericSolverDebugger.tsx +0 -0
- package/site/components/PipelineDebugger.tsx +29 -0
- package/site/components/PipelineStageTable.tsx +149 -0
- package/site/components/SolverBreadcrumbInputDownloader.tsx +62 -0
- package/site/components/SolverToolbar.tsx +128 -0
- package/site/examples/example01-basic.page.tsx +104 -0
- package/tests/functions/generateElbowVariants.test.ts +98 -0
- package/tests/functions/getOrthogonalMinimumSpanningTree.test.ts +23 -0
- package/tsconfig.json +37 -0
- package/vite.config.ts +12 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Format Check
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
format-check:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Setup bun
|
|
18
|
+
uses: oven-sh/setup-bun@v2
|
|
19
|
+
with:
|
|
20
|
+
bun-version: latest
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: bun install
|
|
24
|
+
|
|
25
|
+
- name: Run format check
|
|
26
|
+
run: bun run format:check
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Publish to npm
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
with:
|
|
13
|
+
token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
|
|
14
|
+
- name: Setup bun
|
|
15
|
+
uses: oven-sh/setup-bun@v2
|
|
16
|
+
with:
|
|
17
|
+
bun-version: latest
|
|
18
|
+
- uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: 20
|
|
21
|
+
registry-url: https://registry.npmjs.org/
|
|
22
|
+
- run: npm install -g pver
|
|
23
|
+
- run: bun install --frozen-lockfile
|
|
24
|
+
- run: bun run build
|
|
25
|
+
- run: pver release
|
|
26
|
+
env:
|
|
27
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
28
|
+
GITHUB_TOKEN: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Bun Test
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
pull_request:
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
test:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
timeout-minutes: 5
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout code
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Setup bun
|
|
20
|
+
uses: oven-sh/setup-bun@v2
|
|
21
|
+
with:
|
|
22
|
+
bun-version: latest
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: bun install
|
|
26
|
+
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: bun test
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Type Check
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
type-check:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Setup bun
|
|
18
|
+
uses: oven-sh/setup-bun@v2
|
|
19
|
+
with:
|
|
20
|
+
bun-version: latest
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: bun i
|
|
24
|
+
|
|
25
|
+
- name: Run type check
|
|
26
|
+
run: bunx tsc --noEmit
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 tscircuit Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Schematic Trace Solver
|
|
2
|
+
|
|
3
|
+
Solve for the correct positions and routing for schematic traces and net labels. For use inside [@tscircuit/core](https://github.com/tscircuit/core)
|
|
4
|
+
|
|
5
|
+
[Online Playground](https://schematic-trace-solver.vercel.app) ・ [tscircuit](https://github.com/tscircuit/tscircuit) ・ [@tscircuit/core](https://github.com/tscircuit/core)
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The Schematic Trace Solver is a pipeline that figures out how to route schematic traces
|
|
10
|
+
and place net labels for a given schematic layout.
|
|
11
|
+
|
|
12
|
+
Chips are defined by their center point, width, and height and pins.
|
|
13
|
+
|
|
14
|
+
You then pass in direct connections and net connections. Direct connections are
|
|
15
|
+
explicit pin-to-pin connections. When there's a direct connection between two
|
|
16
|
+
pins, there is guaranteed to be a routed trace between them.
|
|
17
|
+
|
|
18
|
+
Net connections will not be routed, net labels are placed instead.
|
|
19
|
+
|
|
20
|
+
The solver first constructs minimum spanning tree to determine what pin-pairs
|
|
21
|
+
to draw via the `MspConnectionPairSolver`. If there are two pins A and B that both connect to C, this phase will
|
|
22
|
+
determine how to route traces to minimize overlap or crossings. e.g. we may
|
|
23
|
+
decide to route a trace from A to B, then B to C OR we may decide to route a
|
|
24
|
+
trace from A to C, then C to B. The pairs of traces are the mspConnectionPairs,
|
|
25
|
+
these are used in future phases.
|
|
26
|
+
|
|
27
|
+
After the minimum spanning tree is constructed, we draw the schematic traces
|
|
28
|
+
for each mspConnectionPair via the `SchematicTraceLinesSolver`. The `TraceOverlapShiftSolver`
|
|
29
|
+
then shifts the schematic traces to make sure there are no parallel overlapping traces by
|
|
30
|
+
shifting parallel traces orthogonally by a small amount.
|
|
31
|
+
|
|
32
|
+
Finally, the `NetLabelPlacementSolver` places net labels for each net connection. Often
|
|
33
|
+
this requires drawing small traces to adapt to the `availableFacingDirections` of the net connection.
|
|
34
|
+
If there is crowding at the pin, we look for an available spot along the trace connected to the pin.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { SchematicTracePipelineSolver } from "@tscircuit/schematic-trace-solver"
|
|
40
|
+
|
|
41
|
+
type ChipId = string
|
|
42
|
+
type PinId = string
|
|
43
|
+
|
|
44
|
+
const solver = new SchematicTracePipelineSolver({
|
|
45
|
+
chips: {
|
|
46
|
+
chipId: "U1",
|
|
47
|
+
center: { x: 0, y: 0 },
|
|
48
|
+
width: 1.6,
|
|
49
|
+
height: 0.6,
|
|
50
|
+
pins: [
|
|
51
|
+
{
|
|
52
|
+
pinId: "U1.1",
|
|
53
|
+
x: -0.8,
|
|
54
|
+
y: 0.2,
|
|
55
|
+
},
|
|
56
|
+
// ...
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
directConnections: [
|
|
60
|
+
{
|
|
61
|
+
pinIds: ["U1.1", "C1.1"],
|
|
62
|
+
netId: "VCC",
|
|
63
|
+
},
|
|
64
|
+
// ...
|
|
65
|
+
],
|
|
66
|
+
netConnections: [
|
|
67
|
+
{
|
|
68
|
+
availableFacingDirections: ["y-"],
|
|
69
|
+
netId: "GND",
|
|
70
|
+
pinIds: ["U1.3", "C1.2", "C2.2"],
|
|
71
|
+
},
|
|
72
|
+
// ...
|
|
73
|
+
],
|
|
74
|
+
})
|
|
75
|
+
```
|
package/biome.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
|
|
3
|
+
"assist": { "actions": { "source": { "organizeImports": "on" } } },
|
|
4
|
+
"formatter": {
|
|
5
|
+
"enabled": true,
|
|
6
|
+
"indentStyle": "space"
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"includes": ["**", "!**/cosmos-export", "!**/dist", "!**/package.json"]
|
|
10
|
+
},
|
|
11
|
+
"javascript": {
|
|
12
|
+
"formatter": {
|
|
13
|
+
"jsxQuoteStyle": "double",
|
|
14
|
+
"quoteProperties": "asNeeded",
|
|
15
|
+
"trailingCommas": "all",
|
|
16
|
+
"semicolons": "asNeeded",
|
|
17
|
+
"arrowParentheses": "always",
|
|
18
|
+
"bracketSpacing": true,
|
|
19
|
+
"bracketSameLine": false
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"linter": {
|
|
23
|
+
"enabled": true,
|
|
24
|
+
"rules": {
|
|
25
|
+
"recommended": true,
|
|
26
|
+
"suspicious": {
|
|
27
|
+
"noExplicitAny": "off"
|
|
28
|
+
},
|
|
29
|
+
"complexity": {
|
|
30
|
+
"noForEach": "error",
|
|
31
|
+
"useLiteralKeys": "off"
|
|
32
|
+
},
|
|
33
|
+
"a11y": {
|
|
34
|
+
"noAccessKey": "off",
|
|
35
|
+
"noAriaHiddenOnFocusable": "off",
|
|
36
|
+
"noAriaUnsupportedElements": "off",
|
|
37
|
+
"noAutofocus": "off",
|
|
38
|
+
"noDistractingElements": "off",
|
|
39
|
+
"noHeaderScope": "off",
|
|
40
|
+
"noInteractiveElementToNoninteractiveRole": "off",
|
|
41
|
+
"noLabelWithoutControl": "off",
|
|
42
|
+
"noNoninteractiveElementToInteractiveRole": "off",
|
|
43
|
+
"noNoninteractiveTabindex": "off",
|
|
44
|
+
"noPositiveTabindex": "off",
|
|
45
|
+
"noRedundantAlt": "off",
|
|
46
|
+
"noRedundantRoles": "off",
|
|
47
|
+
"noStaticElementInteractions": "off",
|
|
48
|
+
"noSvgWithoutTitle": "off",
|
|
49
|
+
"useAltText": "off",
|
|
50
|
+
"useAnchorContent": "off",
|
|
51
|
+
"useAriaActivedescendantWithTabindex": "off",
|
|
52
|
+
"useAriaPropsForRole": "off",
|
|
53
|
+
"useAriaPropsSupportedByRole": "off",
|
|
54
|
+
"useButtonType": "off",
|
|
55
|
+
"useFocusableInteractive": "off",
|
|
56
|
+
"useHeadingContent": "off",
|
|
57
|
+
"useHtmlLang": "off",
|
|
58
|
+
"useIframeTitle": "off",
|
|
59
|
+
"useKeyWithClickEvents": "off",
|
|
60
|
+
"useKeyWithMouseEvents": "off",
|
|
61
|
+
"useMediaCaption": "off",
|
|
62
|
+
"useSemanticElements": "off",
|
|
63
|
+
"useValidAnchor": "off",
|
|
64
|
+
"useValidAriaProps": "off",
|
|
65
|
+
"useValidAriaRole": "off",
|
|
66
|
+
"useValidAriaValues": "off",
|
|
67
|
+
"useValidAutocomplete": "off",
|
|
68
|
+
"useValidLang": "off"
|
|
69
|
+
},
|
|
70
|
+
"style": {
|
|
71
|
+
"useSingleVarDeclarator": "error",
|
|
72
|
+
"noParameterAssign": "off",
|
|
73
|
+
"noUselessElse": "off",
|
|
74
|
+
"noNonNullAssertion": "off",
|
|
75
|
+
"useNumberNamespace": "off",
|
|
76
|
+
"noUnusedTemplateLiteral": "off",
|
|
77
|
+
"useFilenamingConvention": {
|
|
78
|
+
"level": "error",
|
|
79
|
+
"options": {
|
|
80
|
+
"strictCase": true,
|
|
81
|
+
"requireAscii": true,
|
|
82
|
+
"filenameCases": ["kebab-case", "export"]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"useAsConstAssertion": "error",
|
|
86
|
+
"useDefaultParameterLast": "error",
|
|
87
|
+
"useEnumInitializers": "error",
|
|
88
|
+
"useSelfClosingElements": "error",
|
|
89
|
+
"noInferrableTypes": "error"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
package/bunfig.toml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { useEffect } from "react"
|
|
2
|
+
|
|
3
|
+
export const TailwindDecorator = ({
|
|
4
|
+
children,
|
|
5
|
+
}: {
|
|
6
|
+
children: React.ReactNode
|
|
7
|
+
}) => {
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const script = document.createElement("script")
|
|
10
|
+
script.src = "https://cdn.tailwindcss.com"
|
|
11
|
+
document.head.appendChild(script)
|
|
12
|
+
|
|
13
|
+
return () => {
|
|
14
|
+
document.head.removeChild(script)
|
|
15
|
+
}
|
|
16
|
+
}, [])
|
|
17
|
+
|
|
18
|
+
return <>{children}</>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default TailwindDecorator
|