@tscircuit/hypergraph 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.
package/dist/index.d.ts CHANGED
@@ -63,13 +63,16 @@ type HyperGraph = {
63
63
  ports: RegionPort[];
64
64
  regions: Region[];
65
65
  };
66
- type SerializedGraphPort = Omit<RegionPort, "edges"> & {
66
+ type SerializedGraphPort = {
67
67
  portId: PortId;
68
68
  region1Id: RegionId;
69
69
  region2Id: RegionId;
70
+ d: any;
70
71
  };
71
- type SerializedGraphRegion = Omit<Region, "points" | "assignments"> & {
72
+ type SerializedGraphRegion = {
73
+ regionId: RegionId;
72
74
  pointIds: PortId[];
75
+ d: any;
73
76
  assignments?: SerializedRegionPortAssignment[];
74
77
  };
75
78
  type SerializedRegionPortAssignment = {
@@ -295,11 +298,11 @@ declare class HyperGraphSolver<RegionType extends Region = Region, RegionPortTyp
295
298
  ripCost?: number;
296
299
  });
297
300
  getConstructorParams(): {
298
- inputGraph: HyperGraph | SerializedHyperGraph;
299
- inputConnections: (Connection | SerializedConnection)[];
300
- greedyMultiplier?: number;
301
- rippingEnabled?: boolean;
302
- ripCost?: number;
301
+ inputGraph: SerializedHyperGraph;
302
+ inputConnections: SerializedConnection[];
303
+ greedyMultiplier: number;
304
+ rippingEnabled: boolean;
305
+ ripCost: number;
303
306
  };
304
307
  computeH(candidate: CandidateType): number;
305
308
  /**
@@ -405,6 +408,10 @@ declare class JumperGraphSolver extends HyperGraphSolver<JRegion, JPort> {
405
408
  visualize(): GraphicsObject;
406
409
  }
407
410
 
411
+ declare const convertHyperGraphToSerializedHyperGraph: (graph: HyperGraph) => SerializedHyperGraph;
412
+
413
+ declare const convertConnectionsToSerializedConnections: (connections: Connection[]) => SerializedConnection[];
414
+
408
415
  /**
409
416
  * Applies a transformation matrix to all points in a graph.
410
417
  * Transforms region bounds, region centers, and port positions.
@@ -417,4 +424,4 @@ declare const rotateGraph90Degrees: (graph: JumperGraph) => JumperGraph;
417
424
 
418
425
  declare const calculateGraphBounds: (regions: JRegion[]) => Bounds;
419
426
 
420
- export { type Candidate, 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, type PortId, type Region, type RegionId, type RegionPort, type RegionPortAssignment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SolvedRoute, type XYConnection, applyTransformToGraph, calculateGraphBounds, createGraphWithConnectionsFromBaseGraph, generateJumperGrid, generateJumperX4Grid, rotateGraph90Degrees };
427
+ export { type Candidate, 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, type PortId, type Region, type RegionId, type RegionPort, type RegionPortAssignment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SolvedRoute, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createGraphWithConnectionsFromBaseGraph, generateJumperGrid, generateJumperX4Grid, rotateGraph90Degrees };
package/dist/index.js CHANGED
@@ -1562,6 +1562,36 @@ var convertSerializedHyperGraphToHyperGraph = (inputGraph) => {
1562
1562
  };
1563
1563
  };
1564
1564
 
1565
+ // lib/convertHyperGraphToSerializedHyperGraph.ts
1566
+ var convertHyperGraphToSerializedHyperGraph = (graph) => {
1567
+ const serializedPorts = graph.ports.map((port) => ({
1568
+ portId: port.portId,
1569
+ region1Id: port.region1.regionId,
1570
+ region2Id: port.region2.regionId,
1571
+ d: port.d
1572
+ }));
1573
+ const serializedRegions = graph.regions.map(
1574
+ (region) => ({
1575
+ regionId: region.regionId,
1576
+ pointIds: region.ports.map((port) => port.portId),
1577
+ d: region.d
1578
+ })
1579
+ );
1580
+ return {
1581
+ ports: serializedPorts,
1582
+ regions: serializedRegions
1583
+ };
1584
+ };
1585
+
1586
+ // lib/convertConnectionsToSerializedConnections.ts
1587
+ var convertConnectionsToSerializedConnections = (connections) => {
1588
+ return connections.map((conn) => ({
1589
+ connectionId: conn.connectionId,
1590
+ startRegionId: conn.startRegion.regionId,
1591
+ endRegionId: conn.endRegion.regionId
1592
+ }));
1593
+ };
1594
+
1565
1595
  // lib/convertSerializedConnectionsToConnections.ts
1566
1596
  var convertSerializedConnectionsToConnections = (inputConnections, graph) => {
1567
1597
  const connections = [];
@@ -1768,7 +1798,15 @@ var HyperGraphSolver = class extends BaseSolver {
1768
1798
  lastCandidate = null;
1769
1799
  visitedPointsForCurrentConnection = /* @__PURE__ */ new Map();
1770
1800
  getConstructorParams() {
1771
- return this.input;
1801
+ return {
1802
+ inputGraph: convertHyperGraphToSerializedHyperGraph(this.graph),
1803
+ inputConnections: convertConnectionsToSerializedConnections(
1804
+ this.connections
1805
+ ),
1806
+ greedyMultiplier: this.greedyMultiplier,
1807
+ rippingEnabled: this.rippingEnabled,
1808
+ ripCost: this.ripCost
1809
+ };
1772
1810
  }
1773
1811
  computeH(candidate) {
1774
1812
  return this.estimateCostToEnd(candidate.port);
@@ -2423,6 +2461,8 @@ export {
2423
2461
  JumperGraphSolver,
2424
2462
  applyTransformToGraph,
2425
2463
  calculateGraphBounds,
2464
+ convertConnectionsToSerializedConnections,
2465
+ convertHyperGraphToSerializedHyperGraph,
2426
2466
  createGraphWithConnectionsFromBaseGraph,
2427
2467
  generateJumperGrid,
2428
2468
  generateJumperX4Grid,
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.12",
4
+ "version": "0.0.13",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",