@tscircuit/rectdiff 0.0.12 → 0.0.13

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.
Files changed (32) hide show
  1. package/dist/index.d.ts +163 -27
  2. package/dist/index.js +1884 -1675
  3. package/lib/RectDiffPipeline.ts +18 -17
  4. package/lib/{solvers/rectdiff/types.ts → rectdiff-types.ts} +0 -34
  5. package/lib/{solvers/rectdiff/visualization.ts → rectdiff-visualization.ts} +2 -1
  6. package/lib/solvers/GapFillSolver/FindSegmentsWithAdjacentEmptySpaceSolver.ts +9 -12
  7. package/lib/solvers/GapFillSolver/visuallyOffsetLine.ts +5 -2
  8. package/lib/solvers/RectDiffExpansionSolver/RectDiffExpansionSolver.ts +205 -0
  9. package/lib/solvers/{rectdiff → RectDiffExpansionSolver}/rectsToMeshNodes.ts +1 -2
  10. package/lib/solvers/RectDiffGridSolverPipeline/RectDiffGridSolverPipeline.ts +87 -0
  11. package/lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts +516 -0
  12. package/lib/solvers/RectDiffSeedingSolver/computeCandidates3D.ts +109 -0
  13. package/lib/solvers/RectDiffSeedingSolver/computeDefaultGridSizes.ts +9 -0
  14. package/lib/solvers/{rectdiff/candidates.ts → RectDiffSeedingSolver/computeEdgeCandidates3D.ts} +39 -220
  15. package/lib/solvers/{rectdiff/geometry → RectDiffSeedingSolver}/computeInverseRects.ts +6 -2
  16. package/lib/solvers/{rectdiff → RectDiffSeedingSolver}/layers.ts +4 -3
  17. package/lib/solvers/RectDiffSeedingSolver/longestFreeSpanAroundZ.ts +52 -0
  18. package/lib/utils/buildHardPlacedByLayer.ts +14 -0
  19. package/lib/{solvers/rectdiff/geometry.ts → utils/expandRectFromSeed.ts} +21 -120
  20. package/lib/utils/finalizeRects.ts +49 -0
  21. package/lib/utils/isFullyOccupiedAtPoint.ts +21 -0
  22. package/lib/utils/rectdiff-geometry.ts +94 -0
  23. package/lib/utils/resizeSoftOverlaps.ts +74 -0
  24. package/package.json +1 -1
  25. package/tests/board-outline.test.ts +2 -1
  26. package/tests/obstacle-extra-layers.test.ts +1 -1
  27. package/tests/obstacle-zlayers.test.ts +1 -1
  28. package/utils/rectsEqual.ts +2 -2
  29. package/utils/rectsOverlap.ts +2 -2
  30. package/lib/solvers/RectDiffSolver.ts +0 -231
  31. package/lib/solvers/rectdiff/engine.ts +0 -481
  32. /package/lib/solvers/{rectdiff/geometry → RectDiffSeedingSolver}/isPointInPolygon.ts +0 -0
package/dist/index.d.ts CHANGED
@@ -50,6 +50,12 @@ interface SimpleRouteConnection {
50
50
  externallyConnectedPointIds?: string[][];
51
51
  }
52
52
 
53
+ type XYRect = {
54
+ x: number;
55
+ y: number;
56
+ width: number;
57
+ height: number;
58
+ };
53
59
  type GridFill3DOptions = {
54
60
  gridSizes?: number[];
55
61
  initialCellRatio?: number;
@@ -66,6 +72,20 @@ type GridFill3DOptions = {
66
72
  preferMultiLayer?: boolean;
67
73
  maxMultiLayerSpan?: number;
68
74
  };
75
+ type Candidate3D = {
76
+ x: number;
77
+ y: number;
78
+ z: number;
79
+ distance: number;
80
+ /** Larger values mean more multi-layer potential at this seed. */
81
+ zSpanLen?: number;
82
+ /** Marked when the seed came from the edge analysis pass. */
83
+ isEdgeSeed?: boolean;
84
+ };
85
+ type Placed3D = {
86
+ rect: XYRect;
87
+ zLayers: number[];
88
+ };
69
89
 
70
90
  type CapacityMeshNodeId = string;
71
91
  interface CapacityMeshNode {
@@ -89,32 +109,6 @@ interface CapacityMeshNode {
89
109
  _parent?: CapacityMeshNode;
90
110
  }
91
111
 
92
- /**
93
- * A streaming, one-step-per-iteration solver for capacity mesh generation.
94
- */
95
- declare class RectDiffSolver extends BaseSolver {
96
- private srj;
97
- private gridOptions;
98
- private state;
99
- private _meshNodes;
100
- constructor(opts: {
101
- simpleRouteJson: SimpleRouteJson;
102
- gridOptions?: Partial<GridFill3DOptions>;
103
- });
104
- _setup(): void;
105
- /** Exactly ONE small step per call. */
106
- _step(): void;
107
- /** Compute solver progress (0 to 1). */
108
- computeProgress(): number;
109
- getOutput(): {
110
- meshNodes: CapacityMeshNode[];
111
- };
112
- /** Get color based on z layer for visualization. */
113
- private getColorForZLayer;
114
- /** Streaming visualization: board + obstacles + current placements. */
115
- visualize(): GraphicsObject;
116
- }
117
-
118
112
  interface SegmentWithAdjacentEmptySpace {
119
113
  parent: CapacityMeshNode;
120
114
  start: {
@@ -204,12 +198,154 @@ declare class GapFillSolverPipeline extends BasePipelineSolver<{
204
198
  finalVisualize(): GraphicsObject;
205
199
  }
206
200
 
201
+ type RectDiffSeedingSolverInput = {
202
+ simpleRouteJson: SimpleRouteJson;
203
+ gridOptions?: Partial<GridFill3DOptions>;
204
+ };
205
+ /**
206
+ * First phase of RectDiff: grid-based seeding and placement.
207
+ *
208
+ * This solver is responsible for walking all grid sizes and producing
209
+ * an initial set of placed rectangles.
210
+ */
211
+ declare class RectDiffSeedingSolver extends BaseSolver {
212
+ private input;
213
+ private srj;
214
+ private layerNames;
215
+ private layerCount;
216
+ private bounds;
217
+ private options;
218
+ private obstaclesByLayer;
219
+ private boardVoidRects;
220
+ private gridIndex;
221
+ private candidates;
222
+ private placed;
223
+ private placedByLayer;
224
+ private expansionIndex;
225
+ private edgeAnalysisDone;
226
+ private totalSeedsThisGrid;
227
+ private consumedSeedsThisGrid;
228
+ constructor(input: RectDiffSeedingSolverInput);
229
+ _setup(): void;
230
+ /** Exactly ONE grid candidate step per call. */
231
+ _step(): void;
232
+ /**
233
+ * One micro-step during the GRID phase: handle exactly one candidate.
234
+ */
235
+ private _stepGrid;
236
+ /** Compute solver progress (0 to 1) during GRID phase. */
237
+ computeProgress(): number;
238
+ /**
239
+ * Output the intermediate RectDiff engine data to feed into the
240
+ * expansion phase solver.
241
+ */
242
+ getOutput(): {
243
+ srj: SimpleRouteJson;
244
+ layerNames: string[];
245
+ layerCount: number;
246
+ bounds: XYRect;
247
+ options: Required<Omit<GridFill3DOptions, "gridSizes" | "maxMultiLayerSpan">> & {
248
+ gridSizes: number[];
249
+ maxMultiLayerSpan: number | undefined;
250
+ };
251
+ obstaclesByLayer: XYRect[][];
252
+ boardVoidRects: XYRect[];
253
+ gridIndex: number;
254
+ candidates: Candidate3D[];
255
+ placed: Placed3D[];
256
+ placedByLayer: XYRect[][];
257
+ expansionIndex: number;
258
+ edgeAnalysisDone: boolean;
259
+ totalSeedsThisGrid: number;
260
+ consumedSeedsThisGrid: number;
261
+ };
262
+ /** Get color based on z layer for visualization. */
263
+ private getColorForZLayer;
264
+ /** Visualization focused on the grid seeding phase. */
265
+ visualize(): GraphicsObject;
266
+ }
267
+
268
+ type RectDiffExpansionSolverSnapshot = {
269
+ srj: SimpleRouteJson;
270
+ layerNames: string[];
271
+ layerCount: number;
272
+ bounds: XYRect;
273
+ options: {
274
+ gridSizes: number[];
275
+ [key: string]: any;
276
+ };
277
+ obstaclesByLayer: XYRect[][];
278
+ boardVoidRects: XYRect[];
279
+ gridIndex: number;
280
+ candidates: Candidate3D[];
281
+ placed: Placed3D[];
282
+ placedByLayer: XYRect[][];
283
+ expansionIndex: number;
284
+ edgeAnalysisDone: boolean;
285
+ totalSeedsThisGrid: number;
286
+ consumedSeedsThisGrid: number;
287
+ };
288
+ type RectDiffExpansionSolverInput = {
289
+ initialSnapshot: RectDiffExpansionSolverSnapshot;
290
+ };
291
+ /**
292
+ * Second phase of RectDiff: expand placed rects to their maximal extents.
293
+ *
294
+ * This solver takes the intermediate data produced by RectDiffSeedingSolver
295
+ * and runs the EXPANSION phase, then finalizes to capacity mesh nodes.
296
+ */
297
+ declare class RectDiffExpansionSolver extends BaseSolver {
298
+ private input;
299
+ private srj;
300
+ private layerNames;
301
+ private layerCount;
302
+ private bounds;
303
+ private options;
304
+ private obstaclesByLayer;
305
+ private boardVoidRects;
306
+ private gridIndex;
307
+ private candidates;
308
+ private placed;
309
+ private placedByLayer;
310
+ private expansionIndex;
311
+ private edgeAnalysisDone;
312
+ private totalSeedsThisGrid;
313
+ private consumedSeedsThisGrid;
314
+ private _meshNodes;
315
+ constructor(input: RectDiffExpansionSolverInput);
316
+ _setup(): void;
317
+ _step(): void;
318
+ private _stepExpansion;
319
+ private finalizeIfNeeded;
320
+ computeProgress(): number;
321
+ getOutput(): {
322
+ meshNodes: CapacityMeshNode[];
323
+ };
324
+ /** Simple visualization of expanded placements. */
325
+ visualize(): GraphicsObject;
326
+ }
327
+
328
+ type RectDiffGridSolverPipelineInput = {
329
+ simpleRouteJson: SimpleRouteJson;
330
+ gridOptions?: Partial<GridFill3DOptions>;
331
+ };
332
+ declare class RectDiffGridSolverPipeline extends BasePipelineSolver<RectDiffGridSolverPipelineInput> {
333
+ rectDiffSeedingSolver?: RectDiffSeedingSolver;
334
+ rectDiffExpansionSolver?: RectDiffExpansionSolver;
335
+ pipelineDef: PipelineStep<any>[];
336
+ getConstructorParams(): RectDiffGridSolverPipelineInput[];
337
+ getOutput(): {
338
+ meshNodes: CapacityMeshNode[];
339
+ };
340
+ visualize(): GraphicsObject;
341
+ }
342
+
207
343
  interface RectDiffPipelineInput {
208
344
  simpleRouteJson: SimpleRouteJson;
209
345
  gridOptions?: Partial<GridFill3DOptions>;
210
346
  }
211
347
  declare class RectDiffPipeline extends BasePipelineSolver<RectDiffPipelineInput> {
212
- rectDiffSolver?: RectDiffSolver;
348
+ rectDiffGridSolverPipeline?: RectDiffGridSolverPipeline;
213
349
  gapFillSolver?: GapFillSolverPipeline;
214
350
  pipelineDef: PipelineStep<any>[];
215
351
  getConstructorParams(): RectDiffPipelineInput[];