@tscircuit/rectdiff 0.0.5 → 0.0.7
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 +0 -97
- package/dist/index.js +168 -655
- package/lib/solvers/RectDiffSolver.ts +71 -79
- package/lib/solvers/rectdiff/engine.ts +26 -7
- package/lib/solvers/rectdiff/geometry/computeInverseRects.ts +108 -0
- package/lib/solvers/rectdiff/geometry/isPointInPolygon.ts +20 -0
- package/lib/solvers/rectdiff/types.ts +1 -0
- package/package.json +1 -1
- package/pages/board-with-cutout.page.tsx +11 -0
- package/test-assets/board-with-cutout.json +148 -0
- package/tests/__snapshots__/board-outline.snap.svg +59 -0
- package/tests/board-outline.test.ts +18 -0
package/dist/index.d.ts
CHANGED
|
@@ -69,12 +69,6 @@ interface CapacityMeshNode {
|
|
|
69
69
|
_parent?: CapacityMeshNode;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
type XYRect = {
|
|
73
|
-
x: number;
|
|
74
|
-
y: number;
|
|
75
|
-
width: number;
|
|
76
|
-
height: number;
|
|
77
|
-
};
|
|
78
72
|
type GridFill3DOptions = {
|
|
79
73
|
gridSizes?: number[];
|
|
80
74
|
initialCellRatio?: number;
|
|
@@ -91,93 +85,6 @@ type GridFill3DOptions = {
|
|
|
91
85
|
preferMultiLayer?: boolean;
|
|
92
86
|
maxMultiLayerSpan?: number;
|
|
93
87
|
};
|
|
94
|
-
type Placed3D = {
|
|
95
|
-
rect: XYRect;
|
|
96
|
-
zLayers: number[];
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
interface GapFillOptions {
|
|
100
|
-
/** Minimum width for gap-fill rectangles (can be smaller than main solver) */
|
|
101
|
-
minWidth: number;
|
|
102
|
-
/** Minimum height for gap-fill rectangles */
|
|
103
|
-
minHeight: number;
|
|
104
|
-
/** Maximum iterations to prevent infinite loops */
|
|
105
|
-
maxIterations: number;
|
|
106
|
-
/** Target coverage percentage (0-1) to stop early */
|
|
107
|
-
targetCoverage: number;
|
|
108
|
-
/** Grid resolution for gap detection */
|
|
109
|
-
scanResolution: number;
|
|
110
|
-
}
|
|
111
|
-
/** Context for layer-based operations shared across gap fill functions */
|
|
112
|
-
interface LayerContext {
|
|
113
|
-
bounds: XYRect;
|
|
114
|
-
layerCount: number;
|
|
115
|
-
obstaclesByLayer: XYRect[][];
|
|
116
|
-
placedByLayer: XYRect[][];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* A sub-solver that fills empty spaces (gaps) left by the main grid-based
|
|
121
|
-
* placement algorithm.
|
|
122
|
-
*
|
|
123
|
-
* The preceding grid-based placement is fast but can leave irregular un-placed
|
|
124
|
-
* areas. This solver maximizes board coverage by finding and filling these
|
|
125
|
-
* gaps, which is critical for producing a high-quality capacity mesh.
|
|
126
|
-
*
|
|
127
|
-
* The core of the algorithm is its gap-detection phase. It works by first
|
|
128
|
-
* collecting all unique x and y-coordinates from the edges of existing
|
|
129
|
-
* obstacles and placed rectangles. This set of coordinates is supplemented by a
|
|
130
|
-
* uniform grid based on the `scanResolution` parameter. Together, these form a
|
|
131
|
-
* non-uniform grid of cells. The solver then tests the center of each cell for
|
|
132
|
-
* coverage. Contiguous uncovered cells are merged into larger, maximal
|
|
133
|
-
* rectangles, which become the candidate gaps to be filled.
|
|
134
|
-
*
|
|
135
|
-
* Once a prioritized list of gaps is generated (favoring larger, multi-layer
|
|
136
|
-
* gaps), the solver iteratively attempts to fill each one by expanding a new
|
|
137
|
-
* rectangle from a seed point until it collides with an existing boundary.
|
|
138
|
-
*
|
|
139
|
-
* The time complexity is dominated by the gap detection, which is approximately
|
|
140
|
-
* O((N+1/R)^2 * B), where N is the number of objects, R is the scan
|
|
141
|
-
* resolution, and B is the number of blockers. The algorithm's performance is
|
|
142
|
-
* therefore highly dependent on the `scanResolution`. It is a heuristic
|
|
143
|
-
* designed to be "fast enough" by avoiding a brute-force search, instead
|
|
144
|
-
* relying on this grid-based cell checking to find significant gaps.
|
|
145
|
-
*/
|
|
146
|
-
declare class GapFillSubSolver extends BaseSolver {
|
|
147
|
-
private state;
|
|
148
|
-
private layerCtx;
|
|
149
|
-
constructor(params: {
|
|
150
|
-
placed: Placed3D[];
|
|
151
|
-
options?: Partial<GapFillOptions>;
|
|
152
|
-
layerCtx: LayerContext;
|
|
153
|
-
});
|
|
154
|
-
/**
|
|
155
|
-
* Execute one step of the gap fill algorithm.
|
|
156
|
-
* Each gap goes through four stages: scan for gaps, select a target gap,
|
|
157
|
-
* expand a rectangle from seed point, then place the final result.
|
|
158
|
-
*/
|
|
159
|
-
_step(): void;
|
|
160
|
-
/**
|
|
161
|
-
* Calculate progress as a value between 0 and 1.
|
|
162
|
-
* Accounts for iterations, gaps processed, and current stage within each gap.
|
|
163
|
-
*/
|
|
164
|
-
computeProgress(): number;
|
|
165
|
-
/**
|
|
166
|
-
* Get all placed rectangles including original ones plus newly created gap-fill rectangles.
|
|
167
|
-
*/
|
|
168
|
-
getPlaced(): Placed3D[];
|
|
169
|
-
/**
|
|
170
|
-
* Get placed rectangles organized by Z-layer for efficient layer-based operations.
|
|
171
|
-
*/
|
|
172
|
-
getPlacedByLayer(): XYRect[][];
|
|
173
|
-
getOutput(): {
|
|
174
|
-
placed: Placed3D[];
|
|
175
|
-
placedByLayer: XYRect[][];
|
|
176
|
-
filledCount: number;
|
|
177
|
-
};
|
|
178
|
-
/** Zen visualization: show four-stage gap filling process. */
|
|
179
|
-
visualize(): GraphicsObject;
|
|
180
|
-
}
|
|
181
88
|
|
|
182
89
|
/**
|
|
183
90
|
* A streaming, one-step-per-iteration solver for capacity mesh generation.
|
|
@@ -185,15 +92,11 @@ declare class GapFillSubSolver extends BaseSolver {
|
|
|
185
92
|
declare class RectDiffSolver extends BaseSolver {
|
|
186
93
|
private srj;
|
|
187
94
|
private gridOptions;
|
|
188
|
-
private gapFillOptions;
|
|
189
95
|
private state;
|
|
190
96
|
private _meshNodes;
|
|
191
|
-
/** Active subsolver for GAP_FILL phases. */
|
|
192
|
-
activeSubSolver: GapFillSubSolver | null;
|
|
193
97
|
constructor(opts: {
|
|
194
98
|
simpleRouteJson: SimpleRouteJson;
|
|
195
99
|
gridOptions?: Partial<GridFill3DOptions>;
|
|
196
|
-
gapFillOptions?: Partial<GapFillOptions>;
|
|
197
100
|
});
|
|
198
101
|
_setup(): void;
|
|
199
102
|
/** Exactly ONE small step per call. */
|