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/anchor-ddr-host-endpoints.ts
import {resolveDdrTraceNet} from './ddr-verified-seed'
/** Undo solver coordinate rounding at declared terminals before generating 45°
* geometry. Resolve the real breakout layer, never a projected routing layer.
* Internal trunk vertices are left alone. This does not authorize any copper. */
export function anchorDdrHostEndpoints(trace:any, connections:any[], original:any[]) {
const name=resolveDdrTraceNet(trace,connections)
const connection=connections.find(c=>c.name===name)
if(!connection)throw Error(`Missing endpoint contract for ${name}`)
const terminals=connection.pointsToConnect.map((p:any)=>{
const exit=original.find(e=>e.type==='pcb_breakout_point'&&e.pcb_breakout_point_id===p.pointId)
if(!exit)throw Error(`Missing original terminal ${p.pointId}`)
return exit
})
const copy=structuredClone(trace), corrections:any[]=[]
for(const index of [...new Set([0,copy.route.length-1])]){
const p=copy.route[index];if(p?.route_type!=='wire')continue
const matches=terminals.filter((t:any)=>t.layer===p.layer&&Math.hypot(t.x-p.x,t.y-p.y)<=.001)
if(matches.length>1)throw Error(`Ambiguous rounded terminal for ${name}`)
const exact=matches[0];if(!exact)continue
if(p.x!==exact.x||p.y!==exact.y){
corrections.push({index,pointId:exact.pcb_breakout_point_id,from:{x:p.x,y:p.y},to:{x:exact.x,y:exact.y}})
p.x=exact.x;p.y=exact.y
}
}
return {trace:copy,corrections}
}