tscircuit/autorouting-dataset-01

This code manages the hardware and electronic components for circuit design and PCB layout, defining components like resistors, capacitors, transistors, connectors, and footprints, and providing tools for component placement, PCB topology, and electrical connections.

Version
1.0.102
License
unset
Stars
4

scripts/validate-srj/check.ts

import { allAreWithinOutline } from "./all-are-with-in-outline"
import { getObstacleThatHavePointsToConnect } from "./getObstacleThatHavePointsToConnect"
import { hasOverlappingObstacles } from "./hasOverlappingObstacles"
import type { OverArgs } from "./types"

/** Validates SRJs for obstacle overlaps and outline bounds violations. */
export const check = (params: OverArgs[]) => {
  const failedFileNamesForObstacleOverlap: {
    filesName: string
    which?: string
  }[] = []
  const failedFileNamesForOutOfBoardBounds: {
    filesName: string
    which: string
  }[] = []

  for (const { srj, fileName } of params) {
    const obstaclesThatHavePointsToConnect = getObstacleThatHavePointsToConnect(
      srj.obstacles,
      srj.connections.flatMap((connection) => connection.pointsToConnect),
    )
    const overlapResult = hasOverlappingObstacles(
      obstaclesThatHavePointsToConnect,
      srj.layerCount,
    )
    if (!overlapResult.ok) {
      failedFileNamesForObstacleOverlap.push({
        filesName: fileName,
        which: overlapResult.which,
      })
    }
    if (!allAreWithinOutline(obstaclesThatHavePointsToConnect, srj.bounds)) {
      failedFileNamesForOutOfBoardBounds.push({
        filesName: fileName,
        which: "",
      })
    }
  }

  failedFileNamesForObstacleOverlap.sort((a, b) =>
    a.filesName.localeCompare(b.filesName),
  )
  failedFileNamesForOutOfBoardBounds.sort((a, b) =>
    a.filesName.localeCompare(b.filesName),
  )

  return {
    failedFileNamesForObstacleOverlap,
    failedFileNamesForOutOfBoardBounds,
  }
}