@tscircuit/rectdiff 0.0.24 → 0.0.25
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/AGENTS.md +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +69 -77
- package/lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts +23 -23
- package/lib/solvers/RectDiffSeedingSolver/computeCandidates3D.ts +9 -10
- package/lib/solvers/RectDiffSeedingSolver/computeEdgeCandidates3D.ts +22 -19
- package/lib/solvers/RectDiffSeedingSolver/longestFreeSpanAroundZ.ts +1 -1
- package/lib/utils/expandRectFromSeed.ts +8 -10
- package/lib/utils/isFullyOccupiedAtPoint.ts +2 -2
- package/lib/utils/rectdiff-geometry.ts +13 -20
- package/package.json +2 -1
- package/scripts/benchmark-slow-problem.ts +94 -0
- package/test-assets/keyboard4.json +16165 -0
- package/tests/solver/__snapshots__/rectDiffGridSolverPipeline.snap.svg +1 -1
- package/tests/solver/bugreport03-fe4a17/__snapshots__/bugreport03-fe4a17.snap.svg +1 -1
- package/tests/solver/bugreport09-618e09/__snapshots__/bugreport09-618e09.snap.svg +1 -1
- package/tests/solver/bugreport10-71239a/__snapshots__/bugreport10-71239a.snap.svg +1 -1
- package/tests/solver/bugreport11-b2de3c/__snapshots__/bugreport11-b2de3c.snap.svg +1 -1
- package/tests/solver/bugreport35-191db9/__snapshots__/bugreport35-191db9.snap.svg +1 -1
- package/tests/solver/bugreport36-bf8303/__snapshots__/bugreport36-bf8303.snap.svg +1 -1
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/rectdiff",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "cosmos",
|
|
8
8
|
"build": "tsup-node ./lib/index.ts --format esm --dts",
|
|
9
9
|
"build:site": "cosmos-export",
|
|
10
|
+
"benchmark:slow-problem": "bun scripts/benchmark-slow-problem.ts test-assets/keyboard4.json",
|
|
10
11
|
"format": "biome format --write .",
|
|
11
12
|
"format:check": "biome format ."
|
|
12
13
|
},
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { RectDiffPipeline } from "../lib/RectDiffPipeline"
|
|
2
|
+
import type { SimpleRouteJson } from "../lib/types/srj-types"
|
|
3
|
+
|
|
4
|
+
type BenchmarkInput = {
|
|
5
|
+
simpleRouteJson: SimpleRouteJson
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const args = Bun.argv.slice(2)
|
|
9
|
+
const filePath = args[0] ?? "test-assets/keyboard4.json"
|
|
10
|
+
const repeatArg = args.find((arg) => arg.startsWith("--repeat="))
|
|
11
|
+
const repeatCount = repeatArg
|
|
12
|
+
? Number.parseInt(repeatArg.split("=")[1]!, 10)
|
|
13
|
+
: 5
|
|
14
|
+
|
|
15
|
+
const data = JSON.parse(await Bun.file(filePath).text()) as
|
|
16
|
+
| BenchmarkInput
|
|
17
|
+
| BenchmarkInput[]
|
|
18
|
+
const input = Array.isArray(data) ? data[0] : data
|
|
19
|
+
|
|
20
|
+
if (!input?.simpleRouteJson) {
|
|
21
|
+
throw new Error(`Expected ${filePath} to contain { simpleRouteJson } input`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const areaScore = (
|
|
25
|
+
meshNodes: ReturnType<RectDiffPipeline["getOutput"]>["meshNodes"],
|
|
26
|
+
) =>
|
|
27
|
+
meshNodes.reduce(
|
|
28
|
+
(sum, node) =>
|
|
29
|
+
sum + node.width * node.height * (node.availableZ?.length ?? 1),
|
|
30
|
+
0,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const runs: Array<{
|
|
34
|
+
totalMs: number
|
|
35
|
+
gridMs: number
|
|
36
|
+
gapFillMs: number
|
|
37
|
+
nodeCount: number
|
|
38
|
+
area: number
|
|
39
|
+
}> = []
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < repeatCount; i++) {
|
|
42
|
+
const solver = new RectDiffPipeline(input)
|
|
43
|
+
const t0 = performance.now()
|
|
44
|
+
solver.solve()
|
|
45
|
+
const t1 = performance.now()
|
|
46
|
+
const meshNodes = solver.getOutput().meshNodes
|
|
47
|
+
const stages = solver.getStageStats()
|
|
48
|
+
runs.push({
|
|
49
|
+
totalMs: t1 - t0,
|
|
50
|
+
gridMs: stages.rectDiffGridSolverPipeline?.timeSpent ?? 0,
|
|
51
|
+
gapFillMs: stages.gapFillSolver?.timeSpent ?? 0,
|
|
52
|
+
nodeCount: meshNodes.length,
|
|
53
|
+
area: areaScore(meshNodes),
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const mean = (values: number[]) =>
|
|
58
|
+
values.reduce((sum, value) => sum + value, 0) / values.length
|
|
59
|
+
|
|
60
|
+
console.log(
|
|
61
|
+
JSON.stringify(
|
|
62
|
+
{
|
|
63
|
+
filePath,
|
|
64
|
+
repeatCount,
|
|
65
|
+
obstacleCount: input.simpleRouteJson.obstacles?.length ?? 0,
|
|
66
|
+
connectionCount: input.simpleRouteJson.connections?.length ?? 0,
|
|
67
|
+
averages: {
|
|
68
|
+
totalMs: Number.parseFloat(
|
|
69
|
+
mean(runs.map((run) => run.totalMs)).toFixed(2),
|
|
70
|
+
),
|
|
71
|
+
gridMs: Number.parseFloat(
|
|
72
|
+
mean(runs.map((run) => run.gridMs)).toFixed(2),
|
|
73
|
+
),
|
|
74
|
+
gapFillMs: Number.parseFloat(
|
|
75
|
+
mean(runs.map((run) => run.gapFillMs)).toFixed(2),
|
|
76
|
+
),
|
|
77
|
+
nodeCount: Number.parseFloat(
|
|
78
|
+
mean(runs.map((run) => run.nodeCount)).toFixed(2),
|
|
79
|
+
),
|
|
80
|
+
area: Number.parseFloat(mean(runs.map((run) => run.area)).toFixed(2)),
|
|
81
|
+
},
|
|
82
|
+
runs: runs.map((run, index) => ({
|
|
83
|
+
run: index + 1,
|
|
84
|
+
totalMs: Number.parseFloat(run.totalMs.toFixed(2)),
|
|
85
|
+
gridMs: Number.parseFloat(run.gridMs.toFixed(2)),
|
|
86
|
+
gapFillMs: Number.parseFloat(run.gapFillMs.toFixed(2)),
|
|
87
|
+
nodeCount: run.nodeCount,
|
|
88
|
+
area: Number.parseFloat(run.area.toFixed(2)),
|
|
89
|
+
})),
|
|
90
|
+
},
|
|
91
|
+
null,
|
|
92
|
+
2,
|
|
93
|
+
),
|
|
94
|
+
)
|