-
Notifications
You must be signed in to change notification settings - Fork 1
add new edge to edge gapfill solver #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0hmX
wants to merge
34
commits into
main
Choose a base branch
from
feat/break-into-subsolvers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
24424d8
add gapfill and test to add gapfill
0hmX 969e171
WIP
0hmX b198ed4
WIP
0hmX b5b945b
WIP
0hmX 351d91e
WIP
0hmX c4cf3fe
added FlatbushIndex
0hmX 1501219
seting the MAX_ITERATIONS = 100e6
0hmX 132609e
add maxEdgeDistance param
0hmX d385a60
WIP
0hmX ffc333c
WIP
0hmX 3f5873f
WIP
0hmX 67a9b76
WIP
0hmX 8d0f464
WIP
0hmX 1af7c48
WIP
0hmX c150443
WIP
0hmX 9c0f977
new stratergy to break the segments into parts
0hmX fff431c
WIP
0hmX 1546c3f
WIP
0hmX e61591b
WIP
0hmX 007ed59
WIP
0hmX 874a990
WIP
0hmX d9f63e5
WIP
0hmX cbc19db
WIP
0hmX 652a5c1
WIP
0hmX be88bd1
WIP
0hmX 4b9cf28
WIP
0hmX b04dce2
WIP
0hmX 03ee9b4
WIP
0hmX cd1de71
WIP
0hmX e4e54c9
WIP
0hmX 655de79
WIP
0hmX 6c1c590
WIP
0hmX 1634c34
WIP
0hmX fc51cd9
WIP
0hmX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,17 +2,24 @@ import { BasePipelineSolver, definePipelineStep } from "@tscircuit/solver-utils" | |
| import type { SimpleRouteJson } from "./types/srj-types" | ||
| import type { GridFill3DOptions } from "./solvers/rectdiff/types" | ||
| import { RectDiffSolver } from "./solvers/RectDiffSolver" | ||
| import { EdgeSpatialHashIndexManager } from "./solvers/GapFillSolver/EdgeSpatialHashIndexManager" | ||
| import type { CapacityMeshNode } from "./types/capacity-mesh-types" | ||
| import type { GraphicsObject } from "graphics-debug" | ||
| import { createBaseVisualization } from "./solvers/rectdiff/visualization" | ||
|
|
||
| export interface RectDiffPipelineInput { | ||
| simpleRouteJson: SimpleRouteJson | ||
| gridOptions?: Partial<GridFill3DOptions> | ||
| /** Maximum distance between edges to consider for gap filling (default: 10) */ | ||
| gapFillMaxEdgeDistance?: number | ||
| /** Number of gap fill iterations to run (default: 3) */ | ||
| gapFillIterations?: number | ||
| } | ||
|
|
||
| export class RectDiffPipeline extends BasePipelineSolver<RectDiffPipelineInput> { | ||
| rectDiffSolver?: RectDiffSolver | ||
| gapFillSolver?: EdgeSpatialHashIndexManager | ||
| override MAX_ITERATIONS: number = 100e6 | ||
|
|
||
| override pipelineDef = [ | ||
| definePipelineStep( | ||
|
|
@@ -30,20 +37,93 @@ export class RectDiffPipeline extends BasePipelineSolver<RectDiffPipelineInput> | |
| }, | ||
| }, | ||
| ), | ||
| definePipelineStep( | ||
| "gapFillSolver", | ||
| EdgeSpatialHashIndexManager, | ||
| (instance) => { | ||
| const rectDiffSolver = | ||
| instance.getSolver<RectDiffSolver>("rectDiffSolver")! | ||
| const rectDiffState = (rectDiffSolver as any).state | ||
|
|
||
| return [ | ||
| { | ||
| simpleRouteJson: instance.inputProblem.simpleRouteJson, | ||
| placedRects: rectDiffState.placed || [], | ||
| obstaclesByLayer: rectDiffState.obstaclesByLayer || [], | ||
| maxEdgeDistance: instance.inputProblem.gapFillMaxEdgeDistance ?? 10, | ||
| repeatCount: instance.inputProblem.gapFillIterations ?? 3, | ||
| }, | ||
| ] | ||
| }, | ||
| { | ||
| onSolved: () => { | ||
| // Gap fill completed | ||
| }, | ||
| }, | ||
| ), | ||
| ] | ||
|
|
||
| override getConstructorParams() { | ||
| return [this.inputProblem] | ||
| } | ||
|
|
||
| override getOutput(): { meshNodes: CapacityMeshNode[] } { | ||
| return this.getSolver<RectDiffSolver>("rectDiffSolver")!.getOutput() | ||
| const rectDiffOutput = | ||
| this.getSolver<RectDiffSolver>("rectDiffSolver")!.getOutput() | ||
| const gapFillSolver = | ||
| this.getSolver<EdgeSpatialHashIndexManager>("gapFillSolver") | ||
|
|
||
| if (!gapFillSolver) { | ||
| return rectDiffOutput | ||
| } | ||
|
|
||
| const gapFillOutput = gapFillSolver.getOutput() | ||
|
|
||
| return { | ||
| meshNodes: [...rectDiffOutput.meshNodes, ...gapFillOutput.meshNodes], | ||
| } | ||
| } | ||
|
|
||
| override visualize(): GraphicsObject { | ||
| const solver = this.getSolver<RectDiffSolver>("rectDiffSolver") | ||
| if (solver) { | ||
| return solver.visualize() | ||
| const gapFillSolver = | ||
| this.getSolver<EdgeSpatialHashIndexManager>("gapFillSolver") | ||
| const rectDiffSolver = this.getSolver<RectDiffSolver>("rectDiffSolver") | ||
|
|
||
| if (gapFillSolver && !gapFillSolver.solved) { | ||
| return gapFillSolver.visualize() | ||
| } | ||
|
|
||
| if (rectDiffSolver) { | ||
| const baseViz = rectDiffSolver.visualize() | ||
| if (gapFillSolver?.solved) { | ||
| const gapFillOutput = gapFillSolver.getOutput() | ||
| const gapFillRects = gapFillOutput.meshNodes.map((node) => { | ||
| const minZ = Math.min(...node.availableZ) | ||
| const colors = [ | ||
| { fill: "#dbeafe", stroke: "#3b82f6" }, | ||
| { fill: "#fef3c7", stroke: "#f59e0b" }, | ||
| { fill: "#d1fae5", stroke: "#10b981" }, | ||
| ] | ||
| const color = colors[minZ % colors.length]! | ||
|
|
||
| return { | ||
| center: node.center, | ||
| width: node.width, | ||
| height: node.height, | ||
| fill: color.fill, | ||
| stroke: color.stroke, | ||
| label: `capacity node (gap fill)\nz: [${node.availableZ.join(", ")}]`, | ||
| } | ||
| }) | ||
|
|
||
| return { | ||
| ...baseViz, | ||
| title: "RectDiff Pipeline (with Gap Fill)", | ||
| rects: [...(baseViz.rects || []), ...gapFillRects], | ||
| } | ||
| } | ||
|
|
||
| return baseViz | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use combineVisualizations, same as the AutoroutingPipelineSolver (all pipelines do is combine visualizations, they shouldnt do anything unique- each stage gets its own “step”, check AutoroutingPipelineSolver) |
||
| } | ||
|
|
||
| // Show board and obstacles even before solver is initialized | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import Flatbush from "flatbush" | ||
|
|
||
| export interface ISpatialIndex<T> { | ||
| insert(item: T, minX: number, minY: number, maxX: number, maxY: number): void | ||
| finish(): void | ||
| search(minX: number, minY: number, maxX: number, maxY: number): T[] | ||
| clear(): void | ||
| } | ||
|
|
||
| export class FlatbushIndex<T> implements ISpatialIndex<T> { | ||
| private index: Flatbush | ||
| private items: T[] = [] | ||
| private currentIndex = 0 | ||
| private capacity: number | ||
|
|
||
| constructor(numItems: number) { | ||
| this.capacity = Math.max(1, numItems) | ||
| this.index = new Flatbush(this.capacity) | ||
| } | ||
|
|
||
| insert(item: T, minX: number, minY: number, maxX: number, maxY: number) { | ||
| if (this.currentIndex >= this.index.numItems) { | ||
| throw new Error("Exceeded initial capacity") | ||
| } | ||
| this.items[this.currentIndex] = item | ||
| this.index.add(minX, minY, maxX, maxY) | ||
| this.currentIndex++ | ||
| } | ||
|
|
||
| finish() { | ||
| this.index.finish() | ||
| } | ||
|
|
||
| search(minX: number, minY: number, maxX: number, maxY: number): T[] { | ||
| const ids = this.index.search(minX, minY, maxX, maxY) | ||
| return ids.map((id) => this.items[id] || null).filter(Boolean) as T[] | ||
| } | ||
|
|
||
| clear() { | ||
| this.items = [] | ||
| this.currentIndex = 0 | ||
| this.index = new Flatbush(this.capacity) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.