1export function layoutIssues(rects, w, h) { 2 const issues = []; 3 for (const r of rects) { 4 if (!r.essential) continue; 5 if (r.x < -0.5 || r.y < -0.5 || r.x + r.w > w + 0.5 || r.y + r.h > h + 0.5) issues.push(`${r.name} outside viewport: x=${r.x | 0} y=${r.y | 0} w=${r.w | 0} h=${r.h | 0} in ${w}x${h}`); 6 } 7 const contains = (a, b) => a.x <= b.x + 1 && a.y <= b.y + 1 && a.x + a.w >= b.x + b.w - 1 && a.y + a.h >= b.y + b.h - 1; 8 for (let i = 0; i < rects.length; i++) { 9 for (let j = i + 1; j < rects.length; j++) { 10 const a = rects[i]; 11 const b = rects[j]; 12 const ox = Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x); 13 const oy = Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y); 14 if (ox > 1 && oy > 1 && !contains(a, b) && !contains(b, a)) issues.push(`${a.name} overlaps ${b.name} by ${ox | 0}x${oy | 0}px`); 15 } 16 } 17 return issues; 18}