@tscircuit/schematic-trace-solver 0.0.200 → 0.0.201
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 +37 -2
- package/lib/solvers/SameNetJunctionAlignmentSolver/SameNetJunctionAlignmentSolver.ts +6 -2
- package/lib/solvers/SameNetJunctionAlignmentSolver/shortenSameSideRailToLabelAnchor.ts +62 -0
- package/package.json +1 -1
- package/tests/bug-reports/bug-report-20260916T054012Z/__snapshots__/bug-report-20260916T054012Z.snap.svg +2 -2
- package/tests/bug-reports/bug-report-20260916T054012Z/bug-report-20260916T054012Z.test.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -15159,6 +15159,38 @@ var placeGroundRailLabelsAtOuterEnd = ({
|
|
|
15159
15159
|
return output;
|
|
15160
15160
|
};
|
|
15161
15161
|
|
|
15162
|
+
// lib/solvers/SameNetJunctionAlignmentSolver/shortenSameSideRailToLabelAnchor.ts
|
|
15163
|
+
var MAX_LOCAL_RAIL_SHIFT = 0.5;
|
|
15164
|
+
var MIN_ESCAPE_LENGTH = 1;
|
|
15165
|
+
var shortenSameSideRailToLabelAnchor = ({
|
|
15166
|
+
traces,
|
|
15167
|
+
netLabelPlacements
|
|
15168
|
+
}) => traces.map((trace) => {
|
|
15169
|
+
const path = trace.tracePath;
|
|
15170
|
+
const firstPin = path[0];
|
|
15171
|
+
const secondPin = path.at(-1);
|
|
15172
|
+
if (!firstPin || !secondPin || !nearlyEqual(firstPin.x, secondPin.x)) {
|
|
15173
|
+
return trace;
|
|
15174
|
+
}
|
|
15175
|
+
const railIndex = path.findIndex(
|
|
15176
|
+
(point, index) => index > 0 && index < path.length - 2 && isHorizontal2(path[index - 1], point) && isVertical2(point, path[index + 1]) && isHorizontal2(path[index + 1], path[index + 2])
|
|
15177
|
+
);
|
|
15178
|
+
if (railIndex < 0) return trace;
|
|
15179
|
+
const firstRail = path[railIndex];
|
|
15180
|
+
const secondRail = path[railIndex + 1];
|
|
15181
|
+
const escapeLength = Math.abs(firstRail.x - firstPin.x);
|
|
15182
|
+
const label = netLabelPlacements.find(
|
|
15183
|
+
({ anchorPoint, orientation, mspConnectionPairIds }) => mspConnectionPairIds.includes(trace.mspPairId) && (orientation === "y-" && anchorPoint.y < Math.min(firstPin.y, secondPin.y) || orientation === "y+" && anchorPoint.y > Math.max(firstPin.y, secondPin.y)) && anchorPoint.x >= Math.min(firstPin.x, firstRail.x) && anchorPoint.x <= Math.max(firstPin.x, firstRail.x) && Math.abs(anchorPoint.x - firstPin.x) < escapeLength && Math.abs(anchorPoint.x - firstRail.x) <= MAX_LOCAL_RAIL_SHIFT && escapeLength >= MIN_ESCAPE_LENGTH
|
|
15184
|
+
);
|
|
15185
|
+
if (!label) return trace;
|
|
15186
|
+
return {
|
|
15187
|
+
...trace,
|
|
15188
|
+
tracePath: path.map(
|
|
15189
|
+
(point, index) => index === railIndex || index === railIndex + 1 ? { ...point, x: label.anchorPoint.x } : point
|
|
15190
|
+
)
|
|
15191
|
+
};
|
|
15192
|
+
});
|
|
15193
|
+
|
|
15162
15194
|
// lib/solvers/SameNetJunctionAlignmentSolver/SameNetJunctionAlignmentSolver.ts
|
|
15163
15195
|
var SameNetJunctionAlignmentSolver = class extends BaseSolver {
|
|
15164
15196
|
input;
|
|
@@ -15172,10 +15204,13 @@ var SameNetJunctionAlignmentSolver = class extends BaseSolver {
|
|
|
15172
15204
|
}
|
|
15173
15205
|
_step() {
|
|
15174
15206
|
const alignment = alignSameNetJunctions(this.input);
|
|
15175
|
-
this.outputTraces =
|
|
15207
|
+
this.outputTraces = shortenSameSideRailToLabelAnchor({
|
|
15208
|
+
traces: alignment.traces,
|
|
15209
|
+
netLabelPlacements: alignment.netLabelPlacements
|
|
15210
|
+
});
|
|
15176
15211
|
this.outputNetLabelPlacements = placeGroundRailLabelsAtOuterEnd({
|
|
15177
15212
|
inputProblem: this.input.inputProblem,
|
|
15178
|
-
traces:
|
|
15213
|
+
traces: this.outputTraces,
|
|
15179
15214
|
netLabelPlacements: alignment.netLabelPlacements
|
|
15180
15215
|
});
|
|
15181
15216
|
this.stats.alignedJunctionCount = alignment.alignedJunctionCount;
|
|
@@ -8,6 +8,7 @@ import type { InputProblem } from "lib/types/InputProblem"
|
|
|
8
8
|
import { getColorFromString } from "lib/utils/getColorFromString"
|
|
9
9
|
import { alignSameNetJunctions } from "./alignSameNetJunctions"
|
|
10
10
|
import { placeGroundRailLabelsAtOuterEnd } from "./placeGroundRailLabelsAtOuterEnd"
|
|
11
|
+
import { shortenSameSideRailToLabelAnchor } from "./shortenSameSideRailToLabelAnchor"
|
|
11
12
|
|
|
12
13
|
interface SameNetJunctionAlignmentSolverInput {
|
|
13
14
|
inputProblem: InputProblem
|
|
@@ -31,10 +32,13 @@ export class SameNetJunctionAlignmentSolver extends BaseSolver {
|
|
|
31
32
|
|
|
32
33
|
override _step() {
|
|
33
34
|
const alignment = alignSameNetJunctions(this.input)
|
|
34
|
-
this.outputTraces =
|
|
35
|
+
this.outputTraces = shortenSameSideRailToLabelAnchor({
|
|
36
|
+
traces: alignment.traces,
|
|
37
|
+
netLabelPlacements: alignment.netLabelPlacements,
|
|
38
|
+
})
|
|
35
39
|
this.outputNetLabelPlacements = placeGroundRailLabelsAtOuterEnd({
|
|
36
40
|
inputProblem: this.input.inputProblem,
|
|
37
|
-
traces:
|
|
41
|
+
traces: this.outputTraces,
|
|
38
42
|
netLabelPlacements: alignment.netLabelPlacements,
|
|
39
43
|
})
|
|
40
44
|
this.stats.alignedJunctionCount = alignment.alignedJunctionCount
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
|
|
2
|
+
import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
|
|
3
|
+
import {
|
|
4
|
+
isHorizontal,
|
|
5
|
+
isVertical,
|
|
6
|
+
nearlyEqual,
|
|
7
|
+
} from "lib/solvers/TraceCleanupSolver/sameNetRailAlignment/geometry"
|
|
8
|
+
|
|
9
|
+
const MAX_LOCAL_RAIL_SHIFT = 0.5
|
|
10
|
+
const MIN_ESCAPE_LENGTH = 1
|
|
11
|
+
|
|
12
|
+
export const shortenSameSideRailToLabelAnchor = ({
|
|
13
|
+
traces,
|
|
14
|
+
netLabelPlacements,
|
|
15
|
+
}: {
|
|
16
|
+
traces: SolvedTracePath[]
|
|
17
|
+
netLabelPlacements: NetLabelPlacement[]
|
|
18
|
+
}) =>
|
|
19
|
+
traces.map((trace) => {
|
|
20
|
+
const path = trace.tracePath
|
|
21
|
+
const firstPin = path[0]
|
|
22
|
+
const secondPin = path.at(-1)
|
|
23
|
+
if (!firstPin || !secondPin || !nearlyEqual(firstPin.x, secondPin.x)) {
|
|
24
|
+
return trace
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const railIndex = path.findIndex(
|
|
28
|
+
(point, index) =>
|
|
29
|
+
index > 0 &&
|
|
30
|
+
index < path.length - 2 &&
|
|
31
|
+
isHorizontal(path[index - 1]!, point) &&
|
|
32
|
+
isVertical(point, path[index + 1]!) &&
|
|
33
|
+
isHorizontal(path[index + 1]!, path[index + 2]!),
|
|
34
|
+
)
|
|
35
|
+
if (railIndex < 0) return trace
|
|
36
|
+
const firstRail = path[railIndex]!
|
|
37
|
+
const secondRail = path[railIndex + 1]!
|
|
38
|
+
const escapeLength = Math.abs(firstRail.x - firstPin.x)
|
|
39
|
+
const label = netLabelPlacements.find(
|
|
40
|
+
({ anchorPoint, orientation, mspConnectionPairIds }) =>
|
|
41
|
+
mspConnectionPairIds.includes(trace.mspPairId) &&
|
|
42
|
+
((orientation === "y-" &&
|
|
43
|
+
anchorPoint.y < Math.min(firstPin.y, secondPin.y)) ||
|
|
44
|
+
(orientation === "y+" &&
|
|
45
|
+
anchorPoint.y > Math.max(firstPin.y, secondPin.y))) &&
|
|
46
|
+
anchorPoint.x >= Math.min(firstPin.x, firstRail.x) &&
|
|
47
|
+
anchorPoint.x <= Math.max(firstPin.x, firstRail.x) &&
|
|
48
|
+
Math.abs(anchorPoint.x - firstPin.x) < escapeLength &&
|
|
49
|
+
Math.abs(anchorPoint.x - firstRail.x) <= MAX_LOCAL_RAIL_SHIFT &&
|
|
50
|
+
escapeLength >= MIN_ESCAPE_LENGTH,
|
|
51
|
+
)
|
|
52
|
+
if (!label) return trace
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
...trace,
|
|
56
|
+
tracePath: path.map((point, index) =>
|
|
57
|
+
index === railIndex || index === railIndex + 1
|
|
58
|
+
? { ...point, x: label.anchorPoint.x }
|
|
59
|
+
: point,
|
|
60
|
+
),
|
|
61
|
+
}
|
|
62
|
+
})
|