imrishabh18/corne-keyboard

The code defines and renders two surface-mount chip components with SMT pads, silkscreen outlines, and 3D CAD models (OBJ and STEP) for PCB assembly.

Version
2.0.21
License
unset
Stars
1

scripts/finish-left-search.ts

import fs from 'node:fs'
import * as C from '@tscircuit/checks'
const base=JSON.parse(fs.readFileSync('../left-local.circuit.json','utf8'))
const fns=['checkEachPcbTraceNonOverlapping','checkPadTraceClearance','checkViaTraceClearance','checkViaPadClearance','checkSameNetViaSpacing','checkDifferentNetViaSpacing']
let best:any=base,score=Infinity
search:for(const indices of [[16],[15,16],[16,17],[15,16,17]])for(const dy of [-.015,-.03,-.05,-.08,.015,.03,.05,.08])for(const dx of [0,-.03,.03]){
const c=structuredClone(base),t=c.find((x:any)=>x.type==='pcb_trace'&&x.pcb_trace_id==='source_trace_106_mst0_0');for(const i of indices){t.route[i].x+=dx;t.route[i].y+=dy}
const e=C.dedupePcbDrcErrors(fns.flatMap(k=>(C as any)[k](c)));const s=e.reduce((v:any,x:any)=>v+100+Math.max(0,.1-(x.actual_clearance??Number(x.message.match(/gap: ([\d.-]+)/)?.[1]??0))),0)
if(s<score){score=s;best=c;console.log('candidate',indices,dx,dy,e.length,e.map((x:any)=>x.message))}
if(e.length===0)break search
}
const e=C.dedupePcbDrcErrors([...(await C.runAllRoutingChecks(best)),...C.checkCopperToBoardEdgeClearance(best),...C.checkPcbCopperOverKeepout(best)])
fs.writeFileSync('../left-clean.circuit.json',JSON.stringify(best,null,2));fs.writeFileSync('../left-clean.errors.json',JSON.stringify(e,null,2));console.log('FINAL',e.length,e)