@tscircuit/hypergraph 0.0.51 → 0.0.53

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 +77 -25
  2. package/dist/index.js +1127 -50
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -706,8 +706,8 @@ var viasByNet = {
706
706
  viaId: "6d182b7d-a260-427b-8c43-a09409422252",
707
707
  diameter: 0.3,
708
708
  position: {
709
- x: 0.083422,
710
- y: -0.705274
709
+ x: 0.075,
710
+ y: -0.806274
711
711
  }
712
712
  }
713
713
  ],
@@ -750,32 +750,28 @@ var routeSegments = [
750
750
  y: -0.055081
751
751
  },
752
752
  {
753
- x: 1.01282,
754
- y: -0.252657
753
+ x: 0.893145,
754
+ y: -0.132982
755
755
  },
756
756
  {
757
- x: 1.01282,
758
- y: -0.563283
757
+ x: 0.893145,
758
+ y: -0.753669
759
759
  },
760
760
  {
761
- x: 0.444829,
762
- y: -1.131274
761
+ x: 0.465539,
762
+ y: -1.181274
763
763
  },
764
764
  {
765
- x: -0.093033,
766
- y: -1.131274
765
+ x: -0.113744,
766
+ y: -1.181274
767
767
  },
768
768
  {
769
- x: -0.382222,
770
- y: -0.842085
769
+ x: -0.4,
770
+ y: -0.895018
771
771
  },
772
772
  {
773
- x: -0.382222,
774
- y: 0.433097
775
- },
776
- {
777
- x: -0.528763,
778
- y: 0.579638
773
+ x: -0.4,
774
+ y: 0.547292
779
775
  },
780
776
  {
781
777
  x: -0.528763,
@@ -834,12 +830,12 @@ var routeSegments = [
834
830
  y: 0.691542
835
831
  },
836
832
  {
837
- x: -0.029,
838
- y: -0.592852
833
+ x: 0.075,
834
+ y: 0.587542
839
835
  },
840
836
  {
841
- x: 0.083422,
842
- y: -0.705274
837
+ x: 0.075,
838
+ y: -0.806274
843
839
  }
844
840
  ]
845
841
  },
@@ -1050,6 +1046,62 @@ declare function generateDefaultViaTopologyRegions(opts: Parameters<typeof gener
1050
1046
  ports: JPort[];
1051
1047
  };
1052
1048
 
1049
+ type ViaTileRecommendationProblemInput = {
1050
+ graphWidthMm?: number;
1051
+ graphHeightMm?: number;
1052
+ connectionCount?: number;
1053
+ intersectionCount?: number;
1054
+ xyConnections?: XYConnection[];
1055
+ sample?: {
1056
+ config?: {
1057
+ numCrossings?: number;
1058
+ };
1059
+ connections?: Array<{
1060
+ connectionId: string;
1061
+ startRegionId: string;
1062
+ endRegionId: string;
1063
+ }>;
1064
+ connectionRegions?: Array<{
1065
+ regionId: string;
1066
+ d: {
1067
+ center: {
1068
+ x: number;
1069
+ y: number;
1070
+ };
1071
+ bounds: {
1072
+ minX: number;
1073
+ maxX: number;
1074
+ minY: number;
1075
+ maxY: number;
1076
+ };
1077
+ };
1078
+ }>;
1079
+ };
1080
+ };
1081
+ type ViaTileCandidate = {
1082
+ viaRegionName: string;
1083
+ viaTile: ViaTile;
1084
+ };
1085
+ type ViaTileRecommendationCandidate = {
1086
+ viaRegionName: string;
1087
+ predictedReliability: number;
1088
+ estimatedIterationCost: number;
1089
+ capacityScore: number;
1090
+ requiredCapacityScore: number;
1091
+ acceptedAsReliable: boolean;
1092
+ };
1093
+ type ViaTileRecommendation = {
1094
+ recommendedViaRegionName: string;
1095
+ inputFeatures: {
1096
+ graphWidthMm: number;
1097
+ graphHeightMm: number;
1098
+ connectionCount: number;
1099
+ intersectionCount: number;
1100
+ };
1101
+ candidates: ViaTileRecommendationCandidate[];
1102
+ };
1103
+ declare const recommendViaTileFromGraphInput: (problemInput: ViaTileRecommendationProblemInput, fallbackXYConnections?: XYConnection[], viaTileCandidates?: ViaTileCandidate[], _opts?: unknown) => ViaTileRecommendation;
1104
+
1053
1105
  type ConvexViaGraphFromXYConnectionsResult = JumperGraph & {
1054
1106
  connections: Connection[];
1055
1107
  viaTile: ViaTile;
@@ -1072,10 +1124,10 @@ type ConvexViaGraphFromXYConnectionsResult = JumperGraph & {
1072
1124
  * 5. Attaches connection regions to the graph
1073
1125
  *
1074
1126
  * @param xyConnections - Array of connections with start/end XY coordinates
1075
- * @param viaTile - Via tile data (defaults to built-in via-tile.json)
1127
+ * @param viaTileOrProblem - Optional explicit via tile, or one-problem input used to recommend a tile
1076
1128
  * @param opts - Optional configuration
1077
1129
  */
1078
- declare function createConvexViaGraphFromXYConnections(xyConnections: XYConnection[], viaTile?: ViaTile, opts?: {
1130
+ declare function createConvexViaGraphFromXYConnections(xyConnections: XYConnection[], viaTileOrProblem?: ViaTile | ViaTileRecommendationProblemInput, opts?: {
1079
1131
  tileWidth?: number;
1080
1132
  tileHeight?: number;
1081
1133
  tileSize?: number;
@@ -1133,4 +1185,4 @@ declare function generateConvexViaTopologyRegions(opts: {
1133
1185
  };
1134
1186
  };
1135
1187
 
1136
- export { type Bounds$1 as Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type ConvexViaGraphFromXYConnectionsResult, 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 RouteSegment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SharedBoundary, type SolvedRoute, Topology, TopologyError, VIA_GRAPH_SOLVER_DEFAULTS, type ValidateOpts, type ViaByNet, type ViaData, ViaGraphSolver, type ViaGraphWithConnections, type ViaTile, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createConvexViaGraphFromXYConnections, createGraphWithConnectionsFromBaseGraph, createViaGraphWithConnections, generateConvexViaTopologyRegions, generateDefaultViaTopologyRegions, generateJumperGrid, generateJumperX4Grid, generateViaTopologyRegions, rotateGraph90Degrees, viaTile4Regions as viaTile };
1188
+ export { type Bounds$1 as Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type ConvexViaGraphFromXYConnectionsResult, 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 RouteSegment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SharedBoundary, type SolvedRoute, Topology, TopologyError, VIA_GRAPH_SOLVER_DEFAULTS, type ValidateOpts, type ViaByNet, type ViaData, ViaGraphSolver, type ViaGraphWithConnections, type ViaTile, type ViaTileRecommendation, type ViaTileRecommendationCandidate, type ViaTileRecommendationProblemInput, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createConvexViaGraphFromXYConnections, createGraphWithConnectionsFromBaseGraph, createViaGraphWithConnections, generateConvexViaTopologyRegions, generateDefaultViaTopologyRegions, generateJumperGrid, generateJumperX4Grid, generateViaTopologyRegions, recommendViaTileFromGraphInput, rotateGraph90Degrees, viaTile4Regions as viaTile };
package/dist/index.js CHANGED
@@ -5291,8 +5291,8 @@ var via_tile_4_regions_default = {
5291
5291
  viaId: "6d182b7d-a260-427b-8c43-a09409422252",
5292
5292
  diameter: 0.3,
5293
5293
  position: {
5294
- x: 0.083422,
5295
- y: -0.705274
5294
+ x: 0.075,
5295
+ y: -0.806274
5296
5296
  }
5297
5297
  }
5298
5298
  ],
@@ -5335,32 +5335,28 @@ var via_tile_4_regions_default = {
5335
5335
  y: -0.055081
5336
5336
  },
5337
5337
  {
5338
- x: 1.01282,
5339
- y: -0.252657
5338
+ x: 0.893145,
5339
+ y: -0.132982
5340
5340
  },
5341
5341
  {
5342
- x: 1.01282,
5343
- y: -0.563283
5342
+ x: 0.893145,
5343
+ y: -0.753669
5344
5344
  },
5345
5345
  {
5346
- x: 0.444829,
5347
- y: -1.131274
5346
+ x: 0.465539,
5347
+ y: -1.181274
5348
5348
  },
5349
5349
  {
5350
- x: -0.093033,
5351
- y: -1.131274
5350
+ x: -0.113744,
5351
+ y: -1.181274
5352
5352
  },
5353
5353
  {
5354
- x: -0.382222,
5355
- y: -0.842085
5354
+ x: -0.4,
5355
+ y: -0.895018
5356
5356
  },
5357
5357
  {
5358
- x: -0.382222,
5359
- y: 0.433097
5360
- },
5361
- {
5362
- x: -0.528763,
5363
- y: 0.579638
5358
+ x: -0.4,
5359
+ y: 0.547292
5364
5360
  },
5365
5361
  {
5366
5362
  x: -0.528763,
@@ -5419,12 +5415,12 @@ var via_tile_4_regions_default = {
5419
5415
  y: 0.691542
5420
5416
  },
5421
5417
  {
5422
- x: -0.029,
5423
- y: -0.592852
5418
+ x: 0.075,
5419
+ y: 0.587542
5424
5420
  },
5425
5421
  {
5426
- x: 0.083422,
5427
- y: -0.705274
5422
+ x: 0.075,
5423
+ y: -0.806274
5428
5424
  }
5429
5425
  ]
5430
5426
  },
@@ -16681,35 +16677,1115 @@ function generateConvexViaTopologyRegions(opts) {
16681
16677
  };
16682
16678
  }
16683
16679
 
16684
- // lib/ViaGraphSolver/via-graph-generator/createConvexViaGraphFromXYConnections.ts
16685
- function calculateBoundsFromConnections(xyConnections) {
16686
- if (xyConnections.length === 0) {
16687
- throw new Error("Cannot calculate bounds from empty connections array");
16688
- }
16689
- let minX = Infinity;
16690
- let maxX = -Infinity;
16691
- let minY = Infinity;
16692
- let maxY = -Infinity;
16693
- for (const conn of xyConnections) {
16694
- minX = Math.min(minX, conn.start.x, conn.end.x);
16695
- maxX = Math.max(maxX, conn.start.x, conn.end.x);
16696
- minY = Math.min(minY, conn.start.y, conn.end.y);
16697
- maxY = Math.max(maxY, conn.start.y, conn.end.y);
16698
- }
16699
- return { minX, maxX, minY, maxY };
16700
- }
16701
- function createConvexViaGraphFromXYConnections(xyConnections, viaTile = via_tile_4_regions_default, opts) {
16702
- const bounds = calculateBoundsFromConnections(xyConnections);
16703
- const {
16704
- regions,
16705
- ports,
16706
- viaTile: generatedViaTile,
16707
- tileCount
16708
- } = generateConvexViaTopologyRegions({
16709
- viaTile,
16680
+ // assets/ViaGraphSolver/via-tile-3-regions.json
16681
+ var via_tile_3_regions_default = {
16682
+ viasByNet: {
16683
+ net1: [
16684
+ {
16685
+ viaId: "1b0111be-ce08-409a-80b7-5006cb5e2c5b",
16686
+ diameter: 0.3,
16687
+ position: {
16688
+ x: -0.396773,
16689
+ y: 0.05144
16690
+ }
16691
+ },
16692
+ {
16693
+ viaId: "2f36dd01-8bf4-49dc-b86b-22c27e4cb7bf",
16694
+ diameter: 0.3,
16695
+ position: {
16696
+ x: -0.04486,
16697
+ y: -0.267596
16698
+ }
16699
+ }
16700
+ ],
16701
+ net2: [
16702
+ {
16703
+ viaId: "51af4ca3-53f4-4a03-914b-6dba63eb8c4a",
16704
+ diameter: 0.3,
16705
+ position: {
16706
+ x: 0.39936,
16707
+ y: 0.600815
16708
+ }
16709
+ },
16710
+ {
16711
+ viaId: "b602bfde-3ed8-4f47-9fa7-5baa7a8a9ec4",
16712
+ diameter: 0.3,
16713
+ position: {
16714
+ x: -0.563329,
16715
+ y: -0.420006
16716
+ }
16717
+ }
16718
+ ],
16719
+ net3: [
16720
+ {
16721
+ viaId: "095a83cb-28a7-472c-95fe-bfb08db097f5",
16722
+ diameter: 0.3,
16723
+ position: {
16724
+ x: -0.070756,
16725
+ y: 0.430539
16726
+ }
16727
+ },
16728
+ {
16729
+ viaId: "e8d75a9d-5b0e-4158-8d39-01b264e49299",
16730
+ diameter: 0.3,
16731
+ position: {
16732
+ x: 0.280866,
16733
+ y: 0.111752
16734
+ }
16735
+ }
16736
+ ]
16737
+ },
16738
+ routeSegments: [
16739
+ {
16740
+ routeId: "net1:route_0",
16741
+ fromPort: "1b0111be-ce08-409a-80b7-5006cb5e2c5b",
16742
+ toPort: "2f36dd01-8bf4-49dc-b86b-22c27e4cb7bf",
16743
+ layer: "bottom",
16744
+ segments: [
16745
+ {
16746
+ x: -0.396773,
16747
+ y: 0.05144
16748
+ },
16749
+ {
16750
+ x: -0.363896,
16751
+ y: 0.05144
16752
+ },
16753
+ {
16754
+ x: -0.04486,
16755
+ y: -0.267596
16756
+ }
16757
+ ]
16758
+ },
16759
+ {
16760
+ routeId: "net2:route_0",
16761
+ fromPort: "51af4ca3-53f4-4a03-914b-6dba63eb8c4a",
16762
+ toPort: "b602bfde-3ed8-4f47-9fa7-5baa7a8a9ec4",
16763
+ layer: "bottom",
16764
+ segments: [
16765
+ {
16766
+ x: 0.39936,
16767
+ y: 0.600815
16768
+ },
16769
+ {
16770
+ x: 0.681866,
16771
+ y: 0.318309
16772
+ },
16773
+ {
16774
+ x: 0.681866,
16775
+ y: -0.10797
16776
+ },
16777
+ {
16778
+ x: 0.12124,
16779
+ y: -0.668596
16780
+ },
16781
+ {
16782
+ x: -0.314739,
16783
+ y: -0.668596
16784
+ },
16785
+ {
16786
+ x: -0.563329,
16787
+ y: -0.420006
16788
+ }
16789
+ ]
16790
+ },
16791
+ {
16792
+ routeId: "net3:route_0",
16793
+ fromPort: "095a83cb-28a7-472c-95fe-bfb08db097f5",
16794
+ toPort: "e8d75a9d-5b0e-4158-8d39-01b264e49299",
16795
+ layer: "bottom",
16796
+ segments: [
16797
+ {
16798
+ x: -0.070756,
16799
+ y: 0.430539
16800
+ },
16801
+ {
16802
+ x: -0.037921,
16803
+ y: 0.430539
16804
+ },
16805
+ {
16806
+ x: 0.280866,
16807
+ y: 0.111752
16808
+ }
16809
+ ]
16810
+ }
16811
+ ],
16812
+ tileWidth: 1.6201949999999998,
16813
+ tileHeight: 1.6444109999999998
16814
+ };
16815
+
16816
+ // assets/ViaGraphSolver/via-tile-5-regions.json
16817
+ var via_tile_5_regions_default = {
16818
+ viasByNet: {
16819
+ net1: [
16820
+ {
16821
+ viaId: "14ee4bf1-e7e7-4351-ad16-ba1a8aac0af3",
16822
+ diameter: 0.3,
16823
+ position: {
16824
+ x: 0.778514,
16825
+ y: -0.012215
16826
+ }
16827
+ },
16828
+ {
16829
+ viaId: "8a898812-db2b-4b81-899d-f953b3222f9a",
16830
+ diameter: 0.3,
16831
+ position: {
16832
+ x: -0.770591,
16833
+ y: 0.97317
16834
+ }
16835
+ }
16836
+ ],
16837
+ net2: [
16838
+ {
16839
+ viaId: "1f552ada-e01a-4230-b5f5-0006595b14d5",
16840
+ diameter: 0.3,
16841
+ position: {
16842
+ x: 1.014826,
16843
+ y: 0.42842
16844
+ }
16845
+ },
16846
+ {
16847
+ viaId: "6987544a-501f-4711-bdff-dc583936a21c",
16848
+ diameter: 0.3,
16849
+ position: {
16850
+ x: -0.854951,
16851
+ y: -0.884286
16852
+ }
16853
+ }
16854
+ ],
16855
+ net3: [
16856
+ {
16857
+ viaId: "13cd75da-d582-4eed-bc2c-fee6fa78bc6a",
16858
+ diameter: 0.3,
16859
+ position: {
16860
+ x: -1.067887,
16861
+ y: -0.431891
16862
+ }
16863
+ },
16864
+ {
16865
+ viaId: "9f188f9d-bce8-46c7-b9e8-542b8599d48d",
16866
+ diameter: 0.3,
16867
+ position: {
16868
+ x: 0.695984,
16869
+ y: 0.813573
16870
+ }
16871
+ }
16872
+ ],
16873
+ net4: [
16874
+ {
16875
+ viaId: "2ef3b96b-58c4-4150-b5d1-e90f74b92b25",
16876
+ diameter: 0.3,
16877
+ position: {
16878
+ x: -0.273716,
16879
+ y: 1.029009
16880
+ }
16881
+ },
16882
+ {
16883
+ viaId: "37a70467-7553-415f-8ad7-8b88a5e56ca8",
16884
+ diameter: 0.3,
16885
+ position: {
16886
+ x: -1.062855,
16887
+ y: 0.56748
16888
+ }
16889
+ },
16890
+ {
16891
+ viaId: "6d182b7d-a260-427b-8c43-a09409422252",
16892
+ diameter: 0.3,
16893
+ position: {
16894
+ x: 0.04738,
16895
+ y: -0.678598
16896
+ }
16897
+ }
16898
+ ],
16899
+ net5: [
16900
+ {
16901
+ viaId: "346c301a-f2b4-44d7-b975-5438ddaa0bde",
16902
+ diameter: 0.3,
16903
+ position: {
16904
+ x: 0.462204,
16905
+ y: -0.39945
16906
+ }
16907
+ },
16908
+ {
16909
+ viaId: "c54b4b94-90e0-4240-97ef-883cf097d79d",
16910
+ diameter: 0.3,
16911
+ position: {
16912
+ x: 0.22363,
16913
+ y: 0.977538
16914
+ }
16915
+ },
16916
+ {
16917
+ viaId: "f3cb916e-b0fd-4c5e-b14b-3779f4f9bd01",
16918
+ diameter: 0.3,
16919
+ position: {
16920
+ x: -1.047736,
16921
+ y: 0.067706
16922
+ }
16923
+ }
16924
+ ]
16925
+ },
16926
+ routeSegments: [
16927
+ {
16928
+ routeId: "net1:route_0",
16929
+ fromPort: "14ee4bf1-e7e7-4351-ad16-ba1a8aac0af3",
16930
+ toPort: "8a898812-db2b-4b81-899d-f953b3222f9a",
16931
+ layer: "bottom",
16932
+ segments: [
16933
+ {
16934
+ x: 0.778514,
16935
+ y: -0.012215
16936
+ },
16937
+ {
16938
+ x: 0.863204,
16939
+ y: -0.096905
16940
+ },
16941
+ {
16942
+ x: 0.863204,
16943
+ y: -0.56555
16944
+ },
16945
+ {
16946
+ x: 0.349156,
16947
+ y: -1.079598
16948
+ },
16949
+ {
16950
+ x: -0.11872,
16951
+ y: -1.079598
16952
+ },
16953
+ {
16954
+ x: -0.35362,
16955
+ y: -0.844698
16956
+ },
16957
+ {
16958
+ x: -0.35362,
16959
+ y: -0.818517
16960
+ },
16961
+ {
16962
+ x: -0.646736,
16963
+ y: -0.525401
16964
+ },
16965
+ {
16966
+ x: -0.646736,
16967
+ y: 0.849315
16968
+ },
16969
+ {
16970
+ x: -0.770591,
16971
+ y: 0.97317
16972
+ }
16973
+ ]
16974
+ },
16975
+ {
16976
+ routeId: "net2:route_0",
16977
+ fromPort: "1f552ada-e01a-4230-b5f5-0006595b14d5",
16978
+ toPort: "6987544a-501f-4711-bdff-dc583936a21c",
16979
+ layer: "bottom",
16980
+ segments: [
16981
+ {
16982
+ x: 1.014826,
16983
+ y: 0.42842
16984
+ },
16985
+ {
16986
+ x: 1.179514,
16987
+ y: 0.263732
16988
+ },
16989
+ {
16990
+ x: 1.179514,
16991
+ y: -0.674918
16992
+ },
16993
+ {
16994
+ x: 0.473834,
16995
+ y: -1.380598
16996
+ },
16997
+ {
16998
+ x: -0.358639,
16999
+ y: -1.380598
17000
+ },
17001
+ {
17002
+ x: -0.854951,
17003
+ y: -0.884286
17004
+ }
17005
+ ]
17006
+ },
17007
+ {
17008
+ routeId: "net3:route_0",
17009
+ fromPort: "13cd75da-d582-4eed-bc2c-fee6fa78bc6a",
17010
+ toPort: "9f188f9d-bce8-46c7-b9e8-542b8599d48d",
17011
+ layer: "bottom",
17012
+ segments: [
17013
+ {
17014
+ x: -1.067887,
17015
+ y: -0.431891
17016
+ },
17017
+ {
17018
+ x: -1.255951,
17019
+ y: -0.619955
17020
+ },
17021
+ {
17022
+ x: -1.255951,
17023
+ y: -1.050386
17024
+ },
17025
+ {
17026
+ x: -0.624739,
17027
+ y: -1.681598
17028
+ },
17029
+ {
17030
+ x: 0.598512,
17031
+ y: -1.681598
17032
+ },
17033
+ {
17034
+ x: 1.480514,
17035
+ y: -0.799596
17036
+ },
17037
+ {
17038
+ x: 1.480514,
17039
+ y: 0.529832
17040
+ },
17041
+ {
17042
+ x: 1.180926,
17043
+ y: 0.82942
17044
+ },
17045
+ {
17046
+ x: 0.711831,
17047
+ y: 0.82942
17048
+ },
17049
+ {
17050
+ x: 0.695984,
17051
+ y: 0.813573
17052
+ }
17053
+ ]
17054
+ },
17055
+ {
17056
+ routeId: "net4:route_0",
17057
+ fromPort: "2ef3b96b-58c4-4150-b5d1-e90f74b92b25",
17058
+ toPort: "37a70467-7553-415f-8ad7-8b88a5e56ca8",
17059
+ layer: "bottom",
17060
+ segments: [
17061
+ {
17062
+ x: -0.273716,
17063
+ y: 1.029009
17064
+ },
17065
+ {
17066
+ x: -0.273716,
17067
+ y: 1.043395
17068
+ },
17069
+ {
17070
+ x: -0.604491,
17071
+ y: 1.37417
17072
+ },
17073
+ {
17074
+ x: -0.936691,
17075
+ y: 1.37417
17076
+ },
17077
+ {
17078
+ x: -1.171591,
17079
+ y: 1.13927
17080
+ },
17081
+ {
17082
+ x: -1.171591,
17083
+ y: 0.676216
17084
+ },
17085
+ {
17086
+ x: -1.062855,
17087
+ y: 0.56748
17088
+ }
17089
+ ]
17090
+ },
17091
+ {
17092
+ routeId: "net4:route_1",
17093
+ fromPort: "2ef3b96b-58c4-4150-b5d1-e90f74b92b25",
17094
+ toPort: "6d182b7d-a260-427b-8c43-a09409422252",
17095
+ layer: "bottom",
17096
+ segments: [
17097
+ {
17098
+ x: -0.273716,
17099
+ y: 1.029009
17100
+ },
17101
+ {
17102
+ x: -0.273716,
17103
+ y: -0.357502
17104
+ },
17105
+ {
17106
+ x: 0.04738,
17107
+ y: -0.678598
17108
+ }
17109
+ ]
17110
+ },
17111
+ {
17112
+ routeId: "net5:route_0",
17113
+ fromPort: "346c301a-f2b4-44d7-b975-5438ddaa0bde",
17114
+ toPort: "c54b4b94-90e0-4240-97ef-883cf097d79d",
17115
+ layer: "bottom",
17116
+ segments: [
17117
+ {
17118
+ x: 0.462204,
17119
+ y: -0.39945
17120
+ },
17121
+ {
17122
+ x: 0.22363,
17123
+ y: -0.160876
17124
+ },
17125
+ {
17126
+ x: 0.22363,
17127
+ y: 0.977538
17128
+ }
17129
+ ]
17130
+ },
17131
+ {
17132
+ routeId: "net5:route_1",
17133
+ fromPort: "c54b4b94-90e0-4240-97ef-883cf097d79d",
17134
+ toPort: "f3cb916e-b0fd-4c5e-b14b-3779f4f9bd01",
17135
+ layer: "bottom",
17136
+ segments: [
17137
+ {
17138
+ x: 0.22363,
17139
+ y: 0.977538
17140
+ },
17141
+ {
17142
+ x: 0.22363,
17143
+ y: 1.098763
17144
+ },
17145
+ {
17146
+ x: -0.352777,
17147
+ y: 1.67517
17148
+ },
17149
+ {
17150
+ x: -1.061369,
17151
+ y: 1.67517
17152
+ },
17153
+ {
17154
+ x: -1.472591,
17155
+ y: 1.263948
17156
+ },
17157
+ {
17158
+ x: -1.472591,
17159
+ y: 0.410116
17160
+ },
17161
+ {
17162
+ x: -1.130181,
17163
+ y: 0.067706
17164
+ },
17165
+ {
17166
+ x: -1.047736,
17167
+ y: 0.067706
17168
+ }
17169
+ ]
17170
+ }
17171
+ ],
17172
+ tileWidth: 3.253105,
17173
+ tileHeight: 3.656768
17174
+ };
17175
+
17176
+ // assets/ViaGraphSolver/via-tile-6-regions.json
17177
+ var via_tile_6_regions_default = {
17178
+ viasByNet: {
17179
+ net1: [
17180
+ {
17181
+ viaId: "afbcad2b-4805-48e1-aa34-1f4472329d76",
17182
+ diameter: 0.3,
17183
+ position: {
17184
+ x: 0.648081,
17185
+ y: -0.653655
17186
+ }
17187
+ },
17188
+ {
17189
+ viaId: "d31e4843-afe8-4699-8221-70cba52d9589",
17190
+ diameter: 0.3,
17191
+ position: {
17192
+ x: 0.082317,
17193
+ y: 0.912692
17194
+ }
17195
+ }
17196
+ ],
17197
+ net2: [
17198
+ {
17199
+ viaId: "096f26d0-a555-4492-94da-865de1f8e6e6",
17200
+ diameter: 0.3,
17201
+ position: {
17202
+ x: 1.336913,
17203
+ y: 0.267523
17204
+ }
17205
+ },
17206
+ {
17207
+ viaId: "71432b8b-1d41-4586-88f8-1dd9c542b47b",
17208
+ diameter: 0.3,
17209
+ position: {
17210
+ x: -0.651699,
17211
+ y: -1.264802
17212
+ }
17213
+ }
17214
+ ],
17215
+ net3: [
17216
+ {
17217
+ viaId: "833f3d74-7403-4d5b-8999-848795f1be47",
17218
+ diameter: 0.3,
17219
+ position: {
17220
+ x: -0.652635,
17221
+ y: -0.2648
17222
+ }
17223
+ },
17224
+ {
17225
+ viaId: "ff5f1055-a4f7-4a85-a790-4769e4eea87b",
17226
+ diameter: 0.3,
17227
+ position: {
17228
+ x: 0.58222,
17229
+ y: 0.92265
17230
+ }
17231
+ }
17232
+ ],
17233
+ net4: [
17234
+ {
17235
+ viaId: "6e2c4dc3-f43d-4f13-bff3-c0e08585ceb1",
17236
+ diameter: 0.3,
17237
+ position: {
17238
+ x: -0.15182,
17239
+ y: -1.253675
17240
+ }
17241
+ },
17242
+ {
17243
+ viaId: "b11b8fa4-a804-42b8-8de3-4416f00feda9",
17244
+ diameter: 0.3,
17245
+ position: {
17246
+ x: -0.650488,
17247
+ y: 0.235198
17248
+ }
17249
+ }
17250
+ ],
17251
+ net5: [
17252
+ {
17253
+ viaId: "bd0008ee-fb87-4f6a-922b-14f6d989ee78",
17254
+ diameter: 0.3,
17255
+ position: {
17256
+ x: -0.305576,
17257
+ y: 0.59719
17258
+ }
17259
+ },
17260
+ {
17261
+ viaId: "cd839c31-ee5e-47be-973e-a4e0fd041bae",
17262
+ diameter: 0.3,
17263
+ position: {
17264
+ x: 0.251735,
17265
+ y: -0.95847
17266
+ }
17267
+ }
17268
+ ],
17269
+ net6: [
17270
+ {
17271
+ viaId: "aa3a0b88-786d-4e3a-9cf4-ab924faca4e9",
17272
+ diameter: 0.3,
17273
+ position: {
17274
+ x: -0.65095,
17275
+ y: -0.7648
17276
+ }
17277
+ },
17278
+ {
17279
+ viaId: "c0f2259e-7d00-43c3-bfa3-183bc4286c46",
17280
+ diameter: 0.3,
17281
+ position: {
17282
+ x: 0.971187,
17283
+ y: 0.608473
17284
+ }
17285
+ }
17286
+ ]
17287
+ },
17288
+ routeSegments: [
17289
+ {
17290
+ routeId: "net1:route_0",
17291
+ fromPort: "afbcad2b-4805-48e1-aa34-1f4472329d76",
17292
+ toPort: "d31e4843-afe8-4699-8221-70cba52d9589",
17293
+ layer: "bottom",
17294
+ segments: [
17295
+ {
17296
+ x: 0.648081,
17297
+ y: -0.653655
17298
+ },
17299
+ {
17300
+ x: 0.648081,
17301
+ y: 0.268604
17302
+ },
17303
+ {
17304
+ x: 0.082317,
17305
+ y: 0.834368
17306
+ },
17307
+ {
17308
+ x: 0.082317,
17309
+ y: 0.912692
17310
+ }
17311
+ ]
17312
+ },
17313
+ {
17314
+ routeId: "net2:route_0",
17315
+ fromPort: "096f26d0-a555-4492-94da-865de1f8e6e6",
17316
+ toPort: "71432b8b-1d41-4586-88f8-1dd9c542b47b",
17317
+ layer: "bottom",
17318
+ segments: [
17319
+ {
17320
+ x: 1.336913,
17321
+ y: 0.267523
17322
+ },
17323
+ {
17324
+ x: 1.336913,
17325
+ y: -0.531923
17326
+ },
17327
+ {
17328
+ x: 0.214161,
17329
+ y: -1.654675
17330
+ },
17331
+ {
17332
+ x: -0.31792,
17333
+ y: -1.654675
17334
+ },
17335
+ {
17336
+ x: -0.651699,
17337
+ y: -1.320896
17338
+ },
17339
+ {
17340
+ x: -0.651699,
17341
+ y: -1.264802
17342
+ }
17343
+ ]
17344
+ },
17345
+ {
17346
+ routeId: "net3:route_0",
17347
+ fromPort: "833f3d74-7403-4d5b-8999-848795f1be47",
17348
+ toPort: "ff5f1055-a4f7-4a85-a790-4769e4eea87b",
17349
+ layer: "bottom",
17350
+ segments: [
17351
+ {
17352
+ x: -0.652635,
17353
+ y: -0.2648
17354
+ },
17355
+ {
17356
+ x: -0.71759,
17357
+ y: -0.2648
17358
+ },
17359
+ {
17360
+ x: -1.051488,
17361
+ y: 0.069098
17362
+ },
17363
+ {
17364
+ x: -1.051488,
17365
+ y: 0.418378
17366
+ },
17367
+ {
17368
+ x: -0.156174,
17369
+ y: 1.313692
17370
+ },
17371
+ {
17372
+ x: 0.248417,
17373
+ y: 1.313692
17374
+ },
17375
+ {
17376
+ x: 0.58222,
17377
+ y: 0.979889
17378
+ },
17379
+ {
17380
+ x: 0.58222,
17381
+ y: 0.92265
17382
+ }
17383
+ ]
17384
+ },
17385
+ {
17386
+ routeId: "net4:route_0",
17387
+ fromPort: "6e2c4dc3-f43d-4f13-bff3-c0e08585ceb1",
17388
+ toPort: "b11b8fa4-a804-42b8-8de3-4416f00feda9",
17389
+ layer: "bottom",
17390
+ segments: [
17391
+ {
17392
+ x: -0.15182,
17393
+ y: -1.253675
17394
+ },
17395
+ {
17396
+ x: -0.15182,
17397
+ y: -0.198515
17398
+ },
17399
+ {
17400
+ x: -0.585533,
17401
+ y: 0.235198
17402
+ },
17403
+ {
17404
+ x: -0.650488,
17405
+ y: 0.235198
17406
+ }
17407
+ ]
17408
+ },
17409
+ {
17410
+ routeId: "net5:route_0",
17411
+ fromPort: "bd0008ee-fb87-4f6a-922b-14f6d989ee78",
17412
+ toPort: "cd839c31-ee5e-47be-973e-a4e0fd041bae",
17413
+ layer: "bottom",
17414
+ segments: [
17415
+ {
17416
+ x: -0.305576,
17417
+ y: 0.59719
17418
+ },
17419
+ {
17420
+ x: 0.14918,
17421
+ y: 0.142434
17422
+ },
17423
+ {
17424
+ x: 0.14918,
17425
+ y: -0.855915
17426
+ },
17427
+ {
17428
+ x: 0.251735,
17429
+ y: -0.95847
17430
+ }
17431
+ ]
17432
+ },
17433
+ {
17434
+ routeId: "net6:route_0",
17435
+ fromPort: "aa3a0b88-786d-4e3a-9cf4-ab924faca4e9",
17436
+ toPort: "c0f2259e-7d00-43c3-bfa3-183bc4286c46",
17437
+ layer: "bottom",
17438
+ segments: [
17439
+ {
17440
+ x: -0.65095,
17441
+ y: -0.7648
17442
+ },
17443
+ {
17444
+ x: -0.75509,
17445
+ y: -0.7648
17446
+ },
17447
+ {
17448
+ x: -1.402488,
17449
+ y: -0.117402
17450
+ },
17451
+ {
17452
+ x: -1.402488,
17453
+ y: 0.563766
17454
+ },
17455
+ {
17456
+ x: -0.301563,
17457
+ y: 1.664692
17458
+ },
17459
+ {
17460
+ x: 0.442633,
17461
+ y: 1.664692
17462
+ },
17463
+ {
17464
+ x: 1.023297,
17465
+ y: 1.084028
17466
+ },
17467
+ {
17468
+ x: 1.023297,
17469
+ y: 0.660583
17470
+ },
17471
+ {
17472
+ x: 0.971187,
17473
+ y: 0.608473
17474
+ }
17475
+ ]
17476
+ }
17477
+ ],
17478
+ tileWidth: 3.1144009999999995,
17479
+ tileHeight: 3.619367
17480
+ };
17481
+
17482
+ // lib/ViaGraphSolver/via-graph-generator/recommendViaTileFromGraphInput.ts
17483
+ var DEFAULT_VIA_TILE_CANDIDATES = [
17484
+ {
17485
+ viaRegionName: "via-tile-3-regions",
17486
+ viaTile: via_tile_3_regions_default
17487
+ },
17488
+ {
17489
+ viaRegionName: "via-tile-4-regions",
17490
+ viaTile: via_tile_4_regions_default
17491
+ },
17492
+ {
17493
+ viaRegionName: "via-tile-5-regions",
17494
+ viaTile: via_tile_5_regions_default
17495
+ },
17496
+ {
17497
+ viaRegionName: "via-tile-6-regions",
17498
+ viaTile: via_tile_6_regions_default
17499
+ }
17500
+ ];
17501
+ var round2 = (value) => Math.round(value * 100) / 100;
17502
+ var clamp4 = (value, min, max) => Math.max(min, Math.min(max, value));
17503
+ var sigmoid = (x) => 1 / (1 + Math.exp(-x));
17504
+ var ccw = (a, b, c) => (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
17505
+ var segmentsIntersect = (a1, a2, b1, b2) => ccw(a1, b1, b2) !== ccw(a2, b1, b2) && ccw(a1, a2, b1) !== ccw(a1, a2, b2);
17506
+ var countIntersections = (xyConnections) => {
17507
+ let intersections = 0;
17508
+ for (let i = 0; i < xyConnections.length; i++) {
17509
+ for (let j = i + 1; j < xyConnections.length; j++) {
17510
+ if (segmentsIntersect(
17511
+ xyConnections[i].start,
17512
+ xyConnections[i].end,
17513
+ xyConnections[j].start,
17514
+ xyConnections[j].end
17515
+ )) {
17516
+ intersections++;
17517
+ }
17518
+ }
17519
+ }
17520
+ return intersections;
17521
+ };
17522
+ var getBoundsFromSample = (sample) => {
17523
+ const regions = sample.connectionRegions ?? [];
17524
+ if (regions.length === 0) return null;
17525
+ const minX = Math.min(...regions.map((r) => r.d.bounds.minX));
17526
+ const maxX = Math.max(...regions.map((r) => r.d.bounds.maxX));
17527
+ const minY = Math.min(...regions.map((r) => r.d.bounds.minY));
17528
+ const maxY = Math.max(...regions.map((r) => r.d.bounds.maxY));
17529
+ return {
17530
+ widthMm: maxX - minX,
17531
+ heightMm: maxY - minY
17532
+ };
17533
+ };
17534
+ var extractXYConnectionsFromSample = (sample) => {
17535
+ const connections = sample.connections ?? [];
17536
+ const regionMap = new Map(
17537
+ (sample.connectionRegions ?? []).map((r) => [r.regionId, r.d.center])
17538
+ );
17539
+ const xyConnections = [];
17540
+ for (const conn of connections) {
17541
+ const start = regionMap.get(conn.startRegionId);
17542
+ const end = regionMap.get(conn.endRegionId);
17543
+ if (!start || !end) continue;
17544
+ xyConnections.push({
17545
+ connectionId: conn.connectionId,
17546
+ start,
17547
+ end
17548
+ });
17549
+ }
17550
+ return xyConnections;
17551
+ };
17552
+ var predictViaRegionFromGraphPattern = (input) => {
17553
+ const area = Math.max(input.graphWidthMm * input.graphHeightMm, 0.01);
17554
+ const density = input.connectionCount / area;
17555
+ if (density <= 0.032343248633284985) {
17556
+ if (input.connectionCount <= 11.5) {
17557
+ if (input.connectionCount === 8 && input.intersectionCount >= 17 && input.graphWidthMm <= 15 && input.graphHeightMm >= 20) {
17558
+ return "via-tile-5-regions";
17559
+ }
17560
+ return "via-tile-6-regions";
17561
+ }
17562
+ return "via-tile-3-regions";
17563
+ }
17564
+ if (input.graphHeightMm <= 12.600000000000001) {
17565
+ return "via-tile-3-regions";
17566
+ }
17567
+ if (input.graphWidthMm <= 13.41) {
17568
+ return "via-tile-4-regions";
17569
+ }
17570
+ return "via-tile-5-regions";
17571
+ };
17572
+ var getViaTileBounds = (viaTile) => {
17573
+ const points = [];
17574
+ for (const vias of Object.values(viaTile.viasByNet)) {
17575
+ for (const via of vias) points.push(via.position);
17576
+ }
17577
+ for (const route of viaTile.routeSegments) {
17578
+ for (const p of route.segments) points.push(p);
17579
+ }
17580
+ if (points.length === 0) {
17581
+ return { width: 1, height: 1 };
17582
+ }
17583
+ const minX = Math.min(...points.map((p) => p.x));
17584
+ const maxX = Math.max(...points.map((p) => p.x));
17585
+ const minY = Math.min(...points.map((p) => p.y));
17586
+ const maxY = Math.max(...points.map((p) => p.y));
17587
+ return {
17588
+ width: Math.max(maxX - minX, 0.01),
17589
+ height: Math.max(maxY - minY, 0.01)
17590
+ };
17591
+ };
17592
+ var scoreViaTileForProblem = (problem, candidate) => {
17593
+ const viaCount = Object.values(candidate.viaTile.viasByNet).reduce(
17594
+ (sum, vias) => sum + vias.length,
17595
+ 0
17596
+ );
17597
+ const netCount = Object.keys(candidate.viaTile.viasByNet).length;
17598
+ const routeSegmentCount = candidate.viaTile.routeSegments.length;
17599
+ const bounds = getViaTileBounds(candidate.viaTile);
17600
+ const tileArea = Math.max(
17601
+ candidate.viaTile.tileWidth && candidate.viaTile.tileHeight ? candidate.viaTile.tileWidth * candidate.viaTile.tileHeight : bounds.width * bounds.height,
17602
+ 0.01
17603
+ );
17604
+ const graphArea = Math.max(problem.graphWidthMm * problem.graphHeightMm, 0.01);
17605
+ const crossingPerConnection = problem.intersectionCount / Math.max(problem.connectionCount, 1);
17606
+ const density = problem.connectionCount / graphArea;
17607
+ const requiredCapacityScore = problem.connectionCount * 1.2 + problem.intersectionCount * 1.5 + crossingPerConnection * 5 + density * 40;
17608
+ const capacityScore = viaCount * 3.1 + routeSegmentCount * 2.4 + netCount * 4 + 1 / tileArea * 4.5;
17609
+ const predictedReliability = clamp4(
17610
+ sigmoid((capacityScore - requiredCapacityScore) / 3.2),
17611
+ 0,
17612
+ 1
17613
+ );
17614
+ const oversupplyRatio = Math.max(
17615
+ 0,
17616
+ (capacityScore - requiredCapacityScore) / Math.max(requiredCapacityScore, 1)
17617
+ );
17618
+ const undersupplyRatio = Math.max(
17619
+ 0,
17620
+ (requiredCapacityScore - capacityScore) / Math.max(requiredCapacityScore, 1)
17621
+ );
17622
+ const estimatedIterationCost = problem.connectionCount * 120 + problem.intersectionCount * 140 + oversupplyRatio * 900 + undersupplyRatio * 6e3;
17623
+ return {
17624
+ viaRegionName: candidate.viaRegionName,
17625
+ predictedReliability,
17626
+ estimatedIterationCost,
17627
+ capacityScore,
17628
+ requiredCapacityScore,
17629
+ acceptedAsReliable: predictedReliability >= 0.9
17630
+ };
17631
+ };
17632
+ var calculateBoundsFromConnections = (xyConnections) => {
17633
+ if (xyConnections.length === 0) {
17634
+ throw new Error("Cannot calculate bounds from empty connections array");
17635
+ }
17636
+ let minX = Infinity;
17637
+ let maxX = -Infinity;
17638
+ let minY = Infinity;
17639
+ let maxY = -Infinity;
17640
+ for (const conn of xyConnections) {
17641
+ minX = Math.min(minX, conn.start.x, conn.end.x);
17642
+ maxX = Math.max(maxX, conn.start.x, conn.end.x);
17643
+ minY = Math.min(minY, conn.start.y, conn.end.y);
17644
+ maxY = Math.max(maxY, conn.start.y, conn.end.y);
17645
+ }
17646
+ return { minX, maxX, minY, maxY };
17647
+ };
17648
+ var normalizeGraphProblemInput = (input, fallbackXYConnections) => {
17649
+ const xyConnections = (input.xyConnections && input.xyConnections.length > 0 ? input.xyConnections : fallbackXYConnections).slice();
17650
+ let graphWidthMm = input.graphWidthMm;
17651
+ let graphHeightMm = input.graphHeightMm;
17652
+ let connectionCount = input.connectionCount;
17653
+ let intersectionCount = input.intersectionCount;
17654
+ if (input.sample) {
17655
+ const sampleXYConnections = extractXYConnectionsFromSample(input.sample);
17656
+ if (xyConnections.length === 0 && sampleXYConnections.length > 0) {
17657
+ xyConnections.push(...sampleXYConnections);
17658
+ }
17659
+ if (!connectionCount) {
17660
+ connectionCount = input.sample.connections?.length ?? xyConnections.length;
17661
+ }
17662
+ if (intersectionCount == null) {
17663
+ intersectionCount = input.sample.config?.numCrossings ?? (xyConnections.length > 0 ? countIntersections(xyConnections) : 0);
17664
+ }
17665
+ if (graphWidthMm == null || graphHeightMm == null) {
17666
+ const bounds = getBoundsFromSample(input.sample);
17667
+ if (bounds) {
17668
+ graphWidthMm = graphWidthMm ?? bounds.widthMm;
17669
+ graphHeightMm = graphHeightMm ?? bounds.heightMm;
17670
+ }
17671
+ }
17672
+ }
17673
+ if (xyConnections.length > 0) {
17674
+ const bounds = calculateBoundsFromConnections(xyConnections);
17675
+ graphWidthMm = graphWidthMm ?? bounds.maxX - bounds.minX;
17676
+ graphHeightMm = graphHeightMm ?? bounds.maxY - bounds.minY;
17677
+ connectionCount = connectionCount ?? xyConnections.length;
17678
+ intersectionCount = intersectionCount ?? countIntersections(xyConnections);
17679
+ }
17680
+ if (graphWidthMm == null || graphHeightMm == null || connectionCount == null || intersectionCount == null) {
17681
+ throw new Error(
17682
+ "Insufficient graph input. Provide width/height/connections/intersections, or pass xyConnections."
17683
+ );
17684
+ }
17685
+ return {
17686
+ graphWidthMm: round2(graphWidthMm),
17687
+ graphHeightMm: round2(graphHeightMm),
17688
+ connectionCount,
17689
+ intersectionCount
17690
+ };
17691
+ };
17692
+ var recommendViaTileFromGraphInput = (problemInput, fallbackXYConnections = [], viaTileCandidates = DEFAULT_VIA_TILE_CANDIDATES, _opts) => {
17693
+ if (viaTileCandidates.length === 0) {
17694
+ throw new Error("No via-tile candidates provided");
17695
+ }
17696
+ const xyConnections = problemInput.xyConnections && problemInput.xyConnections.length > 0 ? problemInput.xyConnections : fallbackXYConnections;
17697
+ const normalizedInput = normalizeGraphProblemInput(
17698
+ problemInput,
17699
+ xyConnections
17700
+ );
17701
+ const scored = viaTileCandidates.map((candidate) => scoreViaTileForProblem(normalizedInput, candidate)).sort((a, b) => {
17702
+ if (a.acceptedAsReliable !== b.acceptedAsReliable) {
17703
+ return a.acceptedAsReliable ? -1 : 1;
17704
+ }
17705
+ if (a.acceptedAsReliable && b.acceptedAsReliable) {
17706
+ if (a.estimatedIterationCost !== b.estimatedIterationCost) {
17707
+ return a.estimatedIterationCost - b.estimatedIterationCost;
17708
+ }
17709
+ } else if (a.predictedReliability !== b.predictedReliability) {
17710
+ return b.predictedReliability - a.predictedReliability;
17711
+ }
17712
+ return a.estimatedIterationCost - b.estimatedIterationCost;
17713
+ });
17714
+ const predictedViaRegionName = predictViaRegionFromGraphPattern(normalizedInput);
17715
+ if (predictedViaRegionName) {
17716
+ const predictedCandidate = scored.find(
17717
+ (candidate) => candidate.viaRegionName === predictedViaRegionName
17718
+ );
17719
+ if (predictedCandidate) {
17720
+ const reordered = [
17721
+ predictedCandidate,
17722
+ ...scored.filter(
17723
+ (candidate) => candidate.viaRegionName !== predictedViaRegionName
17724
+ )
17725
+ ];
17726
+ return {
17727
+ recommendedViaRegionName: reordered[0].viaRegionName,
17728
+ inputFeatures: normalizedInput,
17729
+ candidates: reordered
17730
+ };
17731
+ }
17732
+ }
17733
+ return {
17734
+ recommendedViaRegionName: scored[0].viaRegionName,
17735
+ inputFeatures: normalizedInput,
17736
+ candidates: scored
17737
+ };
17738
+ };
17739
+ var selectViaTileForProblemInput = (problemInput, xyConnections) => {
17740
+ const recommendation = recommendViaTileFromGraphInput(
17741
+ problemInput,
17742
+ xyConnections
17743
+ );
17744
+ const selectedCandidate = DEFAULT_VIA_TILE_CANDIDATES.find(
17745
+ (candidate) => candidate.viaRegionName === recommendation.recommendedViaRegionName
17746
+ );
17747
+ return selectedCandidate?.viaTile ?? via_tile_4_regions_default;
17748
+ };
17749
+
17750
+ // lib/ViaGraphSolver/via-graph-generator/createConvexViaGraphFromXYConnections.ts
17751
+ var isViaTile = (input) => Boolean(
17752
+ input && typeof input === "object" && "viasByNet" in input && "routeSegments" in input
17753
+ );
17754
+ function calculateBoundsFromConnections2(xyConnections) {
17755
+ if (xyConnections.length === 0) {
17756
+ throw new Error("Cannot calculate bounds from empty connections array");
17757
+ }
17758
+ let minX = Infinity;
17759
+ let maxX = -Infinity;
17760
+ let minY = Infinity;
17761
+ let maxY = -Infinity;
17762
+ for (const conn of xyConnections) {
17763
+ minX = Math.min(minX, conn.start.x, conn.end.x);
17764
+ maxX = Math.max(maxX, conn.start.x, conn.end.x);
17765
+ minY = Math.min(minY, conn.start.y, conn.end.y);
17766
+ maxY = Math.max(maxY, conn.start.y, conn.end.y);
17767
+ }
17768
+ return { minX, maxX, minY, maxY };
17769
+ }
17770
+ function createConvexViaGraphFromXYConnections(xyConnections, viaTileOrProblem, opts) {
17771
+ const selectedViaTile = isViaTile(viaTileOrProblem) ? viaTileOrProblem : selectViaTileForProblemInput(
17772
+ {
17773
+ ...viaTileOrProblem ?? {},
17774
+ xyConnections: viaTileOrProblem?.xyConnections ?? xyConnections
17775
+ },
17776
+ xyConnections
17777
+ );
17778
+ const bounds = calculateBoundsFromConnections2(xyConnections);
17779
+ const {
17780
+ regions,
17781
+ ports,
17782
+ viaTile: generatedViaTile,
17783
+ tileCount
17784
+ } = generateConvexViaTopologyRegions({
17785
+ viaTile: selectedViaTile,
16710
17786
  bounds,
16711
- tileWidth: opts?.tileWidth ?? viaTile.tileWidth,
16712
- tileHeight: opts?.tileHeight ?? viaTile.tileHeight,
17787
+ tileWidth: opts?.tileWidth ?? selectedViaTile.tileWidth,
17788
+ tileHeight: opts?.tileHeight ?? selectedViaTile.tileHeight,
16713
17789
  tileSize: opts?.tileSize,
16714
17790
  portPitch: opts?.portPitch,
16715
17791
  clearance: opts?.clearance,
@@ -16749,6 +17825,7 @@ export {
16749
17825
  generateJumperGrid,
16750
17826
  generateJumperX4Grid,
16751
17827
  generateViaTopologyRegions,
17828
+ recommendViaTileFromGraphInput,
16752
17829
  rotateGraph90Degrees,
16753
17830
  via_tile_4_regions_default as viaTile
16754
17831
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/hypergraph",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.51",
4
+ "version": "0.0.53",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",