@tscircuit/core 0.0.157 → 0.0.159
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 +0 -1
- package/dist/index.js +131 -23
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3427,14 +3427,48 @@ import "@tscircuit/math-utils";
|
|
|
3427
3427
|
|
|
3428
3428
|
// lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
|
|
3429
3429
|
import { doesLineIntersectLine } from "@tscircuit/math-utils";
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3430
|
+
|
|
3431
|
+
// lib/components/primitive-components/Trace/get-other-schematic-traces.ts
|
|
3432
|
+
var getOtherSchematicTraces = ({
|
|
3433
|
+
db,
|
|
3434
|
+
source_trace_id,
|
|
3435
|
+
sameNetOnly,
|
|
3436
|
+
differentNetOnly
|
|
3433
3437
|
}) => {
|
|
3434
|
-
|
|
3438
|
+
if (!sameNetOnly && !differentNetOnly) {
|
|
3439
|
+
differentNetOnly = true;
|
|
3440
|
+
}
|
|
3441
|
+
const mySourceTrace = db.source_trace.get(source_trace_id);
|
|
3442
|
+
const traces = [];
|
|
3435
3443
|
for (const otherSchematicTrace of db.schematic_trace.list()) {
|
|
3436
|
-
|
|
3444
|
+
if (otherSchematicTrace.source_trace_id === source_trace_id) continue;
|
|
3445
|
+
const otherSourceTrace = db.source_trace.get(
|
|
3446
|
+
otherSchematicTrace.source_trace_id
|
|
3447
|
+
);
|
|
3448
|
+
const isSameNet = otherSourceTrace?.subcircuit_connectivity_map_key === mySourceTrace.subcircuit_connectivity_map_key;
|
|
3449
|
+
if (differentNetOnly && isSameNet) {
|
|
3450
|
+
continue;
|
|
3451
|
+
}
|
|
3452
|
+
if (sameNetOnly && !isSameNet) {
|
|
3453
|
+
continue;
|
|
3454
|
+
}
|
|
3455
|
+
traces.push(otherSchematicTrace);
|
|
3437
3456
|
}
|
|
3457
|
+
return traces;
|
|
3458
|
+
};
|
|
3459
|
+
|
|
3460
|
+
// lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
|
|
3461
|
+
var pushEdgesOfSchematicTraceToPreventOverlap = ({
|
|
3462
|
+
edges,
|
|
3463
|
+
db,
|
|
3464
|
+
source_trace_id
|
|
3465
|
+
}) => {
|
|
3466
|
+
const mySourceTrace = db.source_trace.get(source_trace_id);
|
|
3467
|
+
const otherEdges = getOtherSchematicTraces({
|
|
3468
|
+
db,
|
|
3469
|
+
source_trace_id,
|
|
3470
|
+
differentNetOnly: true
|
|
3471
|
+
}).flatMap((t) => t.edges);
|
|
3438
3472
|
const edgeOrientation = (edge) => {
|
|
3439
3473
|
const { from, to } = edge;
|
|
3440
3474
|
return from.x === to.x ? "vertical" : "horizontal";
|
|
@@ -3468,12 +3502,14 @@ var pushEdgesOfSchematicTraceToPreventOverlap = ({
|
|
|
3468
3502
|
import { doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
|
|
3469
3503
|
var createSchematicTraceCrossingSegments = ({
|
|
3470
3504
|
edges,
|
|
3471
|
-
db
|
|
3505
|
+
db,
|
|
3506
|
+
source_trace_id
|
|
3472
3507
|
}) => {
|
|
3473
|
-
const otherEdges =
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3508
|
+
const otherEdges = getOtherSchematicTraces({
|
|
3509
|
+
db,
|
|
3510
|
+
source_trace_id,
|
|
3511
|
+
differentNetOnly: true
|
|
3512
|
+
}).flatMap((t) => t.edges);
|
|
3477
3513
|
for (let i = 0; i < edges.length; i++) {
|
|
3478
3514
|
const edge = edges[i];
|
|
3479
3515
|
const edgeOrientation = edge.from.x === edge.to.x ? "vertical" : "horizontal";
|
|
@@ -3510,6 +3546,63 @@ var createSchematicTraceCrossingSegments = ({
|
|
|
3510
3546
|
}
|
|
3511
3547
|
};
|
|
3512
3548
|
|
|
3549
|
+
// lib/components/primitive-components/Trace/create-schematic-trace-junctions.ts
|
|
3550
|
+
var isOrthogonal = (edge1, edge2) => {
|
|
3551
|
+
const isVertical1 = edge1.from.x === edge1.to.x;
|
|
3552
|
+
const isVertical2 = edge2.from.x === edge2.to.x;
|
|
3553
|
+
return isVertical1 !== isVertical2;
|
|
3554
|
+
};
|
|
3555
|
+
var getIntersectionPoint = (edge1, edge2) => {
|
|
3556
|
+
if (!isOrthogonal(edge1, edge2)) return null;
|
|
3557
|
+
const isVertical1 = edge1.from.x === edge1.to.x;
|
|
3558
|
+
const vertical = isVertical1 ? edge1 : edge2;
|
|
3559
|
+
const horizontal = isVertical1 ? edge2 : edge1;
|
|
3560
|
+
const minX = Math.min(horizontal.from.x, horizontal.to.x);
|
|
3561
|
+
const maxX = Math.max(horizontal.from.x, horizontal.to.x);
|
|
3562
|
+
if (vertical.from.x < minX || vertical.from.x > maxX) return null;
|
|
3563
|
+
const minY = Math.min(vertical.from.y, vertical.to.y);
|
|
3564
|
+
const maxY = Math.max(vertical.from.y, vertical.to.y);
|
|
3565
|
+
if (horizontal.from.y < minY || horizontal.from.y > maxY) return null;
|
|
3566
|
+
return {
|
|
3567
|
+
x: vertical.from.x,
|
|
3568
|
+
y: horizontal.from.y
|
|
3569
|
+
};
|
|
3570
|
+
};
|
|
3571
|
+
var createSchematicTraceJunctions = ({
|
|
3572
|
+
edges: myEdges,
|
|
3573
|
+
db,
|
|
3574
|
+
source_trace_id
|
|
3575
|
+
}) => {
|
|
3576
|
+
const otherEdges = getOtherSchematicTraces({
|
|
3577
|
+
db,
|
|
3578
|
+
source_trace_id,
|
|
3579
|
+
sameNetOnly: true
|
|
3580
|
+
}).flatMap((t) => t.edges);
|
|
3581
|
+
const junctions = /* @__PURE__ */ new Set();
|
|
3582
|
+
for (const myEdge of myEdges) {
|
|
3583
|
+
for (const otherEdge of otherEdges) {
|
|
3584
|
+
const intersection = getIntersectionPoint(myEdge, otherEdge);
|
|
3585
|
+
if (intersection) {
|
|
3586
|
+
junctions.add(`${intersection.x},${intersection.y}`);
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
return Array.from(junctions).map((key) => {
|
|
3591
|
+
const [x, y] = key.split(",").map(Number);
|
|
3592
|
+
return { x, y };
|
|
3593
|
+
});
|
|
3594
|
+
};
|
|
3595
|
+
|
|
3596
|
+
// lib/utils/schematic/getEnteringEdgeFromDirection.ts
|
|
3597
|
+
var getEnteringEdgeFromDirection = (direction) => {
|
|
3598
|
+
return {
|
|
3599
|
+
up: "bottom",
|
|
3600
|
+
down: "top",
|
|
3601
|
+
left: "right",
|
|
3602
|
+
right: "left"
|
|
3603
|
+
}[direction] ?? null;
|
|
3604
|
+
};
|
|
3605
|
+
|
|
3513
3606
|
// lib/components/primitive-components/Trace/Trace.ts
|
|
3514
3607
|
var portToObjective = (port) => {
|
|
3515
3608
|
const portPosition = port._getGlobalPcbPositionAfterLayout();
|
|
@@ -3920,6 +4013,7 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
3920
4013
|
const { _parsedProps: props, parent } = this;
|
|
3921
4014
|
if (!parent) throw new Error("Trace has no parent");
|
|
3922
4015
|
const { allPortsFound, portsWithSelectors: connectedPorts } = this._findConnectedPorts();
|
|
4016
|
+
const { netsWithSelectors } = this._findConnectedNets();
|
|
3923
4017
|
if (!allPortsFound) return;
|
|
3924
4018
|
const obstacles = [];
|
|
3925
4019
|
const connection = {
|
|
@@ -3954,6 +4048,20 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
3954
4048
|
schematic_port_id: port.schematic_port_id ?? void 0,
|
|
3955
4049
|
facingDirection: port.facingDirection
|
|
3956
4050
|
}));
|
|
4051
|
+
const isPortAndNetConnection = portsWithPosition.length === 1 && netsWithSelectors.length === 1;
|
|
4052
|
+
if (isPortAndNetConnection) {
|
|
4053
|
+
const net = netsWithSelectors[0].net;
|
|
4054
|
+
const { port, position: anchorPos } = portsWithPosition[0];
|
|
4055
|
+
const netLabel = db.schematic_net_label.insert({
|
|
4056
|
+
text: net._parsedProps.name,
|
|
4057
|
+
source_net_id: net.source_net_id,
|
|
4058
|
+
anchor_position: anchorPos,
|
|
4059
|
+
// TODO compute the center based on the text size
|
|
4060
|
+
center: anchorPos,
|
|
4061
|
+
anchor_side: getEnteringEdgeFromDirection(port.facingDirection) ?? "bottom"
|
|
4062
|
+
});
|
|
4063
|
+
return;
|
|
4064
|
+
}
|
|
3957
4065
|
if (portsWithPosition.length < 2) {
|
|
3958
4066
|
return;
|
|
3959
4067
|
}
|
|
@@ -3988,8 +4096,14 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
3988
4096
|
to: route[i + 1]
|
|
3989
4097
|
});
|
|
3990
4098
|
}
|
|
3991
|
-
|
|
3992
|
-
|
|
4099
|
+
const source_trace_id = this.source_trace_id;
|
|
4100
|
+
pushEdgesOfSchematicTraceToPreventOverlap({ edges, db, source_trace_id });
|
|
4101
|
+
createSchematicTraceCrossingSegments({ edges, db, source_trace_id });
|
|
4102
|
+
const junctions = createSchematicTraceJunctions({
|
|
4103
|
+
edges,
|
|
4104
|
+
db,
|
|
4105
|
+
source_trace_id: this.source_trace_id
|
|
4106
|
+
});
|
|
3993
4107
|
const lastEdge = edges[edges.length - 1];
|
|
3994
4108
|
const lastEdgePort = portsWithPosition[portsWithPosition.length - 1];
|
|
3995
4109
|
const lastDominantDirection = getDominantDirection(lastEdge);
|
|
@@ -3999,7 +4113,7 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
3999
4113
|
const trace = db.schematic_trace.insert({
|
|
4000
4114
|
source_trace_id: this.source_trace_id,
|
|
4001
4115
|
edges,
|
|
4002
|
-
junctions
|
|
4116
|
+
junctions
|
|
4003
4117
|
});
|
|
4004
4118
|
this.schematic_trace_id = trace.schematic_trace_id;
|
|
4005
4119
|
}
|
|
@@ -4456,22 +4570,16 @@ var NetAlias = class extends PrimitiveComponent {
|
|
|
4456
4570
|
zodProps: netAliasProps
|
|
4457
4571
|
};
|
|
4458
4572
|
}
|
|
4459
|
-
initPorts() {
|
|
4460
|
-
this.add(
|
|
4461
|
-
new Port({
|
|
4462
|
-
name: "pin1",
|
|
4463
|
-
pinNumber: 1,
|
|
4464
|
-
aliases: ["anode", "pos", "left"]
|
|
4465
|
-
})
|
|
4466
|
-
);
|
|
4467
|
-
}
|
|
4468
4573
|
doInitialSchematicComponentRender() {
|
|
4469
4574
|
const { db } = this.root;
|
|
4470
4575
|
const { _parsedProps: props } = this;
|
|
4576
|
+
const anchorPos = { x: props.schX ?? 0, y: props.schY ?? 0 };
|
|
4471
4577
|
const netAlias = db.schematic_net_label.insert({
|
|
4472
4578
|
text: props.net,
|
|
4473
4579
|
source_net_id: props.net,
|
|
4474
|
-
|
|
4580
|
+
anchor_position: anchorPos,
|
|
4581
|
+
// TODO compute the center based on the text size
|
|
4582
|
+
center: anchorPos,
|
|
4475
4583
|
anchor_side: "bottom"
|
|
4476
4584
|
});
|
|
4477
4585
|
this.source_net_alias_id = netAlias.source_net_id;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.159",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@tscircuit/props": "^0.0.86",
|
|
44
44
|
"@tscircuit/schematic-autolayout": "^0.0.5",
|
|
45
45
|
"@tscircuit/soup-util": "^0.0.33",
|
|
46
|
-
"circuit-json": "^0.0.
|
|
46
|
+
"circuit-json": "^0.0.99",
|
|
47
47
|
"circuit-json-to-connectivity-map": "^0.0.17",
|
|
48
|
-
"circuit-to-svg": "^0.0.
|
|
48
|
+
"circuit-to-svg": "^0.0.67",
|
|
49
49
|
"format-si-unit": "^0.0.2",
|
|
50
50
|
"nanoid": "^5.0.7",
|
|
51
51
|
"performance-now": "^2.1.0",
|