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/check-route-angles.ts
import assert from 'node:assert/strict'
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
/** Audit copper centerlines in the unrotated package frame. Vias end a planar run. */
export function auditRouteAngles(traces: Array<{route:any[];connection?:string;connection_name?:string;pcb_trace_id?:string}>, requireOctilinear=true) {
const violations: Array<{trace:string;index:number;kind:string;degrees:number}> = []
let segmentCount=0, bendCount=0, maximumTurnDegrees=0
for (const [traceIndex,trace] of traces.entries()) {
const id=trace.connection??trace.connection_name??trace.pcb_trace_id??String(traceIndex)
let previous:any=null, heading:number|undefined
for(const [index,point] of trace.route.entries()) {
if(!Number.isFinite(point.x)||!Number.isFinite(point.y)){violations.push({trace:id,index,kind:'nonfinite route coordinate',degrees:0});previous=null;heading=undefined;continue}
if(!['wire','via'].includes(point.route_type)){violations.push({trace:id,index,kind:'unsupported route primitive',degrees:0});previous=null;heading=undefined;continue}
if(point.route_type==='via'){previous=null;heading=undefined;continue}
if(typeof point.layer!=='string'||!point.layer.length){violations.push({trace:id,index,kind:'missing wire layer',degrees:0});previous=null;heading=undefined;continue}
if(!previous||previous.layer!==point.layer){previous=point;heading=undefined;continue}
const dx=point.x-previous.x,dy=point.y-previous.y
// Duplicate wire vertices cannot hide a corner; retain the prior heading.
if(Math.hypot(dx,dy)<1e-7)continue
const nextHeading=Math.atan2(dy,dx)*180/Math.PI
segmentCount++
if(requireOctilinear && Math.abs(nextHeading/45-Math.round(nextHeading/45))>1e-5)violations.push({trace:id,index,kind:'non-45-degree heading',degrees:nextHeading})
if(heading!==undefined){
const turn=Math.abs(((nextHeading-heading+540)%360)-180)
maximumTurnDegrees=Math.max(maximumTurnDegrees,turn)
if(turn>1e-5)bendCount++
if(turn>45+1e-4)violations.push({trace:id,index:index-1,kind:'turn sharper than 45 degrees',degrees:turn})
}
previous=point;heading=nextHeading
}
}
return {valid:violations.length===0,segmentCount,bendCount,maximumTurnDegrees,violations}
}
export function assertRouteAngles(traces:Parameters<typeof auditRouteAngles>[0], requireOctilinear=true) {
const report=auditRouteAngles(traces,requireOctilinear)
assert.ok(report.valid,`Route angle rule failed: ${JSON.stringify(report.violations.slice(0,12))}`)
return report
}
if(import.meta.main){
const reports=[]
for(const profile of ['native','ddr_left','ddr_top','ddr_bottom']){
const saved=JSON.parse(readFileSync(`src/generated/${profile}.trace-paths.json`,'utf8'))
const fixed=JSON.parse(readFileSync(`scripts/fixtures/${profile}.input.json`,'utf8')).input.traces
const report={saved:assertRouteAngles(saved),fixed:assertRouteAngles(fixed)}
reports.push({profile,...report})
console.log(`${profile}: all ${saved.length} saved + ${fixed.length} fixed routes satisfy 45-degree headings and maximum 45-degree turns`)
}
mkdirSync('dist',{recursive:true})
writeFileSync('dist/route-angle-audit.json',JSON.stringify(reports,null,2)+'\n')
}