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/generate-fixed-cap-elbows.ts

/** Run check-capacitor-orientation.tsx first. Endpoint-based generation remains
 * idempotent after elbows have been rendered. This chooses the shortest
 * diagonal-first, axis-last route within the original endpoint rectangle.
 * Geometry validation must follow generation; this does not authorize a DRC
 * change when capacitor positions, pads or via locations change.
 */
import {readFileSync,writeFileSync}from'node:fs'
import assert from 'node:assert/strict'
const input=JSON.parse(readFileSync('dist/six-layer-placed.circuit.json','utf8'))
const names=new Map(input.filter((e:any)=>e.type==='source_trace').map((e:any)=>[e.source_trace_id,e.name]))
const result:Record<string,{x:number;y:number}>={},shortLegs:any[]=[]
for(const t of input.filter((e:any)=>e.type==='pcb_trace')){
 const name=String(names.get(t.source_trace_id));if(!/^C\d+_(POWER|GROUND)$/.test(name))continue
 const a=t.route[0],b=t.route.at(-1),dx=b.x-a.x,dy=b.y-a.y,m=Math.min(Math.abs(dx),Math.abs(dy))
 if(m<1e-7||Math.abs(Math.abs(dx)-Math.abs(dy))<1e-7)continue
 const elbow={x:Number((a.x+Math.sign(dx)*m).toFixed(12)),y:Number((a.y+Math.sign(dy)*m).toFixed(12))}
 result[name]=elbow
 const first=m*Math.SQRT2,last=Math.abs(Math.abs(dx)-Math.abs(dy));if(Math.min(first,last)<.127){
  let margin:number
  if(first<last){const pad=input.find((p:any)=>p.type==='pcb_smtpad'&&p.pcb_port_id===a.start_pcb_port_id);assert(pad&&pad.width&&pad.height,`Cannot verify endpoint pad for ${name}`);margin=Math.min(pad.width/2-Math.abs(elbow.x-a.x),pad.height/2-Math.abs(elbow.y-a.y))-.127/2}
  else {const via=input.find((v:any)=>v.type==='pcb_via'&&Math.hypot(v.x-b.x,v.y-b.y)<1e-7);assert(via,`Cannot verify endpoint via for ${name}`);margin=via.outer_diameter/2-Math.hypot(elbow.x-b.x,elbow.y-b.y)-.127/2}
  assert(margin>=-1e-9,`Exposed sub-width routing leg on ${name}`)
  shortLegs.push({name,firstLengthMm:first,lastLengthMm:last,endpointContainingShortLeg:first<last?'capacitor pad':'via annulus',coveredCopperMarginMm:margin})
 }
}
writeFileSync('src/generated/fixed-cap-elbows.json',JSON.stringify(result,null,2)+'\n')
writeFileSync('dist/fixed-elbow-generation-report.json',JSON.stringify({algorithm:'Endpoint-preserving diagonal-first axis-last; inverse component transform applied at runtime',count:Object.keys(result).length,traceWidthMm:.127,shortLegs,requiredFollowup:'Render and validate all profile fixed+saved copper; verify short endpoint legs remain fully covered by their pad/via copper.'},null,2)+'\n')
console.log(`Generated ${Object.keys(result).length} fixed capacitor elbows; ${shortLegs.length} short endpoint legs verified entirely covered by pad/via copper`)