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/repair-ddr-inherited-plane-webs.ts
/** Remove two explicitly identified inherited inner3 copper slivers. No signal edits. */
import F from '@flatten-js/core'
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{spawnSync}from'node:child_process'
import{objectHash}from'./improve-ddr-a9-power-launches'
import{refreshDdrPlaneContacts}from'./ddr-plane-contact-audit'
import{auditCompositeHostTopology}from'./ddr-composite-routing-context'
import{auditRouteAngles}from'./check-route-angles'
import{auditDdrTraceJunctions}from'./check-ddr-system-copper'
import{planeCoverageIntervals}from'./audit-ddr-host-reference-coverage'
type P={x:number,y:number}
const poly=(v:P[])=>{const p=new F.Polygon(v.map(q=>[q.x,q.y]));if([...p.faces][0]!.orientation()===1)p.reverse();return p},vertices=(f:any):P[]=>[...f.edges].map((e:any)=>({x:e.start.x,y:e.start.y}))
export function bridgeInheritedPlaneWebs(plane:any){
if(plane.type!=='pcb_copper_pour'||plane.layer!=='inner3')throw Error('Expected actual inner3 plane')
let region=poly(plane.brep_shape.outer_ring.vertices);for(const h of plane.brep_shape.inner_rings){const ring=h.vertices.map((p:P)=>new F.Point(p.x,p.y));if([...new F.Polygon(ring).faces][0]!.orientation()!==1)ring.reverse();region.addFace(ring)}
const changes:any[]=[]
for(const shift of[0,13]){
const centers=[{x:-10.800054,y:-8.500046+shift},{x:-11.1,y:-9.1+shift}],holes=centers.map(c=>plane.brep_shape.inner_rings.filter((h:any)=>poly(h.vertices).contains(new F.Point(c.x,c.y))))
if(holes.some(h=>h.length!==1)||objectHash(holes[0][0])===objectHash(holes[1][0]))throw Error('Missing two distinct inherited holes')
const gap=poly(holes[0][0].vertices).distanceTo(poly(holes[1][0].vertices))[0];if(Math.abs(gap-.00330575585486)>1e-7)throw Error('Inherited web before geometry changed')
const a=centers[0]!,b=centers[1]!,length=Math.hypot(b.x-a.x,b.y-a.y),nx=-(b.y-a.y)/length,ny=(b.x-a.x)/length,half=.1524/2,bridge=[{x:a.x+nx*half,y:a.y+ny*half},{x:b.x+nx*half,y:b.y+ny*half},{x:b.x-nx*half,y:b.y-ny*half},{x:a.x-nx*half,y:a.y-ny*half}]
// Rectangle ends lie deep inside the existing circular voids; only the narrow neck is cut.
region=F.BooleanOperations.subtract(region,poly(bridge));changes.push({centers,beforeGapMm:gap,beforeHoles:holes.map(h=>h[0]),bridge,bridgeWidthMm:.1524,operation:'Subtract explicit bridge between existing voids; no refill.'})
}
const faces=[...region.faces],outers=faces.filter(f=>f.orientation()===-1),holes=faces.filter(f=>f.orientation()===1)
if(outers.length!==1||holes.length!==plane.brep_shape.inner_rings.length-2)throw Error('Unexpected plane component/void count')
const rings=holes.map(f=>({vertices:vertices(f)})),affected=rings.filter(h=>changes.some(c=>c.centers.every((p:P)=>poly(h.vertices).contains(new F.Point(p.x,p.y))))),webs=affected.map(h=>Math.min(...rings.filter(o=>o!==h).map(o=>poly(h.vertices).distanceTo(poly(o.vertices))[0]),...[...poly(plane.brep_shape.outer_ring.vertices).edges].map(e=>poly(h.vertices).distanceTo(e.shape)[0])))
if(affected.length!==2||Math.min(...webs)<.127-1e-7)throw Error('Merged hole violates explicit provisional5mil neighboring web')
for(const h of plane.brep_shape.inner_rings)if(F.BooleanOperations.intersect(region,poly(h.vertices)).area()>1e-9)throw Error('Original void refilled')
return{plane:{...plane,brep_shape:{outer_ring:plane.brep_shape.outer_ring,inner_rings:rings}},changes,neighboringWebsMm:webs,outerComponents:1,minimumCopperWebMm:.127,provisionalFabricationRule:true,scope:'Only two inherited slivers removed. Five-mil neighboring-web review is provisional, not fabrication approval.'}
}
if(import.meta.main){
const[parentDir='dist/ddr-nineteen-d10-connected',out='dist/ddr-nineteen-inner3-web-repaired']=process.argv.slice(2),hashes:Record<string,string>={},fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{p=resolve(p);hashes[p]=fh(p);return JSON.parse(readFileSync(p,'utf8'))},write=(n:string,v:any)=>writeFileSync(resolve(out,n),JSON.stringify(v,null,2)+'\n')
if(resolve(out)===resolve(parentDir))throw Error('Isolated output required')
const parent=read(`${parentDir}/candidate.circuit.json`),prior=read(`${parentDir}/report.json`),host=read(`${parentDir}/host-bundle.json`),input=read(`${parentDir}/routing-input.json`),parentManifest=read(`${parentDir}/original-copper-replacements.json`),old=parent.find((e:any)=>e.type==='pcb_copper_pour'&&e.layer==='inner3')
if(!prior.accepted||prior.candidateCircuitSha256!==objectHash(parent)||host.traces.length!==19)throw Error('Expected frozen19 parent')
const repair=bridgeInheritedPlaneWebs(old),candidate=parent.map((e:any)=>e===old?repair.plane:e),planeAudit=refreshDdrPlaneContacts(prior.planeAudit,candidate.filter((e:any)=>e.type==='pcb_copper_pour'),candidate),lostReference:any[]=[]
for(const t of parent.filter((e:any)=>e.type==='pcb_trace'))for(let i=1;i<t.route.length;i++){const a=t.route[i-1],b=t.route[i];if(a.route_type!=='wire'||b.route_type!=='wire'||a.layer!==b.layer||!['inner2','inner4'].includes(a.layer)||Math.hypot(b.x-a.x,b.y-a.y)<1e-8)continue;const missed=(p:any)=>planeCoverageIntervals(a,b,p.brep_shape).filter(i=>!i.covered).reduce((s,i)=>s+i.lengthMm,0),before=missed(old),after=missed(repair.plane);if(after-before>1e-7)lostReference.push({traceId:t.pcb_trace_id,sourceTraceId:t.source_trace_id,segment:i,a,b,beforeUncoveredMm:before,afterUncoveredMm:after,addedUncoveredMm:after-before})}
const topology=auditCompositeHostTopology(candidate,host.traces,input.connections),angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),junctions=auditDdrTraceJunctions(candidate,input.connections)
mkdirSync(out,{recursive:true});write('repair-diagnostic.json',{repair,lostReference,topology,angles,junctions})
if(!topology.valid||!angles.valid||!junctions.valid||lostReference.length)throw Error('Repair failed actual geometry/reference gate; diagnostic only')
const copies:Record<string,any>={};for(const n of['ram-byte0-facing-progress.trace-paths.json','ram-byte1-facing-progress.trace-paths.json','exit-contract.json','ram-byte1-exit-contract.json','source-provenance.json']){copies[n]=read(`${parentDir}/${n}`);if(n.includes('contract'))copies[n]={...copies[n],candidateCircuitSha256:objectHash(candidate)}}
const manifest={captureHash:prior.captureHash,parentDirectory:resolve(parentDir),parentCircuitSha256:objectHash(parent),candidateCircuitSha256:objectHash(candidate),replacements:[{id:`pcb_copper_pour:${old.pcb_copper_pour_id}`,before:old,after:repair.plane}],inputHashes:hashes},report={...prior,accepted:true,candidateCircuitSha256:objectHash(candidate),supportCircuitSha256:objectHash(candidate),originalCopperReplacementsSha256:objectHash(manifest),planeAudit,topology,physical:topology.physical,fullCandidateAngles:angles,fixedJunctionAudit:junctions,inheritedWebRepair:{...repair,plane:undefined,lostReference},...(prior.currentE3Migration?{currentE3Migration:{...prior.currentE3Migration,planeWebPolicy:{...prior.currentE3Migration.planeWebPolicy,scope:'Provisional .127mm copper-web threshold with external .107mm reference-pour clearance; fabricator approval remains outstanding. The two inherited inner3 slivers are repaired in this candidate; see inheritedWebRepair for geometry and reference-coverage evidence.'}}}:{}),inputFileHashes:hashes}
write('candidate.circuit.json',candidate);write('host-bundle.json',host);write('routing-input.json',{...input,traces:host.traces});write('report.json',report);write('original-copper-replacements.json',manifest);write('parent-report.json',prior);write('parent-original-copper-replacements.json',parentManifest);write('host-route-report.json',{captureHash:prior.captureHash,accepted:true,topology,angles,junctions,scope:'All19 hosts unchanged after inherited plane-web repair.'});for(const[n,v]of Object.entries(copies))write(n,n==='source-provenance.json'?{inherited:v,parentCircuitSha256:objectHash(parent),candidateCircuitSha256:objectHash(candidate),manifestSha256:objectHash(manifest),inputHashes:hashes}:v)
for(const s of['audit-ddr-global-power-launches.ts','audit-ddr-host-reference-coverage.ts']){const p=spawnSync(process.execPath,[resolve(`scripts/${s}`),resolve(out)],{encoding:'utf8'});if(p.status!==0)throw Error(p.stderr||p.stdout)}
const power=JSON.parse(readFileSync(`${out}/ram-power-launch-audit.json`,'utf8')),reference=JSON.parse(readFileSync(`${out}/host-reference-coverage.json`,'utf8'));if(power.launchQualified!==56)throw Error('Power regression');Object.assign(report,{launchAuditSha256:objectHash(power),hostReferenceCoverageSha256:objectHash(reference)});write('report.json',report)
for(const[p,h]of Object.entries(hashes))if(fh(p)!==h)throw Error('Input changed');console.log(JSON.stringify({out,candidateHash:objectHash(candidate),neighboringWebsMm:repair.neighboringWebsMm,lostReference:0,power:56}))
}