Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bun-pver-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
paths:
- 'lib/**'
- "lib/**"
workflow_dispatch:
jobs:
publish:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ If there is crowding at the pin, we look for an available spot along the trace c
## Usage

```tsx
import { SchematicTracePipelineSolver } from "@tscircuit/schematic-trace-solver"
import { SchematicTracePipelineSolver } from "@tscircuit/schematic-trace-solver";

type ChipId = string
type PinId = string
type ChipId = string;
type PinId = string;

const solver = new SchematicTracePipelineSolver({
chips: {
Expand Down Expand Up @@ -77,9 +77,9 @@ const solver = new SchematicTracePipelineSolver({
VCC: ["y+", "y-"],
GND: ["y+", "y-"],
},
})
});

solver.solve()
solver.solve();
```

## Development
Expand Down
22 changes: 11 additions & 11 deletions cosmos.decorator.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React, { useEffect } from "react"
import React, { useEffect } from "react";

export const TailwindDecorator = ({
children,
}: {
children: React.ReactNode
children: React.ReactNode;
}) => {
useEffect(() => {
const script = document.createElement("script")
script.src = "https://cdn.tailwindcss.com"
document.head.appendChild(script)
const script = document.createElement("script");
script.src = "https://cdn.tailwindcss.com";
document.head.appendChild(script);

return () => {
document.head.removeChild(script)
}
}, [])
document.head.removeChild(script);
};
}, []);

return <>{children}</>
}
return <>{children}</>;
};

export default TailwindDecorator
export default TailwindDecorator;
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Schematic Trace Solver</title>
<script>
const script = document.createElement("script")
script.src = "https://cdn.tailwindcss.com"
document.head.appendChild(script)
const script = document.createElement("script");
script.src = "https://cdn.tailwindcss.com";
document.head.appendChild(script);
</script>
</head>
<body>
Expand Down
48 changes: 24 additions & 24 deletions lib/data-structures/ChipObstacleSpatialIndex.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import type { InputChip } from "lib/types/InputProblem"
import type { Bounds, Point } from "@tscircuit/math-utils"
import Flatbush from "flatbush"
import { getInputChipBounds } from "lib/solvers/GuidelinesSolver/getInputChipBounds"
import type { InputChip } from "lib/types/InputProblem";
import type { Bounds, Point } from "@tscircuit/math-utils";
import Flatbush from "flatbush";
import { getInputChipBounds } from "lib/solvers/GuidelinesSolver/getInputChipBounds";

export interface SpatiallyIndexedChip extends InputChip {
bounds: Bounds
spatialIndexId: number
bounds: Bounds;
spatialIndexId: number;
}

export class ChipObstacleSpatialIndex {
chips: Array<SpatiallyIndexedChip>
spatialIndex: Flatbush
spatialIndexIdToChip: Map<number, SpatiallyIndexedChip>
chips: Array<SpatiallyIndexedChip>;
spatialIndex: Flatbush;
spatialIndexIdToChip: Map<number, SpatiallyIndexedChip>;

constructor(chips: InputChip[]) {
this.chips = chips.map((chip) => ({
...chip,
bounds: getInputChipBounds(chip),
spatialIndexId: null as any,
}))
}));

this.spatialIndexIdToChip = new Map()
this.spatialIndex = new Flatbush(chips.length)
this.spatialIndexIdToChip = new Map();
this.spatialIndex = new Flatbush(chips.length);

for (const chip of this.chips) {
chip.spatialIndexId = this.spatialIndex.add(
chip.bounds.minX,
chip.bounds.minY,
chip.bounds.maxX,
chip.bounds.maxY,
)
this.spatialIndexIdToChip.set(chip.spatialIndexId, chip)
);
this.spatialIndexIdToChip.set(chip.spatialIndexId, chip);
}

this.spatialIndex.finish()
this.spatialIndex.finish();
}

getChipsInBounds(bounds: Bounds): Array<InputChip & { bounds: Bounds }> {
Expand All @@ -42,29 +42,29 @@ export class ChipObstacleSpatialIndex {
bounds.minY,
bounds.maxX,
bounds.maxY,
)
);

return chipSpatialIndexIds.map((id) => this.spatialIndexIdToChip.get(id)!)
return chipSpatialIndexIds.map((id) => this.spatialIndexIdToChip.get(id)!);
}

doesOrthogonalLineIntersectChip(
line: [Point, Point],
opts: {
excludeChipIds?: string[]
excludeChipIds?: string[];
} = {},
): boolean {
const excludeChipIds = opts.excludeChipIds ?? []
const [p1, p2] = line
const { x: x1, y: y1 } = p1
const { x: x2, y: y2 } = p2
const excludeChipIds = opts.excludeChipIds ?? [];
const [p1, p2] = line;
const { x: x1, y: y1 } = p1;
const { x: x2, y: y2 } = p2;

const chips = this.getChipsInBounds({
minX: Math.min(x1, x2),
minY: Math.min(y1, y2),
maxX: Math.max(x1, x2),
maxY: Math.max(y1, y2),
}).filter((chip) => !excludeChipIds.includes(chip.chipId))
}).filter((chip) => !excludeChipIds.includes(chip.chipId));

return chips.length > 0
return chips.length > 0;
}
}
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
export * from "./types/InputProblem"
export { SchematicTraceSingleLineSolver2 } from "./solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2"
export * from "./solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver";
export * from "./types/InputProblem";
export { SchematicTraceSingleLineSolver2 } from "./solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2";
58 changes: 29 additions & 29 deletions lib/solvers/BaseSolver/BaseSolver.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import type { GraphicsObject } from "graphics-debug"
import type { GraphicsObject } from "graphics-debug";

export class BaseSolver {
MAX_ITERATIONS = 100e3
solved = false
failed = false
iterations = 0
progress = 0
error: string | null = null
activeSubSolver?: BaseSolver | null
failedSubSolvers?: BaseSolver[]
timeToSolve?: number
stats: Record<string, any> = {}
MAX_ITERATIONS = 100e3;
solved = false;
failed = false;
iterations = 0;
progress = 0;
error: string | null = null;
activeSubSolver?: BaseSolver | null;
failedSubSolvers?: BaseSolver[];
timeToSolve?: number;
stats: Record<string, any> = {};

/** DO NOT OVERRIDE! Override _step() instead */
step() {
if (this.solved) return
if (this.failed) return
this.iterations++
if (this.solved) return;
if (this.failed) return;
this.iterations++;
try {
this._step()
this._step();
} catch (e) {
this.error = `${this.constructor.name} error: ${e}`
this.failed = true
throw e
this.error = `${this.constructor.name} error: ${e}`;
this.failed = true;
throw e;

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example07.test.ts:9:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example24.test.tsx:112:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example10.test.ts:9:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example04.test.ts:9:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example29.test.ts:10:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example01.test.ts:9:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example08.test.ts:9:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example23.test.tsx:107:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example11.test.tsx:9:10)

Check failure on line 25 in lib/solvers/BaseSolver/BaseSolver.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'inputProblem.maxMspPairDistance')

at step (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:25:13) at solve (/home/runner/work/schematic-trace-solver/schematic-trace-solver/lib/solvers/BaseSolver/BaseSolver.ts:49:12) at <anonymous> (/home/runner/work/schematic-trace-solver/schematic-trace-solver/tests/examples/example28.test.ts:10:10)
}
if (!this.solved && this.iterations > this.MAX_ITERATIONS) {
this.tryFinalAcceptance()
this.tryFinalAcceptance();
}
if (!this.solved && this.iterations > this.MAX_ITERATIONS) {
this.error = `${this.constructor.name} ran out of iterations`
this.failed = true
this.error = `${this.constructor.name} ran out of iterations`;
this.failed = true;
}
if ("computeProgress" in this) {
// @ts-ignore
this.progress = this.computeProgress() as number
this.progress = this.computeProgress() as number;
}
}

_step() {}

getConstructorParams() {
throw new Error("getConstructorParams not implemented")
throw new Error("getConstructorParams not implemented");
}

solve() {
const startTime = Date.now()
const startTime = Date.now();
while (!this.solved && !this.failed) {
this.step()
this.step();
}
const endTime = Date.now()
this.timeToSolve = endTime - startTime
const endTime = Date.now();
this.timeToSolve = endTime - startTime;
}

visualize(): GraphicsObject {
Expand All @@ -58,7 +58,7 @@
points: [],
rects: [],
circles: [],
}
};
}

/**
Expand All @@ -78,6 +78,6 @@
points: [],
rects: [],
circles: [],
}
};
}
}
Loading
Loading