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/coalesce-fixed-vias.ts
/** Reuse a coincident-net fixed via instead of drilling an overlapping second
* hole. Every moved route is subsequently checked by emitted-copper DRC.
*/
export function coalesceFixedVias(input:any,output:any){
const changes=[]
for(const trace of output.fanoutTraces){
for(const point of trace.route){
if(point.route_type!=='via')continue
const fixed=input.obstacles.find((o:any)=>o.circuitJsonMetadata?.pcb_via_id&&o.connectedTo.includes(trace.connection_name)&&Math.hypot(o.center.x-point.x,o.center.y-point.y)>1e-6&&Math.hypot(o.center.x-point.x,o.center.y-point.y)<.5)
if(!fixed)continue
const before={x:point.x,y:point.y},after=fixed.center
for(const p of trace.route)if(Math.hypot(p.x-before.x,p.y-before.y)<1e-6){p.x=after.x;p.y=after.y}
const rendered=output.simpleRouteJson.traces.find((t:any)=>t.pcb_trace_id===trace.pcb_trace_id)
if(rendered)rendered.route=trace.route
for(const p of output.planeTerminations)if(p.connectionName===trace.connection_name&&p.via&&Math.hypot(p.via.center.x-before.x,p.via.center.y-before.y)<1e-6)p.via.center={...after}
changes.push({connection:trace.connection_name,before,after})
}
}
// Coalescing can collapse a short segment. Canonicalize coordinates and
// remove duplicate wire vertices so polygon cleanup never sees a near-zero edge.
for(const trace of output.fanoutTraces){
for(const p of trace.route){p.x=Number(p.x.toFixed(9));p.y=Number(p.y.toFixed(9))}
trace.route=trace.route.filter((p:any,i:number,r:any[])=>i===0||p.route_type!=='wire'||r[i-1].route_type!=='wire'||p.layer!==r[i-1].layer||p.width!==r[i-1].width||p.x!==r[i-1].x||p.y!==r[i-1].y)
const rendered=output.simpleRouteJson.traces.find((t:any)=>t.pcb_trace_id===trace.pcb_trace_id)
if(rendered)rendered.route=trace.route
}
return changes
}