@tscircuit/rectdiff 0.0.12 → 0.0.14

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 (37) hide show
  1. package/dist/index.d.ts +169 -27
  2. package/dist/index.js +2012 -1672
  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 +252 -0
  9. package/lib/solvers/{rectdiff → RectDiffExpansionSolver}/rectsToMeshNodes.ts +1 -2
  10. package/lib/solvers/RectDiffGridSolverPipeline/RectDiffGridSolverPipeline.ts +106 -0
  11. package/lib/solvers/RectDiffGridSolverPipeline/buildObstacleIndexes.ts +70 -0
  12. package/lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts +487 -0
  13. package/lib/solvers/RectDiffSeedingSolver/computeCandidates3D.ts +109 -0
  14. package/lib/solvers/RectDiffSeedingSolver/computeDefaultGridSizes.ts +9 -0
  15. package/lib/solvers/{rectdiff/candidates.ts → RectDiffSeedingSolver/computeEdgeCandidates3D.ts} +44 -225
  16. package/lib/solvers/{rectdiff/geometry → RectDiffSeedingSolver}/computeInverseRects.ts +6 -2
  17. package/lib/solvers/{rectdiff → RectDiffSeedingSolver}/layers.ts +4 -3
  18. package/lib/solvers/RectDiffSeedingSolver/longestFreeSpanAroundZ.ts +60 -0
  19. package/lib/types/capacity-mesh-types.ts +9 -0
  20. package/lib/utils/buildHardPlacedByLayer.ts +14 -0
  21. package/lib/{solvers/rectdiff/geometry.ts → utils/expandRectFromSeed.ts} +21 -120
  22. package/lib/utils/finalizeRects.ts +54 -0
  23. package/lib/utils/isFullyOccupiedAtPoint.ts +28 -0
  24. package/lib/utils/rectToTree.ts +10 -0
  25. package/lib/utils/rectdiff-geometry.ts +94 -0
  26. package/lib/utils/resizeSoftOverlaps.ts +103 -0
  27. package/lib/utils/sameTreeRect.ts +7 -0
  28. package/package.json +1 -1
  29. package/tests/board-outline.test.ts +2 -1
  30. package/tests/examples/example01.test.tsx +18 -1
  31. package/tests/obstacle-extra-layers.test.ts +1 -1
  32. package/tests/obstacle-zlayers.test.ts +1 -1
  33. package/utils/rectsEqual.ts +2 -2
  34. package/utils/rectsOverlap.ts +2 -2
  35. package/lib/solvers/RectDiffSolver.ts +0 -231
  36. package/lib/solvers/rectdiff/engine.ts +0 -481
  37. /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 {
@@ -88,32 +108,12 @@ interface CapacityMeshNode {
88
108
  _adjacentNodeIds?: CapacityMeshNodeId[];
89
109
  _parent?: CapacityMeshNode;
90
110
  }
91
-
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
- }
111
+ type RTreeRect = XYRect & {
112
+ minX: number;
113
+ minY: number;
114
+ maxX: number;
115
+ maxY: number;
116
+ };
117
117
 
118
118
  interface SegmentWithAdjacentEmptySpace {
119
119
  parent: CapacityMeshNode;
@@ -204,12 +204,154 @@ declare class GapFillSolverPipeline extends BasePipelineSolver<{
204
204
  finalVisualize(): GraphicsObject;
205
205
  }
206
206
 
207
+ type RectDiffSeedingSolverInput = {
208
+ simpleRouteJson: SimpleRouteJson;
209
+ obstacleIndexByLayer: Array<RBush<RTreeRect>>;
210
+ gridOptions?: Partial<GridFill3DOptions>;
211
+ boardVoidRects?: XYRect[];
212
+ };
213
+ /**
214
+ * First phase of RectDiff: grid-based seeding and placement.
215
+ *
216
+ * This solver is responsible for walking all grid sizes and producing
217
+ * an initial set of placed rectangles.
218
+ */
219
+ declare class RectDiffSeedingSolver extends BaseSolver {
220
+ private input;
221
+ private srj;
222
+ private layerNames;
223
+ private layerCount;
224
+ private bounds;
225
+ private options;
226
+ private boardVoidRects?;
227
+ private gridIndex;
228
+ private candidates;
229
+ private placed;
230
+ private placedIndexByLayer;
231
+ private expansionIndex;
232
+ private edgeAnalysisDone;
233
+ private totalSeedsThisGrid;
234
+ private consumedSeedsThisGrid;
235
+ constructor(input: RectDiffSeedingSolverInput);
236
+ _setup(): void;
237
+ /** Exactly ONE grid candidate step per call. */
238
+ _step(): void;
239
+ /**
240
+ * One micro-step during the GRID phase: handle exactly one candidate.
241
+ */
242
+ private _stepGrid;
243
+ /** Compute solver progress (0 to 1) during GRID phase. */
244
+ computeProgress(): number;
245
+ /**
246
+ * Output the intermediate RectDiff engine data to feed into the
247
+ * expansion phase solver.
248
+ */
249
+ getOutput(): {
250
+ srj: SimpleRouteJson;
251
+ layerNames: string[];
252
+ layerCount: number;
253
+ bounds: XYRect;
254
+ options: Required<Omit<GridFill3DOptions, "gridSizes" | "maxMultiLayerSpan">> & {
255
+ gridSizes: number[];
256
+ maxMultiLayerSpan: number | undefined;
257
+ };
258
+ boardVoidRects: XYRect[] | undefined;
259
+ gridIndex: number;
260
+ candidates: Candidate3D[];
261
+ placed: Placed3D[];
262
+ expansionIndex: number;
263
+ edgeAnalysisDone: boolean;
264
+ totalSeedsThisGrid: number;
265
+ consumedSeedsThisGrid: number;
266
+ };
267
+ /** Get color based on z layer for visualization. */
268
+ private getColorForZLayer;
269
+ /** Visualization focused on the grid seeding phase. */
270
+ visualize(): GraphicsObject;
271
+ }
272
+
273
+ type RectDiffExpansionSolverSnapshot = {
274
+ srj: SimpleRouteJson;
275
+ layerNames: string[];
276
+ layerCount: number;
277
+ bounds: XYRect;
278
+ options: {
279
+ gridSizes: number[];
280
+ [key: string]: any;
281
+ };
282
+ boardVoidRects: XYRect[];
283
+ gridIndex: number;
284
+ candidates: Candidate3D[];
285
+ placed: Placed3D[];
286
+ expansionIndex: number;
287
+ edgeAnalysisDone: boolean;
288
+ totalSeedsThisGrid: number;
289
+ consumedSeedsThisGrid: number;
290
+ };
291
+ type RectDiffExpansionSolverInput = {
292
+ initialSnapshot: RectDiffExpansionSolverSnapshot;
293
+ obstacleIndexByLayer: Array<RBush<RTreeRect>>;
294
+ };
295
+ /**
296
+ * Second phase of RectDiff: expand placed rects to their maximal extents.
297
+ *
298
+ * This solver takes the intermediate data produced by RectDiffSeedingSolver
299
+ * and runs the EXPANSION phase, then finalizes to capacity mesh nodes.
300
+ */
301
+ declare class RectDiffExpansionSolver extends BaseSolver {
302
+ private input;
303
+ private srj;
304
+ private layerNames;
305
+ private layerCount;
306
+ private bounds;
307
+ private options;
308
+ private boardVoidRects;
309
+ private gridIndex;
310
+ private candidates;
311
+ private placed;
312
+ private placedIndexByLayer;
313
+ private expansionIndex;
314
+ private edgeAnalysisDone;
315
+ private totalSeedsThisGrid;
316
+ private consumedSeedsThisGrid;
317
+ private _meshNodes;
318
+ constructor(input: RectDiffExpansionSolverInput);
319
+ _setup(): void;
320
+ _step(): void;
321
+ private _stepExpansion;
322
+ private finalizeIfNeeded;
323
+ computeProgress(): number;
324
+ getOutput(): {
325
+ meshNodes: CapacityMeshNode[];
326
+ };
327
+ /** Simple visualization of expanded placements. */
328
+ visualize(): GraphicsObject;
329
+ }
330
+
331
+ type RectDiffGridSolverPipelineInput = {
332
+ simpleRouteJson: SimpleRouteJson;
333
+ gridOptions?: Partial<GridFill3DOptions>;
334
+ };
335
+ declare class RectDiffGridSolverPipeline extends BasePipelineSolver<RectDiffGridSolverPipelineInput> {
336
+ rectDiffSeedingSolver?: RectDiffSeedingSolver;
337
+ rectDiffExpansionSolver?: RectDiffExpansionSolver;
338
+ private boardVoidRects?;
339
+ private obstacleIndexByLayer;
340
+ constructor(inputProblem: RectDiffGridSolverPipelineInput);
341
+ pipelineDef: PipelineStep<any>[];
342
+ getConstructorParams(): RectDiffGridSolverPipelineInput[];
343
+ getOutput(): {
344
+ meshNodes: CapacityMeshNode[];
345
+ };
346
+ visualize(): GraphicsObject;
347
+ }
348
+
207
349
  interface RectDiffPipelineInput {
208
350
  simpleRouteJson: SimpleRouteJson;
209
351
  gridOptions?: Partial<GridFill3DOptions>;
210
352
  }
211
353
  declare class RectDiffPipeline extends BasePipelineSolver<RectDiffPipelineInput> {
212
- rectDiffSolver?: RectDiffSolver;
354
+ rectDiffGridSolverPipeline?: RectDiffGridSolverPipeline;
213
355
  gapFillSolver?: GapFillSolverPipeline;
214
356
  pipelineDef: PipelineStep<any>[];
215
357
  getConstructorParams(): RectDiffPipelineInput[];