@tscircuit/hypergraph 0.0.19 → 0.0.20
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 +12 -0
- package/dist/index.js +65 -7
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,10 @@ interface JRegion extends Region {
|
|
|
110
110
|
x: number;
|
|
111
111
|
y: number;
|
|
112
112
|
};
|
|
113
|
+
polygon?: {
|
|
114
|
+
x: number;
|
|
115
|
+
y: number;
|
|
116
|
+
}[];
|
|
113
117
|
isPad: boolean;
|
|
114
118
|
isThroughJumper?: boolean;
|
|
115
119
|
isConnectionRegion?: boolean;
|
|
@@ -458,6 +462,10 @@ type SharedBoundary = {
|
|
|
458
462
|
type RegionData = {
|
|
459
463
|
id: string;
|
|
460
464
|
bounds: Bounds | null;
|
|
465
|
+
polygon: {
|
|
466
|
+
x: number;
|
|
467
|
+
y: number;
|
|
468
|
+
}[] | null;
|
|
461
469
|
center: {
|
|
462
470
|
x: number;
|
|
463
471
|
y: number;
|
|
@@ -495,6 +503,10 @@ declare class RegionBuilder implements RegionRef {
|
|
|
495
503
|
constructor(id: string);
|
|
496
504
|
get id(): string;
|
|
497
505
|
rect(b: Bounds): this;
|
|
506
|
+
polygon(points: {
|
|
507
|
+
x: number;
|
|
508
|
+
y: number;
|
|
509
|
+
}[]): this;
|
|
498
510
|
center(x: number, y: number): this;
|
|
499
511
|
size(w: number, h: number, anchor?: "center" | "min"): this;
|
|
500
512
|
pad(isPad?: boolean): this;
|
package/dist/index.js
CHANGED
|
@@ -2117,10 +2117,11 @@ var visualizeJumperGraph = (graph, options) => {
|
|
|
2117
2117
|
points: [],
|
|
2118
2118
|
rects: [],
|
|
2119
2119
|
texts: [],
|
|
2120
|
+
polygons: [],
|
|
2120
2121
|
coordinateSystem: "cartesian"
|
|
2121
2122
|
};
|
|
2122
2123
|
for (const region of graph.regions) {
|
|
2123
|
-
const { bounds, isPad, isThroughJumper, isConnectionRegion } = region.d;
|
|
2124
|
+
const { bounds, isPad, isThroughJumper, isConnectionRegion, polygon } = region.d;
|
|
2124
2125
|
const centerX = (bounds.minX + bounds.maxX) / 2;
|
|
2125
2126
|
const centerY = (bounds.minY + bounds.maxY) / 2;
|
|
2126
2127
|
const width = bounds.maxX - bounds.minX;
|
|
@@ -2135,12 +2136,22 @@ var visualizeJumperGraph = (graph, options) => {
|
|
|
2135
2136
|
} else {
|
|
2136
2137
|
fill = "rgba(200, 200, 255, 0.1)";
|
|
2137
2138
|
}
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2139
|
+
if (polygon && polygon.length >= 3) {
|
|
2140
|
+
const points = polygon;
|
|
2141
|
+
graphics.polygons.push({
|
|
2142
|
+
points,
|
|
2143
|
+
fill,
|
|
2144
|
+
stroke: "rgba(128, 128, 128, 0.5)",
|
|
2145
|
+
strokeWidth: 0.03
|
|
2146
|
+
});
|
|
2147
|
+
} else {
|
|
2148
|
+
graphics.rects.push({
|
|
2149
|
+
center: { x: centerX, y: centerY },
|
|
2150
|
+
width: width - 0.1,
|
|
2151
|
+
height: height - 0.1,
|
|
2152
|
+
fill
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2144
2155
|
}
|
|
2145
2156
|
if (!options?.hidePortPoints) {
|
|
2146
2157
|
for (const port of graph.ports) {
|
|
@@ -2590,6 +2601,7 @@ var RegionBuilder = class {
|
|
|
2590
2601
|
this.data = {
|
|
2591
2602
|
id,
|
|
2592
2603
|
bounds: null,
|
|
2604
|
+
polygon: null,
|
|
2593
2605
|
center: null,
|
|
2594
2606
|
width: null,
|
|
2595
2607
|
height: null,
|
|
@@ -2606,6 +2618,35 @@ var RegionBuilder = class {
|
|
|
2606
2618
|
// Geometry methods
|
|
2607
2619
|
rect(b) {
|
|
2608
2620
|
this.data.bounds = { ...b };
|
|
2621
|
+
this.data.polygon = null;
|
|
2622
|
+
this.data.center = null;
|
|
2623
|
+
this.data.width = null;
|
|
2624
|
+
this.data.height = null;
|
|
2625
|
+
return this;
|
|
2626
|
+
}
|
|
2627
|
+
polygon(points) {
|
|
2628
|
+
if (points.length < 3) {
|
|
2629
|
+
throw new TopologyError(
|
|
2630
|
+
`Region "${this.data.id}" has invalid polygon: at least 3 points required`,
|
|
2631
|
+
{
|
|
2632
|
+
regionIds: [this.data.id],
|
|
2633
|
+
suggestion: "Provide at least three polygon vertices"
|
|
2634
|
+
}
|
|
2635
|
+
);
|
|
2636
|
+
}
|
|
2637
|
+
for (const point of points) {
|
|
2638
|
+
if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) {
|
|
2639
|
+
throw new TopologyError(
|
|
2640
|
+
`Region "${this.data.id}" has invalid polygon point`,
|
|
2641
|
+
{
|
|
2642
|
+
regionIds: [this.data.id],
|
|
2643
|
+
suggestion: "Use finite numeric x/y values"
|
|
2644
|
+
}
|
|
2645
|
+
);
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
this.data.polygon = points.map((p) => ({ x: p.x, y: p.y }));
|
|
2649
|
+
this.data.bounds = null;
|
|
2609
2650
|
this.data.center = null;
|
|
2610
2651
|
this.data.width = null;
|
|
2611
2652
|
this.data.height = null;
|
|
@@ -2614,6 +2655,7 @@ var RegionBuilder = class {
|
|
|
2614
2655
|
center(x, y) {
|
|
2615
2656
|
this.data.center = { x, y };
|
|
2616
2657
|
this.data.bounds = null;
|
|
2658
|
+
this.data.polygon = null;
|
|
2617
2659
|
return this;
|
|
2618
2660
|
}
|
|
2619
2661
|
size(w, h, anchor = "center") {
|
|
@@ -2630,6 +2672,7 @@ var RegionBuilder = class {
|
|
|
2630
2672
|
this.data.height = h;
|
|
2631
2673
|
this.data.anchor = anchor;
|
|
2632
2674
|
this.data.bounds = null;
|
|
2675
|
+
this.data.polygon = null;
|
|
2633
2676
|
return this;
|
|
2634
2677
|
}
|
|
2635
2678
|
// Semantic methods
|
|
@@ -2665,6 +2708,20 @@ function computeBoundsFromRegionData(data) {
|
|
|
2665
2708
|
if (data.bounds) {
|
|
2666
2709
|
return data.bounds;
|
|
2667
2710
|
}
|
|
2711
|
+
if (data.polygon && data.polygon.length > 0) {
|
|
2712
|
+
let minX = data.polygon[0].x;
|
|
2713
|
+
let maxX = data.polygon[0].x;
|
|
2714
|
+
let minY = data.polygon[0].y;
|
|
2715
|
+
let maxY = data.polygon[0].y;
|
|
2716
|
+
for (let i = 1; i < data.polygon.length; i++) {
|
|
2717
|
+
const point = data.polygon[i];
|
|
2718
|
+
minX = Math.min(minX, point.x);
|
|
2719
|
+
maxX = Math.max(maxX, point.x);
|
|
2720
|
+
minY = Math.min(minY, point.y);
|
|
2721
|
+
maxY = Math.max(maxY, point.y);
|
|
2722
|
+
}
|
|
2723
|
+
return { minX, maxX, minY, maxY };
|
|
2724
|
+
}
|
|
2668
2725
|
if (data.center && data.width !== null && data.height !== null) {
|
|
2669
2726
|
const halfW = data.width / 2;
|
|
2670
2727
|
const halfH = data.height / 2;
|
|
@@ -3277,6 +3334,7 @@ ${errors.map((e) => ` - ${e}`).join("\n")}`
|
|
|
3277
3334
|
bounds,
|
|
3278
3335
|
center,
|
|
3279
3336
|
isPad: data.isPad,
|
|
3337
|
+
...data.polygon && { polygon: data.polygon },
|
|
3280
3338
|
...data.isThroughJumper && { isThroughJumper: true },
|
|
3281
3339
|
...data.isConnectionRegion && { isConnectionRegion: true },
|
|
3282
3340
|
...data.meta
|
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.
|
|
4
|
+
"version": "0.0.20",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "cosmos",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@tscircuit/math-utils": "^0.0.29",
|
|
20
20
|
"@types/bun": "latest",
|
|
21
21
|
"bun-match-svg": "^0.0.15",
|
|
22
|
-
"graphics-debug": "^0.0.
|
|
22
|
+
"graphics-debug": "^0.0.83",
|
|
23
23
|
"react-cosmos": "^7.1.0",
|
|
24
24
|
"react-cosmos-plugin-vite": "^7.1.0",
|
|
25
25
|
"transformation-matrix": "^3.1.0",
|