@tscircuit/hypergraph 0.0.3 → 0.0.5

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
@@ -115,9 +115,17 @@ interface JPort extends RegionPort {
115
115
  type JumperGraph = {
116
116
  regions: JRegion[];
117
117
  ports: JPort[];
118
+ jumperLocations?: Array<{
119
+ center: {
120
+ x: number;
121
+ y: number;
122
+ };
123
+ orientation: "vertical" | "horizontal";
124
+ padRegions: JRegion[];
125
+ }>;
118
126
  };
119
127
 
120
- declare const generateJumperX4Grid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, regionsBetweenPads, outerPaddingX, outerPaddingY, outerChannelXPointCount, outerChannelYPointCount, orientation, center, }: {
128
+ declare const generateJumperX4Grid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, regionsBetweenPads, outerPaddingX: outerPaddingXParam, outerPaddingY: outerPaddingYParam, outerChannelXPointCount, outerChannelYPointCount, orientation, center, bounds, }: {
121
129
  cols: number;
122
130
  rows: number;
123
131
  marginX: number;
@@ -134,6 +142,12 @@ declare const generateJumperX4Grid: ({ cols, rows, marginX, marginY, innerColCha
134
142
  x: number;
135
143
  y: number;
136
144
  };
145
+ bounds?: {
146
+ minX: number;
147
+ maxX: number;
148
+ minY: number;
149
+ maxY: number;
150
+ };
137
151
  }) => JumperGraph;
138
152
 
139
153
  declare const generateJumperGrid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, outerPaddingX, outerPaddingY, outerChannelXPoints, outerChannelYPoints, }: {
package/dist/index.js CHANGED
@@ -173,9 +173,29 @@ var applyTransformToGraph = (graph, matrix) => {
173
173
  newRegion2.ports.push(newPort);
174
174
  return newPort;
175
175
  });
176
+ const transformedJumperLocations = graph.jumperLocations?.map((loc) => {
177
+ const newCenter = applyToPoint(matrix, loc.center);
178
+ const newPadRegions = loc.padRegions.map(
179
+ (region) => regionMap.get(region)
180
+ );
181
+ const unitX = applyToPoint(matrix, { x: 1, y: 0 });
182
+ const origin = applyToPoint(matrix, { x: 0, y: 0 });
183
+ const dx = unitX.x - origin.x;
184
+ const dy = unitX.y - origin.y;
185
+ const isRotated90 = Math.abs(dy) > Math.abs(dx);
186
+ const newOrientation = isRotated90 ? loc.orientation === "horizontal" ? "vertical" : "horizontal" : loc.orientation;
187
+ return {
188
+ center: newCenter,
189
+ orientation: newOrientation,
190
+ padRegions: newPadRegions
191
+ };
192
+ });
176
193
  return {
177
194
  regions: transformedRegions,
178
- ports: transformedPorts
195
+ ports: transformedPorts,
196
+ ...transformedJumperLocations && {
197
+ jumperLocations: transformedJumperLocations
198
+ }
179
199
  };
180
200
  };
181
201
  var rotateGraph90Degrees = (graph) => {
@@ -199,15 +219,14 @@ var generateJumperX4Grid = ({
199
219
  innerColChannelPointCount = 1,
200
220
  innerRowChannelPointCount = 1,
201
221
  regionsBetweenPads = false,
202
- outerPaddingX = 0.5,
203
- outerPaddingY = 0.5,
222
+ outerPaddingX: outerPaddingXParam = 0.5,
223
+ outerPaddingY: outerPaddingYParam = 0.5,
204
224
  outerChannelXPointCount,
205
225
  outerChannelYPointCount,
206
226
  orientation: orientation2 = "vertical",
207
- center
227
+ center,
228
+ bounds
208
229
  }) => {
209
- const effectiveOuterChannelXPoints = outerChannelXPointCount ?? Math.max(1, Math.floor(outerPaddingX / 0.4));
210
- const effectiveOuterChannelYPoints = outerChannelYPointCount ?? Math.max(1, Math.floor(outerPaddingY / 0.4));
211
230
  const regions = [];
212
231
  const ports = [];
213
232
  const {
@@ -226,11 +245,24 @@ var generateJumperX4Grid = ({
226
245
  const horizontalSpacing = cellWidth + marginX;
227
246
  const cellHeight = row1CenterY - row4CenterY + padHeight;
228
247
  const verticalSpacing = cellHeight + marginY;
248
+ let outerPaddingX = outerPaddingXParam;
249
+ let outerPaddingY = outerPaddingYParam;
250
+ if (bounds) {
251
+ const contentWidth = cols * cellWidth + (cols - 1) * marginX;
252
+ const contentHeight = rows * cellHeight + (rows - 1) * marginY;
253
+ const boundsWidth = orientation2 === "horizontal" ? bounds.maxY - bounds.minY : bounds.maxX - bounds.minX;
254
+ const boundsHeight = orientation2 === "horizontal" ? bounds.maxX - bounds.minX : bounds.maxY - bounds.minY;
255
+ outerPaddingX = (boundsWidth - contentWidth) / 2;
256
+ outerPaddingY = (boundsHeight - contentHeight) / 2;
257
+ }
258
+ const effectiveOuterChannelXPoints = outerChannelXPointCount ?? Math.max(1, Math.floor(outerPaddingX / 0.4));
259
+ const effectiveOuterChannelYPoints = outerChannelYPointCount ?? Math.max(1, Math.floor(outerPaddingY / 0.4));
229
260
  const cells = [];
230
- const createRegion = (id, bounds, isPad, isThroughJumper) => ({
261
+ const collectedJumperLocations = [];
262
+ const createRegion = (id, bounds2, isPad, isThroughJumper) => ({
231
263
  regionId: id,
232
264
  ports: [],
233
- d: { bounds, center: computeBoundsCenter(bounds), isPad, isThroughJumper }
265
+ d: { bounds: bounds2, center: computeBoundsCenter(bounds2), isPad, isThroughJumper }
234
266
  });
235
267
  const createPort = (id, region1, region2) => {
236
268
  const b1 = region1.d.bounds;
@@ -433,6 +465,13 @@ var generateJumperX4Grid = ({
433
465
  throughjumper3,
434
466
  throughjumper4
435
467
  );
468
+ const jumperCenterX = (p1CenterX + p8CenterX) / 2;
469
+ const jumperCenterY = (p1CenterY + p4CenterY) / 2;
470
+ collectedJumperLocations.push({
471
+ center: { x: jumperCenterX, y: jumperCenterY },
472
+ orientation: "vertical",
473
+ padRegions: [pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8]
474
+ });
436
475
  let leftBP12 = null;
437
476
  let leftBP23 = null;
438
477
  let leftBP34 = null;
@@ -837,7 +876,7 @@ var generateJumperX4Grid = ({
837
876
  `cell_${row}_${col - 1}->cell_${row}_${col}:T-T`,
838
877
  prevCell.top,
839
878
  top,
840
- innerRowChannelPointCount
879
+ effectiveOuterChannelYPoints
841
880
  )
842
881
  );
843
882
  }
@@ -847,7 +886,7 @@ var generateJumperX4Grid = ({
847
886
  `cell_${row}_${col - 1}->cell_${row}_${col}:B-B`,
848
887
  prevCell.bottom,
849
888
  bottom,
850
- innerRowChannelPointCount
889
+ isLastRow ? effectiveOuterChannelYPoints : innerRowChannelPointCount
851
890
  )
852
891
  );
853
892
  }
@@ -914,19 +953,31 @@ var generateJumperX4Grid = ({
914
953
  }
915
954
  }
916
955
  }
917
- let graph = { regions, ports };
956
+ let graph = {
957
+ regions,
958
+ ports,
959
+ jumperLocations: collectedJumperLocations
960
+ };
918
961
  const needsRotation = orientation2 === "horizontal";
919
962
  const needsCentering = center !== void 0;
920
- if (needsRotation || needsCentering) {
963
+ const needsBoundsTransform = bounds !== void 0;
964
+ if (needsRotation || needsCentering || needsBoundsTransform) {
921
965
  const currentBounds = calculateGraphBounds(graph.regions);
922
966
  const currentCenter = computeBoundsCenter(currentBounds);
923
967
  const matrices = [];
924
- matrices.push(translate(-currentCenter.x, -currentCenter.y));
968
+ let targetCenter;
969
+ if (center) {
970
+ targetCenter = center;
971
+ } else if (bounds) {
972
+ targetCenter = computeBoundsCenter(bounds);
973
+ } else {
974
+ targetCenter = currentCenter;
975
+ }
976
+ matrices.push(translate(targetCenter.x, targetCenter.y));
925
977
  if (needsRotation) {
926
978
  matrices.push(rotate(-Math.PI / 2));
927
979
  }
928
- const targetCenter = center ?? currentCenter;
929
- matrices.push(translate(targetCenter.x, targetCenter.y));
980
+ matrices.push(translate(-currentCenter.x, -currentCenter.y));
930
981
  const matrix = compose(...matrices);
931
982
  graph = applyTransformToGraph(graph, matrix);
932
983
  }
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@tscircuit/hypergraph",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",
8
+ "format": "biome format --write .",
9
+ "format:check": "biome format .",
8
10
  "build:site": "cosmos-export",
9
11
  "build": "tsup ./lib/index.ts --dts --format esm"
10
12
  },