@tscircuit/schematic-trace-solver 0.0.121 → 0.0.123

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.
Files changed (48) hide show
  1. package/dist/index.d.ts +10 -3
  2. package/dist/index.js +247 -31
  3. package/lib/solvers/RailNetLabelCornerPlacementSolver/RailNetLabelCornerPlacementSolver.ts +223 -21
  4. package/lib/solvers/RailNetLabelCornerPlacementSolver/types.ts +3 -3
  5. package/lib/solvers/SameNetJunctionAlignmentSolver/alignSameNetJunctions.ts +50 -5
  6. package/lib/solvers/SameNetJunctionAlignmentSolver/pathIntersectsAnyNetLabel.ts +29 -0
  7. package/lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts +34 -9
  8. package/package.json +1 -1
  9. package/site/bug-reports/bug-report-20260804T095800Z.page.tsx +4 -0
  10. package/site/bug-reports/bug-report-20260804T171919Z.page.tsx +4 -0
  11. package/site/bug-reports/bug-report-20260804T225912Z.page.tsx +4 -0
  12. package/tests/bug-reports/bug-report-20260706T213649Z/__snapshots__/bug-report-20260706T213649Z.snap.svg +4 -4
  13. package/tests/bug-reports/bug-report-20260706T220324Z/__snapshots__/bug-report-20260706T220324Z.snap.svg +5 -5
  14. package/tests/bug-reports/bug-report-20260717T042845Z/__snapshots__/bug-report-20260717T042845Z.snap.svg +12 -12
  15. package/tests/bug-reports/bug-report-20260721T221026Z/__snapshots__/bug-report-20260721T221026Z.snap.svg +2 -2
  16. package/tests/bug-reports/bug-report-20260728T144234Z/__snapshots__/bug-report-20260728T144234Z.snap.svg +2 -2
  17. package/tests/bug-reports/bug-report-20260804T095800Z/__snapshots__/bug-report-20260804T095800Z.snap.svg +135 -0
  18. package/tests/bug-reports/bug-report-20260804T095800Z/bug-report-20260804T095800Z.json +634 -0
  19. package/tests/bug-reports/bug-report-20260804T095800Z/bug-report-20260804T095800Z.test.ts +12 -0
  20. package/tests/bug-reports/bug-report-20260804T171919Z/__snapshots__/bug-report-20260804T171919Z.snap.svg +355 -0
  21. package/tests/bug-reports/bug-report-20260804T171919Z/bug-report-20260804T171919Z.json +1775 -0
  22. package/tests/bug-reports/bug-report-20260804T171919Z/bug-report-20260804T171919Z.test.ts +12 -0
  23. package/tests/bug-reports/bug-report-20260804T225912Z/__snapshots__/bug-report-20260804T225912Z.snap.svg +60 -0
  24. package/tests/bug-reports/bug-report-20260804T225912Z/bug-report-20260804T225912Z.json +148 -0
  25. package/tests/bug-reports/bug-report-20260804T225912Z/bug-report-20260804T225912Z.test.ts +12 -0
  26. package/tests/examples/__snapshots__/example12.snap.svg +2 -2
  27. package/tests/examples/__snapshots__/example13.snap.svg +4 -4
  28. package/tests/examples/__snapshots__/example14.snap.svg +36 -36
  29. package/tests/examples/__snapshots__/example31.snap.svg +6 -6
  30. package/tests/examples/__snapshots__/example43.snap.svg +2 -2
  31. package/tests/examples/__snapshots__/example44.snap.svg +2 -2
  32. package/tests/repros/__snapshots__/board-15984-same-net-junction.snap.svg +2 -2
  33. package/tests/repros/__snapshots__/bugreport-001-gnd-overlap.snap.svg +26 -26
  34. package/tests/repros/__snapshots__/netlabel-connector-through-rail-label.snap.svg +2 -2
  35. package/tests/repros/__snapshots__/repro-atmega328p-fault-pullup.snap.svg +2 -2
  36. package/tests/repros/__snapshots__/repro-atmega328p-missing-gnd-netlabel.snap.svg +2 -2
  37. package/tests/repros/__snapshots__/repro-bq25895-cross-net-trace-overlap.snap.svg +2 -2
  38. package/tests/repros/__snapshots__/repro-missing-trace-netlabel.snap.svg +18 -18
  39. package/tests/repros/__snapshots__/repro-netlabel-overlap-trace.snap.svg +3 -3
  40. package/tests/repros/__snapshots__/repro-nrf52810-clock-routing.snap.svg +82 -0
  41. package/tests/repros/__snapshots__/repro161-power-section-autolayout.snap.svg +112 -0
  42. package/tests/repros/assets/repro-nrf52810-clock-routing.input.json +234 -0
  43. package/tests/repros/assets/repro161-power-section-autolayout.input.json +578 -0
  44. package/tests/repros/repro-bq25895-cross-net-trace-overlap.test.ts +13 -0
  45. package/tests/repros/repro-missing-trace-netlabel.test.ts +12 -0
  46. package/tests/repros/repro-netlabel-overlap-trace.test.ts +38 -0
  47. package/tests/repros/repro-nrf52810-clock-routing.test.ts +28 -0
  48. package/tests/repros/repro161-power-section-autolayout.test.ts +34 -0
@@ -1,13 +1,19 @@
1
1
  import type { GraphicsObject } from "graphics-debug"
2
+ import type { Point } from "@tscircuit/math-utils"
2
3
  import { traceCrossesBoundsInterior } from "lib/solvers/AvailableNetOrientationSolver/geometry"
3
4
  import { BaseSolver } from "lib/solvers/BaseSolver/BaseSolver"
5
+ import { moveAttachedLabelsToReroutedTrace } from "lib/solvers/Example28Solver/labelMovement"
4
6
  import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
5
7
  import {
6
8
  getCenterFromAnchor,
7
9
  getRectBounds,
8
10
  } from "lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/geometry"
9
11
  import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
12
+ import { isPathCollidingWithObstacles } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/collisions"
13
+ import { getObstacleRects } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/rect"
14
+ import { simplifyPath } from "lib/solvers/TraceCleanupSolver/simplifyPath"
10
15
  import type { InputProblem } from "lib/types/InputProblem"
16
+ import { doesPathOverlapTraceStrokes } from "lib/utils/doesPathCoincideWithTraces"
11
17
  import {
12
18
  EPS,
13
19
  getDistance,
@@ -95,6 +101,7 @@ export class RailNetLabelCornerPlacementSolver extends BaseSolver {
95
101
 
96
102
  getOutput() {
97
103
  return {
104
+ traces: this.traces,
98
105
  netLabelPlacements: this.outputNetLabelPlacements,
99
106
  }
100
107
  }
@@ -163,7 +170,7 @@ export class RailNetLabelCornerPlacementSolver extends BaseSolver {
163
170
  center,
164
171
  width: label.width,
165
172
  height: label.height,
166
- status: this.getCandidateStatus(bounds, labelIndex),
173
+ status: this.getCandidateStatus(bounds, labelIndex, candidate),
167
174
  selected: false,
168
175
  }
169
176
  }
@@ -171,11 +178,27 @@ export class RailNetLabelCornerPlacementSolver extends BaseSolver {
171
178
  private getCandidateStatus(
172
179
  bounds: Bounds,
173
180
  labelIndex: number,
181
+ candidate: TraceCornerCandidate,
174
182
  ): CornerCandidateStatus {
175
183
  if (this.intersectsAnyChip(bounds)) return "chip-collision"
176
184
  if (rectIntersectsAnyTextBox(bounds, this.inputProblem))
177
185
  return "text-collision"
178
- if (traceCrossesBoundsInterior(bounds, this.traceMap)) {
186
+ const candidateTraceMap = candidate.reroutedTracePath
187
+ ? {
188
+ ...this.traceMap,
189
+ [candidate.traceId]: {
190
+ ...this.traceMap[candidate.traceId]!,
191
+ tracePath: candidate.reroutedTracePath,
192
+ },
193
+ }
194
+ : this.traceMap
195
+ if (traceCrossesBoundsInterior(bounds, candidateTraceMap)) {
196
+ return "trace-collision"
197
+ }
198
+ if (
199
+ candidate.reroutedTracePath &&
200
+ !this.isReroutedTraceClear(candidate, labelIndex)
201
+ ) {
179
202
  return "trace-collision"
180
203
  }
181
204
  if (this.intersectsAnyOtherNetLabel(bounds, labelIndex)) {
@@ -190,6 +213,24 @@ export class RailNetLabelCornerPlacementSolver extends BaseSolver {
190
213
  label: NetLabelPlacement,
191
214
  candidate: EvaluatedCornerCandidate,
192
215
  ) {
216
+ if (candidate.reroutedTracePath) {
217
+ const originalTrace = this.traceMap[candidate.traceId]!
218
+ const reroutedTrace = {
219
+ ...originalTrace,
220
+ tracePath: candidate.reroutedTracePath,
221
+ }
222
+ this.traces = this.traces.map((trace) =>
223
+ trace.mspPairId === candidate.traceId ? reroutedTrace : trace,
224
+ )
225
+ this.traceMap[candidate.traceId] = reroutedTrace
226
+ this.outputNetLabelPlacements = moveAttachedLabelsToReroutedTrace({
227
+ trace: originalTrace,
228
+ originalTracePath: originalTrace.tracePath,
229
+ reroutedTracePath: candidate.reroutedTracePath,
230
+ netLabelPlacements: this.outputNetLabelPlacements,
231
+ })
232
+ }
233
+
193
234
  this.outputNetLabelPlacements[labelIndex] = {
194
235
  ...label,
195
236
  anchorPoint: candidate.anchorPoint,
@@ -225,36 +266,197 @@ export class RailNetLabelCornerPlacementSolver extends BaseSolver {
225
266
  }
226
267
 
227
268
  private getCornerCandidatesForLabel(label: NetLabelPlacement) {
228
- const isVertical = label.orientation === "y+" || label.orientation === "y-"
229
- const candidates: TraceCornerCandidate[] = []
230
- const seenCornerKeys = new Set<string>()
269
+ const anchorAlignedCandidates: TraceCornerCandidate[] = []
270
+ const railAlignedCandidates: TraceCornerCandidate[] = []
271
+ const labelTraces = this.getTraceLinesForLabel(label)
272
+ const allowRailAlignedFallback =
273
+ this.isConfiguredRailLabel(label) &&
274
+ !labelTraces.some((trace) =>
275
+ getTraceCorners(trace.tracePath).some((corner) =>
276
+ this.pointsEqual(corner, label.anchorPoint),
277
+ ),
278
+ )
231
279
 
232
- for (const trace of this.getTraceLinesForLabel(label)) {
280
+ for (const trace of labelTraces) {
233
281
  const path = trace.tracePath
234
282
  const pins = [path[0]!, path[path.length - 1]!]
235
283
  for (const anchorPoint of getTraceCorners(path)) {
236
- const key = `${anchorPoint.x}:${anchorPoint.y}`
237
- if (seenCornerKeys.has(key)) continue
238
- seenCornerKeys.add(key)
239
- const pinAligned = pins.some((pin) => {
240
- if (isVertical) return Math.abs(pin.x - anchorPoint.x) < EPS
241
- return Math.abs(pin.y - anchorPoint.y) < EPS
242
- })
243
- // Only pin-aligned corners are worth snapping a rail label to (a clean
244
- // stub off a pin). Non-aligned corners are no better than where the
245
- // label already is, so they aren't offered as candidates — this keeps
246
- // already-well-placed labels untouched.
284
+ const cornerIndex = path.indexOf(anchorPoint)
285
+ const anchorAlignedToPin = pins.some(
286
+ (pin) => Math.abs(pin.x - anchorPoint.x) <= EPS,
287
+ )
288
+ const pinAligned =
289
+ anchorAlignedToPin ||
290
+ (allowRailAlignedFallback &&
291
+ this.isPinAlignedCorner(path, cornerIndex))
247
292
  if (!pinAligned) continue
248
- candidates.push({
293
+
294
+ const candidates = anchorAlignedToPin
295
+ ? anchorAlignedCandidates
296
+ : railAlignedCandidates
297
+ candidates.push(
298
+ {
299
+ anchorPoint,
300
+ traceId: trace.mspPairId,
301
+ distance: getDistance(anchorPoint, label.anchorPoint),
302
+ pinAligned,
303
+ },
304
+ ...this.getClearanceShiftedCornerCandidates({
305
+ label,
306
+ trace,
307
+ cornerIndex,
308
+ pinAligned,
309
+ }),
310
+ )
311
+ }
312
+ }
313
+
314
+ return [
315
+ ...anchorAlignedCandidates.sort((a, b) => a.distance - b.distance),
316
+ ...railAlignedCandidates.sort((a, b) => a.distance - b.distance),
317
+ ]
318
+ }
319
+
320
+ private isConfiguredRailLabel(label: NetLabelPlacement) {
321
+ if (!label.netId) return false
322
+ return this.inputProblem.availableNetLabelOrientations[label.netId]?.some(
323
+ (orientation) => orientation === "y+" || orientation === "y-",
324
+ )
325
+ }
326
+
327
+ private pointsEqual(a: Point, b: Point) {
328
+ return Math.abs(a.x - b.x) <= EPS && Math.abs(a.y - b.y) <= EPS
329
+ }
330
+
331
+ private getVerticalSegmentPointIndices(path: Point[], cornerIndex: number) {
332
+ const corner = path[cornerIndex]!
333
+ const previousIsVertical =
334
+ Math.abs(path[cornerIndex - 1]!.x - corner.x) <= EPS
335
+ const nextIsVertical = Math.abs(path[cornerIndex + 1]!.x - corner.x) <= EPS
336
+ if (previousIsVertical === nextIsVertical) return null
337
+
338
+ const indices = previousIsVertical
339
+ ? [cornerIndex - 1, cornerIndex]
340
+ : [cornerIndex, cornerIndex + 1]
341
+ return indices
342
+ }
343
+
344
+ private isPinAlignedCorner(path: Point[], cornerIndex: number) {
345
+ const verticalPointIndices = this.getVerticalSegmentPointIndices(
346
+ path,
347
+ cornerIndex,
348
+ )
349
+ if (!verticalPointIndices) return false
350
+
351
+ const [startIndex, endIndex] = verticalPointIndices
352
+ return startIndex! <= 1 || endIndex! >= path.length - 2
353
+ }
354
+
355
+ private getClearanceShiftedCornerCandidates({
356
+ label,
357
+ trace,
358
+ cornerIndex,
359
+ pinAligned,
360
+ }: {
361
+ label: NetLabelPlacement
362
+ trace: SolvedTracePath
363
+ cornerIndex: number
364
+ pinAligned: boolean
365
+ }): TraceCornerCandidate[] {
366
+ if (label.orientation !== "y+" && label.orientation !== "y-") return []
367
+
368
+ const path = trace.tracePath
369
+ const corner = path[cornerIndex]!
370
+ const verticalPointIndices = this.getVerticalSegmentPointIndices(
371
+ path,
372
+ cornerIndex,
373
+ )
374
+ if (
375
+ !verticalPointIndices ||
376
+ verticalPointIndices.includes(0) ||
377
+ verticalPointIndices.includes(path.length - 1)
378
+ ) {
379
+ return []
380
+ }
381
+
382
+ const center = getCenterFromAnchor(
383
+ corner,
384
+ label.orientation,
385
+ label.width,
386
+ label.height,
387
+ )
388
+ const labelBounds = getRectBounds(center, label.width, label.height)
389
+ const collidingChipBounds = this.inputProblem.chips
390
+ .map((chip) => getRectBounds(chip.center, chip.width, chip.height))
391
+ .filter((chipBounds) => rectsOverlap(labelBounds, chipBounds))
392
+ const shiftedCoordinates = new Set<number>()
393
+ for (const chipBounds of collidingChipBounds) {
394
+ shiftedCoordinates.add(chipBounds.minX - label.width / 2)
395
+ shiftedCoordinates.add(chipBounds.maxX + label.width / 2)
396
+ }
397
+
398
+ return [...shiftedCoordinates].flatMap((x) => {
399
+ if (Math.abs(x - corner.x) <= EPS) return []
400
+ const reroutedTracePath = simplifyPath(
401
+ path.map((point, pointIndex) =>
402
+ verticalPointIndices.includes(pointIndex) ? { ...point, x } : point,
403
+ ),
404
+ )
405
+ const anchorPoint = { x, y: corner.y }
406
+ const remainsCorner = getTraceCorners(reroutedTracePath).some((point) =>
407
+ this.pointsEqual(point, anchorPoint),
408
+ )
409
+ if (!remainsCorner) return []
410
+
411
+ return [
412
+ {
249
413
  anchorPoint,
250
414
  traceId: trace.mspPairId,
251
415
  distance: getDistance(anchorPoint, label.anchorPoint),
252
416
  pinAligned,
253
- })
254
- }
417
+ reroutedTracePath,
418
+ },
419
+ ]
420
+ })
421
+ }
422
+
423
+ private isReroutedTraceClear(
424
+ candidate: TraceCornerCandidate,
425
+ labelIndex: number,
426
+ ) {
427
+ const reroutedTracePath = candidate.reroutedTracePath!
428
+ if (
429
+ isPathCollidingWithObstacles(
430
+ reroutedTracePath,
431
+ getObstacleRects(this.inputProblem),
432
+ )
433
+ ) {
434
+ return false
435
+ }
436
+
437
+ const candidateTrace = this.traceMap[candidate.traceId]!
438
+ const otherNetTraces = this.traces.filter(
439
+ (trace) =>
440
+ trace.mspPairId !== candidate.traceId &&
441
+ trace.globalConnNetId !== candidateTrace.globalConnNetId,
442
+ )
443
+ if (doesPathOverlapTraceStrokes(reroutedTracePath, otherNetTraces)) {
444
+ return false
255
445
  }
256
446
 
257
- return candidates.sort((a, b) => a.distance - b.distance)
447
+ const reroutedTraceMap = {
448
+ [candidate.traceId]: {
449
+ ...candidateTrace,
450
+ tracePath: reroutedTracePath,
451
+ },
452
+ }
453
+ return this.outputNetLabelPlacements.every((label, index) => {
454
+ if (index === labelIndex) return true
455
+ return !traceCrossesBoundsInterior(
456
+ getRectBounds(label.center, label.width, label.height),
457
+ reroutedTraceMap,
458
+ )
459
+ })
258
460
  }
259
461
 
260
462
  private getTraceLinesForLabel(label: NetLabelPlacement) {
@@ -21,11 +21,11 @@ export type TraceCornerCandidate = {
21
21
  traceId: string
22
22
  distance: number
23
23
  /**
24
- * True when the corner lines up with one of the trace's pins along the
25
- * label's stub axis (same x for a vertical rail label), so the label reads as
26
- * a clean stub off that pin rather than floating over a mid-trace bend.
24
+ * True when the corner is on a vertical rail that connects directly to one
25
+ * of the trace's endpoint pins, rather than on an arbitrary middle bend.
27
26
  */
28
27
  pinAligned: boolean
28
+ reroutedTracePath?: Point[]
29
29
  }
30
30
 
31
31
  export type CornerCandidateStatus =
@@ -12,7 +12,10 @@ import {
12
12
  } from "lib/solvers/TraceCleanupSolver/sameNetRailAlignment/geometry"
13
13
  import type { InputPin, InputProblem } from "lib/types/InputProblem"
14
14
  import { doesPathCoincideWithTraces } from "lib/utils/doesPathCoincideWithTraces"
15
- import { pathIntersectsAnyNetLabel } from "./pathIntersectsAnyNetLabel"
15
+ import {
16
+ pathEntersAnyNetLabel,
17
+ pathIntersectsAnyNetLabel,
18
+ } from "./pathIntersectsAnyNetLabel"
16
19
 
17
20
  interface AlignSameNetJunctionsInput {
18
21
  inputProblem: InputProblem
@@ -25,7 +28,10 @@ interface HorizontalSegment {
25
28
  end: Point
26
29
  }
27
30
 
31
+ // Only near-level load pins should be combined onto one horizontal rail.
28
32
  const MAX_ALIGNED_LOAD_PIN_OFFSET = 0.2
33
+ // Limit label-boundary alignment to small corrections that cannot create spikes.
34
+ const MAX_SAME_NET_LABEL_BOUNDARY_RAIL_OFFSET = 0.2
29
35
 
30
36
  const getSharedPin = ({
31
37
  donorTrace,
@@ -135,11 +141,13 @@ const getAlignedBranchPath = ({
135
141
 
136
142
  const candidateIsClear = ({
137
143
  candidateTrace,
144
+ originalTrace,
138
145
  traces,
139
146
  inputProblem,
140
147
  netLabelPlacements,
141
148
  }: {
142
149
  candidateTrace: SolvedTracePath
150
+ originalTrace: SolvedTracePath
143
151
  traces: SolvedTracePath[]
144
152
  inputProblem: InputProblem
145
153
  netLabelPlacements: NetLabelPlacement[]
@@ -156,10 +164,46 @@ const candidateIsClear = ({
156
164
  return false
157
165
  }
158
166
 
159
- return !pathIntersectsAnyNetLabel({
160
- path: candidateTrace.tracePath,
161
- netLabelPlacements,
162
- })
167
+ const otherNetLabelPlacements = netLabelPlacements.filter(
168
+ (label) => label.globalConnNetId !== candidateTrace.globalConnNetId,
169
+ )
170
+ if (
171
+ pathIntersectsAnyNetLabel({
172
+ path: candidateTrace.tracePath,
173
+ netLabelPlacements: otherNetLabelPlacements,
174
+ })
175
+ ) {
176
+ return false
177
+ }
178
+
179
+ const sameNetLabelPlacements = netLabelPlacements.filter(
180
+ (label) => label.globalConnNetId === candidateTrace.globalConnNetId,
181
+ )
182
+ // A same-net rail may follow its label edge, but never enter the label body.
183
+ if (
184
+ !pathIntersectsAnyNetLabel({
185
+ path: candidateTrace.tracePath,
186
+ netLabelPlacements: sameNetLabelPlacements,
187
+ })
188
+ ) {
189
+ return true
190
+ }
191
+ if (
192
+ pathEntersAnyNetLabel({
193
+ path: candidateTrace.tracePath,
194
+ netLabelPlacements: sameNetLabelPlacements,
195
+ })
196
+ ) {
197
+ return false
198
+ }
199
+
200
+ const originalRail = getLongestHorizontalSegment(originalTrace)
201
+ const candidateRail = getLongestHorizontalSegment(candidateTrace)
202
+ if (!originalRail || !candidateRail) return false
203
+ return (
204
+ Math.abs(originalRail.start.y - candidateRail.start.y) <=
205
+ MAX_SAME_NET_LABEL_BOUNDARY_RAIL_OFFSET
206
+ )
163
207
  }
164
208
 
165
209
  export const alignSameNetJunctions = ({
@@ -202,6 +246,7 @@ export const alignSameNetJunctions = ({
202
246
  if (
203
247
  !candidateIsClear({
204
248
  candidateTrace,
249
+ originalTrace: branchTrace,
205
250
  traces: outputTraces,
206
251
  inputProblem,
207
252
  netLabelPlacements,
@@ -3,6 +3,9 @@ import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetL
3
3
  import { segmentIntersectsRect } from "lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/collisions"
4
4
  import { getRectBounds } from "lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/geometry"
5
5
 
6
+ // Insetting distinguishes harmless edge contact from entering the label body.
7
+ const NET_LABEL_INTERIOR_INSET = 1e-6
8
+
6
9
  export const pathIntersectsAnyNetLabel = ({
7
10
  path,
8
11
  netLabelPlacements,
@@ -20,3 +23,29 @@ export const pathIntersectsAnyNetLabel = ({
20
23
  }
21
24
  return false
22
25
  }
26
+
27
+ export const pathEntersAnyNetLabel = ({
28
+ path,
29
+ netLabelPlacements,
30
+ }: {
31
+ path: Point[]
32
+ netLabelPlacements: NetLabelPlacement[]
33
+ }) => {
34
+ for (const label of netLabelPlacements) {
35
+ const labelBounds = getRectBounds(label.center, label.width, label.height)
36
+ const labelInteriorBounds = {
37
+ minX: labelBounds.minX + NET_LABEL_INTERIOR_INSET,
38
+ minY: labelBounds.minY + NET_LABEL_INTERIOR_INSET,
39
+ maxX: labelBounds.maxX - NET_LABEL_INTERIOR_INSET,
40
+ maxY: labelBounds.maxY - NET_LABEL_INTERIOR_INSET,
41
+ }
42
+ for (let index = 0; index < path.length - 1; index++) {
43
+ if (
44
+ segmentIntersectsRect(path[index], path[index + 1], labelInteriorBounds)
45
+ ) {
46
+ return true
47
+ }
48
+ }
49
+ }
50
+ return false
51
+ }
@@ -22,6 +22,7 @@ import { LongDistancePairSolver } from "../LongDistancePairSolver/LongDistancePa
22
22
  import { MergedNetLabelObstacleSolver } from "../TraceLabelOverlapAvoidanceSolver/sub-solvers/LabelMergingSolver/LabelMergingSolver"
23
23
  import { TraceCleanupSolver } from "../TraceCleanupSolver/TraceCleanupSolver"
24
24
  import { Example28Solver } from "../Example28Solver/Example28Solver"
25
+ import { moveAttachedLabelsToReroutedTrace } from "../Example28Solver/labelMovement"
25
26
  import { AvailableNetOrientationSolver } from "../AvailableNetOrientationSolver/AvailableNetOrientationSolver"
26
27
  import { RailNetLabelCornerPlacementSolver } from "../RailNetLabelCornerPlacementSolver/RailNetLabelCornerPlacementSolver"
27
28
  import { TraceAnchoredNetLabelOverlapSolver } from "../TraceAnchoredNetLabelOverlapSolver/TraceAnchoredNetLabelOverlapSolver"
@@ -325,9 +326,8 @@ export class SchematicTracePipelineSolver extends BaseSolver {
325
326
  (instance) => [
326
327
  {
327
328
  inputProblem: instance.inputProblem,
328
- traces: Object.values(
329
- instance.postLabelTraceOverlapShiftSolver!.correctedTraceMap,
330
- ),
329
+ traces:
330
+ instance.railNetLabelCornerPlacementSolver!.getOutput().traces,
331
331
  netLabelPlacements:
332
332
  instance.railNetLabelCornerPlacementSolver!
333
333
  .outputNetLabelPlacements,
@@ -340,9 +340,8 @@ export class SchematicTracePipelineSolver extends BaseSolver {
340
340
  (instance) => [
341
341
  {
342
342
  inputProblem: instance.inputProblem,
343
- traces: Object.values(
344
- instance.postLabelTraceOverlapShiftSolver!.correctedTraceMap,
345
- ),
343
+ traces:
344
+ instance.railNetLabelCornerPlacementSolver!.getOutput().traces,
346
345
  netLabelPlacements:
347
346
  instance.traceAnchoredNetLabelOverlapSolver!
348
347
  .outputNetLabelPlacements,
@@ -379,14 +378,40 @@ export class SchematicTracePipelineSolver extends BaseSolver {
379
378
  "netLabelTraceCollisionSolver",
380
379
  NetLabelTraceCollisionSolver,
381
380
  (instance) => {
382
- const previousCollisionOutput =
381
+ const previousOutput =
383
382
  instance.preAlignmentNetLabelTraceCollisionSolver!.getOutput()
383
+ const alignmentOutput = instance.traceCleanupSolver2!.getOutput()
384
+ const previousTraceMap = new Map(
385
+ previousOutput.traces.map((trace) => [trace.mspPairId, trace]),
386
+ )
387
+ let netLabelPlacements = previousOutput.netLabelPlacements
388
+
389
+ for (const trace of alignmentOutput.traces) {
390
+ const previousTrace = previousTraceMap.get(trace.mspPairId)
391
+ if (!previousTrace || previousTrace.tracePath === trace.tracePath) {
392
+ continue
393
+ }
394
+
395
+ const currentLabels = netLabelPlacements
396
+ const movedLabels = moveAttachedLabelsToReroutedTrace({
397
+ trace: previousTrace,
398
+ originalTracePath: previousTrace.tracePath,
399
+ reroutedTracePath: trace.tracePath,
400
+ netLabelPlacements: currentLabels,
401
+ })
402
+ netLabelPlacements = movedLabels.map((movedLabel, labelIndex) => {
403
+ const label = currentLabels[labelIndex]!
404
+ return label.orientation === "y+" || label.orientation === "y-"
405
+ ? movedLabel
406
+ : label
407
+ })
408
+ }
384
409
 
385
410
  return [
386
411
  {
387
412
  inputProblem: instance.inputProblem,
388
- traces: instance.traceCleanupSolver2!.getOutput().traces,
389
- netLabelPlacements: previousCollisionOutput.netLabelPlacements,
413
+ traces: alignmentOutput.traces,
414
+ netLabelPlacements,
390
415
  },
391
416
  ]
392
417
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/schematic-trace-solver",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.121",
4
+ "version": "0.0.123",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",
@@ -0,0 +1,4 @@
1
+ import { PipelineDebugger } from "site/components/PipelineDebugger"
2
+ import inputProblem from "../../tests/bug-reports/bug-report-20260804T095800Z/bug-report-20260804T095800Z.json"
3
+
4
+ export default () => <PipelineDebugger inputProblem={inputProblem as any} />
@@ -0,0 +1,4 @@
1
+ import { PipelineDebugger } from "site/components/PipelineDebugger"
2
+ import inputProblem from "../../tests/bug-reports/bug-report-20260804T171919Z/bug-report-20260804T171919Z.json"
3
+
4
+ export default () => <PipelineDebugger inputProblem={inputProblem as any} />
@@ -0,0 +1,4 @@
1
+ import { PipelineDebugger } from "site/components/PipelineDebugger"
2
+ import inputProblem from "../../tests/bug-reports/bug-report-20260804T225912Z/bug-report-20260804T225912Z.json"
3
+
4
+ export default () => <PipelineDebugger inputProblem={inputProblem as any} />