@tscircuit/hypergraph 0.0.4 → 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 +8 -0
- package/dist/index.js +40 -8
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -115,6 +115,14 @@ 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
128
|
declare const generateJumperX4Grid: ({ cols, rows, marginX, marginY, innerColChannelPointCount, innerRowChannelPointCount, regionsBetweenPads, outerPaddingX: outerPaddingXParam, outerPaddingY: outerPaddingYParam, outerChannelXPointCount, outerChannelYPointCount, orientation, center, bounds, }: {
|
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) => {
|
|
@@ -230,14 +250,15 @@ var generateJumperX4Grid = ({
|
|
|
230
250
|
if (bounds) {
|
|
231
251
|
const contentWidth = cols * cellWidth + (cols - 1) * marginX;
|
|
232
252
|
const contentHeight = rows * cellHeight + (rows - 1) * marginY;
|
|
233
|
-
const boundsWidth = bounds.maxX - bounds.minX;
|
|
234
|
-
const boundsHeight = bounds.maxY - bounds.minY;
|
|
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;
|
|
235
255
|
outerPaddingX = (boundsWidth - contentWidth) / 2;
|
|
236
256
|
outerPaddingY = (boundsHeight - contentHeight) / 2;
|
|
237
257
|
}
|
|
238
258
|
const effectiveOuterChannelXPoints = outerChannelXPointCount ?? Math.max(1, Math.floor(outerPaddingX / 0.4));
|
|
239
259
|
const effectiveOuterChannelYPoints = outerChannelYPointCount ?? Math.max(1, Math.floor(outerPaddingY / 0.4));
|
|
240
260
|
const cells = [];
|
|
261
|
+
const collectedJumperLocations = [];
|
|
241
262
|
const createRegion = (id, bounds2, isPad, isThroughJumper) => ({
|
|
242
263
|
regionId: id,
|
|
243
264
|
ports: [],
|
|
@@ -444,6 +465,13 @@ var generateJumperX4Grid = ({
|
|
|
444
465
|
throughjumper3,
|
|
445
466
|
throughjumper4
|
|
446
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
|
+
});
|
|
447
475
|
let leftBP12 = null;
|
|
448
476
|
let leftBP23 = null;
|
|
449
477
|
let leftBP34 = null;
|
|
@@ -925,7 +953,11 @@ var generateJumperX4Grid = ({
|
|
|
925
953
|
}
|
|
926
954
|
}
|
|
927
955
|
}
|
|
928
|
-
let graph = {
|
|
956
|
+
let graph = {
|
|
957
|
+
regions,
|
|
958
|
+
ports,
|
|
959
|
+
jumperLocations: collectedJumperLocations
|
|
960
|
+
};
|
|
929
961
|
const needsRotation = orientation2 === "horizontal";
|
|
930
962
|
const needsCentering = center !== void 0;
|
|
931
963
|
const needsBoundsTransform = bounds !== void 0;
|
|
@@ -933,10 +965,6 @@ var generateJumperX4Grid = ({
|
|
|
933
965
|
const currentBounds = calculateGraphBounds(graph.regions);
|
|
934
966
|
const currentCenter = computeBoundsCenter(currentBounds);
|
|
935
967
|
const matrices = [];
|
|
936
|
-
matrices.push(translate(-currentCenter.x, -currentCenter.y));
|
|
937
|
-
if (needsRotation) {
|
|
938
|
-
matrices.push(rotate(-Math.PI / 2));
|
|
939
|
-
}
|
|
940
968
|
let targetCenter;
|
|
941
969
|
if (center) {
|
|
942
970
|
targetCenter = center;
|
|
@@ -946,6 +974,10 @@ var generateJumperX4Grid = ({
|
|
|
946
974
|
targetCenter = currentCenter;
|
|
947
975
|
}
|
|
948
976
|
matrices.push(translate(targetCenter.x, targetCenter.y));
|
|
977
|
+
if (needsRotation) {
|
|
978
|
+
matrices.push(rotate(-Math.PI / 2));
|
|
979
|
+
}
|
|
980
|
+
matrices.push(translate(-currentCenter.x, -currentCenter.y));
|
|
949
981
|
const matrix = compose(...matrices);
|
|
950
982
|
graph = applyTransformToGraph(graph, matrix);
|
|
951
983
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/hypergraph",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "cosmos",
|
|
8
8
|
"format": "biome format --write .",
|
|
9
|
+
"format:check": "biome format .",
|
|
9
10
|
"build:site": "cosmos-export",
|
|
10
11
|
"build": "tsup ./lib/index.ts --dts --format esm"
|
|
11
12
|
},
|