@tscircuit/core 0.0.1293 → 0.0.1294
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.js +122 -39
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18444,15 +18444,40 @@ function applyNetLabelPlacements(args) {
|
|
|
18444
18444
|
} = args;
|
|
18445
18445
|
const { db } = group.root;
|
|
18446
18446
|
const netLabelPlacements = solver.netLabelTraceCollisionSolver?.getOutput().netLabelPlacements ?? solver.netLabelPlacementSolver?.netLabelPlacements ?? solver.traceLabelOverlapAvoidanceSolver?.getOutput().netLabelPlacements ?? [];
|
|
18447
|
-
const
|
|
18447
|
+
const dedupedNetLabelPlacements = [];
|
|
18448
|
+
const netLabelPlacementKeys = /* @__PURE__ */ new Set();
|
|
18448
18449
|
for (const placement of netLabelPlacements) {
|
|
18450
|
+
const pinIds = [...placement.pinIds ?? []].sort();
|
|
18451
|
+
const key = `${placement.globalConnNetId}|${pinIds.join("::")}|${placement.netId ?? ""}`;
|
|
18452
|
+
if (netLabelPlacementKeys.has(key)) {
|
|
18453
|
+
debug9(
|
|
18454
|
+
`skipping duplicate placement for "${placement.netId}" REASON:identical net label placement`
|
|
18455
|
+
);
|
|
18456
|
+
continue;
|
|
18457
|
+
}
|
|
18458
|
+
netLabelPlacementKeys.add(key);
|
|
18459
|
+
dedupedNetLabelPlacements.push(placement);
|
|
18460
|
+
}
|
|
18461
|
+
const netLabelPlacementCountByGlobalNetId = /* @__PURE__ */ new Map();
|
|
18462
|
+
const routedPairKeysByGlobalNetId = /* @__PURE__ */ new Map();
|
|
18463
|
+
const globalNetIdsWithPortOnlyPlacements = /* @__PURE__ */ new Set();
|
|
18464
|
+
for (const placement of dedupedNetLabelPlacements) {
|
|
18449
18465
|
netLabelPlacementCountByGlobalNetId.set(
|
|
18450
18466
|
placement.globalConnNetId,
|
|
18451
18467
|
(netLabelPlacementCountByGlobalNetId.get(placement.globalConnNetId) ?? 0) + 1
|
|
18452
18468
|
);
|
|
18469
|
+
if ((placement.pinIds?.length ?? 0) > 1) {
|
|
18470
|
+
if (!routedPairKeysByGlobalNetId.has(placement.globalConnNetId)) {
|
|
18471
|
+
routedPairKeysByGlobalNetId.set(placement.globalConnNetId, /* @__PURE__ */ new Set());
|
|
18472
|
+
}
|
|
18473
|
+
routedPairKeysByGlobalNetId.get(placement.globalConnNetId).add(placement.pinIds.slice().sort().join("::"));
|
|
18474
|
+
}
|
|
18475
|
+
if ((placement.pinIds?.length ?? 0) <= 1) {
|
|
18476
|
+
globalNetIdsWithPortOnlyPlacements.add(placement.globalConnNetId);
|
|
18477
|
+
}
|
|
18453
18478
|
}
|
|
18454
18479
|
const globalConnMap = solver.mspConnectionPairSolver.globalConnMap;
|
|
18455
|
-
for (const placement of
|
|
18480
|
+
for (const placement of dedupedNetLabelPlacements) {
|
|
18456
18481
|
debug9(`processing placement: ${placement.netId}`);
|
|
18457
18482
|
const placementUserNetId = globalConnMap.getIdsConnectedToNet(placement.globalConnNetId).find((id) => userNetIdToConnKey.get(id));
|
|
18458
18483
|
const placementConnKey = userNetIdToConnKey.get(placementUserNetId);
|
|
@@ -18508,7 +18533,9 @@ function applyNetLabelPlacements(args) {
|
|
|
18508
18533
|
}
|
|
18509
18534
|
const ports = group.selectAll("port").filter((p) => p._getSubcircuitConnectivityKey() === placementConnKey);
|
|
18510
18535
|
const { name: text, wasAssignedDisplayLabel } = getNetNameFromPorts(ports);
|
|
18511
|
-
|
|
18536
|
+
const isRoutedPairPlacement = (placement.pinIds?.length ?? 0) > 1;
|
|
18537
|
+
const shouldKeepRoutedPairLabel = isRoutedPairPlacement && (globalNetIdsWithPortOnlyPlacements.has(placement.globalConnNetId) || (routedPairKeysByGlobalNetId.get(placement.globalConnNetId)?.size ?? 0) > 1);
|
|
18538
|
+
if (!wasAssignedDisplayLabel && !shouldKeepRoutedPairLabel && schPortIds.some(
|
|
18512
18539
|
(schPortId) => schematicPortIdsWithRoutedTraces.has(schPortId)
|
|
18513
18540
|
)) {
|
|
18514
18541
|
debug9(
|
|
@@ -18535,6 +18562,26 @@ function applyNetLabelPlacements(args) {
|
|
|
18535
18562
|
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/insertNetLabelsForPortsMissingTrace.ts
|
|
18536
18563
|
var NEAR_EXISTING_NET_LABEL_DISTANCE = 0.5;
|
|
18537
18564
|
var SAME_ANCHOR_POSITION_DISTANCE = 0.1;
|
|
18565
|
+
var doesSchematicNetLabelRepresentCurrentSourceConnection = (args) => {
|
|
18566
|
+
const { nl, connKey, sourceNet, text } = args;
|
|
18567
|
+
if (sourceNet?.source_net_id && nl.source_net_id) {
|
|
18568
|
+
return nl.source_net_id === sourceNet.source_net_id;
|
|
18569
|
+
}
|
|
18570
|
+
if (nl.source_net_id) {
|
|
18571
|
+
return nl.source_net_id === connKey;
|
|
18572
|
+
}
|
|
18573
|
+
return nl.text === text;
|
|
18574
|
+
};
|
|
18575
|
+
var getSourcePortNetLabelText = (db, sourcePortId) => {
|
|
18576
|
+
const sourcePort = db.source_port.get(sourcePortId);
|
|
18577
|
+
if (!sourcePort) return void 0;
|
|
18578
|
+
let sourceComponent;
|
|
18579
|
+
if (sourcePort.source_component_id) {
|
|
18580
|
+
sourceComponent = db.source_component.get(sourcePort.source_component_id);
|
|
18581
|
+
}
|
|
18582
|
+
if (!sourceComponent?.name || !sourcePort.name) return void 0;
|
|
18583
|
+
return `${sourceComponent.name}_${sourcePort.name}`;
|
|
18584
|
+
};
|
|
18538
18585
|
var insertNetLabelsForPortsMissingTrace = ({
|
|
18539
18586
|
allSourceAndSchematicPortIdsInScope,
|
|
18540
18587
|
group,
|
|
@@ -18554,10 +18601,14 @@ var insertNetLabelsForPortsMissingTrace = ({
|
|
|
18554
18601
|
const connKey = sourcePort?.subcircuit_connectivity_map_key;
|
|
18555
18602
|
if (!connKey) continue;
|
|
18556
18603
|
const sourceNet = connKeyToSourceNet.get(connKey);
|
|
18557
|
-
|
|
18558
|
-
|
|
18559
|
-
|
|
18560
|
-
|
|
18604
|
+
const connectedSourcePortIdsForKey = Array.from(
|
|
18605
|
+
allSourceAndSchematicPortIdsInScope
|
|
18606
|
+
).map((portId) => schPortIdToSourcePortId.get(portId)).filter((sourcePortId) => {
|
|
18607
|
+
if (!sourcePortId) return false;
|
|
18608
|
+
return db.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key === connKey;
|
|
18609
|
+
});
|
|
18610
|
+
const implicitPortLabelText = connectedSourcePortIdsForKey.map((sourcePortId) => getSourcePortNetLabelText(db, sourcePortId)).filter((label) => Boolean(label)).join("/");
|
|
18611
|
+
const text = sourceNet?.name || sourceNet?.source_net_id || implicitPortLabelText || connKey;
|
|
18561
18612
|
const connectedPortCountForKey = Array.from(
|
|
18562
18613
|
allSourceAndSchematicPortIdsInScope
|
|
18563
18614
|
).filter((portId) => {
|
|
@@ -18565,13 +18616,12 @@ var insertNetLabelsForPortsMissingTrace = ({
|
|
|
18565
18616
|
if (!sourcePortId) return false;
|
|
18566
18617
|
return db.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key === connKey;
|
|
18567
18618
|
}).length;
|
|
18568
|
-
const isGndNet = sourceNet
|
|
18569
|
-
const isPowerNet = !isGndNet && sourceNet
|
|
18570
|
-
const usePowerSymbolSide = connectedPortCountForKey > 1;
|
|
18619
|
+
const isGndNet = sourceNet?.is_ground ?? false;
|
|
18620
|
+
const isPowerNet = !isGndNet && (sourceNet?.is_power ?? false);
|
|
18571
18621
|
let side;
|
|
18572
|
-
if (
|
|
18622
|
+
if (isGndNet) {
|
|
18573
18623
|
side = "top";
|
|
18574
|
-
} else if (
|
|
18624
|
+
} else if (isPowerNet) {
|
|
18575
18625
|
side = "bottom";
|
|
18576
18626
|
} else {
|
|
18577
18627
|
side = getEnteringEdgeFromDirection(
|
|
@@ -18583,32 +18633,40 @@ var insertNetLabelsForPortsMissingTrace = ({
|
|
|
18583
18633
|
anchor_side: side,
|
|
18584
18634
|
text
|
|
18585
18635
|
});
|
|
18586
|
-
const
|
|
18587
|
-
|
|
18588
|
-
|
|
18589
|
-
|
|
18590
|
-
|
|
18591
|
-
|
|
18592
|
-
if (sameNetLabel && connectedPortCountForKey <= 1) {
|
|
18593
|
-
db.schematic_net_label.update(sameNetLabel.schematic_net_label_id, {
|
|
18594
|
-
text,
|
|
18595
|
-
anchor_position: schPort.center,
|
|
18596
|
-
center,
|
|
18597
|
-
anchor_side: side
|
|
18636
|
+
const existingNetLabelForCurrentSourceConnection = db.schematic_net_label.list().find((nl) => {
|
|
18637
|
+
return doesSchematicNetLabelRepresentCurrentSourceConnection({
|
|
18638
|
+
nl,
|
|
18639
|
+
connKey,
|
|
18640
|
+
sourceNet,
|
|
18641
|
+
text
|
|
18598
18642
|
});
|
|
18599
|
-
|
|
18600
|
-
|
|
18601
|
-
|
|
18602
|
-
|
|
18603
|
-
|
|
18604
|
-
const labelIsNearPort = dx * dx + dy * dy < NEAR_EXISTING_NET_LABEL_DISTANCE * NEAR_EXISTING_NET_LABEL_DISTANCE;
|
|
18605
|
-
if (labelIsNearPort && sourceNet.is_ground) {
|
|
18606
|
-
db.schematic_net_label.update(sameNetLabel.schematic_net_label_id, {
|
|
18643
|
+
});
|
|
18644
|
+
if (existingNetLabelForCurrentSourceConnection && connectedPortCountForKey <= 1) {
|
|
18645
|
+
db.schematic_net_label.update(
|
|
18646
|
+
existingNetLabelForCurrentSourceConnection.schematic_net_label_id,
|
|
18647
|
+
{
|
|
18607
18648
|
text,
|
|
18608
18649
|
anchor_position: schPort.center,
|
|
18609
18650
|
center,
|
|
18610
18651
|
anchor_side: side
|
|
18611
|
-
}
|
|
18652
|
+
}
|
|
18653
|
+
);
|
|
18654
|
+
continue;
|
|
18655
|
+
}
|
|
18656
|
+
if (existingNetLabelForCurrentSourceConnection) {
|
|
18657
|
+
const dx = existingNetLabelForCurrentSourceConnection.anchor_position.x - schPort.center.x;
|
|
18658
|
+
const dy = existingNetLabelForCurrentSourceConnection.anchor_position.y - schPort.center.y;
|
|
18659
|
+
const labelIsNearPort = dx * dx + dy * dy < NEAR_EXISTING_NET_LABEL_DISTANCE * NEAR_EXISTING_NET_LABEL_DISTANCE;
|
|
18660
|
+
if (labelIsNearPort && isGndNet) {
|
|
18661
|
+
db.schematic_net_label.update(
|
|
18662
|
+
existingNetLabelForCurrentSourceConnection.schematic_net_label_id,
|
|
18663
|
+
{
|
|
18664
|
+
text,
|
|
18665
|
+
anchor_position: schPort.center,
|
|
18666
|
+
center,
|
|
18667
|
+
anchor_side: side
|
|
18668
|
+
}
|
|
18669
|
+
);
|
|
18612
18670
|
continue;
|
|
18613
18671
|
}
|
|
18614
18672
|
const existingAtPort = db.schematic_net_label.list().some((nl) => {
|
|
@@ -18617,16 +18675,41 @@ var insertNetLabelsForPortsMissingTrace = ({
|
|
|
18617
18675
|
if (dx2 * dx2 + dy2 * dy2 >= SAME_ANCHOR_POSITION_DISTANCE * SAME_ANCHOR_POSITION_DISTANCE) {
|
|
18618
18676
|
return false;
|
|
18619
18677
|
}
|
|
18620
|
-
|
|
18621
|
-
|
|
18622
|
-
|
|
18623
|
-
|
|
18678
|
+
return doesSchematicNetLabelRepresentCurrentSourceConnection({
|
|
18679
|
+
nl,
|
|
18680
|
+
connKey,
|
|
18681
|
+
sourceNet,
|
|
18682
|
+
text
|
|
18683
|
+
});
|
|
18624
18684
|
});
|
|
18625
18685
|
if (existingAtPort) continue;
|
|
18626
18686
|
}
|
|
18687
|
+
if (!sourceNet) {
|
|
18688
|
+
for (const nl of db.schematic_net_label.list()) {
|
|
18689
|
+
if (nl.source_net_id !== connKey) continue;
|
|
18690
|
+
const isAttachedToConnectedPort = connectedSourcePortIdsForKey.some(
|
|
18691
|
+
(sourcePortId) => {
|
|
18692
|
+
const schPortId = Array.from(
|
|
18693
|
+
schPortIdToSourcePortId.entries()
|
|
18694
|
+
).find(([, id]) => id === sourcePortId)?.[0];
|
|
18695
|
+
let connectedSchPort;
|
|
18696
|
+
if (schPortId) {
|
|
18697
|
+
connectedSchPort = db.schematic_port.get(schPortId);
|
|
18698
|
+
}
|
|
18699
|
+
if (!connectedSchPort?.center || !nl.anchor_position) return false;
|
|
18700
|
+
const dx = nl.anchor_position.x - connectedSchPort.center.x;
|
|
18701
|
+
const dy = nl.anchor_position.y - connectedSchPort.center.y;
|
|
18702
|
+
return dx * dx + dy * dy < SAME_ANCHOR_POSITION_DISTANCE * SAME_ANCHOR_POSITION_DISTANCE;
|
|
18703
|
+
}
|
|
18704
|
+
);
|
|
18705
|
+
if (!isAttachedToConnectedPort) {
|
|
18706
|
+
db.schematic_net_label.delete(nl.schematic_net_label_id);
|
|
18707
|
+
}
|
|
18708
|
+
}
|
|
18709
|
+
}
|
|
18627
18710
|
const netLabel = {
|
|
18628
18711
|
text,
|
|
18629
|
-
source_net_id: sourceNet
|
|
18712
|
+
source_net_id: sourceNet?.source_net_id ?? connKey,
|
|
18630
18713
|
anchor_position: schPort.center,
|
|
18631
18714
|
center,
|
|
18632
18715
|
anchor_side: side
|
|
@@ -22265,7 +22348,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
22265
22348
|
var package_default = {
|
|
22266
22349
|
name: "@tscircuit/core",
|
|
22267
22350
|
type: "module",
|
|
22268
|
-
version: "0.0.
|
|
22351
|
+
version: "0.0.1293",
|
|
22269
22352
|
types: "dist/index.d.ts",
|
|
22270
22353
|
main: "dist/index.js",
|
|
22271
22354
|
module: "dist/index.js",
|