@tscircuit/rectdiff 0.0.18 → 0.0.20
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 +4 -19
- package/dist/index.js +202 -131
- package/lib/fixtures/twoNodeExpansionFixture.ts +2 -9
- package/lib/solvers/RectDiffExpansionSolver/RectDiffExpansionSolver.ts +55 -108
- package/lib/solvers/RectDiffGridSolverPipeline/RectDiffGridSolverPipeline.ts +22 -7
- package/lib/solvers/RectDiffGridSolverPipeline/buildObstacleIndexes.ts +2 -1
- package/lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts +5 -16
- package/lib/types/capacity-mesh-types.ts +1 -0
- package/lib/utils/expandRectFromSeed.ts +89 -2
- package/lib/utils/isSelfRect.ts +15 -0
- package/lib/utils/rectToTree.ts +5 -1
- package/lib/utils/resizeSoftOverlaps.ts +8 -16
- package/lib/utils/searchStrip.ts +50 -0
- package/package.json +1 -1
- package/tests/__snapshots__/should-expand-node.snap.svg +2 -2
- package/tests/fixtures/makeSimpleRouteOutlineGraphics.ts +41 -0
- package/tests/incremental-solver.test.ts +1 -1
- package/tests/should-expand-node.test.ts +6 -3
- package/tests/solver/__snapshots__/rectDiffGridSolverPipeline.snap.svg +1 -1
- package/tests/solver/rectDiffGridSolverPipeline.test.ts +5 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<svg width="640" height="480" viewBox="0 0 640 480" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="white"/><g><rect data-type="rect" data-label="node" data-x="
|
|
1
|
+
<svg width="640" height="480" viewBox="0 0 640 480" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="white"/><g><polyline data-points="0,0 12,0 12,4 0,4 0,0" data-type="line" data-label="bounds" points="40,333.3333333333333 600,333.3333333333333 600,146.66666666666666 40,146.66666666666666 40,333.3333333333333" fill="none" stroke="#111827" stroke-width="4.666666666666667"/></g><g><rect data-type="rect" data-label="node" data-x="4.75" data-y="2" x="40" y="146.66666666666666" width="443.3333333333333" height="186.66666666666666" fill="#dbeafe" stroke="black" stroke-width="0.02142857142857143"/></g><g><rect data-type="rect" data-label="node" data-x="10.75" data-y="2" x="483.3333333333333" y="146.66666666666666" width="116.66666666666669" height="186.66666666666666" fill="#dbeafe" stroke="black" stroke-width="0.02142857142857143"/></g><g id="crosshair" style="display: none"><line id="crosshair-h" y1="0" y2="480" stroke="#666" stroke-width="0.5"/><line id="crosshair-v" x1="0" x2="640" stroke="#666" stroke-width="0.5"/><text id="coordinates" font-family="monospace" font-size="12" fill="#666"></text></g><script><![CDATA[
|
|
2
2
|
document.currentScript.parentElement.addEventListener('mousemove', (e) => {
|
|
3
3
|
const svg = e.currentTarget;
|
|
4
4
|
const rect = svg.getBoundingClientRect();
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
v.setAttribute('y2', '480');
|
|
21
21
|
|
|
22
22
|
// Calculate real coordinates using inverse transformation
|
|
23
|
-
const matrix = {"a":
|
|
23
|
+
const matrix = {"a":46.666666666666664,"c":0,"e":40,"b":0,"d":-46.666666666666664,"f":333.3333333333333};
|
|
24
24
|
// Manually invert and apply the affine transform
|
|
25
25
|
// Since we only use translate and scale, we can directly compute:
|
|
26
26
|
// x' = (x - tx) / sx
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { GraphicsObject, Line } from "graphics-debug"
|
|
2
|
+
import type { SimpleRouteJson } from "lib/types/srj-types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a GraphicsObject that draws the SRJ outline (or bounds fallback).
|
|
6
|
+
*/
|
|
7
|
+
export const makeSimpleRouteOutlineGraphics = (
|
|
8
|
+
srj: SimpleRouteJson,
|
|
9
|
+
): GraphicsObject => {
|
|
10
|
+
const lines: NonNullable<Line[]> = []
|
|
11
|
+
|
|
12
|
+
if (srj.outline && srj.outline.length > 1) {
|
|
13
|
+
lines.push({
|
|
14
|
+
points: [...srj.outline, srj.outline[0]!],
|
|
15
|
+
strokeColor: "#111827",
|
|
16
|
+
strokeWidth: 0.1,
|
|
17
|
+
label: "outline",
|
|
18
|
+
})
|
|
19
|
+
} else {
|
|
20
|
+
const { minX, maxX, minY, maxY } = srj.bounds
|
|
21
|
+
lines.push({
|
|
22
|
+
points: [
|
|
23
|
+
{ x: minX, y: minY },
|
|
24
|
+
{ x: maxX, y: minY },
|
|
25
|
+
{ x: maxX, y: maxY },
|
|
26
|
+
{ x: minX, y: maxY },
|
|
27
|
+
{ x: minX, y: minY },
|
|
28
|
+
],
|
|
29
|
+
strokeColor: "#111827",
|
|
30
|
+
strokeWidth: 0.1,
|
|
31
|
+
label: "bounds",
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
title: "SimpleRoute Outline",
|
|
37
|
+
coordinateSystem: "cartesian",
|
|
38
|
+
lines,
|
|
39
|
+
points: [],
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -28,7 +28,7 @@ test("RectDiffSolver supports incremental stepping", () => {
|
|
|
28
28
|
|
|
29
29
|
// Step advances one candidate at a time
|
|
30
30
|
let stepCount = 0
|
|
31
|
-
const maxSteps =
|
|
31
|
+
const maxSteps = 5000 // safety limit
|
|
32
32
|
|
|
33
33
|
while (!pipeline.solved && stepCount < maxSteps) {
|
|
34
34
|
pipeline.step()
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { expect, test } from "bun:test"
|
|
2
|
-
import { getSvgFromGraphicsObject } from "graphics-debug"
|
|
2
|
+
import { getSvgFromGraphicsObject, mergeGraphics } from "graphics-debug"
|
|
3
3
|
import { RectDiffExpansionSolver } from "lib/solvers/RectDiffExpansionSolver/RectDiffExpansionSolver"
|
|
4
4
|
import { createTwoNodeExpansionInput } from "lib/fixtures/twoNodeExpansionFixture"
|
|
5
5
|
import { makeCapacityMeshNodeWithLayerInfo } from "./fixtures/makeCapacityMeshNodeWithLayerInfo"
|
|
6
|
+
import { makeSimpleRouteOutlineGraphics } from "./fixtures/makeSimpleRouteOutlineGraphics"
|
|
6
7
|
|
|
7
8
|
test("RectDiff expansion reproduces the two-node gap fixture", async () => {
|
|
8
|
-
const
|
|
9
|
+
const input = createTwoNodeExpansionInput()
|
|
10
|
+
const solver = new RectDiffExpansionSolver(input)
|
|
9
11
|
|
|
10
12
|
solver.solve()
|
|
11
13
|
|
|
@@ -13,8 +15,9 @@ test("RectDiff expansion reproduces the two-node gap fixture", async () => {
|
|
|
13
15
|
expect(meshNodes.length).toBeGreaterThanOrEqual(2)
|
|
14
16
|
|
|
15
17
|
const finalGraphics = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
18
|
+
const outline = makeSimpleRouteOutlineGraphics(input.srj)
|
|
16
19
|
const svg = getSvgFromGraphicsObject(
|
|
17
|
-
{ rects: finalGraphics.values().toArray().flat() },
|
|
20
|
+
mergeGraphics({ rects: finalGraphics.values().toArray().flat() }, outline),
|
|
18
21
|
{
|
|
19
22
|
svgWidth: 640,
|
|
20
23
|
svgHeight: 480,
|