@tscircuit/curvy-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 +16 -0
- package/README.md +3 -0
- package/biome.json +96 -0
- package/bunfig.toml +5 -0
- package/cosmos.config.json +5 -0
- package/cosmos.decorator.tsx +21 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +1643 -0
- package/fixtures/basics/basics01-input.json +15 -0
- package/fixtures/basics/basics01.fixture.tsx +11 -0
- package/fixtures/problem-generator.fixture.tsx +50 -0
- package/index.html +12 -0
- package/lib/CurvyTraceSolver.ts +775 -0
- package/lib/geometry/getObstacleOuterSegments.ts +25 -0
- package/lib/geometry/index.ts +8 -0
- package/lib/index.ts +2 -0
- package/lib/problem-generator/countChordCrossings.ts +119 -0
- package/lib/problem-generator/createRng.ts +13 -0
- package/lib/problem-generator/generateRandomProblem.ts +225 -0
- package/lib/problem-generator/index.ts +1 -0
- package/lib/problem-generator/randomBoundaryPoint.ts +30 -0
- package/lib/problem-generator/wouldCrossAny.ts +16 -0
- package/lib/sampleTraceIntoSegments.ts +62 -0
- package/lib/scoreOutputCost.ts +116 -0
- package/lib/types.ts +35 -0
- package/lib/visualization-utils/index.ts +14 -0
- package/lib/visualization-utils/visualizeCurvyTraceProblem.ts +66 -0
- package/package.json +27 -0
- package/scripts/benchmarks/run-benchmark.ts +85 -0
- package/tests/__snapshots__/svg.snap.svg +3 -0
- package/tests/basics/__snapshots__/basics01.snap.svg +44 -0
- package/tests/basics/basics01.test.ts +12 -0
- package/tests/fixtures/preload.ts +1 -0
- package/tests/svg.test.ts +12 -0
- package/tsconfig.json +35 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(npx tsc:*)",
|
|
5
|
+
"mcp__ide__getDiagnostics",
|
|
6
|
+
"Bash(xargs:*)",
|
|
7
|
+
"Bash(npx tsx:*)",
|
|
8
|
+
"Bash(npm run benchmark:*)",
|
|
9
|
+
"Bash(for i in 1 2 3)",
|
|
10
|
+
"Bash(do echo \"Run $i:\")",
|
|
11
|
+
"Bash(done)",
|
|
12
|
+
"Bash(UPDATE_SNAPSHOTS=1 bun test:*)",
|
|
13
|
+
"Bash(BUN_UPDATE_SNAPSHOTS=true bun test:*)"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
package/README.md
ADDED
package/biome.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
"correctness": {
|
|
34
|
+
"useExhaustiveDependencies": "off"
|
|
35
|
+
},
|
|
36
|
+
"a11y": {
|
|
37
|
+
"noAccessKey": "off",
|
|
38
|
+
"noAriaHiddenOnFocusable": "off",
|
|
39
|
+
"noAriaUnsupportedElements": "off",
|
|
40
|
+
"noAutofocus": "off",
|
|
41
|
+
"noDistractingElements": "off",
|
|
42
|
+
"noHeaderScope": "off",
|
|
43
|
+
"noInteractiveElementToNoninteractiveRole": "off",
|
|
44
|
+
"noLabelWithoutControl": "off",
|
|
45
|
+
"noNoninteractiveElementToInteractiveRole": "off",
|
|
46
|
+
"noNoninteractiveTabindex": "off",
|
|
47
|
+
"noPositiveTabindex": "off",
|
|
48
|
+
"noRedundantAlt": "off",
|
|
49
|
+
"noRedundantRoles": "off",
|
|
50
|
+
"noStaticElementInteractions": "off",
|
|
51
|
+
"noSvgWithoutTitle": "off",
|
|
52
|
+
"useAltText": "off",
|
|
53
|
+
"useAnchorContent": "off",
|
|
54
|
+
"useAriaActivedescendantWithTabindex": "off",
|
|
55
|
+
"useAriaPropsForRole": "off",
|
|
56
|
+
"useAriaPropsSupportedByRole": "off",
|
|
57
|
+
"useButtonType": "off",
|
|
58
|
+
"useFocusableInteractive": "off",
|
|
59
|
+
"useHeadingContent": "off",
|
|
60
|
+
"useHtmlLang": "off",
|
|
61
|
+
"useIframeTitle": "off",
|
|
62
|
+
"useKeyWithClickEvents": "off",
|
|
63
|
+
"useKeyWithMouseEvents": "off",
|
|
64
|
+
"useMediaCaption": "off",
|
|
65
|
+
"useSemanticElements": "off",
|
|
66
|
+
"useValidAnchor": "off",
|
|
67
|
+
"useValidAriaProps": "off",
|
|
68
|
+
"useValidAriaRole": "off",
|
|
69
|
+
"useValidAriaValues": "off",
|
|
70
|
+
"useValidAutocomplete": "off",
|
|
71
|
+
"useValidLang": "off"
|
|
72
|
+
},
|
|
73
|
+
"style": {
|
|
74
|
+
"useSingleVarDeclarator": "error",
|
|
75
|
+
"noParameterAssign": "off",
|
|
76
|
+
"noUselessElse": "off",
|
|
77
|
+
"noNonNullAssertion": "off",
|
|
78
|
+
"useNumberNamespace": "off",
|
|
79
|
+
"noUnusedTemplateLiteral": "off",
|
|
80
|
+
"useFilenamingConvention": {
|
|
81
|
+
"level": "error",
|
|
82
|
+
"options": {
|
|
83
|
+
"strictCase": true,
|
|
84
|
+
"requireAscii": true,
|
|
85
|
+
"filenameCases": ["kebab-case", "export"]
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"useAsConstAssertion": "error",
|
|
89
|
+
"useDefaultParameterLast": "error",
|
|
90
|
+
"useEnumInitializers": "error",
|
|
91
|
+
"useSelfClosingElements": "error",
|
|
92
|
+
"noInferrableTypes": "error"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
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
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BaseSolver } from '@tscircuit/solver-utils';
|
|
2
|
+
import { Bounds, Point } from '@tscircuit/math-utils';
|
|
3
|
+
import { GraphicsObject } from 'graphics-debug';
|
|
4
|
+
|
|
5
|
+
interface WaypointPair {
|
|
6
|
+
start: Point;
|
|
7
|
+
end: Point;
|
|
8
|
+
networkId?: string;
|
|
9
|
+
}
|
|
10
|
+
interface Obstacle extends Bounds {
|
|
11
|
+
center: Point;
|
|
12
|
+
networkId?: string;
|
|
13
|
+
outerSegments?: [Point, Point][];
|
|
14
|
+
}
|
|
15
|
+
interface CurvyTraceProblem {
|
|
16
|
+
bounds: Bounds;
|
|
17
|
+
waypointPairs: WaypointPair[];
|
|
18
|
+
obstacles: Obstacle[];
|
|
19
|
+
preferredSpacing: number;
|
|
20
|
+
}
|
|
21
|
+
interface OutputTrace {
|
|
22
|
+
waypointPair: WaypointPair;
|
|
23
|
+
points: Point[];
|
|
24
|
+
networkId?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare class CurvyTraceSolver extends BaseSolver {
|
|
28
|
+
problem: CurvyTraceProblem;
|
|
29
|
+
outputTraces: OutputTrace[];
|
|
30
|
+
private traces;
|
|
31
|
+
private optimizationStep;
|
|
32
|
+
private readonly maxOptimizationSteps;
|
|
33
|
+
private sampledPoints;
|
|
34
|
+
private traceBounds;
|
|
35
|
+
private obstacleSegments;
|
|
36
|
+
private obstacleNetworkIds;
|
|
37
|
+
private numObstacleSegments;
|
|
38
|
+
private collisionPairs;
|
|
39
|
+
private lastCost;
|
|
40
|
+
private stagnantSteps;
|
|
41
|
+
constructor(problem: CurvyTraceProblem);
|
|
42
|
+
getConstructorParams(): CurvyTraceProblem;
|
|
43
|
+
private precomputeObstacles;
|
|
44
|
+
private initializeTraces;
|
|
45
|
+
private updateSampledTraces;
|
|
46
|
+
private updateSingleTraceSample;
|
|
47
|
+
private updateCollisionPairs;
|
|
48
|
+
private computeTotalCost;
|
|
49
|
+
private computeCostForTrace;
|
|
50
|
+
private optimizeStep;
|
|
51
|
+
private buildOutputTraces;
|
|
52
|
+
_step(): void;
|
|
53
|
+
visualize(): GraphicsObject;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { type CurvyTraceProblem, CurvyTraceSolver, type Obstacle, type OutputTrace, type WaypointPair };
|