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/ddr-plane-contact-audit.ts
type Point={x:number;y:number}
function inside(p:Point,vertices:Point[]){let yes=false;for(let i=0,j=vertices.length-1;i<vertices.length;j=i++){const a=vertices[i]!,b=vertices[j]!;if((a.y>p.y)!==(b.y>p.y)&&p.x<(b.x-a.x)*(p.y-a.y)/(b.y-a.y)+a.x)yes=!yes}return yes}
/** Recheck existing, source-owned via contact witnesses after approved hole
* subtraction. Full conductor clearance is a separate mandatory predicate. */
export function refreshDdrPlaneContacts(previous:any[],planes:any[],circuit:any[]){
if(!Array.isArray(previous)||previous.length!==planes.length)throw Error('Missing prior plane contact audit')
const vias=circuit.flatMap((e:any)=>e.type==='pcb_via'?[{x:e.x,y:e.y,r:e.outer_diameter/2}]:e.type==='pcb_trace'?e.route.filter((p:any)=>p.route_type==='via').map((p:any)=>({x:p.x,y:p.y,r:p.via_diameter/2})):[])
return previous.map(audit=>{
const plane=planes.find(p=>p.layer===audit.layer&&p.source_net_id===audit.source_net_id)
if(!plane?.brep_shape)throw Error('Plane identity changed')
const shape=plane.brep_shape,contacts=audit.viaContacts.map((v:any)=>{
const matches=vias.filter(p=>Math.hypot(p.x-v.x,p.y-v.y)<1e-7)
if(!matches.length)throw Error('Missing actual contact via')
const radius=Math.max(...matches.map(p=>p.r))
if(!Number.isFinite(radius)||radius<=0)throw Error('Invalid contact radius')
const samples=Array.from({length:32},(_,i)=>({x:v.x+radius*.9*Math.cos(i*Math.PI/16),y:v.y+radius*.9*Math.sin(i*Math.PI/16)}))
const n=samples.filter(p=>inside(p,shape.outer_ring.vertices)&&!shape.inner_rings.some((h:any)=>inside(p,h.vertices))).length
return {...v,annulusSamplesInPlane:n,total:32}
})
const missing=contacts.filter((v:any)=>v.annulusSamplesInPlane!==32)
if(missing.length)throw Error(`Plane change loses existing via contact on ${audit.layer}`)
return {...audit,holes:shape.inner_rings.length,viaContacts:contacts,capViaContacts:contacts.filter((v:any)=>v.id.startsWith('power_plan_caps_')),missingFullAnnulusContacts:[],uniqueMissingFullAnnulusContacts:[],recheckedAfterSignalAntipads:true}
})
}