@tscircuit/schematic-trace-solver 0.0.82 → 0.0.84
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/biome.json +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +166 -74
- package/lib/solvers/Example28Solver/Example28Solver.ts +114 -2
- package/lib/solvers/Example28Solver/reroute.ts +32 -21
- package/lib/solvers/NetLabelTraceCollisionSolver/NetLabelTraceCollisionSolver.ts +1 -0
- package/package.json +1 -1
- package/tests/bug-reports/bug-report-20260706T220324Z/__snapshots__/bug-report-20260706T220324Z.snap.svg +3449 -0
- package/tests/bug-reports/bug-report-20260706T220324Z/bug-report-20260706T220324Z.json +1799 -0
- package/tests/bug-reports/bug-report-20260706T220324Z/bug-report-20260706T220324Z.test.ts +12 -0
- package/tests/examples/__snapshots__/example03.snap.svg +64 -64
- package/tests/examples/__snapshots__/example28.snap.svg +21 -18
- package/tests/examples/__snapshots__/example32.snap.svg +3 -3
- package/tests/examples/__snapshots__/example48.snap.svg +30 -30
- package/tests/examples/__snapshots__/example49.snap.svg +1 -1
- package/tests/repros/__snapshots__/repro51-overlap-junction-crossing.snap.svg +177 -0
- package/tests/repros/assets/repro51-overlap-junction-crossing.input.json +129 -0
- package/tests/repros/repro51-overlap-junction-crossing.test.ts +99 -0
|
@@ -20,8 +20,7 @@ import type {
|
|
|
20
20
|
TracePathScore,
|
|
21
21
|
} from "./types"
|
|
22
22
|
|
|
23
|
-
const
|
|
24
|
-
const LABEL_HUG_CLEARANCE = 0.001
|
|
23
|
+
const LABEL_CLEARANCE = 0.1
|
|
25
24
|
|
|
26
25
|
export const findBestReroutePath = ({
|
|
27
26
|
trace,
|
|
@@ -102,7 +101,7 @@ export const generateRerouteCandidateResults = ({
|
|
|
102
101
|
trace,
|
|
103
102
|
label,
|
|
104
103
|
problem: inputProblem,
|
|
105
|
-
paddingBuffer:
|
|
104
|
+
paddingBuffer: LABEL_CLEARANCE,
|
|
106
105
|
detourCount: 0,
|
|
107
106
|
}),
|
|
108
107
|
...generateEndpointDetourCandidates(trace, label),
|
|
@@ -188,9 +187,11 @@ const generateEndpointDetourCandidates = (
|
|
|
188
187
|
const start = trace.tracePath[0]
|
|
189
188
|
const end = trace.tracePath[trace.tracePath.length - 1]
|
|
190
189
|
if (!start || !end) return []
|
|
190
|
+
const startExit = trace.tracePath[1] ?? start
|
|
191
|
+
const endEntry = trace.tracePath[trace.tracePath.length - 2] ?? end
|
|
191
192
|
|
|
192
193
|
const bounds = getRectBounds(label.center, label.width, label.height)
|
|
193
|
-
const padding =
|
|
194
|
+
const padding = LABEL_CLEARANCE
|
|
194
195
|
const labelDirection = dir(label.orientation)
|
|
195
196
|
const labelSideX =
|
|
196
197
|
labelDirection.x < 0 ? bounds.minX - padding : bounds.maxX + padding
|
|
@@ -204,18 +205,22 @@ const generateEndpointDetourCandidates = (
|
|
|
204
205
|
candidates.push(
|
|
205
206
|
[
|
|
206
207
|
start,
|
|
207
|
-
|
|
208
|
+
startExit,
|
|
209
|
+
{ x: startExit.x, y: topY },
|
|
208
210
|
{ x: sideX, y: topY },
|
|
209
211
|
{ x: sideX, y: bottomY },
|
|
210
|
-
{ x:
|
|
212
|
+
{ x: endEntry.x, y: bottomY },
|
|
213
|
+
endEntry,
|
|
211
214
|
end,
|
|
212
215
|
],
|
|
213
216
|
[
|
|
214
217
|
start,
|
|
215
|
-
|
|
218
|
+
startExit,
|
|
219
|
+
{ x: startExit.x, y: bottomY },
|
|
216
220
|
{ x: sideX, y: bottomY },
|
|
217
221
|
{ x: sideX, y: topY },
|
|
218
|
-
{ x:
|
|
222
|
+
{ x: endEntry.x, y: topY },
|
|
223
|
+
endEntry,
|
|
219
224
|
end,
|
|
220
225
|
],
|
|
221
226
|
)
|
|
@@ -231,6 +236,8 @@ const generateLabelHugCandidates = (
|
|
|
231
236
|
const start = trace.tracePath[0]
|
|
232
237
|
const end = trace.tracePath[trace.tracePath.length - 1]
|
|
233
238
|
if (!start || !end) return []
|
|
239
|
+
const startExit = trace.tracePath[1] ?? start
|
|
240
|
+
const endEntry = trace.tracePath[trace.tracePath.length - 2] ?? end
|
|
234
241
|
|
|
235
242
|
const labelDirection = dir(label.orientation)
|
|
236
243
|
if (labelDirection.x === 0) return []
|
|
@@ -238,29 +245,33 @@ const generateLabelHugCandidates = (
|
|
|
238
245
|
const bounds = getRectBounds(label.center, label.width, label.height)
|
|
239
246
|
const sideX =
|
|
240
247
|
labelDirection.x < 0
|
|
241
|
-
? bounds.minX -
|
|
242
|
-
: bounds.maxX +
|
|
243
|
-
const topY = bounds.maxY +
|
|
244
|
-
const bottomY = bounds.minY -
|
|
245
|
-
const startsAboveEnd =
|
|
248
|
+
? bounds.minX - LABEL_CLEARANCE
|
|
249
|
+
: bounds.maxX + LABEL_CLEARANCE
|
|
250
|
+
const topY = bounds.maxY + LABEL_CLEARANCE
|
|
251
|
+
const bottomY = bounds.minY - LABEL_CLEARANCE
|
|
252
|
+
const startsAboveEnd = startExit.y >= endEntry.y
|
|
246
253
|
const firstY = startsAboveEnd ? topY : bottomY
|
|
247
254
|
const secondY = startsAboveEnd ? bottomY : topY
|
|
248
255
|
|
|
249
256
|
return [
|
|
250
257
|
[
|
|
251
258
|
start,
|
|
252
|
-
|
|
259
|
+
startExit,
|
|
260
|
+
{ x: startExit.x, y: firstY },
|
|
253
261
|
{ x: sideX, y: firstY },
|
|
254
262
|
{ x: sideX, y: secondY },
|
|
255
|
-
{ x:
|
|
263
|
+
{ x: endEntry.x, y: secondY },
|
|
264
|
+
endEntry,
|
|
256
265
|
end,
|
|
257
266
|
],
|
|
258
267
|
[
|
|
259
268
|
start,
|
|
260
|
-
|
|
269
|
+
startExit,
|
|
270
|
+
{ x: startExit.x, y: secondY },
|
|
261
271
|
{ x: sideX, y: secondY },
|
|
262
272
|
{ x: sideX, y: firstY },
|
|
263
|
-
{ x:
|
|
273
|
+
{ x: endEntry.x, y: firstY },
|
|
274
|
+
endEntry,
|
|
264
275
|
end,
|
|
265
276
|
],
|
|
266
277
|
]
|
|
@@ -341,9 +352,9 @@ const generateHorizontalSegmentPushCandidate = (
|
|
|
341
352
|
return null
|
|
342
353
|
}
|
|
343
354
|
|
|
344
|
-
let segmentPushX = bounds.minX -
|
|
355
|
+
let segmentPushX = bounds.minX - LABEL_CLEARANCE
|
|
345
356
|
if (labelDirection.x > 0) {
|
|
346
|
-
segmentPushX = bounds.maxX +
|
|
357
|
+
segmentPushX = bounds.maxX + LABEL_CLEARANCE
|
|
347
358
|
}
|
|
348
359
|
const segmentPushStartY = getClearedHorizontalY({
|
|
349
360
|
start: previousAnchor,
|
|
@@ -393,10 +404,10 @@ const getClearedHorizontalY = ({
|
|
|
393
404
|
|
|
394
405
|
const labelCenterY = (labelBounds.minY + labelBounds.maxY) / 2
|
|
395
406
|
if (start.y >= labelCenterY) {
|
|
396
|
-
return labelBounds.maxY +
|
|
407
|
+
return labelBounds.maxY + LABEL_CLEARANCE
|
|
397
408
|
}
|
|
398
409
|
|
|
399
|
-
return labelBounds.minY -
|
|
410
|
+
return labelBounds.minY - LABEL_CLEARANCE
|
|
400
411
|
}
|
|
401
412
|
|
|
402
413
|
const markSelectedCandidate = (
|