0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
scripts/audit-ddr-host-fixed-contacts.ts
/** Exact copper same-net contact inventory. Candidate remains untouched. */
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{verifyDdrSystemCopper,ddrCopperShapeGap}from'./check-ddr-system-copper'
import{objectHash}from'./improve-ddr-a9-power-launches'
const point=(a:any,b:any)=>Math.hypot(a.x-b.x,a.y-b.y)<1e-7
export function classifyHostFixedContact(contact:any,host:any,terminalJoinMm=.25){
if(!Number.isFinite(terminalJoinMm)||terminalJoinMm<0)throw Error('Invalid terminal join allowance')
const fresh=contact.aShape.fresh?contact.aShape:contact.bShape,fixed=contact.aShape.fresh?contact.bShape:contact.aShape,route=host.route
const indices=route.flatMap((p:any,i:number)=>{const q=route[i+1];return q&&p.route_type==='wire'&&q.route_type==='wire'&&p.layer===contact.layer&&point(p,fresh.a)&&point(q,fresh.b)?[i]:[]})
const endpoints=[route[0],route.at(-1)],joins=endpoints.filter(p=>p.layer===contact.layer&&(point(fresh.a,p)||point(fresh.b,p))&&(point(fixed.a,p)||point(fixed.b,p))),atDeclaredEndpoint=joins.length>0
let contactOutsideTerminalJoin=false
if(atDeclaredEndpoint){
const length=Math.hypot(fixed.b.x-fixed.a.x,fixed.b.y-fixed.a.y)
if(fixed.rect||fixed.polygon)contactOutsideTerminalJoin=true
else if(length>1e-7){
const from=joins.some(p=>point(p,fixed.a))?Math.min(terminalJoinMm,length):0,to=joins.some(p=>point(p,fixed.b))?Math.max(0,length-terminalJoinMm):length
if(to>from+1e-8){const lerp=(d:number)=>({x:fixed.a.x+(fixed.b.x-fixed.a.x)*d/length,y:fixed.a.y+(fixed.b.y-fixed.a.y)*d/length});contactOutsideTerminalJoin=ddrCopperShapeGap({...fixed,a:lerp(from),b:lerp(to)},fresh)<=1e-7}
}
}
return{hostTraceId:host.pcb_trace_id,hostSourceTraceId:host.source_trace_id,hostSegmentIndices:indices,fixedTraceId:fixed.traceId,fixedObjectId:fixed.join,layer:contact.layer,gapMm:contact.gapMm,terminalJoinMm,contactOutsideTerminalJoin,classification:atDeclaredEndpoint&&!contactOutsideTerminalJoin?'endpoint-contact-needs-contract-validation':'unintended-interior-contact',hostShape:fresh,fixedShape:fixed}
}
if(import.meta.main){
const dir=resolve(process.argv[2]??'dist/ddr-facing-progress-45'),out=resolve(process.argv[3]??'dist/ddr-host-fixed-contact-audit'),read=(n:string)=>JSON.parse(readFileSync(`${dir}/${n}`,'utf8')),c=read('candidate.circuit.json'),bundle=read('host-bundle.json'),input=read('routing-input.json'),ids=new Set(bundle.traces.map((t:any)=>t.pcb_trace_id)),hosts=c.filter((e:any)=>e.type==='pcb_trace'&&ids.has(e.pcb_trace_id)),r=verifyDdrSystemCopper(c.filter((e:any)=>e.type!=='pcb_trace'||!ids.has(e.pcb_trace_id)),hosts,input.connections,{},50,{reportSameNetContacts:true}),contacts=r.sameNetContacts!.map((v:any)=>classifyHostFixedContact(v,hosts.find((h:any)=>h.pcb_trace_id===(v.aShape.fresh?v.aShape:v.bShape).traceId))),suspect=contacts.filter((v:any)=>v.classification==='unintended-interior-contact'),source=(id:string)=>c.find((e:any)=>e.type==='source_trace'&&e.source_trace_id===id)
const dq12=hosts.find((h:any)=>h.source_trace_id==='source_trace_690'),saved=c.find((e:any)=>e.type==='pcb_trace'&&e.source_trace_id==='source_trace_629'),via=saved.route[2],length=(route:any[])=>route.slice(1).reduce((n,p,i)=>n+(p.route_type==='wire'&&route[i].route_type==='wire'&&p.layer===route[i].layer?Math.hypot(p.x-route[i].x,p.y-route[i].y):0),0),h=dq12.route[10],q=dq12.route[11],fraction=((via.x-h.x)*(q.x-h.x)+(via.y-h.y)*(q.y-h.y))/((q.x-h.x)**2+(q.y-h.y)**2),projection={x:h.x+fraction*(q.x-h.x),y:h.y+fraction*(q.y-h.y)},hostStartToProjection=length(dq12.route.slice(0,11))+Math.hypot(projection.x-h.x,projection.y-h.y),savedViaToExit=length(saved.route.slice(3)),sameSourcePort=source('source_trace_690').connected_source_port_ids.filter((id:string)=>source('source_trace_629').connected_source_port_ids.includes(id)),quantification={sameSourcePort,hostSourceWitness:source('source_trace_690'),savedSourceWitness:source('source_trace_629'),via,hostSegmentIndex:10,projection,centerlineMissMm:Math.hypot(projection.x-via.x,projection.y-via.y),copperGapMm:Math.hypot(projection.x-via.x,projection.y-via.y)-.2286-.06,hostStartToViaProjectionMm:hostStartToProjection,savedViaToExitMm:savedViaToExit,nominalLoopCenterlineMm:hostStartToProjection+savedViaToExit,nominalLengthBypassedAtViaMm:hostStartToProjection+savedViaToExit,hostTotalPlanarMm:length(dq12.route),scope:'The host crosses the full via annulus with a54nm centerline offset. Loop metric is nominal centerline via→savedexit→host→via projection; overlap/contact elsewhere creates additional shortcuts. This is not an EM delay or unique shortest-path calculation.'}
mkdirSync(out,{recursive:true});writeFileSync(`${out}/report.json`,JSON.stringify({captureHash:bundle.captureHash,parentCircuitSha256:objectHash(c),errors:r.errors,hostCount:hosts.length,contacts,suspect,quantification,scope:'Exact same-net host-vs-fixed contact witnesses from the full copper checker. Endpoint contacts still require explicit contract validation; non-endpoint contacts reject simple serial-path length interpretation.'},null,2));console.log(JSON.stringify({hostCount:hosts.length,contacts:contacts.length,suspect:suspect.length,affectedHosts:[...new Set(suspect.map(s=>s.hostSourceTraceId))],quantification},null,2))
}