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