@tscircuit/core 0.0.1317 → 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 +77 -26
- 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;
|
|
@@ -19127,6 +19132,24 @@ function createSchematicTraceSolverInputProblem(group) {
|
|
|
19127
19132
|
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/applyTracesFromSolverOutput.ts
|
|
19128
19133
|
import "@tscircuit/schematic-trace-solver";
|
|
19129
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
|
+
|
|
19130
19153
|
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/compute-crossings.ts
|
|
19131
19154
|
var TOL = 1e-6;
|
|
19132
19155
|
function isHorizontalEdge(edge) {
|
|
@@ -19146,27 +19169,6 @@ function paramAlong(a, b, p) {
|
|
|
19146
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));
|
|
19147
19170
|
return Math.max(0, Math.min(1, t)) * L;
|
|
19148
19171
|
}
|
|
19149
|
-
function cross(ax, ay, bx, by) {
|
|
19150
|
-
return ax * by - ay * bx;
|
|
19151
|
-
}
|
|
19152
|
-
function segmentIntersection(p1, p2, q1, q2) {
|
|
19153
|
-
const r = { x: p2.x - p1.x, y: p2.y - p1.y };
|
|
19154
|
-
const s = { x: q2.x - q1.x, y: q2.y - q1.y };
|
|
19155
|
-
const rxs = cross(r.x, r.y, s.x, s.y);
|
|
19156
|
-
const q_p = { x: q1.x - p1.x, y: q1.y - p1.y };
|
|
19157
|
-
const q_pxr = cross(q_p.x, q_p.y, r.x, r.y);
|
|
19158
|
-
if (Math.abs(rxs) < TOL && Math.abs(q_pxr) < TOL) {
|
|
19159
|
-
return null;
|
|
19160
|
-
}
|
|
19161
|
-
if (Math.abs(rxs) < TOL && Math.abs(q_pxr) >= TOL) {
|
|
19162
|
-
return null;
|
|
19163
|
-
}
|
|
19164
|
-
const t = cross(q_p.x, q_p.y, s.x, s.y) / rxs;
|
|
19165
|
-
const u = cross(q_p.x, q_p.y, r.x, r.y) / rxs;
|
|
19166
|
-
if (t < -TOL || t > 1 + TOL || u < -TOL || u > 1 + TOL) return null;
|
|
19167
|
-
const pt = { x: p1.x + t * r.x, y: p1.y + t * r.y };
|
|
19168
|
-
return pt;
|
|
19169
|
-
}
|
|
19170
19172
|
function mergeIntervals(intervals, tol = TOL) {
|
|
19171
19173
|
if (intervals.length === 0) return intervals;
|
|
19172
19174
|
intervals.sort((a, b) => a.start - b.start);
|
|
@@ -19232,7 +19234,10 @@ function computeCrossings(traces, opts = {}) {
|
|
|
19232
19234
|
const B = traces[tj];
|
|
19233
19235
|
for (let ej = tj === ti ? ei + 1 : 0; ej < B.edges.length; ej++) {
|
|
19234
19236
|
const eB = B.edges[ej];
|
|
19235
|
-
|
|
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);
|
|
19236
19241
|
if (!P) continue;
|
|
19237
19242
|
const LA = length6(eA.from, eA.to);
|
|
19238
19243
|
const LB = length6(eB.from, eB.to);
|
|
@@ -19270,6 +19275,7 @@ function computeCrossings(traces, opts = {}) {
|
|
|
19270
19275
|
}
|
|
19271
19276
|
const out = traces.map((t) => ({
|
|
19272
19277
|
source_trace_id: t.source_trace_id,
|
|
19278
|
+
connectivity_key: t.connectivity_key,
|
|
19273
19279
|
edges: []
|
|
19274
19280
|
}));
|
|
19275
19281
|
for (let ti = 0; ti < traces.length; ti++) {
|
|
@@ -19323,6 +19329,9 @@ function dedupePoints(points, tol = TOL2) {
|
|
|
19323
19329
|
function edgeVec(e) {
|
|
19324
19330
|
return { x: e.to.x - e.from.x, y: e.to.y - e.from.y };
|
|
19325
19331
|
}
|
|
19332
|
+
function isEndpointOfEdge(p, e, tol = TOL2) {
|
|
19333
|
+
return pointEq(p, e.from, tol) || pointEq(p, e.to, tol);
|
|
19334
|
+
}
|
|
19326
19335
|
function isParallel(e1, e2, tol = TOL2) {
|
|
19327
19336
|
const v1 = edgeVec(e1);
|
|
19328
19337
|
const v2 = edgeVec(e2);
|
|
@@ -19386,6 +19395,22 @@ function computeJunctions(traces, opts = {}) {
|
|
|
19386
19395
|
for (let j = i + 1; j < traces.length; j++) {
|
|
19387
19396
|
const B = traces[j];
|
|
19388
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
|
+
}
|
|
19389
19414
|
for (const pa of AEnds) {
|
|
19390
19415
|
for (const pb of BEnds) {
|
|
19391
19416
|
if (pointEq(pa, pb, tol)) {
|
|
@@ -19508,6 +19533,18 @@ function applyTracesFromSolverOutput(args) {
|
|
|
19508
19533
|
String(solvedTracePath.userNetId)
|
|
19509
19534
|
);
|
|
19510
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
|
+
}
|
|
19511
19548
|
pendingTraces.push({
|
|
19512
19549
|
source_trace_id,
|
|
19513
19550
|
edges,
|
|
@@ -19520,10 +19557,24 @@ function applyTracesFromSolverOutput(args) {
|
|
|
19520
19557
|
const withCrossings = computeCrossings(
|
|
19521
19558
|
pendingTraces.map((t) => ({
|
|
19522
19559
|
source_trace_id: t.source_trace_id,
|
|
19523
|
-
edges: t.edges
|
|
19560
|
+
edges: t.edges,
|
|
19561
|
+
connectivity_key: t.subcircuit_connectivity_map_key
|
|
19524
19562
|
}))
|
|
19525
19563
|
);
|
|
19526
|
-
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
|
+
]);
|
|
19527
19578
|
for (const t of withCrossings) {
|
|
19528
19579
|
db.schematic_trace.insert({
|
|
19529
19580
|
source_trace_id: t.source_trace_id,
|
|
@@ -23515,7 +23566,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
23515
23566
|
var package_default = {
|
|
23516
23567
|
name: "@tscircuit/core",
|
|
23517
23568
|
type: "module",
|
|
23518
|
-
version: "0.0.
|
|
23569
|
+
version: "0.0.1317",
|
|
23519
23570
|
types: "dist/index.d.ts",
|
|
23520
23571
|
main: "dist/index.js",
|
|
23521
23572
|
module: "dist/index.js",
|