@tscircuit/core 0.0.1350 → 0.0.1351
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 +132 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19796,6 +19796,111 @@ function computeJunctions(traces, opts = {}) {
|
|
|
19796
19796
|
return result;
|
|
19797
19797
|
}
|
|
19798
19798
|
|
|
19799
|
+
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/remove-overlapping-same-net-crossing-segments.ts
|
|
19800
|
+
var TOL3 = 1e-6;
|
|
19801
|
+
function isCollinear(a, b, tol = TOL3) {
|
|
19802
|
+
const adx = a.to.x - a.from.x;
|
|
19803
|
+
const ady = a.to.y - a.from.y;
|
|
19804
|
+
const bdx = b.to.x - b.from.x;
|
|
19805
|
+
const bdy = b.to.y - b.from.y;
|
|
19806
|
+
const aLen = Math.hypot(adx, ady);
|
|
19807
|
+
const bLen = Math.hypot(bdx, bdy);
|
|
19808
|
+
if (aLen <= tol || bLen <= tol) return false;
|
|
19809
|
+
const directionCross = adx * bdy - ady * bdx;
|
|
19810
|
+
if (Math.abs(directionCross) > tol * aLen * bLen) return false;
|
|
19811
|
+
const offsetCross = adx * (b.from.y - a.from.y) - ady * (b.from.x - a.from.x);
|
|
19812
|
+
return Math.abs(offsetCross) <= tol * aLen;
|
|
19813
|
+
}
|
|
19814
|
+
function splitEdgeAroundIntervals(edge, intervals) {
|
|
19815
|
+
const merged = mergeIntervals(intervals);
|
|
19816
|
+
if (merged.length === 0) return [edge];
|
|
19817
|
+
const edgeLength = length6(edge.from, edge.to);
|
|
19818
|
+
if (edgeLength <= TOL3) return [edge];
|
|
19819
|
+
const result = [];
|
|
19820
|
+
let cursor = 0;
|
|
19821
|
+
for (const interval of merged) {
|
|
19822
|
+
if (interval.start - cursor > TOL3) {
|
|
19823
|
+
result.push({
|
|
19824
|
+
from: pointAt(edge.from, edge.to, cursor / edgeLength),
|
|
19825
|
+
to: pointAt(edge.from, edge.to, interval.start / edgeLength)
|
|
19826
|
+
});
|
|
19827
|
+
}
|
|
19828
|
+
if (interval.end - interval.start > TOL3) {
|
|
19829
|
+
result.push({
|
|
19830
|
+
from: pointAt(edge.from, edge.to, interval.start / edgeLength),
|
|
19831
|
+
to: pointAt(edge.from, edge.to, interval.end / edgeLength),
|
|
19832
|
+
is_crossing: true
|
|
19833
|
+
});
|
|
19834
|
+
}
|
|
19835
|
+
cursor = Math.max(cursor, interval.end);
|
|
19836
|
+
}
|
|
19837
|
+
if (edgeLength - cursor > TOL3) {
|
|
19838
|
+
result.push({
|
|
19839
|
+
from: pointAt(edge.from, edge.to, cursor / edgeLength),
|
|
19840
|
+
to: edge.to
|
|
19841
|
+
});
|
|
19842
|
+
}
|
|
19843
|
+
return result;
|
|
19844
|
+
}
|
|
19845
|
+
function removeOverlappingSameNetCrossingSegments(traces) {
|
|
19846
|
+
const intervalsToRemove = /* @__PURE__ */ new Map();
|
|
19847
|
+
for (let crossingTraceIndex = 0; crossingTraceIndex < traces.length; crossingTraceIndex++) {
|
|
19848
|
+
const crossingTrace = traces[crossingTraceIndex];
|
|
19849
|
+
if (!crossingTrace.connectivity_key) continue;
|
|
19850
|
+
for (const crossingEdge of crossingTrace.edges) {
|
|
19851
|
+
if (!crossingEdge.is_crossing || length6(crossingEdge.from, crossingEdge.to) <= TOL3)
|
|
19852
|
+
continue;
|
|
19853
|
+
for (let traceIndex = 0; traceIndex < traces.length; traceIndex++) {
|
|
19854
|
+
const candidateTrace = traces[traceIndex];
|
|
19855
|
+
if (traceIndex === crossingTraceIndex || candidateTrace.connectivity_key !== crossingTrace.connectivity_key) {
|
|
19856
|
+
continue;
|
|
19857
|
+
}
|
|
19858
|
+
for (let edgeIndex = 0; edgeIndex < candidateTrace.edges.length; edgeIndex++) {
|
|
19859
|
+
const candidateEdge = candidateTrace.edges[edgeIndex];
|
|
19860
|
+
const candidateLength = length6(candidateEdge.from, candidateEdge.to);
|
|
19861
|
+
if (candidateEdge.is_crossing || candidateLength <= TOL3) continue;
|
|
19862
|
+
if (!isCollinear(candidateEdge, crossingEdge)) continue;
|
|
19863
|
+
const start = Math.max(
|
|
19864
|
+
0,
|
|
19865
|
+
Math.min(
|
|
19866
|
+
paramAlong(
|
|
19867
|
+
candidateEdge.from,
|
|
19868
|
+
candidateEdge.to,
|
|
19869
|
+
crossingEdge.from
|
|
19870
|
+
),
|
|
19871
|
+
paramAlong(candidateEdge.from, candidateEdge.to, crossingEdge.to)
|
|
19872
|
+
)
|
|
19873
|
+
);
|
|
19874
|
+
const end = Math.min(
|
|
19875
|
+
candidateLength,
|
|
19876
|
+
Math.max(
|
|
19877
|
+
paramAlong(
|
|
19878
|
+
candidateEdge.from,
|
|
19879
|
+
candidateEdge.to,
|
|
19880
|
+
crossingEdge.from
|
|
19881
|
+
),
|
|
19882
|
+
paramAlong(candidateEdge.from, candidateEdge.to, crossingEdge.to)
|
|
19883
|
+
)
|
|
19884
|
+
);
|
|
19885
|
+
if (end - start <= TOL3) continue;
|
|
19886
|
+
const key = `${traceIndex}:${edgeIndex}`;
|
|
19887
|
+
const intervals = intervalsToRemove.get(key) ?? [];
|
|
19888
|
+
intervals.push({ start, end });
|
|
19889
|
+
intervalsToRemove.set(key, intervals);
|
|
19890
|
+
}
|
|
19891
|
+
}
|
|
19892
|
+
}
|
|
19893
|
+
}
|
|
19894
|
+
if (intervalsToRemove.size === 0) return traces;
|
|
19895
|
+
return traces.map((trace, traceIndex) => ({
|
|
19896
|
+
...trace,
|
|
19897
|
+
edges: trace.edges.flatMap((edge, edgeIndex) => {
|
|
19898
|
+
const intervals = intervalsToRemove.get(`${traceIndex}:${edgeIndex}`);
|
|
19899
|
+
return intervals ? splitEdgeAroundIntervals(edge, intervals) : [edge];
|
|
19900
|
+
})
|
|
19901
|
+
}));
|
|
19902
|
+
}
|
|
19903
|
+
|
|
19799
19904
|
// lib/components/primitive-components/Group/Group_doInitialSchematicTraceRender/applyTracesFromSolverOutput.ts
|
|
19800
19905
|
import Debug10 from "debug";
|
|
19801
19906
|
var debug8 = Debug10("Group_doInitialSchematicTraceRender");
|
|
@@ -19950,19 +20055,37 @@ function applyTracesFromSolverOutput(args) {
|
|
|
19950
20055
|
);
|
|
19951
20056
|
const existingTracesForJunctions = [];
|
|
19952
20057
|
for (const t of db.schematic_trace.list()) {
|
|
19953
|
-
if (
|
|
19954
|
-
const sourceTrace = db.source_trace.get(t.source_trace_id);
|
|
20058
|
+
if (t.edges.length === 0) continue;
|
|
20059
|
+
const sourceTrace = t.source_trace_id ? db.source_trace.get(t.source_trace_id) : void 0;
|
|
19955
20060
|
existingTracesForJunctions.push({
|
|
19956
|
-
|
|
20061
|
+
schematic_trace_id: t.schematic_trace_id,
|
|
20062
|
+
source_trace_id: t.source_trace_id ?? t.schematic_trace_id,
|
|
19957
20063
|
edges: t.edges,
|
|
19958
20064
|
connectivity_key: t.subcircuit_connectivity_map_key ?? sourceTrace?.subcircuit_connectivity_map_key
|
|
19959
20065
|
});
|
|
19960
20066
|
}
|
|
19961
|
-
const
|
|
20067
|
+
const tracesWithTrimmedCrossingOverlaps = removeOverlappingSameNetCrossingSegments([
|
|
19962
20068
|
...withCrossings,
|
|
19963
20069
|
...existingTracesForJunctions
|
|
19964
20070
|
]);
|
|
19965
|
-
|
|
20071
|
+
const visibleTraces = tracesWithTrimmedCrossingOverlaps.slice(
|
|
20072
|
+
0,
|
|
20073
|
+
withCrossings.length
|
|
20074
|
+
);
|
|
20075
|
+
const visibleExistingTraces = tracesWithTrimmedCrossingOverlaps.slice(
|
|
20076
|
+
withCrossings.length
|
|
20077
|
+
);
|
|
20078
|
+
for (const trace of visibleExistingTraces) {
|
|
20079
|
+
if (!trace.schematic_trace_id) continue;
|
|
20080
|
+
db.schematic_trace.update(trace.schematic_trace_id, {
|
|
20081
|
+
edges: trace.edges
|
|
20082
|
+
});
|
|
20083
|
+
}
|
|
20084
|
+
const junctionsById = computeJunctions([
|
|
20085
|
+
...visibleTraces,
|
|
20086
|
+
...visibleExistingTraces
|
|
20087
|
+
]);
|
|
20088
|
+
for (const t of visibleTraces) {
|
|
19966
20089
|
db.schematic_trace.insert({
|
|
19967
20090
|
source_trace_id: t.source_trace_id,
|
|
19968
20091
|
edges: t.edges,
|
|
@@ -24065,7 +24188,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
24065
24188
|
var package_default = {
|
|
24066
24189
|
name: "@tscircuit/core",
|
|
24067
24190
|
type: "module",
|
|
24068
|
-
version: "0.0.
|
|
24191
|
+
version: "0.0.1350",
|
|
24069
24192
|
types: "dist/index.d.ts",
|
|
24070
24193
|
main: "dist/index.js",
|
|
24071
24194
|
module: "dist/index.js",
|
|
@@ -30330,7 +30453,7 @@ var SchematicSection = class _SchematicSection extends PrimitiveComponent2 {
|
|
|
30330
30453
|
const PADDING = 0.5;
|
|
30331
30454
|
const LABEL_PADDING = 0.2;
|
|
30332
30455
|
const STROKE_WIDTH = 0.02;
|
|
30333
|
-
const
|
|
30456
|
+
const TOL4 = 1e-3;
|
|
30334
30457
|
const namedSectionsWithBounds = allSections.map((section) => {
|
|
30335
30458
|
const bounds = section._computeSectionBounds(
|
|
30336
30459
|
board,
|
|
@@ -30387,10 +30510,10 @@ var SchematicSection = class _SchematicSection extends PrimitiveComponent2 {
|
|
|
30387
30510
|
});
|
|
30388
30511
|
}
|
|
30389
30512
|
const hDividers = dividers.filter(
|
|
30390
|
-
(l) => Math.abs(l.start.y - l.end.y) <
|
|
30513
|
+
(l) => Math.abs(l.start.y - l.end.y) < TOL4
|
|
30391
30514
|
);
|
|
30392
30515
|
const vDividers = dividers.filter(
|
|
30393
|
-
(l) => Math.abs(l.start.x - l.end.x) <
|
|
30516
|
+
(l) => Math.abs(l.start.x - l.end.x) < TOL4
|
|
30394
30517
|
);
|
|
30395
30518
|
for (const {
|
|
30396
30519
|
displayName,
|