@tscircuit/hypergraph 0.0.20 → 0.0.22

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 (3) hide show
  1. package/dist/index.d.ts +281 -119
  2. package/dist/index.js +4285 -2855
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { GraphicsObject } from 'graphics-debug';
2
1
  import { BaseSolver } from '@tscircuit/solver-utils';
3
2
  import { Matrix } from 'transformation-matrix';
3
+ import { GraphicsObject } from 'graphics-debug';
4
4
 
5
5
  type PortId = string;
6
6
  type GraphEdgeId = string;
@@ -96,109 +96,9 @@ type SerializedConnection = {
96
96
  endRegionId: RegionId;
97
97
  };
98
98
 
99
- type Bounds = {
100
- minX: number;
101
- minY: number;
102
- maxX: number;
103
- maxY: number;
104
- };
105
-
106
- interface JRegion extends Region {
107
- d: {
108
- bounds: Bounds;
109
- center: {
110
- x: number;
111
- y: number;
112
- };
113
- polygon?: {
114
- x: number;
115
- y: number;
116
- }[];
117
- isPad: boolean;
118
- isThroughJumper?: boolean;
119
- isConnectionRegion?: boolean;
120
- };
121
- }
122
- interface JPort extends RegionPort {
123
- d: {
124
- x: number;
125
- y: number;
126
- };
127
- }
128
- type JumperGraph = {
129
- regions: JRegion[];
130
- ports: JPort[];
131
- jumperLocations?: Array<{
132
- center: {
133
- x: number;
134
- y: number;
135
- };
136
- orientation: "vertical" | "horizontal";
137
- padRegions: JRegion[];
138
- }>;
139
- };
140
-
141
- declare const generateJumperX4Grid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, regionsBetweenPads, outerPaddingX: outerPaddingXParam, outerPaddingY: outerPaddingYParam, outerChannelXPointCount, outerChannelYPointCount, orientation, center, bounds, parallelTracesUnderJumperCount, }: {
142
- cols: number;
143
- rows: number;
144
- marginX: number;
145
- marginY: number;
146
- innerColChannelPointCount?: number;
147
- innerRowChannelPointCount?: number;
148
- regionsBetweenPads?: boolean;
149
- outerPaddingX?: number;
150
- outerPaddingY?: number;
151
- outerChannelXPointCount?: number;
152
- outerChannelYPointCount?: number;
153
- orientation?: "vertical" | "horizontal";
154
- center?: {
155
- x: number;
156
- y: number;
157
- };
158
- bounds?: {
159
- minX: number;
160
- maxX: number;
161
- minY: number;
162
- maxY: number;
163
- };
164
- /** Number of trace points that can pass through the jumper body from top to bottom without using jumpers */
165
- parallelTracesUnderJumperCount?: number;
166
- }) => JumperGraph;
167
-
168
- declare const generateJumperGrid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, outerPaddingX, outerPaddingY, outerChannelXPoints, outerChannelYPoints, orientation, }: {
169
- cols: number;
170
- rows: number;
171
- marginX: number;
172
- marginY: number;
173
- innerColChannelPointCount?: number;
174
- innerRowChannelPointCount?: number;
175
- outerPaddingX?: number;
176
- outerPaddingY?: number;
177
- outerChannelXPoints?: number;
178
- outerChannelYPoints?: number;
179
- orientation?: "vertical" | "horizontal";
180
- }) => JumperGraph;
99
+ declare const convertConnectionsToSerializedConnections: (connections: Connection[]) => SerializedConnection[];
181
100
 
182
- type XYConnection = {
183
- start: {
184
- x: number;
185
- y: number;
186
- };
187
- end: {
188
- x: number;
189
- y: number;
190
- };
191
- connectionId: string;
192
- };
193
- type JumperGraphWithConnections = JumperGraph & {
194
- connections: Connection[];
195
- };
196
- /**
197
- * Creates a new graph from a base graph with additional connection regions at
198
- * specified positions on the boundary. Connection regions are 0.4x0.4 pseudo-regions
199
- * that contain one port point connecting them to the grid boundary.
200
- */
201
- declare const createGraphWithConnectionsFromBaseGraph: (baseGraph: JumperGraph, xyConnections: XYConnection[]) => JumperGraphWithConnections;
101
+ declare const convertHyperGraphToSerializedHyperGraph: (graph: HyperGraph) => SerializedHyperGraph;
202
102
 
203
103
  type Node = {
204
104
  f: number;
@@ -349,6 +249,23 @@ declare class HyperGraphSolver<RegionType extends Region = Region, RegionPortTyp
349
249
  * redundant.
350
250
  */
351
251
  selectCandidatesForEnteringRegion(candidates: Candidate[]): Candidate[];
252
+ /**
253
+ * OPTIONALLY OVERRIDE THIS
254
+ *
255
+ * Compute the full set of solved routes that must be ripped to accept
256
+ * `newlySolvedRoute`. By default this returns all conflicting routes
257
+ * (always-rip behavior)
258
+ *
259
+ * Override this to implement partial ripping, where only a subset of
260
+ * conflicting routes are removed.
261
+ */
262
+ computeRoutesToRip(newlySolvedRoute: SolvedRoute): Set<SolvedRoute>;
263
+ /**
264
+ * Returns solved routes that overlap ports with the newly solved route.
265
+ * Use this in computeRoutesToRip overrides to include port reuse rips.
266
+ */
267
+ computePortOverlapRoutes(newlySolvedRoute: SolvedRoute): Set<SolvedRoute>;
268
+ computeCrossingRoutes(newlySolvedRoute: SolvedRoute): Set<SolvedRoute>;
352
269
  getNextCandidates(currentCandidate: CandidateType): CandidateType[];
353
270
  processSolvedRoute(finalCandidate: CandidateType): void;
354
271
  /**
@@ -375,6 +292,59 @@ declare class HyperGraphSolver<RegionType extends Region = Region, RegionPortTyp
375
292
  _step(): void;
376
293
  }
377
294
 
295
+ type Bounds$1 = {
296
+ minX: number;
297
+ minY: number;
298
+ maxX: number;
299
+ maxY: number;
300
+ };
301
+
302
+ interface JRegion extends Region {
303
+ d: {
304
+ bounds: Bounds$1;
305
+ center: {
306
+ x: number;
307
+ y: number;
308
+ };
309
+ polygon?: {
310
+ x: number;
311
+ y: number;
312
+ }[];
313
+ isPad: boolean;
314
+ isThroughJumper?: boolean;
315
+ isConnectionRegion?: boolean;
316
+ isViaRegion?: boolean;
317
+ };
318
+ }
319
+ interface JPort extends RegionPort {
320
+ d: {
321
+ x: number;
322
+ y: number;
323
+ };
324
+ }
325
+ type JumperGraph = {
326
+ regions: JRegion[];
327
+ ports: JPort[];
328
+ jumperLocations?: Array<{
329
+ center: {
330
+ x: number;
331
+ y: number;
332
+ };
333
+ orientation: "vertical" | "horizontal";
334
+ padRegions: JRegion[];
335
+ }>;
336
+ };
337
+
338
+ /**
339
+ * Applies a transformation matrix to all points in a graph.
340
+ * Transforms region bounds, region centers, and port positions.
341
+ */
342
+ declare const applyTransformToGraph: (graph: JumperGraph, matrix: Matrix) => JumperGraph;
343
+ /**
344
+ * Rotates a graph 90 degrees clockwise around its center.
345
+ */
346
+ declare const rotateGraph90Degrees: (graph: JumperGraph) => JumperGraph;
347
+
378
348
  declare const JUMPER_GRAPH_SOLVER_DEFAULTS: {
379
349
  portUsagePenalty: number;
380
350
  portUsagePenaltySq: number;
@@ -413,21 +383,69 @@ declare class JumperGraphSolver extends HyperGraphSolver<JRegion, JPort> {
413
383
  visualize(): GraphicsObject;
414
384
  }
415
385
 
416
- declare const convertHyperGraphToSerializedHyperGraph: (graph: HyperGraph) => SerializedHyperGraph;
417
-
418
- declare const convertConnectionsToSerializedConnections: (connections: Connection[]) => SerializedConnection[];
386
+ declare const calculateGraphBounds: (regions: JRegion[]) => Bounds$1;
419
387
 
388
+ type XYConnection = {
389
+ start: {
390
+ x: number;
391
+ y: number;
392
+ };
393
+ end: {
394
+ x: number;
395
+ y: number;
396
+ };
397
+ connectionId: string;
398
+ };
399
+ type JumperGraphWithConnections = JumperGraph & {
400
+ connections: Connection[];
401
+ };
420
402
  /**
421
- * Applies a transformation matrix to all points in a graph.
422
- * Transforms region bounds, region centers, and port positions.
423
- */
424
- declare const applyTransformToGraph: (graph: JumperGraph, matrix: Matrix) => JumperGraph;
425
- /**
426
- * Rotates a graph 90 degrees clockwise around its center.
403
+ * Creates a new graph from a base graph with additional connection regions at
404
+ * specified positions on the boundary. Connection regions are 0.4x0.4 pseudo-regions
405
+ * that contain one port point connecting them to the grid boundary.
427
406
  */
428
- declare const rotateGraph90Degrees: (graph: JumperGraph) => JumperGraph;
407
+ declare const createGraphWithConnectionsFromBaseGraph: (baseGraph: JumperGraph, xyConnections: XYConnection[]) => JumperGraphWithConnections;
429
408
 
430
- declare const calculateGraphBounds: (regions: JRegion[]) => Bounds;
409
+ declare const generateJumperGrid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, outerPaddingX, outerPaddingY, outerChannelXPoints, outerChannelYPoints, orientation, }: {
410
+ cols: number;
411
+ rows: number;
412
+ marginX: number;
413
+ marginY: number;
414
+ innerColChannelPointCount?: number;
415
+ innerRowChannelPointCount?: number;
416
+ outerPaddingX?: number;
417
+ outerPaddingY?: number;
418
+ outerChannelXPoints?: number;
419
+ outerChannelYPoints?: number;
420
+ orientation?: "vertical" | "horizontal";
421
+ }) => JumperGraph;
422
+
423
+ declare const generateJumperX4Grid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, regionsBetweenPads, outerPaddingX: outerPaddingXParam, outerPaddingY: outerPaddingYParam, outerChannelXPointCount, outerChannelYPointCount, orientation, center, bounds, parallelTracesUnderJumperCount, }: {
424
+ cols: number;
425
+ rows: number;
426
+ marginX: number;
427
+ marginY: number;
428
+ innerColChannelPointCount?: number;
429
+ innerRowChannelPointCount?: number;
430
+ regionsBetweenPads?: boolean;
431
+ outerPaddingX?: number;
432
+ outerPaddingY?: number;
433
+ outerChannelXPointCount?: number;
434
+ outerChannelYPointCount?: number;
435
+ orientation?: "vertical" | "horizontal";
436
+ center?: {
437
+ x: number;
438
+ y: number;
439
+ };
440
+ bounds?: {
441
+ minX: number;
442
+ maxX: number;
443
+ minY: number;
444
+ maxY: number;
445
+ };
446
+ /** Number of trace points that can pass through the jumper body from top to bottom without using jumpers */
447
+ parallelTracesUnderJumperCount?: number;
448
+ }) => JumperGraph;
431
449
 
432
450
  type RegionRef = {
433
451
  id: string;
@@ -461,7 +479,7 @@ type SharedBoundary = {
461
479
  };
462
480
  type RegionData = {
463
481
  id: string;
464
- bounds: Bounds | null;
482
+ bounds: Bounds$1 | null;
465
483
  polygon: {
466
484
  x: number;
467
485
  y: number;
@@ -502,7 +520,7 @@ declare class RegionBuilder implements RegionRef {
502
520
  private data;
503
521
  constructor(id: string);
504
522
  get id(): string;
505
- rect(b: Bounds): this;
523
+ rect(b: Bounds$1): this;
506
524
  polygon(points: {
507
525
  x: number;
508
526
  y: number;
@@ -531,7 +549,7 @@ declare class ConnectBuilder {
531
549
  private portIds;
532
550
  private boundary;
533
551
  private prefixWasExplicitlySet;
534
- constructor(region1Id: string, region2Id: string, bounds1: Bounds, bounds2: Bounds, addPortFn: AddPortFn$1, prefixIdFn: PrefixIdFn, opts?: {
552
+ constructor(region1Id: string, region2Id: string, bounds1: Bounds$1, bounds2: Bounds$1, addPortFn: AddPortFn$1, prefixIdFn: PrefixIdFn, opts?: {
535
553
  idPrefix?: string;
536
554
  tolerance?: number;
537
555
  });
@@ -551,7 +569,7 @@ declare class ConnectBuilder {
551
569
 
552
570
  type ResolveRegionFn = (ref: RegionRef | string) => {
553
571
  id: string;
554
- bounds: Bounds;
572
+ bounds: Bounds$1;
555
573
  };
556
574
  type AddPortFn = (port: PortData) => void;
557
575
  declare class PortBuilder {
@@ -607,4 +625,148 @@ declare class Topology {
607
625
  getPortIds(): string[];
608
626
  }
609
627
 
610
- export { type Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type GScore, type GraphEdgeId, type HyperGraph, HyperGraphSolver, type JPort, type JRegion, JUMPER_GRAPH_SOLVER_DEFAULTS, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, PortBuilder, type PortData, type PortId, type PortSpread, type Region, RegionBuilder, type RegionData, type RegionId, type RegionPort, type RegionPortAssignment, type RegionRef, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SharedBoundary, type SolvedRoute, Topology, TopologyError, type ValidateOpts, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createGraphWithConnectionsFromBaseGraph, generateJumperGrid, generateJumperX4Grid, rotateGraph90Degrees };
628
+ declare const VIA_GRAPH_SOLVER_DEFAULTS: {
629
+ portUsagePenalty: number;
630
+ portUsagePenaltySq: number;
631
+ crossingPenalty: number;
632
+ crossingPenaltySq: number;
633
+ ripCost: number;
634
+ greedyMultiplier: number;
635
+ };
636
+ type ViaData$1 = {
637
+ viaId: string;
638
+ diameter: number;
639
+ position: {
640
+ x: number;
641
+ y: number;
642
+ };
643
+ };
644
+ type ViasByNet$1 = Record<string, ViaData$1[]>;
645
+ declare class ViaGraphSolver extends HyperGraphSolver<JRegion, JPort> {
646
+ getSolverName(): string;
647
+ UNIT_OF_COST: string;
648
+ viasByNet?: ViasByNet$1;
649
+ portUsagePenalty: number;
650
+ portUsagePenaltySq: number;
651
+ crossingPenalty: number;
652
+ crossingPenaltySq: number;
653
+ ripCost: number;
654
+ baseMaxIterations: number;
655
+ additionalMaxIterationsPerConnection: number;
656
+ additionalMaxIterationsPerCrossing: number;
657
+ constructor(input: {
658
+ inputGraph: HyperGraph | SerializedHyperGraph;
659
+ inputConnections: (Connection | SerializedConnection)[];
660
+ viasByNet?: ViasByNet$1;
661
+ ripCost?: number;
662
+ portUsagePenalty?: number;
663
+ crossingPenalty?: number;
664
+ baseMaxIterations?: number;
665
+ additionalMaxIterationsPerConnection?: number;
666
+ });
667
+ private populateDistanceToEndMaps;
668
+ estimateCostToEnd(port: JPort): number;
669
+ getPortUsagePenalty(port: JPort): number;
670
+ computeIncreasedRegionCostIfPortsAreUsed(region: JRegion, port1: JPort, port2: JPort): number;
671
+ getRipsRequiredForPortUsage(region: JRegion, port1: JPort, port2: JPort): RegionPortAssignment[];
672
+ routeSolvedHook(solvedRoute: SolvedRoute): void;
673
+ routeStartedHook(connection: Connection): void;
674
+ visualize(): GraphicsObject;
675
+ }
676
+
677
+ type ViaGraphFromXYConnectionsResult = JumperGraph & {
678
+ connections: Connection[];
679
+ tiledViasByNet: ViasByNet$1;
680
+ tileCount: {
681
+ rows: number;
682
+ cols: number;
683
+ };
684
+ };
685
+ /**
686
+ * Creates a complete via topology graph from XY connections.
687
+ *
688
+ * This is the main entry point for integrating ViaGraphSolver with dataset02.
689
+ * It:
690
+ * 1. Calculates bounds from connection XY coordinates (no margin)
691
+ * 2. Generates a tiled grid of via topologies that fits within bounds
692
+ * 3. Creates outer frame regions to fill remaining space
693
+ * 4. Attaches connection regions to the graph
694
+ *
695
+ * @param xyConnections - Array of connections with start/end XY coordinates
696
+ * @param viasByNet - Via positions grouped by net name
697
+ * @param opts - Optional configuration (tileSize defaults to 5mm, portPitch to 0.4mm)
698
+ */
699
+ declare function createViaGraphFromXYConnections(xyConnections: XYConnection[], viasByNet: ViasByNet$1, opts?: {
700
+ tileSize?: number;
701
+ portPitch?: number;
702
+ }): ViaGraphFromXYConnectionsResult;
703
+
704
+ type ViaGraphWithConnections = JumperGraph & {
705
+ connections: Connection[];
706
+ };
707
+ /**
708
+ * Creates a new graph from a via topology base graph with additional connection
709
+ * regions at specified positions on the boundary.
710
+ *
711
+ * Uses polygon-edge proximity (not bounding-box proximity) to find the correct
712
+ * boundary region for each connection endpoint. This is necessary because the
713
+ * via topology's polygon regions have overlapping bounding boxes.
714
+ */
715
+ declare const createViaGraphWithConnections: (baseGraph: JumperGraph, xyConnections: XYConnection[]) => ViaGraphWithConnections;
716
+
717
+ type Bounds = {
718
+ minX: number;
719
+ maxX: number;
720
+ minY: number;
721
+ maxY: number;
722
+ };
723
+ /**
724
+ * Generates a tiled grid of via topologies with outer frame regions.
725
+ *
726
+ * The via tiles are centered within the given bounds. If the bounds are smaller
727
+ * than one tile, no via tiles are created - only outer frame regions.
728
+ *
729
+ * The outer frame consists of rectangular regions (T, B, L, R) that fill the
730
+ * space between the tiled area and the problem bounds.
731
+ */
732
+ declare function generateViaTopologyGrid(opts: {
733
+ viasByNet: ViasByNet$1;
734
+ bounds: Bounds;
735
+ tileSize?: number;
736
+ portPitch?: number;
737
+ }): {
738
+ regions: JRegion[];
739
+ ports: JPort[];
740
+ tiledViasByNet: ViasByNet$1;
741
+ tileCount: {
742
+ rows: number;
743
+ cols: number;
744
+ };
745
+ };
746
+
747
+ type ViaData = {
748
+ viaId: string;
749
+ diameter: number;
750
+ position: {
751
+ x: number;
752
+ y: number;
753
+ };
754
+ };
755
+ type ViasByNet = Record<string, ViaData[]>;
756
+ /**
757
+ * Generates four outer topology regions (top, bottom, left, right) that wrap
758
+ * around all vias, forming a closed frame that extends to the graph boundary.
759
+ *
760
+ * Each region is a polygon whose inner edge follows the extreme via edges
761
+ * (connected by straight diagonal lines between segments), and whose outer
762
+ * edge is the graph boundary.
763
+ */
764
+ declare const generateViaTopologyRegions: (viasByNet: ViasByNet, opts?: {
765
+ graphSize?: number;
766
+ idPrefix?: string;
767
+ }) => {
768
+ regions: JRegion[];
769
+ ports: JPort[];
770
+ };
771
+
772
+ export { type Bounds$1 as Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type GScore, type GraphEdgeId, type HyperGraph, HyperGraphSolver, type JPort, type JRegion, JUMPER_GRAPH_SOLVER_DEFAULTS, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, PortBuilder, type PortData, type PortId, type PortSpread, type Region, RegionBuilder, type RegionData, type RegionId, type RegionPort, type RegionPortAssignment, type RegionRef, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SharedBoundary, type SolvedRoute, Topology, TopologyError, VIA_GRAPH_SOLVER_DEFAULTS, type ValidateOpts, type ViaData$1 as ViaData, type ViaGraphFromXYConnectionsResult, ViaGraphSolver, type ViaGraphWithConnections, type ViasByNet$1 as ViasByNet, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createGraphWithConnectionsFromBaseGraph, createViaGraphFromXYConnections, createViaGraphWithConnections, generateJumperGrid, generateJumperX4Grid, generateViaTopologyGrid, generateViaTopologyRegions, rotateGraph90Degrees };