import { readFileSync } from 'node:fs'; const { compData, wireData, pinData } = JSON.parse(readFileSync('H:/caiic_workspace/mothercup/hardware_design/_dump.json', 'utf8')); function onSeg(px, py, ax, ay, bx, by, tol = 4) { const cr = (bx - ax) * (py - ay) - (by - ay) * (px - ax); if (Math.abs(cr) > tol * 20) return false; return px >= Math.min(ax, bx) - tol && px <= Math.max(ax, bx) + tol && py >= Math.min(ay, by) - tol && py <= Math.max(ay, by) + tol; } function wpts(line) { if (!Array.isArray(line)) return []; if (Array.isArray(line[0])) return line.flat(); return line; } // net flags const netflags = compData.filter(c => (!c.d || c.d.trim()==='') && c.n); // For a pin at (px,py), find nets of wires touching it (pin connects at its own x,y) function netsAt(px, py) { const s = new Set(); for (const w of wireData) { const p = wpts(w.line); for (let i=0;i+3 net (pin at own x,y) ==='); for (const k of ['SW1','Q1','Q7','Q4','Q2','Q3','D1','Q5','U1','U3','U5']) { const pd = pinData[k]; if (!pd) { console.log(`${k}: not found`); continue; } console.log(`${k} (${pd.name}) @(${pd.pos.x.toFixed(0)},${pd.pos.y.toFixed(0)})`); for (const p of pd.pins) { console.log(` pin${p.num} ${p.name||''} @(${p.x.toFixed(0)},${p.y.toFixed(0)}) -> ${JSON.stringify(netsAt(p.x,p.y))}`); } } // also dump components near the power-switch region with positions console.log('\n=== components x -2000..-1500, y -1100..-400 ==='); for (const c of compData.filter(c=>c.d&&c.d.trim()).sort((a,b)=>a.x-b.x)) { if (c.x>=-2000 && c.x<=-1500 && c.y>=-1100 && c.y<=-400) console.log(` ${c.d}:${c.n||''} @(${c.x.toFixed(0)},${c.y.toFixed(0)})`); }