ShiboSoftwareDev/nema8-20mm-dual-usbc-stepper-controller
BAT54C dual Schottky diode in a 3-pin SMD package, with two anodes and a shared cathode.
- Version
- 1.0.14
- License
- unset
- Stars
- 0
scripts/search-dp-horizontal.mjs
import fs from "node:fs"
import { runAllRoutingChecks } from "@tscircuit/checks"
const original = JSON.parse(fs.readFileSync("dist/index/circuit.json", "utf8"))
.filter((element) => !String(element.type).endsWith("error"))
const dpPortIds = new Set(["pcb_port_36", "pcb_port_37"])
const candidateAt = (centerX, centerY) => original.map((element) => {
const transform = (x, y) => ({
x: centerX + (y - 2.5),
y: centerY - x,
})
if (element.type === "pcb_trace") {
return {
...element,
route: element.route.map((point) => (
dpPortIds.has(point.start_pcb_port_id) || dpPortIds.has(point.end_pcb_port_id)
? { ...point, ...transform(point.x, point.y) }
: point
)),
}
}
if (element.pcb_component_id === "pcb_component_6" && typeof element.x === "number") {
return {
...element,
...transform(element.x, element.y),
...(typeof element.width === "number" ? { width: element.height, height: element.width } : {}),
...(typeof element.rotation === "number" ? { rotation: element.rotation - 90 } : {}),
}
}
if (element.type === "pcb_component" && element.pcb_component_id === "pcb_component_6") {
return { ...element, center: { ...element.center, x: centerX, y: centerY }, rotation: (element.rotation ?? 90) - 90 }
}
return element
})
const before = await runAllRoutingChecks(original)
let best = { count: before.length, x: 0, y: 2.5, errors: before }
console.log(`start\t${before.length}`)
for (let x = -0.2; x <= 1.8 + 1e-6; x += 0.1) {
for (let y = 1.4; y <= 3.6 + 1e-6; y += 0.1) {
const errors = await runAllRoutingChecks(candidateAt(Number(x.toFixed(2)), Number(y.toFixed(2))))
if (errors.length < best.count) {
best = { count: errors.length, x, y, errors }
console.log(`best\t${best.count}\t${x.toFixed(2)},${y.toFixed(2)}`)
}
}
}
console.log(`winner\t${best.count}\t${best.x.toFixed(2)},${best.y.toFixed(2)}`)
console.log(best.errors.map((error) => error.message).join("\n"))