| 342 | } |
| 343 | |
| 344 | function isReasonableLayout(layout, commitCount) { |
| 345 | if (!layout || !Array.isArray(layout.rowDrawInfo) || layout.rowDrawInfo.length !== commitCount) return false; |
| 346 | if (!Number.isFinite(layout.laneCount) || layout.laneCount < 1) return false; |
| 347 | |
| 348 | for (let i = 0; i < layout.rowDrawInfo.length; i++) { |
| 349 | const row = layout.rowDrawInfo[i]; |
| 350 | if (!row || !Number.isFinite(row.lane) || row.lane < 0) return false; |
| 351 | if (!Array.isArray(row.parentLanes) || !Array.isArray(row.lanesBefore)) return false; |
| 352 | for (let j = 0; j < row.parentLanes.length; j++) { |
| 353 | if (!Number.isFinite(row.parentLanes[j].lane) || row.parentLanes[j].lane < 0) return false; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | // If almost every row gets its own lane, the topology solver likely drifted. |
| 358 | if (commitCount >= 12 && layout.laneCount > Math.ceil(commitCount * 0.5)) return false; |
| 359 | return true; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Compute per-row graph layout using global topology (Vertex/Branch/determinePath). |