@tscircuit/core 0.0.1316 → 0.0.1318
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 +78 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3778,10 +3778,15 @@ var Trace_doInitialSchematicTraceRender = (trace) => {
|
|
|
3778
3778
|
edges2.push({ from: anchorPos, to: { x: labelPos.x, y: anchorPos.y } });
|
|
3779
3779
|
edges2.push({ from: { x: labelPos.x, y: anchorPos.y }, to: labelPos });
|
|
3780
3780
|
}
|
|
3781
|
+
const junctions2 = createSchematicTraceJunctions({
|
|
3782
|
+
edges: edges2,
|
|
3783
|
+
db,
|
|
3784
|
+
source_trace_id: trace.source_trace_id
|
|
3785
|
+
});
|
|
3781
3786
|
const dbTrace2 = db.schematic_trace.insert({
|
|
3782
3787
|
source_trace_id: trace.source_trace_id,
|
|
3783
3788
|
edges: edges2,
|
|
3784
|
-
junctions:
|
|
3789
|
+
junctions: junctions2,
|
|
3785
3790
|
subcircuit_connectivity_map_key: trace.subcircuit_connectivity_map_key ?? void 0
|
|
3786
3791
|
});
|
|
3787
3792
|
trace.schematic_trace_id = dbTrace2.schematic_trace_id;
|
|
@@ -15800,9 +15805,7 @@ var getSimpleRouteJsonFromCircuitJson = ({
|
|
|
15800
15805
|
]
|
|
15801
15806
|
};
|
|
15802
15807
|
}).filter((c) => c !== null);
|
|
15803
|
-
const source_nets = db.source_net.list().filter(
|
|
15804
|
-
(e) => !subcircuit_id || relevantSubcircuitIds?.has(e.subcircuit_id)
|
|
15805
|
-
);
|
|
15808
|
+
const source_nets = db.source_net.list().filter((e) => !subcircuit_id || e.subcircuit_id === subcircuit_id);
|
|
15806
15809
|
const connectionsFromNets = [];
|
|
15807
15810
|
for (const net of source_nets) {
|
|
15808
15811
|
const connectedSourceTraces = db.source_trace.list().filter((st) => st.connected_source_net_ids?.includes(net.source_net_id));
|
|
@@ -19129,6 +19132,24 @@ function createSchematicTraceSolverInputProblem(group) {
|
|
|
19129
19132
|
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/applyTracesFromSolverOutput.ts
|
|
19130
19133
|
import "@tscircuit/schematic-trace-solver";
|
|
19131
19134
|
|
|
19135
|
+
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/segment-intersection.ts
|
|
19136
|
+
var cross = (ax, ay, bx, by) => {
|
|
19137
|
+
return ax * by - ay * bx;
|
|
19138
|
+
};
|
|
19139
|
+
function segmentIntersection(p1, p2, q1, q2, tol) {
|
|
19140
|
+
const r = { x: p2.x - p1.x, y: p2.y - p1.y };
|
|
19141
|
+
const s = { x: q2.x - q1.x, y: q2.y - q1.y };
|
|
19142
|
+
const rxs = cross(r.x, r.y, s.x, s.y);
|
|
19143
|
+
const q_p = { x: q1.x - p1.x, y: q1.y - p1.y };
|
|
19144
|
+
const q_pxr = cross(q_p.x, q_p.y, r.x, r.y);
|
|
19145
|
+
if (Math.abs(rxs) < tol && Math.abs(q_pxr) < tol) return null;
|
|
19146
|
+
if (Math.abs(rxs) < tol && Math.abs(q_pxr) >= tol) return null;
|
|
19147
|
+
const t = cross(q_p.x, q_p.y, s.x, s.y) / rxs;
|
|
19148
|
+
const u = cross(q_p.x, q_p.y, r.x, r.y) / rxs;
|
|
19149
|
+
if (t < -tol || t > 1 + tol || u < -tol || u > 1 + tol) return null;
|
|
19150
|
+
return { x: p1.x + t * r.x, y: p1.y + t * r.y };
|
|
19151
|
+
}
|
|
19152
|
+
|
|
19132
19153
|
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/compute-crossings.ts
|
|
19133
19154
|
var TOL = 1e-6;
|
|
19134
19155
|
function isHorizontalEdge(edge) {
|
|
@@ -19148,27 +19169,6 @@ function paramAlong(a, b, p) {
|
|
|
19148
19169
|
const t = ((p.x - a.x) * (b.x - a.x) + (p.y - a.y) * (b.y - a.y)) / ((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
|
|
19149
19170
|
return Math.max(0, Math.min(1, t)) * L;
|
|
19150
19171
|
}
|
|
19151
|
-
function cross(ax, ay, bx, by) {
|
|
19152
|
-
return ax * by - ay * bx;
|
|
19153
|
-
}
|
|
19154
|
-
function segmentIntersection(p1, p2, q1, q2) {
|
|
19155
|
-
const r = { x: p2.x - p1.x, y: p2.y - p1.y };
|
|
19156
|
-
const s = { x: q2.x - q1.x, y: q2.y - q1.y };
|
|
19157
|
-
const rxs = cross(r.x, r.y, s.x, s.y);
|
|
19158
|
-
const q_p = { x: q1.x - p1.x, y: q1.y - p1.y };
|
|
19159
|
-
const q_pxr = cross(q_p.x, q_p.y, r.x, r.y);
|
|
19160
|
-
if (Math.abs(rxs) < TOL && Math.abs(q_pxr) < TOL) {
|
|
19161
|
-
return null;
|
|
19162
|
-
}
|
|
19163
|
-
if (Math.abs(rxs) < TOL && Math.abs(q_pxr) >= TOL) {
|
|
19164
|
-
return null;
|
|
19165
|
-
}
|
|
19166
|
-
const t = cross(q_p.x, q_p.y, s.x, s.y) / rxs;
|
|
19167
|
-
const u = cross(q_p.x, q_p.y, r.x, r.y) / rxs;
|
|
19168
|
-
if (t < -TOL || t > 1 + TOL || u < -TOL || u > 1 + TOL) return null;
|
|
19169
|
-
const pt = { x: p1.x + t * r.x, y: p1.y + t * r.y };
|
|
19170
|
-
return pt;
|
|
19171
|
-
}
|
|
19172
19172
|
function mergeIntervals(intervals, tol = TOL) {
|
|
19173
19173
|
if (intervals.length === 0) return intervals;
|
|
19174
19174
|
intervals.sort((a, b) => a.start - b.start);
|
|
@@ -19234,7 +19234,10 @@ function computeCrossings(traces, opts = {}) {
|
|
|
19234
19234
|
const B = traces[tj];
|
|
19235
19235
|
for (let ej = tj === ti ? ei + 1 : 0; ej < B.edges.length; ej++) {
|
|
19236
19236
|
const eB = B.edges[ej];
|
|
19237
|
-
|
|
19237
|
+
if (A.connectivity_key !== void 0 && A.connectivity_key === B.connectivity_key) {
|
|
19238
|
+
continue;
|
|
19239
|
+
}
|
|
19240
|
+
const P = segmentIntersection(eA.from, eA.to, eB.from, eB.to, tol);
|
|
19238
19241
|
if (!P) continue;
|
|
19239
19242
|
const LA = length6(eA.from, eA.to);
|
|
19240
19243
|
const LB = length6(eB.from, eB.to);
|
|
@@ -19272,6 +19275,7 @@ function computeCrossings(traces, opts = {}) {
|
|
|
19272
19275
|
}
|
|
19273
19276
|
const out = traces.map((t) => ({
|
|
19274
19277
|
source_trace_id: t.source_trace_id,
|
|
19278
|
+
connectivity_key: t.connectivity_key,
|
|
19275
19279
|
edges: []
|
|
19276
19280
|
}));
|
|
19277
19281
|
for (let ti = 0; ti < traces.length; ti++) {
|
|
@@ -19325,6 +19329,9 @@ function dedupePoints(points, tol = TOL2) {
|
|
|
19325
19329
|
function edgeVec(e) {
|
|
19326
19330
|
return { x: e.to.x - e.from.x, y: e.to.y - e.from.y };
|
|
19327
19331
|
}
|
|
19332
|
+
function isEndpointOfEdge(p, e, tol = TOL2) {
|
|
19333
|
+
return pointEq(p, e.from, tol) || pointEq(p, e.to, tol);
|
|
19334
|
+
}
|
|
19328
19335
|
function isParallel(e1, e2, tol = TOL2) {
|
|
19329
19336
|
const v1 = edgeVec(e1);
|
|
19330
19337
|
const v2 = edgeVec(e2);
|
|
@@ -19388,6 +19395,22 @@ function computeJunctions(traces, opts = {}) {
|
|
|
19388
19395
|
for (let j = i + 1; j < traces.length; j++) {
|
|
19389
19396
|
const B = traces[j];
|
|
19390
19397
|
const BEnds = endpointsByTrace[j];
|
|
19398
|
+
const isSameNet = A.connectivity_key !== void 0 && A.connectivity_key === B.connectivity_key;
|
|
19399
|
+
if (isSameNet) {
|
|
19400
|
+
for (const eA of A.edges) {
|
|
19401
|
+
for (const eB of B.edges) {
|
|
19402
|
+
const p = segmentIntersection(eA.from, eA.to, eB.from, eB.to, tol);
|
|
19403
|
+
if (!p) continue;
|
|
19404
|
+
if (isEndpointOfEdge(p, eA, tol) || isEndpointOfEdge(p, eB, tol)) {
|
|
19405
|
+
continue;
|
|
19406
|
+
}
|
|
19407
|
+
result[A.source_trace_id].push(p);
|
|
19408
|
+
if (A.source_trace_id !== B.source_trace_id) {
|
|
19409
|
+
result[B.source_trace_id].push(p);
|
|
19410
|
+
}
|
|
19411
|
+
}
|
|
19412
|
+
}
|
|
19413
|
+
}
|
|
19391
19414
|
for (const pa of AEnds) {
|
|
19392
19415
|
for (const pb of BEnds) {
|
|
19393
19416
|
if (pointEq(pa, pb, tol)) {
|
|
@@ -19510,6 +19533,18 @@ function applyTracesFromSolverOutput(args) {
|
|
|
19510
19533
|
String(solvedTracePath.userNetId)
|
|
19511
19534
|
);
|
|
19512
19535
|
}
|
|
19536
|
+
if (!subcircuit_connectivity_map_key) {
|
|
19537
|
+
const sourcePortConnKeys = solvedTraceSchematicPortIds.map((schematicPortId) => {
|
|
19538
|
+
const schematicPort = db.schematic_port.get(schematicPortId);
|
|
19539
|
+
const sourcePortId = schematicPort?.source_port_id;
|
|
19540
|
+
if (!sourcePortId) return void 0;
|
|
19541
|
+
return db.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key;
|
|
19542
|
+
}).filter((key) => Boolean(key));
|
|
19543
|
+
const uniqueSourcePortConnKeys = new Set(sourcePortConnKeys);
|
|
19544
|
+
if (uniqueSourcePortConnKeys.size === 1) {
|
|
19545
|
+
subcircuit_connectivity_map_key = sourcePortConnKeys[0];
|
|
19546
|
+
}
|
|
19547
|
+
}
|
|
19513
19548
|
pendingTraces.push({
|
|
19514
19549
|
source_trace_id,
|
|
19515
19550
|
edges,
|
|
@@ -19522,10 +19557,24 @@ function applyTracesFromSolverOutput(args) {
|
|
|
19522
19557
|
const withCrossings = computeCrossings(
|
|
19523
19558
|
pendingTraces.map((t) => ({
|
|
19524
19559
|
source_trace_id: t.source_trace_id,
|
|
19525
|
-
edges: t.edges
|
|
19560
|
+
edges: t.edges,
|
|
19561
|
+
connectivity_key: t.subcircuit_connectivity_map_key
|
|
19526
19562
|
}))
|
|
19527
19563
|
);
|
|
19528
|
-
const
|
|
19564
|
+
const existingTracesForJunctions = [];
|
|
19565
|
+
for (const t of db.schematic_trace.list()) {
|
|
19566
|
+
if (!t.source_trace_id || t.edges.length === 0) continue;
|
|
19567
|
+
const sourceTrace = db.source_trace.get(t.source_trace_id);
|
|
19568
|
+
existingTracesForJunctions.push({
|
|
19569
|
+
source_trace_id: t.source_trace_id,
|
|
19570
|
+
edges: t.edges,
|
|
19571
|
+
connectivity_key: t.subcircuit_connectivity_map_key ?? sourceTrace?.subcircuit_connectivity_map_key
|
|
19572
|
+
});
|
|
19573
|
+
}
|
|
19574
|
+
const junctionsById = computeJunctions([
|
|
19575
|
+
...withCrossings,
|
|
19576
|
+
...existingTracesForJunctions
|
|
19577
|
+
]);
|
|
19529
19578
|
for (const t of withCrossings) {
|
|
19530
19579
|
db.schematic_trace.insert({
|
|
19531
19580
|
source_trace_id: t.source_trace_id,
|
|
@@ -23517,7 +23566,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
23517
23566
|
var package_default = {
|
|
23518
23567
|
name: "@tscircuit/core",
|
|
23519
23568
|
type: "module",
|
|
23520
|
-
version: "0.0.
|
|
23569
|
+
version: "0.0.1317",
|
|
23521
23570
|
types: "dist/index.d.ts",
|
|
23522
23571
|
main: "dist/index.js",
|
|
23523
23572
|
module: "dist/index.js",
|