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

tests/ddr-host-signal-projection.test.ts

import {expect,test} from 'bun:test'
import {projectHostObstacles,boundHostPlanningRegion} from '../scripts/prepare-ddr-host-signal-projection'
const obstacle={type:'rect',center:{x:0,y:0},width:1,height:.1,layers:['inner2'],connectedTo:['source'],obstacleId:'fixed_trace_t_0_segment'}
test('signal projection keeps footprints and forces physical barrels onto all virtual layers',()=>{
 const {projected,omitted}=projectHostObstacles([obstacle,{...obstacle,obstacleId:'fixed_via_v',circuitJsonMetadata:{pcb_via_id:'v'},layers:['top','inner1','inner2','inner3','inner4','inner5','inner6','inner7','inner8','bottom'],width:.4572,height:.4572}])
 expect(projected[0].layers).toEqual(['inner1'])
 expect(projected[1].layers).toEqual(['top','inner1','inner2','bottom'])
 expect(projected[1].width).toBe(.4572)
 expect(projected.every(o=>o.netIsAssignable===false)).toBe(true)
 expect(omitted).toEqual([])
})
test('off-signal-only copper is explicitly inventoried for mandatory physical checks',()=>{
 const r=projectHostObstacles([{...obstacle,layers:['inner1']},{...obstacle,layers:['bottom']}])
 expect(r.projected).toEqual([])
 expect(r.omitted).toHaveLength(2)
 expect(r.omitted.map(o=>o.layers)).toEqual([['inner1'],['bottom']])
})
test('rotated trace rectangle partitions conservatively enclose every copper point',()=>{
 const angle=45*Math.PI/180,{projected}=projectHostObstacles([{...obstacle,ccwRotationDegrees:45}])
 expect(projected).toHaveLength(10)
 for(let i=0;i<=100;i++)for(const side of [-1,0,1]){
  const u=i/100-.5,v=side*.05,x=u*Math.cos(angle)-v*Math.sin(angle),y=u*Math.sin(angle)+v*Math.cos(angle)
  expect(projected.some(o=>Math.abs(o.center.x-x)<=o.width/2+1e-9&&Math.abs(o.center.y-y)<=o.height/2+1e-9)).toBe(true)
 }
 expect(projected.every(o=>o.ccwRotationDegrees===0)).toBe(true)
})
test('unknown obstacle geometry fails closed',()=>{
 expect(()=>projectHostObstacles([{...obstacle,width:NaN}])).toThrow()
 expect(()=>projectHostObstacles([{...obstacle,type:'polygon'}])).toThrow()
})

test('bounded planning retains closed via-plus-clearance envelope and rejects lost terminals',()=>{
 const input={bounds:{minX:-10,maxX:10,minY:-10,maxY:10},connections:[{name:'D0',pointsToConnect:[{x:3,y:0}]}],obstacles:[
 {...obstacle,center:{x:3.6,y:0},width:.2},
 {...obstacle,center:{x:3.631,y:0},width:.2},
 {...obstacle,center:{x:0,y:10.3},height:.1},
 {...obstacle,center:{x:0,y:10.5},height:.1}]}
 const r=boundHostPlanningRegion(input,3.2)
 expect(r.input.bounds.maxX).toBe(3.2)
 expect(r.input.obstacles).toHaveLength(2)
 expect(r.input.obstacles[0]).toEqual(input.obstacles[0])
 expect(r.report.expandedDomainMarginMm).toBeCloseTo(.3302)
 expect(r.report.culledObstacleCount).toBe(2)
 expect(input.obstacles).toHaveLength(4)
 expect(()=>boundHostPlanningRegion(input,2.9)).toThrow('Terminal outside')
 expect(()=>boundHostPlanningRegion(input,NaN)).toThrow()
})