impedora 0.0.0-stage → 0.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # impedora
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Impedora Board check](https://impedora.com/board-check/) on the command line: checks a KiCad board for what passes DRC but can still stop it working.
4
+
5
+ ```
6
+ npx impedora board.kicad_pcb
7
+ ```
8
+
9
+ - **Signal integrity:** the impedance of every USB, Ethernet, HDMI, PCIe, DDR and RF net (2D field solver, with your stackup and solder mask), length matching and lane skew, via stubs and loss, gaps in the reference plane, return vias, crosstalk.
10
+ - **First-board mistakes:** USB-C CC resistors, crystal placement, buck converter layout, STM32 BOOT0, ESP32 strapping pins, programming access, I2C pull-ups, LED resistors, decoupling.
11
+
12
+ The `.kicad_pro` next to the board is read for netclass impedance targets. Refill zones (press B) before saving, so the planes are in the file. Nothing is uploaded: the check runs on your machine.
13
+
14
+ ## Options
15
+
16
+ ```
17
+ --fail-on <level> exit 1 if any finding is at or above: fail (default), warn, or never
18
+ --notes list notes too
19
+ --passed list passed checks too
20
+ --json every finding as JSON
21
+ --markdown a Markdown report, for a pull request comment
22
+ --pro <file> the project file for netclass targets (default: next to the board)
23
+ --no-pro don't read a project file
24
+ ```
25
+
26
+ Exit code 0: nothing at or above `--fail-on`. 1: there is. 2: the board could not be read.
27
+
28
+ ## In GitHub Actions
29
+
30
+ ```yaml
31
+ - uses: impedora/board-check@v1
32
+ ```
33
+
34
+ See [impedora/board-check](https://github.com/impedora/board-check). Findings show as annotations and the report goes to the job summary.
35
+
36
+ Findings are estimates from the board file, not a sign-off. Free to use; not open source.
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import{readFileSync as ys,existsSync as Nr,appendFileSync as Mi}from"node:fs";import{basename as wi,resolve as bs}from"node:path";function ro(e){let t=e.length,n=[],o=0,u,d=i=>{n.length?n[n.length-1].push(i):u===void 0&&(u=i)};for(;o<t;){let i=e.charCodeAt(o);if(i===32||i===9||i===10||i===13||i===12||i===11||i===65279||i===160){o++;continue}if(i===40){let l=[];d(l),n.push(l),o++;continue}if(i===41){if(!n.length)throw new Error(`Unexpected character at position ${o}.`);if(n.pop(),o++,!n.length)return u;continue}if(i===34){o++;let l=o;for(;o<t&&e.charCodeAt(o)!==34&&e.charCodeAt(o)!==92;)o++;if(o<t&&e.charCodeAt(o)===92){let p=e.slice(l,o);for(;o<t&&e.charCodeAt(o)!==34;)e.charCodeAt(o)===92&&o+1<t?(p+=e[o+1],o+=2):p+=e[o++];o++,d(p)}else d(e.slice(l,o)),o++;continue}let a=o;for(;o<t;){let l=e.charCodeAt(o);if(l===40||l===41||l===32||l===9||l===10||l===13||l===12||l===11)break;o++}if(d(e.slice(a,o)),!n.length)return u}if(n.length)throw new Error("Unexpected end of file: unbalanced parentheses.");if(u===void 0)throw new Error(`Unexpected character at position ${o}.`);return u}var On=e=>Array.isArray(e),Ln=e=>On(e)&&typeof e[0]=="string"?e[0]:"",Nn=(e,t)=>On(e)?e.find(n=>Ln(n)===t):void 0,to=(e,t)=>On(e)?e.filter(n=>Ln(n)===t):[],Vt=(e,t)=>{let n=e?Nn(e,t):void 0;return n&&typeof n[1]=="string"?n[1]:void 0},no=/\b(gnd|ground|pwr|power|vcc|vdd|plane|agnd|dgnd)\b/i;function oo(e){if(Ln(e)!=="kicad_pcb")throw new Error("This is not a KiCad board file (.kicad_pcb).");let t=[],n=new Map;for(let i of(Nn(e,"layers")??[]).slice(1))On(i)&&typeof i[1]=="string"&&typeof i[2]=="string"&&n.set(i[1],{type:i[2],user:typeof i[3]=="string"?i[3]:void 0});let o=Nn(Nn(e,"setup")??[],"stackup");if(!o)throw new Error("This board has no physical stackup defined. In KiCad: Board Setup \u2192 Physical Stackup, then save and import again.");let u=[],d=[];for(let i of to(o,"layer")){let a=typeof i[1]=="string"?i[1]:"",l=(Vt(i,"type")??"").toLowerCase(),p=s=>s===void 0?NaN:parseFloat(s)*.001;if(l==="copper"){let s=p(Vt(i,"thickness"));d.push(a);let r=n.get(a),f=r?.user&&r.user!==a?`${a} (${r.user})`:a;u.push({kind:"copper",name:f,t:isFinite(s)?s:35e-6,er:1,plane:!1}),isFinite(s)||t.push(`${a}: no copper thickness in the file, 35 \xB5m assumed.`)}else if(l==="core"||l==="prepreg"||l.includes("dielectric")){let s=[[]];for(let M of i.slice(2))M==="addsublayer"?s.push([]):Ln(M)==="addsublayer"?s.push(M.slice(1)):s[s.length-1].push(M);let r=0,f=0,c=0,x=!0;for(let M of s){let b=p(Vt(["_",...M],"thickness")),h=parseFloat(Vt(["_",...M],"epsilon_r")??"");if(!isFinite(b))continue;r+=b,f+=b*(isFinite(h)?h:4.5);let w=parseFloat(Vt(["_",...M],"loss_tangent")??"");isFinite(w)&&w>0?c+=b*w:x=!1,isFinite(h)||t.push(`${a}: no \u03B5r in the file, 4.5 assumed.`)}let S=Vt(i,"material");u.push({kind:"dielectric",name:`${l==="core"?"Core":"Prepreg"}${S?` ${S}`:""}`,t:r,er:r>0?f/r:4.5,plane:!1,...x&&r>0?{tanD:c/r}:{}})}}if(d.length<1)throw new Error("No copper layers found in the stackup.");return u.forEach((i,a)=>{if(i.kind!=="copper")return;let l=u.slice(0,a+1).filter(r=>r.kind==="copper").length-1,p=l===0||l===d.length-1,s=n.get(d[l]);!p&&(s?.type==="power"||no.test(s?.user??"")||no.test(d[l]))&&(i.plane=!0)}),u.some(i=>i.plane)||t.push("No inner plane detected. Tick \u201CReference plane\u201D on your ground and power layers."),to(o,"layer").some(i=>(Vt(i,"type")??"").toLowerCase().includes("solder mask"))&&t.push("Solder mask is in the file but not used yet (it lowers outer-layer impedance by a few \u03A9)."),{layers:u,warnings:t}}function Kt(e,t){let n=e.findIndex(c=>c.id===t);if(n<0||e[n].kind!=="copper")return null;let o=c=>{let x=[],S=!1,M=0,b="";for(let h=n+c;h>=0&&h<e.length;h+=c){let w=e[h];if(w.kind==="copper"&&w.plane)return x.length&&(x[x.length-1].h+=M),{slabs:x,plane:!0,crossed:S,name:b};w.kind==="dielectric"?(x.length||(b=w.name),x.push({h:w.t+M,er:w.er,tanD:w.tanD??.02}),M=0):(S=!0,M+=w.t)}return{slabs:x,plane:!1,crossed:S&&x.length>0&&M===0,name:b}},u=o(-1),d=o(1);if(!u.plane&&!d.plane)return null;let[i,a]=d.plane?[d,u]:[u,d];if(!i.slabs.length)return null;let l=[...i.slabs].reverse(),p=a.slabs,s=i.slabs[0],r=a.slabs[0],f=r?{er:(s.er+r.er)/2,tanD:(s.tanD+r.tanD)/2}:void 0;return{below:l,above:p,topPlane:a.plane,fill:f,crossed:i.crossed||a.crossed,names:{below:i.name,...r?{above:a.name}:{}}}}var K=(e,t,n,o=1,u=!1,d=.02)=>({id:0,kind:e,name:t,t:n*1e-6,er:o,plane:u,...e==="dielectric"?{tanD:d}:{}}),gt=1.6*25.4,ir={"JLCPCB 2-layer, 1.6 mm (JLC0216)":()=>[K("copper","Top",gt),K("dielectric","NP-155F core",1430,4.42),K("copper","Bottom",gt,1,!0)],"JLCPCB 4-layer, 1.6 mm (JLC04161H-7628)":()=>[K("copper","L1 Top",gt),K("dielectric","7628 prepreg",210.4,4.4),K("copper","L2 (plane)",15.2,1,!0),K("dielectric","NP-155F core",1065,4.38),K("copper","L3 (plane)",15.2,1,!0),K("dielectric","7628 prepreg",210.4,4.4),K("copper","L4 Bottom",gt)],"JLCPCB 4-layer, 1.6 mm (JLC04161H-3313)":()=>[K("copper","L1 Top",gt),K("dielectric","3313 prepreg",99.4,4.1),K("copper","L2 (plane)",15.2,1,!0),K("dielectric","NP-155F core",1265,4.42),K("copper","L3 (plane)",15.2,1,!0),K("dielectric","3313 prepreg",99.4,4.1),K("copper","L4 Bottom",gt)],"JLCPCB 4-layer, 1.6 mm (JLC04161H-2116)":()=>[K("copper","L1 Top",gt),K("dielectric","2116 prepreg",116.4,4.16),K("copper","L2 (plane)",15.2,1,!0),K("dielectric","NP-155F core",1265,4.42),K("copper","L3 (plane)",15.2,1,!0),K("dielectric","2116 prepreg",116.4,4.16),K("copper","L4 Bottom",gt)],"JLCPCB 4-layer, 1.6 mm (JLC04161H-1080)":()=>[K("copper","L1 Top",gt),K("dielectric","1080 prepreg",76.4,3.91),K("copper","L2 (plane)",15.2,1,!0),K("dielectric","NP-155F core",1265,4.42),K("copper","L3 (plane)",15.2,1,!0),K("dielectric","1080 prepreg",76.4,3.91),K("copper","L4 Bottom",gt)],"JLCPCB 6-layer, 1.6 mm (JLC06161H-3313)":()=>[K("copper","L1 Top",gt),K("dielectric","3313 prepreg",99.4,4.1),K("copper","L2 (plane)",15.2,1,!0),K("dielectric","NP-155F core",550,4.41),K("copper","L3",15.2),K("dielectric","2116 prepreg",108.8,4.16),K("copper","L4",15.2),K("dielectric","NP-155F core",550,4.41),K("copper","L5 (plane)",15.2,1,!0),K("dielectric","3313 prepreg",99.4,4.1),K("copper","L6 Bottom",gt)],"JLCPCB 6-layer, 1.6 mm (JLC06161H-7628)":()=>[K("copper","L1 Top",gt),K("dielectric","7628 prepreg",210.4,4.4),K("copper","L2 (plane)",15.2,1,!0),K("dielectric","NP-155F core",400,4.36),K("copper","L3",15.2),K("dielectric","7628 prepreg",202.8,4.4),K("copper","L4",15.2),K("dielectric","NP-155F core",400,4.36),K("copper","L5 (plane)",15.2,1,!0),K("dielectric","7628 prepreg",210.4,4.4),K("copper","L6 Bottom",gt)],"PCBWay 4-layer, 1.6 mm":()=>[K("copper","L1 Top",35),K("dielectric","7628 prepreg",185.5,4.74),K("copper","L2 (plane)",35,1,!0),K("dielectric","Core",1030,4.6),K("copper","L3 (plane)",35,1,!0),K("dielectric","7628 prepreg",185.5,4.74),K("copper","L4 Bottom",35)],"PCBWay 6-layer, 1.6 mm":()=>[K("copper","L1 Top",35),K("dielectric","2116 prepreg",119.5,4.45),K("copper","L2 (plane)",35,1,!0),K("dielectric","Core",430,4.6),K("copper","L3",35),K("dielectric","7628 prepreg",175,4.74),K("copper","L4",35),K("dielectric","Core",430,4.6),K("copper","L5 (plane)",35,1,!0),K("dielectric","2116 prepreg",119.5,4.45),K("copper","L6 Bottom",35)],"Generic 4-layer, 1.6 mm (example)":()=>[K("copper","L1 Top",35),K("dielectric","Prepreg",210,4.3),K("copper","L2 GND",35,1,!0),K("dielectric","Core",1040,4.5),K("copper","L3 PWR",35,1,!0),K("dielectric","Prepreg",210,4.3),K("copper","L4 Bottom",35)],"Generic 6-layer, 1.6 mm (example)":()=>[K("copper","L1 Top",35),K("dielectric","Prepreg",100,4.2),K("copper","L2 GND",18,1,!0),K("dielectric","Core",300,4.4),K("copper","L3 Signal",18),K("dielectric","Prepreg",658,4.3),K("copper","L4 Signal",18),K("dielectric","Core",300,4.4),K("copper","L5 GND",18,1,!0),K("dielectric","Prepreg",100,4.2),K("copper","L6 Bottom",35)],"Generic 2-layer, 1.6 mm (example)":()=>[K("copper","Top",35),K("dielectric","Core",1530,4.5),K("copper","Bottom",35,1,!0)],"AISLER 4-layer, 1.6 mm":()=>[K("copper","TOP",35),K("dielectric","2\xD7 1080 prepreg",140,4.15),K("copper","IN1 (plane)",35,1,!0),K("dielectric","FR-4 core",1200,4.55),K("copper","IN2 (plane)",35,1,!0),K("dielectric","2\xD7 1080 prepreg",140,4.15),K("copper","BOT",35)],"Multi-CB 4-layer, 1.6 mm (4L-01)":()=>[K("copper","TOP",35),K("dielectric","2\xD7 1080 prepreg",140,4),K("copper","IN2 (plane)",35,1,!0),K("dielectric","FR-4 core",1200,4.6),K("copper","IN3 (plane)",35,1,!0),K("dielectric","2\xD7 1080 prepreg",140,4),K("copper","BOT",35)],"OSH Park 2-layer, 1.6 mm (FR4)":()=>[K("copper","Top",35.6),K("dielectric","KB6167F FR-4 core",1524,4.5),K("copper","Bottom",35.6,1,!0)],"OSH Park 4-layer, 1.6 mm (FR408HR)":()=>[K("copper","L1 Top",43.2),K("dielectric","FR408HR 2113 prepreg",199.9,3.61,!1,.009),K("copper","L2 (plane)",17.5,1,!0),K("dielectric","FR408HR core",990.6,3.87,!1,.009),K("copper","L3 (plane)",17.5,1,!0),K("dielectric","FR408HR 2113 prepreg",199.9,3.61,!1,.009),K("copper","L4 Bottom",43.2)],"OSH Park 6-layer, 1.6 mm (FR408HR)":()=>[K("copper","L1 Top",43.2),K("dielectric","FR408HR 106 prepreg",110.7,3.23,!1,.011),K("copper","L2 (plane)",17.5,1,!0),K("dielectric","FR408HR 2113 core",101.6,3.66,!1,.009),K("copper","L3",17.5),K("dielectric","FR408HR core",925.6,3.71,!1,.009),K("copper","L4",17.5),K("dielectric","FR408HR 2113 core",101.6,3.66,!1,.009),K("copper","L5 (plane)",17.5,1,!0),K("dielectric","FR408HR 106 prepreg",110.7,3.23,!1,.011),K("copper","L6 Bottom",43.2)]};var Mt=e=>Array.isArray(e),sn=e=>Mt(e)?e[0]:"",$t=(e,t)=>e.filter(n=>Mt(n)&&n[0]===t),ie=(e,t)=>e.find(n=>Mt(n)&&n[0]===t),pt=e=>Number(e),Ue=e=>({x:pt(e?.[1]),y:pt(e?.[2])});function ao(e){if(!e.trim())throw new Error("This file is empty. Save the board again in KiCad and drop it here.");if(!/^\s*(\uFEFF)?\s*\(\s*kicad_pcb\b/.test(e))throw new Error("This is not a KiCad board file (.kicad_pcb).");let t;try{t=ro(e)}catch{throw new Error("This board file is cut off or damaged, so it cannot be read. Save it again in KiCad and drop it here.")}if(!Mt(t)||t[0]!=="kicad_pcb")throw new Error("This is not a KiCad board file (.kicad_pcb).");let n=[],o=(ie(t,"layers")??[]).filter(Mt).filter(m=>/\.Cu$/.test(String(m[1]))).map(m=>String(m[1])),u,d="file";try{u=oo(t)}catch{d="assumed";let m=0;u={layers:Ks(o.length).map(C=>C.kind==="copper"?{...C,name:o[m++]??C.name}:C),warnings:[]},n.push(`The file has no physical stackup, so a typical 1.6 mm board is assumed${o.length>2?" (0.1 mm from each outer layer to the next copper)":""} and the impedances are rough. Set it in KiCad under Board Setup \u2192 Physical Stackup.`)}u.layers=u.layers.map(m=>m.kind==="copper"?{...m,name:m.name.replace(/ \(.*\)$/,"")}:m),n.push(...u.warnings.filter(m=>!/plane|[Ss]older mask/.test(m)));let i=u.layers.reduce((m,C)=>m+C.t,0)*1e3||pt(ie(ie(t,"general")??[],"thickness")?.[1])||1.6,a=new Map,l=m=>m.replace(/\{slash\}/g,"/").replace(/\{backslash\}/g,"\\").replace(/\{space\}/g," ").replace(/\{dblquote\}/g,'"').replace(/\{colon\}/g,":").replace(/\{lt\}/g,"<").replace(/\{gt\}/g,">");for(let m of $t(t,"net"))m.length>=3&&a.set(String(m[1]),l(String(m[2])));let p=m=>{let C=ie(m,"net");if(!C)return"";if(C.length>=3)return l(String(C[2]));let k=String(C[1]);return a.get(k)??l(k)},s=[];for(let m of t.filter(Mt)){let C=sn(m);if(C!=="segment"&&C!=="arc")continue;let k=String(ie(m,"layer")?.[1]??"");s.push({net:p(m),layer:k,w:pt(ie(m,"width")?.[1]),a:Ue(ie(m,"start")),b:Ue(ie(m,"end")),...C==="arc"?{mid:Ue(ie(m,"mid"))}:{}})}let r=[];for(let m of $t(t,"via")){let C=(ie(m,"layers")??[]).slice(1).map(String),k=m.includes("micro")?"micro":m.includes("blind")?"blind":"through",I=C[0]??o[0],R=C[C.length-1]??o[o.length-1];r.push({net:p(m),at:Ue(ie(m,"at")),size:pt(ie(m,"size")?.[1]),drill:pt(ie(m,"drill")?.[1]),from:I,to:R,kind:k==="through"&&(I!==o[0]||R!==o[o.length-1])?"blind":k})}let f=[];for(let m of $t(t,"zone")){let C=ie(m,"net_name")?.[1],k=C!==void 0?l(String(C)):p(m);for(let I of $t(m,"filled_polygon")){let R=String(ie(I,"layer")?.[1]??ie(m,"layer")?.[1]??""),N=(ie(I,"pts")??[]).filter(Mt).filter(L=>L[0]==="xy").map(Ue);if(N.length<3)continue;let A=f.find(L=>L.net===k&&L.layer===R);A||f.push(A={net:k,layer:R,polys:[]}),A.polys.push(N)}}!f.length&&$t(t,"zone").length&&n.push("The zones are not filled in this file. Refill them in KiCad (press B) and save, then load the board again.");let c=[];for(let m of $t(t,"footprint").concat($t(t,"module"))){let C=ie(m,"at"),k=Ue(C),I=Number(C?.[3]??0)||0,R=j=>{let Z=$t(m,"property").find(z=>z[1]===j);if(Z)return String(Z[2]);let ae=$t(m,"fp_text").find(z=>z[1]===j.toLowerCase());return ae?String(ae[2]):""},N=R("Reference"),A=String(ie(m,"layer")?.[1]??"F.Cu").startsWith("B")?"B":"F",L=-I*Math.PI/180,H=Math.cos(L),U=Math.sin(L),P=$t(m,"pad").map(j=>{let Z=ie(j,"at"),ae=ie(j,"size"),z=pt(Z?.[1]),oe=pt(Z?.[2]);return{ref:N,num:String(j[1]),net:p(j),at:{x:k.x+z*H-oe*U,y:k.y+z*U+oe*H},w:pt(ae?.[1]),h:pt(ae?.[2]),layers:(ie(j,"layers")??[]).slice(1).map(String),...pt(Z?.[3])?{rot:pt(Z?.[3])}:{},...ie(j,"pinfunction")?{fn:String(ie(j,"pinfunction")[1])}:{},...ie(j,"pintype")?{type:String(ie(j,"pintype")[1])}:{}}}),F=j=>({x:k.x+j.x*H-j.y*U,y:k.y+j.x*U+j.y*H}),V=j=>{let Z=[];for(let ae of m.filter(Mt).filter(z=>/^fp_(line|rect|poly)$/.test(String(z[0]))&&j.test(String(ie(z,"layer")?.[1]??""))))if(ae[0]==="fp_poly")for(let z of $t(ie(ae,"pts")??[],"xy"))Z.push(F(Ue(z)));else{let z=Ue(ie(ae,"start")),oe=Ue(ie(ae,"end"));Z.push(F(z),F(oe)),ae[0]==="fp_rect"&&Z.push(F({x:z.x,y:oe.y}),F({x:oe.x,y:z.y}))}return Z.filter(ae=>isFinite(ae.x)&&isFinite(ae.y))},O=V(/CrtYd|Fab/),G=O.length?O:V(/SilkS/),J=G.length?{x0:Math.min(...G.map(j=>j.x)),y0:Math.min(...G.map(j=>j.y)),x1:Math.max(...G.map(j=>j.x)),y1:Math.max(...G.map(j=>j.y))}:void 0;c.push({ref:N,value:R("Value"),lib:String(m[1]),at:k,side:A,pads:P,...J?{body:J}:{}})}let x=1/0,S=1/0,M=-1/0,b=-1/0,h=m=>{x=Math.min(x,m.x),S=Math.min(S,m.y),M=Math.max(M,m.x),b=Math.max(b,m.y)},w=[],v=m=>{for(let C=0;C<m.length;C++)w.push([m[C],m[(C+1)%m.length]])};for(let m of t.filter(Mt)){if(!/^gr_(line|rect|arc|circle|poly)$/.test(sn(m))||ie(m,"layer")?.[1]!=="Edge.Cuts")continue;let C=sn(m);if(C==="gr_line")w.push([Ue(ie(m,"start")),Ue(ie(m,"end"))]);else if(C==="gr_rect"){let k=Ue(ie(m,"start")),I=Ue(ie(m,"end"));v([k,{x:I.x,y:k.y},I,{x:k.x,y:I.y}])}else if(C==="gr_poly")v((ie(m,"pts")??[]).filter(Mt).filter(k=>k[0]==="xy").map(k=>Ue(k)));else if(C==="gr_circle"){let k=Ue(ie(m,"center")),I=Ue(ie(m,"end")),R=Math.hypot(I.x-k.x,I.y-k.y);v(Array.from({length:48},(N,A)=>({x:k.x+R*Math.cos(A/48*2*Math.PI),y:k.y+R*Math.sin(A/48*2*Math.PI)})))}else if(C==="gr_arc"&&ie(m,"mid"))w.push(...js(Ue(ie(m,"start")),Ue(ie(m,"mid")),Ue(ie(m,"end"))));else if(C==="gr_arc"){let k=Ue(ie(m,"start")),I=Ue(ie(m,"end")),R=pt(ie(m,"angle")?.[1])*Math.PI/180,N=Math.hypot(I.x-k.x,I.y-k.y),A=Math.atan2(I.y-k.y,I.x-k.x),L=Math.max(2,Math.ceil(Math.abs(R)/(Math.PI/24)));for(let H=0;H<L;H++)w.push([{x:k.x+N*Math.cos(A+R*H/L),y:k.y+N*Math.sin(A+R*H/L)},{x:k.x+N*Math.cos(A+R*(H+1)/L),y:k.y+N*Math.sin(A+R*(H+1)/L)}])}for(let k of["start","end","mid"]){let I=ie(m,k);I&&h(Ue(I))}for(let k of(ie(m,"pts")??[]).filter(Mt))k[0]==="xy"&&h(Ue(k));if(sn(m)==="gr_circle"){let k=Ue(ie(m,"center")),I=Ue(ie(m,"end")),R=Math.hypot(I.x-k.x,I.y-k.y);h({x:k.x-R,y:k.y-R}),h({x:k.x+R,y:k.y+R})}}if(!isFinite(x)){n.push("No board outline on Edge.Cuts: the board area is taken from the copper.");for(let m of s)h(m.a),h(m.b)}let g={x0:x,y0:S,x1:M,y1:b};if(d==="file"&&Gs(u.layers)){let m=u.layers.filter(k=>k.kind==="dielectric"),C=m.length>1&&m.every(k=>Math.abs(k.t-m[0].t)<2e-6);d=C?"assumed":"default",n.push(C?"This file's stackup is KiCad's untouched default (every dielectric the same thickness, \u03B5r 4.5), so its heights are not your fabricator's either: impedance and crosstalk results are rough notes. Set the real stackup in KiCad under Board Setup \u2192 Physical Stackup to have them checked.":"Every dielectric in this file's stackup has \u03B5r 4.5, KiCad's default, so it is probably not your fabricator's. Impedances are judged over \u03B5r 3.9 to 4.5: set the real stackup in KiCad under Board Setup \u2192 Physical Stackup to judge them exactly.")}let $,y;if(d==="assumed"){let m=Hs(t,e,o.length,i);if(m){let C=0;u.layers=m.layers.map(k=>k.kind==="copper"?{kind:"copper",name:o[C++],t:k.t,er:1,plane:!1}:{kind:"dielectric",name:k.name,t:k.t,er:k.er,plane:!1,...k.tanD!==void 0?{tanD:k.tanD}:{}}),$=m.name,y={F:m.mask,B:m.mask},m.exact&&(d="fab");for(let k=n.length-1;k>=0;k--)/no physical stackup|untouched default/.test(n[k])&&n.splice(k,1);n.push(m.exact?`The file has no stackup of its own, but ${m.named?`${m.why} names ${m.name}`:`it looks like a ${m.fab} board (${m.why}), and ${m.fab} has one stackup for it, ${m.name}`}, so that stackup is used and the results are checked. If the board was built on another, set it in KiCad under Board Setup \u2192 Physical Stackup.`:`The file has no stackup of its own, but it looks like a ${m.fab} board (${m.why}), so ${m.fab}'s standard stackup (${m.name}) is used. ${m.fab} builds this board on more than one stackup, so impedance and crosstalk results are rough notes. Name the stackup in a text on the board (JLC04161H-3313, say) or set it in KiCad under Board Setup \u2192 Physical Stackup to have them checked.`)}}let T=y??{};for(let m of $t(ie(ie(t,"setup")??[],"stackup")??[],"layer")){let C=m[1]==="F.Mask"?"F":m[1]==="B.Mask"?"B":null;if(!C)continue;let k=pt(ie(m,"thickness")?.[1]);k>0&&(T[C]={t:k,er:pt(ie(m,"epsilon_r")?.[1])||3.8})}let E=[...new Set([...a.values(),...s.map(m=>m.net),...r.map(m=>m.net)])].filter(m=>m!=="");return s.length&&!E.some(m=>m)&&n.push("No track or pad in this file has a net, so there are no signals to check. Update the board from the schematic in KiCad (Tools \u2192 Update PCB from Schematic, F8) and save it again."),{copper:o,stackup:u.layers,thickness:i,nets:E,tracks:s,vias:r,zones:f,parts:c,mask:T,stackupFrom:d,...$?{stackupName:$}:{},...$?.startsWith("JLCPCB")?{etch:.7*.0254}:{},outline:g,edges:w,warnings:n}}function Bn(e){let t=0;for(let n=0,o=e.length-1;n<e.length;o=n++)t+=(e[o].x+e[n].x)*(e[o].y-e[n].y);return Math.abs(t)/2}var so=new WeakMap;function io(e){let t=so.get(e);if(t)return t;let n=1/0,o=-1/0,u=1/0,d=-1/0;for(let p of e)n=Math.min(n,p.x),o=Math.max(o,p.x),u=Math.min(u,p.y),d=Math.max(d,p.y);let i=Math.max(1,Math.min(8192,Math.ceil(e.length/8))),a=Math.max((d-u)/i,1e-9),l=Array.from({length:i},()=>[]);for(let p=0,s=e.length-1;p<e.length;s=p++){let r=Math.max(0,Math.floor((Math.min(e[p].y,e[s].y)-u)/a)),f=Math.min(i-1,Math.floor((Math.max(e[p].y,e[s].y)-u)/a));for(let c=r;c<=f;c++)l[c].push(p)}return t={x0:n,x1:o,y0:u,y1:d,dy:a,bins:l.map(p=>Int32Array.from(p)),p:e},so.set(e,t),t}function Un(e){return io(e)}function _e(e,t){let n=io(t);if(e.x<n.x0||e.x>n.x1||e.y<n.y0||e.y>n.y1)return!1;let o=Math.min(n.bins.length-1,Math.floor((e.y-n.y0)/n.dy)),u=n.p,d=!1;for(let i of n.bins[o]){let a=i===0?u.length-1:i-1;u[i].y>e.y!=u[a].y>e.y&&e.x<(u[a].x-u[i].x)*(e.y-u[i].y)/(u[a].y-u[i].y)+u[i].x&&(d=!d)}return d}var zs={t:.6*.0254,er:3.8},Vs={t:.6*.0254,er:3.9};function Hs(e,t,n,o){if(Math.abs(o-1.6)>.1||![2,4,6].includes(n))return null;let u=r=>ir[r]?ir[r]():null,d=(r,f,c,x,S=!1)=>{let M=u(r);return M&&M.filter(b=>b.kind==="copper").length===n?{name:r,fab:f,exact:c,named:S,why:x,layers:M,mask:f==="OSH Park"?Vs:zs}:null},i=[],a=r=>{if(!Mt(r))return;let f=sn(r);if(!(f==="footprint"||f==="module")){if(f==="gr_text"||f==="gr_text_box"||f==="comment"||f==="title"||f==="company"){for(let c of r.slice(1))typeof c=="string"&&i.push(c);return}for(let c of r)a(c)}};a(e);let l=t.match(/JLC0?([46])161H-?(7628|3313|2116|1080)/i);if(l){let r=d(`JLCPCB ${l[1]}-layer, 1.6 mm (JLC0${l[1]}161H-${l[2]})`,"JLCPCB",!0,"the file",!0);if(r)return r}for(let r of i){let f=/JLC/i.test(r)?r.match(/\b(7628|3313|2116|1080)\b/):null;if(f){let c=d(`JLCPCB ${n}-layer, 1.6 mm (JLC0${n}161H-${f[1]})`,"JLCPCB",!0,"a note on the board",!0);if(c)return c}}let p=r=>i.some(f=>r.test(f));if(n===4&&p(/AISLER/i))return d("AISLER 4-layer, 1.6 mm","AISLER",!0,"a note on the board names AISLER");if(n===4&&p(/Multi[- ]?CB|Multi Circuit Boards/i))return d("Multi-CB 4-layer, 1.6 mm (4L-01)","Multi-CB",!0,"a note on the board names Multi-CB");if(p(/OSH ?Park/i))return d(`OSH Park ${n}-layer, 1.6 mm (${n===2?"FR4":"FR408HR"})`,"OSH Park",!0,"a note on the board names OSH Park");let s=(r,f)=>r==="JLCPCB"?d(n===2?"JLCPCB 2-layer, 1.6 mm (JLC0216)":`JLCPCB ${n}-layer, 1.6 mm (JLC0${n}161H-${n===4?"7628":"3313"})`,r,n===2,f):d(`PCBWay ${n}-layer, 1.6 mm`,r,!1,f);return p(/PCB ?Way/i)&&n>2?s("PCBWay","a note on the board names PCBWay"):i.some(r=>/JLCJLC/i.test(r))?s("JLCPCB","its silkscreen has JLCPCB's order-number mark"):p(/JLC/i)?s("JLCPCB","a note on the board names JLCPCB"):/\(property "(LCSC|LCSC[ _]?(Part|PN|#)[^"]*|JLC(PCB)?[ _]?(Part|PN|#)[^"]*)" "C\d{3,}"/i.test(t)?s("JLCPCB","its parts carry LCSC part numbers, for JLCPCB assembly"):null}function Gs(e){let t=e.filter(n=>n.kind==="dielectric");return t.length>0&&t.every(n=>Math.abs(n.er-4.5)<1e-6)}function Ks(e){let t=u=>({kind:"copper",name:u===0?"F.Cu":u===e-1?"B.Cu":`In${u}.Cu`,t:35e-6,er:1,plane:!1});if(e<=2)return[t(0),{kind:"dielectric",name:"Core",t:.00151,er:4.5,plane:!1,tanD:.02},{...t(1),name:"B.Cu"}];let n=[],o=(.0016-e*35e-6-(e-2)*1e-4)/Math.max(1,(e-2)/2);for(let u=0;u<e;u++)n.push(t(u)),u<e-1&&n.push({kind:"dielectric",name:u%2===0?"Prepreg":"Core",t:u%2===0?1e-4:Math.max(o,1e-4),er:4.5,plane:!1,tanD:.02});return n}function js(e,t,n){let o=2*(e.x*(t.y-n.y)+t.x*(n.y-e.y)+n.x*(e.y-t.y));if(Math.abs(o)<1e-12)return[[e,n]];let u=x=>x.x*x.x+x.y*x.y,d={x:(u(e)*(t.y-n.y)+u(t)*(n.y-e.y)+u(n)*(e.y-t.y))/o,y:(u(e)*(n.x-t.x)+u(t)*(e.x-n.x)+u(n)*(t.x-e.x))/o},i=Math.hypot(e.x-d.x,e.y-d.y),a=Math.atan2(e.y-d.y,e.x-d.x),l=Math.atan2(t.y-d.y,t.x-d.x),p=Math.atan2(n.y-d.y,n.x-d.x),s=x=>(x%(2*Math.PI)+2*Math.PI)%(2*Math.PI),r=s(p-a);s(l-a)>r&&(r-=2*Math.PI);let f=Math.max(2,Math.ceil(Math.abs(r)/(Math.PI/24))),c=[];for(let x=0;x<f;x++){let S=a+r*x/f,M=a+r*(x+1)/f;c.push([{x:d.x+i*Math.cos(S),y:d.y+i*Math.sin(S)},{x:d.x+i*Math.cos(M),y:d.y+i*Math.sin(M)}])}return c}var Ws={usb2:{label:"USB 2.0",z:90,rate:48e7},usb3:{label:"USB 3",z:90,rate:5e9},ethernet:{label:"Ethernet",z:100,rate:125e6},pcie:{label:"PCIe",z:85,rate:8e9},sata:{label:"SATA",z:100,rate:6e9},hdmi:{label:"HDMI",z:100,rate:34e8},dp:{label:"DisplayPort",z:100,rate:54e8},lvds:{label:"LVDS",z:100,rate:1e9},mipi:{label:"MIPI",z:100,rate:15e8},pair:{label:"Differential pair",z:100,rate:1e9},rf:{label:"RF",z:50,rate:24e8},ddr:{label:"DDR",z:50,rate:16e8},se:{label:"Single-ended",z:50,rate:1e9}},Bt=e=>({kind:e,...Ws[e]});function co(e,t){if((e.kind==="pcie"||e.kind==="sata"||e.kind==="usb3")&&/(REF_?)?CLK|CLOCK/i.test(t.slice(t.lastIndexOf("/")+1)))return{...e,label:`${e.label} reference clock`,rate:15e8};if(e.kind!=="pcie")return e;let n=t.toUpperCase().match(/GEN_?([1-6])(?![0-9])/),o=n?+n[1]:3,u=[25e8,5e9,8e9,16e9,32e9,32e9][o-1];return o===3?e:{...e,label:`PCIe Gen ${o}`,rate:u}}var B=e=>e.slice(e.lastIndexOf("/")+1).toUpperCase(),Js=[[/^(.*(?:TD|RD|TX|RX))\+$/,"+","-"],[/^(.*(?:TD|RD|TX|RX))-$/,"+","-"],[/^(.*)D\+$/,"D+","D-"],[/^(.*)D-$/,"D+","D-"],[/^(.*)DP$/,"DP","DM"],[/^(.*)DM$/,"DP","DM"],[/^(.*)_P$/,"_P","_N"],[/^(.*)_N$/,"_P","_N"],[/^(.*)\+$/,"+","-"],[/^(.*)-$/,"+","-"],[/^(.*[0-9_])P$/,"P","N"],[/^(.*[0-9_])N$/,"P","N"],[/^(.*(?:TX|RX|CLK|CK|TXC|RXC))P$/,"P","N"],[/^(.*(?:TX|RX|CLK|CK|TXC|RXC))N$/,"P","N"]];function lo(e,t,n){let o=e.toUpperCase(),u=t.toUpperCase(),d=uo(o,n),i=uo(u,n);return/(^|[^A-Z])(SS)?(TX|RX)\d?([^A-Z]|$)/.test(o)&&!/ETH|MDI|RJ45|TRD/.test(o)&&/USB/.test(u)&&(d==="ethernet"||d===null)?"usb3":d??i??(n==="D+"||n==="DP"?"usb2":"pair")}function uo(e,t){return/(^|[^A-Z])(AUX|SBU)/.test(e)?"pair":/SSTX|SSRX|USB3|SS_?TX|SS_?RX/.test(e)?"usb3":/PCIE|PET[0-9]|PER[0-9]|REFCLK/.test(e)?"pcie":/SATA|(^|[^A-Z])S_(TX|RX)/.test(e)?"sata":/HDMI|TMDS/.test(e)?"hdmi":/DISPLAYPORT|EDP|(^|[^A-Z])DP\d|_DP_?\d|ML_|LANE\d/.test(e)&&!/USB/.test(e.replace(/DP\d.*/,""))?"dp":/MIPI|CSI|DSI|D_?PHY/.test(e)?"mipi":/LVDS/.test(e)?"lvds":(/ETH|MDI|RJ45|TRD|TXP|RXP|TD_|RD_|\bTX[0-9]?_?\b|\bRX[0-9]?_?\b/.test(e)||/^(TD|RD|TX|RX)$/.test(e))&&!/USB/.test(e)?"ethernet":/USB/.test(e)&&/(^|[^A-Z])(TX|RX)/.test(e)?"usb3":/USB/.test(e)?"usb2":null}function po(e){let t=new Set(e.nets),n=new Map(e.nets.map(v=>[v.toUpperCase(),v])),o=[],u=new Set;for(let v of e.nets){if(u.has(v))continue;let g=v.toUpperCase(),$=g.lastIndexOf("/")+1,y=g.slice(0,$),T=g.slice($),E=T.match(/^(.*(?:TX|RX|CLK|CK))([PN])(\d{1,2})$/);if(E){let[,m,,C]=E,k=n.get(`${y}${m}P${C}`),I=n.get(`${y}${m}N${C}`);if(k&&I&&!u.has(k)&&!u.has(I)){u.add(k),u.add(I);let R=(v.slice(1,v.lastIndexOf("/")+1)+k.slice(k.lastIndexOf("/")+1,k.length-1-C.length)+`${C} P/N`).replace(/^\//,"");o.push({name:R,p:k,n:I,role:co(Bt(lo(m,y,"P")),`${y}/${m}`)});continue}}for(let[m,C,k]of Js){let I=T.match(m);if(!I)continue;let R=I[1];if(/SENSE|SNS|ISEN|SHUNT|VREF|REF_|AIN|ADC|BAT|VBUS|VCC|VDD|GND/.test(R))break;let N=n.get(y+R+C),A=n.get(y+R+k);if(N&&A&&N!==A&&t.has(N)&&t.has(A)&&!u.has(N)&&!u.has(A)){u.add(N),u.add(A);let L={"D+":"D\xB1",DP:"DP/DM",_P:"_P/N","+":"\xB1",P:"P/N"}[C]??"",H=(v.slice(1,v.lastIndexOf("/")+1)+N.slice(N.lastIndexOf("/")+1,N.length-C.length)+L).replace(/^\//,"");o.push({name:H,p:N,n:A,role:co(Bt(lo(R,y,C)),`${y}/${R}`)})}break}}let d=new Map;for(let v of e.parts)for(let g of v.pads)g.net&&d.set(g.net,[...d.get(g.net)??[],`${v.lib} ${v.value}`.toUpperCase()]);let i=v=>{let g=d.get(v)??[];return g.some($=>/RJ-?45|8P8C|MAGJACK|HR911|HANRUN|LAN.?TRANS|H1102|HX11\d\d|ETHERNET.?TRANS|PULSE.?H\d|LPJ\d/.test($))?"ethernet":g.some($=>/HDMI/.test($))?"hdmi":g.some($=>/DISPLAYPORT|DP_CONN|DP-CONN/.test($))?"dp":g.some($=>/SATA/.test($))?"sata":g.some($=>/USB/.test($)&&/CONN|RECEPT|USB_[ABC]|TYPE.?C|USB-?C|MICRO/.test($))?"usb":null};for(let v of o){let g=i(v.p)??i(v.n);if(!g)continue;let $=v.role.kind,y=B(v.p).toUpperCase();/(^|[^A-Z])(AUX|SBU|CC\d?)([^A-Z]|$)/.test(y)||(g==="ethernet"&&($==="pair"||$==="usb2")?v.role=Bt("ethernet"):g==="usb"&&$==="pair"?v.role=Bt(/(^|[^A-Z])(SS)?(TX|RX)\d?/.test(y)?"usb3":"usb2"):g!=="usb"&&g!=="ethernet"&&$==="pair"&&(v.role=Bt(g)))}let a=v=>{let g=v.replace(/\s/g,"").match(/^(\d+(?:\.\d+)?)(m)?(?:Ω|R|OHMS?)?$/i)??v.match(/^R(\d+)$/i);if(!g)return!1;let $=v.match(/^R\d+$/i)?+("0."+g[1]):Number(g[1])*(g[2]?.001:1);return $>0&&$<=.1},l=new Set(e.parts.filter(v=>/^R\d+/.test(v.ref)&&v.pads.length===2&&a(v.value)).map(v=>v.pads.map(g=>g.net).sort().join("|")));for(let v=o.length-1;v>=0;v--)l.has([o[v].p,o[v].n].sort().join("|"))&&o.splice(v,1);let p=/RP2040|RP2350|RPI_PICO|(^|[^A-Z])PICO([^A-Z]|$)|PRO_?MICRO|ELITE-?C|NICE.?NANO|XIAO|ATMEGA\d*U\d|AT90USB|ATSAMD|ATSAML2|SAMD\d\d|STM32(F0|F1|F3|F4|L0|L1|L4|L5|G0|G4|C0|U0|WB)|GD32F[13]|CH32V[0-2]|CH55\d|CH34[01]|CH910\d|CP210\d|CP2112|FT23[01]X|FT232R|FT230X|PCM27\d\d|PCM29\d\d|MCP22\d\d|NRF52|ESP32-?S[23]|ESP32-?C[36]|EFM8UB|PIC18F|PIC32MX|LPC11U|LPC13|MK20|MKL2/,s=/M\.2|NGFF|MINI.?PCIE|MPCIE|SODIMM|DIMM|(^|[^A-Z])SOM([^A-Z]|$)|JETSON|SMARC|QSEVEN|COM.?EXPRESS|USB3|SUPERSPEED/,r=/USB33\d\d|ULPI|USB25\d\d|USB24\d\d|FE1\.1|GL85\d|TUSB|CYUSB|FX3|FT2232H|FT232H|FT4232H|CM4|CM5|COMPUTE.?MODULE|USB5\d{3}|USB7\d{3}|SL2\.1|CH33[45]|VL8\d\d|ASM\d{4}|JMS\d+|RTL8\d{3}|LAN78|LAN95|AX88/,f=e.parts.map(v=>`${v.lib} ${v.value}`.toUpperCase()),c=f.some(v=>p.test(v))&&!f.some(v=>r.test(v)||s.test(v)),x=v=>e.parts.filter(g=>g.pads.length===2&&/^(R|FB|L)\d+/.test(g.ref)&&g.pads.some($=>$.net===v)).flatMap(g=>g.pads.map($=>$.net)).filter(g=>g&&g!==v);for(let v of o){if(v.role.kind!=="usb2"||v.role.netclass)continue;let g=new Set([v.p,v.n,...x(v.p),...x(v.n)]),$=e.parts.filter(T=>T.pads.length>=6&&T.pads.some(E=>g.has(E.net))).map(T=>`${T.lib} ${T.value}`.toUpperCase());($.some(T=>p.test(T))?!$.some(T=>r.test(T)):!$.some(T=>r.test(T))&&c)&&(v.role={...v.role,label:"USB 2.0 full speed",rate:12e6})}let S=v=>/(^|[^A-Z])(SEN|SENSE|VSENSE|ISENSE|SNS|ISNS|VSNS|FB|KELVIN)([^A-Z]|$)/.test(B(v).toUpperCase());for(let v=o.length-1;v>=0;v--)S(o[v].p)&&o.splice(v,1);let M=/(^|[^A-Z])(EN|ENABLE|SW|SEL|CTRL|CTL|V\d?|VCC|VDD|PWR|ON|OFF|LED|RST|RESET|IRQ|INT|DET|BIAS|GPIO|SHDN|PA_?EN|LNA_?EN|TX_?EN|RX_?EN)\d*([^A-Z]|$)/,b=e.nets.filter(v=>!u.has(v)&&/(^|[^A-Z])(RF|ANT|ANTENNA)([^A-Z]|$)/.test(B(v))&&!/RFU/.test(B(v))&&!M.test(B(v).toUpperCase())).map(v=>({net:v,role:Bt("rf")})),h=e.parts.filter(v=>v.pads.length>=60&&!/^(J|P|CN|X|CON)\d/i.test(v.ref)&&!/DIMM|SOCKET|Bus_|CONN/i.test(v.lib)&&/DDR[34]|LPDDR|SDRAM|MT4[01]K|MT40A|MT53|AS4C\d+M\d+D[34]|K4[AB]\d|H5(TQ|AN)|NT5(CC|AD)|IS4[36](TR|QR)|W63|W97/i.test(`${v.lib} ${v.value}`)),w=new Set([...u,...b.map(v=>v.net)]);for(let v of h)for(let g of v.pads){let $=g.net,y=B($).toUpperCase();!$||w.has($)||v.pads.filter(T=>T.net===$).length>1||/^NET-\(|GND|VSS|VDD|VCC|VTT|REF|ZQ|RESET|RST|TEN|ALERT|DRAM$|^NC|UNCONNECTED|^\+|\d+V\d*$|\d[._]\d/.test(y)||(w.add($),b.push({net:$,role:Bt("ddr")}))}return{pairs:o,singles:b}}function Xs(e){let t=e.match(/(?:^|[^0-9])(\d{2,3})\s*(?:ohms?|Ω|R(?![A-Z]))/i)??e.match(/(?:^|[^A-Z])Z_?(\d{2,3})(?![0-9])/i),n=t?Number(t[1]):NaN;return n>=25&&n<=150?n:null}var Zs=e=>new RegExp("^"+e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".")+"$");function fo(e,t){let n=new Map,o;try{o=JSON.parse(e)}catch{return n}let u=o.net_settings??{},d=(a,l)=>{let p=Xs(l);p&&!n.has(a)&&n.set(a,{cls:l,z:p})};for(let[a,l]of Object.entries(u.netclass_assignments??{}))d(a,Array.isArray(l)?l[0]:l);for(let a of u.classes??[])for(let l of a.nets??[])a.name&&d(l,a.name);let i=(u.netclass_patterns??[]).map(a=>({cls:a.netclass,re:Zs(a.pattern)}));if(i.length){for(let a of t)for(let l of i)if(l.re.test(a)){d(a,l.cls);break}}return n}function ho(e,t){let n=e.pairs.map(d=>{let i=t.get(d.p)??t.get(d.n);return i?{...d,role:{...d.role,z:i.z,netclass:i.cls}}:d}),o=e.singles.map(d=>{let i=t.get(d.net);return i&&i.z<80?{...d,role:{...d.role,z:i.z,netclass:i.cls}}:d}),u=new Set([...n.flatMap(d=>[d.p,d.n]),...o.map(d=>d.net)]);for(let[d,i]of t)!u.has(d)&&i.z<80&&o.push({net:d,role:{...Bt("se"),z:i.z,netclass:i.cls}});return{pairs:n,singles:o}}var cr=172e-10;var ze=88541878128e-22,Ve=125663706212e-17;function Ys(e,t,n,o,u){let d=[],i=[],a=t,l=n,p=0;for(;p<e;){if(a<=l){let r=Math.min(a,u);d.push(r),p+=r,a*=o}else{let r=Math.min(l,u);i.push(r),p+=r,l*=o}if(d.length+i.length>5e3)break}let s=e/p;return[...d,...i.reverse()].map(r=>r*s)}function jt(e,t){let n=[...e].sort((u,d)=>u.pos-d.pos),o=[];for(let u of n){let d=o[o.length-1];d&&u.pos-d.pos<t?u.moved!==0&&(d.moved=u.moved):o.push({...u})}return o}function Wt(e,t,n,o,u,d){let i=s=>Math.min(...t.map(r=>n+(o-1)*Math.abs(s-r))),a=[e[0].pos];for(let s=0;s+1<e.length;s++){let r=e[s+1].pos-e[s].pos,f=e[s].pos>=u?1/0:r/6;for(let c of Ys(r,i(e[s].pos),i(e[s+1].pos),o,f))a.push(a[a.length-1]+c);a[a.length-1]=e[s+1].pos}for(let s=0;s<d;s++){let r=[a[0]];for(let f=1;f<a.length;f++)r.push((a[f-1]+a[f])/2,a[f]);a=r}let l=a.slice(),p=0;for(let s=0;s<a.length;s++){for(;p+2<e.length&&a[s]>e[p+1].pos;)p++;let r=e[p].pos,f=e[p+1].pos,c=r+e[p].moved,x=f+e[p+1].moved;l[s]=c+(a[s]-r)/(f-r)*(x-c)}return{xs:a,shifted:l}}function zn(e,t,n,o,u,d){let i=e*t,{aE:a,aN:l,aX:p}=n,s=o.aE,r=o.aN,f=new Float64Array(i),c=new Float64Array(i),x=new Float64Array(i),S=new Float64Array(i),M=new Float64Array(i),b=new Float64Array(i),h=new Float64Array(i);for(let C=0;C<i;C++){let k=C>0?C-1:-1,I=C-e;f[C]=a[C]+l[C]+(k>=0?a[k]+p[k]:0)+(I>=0?l[I]+p[I]:0),c[C]=s[C]+r[C]+(k>=0?s[k]:0)+(I>=0?r[I]:0)}let w=.97,v=1e-4;for(let C=0;C<i;C++){if(u[C])continue;let k=C%e,I=C/e|0,R=c[C];if(k>0&&!u[C-1]){let N=C-1,A=s[N]*x[N];R-=A*A+w*(s[N]*(I+1<t&&!u[N+e]?r[N]:0)*x[N]*x[N])}if(I>0&&!u[C-e]){let N=C-e,A=r[N]*x[N];R-=A*A+w*(r[N]*(k+1<e&&!u[N+1]?s[N]:0)*x[N]*x[N])}R<v*c[C]&&(R=c[C]),x[C]=1/Math.sqrt(R)}let g=(C,k)=>{for(let I=0;I<i;I++){if(u[I]){k[I]=0;continue}let R=f[I]*C[I];I+1<i&&(R-=a[I]*C[I+1]),I>0&&(R-=a[I-1]*C[I-1]),I+e<i&&(R-=l[I]*C[I+e]),I>=e&&(R-=l[I-e]*C[I-e]+p[I-e]*C[I-e+1]),I>0&&I+e-1<i&&(R-=p[I-1]*C[I+e-1]),k[I]=R}},$=(C,k)=>{for(let I=0;I<i;I++){if(u[I]){h[I]=0;continue}let R=I%e,N=I/e|0,A=C[I];R>0&&!u[I-1]&&(A+=s[I-1]*x[I-1]*h[I-1]),N>0&&!u[I-e]&&(A+=r[I-e]*x[I-e]*h[I-e]),h[I]=A*x[I]}for(let I=i-1;I>=0;I--){if(u[I]){k[I]=0;continue}let R=I%e,N=I/e|0,A=h[I];R+1<e&&!u[I+1]&&(A+=s[I]*x[I]*k[I+1]),N+1<t&&!u[I+e]&&(A+=r[I]*x[I]*k[I+e]),k[I]=A*x[I]}},y=0;for(let C=0;C<i;C++){if(u[C]){S[C]=0;continue}let k=-f[C]*d[C],I=0,R=(N,A)=>{k+=N*d[A],u[A]&&(I+=N*d[A])};C+1<i&&R(a[C],C+1),C>0&&R(a[C-1],C-1),C+e<i&&R(l[C],C+e),C>=e&&(R(l[C-e],C-e),R(p[C-e],C-e+1)),C>0&&C+e-1<i&&R(p[C-1],C+e-1),S[C]=k,y+=I*I}if(y===0)return 0;$(S,M),b.set(M);let T=0;for(let C=0;C<i;C++)T+=S[C]*M[C];let E=new Float64Array(i),m=0;for(;m<4e3;m++){g(b,E);let C=0;for(let A=0;A<i;A++)C+=b[A]*E[A];let k=T/C,I=0;for(let A=0;A<i;A++)d[A]+=k*b[A],S[A]-=k*E[A],I+=S[A]*S[A];if(I<1e-20*y){m++;break}$(S,M);let R=0;for(let A=0;A<i;A++)R+=S[A]*M[A];let N=R/T;T=R;for(let A=0;A<i;A++)b[A]=M[A]+N*b[A]}return m}function lr(e,t,n=0){let o=e.refine??1,u=e.slabs.reduce((ne,te)=>ne+te.h,0),d=t!=="single",i=d?e.s/2:0,a=d?e.s/2+e.w:e.w/2,l=e.y0,p=e.y0+e.t;if(e.topPlane&&p>u+1e-12)throw new Error("The trace does not fit between the planes.");let s=e.mask?e.mask.t:0,r=e.mask?e.mask.tBase??e.mask.t:0,f=!!e.coplanar,c=f?a+e.coplanar.gap:1/0,x=e.t>0?(e.narrow??0)/2:0,S=x>0?x/e.t:0,M=Math.hypot(1,S),b=(e.narrowAt??"top")==="top",h=[e.w-2*x,l,e.t>0?e.t:1/0,e.topPlane?u-p:1/0,d?e.s:1/0,s||1/0,r||1/0,f?e.coplanar.gap:1/0].filter(ne=>ne>0),w=Math.min(...h)/((e.t>0?4096:65536)*o),v=1+.5/o,g=e.topPlane?4*u:200*(p+(d?e.s+e.w:e.w/2)),$=a+g,y=e.topPlane?u:p+g,T=1e-4*Math.min(e.w-2*x,e.t>0?e.t:e.w),E=T*(M+S),m=w*.01,C=!f||c-s>a+s+m,k=[{pos:0,moved:0},{pos:a,moved:-E},{pos:$,moved:0}];d&&k.push({pos:i,moved:E}),f&&k.push({pos:c,moved:E});let I=[{pos:0,moved:-T},{pos:l,moved:T},{pos:p,moved:-T},{pos:y,moved:e.topPlane?T:0}],R=0;for(let ne of e.slabs)R+=ne.h,R<y-1e-12&&I.push({pos:R,moved:0});s&&(C&&k.push({pos:a+s,moved:0}),f&&C&&k.push({pos:c-s,moved:0}),d&&i-s>m&&k.push({pos:i-s,moved:0}),I.push({pos:u+r,moved:0},{pos:p+s,moved:0}));let N=[a,...d?[i]:[],...f?[c]:[]],A=Wt(jt(k,m),N,w,v,(f?c:a+s)-m/2,n),L=Wt(jt(I,m),[l,p],w,v,e.topPlane?1/0:Math.max(p+s,u+r)-m/2,n),H=A.xs,U=L.xs,P=H.length,F=U.length,V=P*F,O=(ne,te,ke,ve,fe,le,xe,he)=>{let Ce=new Float64Array(V);if(!(le>0)){for(let pe=0;pe<F;pe++)for(let je=0;je<P;je++)Ce[je+pe*P]=ne[je];return Ce}let re=[[0,0]];d&&(s&&ke-s>m&&re.push([ke-s,le]),re.push([ke,le])),re.push([ve,-le]),s&&C&&re.push([ve+s,-le]),f&&(s&&C&&re.push([fe-s,le]),re.push([fe,le]));let[Ae,ct]=re[re.length-1],Ke=4*Math.max(e.t,le),lt=pe=>{if(pe>=Ae)return ct*Math.max(0,1-(pe-Ae)/Ke);let je=0;for(;pe>re[je+1][0];)je++;let[Dt,wt]=re[je],[vn,Tn]=re[je+1];return wt+(pe-Dt)/(vn-Dt)*(Tn-wt)},He=ne.map(lt);for(let pe=0;pe<F;pe++){let je=Math.min(1,Math.max(0,(te[pe]-xe)/(he-xe))),Dt=b?je:1-je;for(let wt=0;wt<P;wt++)Ce[wt+pe*P]=ne[wt]+He[wt]*Dt}return Ce},G=O(H,U,i,a,c,x,l,p),J=e.slabs.length+2,j=J-1,Z=[1,...e.slabs.map(ne=>ne.er),e.mask?e.mask.er:1],ae=new Uint8Array((P-1)*(F-1)),z=[];R=0;for(let ne of e.slabs)R+=ne.h,z.push(R);for(let ne=0;ne+1<F;ne++){let te=(U[ne]+U[ne+1])/2,ke=0;for(let ve=0;ve<z.length;ve++)if(te<z[ve]){ke=ve+1;break}for(let ve=0;ve+1<P;ve++){let fe=(H[ve]+H[ve+1])/2,le=ke;if(s&&ke===0){let xe=te<p+s&&(fe<a+s&&(!d||fe>i-s)||fe>c-s);(te<u+r||xe)&&(le=j)}ae[ve+ne*(P-1)]=le}}let oe=new Uint8Array(V),Te=new Float64Array(V);for(let ne=0;ne<F;ne++)for(let te=0;te<P;te++){let ke=te+ne*P,ve=U[ne]>=l-m&&U[ne]<=p+m;ve&&H[te]>=i-m&&H[te]<=a+m?(oe[ke]=1,Te[ke]=1):(ne===0||e.topPlane&&ne===F-1||t==="odd"&&te===0||ve&&H[te]>=c-m)&&(oe[ke]=1)}let Ie=(ne,te,ke)=>{let ve=new Float64Array(V),fe=new Float64Array(V),le=new Float64Array(V);for(let xe=0;xe+1<F;xe++){let he=ke[xe+1]-ke[xe];for(let Ce=0;Ce+1<P;Ce++){let re=Ce+xe*P,Ae=(ne?Z[ae[Ce+xe*(P-1)]]:1)/(2*he),ct=te[re],Ke=te[re+1],lt=te[re+P],He=te[re+P+1];ve[re]+=Ae*(he*he+(lt-Ke)*(lt-ct))/(Ke-ct),fe[re]+=Ae*(Ke-lt),fe[re+1]+=Ae*(Ke-lt),ve[re+P]+=Ae*(he*he+(Ke-lt)*(Ke-He))/(He-lt),le[re]+=Ae*(lt-ct+He-Ke)}}return{aE:ve,aN:fe,aX:le}},Ne=(ne,te,ke)=>{let ve=new Array(J).fill(0);for(let fe=0;fe+1<F;fe++){let le=ke[fe+1]-ke[fe];for(let xe=0;xe+1<P;xe++){let he=xe+fe*P,Ce=te[he],re=te[he+1],Ae=te[he+P],ct=te[he+P+1],Ke=ne[he+1]-ne[he],lt=ne[he+P+1]-ne[he+P],He=ne[he+P]-ne[he],pe=ne[he+P+1]-ne[he+1],je=ne[he+P]-ne[he+1];ve[ae[xe+fe*(P-1)]]+=((le*le+(Ae-re)*(Ae-Ce))/(re-Ce)*Ke*Ke+(le*le+(re-Ae)*(re-ct))/(ct-Ae)*lt*lt+(re-Ae)*(He*He+pe*pe)+(Ae-Ce+ct-re)*je*je)/(2*le)}}return ve},Q=t==="single"?2:1,ye=ne=>ne.reduce((te,ke)=>te+ke,0),be=x>0?O(H,U,i,a,c,0,l,p):G,Ee=Te.slice(),Qe=Ie(!0,G,U),rt=zn(P,F,Qe,x>0?Ie(!0,be,U):Qe,oe,Ee),ft=Ne(Ee,G,U).map(ne=>ne*Q),qe=Te.slice(),ce=Ie(!1,G,U),Oe=zn(P,F,ce,x>0?Ie(!1,be,U):ce,oe,qe),Se=ye(Ne(qe,G,U))*Q,Xe=ft.reduce((ne,te,ke)=>ne+te*Z[ke],0),Re=O(A.shifted,L.shifted,i+E,a-E,c+E,x-2*S*T,l+T,p-T),Je=e.t>0?ye(Ne(qe,Re,L.shifted))*Q:Se;return{c:ze*Xe,cAir:ze*Se,z0:1/(299792458*ze*Math.sqrt(Xe*Se)),eeff:Xe/Se,g:ft,dcAir:ze*(Je-Se)/T,nodes:V,iterations:rt+Oe}}function _n(e,t){let n=lr(e,t,0),o=lr(e,t,1),u=(a,l)=>(4*l-a)/3,d=u(n.c,o.c),i=u(n.cAir,o.cAir);return{c:d,cAir:i,z0:1/(299792458*Math.sqrt(d*i)),eeff:d/i,g:n.g.map((a,l)=>u(a,o.g[l])),dcAir:u(n.dcAir,o.dcAir),nodes:n.nodes+o.nodes,iterations:n.iterations+o.iterations}}function mo(e,t){if(!(e.w>0)||!(e.y0>0)||e.t<0)throw new Error("Width and height must be positive.");return _n(e,t)}function an(e,t){if(!(e.w>0)||!(e.y0>0)||e.t<0)throw new Error("Width and height must be positive.");let n=lr(e,t,0);return{...n,z0:1/(299792458*Math.sqrt(n.c*n.cAir)),eeff:n.c/n.cAir}}function go(e){if(!(e.w>0)||!(e.y0>0)||e.t<0)throw new Error("Width and height must be positive.");if(e.s!==void 0&&!(e.s>0))throw new Error("The gap must be positive.");if(e.narrow!==void 0&&(e.narrow<0||e.narrow>=e.w))throw new Error("The narrow face must be narrower than the trace width and wider than zero.");if(e.coplanar&&!(e.coplanar.gap>0))throw new Error("The gap to the coplanar ground must be positive.");let t=[1,...e.slabs.map(n=>n.er),e.mask?e.mask.er:1];return e.s===void 0?{single:_n(e,"single"),er:t}:{odd:_n(e,"odd"),even:_n(e,"even"),er:t}}function yo(e,t,n={}){let o=[...t].sort((a,l)=>a.y-l.y);if(o.length<2||!(o[0].y<0)||!(o[o.length-1].y>0))throw new Error("slotPlanesC: needs a plane above and below the trace");let u=a=>{let l=e/2,p=o.slice(1,-1).filter(U=>U.s>0),s=o[o.length-1].y-o[0].y,r=Math.max(l,...p.map(U=>U.s)),f=[e,...o.map(U=>Math.abs(U.y)),...p.flatMap(U=>[U.s,Math.abs(U.s-l)||1/0])].filter(U=>U>0&&isFinite(U)),c=Math.min(...f)/(n.div??65536),x=1.5,S=c*.01,M=r+(n.reach??40)*s,b=[{pos:0,moved:0},{pos:l,moved:0},{pos:M,moved:0},...p.map(U=>({pos:U.s,moved:0}))],h=[{pos:0,moved:0},...o.map(U=>({pos:U.y,moved:0}))],w=Wt(jt(b,S),[l,...p.map(U=>U.s)],c,x,r+s,a),v=Wt(jt(h,S),[0,...p.map(U=>U.y)],c,x,1/0,a),g=w.xs,$=v.xs,y=g.length,T=$.length,E=y*T,m=$.findIndex(U=>Math.abs(U)<S),C=o.map(U=>({j:$.findIndex(P=>Math.abs(P-U.y)<S),s:U.s})),k=new Uint8Array(E),I=new Float64Array(E);for(let U=0;U<T;U++)for(let P=0;P<y;P++){let F=P+U*y;U===m&&g[P]<=l+S?(k[F]=1,I[F]=1):(U===0||U===T-1||P===y-1||C.some(V=>V.j===U&&g[P]>=V.s-S))&&(k[F]=1)}let R=new Float64Array(E),N=new Float64Array(E),A=new Float64Array(E);for(let U=0;U+1<T;U++){let P=$[U+1]-$[U];for(let F=0;F+1<y;F++){let V=F+U*y,O=g[F+1]-g[F];R[V]+=P/(2*O),R[V+y]+=P/(2*O),N[V]+=O/(2*P),N[V+1]+=O/(2*P)}}let L={aE:R,aN:N,aX:A};zn(y,T,L,L,k,I);let H=0;for(let U=0;U<E;U++)U%y+1<y&&(H+=R[U]*(I[U+1]-I[U])**2),U+y<E&&(H+=N[U]*(I[U+y]-I[U])**2);return 2*H},d=u(0);return(4*u(1)-d)/3}function dr(e,t,n,o,u={}){let d=l=>{let p=e/2,s=[e,t,o,...n>0?[n,Math.abs(n-p)||1/0]:[]].filter(F=>F>0&&isFinite(F)),r=Math.min(...s)/(u.div??65536),f=1.5,c=(u.reach??200)*(t+Math.max(p,n)),x=Math.max(p,n)+c,S=t+c,M=-o,b=r*.01,h=[{pos:0,moved:0},{pos:p,moved:0},{pos:x,moved:0}];n>0&&h.push({pos:n,moved:0});let w=[{pos:M,moved:0},{pos:0,moved:0},{pos:t,moved:0},{pos:S,moved:0}],v=n>0?[p,n]:[p],g=Wt(jt(h,b),v,r,f,Math.max(p,n)+t,l),$=Wt(jt(w,b),n>0?[t,0]:[t],r,f,t+Math.max(p,n),l),y=g.xs,T=$.xs,E=y.length,m=T.length,C=E*m,k=T.findIndex(F=>Math.abs(F)<b),I=T.findIndex(F=>Math.abs(F-t)<b),R=new Uint8Array(C),N=new Float64Array(C);for(let F=0;F<m;F++)for(let V=0;V<E;V++){let O=V+F*E;F===I&&y[V]<=p+b?(R[O]=1,N[O]=1):(F===0||F===m-1||V===E-1||F===k&&y[V]>=n-b)&&(R[O]=1)}let A=new Float64Array(C),L=new Float64Array(C),H=new Float64Array(C);for(let F=0;F+1<m;F++){let V=T[F+1]-T[F];for(let O=0;O+1<E;O++){let G=O+F*E,J=y[O+1]-y[O];A[G]+=V/(2*J),A[G+E]+=V/(2*J),L[G]+=J/(2*V),L[G+1]+=J/(2*V)}}let U={aE:A,aN:L,aX:H};zn(E,m,U,U,R,N);let P=0;for(let F=0;F<C;F++)F%E+1<E&&(P+=A[F]*(N[F+1]-N[F])**2),F+E<C&&(P+=L[F]*(N[F+E]-N[F])**2);return 2*P},i=d(0),a=d(1);return Ve/((4*a-i)/3)}var Qs="Electrostatic field solution of the cross-section (quasi-TEM). Checked against exact conformal-mapping results and an independent finite-element solver: see Validation.";function cn(e){let{stack:t}=e,n=t.topPlane||t.above.length>0,o=[...t.below];if(n){let i=t.fill??{er:t.below[t.below.length-1].er,tanD:t.below[t.below.length-1].tanD};e.t>0&&o.push({h:e.t,...i}),o.push(...t.above)}let u=t.below.reduce((i,a)=>i+a.h,0),d=!n&&e.mask&&e.mask.t>0?e.mask:void 0;return{g:{slabs:o.map(({h:i,er:a})=>({h:i,er:a})),topPlane:t.topPlane,y0:u,w:e.w,t:e.t,s:e.s,mask:d&&{t:d.t,er:d.er,...d.tBase?{tBase:d.tBase}:{}},...e.narrow&&e.t>0?{narrow:e.narrow,narrowAt:n&&e.wideFace==="above"?"bottom":"top"}:{},...e.coplanarGap?{coplanar:{gap:e.coplanarGap}}:{}},tanD:[0,...o.map(i=>i.tanD),d?d.tanD:0]}}function Vn(e){if(!e.stack.below.length||e.stack.below.some(l=>!(l.h>0)))throw new Error("The trace needs a dielectric between it and its reference plane.");if(e.stack.above.some(l=>!(l.h>0)))throw new Error("Every dielectric layer needs a thickness.");let{g:t,tanD:n}=cn(e),o=go(t),u=[];e.stack.crossed&&u.push("Another signal layer sits between this trace and its reference plane. Its copper is treated as dielectric, and coupling to traces on that layer is not modelled."),u.push("The numerical error of the field solution is below 0.02%. The result is as good as the dimensions and \u03B5r you enter: finished width, copper thickness and pressed dielectric height from your fabricator matter far more."),e.narrow&&e.t>0||u.push("Rectangular trace. Etched traces are narrower on the face away from the core, which typically raises the impedance by about a percent: enter the width lost to etching to include it."),e.coplanarGap&&u.push("The coplanar ground is taken as continuous copper at the potential of the reference plane. That needs stitching vias close to the gap edge, spaced well under a tenth of a wavelength."),!e.stack.topPlane&&e.stack.above.length===0&&!e.mask&&u.push("No solder mask. Mask over the trace typically lowers the impedance by 1 to 3 \u03A9. Switch it on if your board has it."),u.push("Quasi-static: valid while the cross-section is small against the wavelength, which holds for PCB traces far beyond 50 GHz.");let d={method:"2D field solver",source:Qs,notes:u,er:o.er,tanD:n};if(o.single)return{...d,diff:!1,z:o.single.z0,eeff:o.single.eeff,mode:o.single,nodes:o.single.nodes};let i=o.odd,a=o.even;return{...d,diff:!0,z:2*i.z0,zodd:i.z0,zeven:a.z0,zcm:a.z0/2,eeff:i.eeff,eeffEven:a.eeff,mode:i,modeEven:a,nodes:i.nodes+a.nodes}}function bo(e,t,n,o,u=1){return{z:2*t.z0*u,eeff:t.eeff,mode:t,er:[1,...n.slabs.map(d=>d.er),n.mask?.er??1],tanD:o}}function xo(e){if(!e.stack.below.length||e.stack.below.some(o=>!(o.h>0)))throw new Error("The trace needs a dielectric between it and its reference plane.");if(e.stack.above.some(o=>!(o.h>0)))throw new Error("Every dielectric layer needs a thickness.");let{g:t,tanD:n}=cn(e);return bo(e,mo(t,"odd"),t,n)}function $o(e){let{g:t,tanD:n}=cn(e);return bo(e,an(t,"odd"),t,n,1.008)}var ur=20/Math.LN10,pr=1e3,fr=1e12;function qs(e,t,n,o){if(!(t>0))return[e,0];let u=r=>[.5*Math.log((fr*fr+r*r)/(pr*pr+r*r)),Math.atan2(r,fr)-Math.atan2(r,pr)],[d,i]=u(n),a=-e*t/i,l=e-a*d,[p,s]=u(o);return[l+a*p,-a*s]}function ea(e,t){if(!e||e.model==="none")return 1;if(e.model==="hammerstad")return e.rq>0?1+2/Math.PI*Math.atan(1.4*(e.rq/t)**2):1;if(!(e.rz>0))return 1;let n=.06*e.rz,o=t/n;return 1+7*Math.PI/3/(1+o+o*o/2)}function ta(e,t,n=cr){let o=Math.sqrt(Math.PI*t*Ve*n),u=-Ve*ze*e.dcAir/(e.cAir*e.cAir);return o/Ve*u}function hr(e,t,n){let o=t.rho??cr,u=2*Math.PI*n,d=0,i=0;for(let L=0;L<e.g.length;L++){let[H,U]=qs(t.er[L],t.tanD[L]??0,t.fRef,n);d+=H*e.g[L],i+=U*e.g[L]}let a=ze*d,l=u*ze*i,p=Math.sqrt(o/(Math.PI*n*Ve)),s=ea(t.roughness,p),r=t.t>0?ta(e,n,o)*s:0,f=t.t>0?o/(t.w*t.t):0,c=Math.hypot(f,r),x=Ve*ze/e.cAir+Math.min(r/u,Ve/(8*Math.PI)),S=c,M=u*x,b=l,h=u*a,w=S*b-M*h,v=S*h+M*b,g=Math.hypot(w,v),$=Math.sqrt(Math.max(0,(g+w)/2)),y=Math.sqrt((g-w)/2),T=b*b+h*h,E=(S*b+M*h)/T,m=(M*b-S*h)/T,C=Math.hypot(E,m),k=[Math.sqrt((C+E)/2),Math.sign(m)*Math.sqrt(Math.max(0,(C-E)/2))],I=Math.hypot(k[0],k[1]),R=c/k[0],N=l*k[0],A=R+N>0?ur*$*R/(R+N):0;return{f:n,R:c,L:x,G:l,C:a,zc:k,z0:I,alpha:$,beta:y,loss:ur*$,lossC:A,lossD:ur*$-A,eeff:(y*299792458/u)**2,delay:y/u,skinDepth:p,kRough:s}}function Mo(e,t,n,o=1.25,u=400){let d=t-e;if(d<=0)return[e];let i=[0],a=n,l=0;for(;l+a<d/2&&i.length<u;)l+=a,i.push(l),a*=o;let p=i.map(c=>e+c),s=i.map(c=>t-c).reverse(),r=[...p,...s].sort((c,x)=>c-x),f=[];for(let c of r)(!f.length||c-f[f.length-1]>n*.3)&&f.push(c);return f[f.length-1]!==t&&(f[f.length-1]=t),f}function wo(...e){let t=e.flat().sort((o,u)=>o-u),n=[];for(let o of t)(!n.length||o-n[n.length-1]>1e-12)&&n.push(o);return n}function ko(e){let t=e.refine??1,n=e.ends?.lo??e.zLo,o=e.ends?.hi??e.zHi,u=e.ends?.lo!==void 0||e.ends?.hi!==void 0,d=e.pads??[],i=e.planes,a=Math.max(...i.map(w=>w.R)),l=i.map((w,v)=>v).sort((w,v)=>i[w].z0-i[v].z0),p=[n,...l.flatMap(w=>[i[w].z0,i[w].z1]),o],s=0;for(let w=0;w<p.length;w+=2)s=Math.max(s,p[w+1]-p[w]);let r=a+6*Math.max(s,...i.map(w=>w.z1-w.z0))+4*(a-e.rb),f=Math.min(...i.map(w=>Math.min(w.R-e.rb,w.z1-w.z0)),...d.map(w=>w.z1-w.z0))/(6*t),c=w=>w>n+1e-12&&w<o-1e-12,x=na({axis:u,rEdges:[...u?[0]:[],e.rb,...d.map(w=>w.r),...i.map(w=>w.R),r].filter(w=>(u||w>=e.rb)&&w<=r),zEdges:[n,...[e.zLo,e.zHi].filter(c),...d.flatMap(w=>[w.z0,w.z1]).filter(c),...i.flatMap(w=>[w.z0,w.z1]).filter(c),o],h0:f,growth:1.2+.05/t,eps:w=>e.er(w)*ze,fixed:(w,v)=>{if(u){if(w<=e.rb+1e-15&&v>=e.zLo-1e-15&&v<=e.zHi+1e-15)return 1;if(e.ends.lo!==void 0&&v<=n+1e-15||e.ends.hi!==void 0&&v>=o-1e-15)return 0}for(let g of d)if(v>=g.z0-1e-15&&v<=g.z1+1e-15&&w<=g.r+1e-15)return 1;for(let g of i)if(v>=g.z0-1e-15&&v<=g.z1+1e-15&&w>=g.R-1e-15)return 0;return NaN}}),S=i.map(w=>(w.z0+w.z1)/2),M=i.map(()=>({Cup:0,Cdn:0})),b=0,h=0;return x.links((w,v,g,$,y,T)=>{if(y===0===(T===0))return;let C=v*Math.abs(g-$);if(w<e.zLo-1e-15){b+=C;return}if(w>e.zHi+1e-15){h+=C;return}let k=0;for(let I=1;I<S.length;I++)Math.abs(w-S[I])<Math.abs(w-S[k])&&(k=I);w>=S[k]?M[k].Cup+=C:M[k].Cdn+=C}),{planes:M,endLo:b,endHi:h}}function na(e){let t=[...new Set(e.rEdges)].sort((P,F)=>P-F),n=[...new Set(e.zEdges)].sort((P,F)=>P-F),o=[];for(let P=0;P<t.length-1;P++)t[P+1]-t[P]>1e-12&&o.push(Mo(t[P],t[P+1],e.h0,e.growth));let u=wo(...o),d=[];for(let P=0;P<n.length-1;P++)n[P+1]-n[P]>1e-12&&d.push(Mo(n[P],n[P+1],e.h0,e.growth));let i=wo(...d),a=u.length,l=i.length,p=a*l,s=(P,F)=>F*a+P,r=new Float64Array(Math.max(l-1,1));for(let P=0;P<l-1;P++)r[P]=e.eps((i[P]+i[P+1])/2);let f=P=>r[P],c=new Float64Array(p).fill(NaN);for(let P=0;P<l;P++){for(let F=0;F<a;F++)c[s(F,P)]=e.fixed(u[F],i[P]);e.axis||(c[s(0,P)]=1),isNaN(c[s(a-1,P)])&&(c[s(a-1,P)]=0)}let x=P=>(u[P]+u[P+1])/2,S=new Float64Array(p),M=new Float64Array(p);for(let P=0;P<l;P++)for(let F=0;F<a-1;F++){let V=0;P>0&&(V+=f(P-1)*(i[P]-i[P-1])/2),P<l-1&&(V+=f(P)*(i[P+1]-i[P])/2),S[s(F,P)]=2*Math.PI*x(F)*V/(u[F+1]-u[F])}for(let P=0;P<l-1;P++)for(let F=0;F<a;F++){let V=F>0?x(F-1):u[0],O=F<a-1?x(F):u[a-1],G=Math.PI*(O*O-V*V);M[s(F,P)]=f(P)*G/(i[P+1]-i[P])}let b=new Float64Array(p);for(let P=0;P<p;P++)b[P]=isNaN(c[P])?.5:c[P];let h=[];for(let P=0;P<p;P++)isNaN(c[P])&&h.push(P);let w=new Float64Array(p),v=new Int32Array(p).fill(-1);h.forEach((P,F)=>v[P]=F);let g=new Int32Array(h.length+1),$=new Int32Array(h.length*4),y=new Float64Array(h.length*4),T=new Float64Array(h.length),E=0;for(let P=0;P<h.length;P++){let F=h[P],V=F%a,O=(F-V)/a;g[P]=E;let G=(J,j)=>{w[F]+=j,isNaN(c[J])||(T[P]+=j*c[J]),$[E]=v[J],y[E]=j,E++};V<a-1&&G(F+1,S[F]),V>0&&G(F-1,S[F-1]),O<l-1&&G(F+a,M[F]),O>0&&G(F-a,M[F-a])}g[h.length]=E;let m=new Float64Array(h.length);for(let P=0;P<h.length;P++)m[P]=w[h[P]];let C=(P,F)=>{for(let V=0;V<m.length;V++){let O=m[V]*P[V];for(let G=g[V],J=g[V+1];G<J;G++){let j=$[G];j>=0&&(O-=y[G]*P[j])}F[V]=O}},k=h.length,I=new Float64Array(k).fill(.5),R=new Float64Array(k),N=new Float64Array(k),A=new Float64Array(k),L=new Float64Array(k);C(I,L);for(let P=0;P<k;P++)R[P]=T[P]-L[P],N[P]=R[P]/m[P],A[P]=N[P];let H=0;for(let P=0;P<k;P++)H+=R[P]*N[P];let U=Math.sqrt(T.reduce((P,F)=>P+F*F,0))||1;for(let P=0;P<20*k&&P<2e4;P++){C(A,L);let F=0;for(let j=0;j<k;j++)F+=A[j]*L[j];let V=H/F,O=0;for(let j=0;j<k;j++)I[j]+=V*A[j],R[j]-=V*L[j],O+=R[j]*R[j];if(Math.sqrt(O)<1e-11*U)break;let G=0;for(let j=0;j<k;j++)N[j]=R[j]/m[j],G+=R[j]*N[j];let J=G/H;H=G;for(let j=0;j<k;j++)A[j]=N[j]+J*A[j]}return h.forEach((P,F)=>b[P]=I[F]),{links(P){for(let F=0;F<l;F++)for(let V=0;V<a-1;V++)P(i[F],S[s(V,F)],b[s(V,F)],b[s(V+1,F)],c[s(V,F)],c[s(V+1,F)]);for(let F=0;F<l-1;F++)for(let V=0;V<a;V++)P((i[F]+i[F+1])/2,M[s(V,F)],b[s(V,F)],b[s(V,F+1)],c[s(V,F)],c[s(V,F+1)])}}}var W=(e,t=0)=>[e,t],ge=(e,t)=>[e[0]+t[0],e[1]+t[1]],$e=(e,t)=>[e[0]-t[0],e[1]-t[1]],X=(e,t)=>[e[0]*t[0]-e[1]*t[1],e[0]*t[1]+e[1]*t[0]],De=(e,t)=>{let n=t[0]*t[0]+t[1]*t[1];return[(e[0]*t[0]+e[1]*t[1])/n,(e[1]*t[0]-e[0]*t[1])/n]},Ut=e=>Math.hypot(e[0],e[1]);var ln=e=>20*Math.log10(Math.max(e,1e-15)),ee=(e,t)=>[e[0]*t,e[1]*t];var St=e=>{let t=Math.exp(e[0]);return[t*Math.cos(e[1]),t*Math.sin(e[1])]},mr=e=>[Math.log(Math.hypot(e[0],e[1])),Math.atan2(e[1],e[0])],Tt=e=>{let t=Math.hypot(e[0],e[1]),n=Math.sqrt((t+e[0])/2),o=Math.sign(e[1]||1)*Math.sqrt(Math.max(0,(t-e[0])/2));return[n,o]};var Gi=W(0,1);function gr(e,t){let n=t.length,o=e.map((d,i)=>[...d,t[i]]);for(let d=0;d<n;d++){let i=d;for(let a=d+1;a<n;a++)Ut(o[a][d])>Ut(o[i][d])&&(i=a);if(Ut(o[i][d])===0)throw new Error("csolve: singular matrix");[o[d],o[i]]=[o[i],o[d]];for(let a=d+1;a<n;a++){let l=De(o[a][d],o[d][d]);if(!(l[0]===0&&l[1]===0))for(let p=d;p<=n;p++)o[a][p]=$e(o[a][p],X(l,o[d][p]))}}let u=new Array(n);for(let d=n-1;d>=0;d--){let i=o[d][n];for(let a=d+1;a<n;a++)i=$e(i,X(o[d][a],u[a]));u[d]=De(i,o[d][d])}return u}function dn(e){let t=e.length,n=Array.from({length:t},(o,u)=>gr(e,Array.from({length:t},(d,i)=>W(i===u?1:0))));return Array.from({length:t},(o,u)=>Array.from({length:t},(d,i)=>n[i][u]))}var yr=.5772156649015329;function Co(e){let t=ee(X(e,e),-.25),n=W(1),o=W(1),u=W(0),d=0;for(let l=1;l<200&&(n=ee(X(n,t),1/(l*l)),d+=1/l,o=ge(o,n),u=ge(u,ee(n,-d)),!(Math.hypot(n[0],n[1])<1e-17*Math.hypot(o[0],o[1])&&l>5));l++);let i=ge(mr(ee(e,.5)),W(yr)),a=ee(ge(X(i,o),u),2/Math.PI);return{j0:o,y0:a}}function So(e){let t=W(1),n=1,o=W(1),u=W(1),d=W(0,-1),i=1/0;for(let p=1;p<30;p++){n*=-((2*p-1)**2)/(p*8),o=X(o,e),u=X(u,d);let s=ee(De(u,o),n),r=Math.hypot(s[0],s[1]);if(r>i||(t=ge(t,s),i=r,r<1e-17))break}let a=Tt(De(W(2/Math.PI),e)),l=St(X(W(0,-1),$e(e,W(Math.PI/4))));return X(X(a,l),t)}function un(e){if(Math.hypot(e[0],e[1])<=12)return Co(e);let t=So(e),n=ra(e);return{j0:ee(ge(n,t),.5),y0:De($e(n,t),W(0,2))}}function ra(e){let t=W(1),n=1,o=W(1),u=W(1),d=1/0;for(let l=1;l<30;l++){n*=-((2*l-1)**2)/(l*8),o=X(o,e),u=X(u,W(0,1));let p=ee(De(u,o),n),s=Math.hypot(p[0],p[1]);if(s>d||(t=ge(t,p),d=s,s<1e-17))break}let i=Tt(De(W(2/Math.PI),e)),a=St(X(W(0,1),$e(e,W(Math.PI/4))));return X(X(i,a),t)}function pn(e){if(Math.hypot(e[0],e[1])>12)return So(e);let{j0:t,y0:n}=Co(e);return $e(t,X(W(0,1),n))}function oa(e){let t=ee(X(e,e),-.25),n=ee(e,.5),o=W(1),u=W(1),d=0,i=W(1-2*yr);for(let p=1;p<200&&(o=ee(X(o,t),1/(p*(p+1))),d+=1/p,u=ge(u,o),i=ge(i,ee(o,2*d+1/(p+1)-2*yr)),!(Math.hypot(o[0],o[1])<1e-17*Math.hypot(u[0],u[1])&&p>5));p++);let a=X(n,u),l=ge(ge(De(W(-2/Math.PI),e),ee(X(mr(n),a),2/Math.PI)),ee(X(n,i),-1/Math.PI));return{j1:a,y1:l}}function sa(e,t){let n=W(1),o=1,u=W(1),d=W(1),i=1/0;for(let p=1;p<40;p++){o*=(4*t*t-(2*p-1)**2)/(8*p),u=X(u,e),d=X(d,W(0,-1));let s=ee(De(d,u),o),r=Math.hypot(s[0],s[1]);if(r>i||(n=ge(n,s),i=r,r<1e-17))break}let a=Tt(De(W(2/Math.PI),e)),l=St(X(W(0,-1),$e(e,W(t*Math.PI/2+Math.PI/4))));return X(X(a,l),n)}function aa(e){if(Math.hypot(e[0],e[1])>12)return sa(e,1);let{j1:t,y1:n}=oa(e);return $e(t,X(W(0,1),n))}function Gt(e,t){let n=Math.hypot(t[0],t[1]),o=2*Math.ceil((Math.max(e,n)+40)/2),u=new Array(o+2);u[o+1]=W(0),u[o]=W(1);let d=De(W(2),t);for(let s=o;s>=1;s--)if(u[s-1]=$e(X(ee(d,s),u[s]),u[s+1]),Math.hypot(u[s-1][0],u[s-1][1])>1e100)for(let r=s-1;r<=o;r++)u[r]=ee(u[r],1e-100);let i=Math.abs(t[1])>Math.abs(t[0]),a=u[0];for(let s=2;s<=o;s+=2)a=ge(a,ee(u[s],i&&s/2%2?-2:2));i&&(a=De(a,W(Math.cos(t[0])*Math.cosh(t[1]),-Math.sin(t[0])*Math.sinh(t[1]))));let l=u.slice(0,e+1).map(s=>De(s,a)),p=[pn(t)];e>=1&&p.push(aa(t));for(let s=1;s<e;s++)p.push($e(X(ee(d,s),p[s]),p[s-1]));return{j:l,h:p}}var br=(e,t)=>t>=0?e[t]:t%2?ee(e[-t],-1):e[-t],xr=(e,t)=>W(Math.cos(e*t),Math.sin(e*t));function $r(e,t,n,o){let u=t.length,d=2*n+1,i=t.map((g,$)=>g.kind==="signal"?$:-1).filter(g=>g>=0),a=(g,$)=>g*d+($+n),l=Array.from({length:u*d},()=>Array.from({length:u*d},()=>W(0))),p=new Map,s=g=>{let $=Math.round(g*1e9),y=p.get($);return y||(y=Gt(2*n,ee(e,g)).h,p.set($,y)),y};for(let g=0;g<u;g++)for(let $=0;$<u;$++){if(g===$)continue;let y=t[$].x-t[g].x,T=t[$].y-t[g].y,E=s(Math.hypot(y,T)),m=Math.atan2(T,y);for(let C=-n;C<=n;C++)for(let k=-n;k<=n;k++)l[a($,k)][a(g,C)]=X(br(E,C-k),xr(C-k,m))}if(o){let g=ee(e,o.R),$=20+Math.ceil(Math.hypot(g[0],g[1])),y=Gt($+1,g),T=X(W(0,1),o.zeta),E=(k,I)=>I===0?ee(k[1],-1):$e(k[I-1],X(De(W(I),g),k[I])),m=Array.from({length:$+1},(k,I)=>ee(De($e(y.h[I],X(T,E(y.h,I))),$e(y.j[I],X(T,E(y.j,I)))),-1)),C=t.map(k=>{let I=Math.hypot(k.x,k.y);return{J:I<1e-12?[W(1),...Array.from({length:$+n},()=>W(0))]:Gt($+n,ee(e,I)).j,out:Math.atan2(-k.y,-k.x),back:Math.atan2(k.y,k.x)}});for(let k=0;k<u;k++)for(let I=0;I<u;I++)for(let R=-n;R<=n;R++)for(let N=-n;N<=n;N++){let A=W(0);for(let L=-$;L<=$;L++){let H=X(br(C[k].J,R-L),xr(R-L,C[k].out)),U=X(br(C[I].J,L-N),xr(L-N,C[I].back));A=ge(A,X(X(H,m[Math.abs(L)]),U))}l[a(I,N)][a(k,R)]=ge(l[a(I,N)][a(k,R)],A)}}let r=(g,$)=>$===0&&t[g].kind==="signal",f=[];for(let g=0;g<u;g++)for(let $=-n;$<=n;$++)r(g,$)||f.push([g,$]);let c=new Map,x=t.map(g=>{let $=c.get(g.r);if(!$){let y=Gt(n,ee(e,g.r));$=y.j.map((T,E)=>De(T,y.h[E])),c.set(g.r,$)}return $}),S=f.length,M=i.length,b=S+M,h=new Float64Array(S*b),w=new Float64Array(S*b);f.forEach(([g,$],y)=>{let T=x[g][Math.abs($)];f.forEach(([E,m],C)=>{let k=X(T,l[a(g,$)][a(E,m)]);h[y*b+C]=k[0]+(y===C?1:0),w[y*b+C]=k[1]}),i.forEach((E,m)=>{let C=X(T,l[a(g,$)][a(E,0)]);h[y*b+S+m]=-C[0],w[y*b+S+m]=-C[1]})});for(let g=0;g<S;g++){let $=g,y=0;for(let C=g;C<S;C++){let k=h[C*b+g]**2+w[C*b+g]**2;k>y&&(y=k,$=C)}if(y===0)throw new Error("plateReaction: singular system");if($!==g)for(let C=g;C<b;C++){let k=h[g*b+C],I=w[g*b+C];h[g*b+C]=h[$*b+C],w[g*b+C]=w[$*b+C],h[$*b+C]=k,w[$*b+C]=I}let T=h[g*b+g],E=w[g*b+g],m=T*T+E*E;for(let C=g+1;C<S;C++){let k=h[C*b+g],I=w[C*b+g];if(k===0&&I===0)continue;let R=(k*T+I*E)/m,N=(I*T-k*E)/m;for(let A=g;A<b;A++){let L=h[g*b+A],H=w[g*b+A];h[C*b+A]-=R*L-N*H,w[C*b+A]-=R*H+N*L}}}let v=i.map(()=>new Array(S));for(let g=0;g<M;g++)for(let $=S-1;$>=0;$--){let y=h[$*b+S+g],T=w[$*b+S+g];for(let k=$+1;k<S;k++){let I=v[g][k];y-=h[$*b+k]*I[0]-w[$*b+k]*I[1],T-=h[$*b+k]*I[1]+w[$*b+k]*I[0]}let E=h[$*b+$],m=w[$*b+$],C=E*E+m*m;v[g][$]=W((y*E+T*m)/C,(T*E-y*m)/C)}return i.map(g=>i.map(($,y)=>{let T=l[a(g,0)][a($,0)];return f.forEach(([E,m],C)=>{T=ge(T,X(l[a(g,0)][a(E,m)],v[y][C]))}),T}))}function Jt(e){let t=Math.hypot(e[0],e[1]);if(e[0]>15&&t>12){let i=W(1),a=W(1),l=W(1),p=1,s=1/0;for(let f=1;f<40;f++){p*=(2*f-1)**2/(8*f),l=X(l,e);let c=ee(De(W(1),l),p),x=Math.hypot(c[0],c[1]);if(x>s||(i=ge(i,c),a=f%2?$e(a,c):ge(a,c),s=x,x<1e-17))break}let r=Tt(e);return{i0e:De(i,ee(r,Math.sqrt(2*Math.PI))),k0e:De(ee(a,Math.sqrt(Math.PI/2)),r)}}let n=W(e[1],-e[0]),o,u;if(t<=12){let i=un(n);o=i.j0,u=$e(i.j0,X(W(0,1),i.y0))}else o=un(n).j0,u=pn(n);let d=X(W(0,-Math.PI/2),u);return{i0e:X(o,St(ee(e,-1))),k0e:X(d,St(e))}}function vo(e,t,n){let o=ee(e,t),u=ee(e,n),d=Jt(o),i=Jt(u),a=X(i.i0e,i.k0e),l=X(De(X(d.i0e,X(i.k0e,i.k0e)),d.k0e),St(ee($e(o,u),2)));return $e(W(1),ee($e(a,l),1/Math.log(n/t)))}var ia=24,Po=400;function To(e,t,n,o){let u=4*Math.PI*ze*o/(n*Math.log(t/e)),d=[],i=0,a=0,l=0;for(let r=1;r<=Po;r++){let f=r*Math.PI/n,c=u/(f*f)*vo(W(f),e,t)[0];r<=ia&&d.push(c),r%2&&(i+=c),l=a,a+=r%2?-c:c}let p=Po,s=u*n*n/(Math.PI*Math.PI);return i+=s*(1/(2*p)-n/(2*Math.PI*t*Math.log(t/e))/(4*p*p)),{cn:d,cOdd:2*i,cAlt:(a+l)/2}}function Io(e,t,n,o,u,d,i,a=1/0){let l=2*Math.PI*e,p=W(ze*u,-ze*u*d),s=ee(p,l*l*Ve),r=Tt(s),f=W(r[0],-Math.abs(r[1])),c=Math.log(n/t),x=W(1,-d),S=un(ee(f,t)),M=un(ee(f,n)),b=$e(S.j0,X(W(0,1),S.y0)),h=$e(M.j0,X(W(0,1),M.y0)),w=ee($e(X(M.y0,S.j0),X(M.j0,S.y0)),Math.PI/(2*c)),v=X(De(X(W(0,-2*Math.PI*l/(o*c)),p),s),$e(W(1),X(w,De(h,b)))),g=ee(b,l*Ve*o/4),$=ee(p,4*Math.PI/(o*c)),y=W(0),T=W(0),E=[];for(let m=1;m<=i.cn.length;m++){let C=$e(W((m*Math.PI/o)**2),s),k=Tt(C),I=X(De($,C),vo(k,t,n)),R=$e(I,ee(x,i.cn[m-1]));if(m%2?(y=ge(y,R),T=$e(T,R)):T=ge(T,R),k[0]*a<7){let N=Jt(ee(k,t)),A=Jt(ee(k,n)),L=St(ee(k,n-t)),H=ee($e(X(X(A.i0e,N.k0e),L),De(X(A.k0e,N.i0e),L)),1/c),U=X(W(0,2/Math.PI),X(N.k0e,St(ee(k,-t)))),P=X(N.i0e,St(ee(k,t))),F=ee(C,-1);E.push({n:m,kn:W(k[1],-k[0]),coef:De(X(ee(p,8*l/o),X(H,H)),X(F,U)),h0a:U,j0a:P})}}return{y0:v,T:w,j0a:S.j0,zss:g,cShuntDelta:ee(y,2),cSeries:ge(ee(x,i.cAlt),T),reach:E}}var Ao=(e,t)=>1/(2*e*Math.sqrt(Ve*ze*t));function Mr(e,t,n,o,u){let d=[...new Set(e.map(l=>+l.toPrecision(12)))].sort((l,p)=>l-p),i=l=>Math.min(u,...t.map(p=>n+(o-1)*Math.abs(l-p))),a=[d[0]];for(let l=0;l+1<d.length;l++){let p=d[l],s=d[l+1],r=p;for(;;){let f=Math.min(i(r),(s-p)/2);if(r+f>=s-.3*f)break;r+=f,a.push(r)}a.push(s)}return a}function wr(e,t,n,o,u,d){let i=e.length,a=t.length,l=n.length,p=i*a*l,s=i,r=i*a,f=(O,G)=>((G>0?O[G]-O[G-1]:0)+(G<O.length-1?O[G+1]-O[G]:0))/2,c=n.slice(0,-1).map((O,G)=>o((O+n[G+1])/2)),x=O=>{let G=O>0?c[O-1]*(n[O]-n[O-1]):0,J=O<l-1?c[O]*(n[O+1]-n[O]):0;return(G+J)/((O>0?n[O]-n[O-1]:0)+(O<l-1?n[O+1]-n[O]:0))},S=new Float64Array(p),M=new Float64Array(p),b=new Float64Array(p),h=e.map((O,G)=>f(e,G)),w=t.map((O,G)=>f(t,G));for(let O=0;O<l;O++){let G=f(n,O),J=x(O);for(let j=0;j<a;j++)for(let Z=0;Z<i;Z++){let ae=Z+s*j+r*O;Z<i-1&&(S[ae]=J*w[j]*G/(e[Z+1]-e[Z])),j<a-1&&(M[ae]=J*h[Z]*G/(t[j+1]-t[j])),O<l-1&&(b[ae]=c[O]*h[Z]*w[j]/(n[O+1]-n[O]))}}let v=new Float64Array(p),g=new Uint8Array(p);for(let O=0;O<l;O++)for(let G=0;G<a;G++)for(let J=0;J<i;J++){let j=J+s*G+r*O,Z=u(e[J],t[G],n[O],J,G);Number.isNaN(Z)?(g[j]=1,v[j]=d?d[j]:.3):v[j]=Z}let $=[];for(let O=0;O<p;O++)g[O]&&$.push(O);let y=$.length,T=new Int32Array(p).fill(-1);$.forEach((O,G)=>{T[O]=G});let E=new Int32Array(6*y).fill(-1),m=new Float64Array(6*y),C=new Float64Array(y),k=new Float64Array(y),I=new Float64Array(y);for(let O=0;O<y;O++){let G=$[O],J=G%i,j=(G-J)/i%a,Z=(G-J-s*j)/r,ae=[];J<i-1&&ae.push([G+1,S[G]]),J>0&&ae.push([G-1,S[G-1]]),j<a-1&&ae.push([G+s,M[G]]),j>0&&ae.push([G-s,M[G-s]]),Z<l-1&&ae.push([G+r,b[G]]),Z>0&&ae.push([G-r,b[G-r]]),ae.forEach(([z,oe],Te)=>{C[O]+=oe,g[z]?(E[6*O+Te]=T[z],m[6*O+Te]=oe):k[O]+=oe*v[z]}),I[O]=v[G]}let R=(O,G)=>{for(let J=0;J<y;J++){let j=C[J]*O[J];for(let Z=6*J;Z<6*J+6;Z++){let ae=E[Z];ae>=0&&(j-=m[Z]*O[ae])}G[J]=j}},N=(O,G)=>{for(let J=0;J<y;J++){let j=O[J];for(let Z=6*J;Z<6*J+6;Z++){let ae=E[Z];ae>=0&&ae<J&&(j+=m[Z]*G[ae])}G[J]=j/C[J]}for(let J=0;J<y;J++)G[J]*=C[J];for(let J=y-1;J>=0;J--){let j=G[J];for(let Z=6*J;Z<6*J+6;Z++){let ae=E[Z];ae>J&&(j+=m[Z]*G[ae])}G[J]=j/C[J]}},A=new Float64Array(y),L=new Float64Array(y),H=new Float64Array(y),U=new Float64Array(y);R(I,U);let P=0;for(let O=0;O<y;O++)A[O]=k[O]-U[O],P+=k[O]*k[O];P=Math.sqrt(P)||1,N(A,L),H.set(L);let F=0;for(let O=0;O<y;O++)F+=A[O]*L[O];for(let O=0;O<3e3;O++){R(H,U);let G=0;for(let z=0;z<y;z++)G+=H[z]*U[z];let J=F/G,j=0;for(let z=0;z<y;z++)I[z]+=J*H[z],A[z]-=J*U[z],j+=A[z]*A[z];if(Math.sqrt(j)<1e-4*P)break;N(A,L);let Z=0;for(let z=0;z<y;z++)Z+=A[z]*L[z];let ae=Z/F;F=Z;for(let z=0;z<y;z++)H[z]=L[z]+ae*H[z]}for(let O=0;O<y;O++)v[$[O]]=I[O];let V=0;for(let O=0;O<p;O++){let G=O%i,J=(O-G)/i%a,j=(O-G-s*J)/r;G<i-1&&(V+=S[O]*(v[O+1]-v[O])**2),J<a-1&&(V+=M[O]*(v[O+s]-v[O])**2),j<l-1&&(V+=b[O]*(v[O+r]-v[O])**2)}return{C:2*ze*V,V:v}}function ca(e,t,n,o){let u=[0,1],{C:d}=wr(u,e,t,n,(i,a,l)=>o(a,l));return d}var Fo=new Map;function Do(e,t=.5){let n=P=>JSON.stringify([P.a,P.rp,P.w,P.barrel,P.planes,[-3,-2,-1,-.5,.5,1,2,3].map(F=>P.er(F*1e-4)),t]),o={...e,barrel:[-e.barrel[1],-e.barrel[0]],planes:e.planes.map(P=>({z0:-P.z1,z1:-P.z0,ra:P.ra})).reverse(),er:P=>e.er(-P)},[u,d]=[n(e),n(o)],i=d<u?o:e,a=d<u?d:u,l=Fo.get(a);if(l!==void 0)return l;let p=i.planes.filter(P=>P.z0>0).sort((P,F)=>P.z0-F.z0)[0],s=i.planes.filter(P=>P.z1<0).sort((P,F)=>F.z1-P.z1)[0];if(!p||!s)throw new Error("junctionC: the trace needs a plane above and below");let r=p.z0-s.z1,f=P=>{let F=P>0?p:s;if(!(P>0?i.barrel[1]>F.z1-1e-12:i.barrel[0]<F.z0+1e-12))return P>0?F.z1:F.z0;let O=i.planes.filter(J=>P>0?J.z0>F.z1:J.z1<F.z0).sort((J,j)=>P>0?J.z0-j.z0:j.z1-J.z1)[0],G=P>0?F.z1+r:F.z0-r;return O?P>0?Math.min(O.z1,G):Math.max(O.z0,G):G},c=f(1),x=f(-1),S=i.planes.filter(P=>P.z1>x-1e-12&&P.z0<c+1e-12),M=[...new Set(S.map(P=>P.ra).filter(P=>P!==null))],b=Math.max(i.rp,...M),h=i.rp+2*r,w=b+1.5*r,v=b+1.5*r,g=Math.min(i.w/2,i.rp-i.a,r/4)/(8*t),$=1.3,y=r/(3*t),T=-Math.sqrt(Math.max(0,i.rp**2-(i.w/2)**2)),E=Mr([-h,-i.rp,-i.a,0,i.a,i.rp,...M.flatMap(P=>[-P,P]),w],[-i.rp,T,-i.a,i.a,i.rp,...M.flatMap(P=>[-P,P])],g,$,y),m=Mr([0,i.w/2,i.a,i.rp,...M,v],[i.w/2,i.a,i.rp,...M],g,$,y),C=S.flatMap(P=>[P.z0,P.z1]),k=Mr([x,c,0,...C,...i.barrel].filter(P=>P>=x-1e-12&&P<=c+1e-12),[0,...S.filter(P=>P.ra!==null).flatMap(P=>[P.z0,P.z1])],g,$,y),I=g*.001,R=P=>S.find(F=>P>=F.z0-I&&P<=F.z1+I),N=(P,F,V,O,G,J)=>{let j=Math.hypot(P,F),Z=R(V);return Z&&(Z.ra===null||j>=Z.ra-I)?0:j<=i.a+I&&V>=i.barrel[0]-I&&V<=i.barrel[1]+I||Math.abs(V)<I&&(j<=i.rp+I||J&&P<=T+I&&F<=i.w/2+I)?1:O===E.length-1||G===m.length-1?0:NaN},A=wr(E,m,k,i.er,(P,F,V,O,G)=>N(P,F,V,O,G,!1)),L=wr(E,m,k,i.er,(P,F,V,O,G)=>N(P,F,V,O,G,!0),A.V),H=ca(m,k,i.er,(P,F)=>R(F)?0:Math.abs(F)<I&&P<=i.w/2+I?1:P>=m[m.length-1]-I?0:NaN),U=L.C-A.C-H*(h-i.rp);return Fo.set(a,U),U}var fn={microstrip:2e10,stripline:2e10,backdrill:17e9,striplineThru:3e10,pair:2e10},kr=[20,25,30,40,50];function la(e){if(!(e>0))return"0";let t=Math.floor(Math.log10(e)),n=Math.ceil(e/10**(t-1)-1e-9)*10**(t-1);return n>=10**(t+1)-1e-12&&(t+=1),n.toFixed(Math.max(0,1-t))}function Eo(e){let t=e.map(n=>`${la(n.diff)} up to ${n.upTo} GHz`);return t.length>1?`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`:t[0]??""}var Cr={microstrip:{cases:["ms1","ms2","ms1a","ms1b","ms2a","ms2b"],upTo:[[20,.0308],[25,.0447],[30,.0634],[40,.1412],[50,.3516]]},stripline:{cases:["bl1","bl2","bl3","bl4","bl5","bl6"],upTo:[[20,.0323],[25,.054],[30,.0868],[40,.1875],[50,.3798]]},backdrill:{cases:["bd1","bd2"],upTo:[[20,.048],[25,.0953],[30,.1771],[40,.5925],[50,.7523]]},striplineThru:{cases:["th1","th2","th3"],upTo:[[20,.0202],[25,.0216],[30,.0337],[40,.0468],[50,.0604]]},pair:{cases:["md1"],upTo:[[20,.0226],[25,.0308],[30,.0416],[40,.0714],[50,.0995]]}};var Ro=5e-6,da=["no","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"],ua=.8;function Oo(e,t){let n=e.length,o=e.slice(1).map((i,a)=>i-e[a]),u=o.map((i,a)=>(t[a+1]-t[a])/i),d=e.map((i,a)=>a===0?u[0]:a===n-1?u[n-2]:u[a-1]*u[a]<=0?0:3*(o[a-1]+o[a])/((2*o[a]+o[a-1])/u[a-1]+(o[a]+2*o[a-1])/u[a]));return i=>{let a=0;for(;a<n-2&&i>e[a+1];)a++;let l=(i-e[a])/o[a],p=l*l,s=p*l;return(2*s-3*p+1)*t[a]+(s-2*p+l)*o[a]*d[a]+(-2*s+3*p)*t[a+1]+(s-p)*o[a]*d[a+1]}}var No=new Map;function pa(e,t,n,o,u,d){if(!(u>n))return{out:0,pad:0};let i=[e,t,n,o,u,d].map(b=>b.toPrecision(6)).join(),a=No.get(i);if(a)return a;let l=Math.sqrt(u*u-n*n),p={div:256,reach:50},s=dr(e,t,0,d,p),r=[0],f=[0];for(let b=1;b<=3;b++){let h=l*b/3;r.push(h),f.push(dr(e,t,h,d,p)-s)}let c=Oo(r,f),x=200,S=(b,h)=>{if(!(h>b))return 0;let w=0,v=(h-b)/x;for(let g=0;g<=x;g++)w+=(g===0||g===x?1:g%2?4:2)*c(Math.sqrt(Math.max(0,u*u-(b+g*v)**2)));return w*v/3},M={out:S(Math.max(o,n),u),pad:S(n,Math.min(o,u))};return No.set(i,M),M}var hn=new Map;function fa(e,t,n,o,u){let d=Math.max(o,n);if(!(u>d)||!t.some(w=>w.slotted))return 0;let i=[e,n,o,u,...t.flatMap(w=>[w.y,w.slotted?1:0])].map(w=>(+w).toPrecision(6)).join(),a=hn.get(i);if(a!==void 0)return a;let l=Math.sqrt(u*u-d*d),p={div:64},s=w=>Ve/yo(e,t.map(v=>({y:v.y,s:v.slotted?w:0})),p),r=s(0),f=[0],c=[0];for(let w=1;w<=3;w++){let v=l*w/3;f.push(v),c.push(s(v)-r)}let x=Oo(f,c),S=200,M=(u-d)/S,b=0;for(let w=0;w<=S;w++)b+=(w===0||w===S?1:w%2?4:2)*x(Math.sqrt(Math.max(0,u*u-(d+w*M)**2)));let h=b*M/3;return hn.set(i,h),hn.size>64&&hn.delete(hn.keys().next().value),h}function ha(e){let t=0;return e.map(n=>{let o={top:t,bottom:t+n.t};return t+=n.t,o})}function ma(e,t,n,o){let u=0,d=0;return e.forEach((i,a)=>{if(i.kind!=="dielectric")return;let l=Math.max(0,Math.min(o,t[a].bottom)-Math.max(n,t[a].top));u+=l,d+=l*i.er}),u>0?d/u:4}function ga(e){let t=e.drill/2,n=e.diff?[{x:-e.pitch/2,y:0},{x:e.pitch/2,y:0}]:[{x:0,y:0}],o=[],u=e.ground.dist;if(e.diff)e.ground.n===1&&o.push({x:0,y:u}),e.ground.n>=2&&o.push({x:-(e.pitch/2+u),y:0},{x:e.pitch/2+u,y:0}),e.ground.n===4&&o.push({x:0,y:u},{x:0,y:-u});else{let d=e.ground.angle??0;for(let i=0;i<e.ground.n;i++){let a=d+2*Math.PI*i/e.ground.n;o.push({x:u*Math.cos(a),y:u*Math.sin(a)})}}return o.push(...e.groundExtra??[]),[...n.map(d=>({...d,r:t,kind:"signal"})),...o.map(d=>({...d,r:t,kind:"ground"}))]}var mn=new Map;function Sr(e,t,n){let o=JSON.stringify([e,t.map(d=>[d.kind,d.t,d.er])]),u=mn.get(o);return u||(u=ko({...e,er:n}),mn.set(o,u),mn.size>12&&mn.delete(mn.keys().next().value)),u}function ya(e){let t=n=>n!==void 0&&isFinite(n)&&n>0;if(!e.layers.every(n=>isFinite(n.t)&&n.t>0))return"Every layer needs a thickness above zero (see Stackup).";if(!e.layers.every(n=>n.kind!=="dielectric"||isFinite(n.er)&&n.er>=1))return"Every dielectric needs a relative permittivity of 1 or more (see Stackup).";if(!t(e.drill))return"The drill diameter must be above zero.";if(!(isFinite(e.pad)&&e.pad>=0))return"The pad diameter cannot be negative.";if(!t(e.antipad))return"The antipad diameter must be above zero.";if(!(isFinite(e.tanD)&&e.tanD>=0))return"The loss tangent cannot be negative.";if(!t(e.z0))return"The port impedance must be above zero.";if(e.ground.n>0&&!t(e.ground.dist))return"The stitching via distance must be above zero.";if(e.diff&&!t(e.pitch))return"The pair pitch must be above zero.";if(!(e.stub===void 0||isFinite(e.stub)&&e.stub>=0))return"The stub length cannot be negative.";for(let n of[e.traceW?.upper,e.traceW?.lower])if(n!==void 0&&!t(n))return"The trace width must be above zero.";return null}function Bo(e,t,n=200){let o=ya(e);if(o)return{ok:!1,message:o};let u=e.layers,d=ha(u),i=d[d.length-1].bottom;if(!d[e.from]||!d[e.to])return{ok:!1,message:"Pick the two layers the via connects."};let[a,l]=d[e.from].top<=d[e.to].top?[e.from,e.to]:[e.to,e.from];if(a===l)return{ok:!1,message:"Pick two different layers."};if(u[a].plane||u[l].plane)return{ok:!1,message:"One of the chosen layers is a reference plane. A via that connects to a plane is a ground via. Pick two signal layers."};if(e.antipad<=e.drill)return{ok:!1,message:"The antipad must be larger than the drill."};let p=e.backdrill?d[a].top:0,s=e.backdrill?Math.min(i,d[l].bottom+(e.stub??0)):i,r=u.map((D,_)=>_).filter(D=>u[D].kind==="copper"&&u[D].plane),f=D=>d[D].top>=p-1e-12&&d[D].bottom<=s+1e-12,c=D=>{let _=(d[D].top+d[D].bottom)/2;return r.reduce((q,se)=>Math.abs((d[se].top+d[se].bottom)/2-_)<Math.abs((d[q].top+d[q].bottom)/2-_)?se:q,r[0])};if(!r.length)return{ok:!1,message:"Mark at least two reference planes in the stackup."};let x=D=>r.filter(_=>_<D).pop(),S=D=>r.find(_=>_>D),M=(D,_)=>{let q=x(D),se=S(D);if(!e.launch||q===void 0||se===void 0)return null;let Fe=_?p>d[q].bottom+1e-12:s<d[se].top-1e-12,Ze=_?p<=d[q].top+1e-12:s>=d[se].bottom-1e-12;return!Fe&&!Ze?null:{pU:q,pD:se,h:d[se].top-d[q].bottom,d:(d[D].top+d[D].bottom)/2-d[q].bottom,thru:Ze}},b=M(a,!0),h=M(l,!1),w=[b,h].filter(D=>!!D),v=[...r.filter(f),c(a),c(l),...w.flatMap(D=>[D.pU,D.pD])],g=Math.min(...v),$=Math.max(...v),y=r.filter(D=>D>=g&&D<=$);if(y.length<1)return{ok:!1,message:"No reference plane found near the trace layers. Mark ground or power layers as reference planes in Stackup."};let T=[],E=(e.barrel??"modal")==="modal",m=ga(e),C=e.diff?2:1,k=e.antipad/2,I=e.drill/2;if(e.diff&&e.pitch<e.antipad-1e-12)return{ok:!1,message:"The antipads of the pair overlap (pitch smaller than the antipad diameter). The model needs a separate antipad around each via. A shared oval antipad is not modelled yet."};for(let D of m.filter(_=>_.kind==="ground"))for(let _ of m.filter(q=>q.kind==="signal"))if(Math.hypot(D.x-_.x,D.y-_.y)<k+I-1e-12)return{ok:!1,message:`A stitching via sits inside the antipad (plane clearance) of the signal via. Move the stitching vias further out: at least ${((k+I)*1e3).toFixed(2)} mm (${((k+I)/254e-7).toFixed(1)} mil) centre to centre.`};let R=new Set([a,l]);p<=1e-12&&R.add(0),s>=i-1e-12&&R.add(u.length-1);let N=y.filter(f),A=u.map((D,_)=>({l:D,i:_})).filter(D=>D.l.kind==="dielectric"),L=D=>{let _=4,q=1/0;for(let{l:se,i:Fe}of A){let Ze=-D<d[Fe].top?d[Fe].top+D:-D>d[Fe].bottom?-D-d[Fe].bottom:0;Ze<q&&(q=Ze,_=se.er)}return _},H=[];for(let D of R)!u[D].plane&&d[D].bottom>p-1e-12&&d[D].top<s+1e-12&&H.push({z0:-d[D].bottom,z1:-d[D].top,r:(D===l&&D!==a?e.padTo??e.pad:e.pad)/2});let U={rb:e.drill/2,zLo:-s,zHi:-p,planes:N.map(D=>({z0:-d[D].bottom,z1:-d[D].top,R:e.antipad/2})),pads:H.filter(D=>D.r>e.drill/2+1e-9)},P=!!e.launch&&x(a)===void 0&&S(a)!==void 0&&d[S(a)].top-d[a].bottom>Ro,F=!!e.launch&&S(l)===void 0&&x(l)!==void 0&&d[l].top-d[x(l)].bottom>Ro,V=D=>_=>Math.abs(_.z1+d[D].top)<1e-12,O=U.pads.filter(D=>P&&V(a)(D)||F&&V(l)(D)),G=U.pads.filter(D=>b&&V(a)(D)||h&&V(l)(D)),J={...b&&!b.thru?{hi:-d[b.pU].bottom}:{},...h&&!h.thru?{lo:-d[h.pD].top}:{}},j={...U,pads:U.pads.filter(D=>!O.includes(D)&&!G.includes(D)),...Object.keys(J).length?{ends:J}:{}},Z=N.length?Sr(j,u,L):{planes:[],endLo:0,endHi:0},ae=Z.planes,z=D=>D.planes.reduce((_,q)=>_+q.Cup+q.Cdn,0),oe=D=>{let _=Sr({...j,pads:[...j.pads,...O.filter(V(D))]},u,L);return Math.max(0,z(_)-z(Z))},Te=P?oe(a):0,Ie=F?oe(l):0,Ne=D=>{let _=Sr({...j,pads:[...j.pads,...G.filter(V(D))]},u,L);return Math.max(0,z(_)+_.endLo+_.endHi-z(Z)-Z.endLo-Z.endHi)},Q=(D,_)=>{if(!(_>0))return 0;let q=(d[D].top+d[D].bottom)/2;try{return Do({a:e.drill/2,rp:(D===l&&D!==a?e.padTo??e.pad:e.pad)/2,w:_,barrel:[q-s,q-p],planes:r.map(se=>({z0:q-d[se].bottom,z1:q-d[se].top,ra:f(se)?e.antipad/2:null})),er:se=>L(se-q)})}catch(se){if(!(se instanceof Error&&se.message.startsWith("junctionC:")))throw se;return 0}},ye=b&&G.some(V(a))?Math.max(0,Ne(a)+Q(a,e.traceW?.upper)):0,be=h&&G.some(V(l))?Math.max(0,Ne(l)+Q(l,e.traceW?.lower)):0,Ee=y.map(D=>{let _=ae[N.indexOf(D)]??{Cup:0,Cdn:0};return{name:D,depth:(d[D].top+d[D].bottom)/2,C:_.Cup+_.Cdn,Cup:_.Cup,Cdn:_.Cdn}}),Qe=!1,rt=y.slice(0,-1).map((D,_)=>{let q=y[_+1],se=d[q].top-d[D].bottom,Fe=Math.max(0,Math.min(s,d[q].top)-Math.max(p,d[D].bottom));return Fe<se-1e-9&&(Qe=!0),{top:D,bottom:q,h:se,hx:Fe,er:ma(u,d,d[D].bottom,d[q].top)}});Qe&&T.push("The barrel ends inside a plane pair (backdrill or blind via). That cavity is modelled with the barrel length inside it, which is an approximation.");let ft=D=>{let _=(d[D].top+d[D].bottom)/2,q=0;return Ee.forEach((se,Fe)=>{Math.abs(se.depth-_)<Math.abs(Ee[q].depth-_)&&(q=Fe)}),q},qe=ft(a),ce=ft(l);qe===ce&&T.push("Both trace layers use the same nearest plane, so no plane pair sits in the return path between them. The via then acts mainly as a shunt capacitance and its own inductance is not included, which is optimistic.");let Oe=D=>r.some(_=>_<D)&&r.some(_=>_>D);(Oe(a)&&!b||Oe(l)&&!h)&&T.push("A stripline port is referenced to its nearest plane only. The second plane of the stripline is not included in the launch.");let Se=C,Xe=Ee.length,Re=0,Je=1,ne=D=>D,te=(D,_,q)=>Se+(D*2+_)*C+q,ke=P||!!b,ve=F||!!h,fe=Se+Xe*2*C,le=fe+(ke?2*C:0),xe=D=>fe+2*D,he=D=>xe(D)+1,Ce=D=>le+2*D,re=D=>Ce(D)+1,Ae=le+(ve?2*C:0),ct=(D,_)=>(d[D].top+d[D].bottom)/2<Ee[_].depth?Re:Je,Ke=ct(a,qe),lt=ct(l,ce),He=te(qe,Ke,0),pe=D=>D<He?D:D-1,je=[],Dt=D=>Ee.findIndex(_=>_.name===D),wt=(D,_)=>[[te(Dt(D.pU),Je,_),(D.h-D.d)/D.h],[te(Dt(D.pD),Re,_),D.d/D.h]];for(let D=0;D<C;D++)je.push(b?{pos:xe(D),neg:wt(b,D)}:{pos:P?xe(D):ne(D),neg:[[te(qe,Ke,D),1]]});for(let D=0;D<C;D++)je.push(h?{pos:Ce(D),neg:wt(h,D)}:{pos:F?Ce(D):ne(D),neg:[[te(ce,lt,D),1]]});let vn=(D,_)=>Ve*D/(2*Math.PI)*(Math.asinh(D/_)-Math.hypot(1,_/D)+_/D),Tn=D=>.5*vn(2*D,e.drill/2)*(e.launchScale?.post??1),Lr=P?d[S(a)].top-(d[a].top+d[a].bottom)/2:0,Or=F?(d[l].top+d[l].bottom)/2-d[x(l)].bottom:0,Br=D=>{let _=0;for(let q=1;q<=400;q++){let se=q*Math.PI/D.h,Fe=D.h/(q*Math.PI)*Math.sin(q*Math.PI*D.d/D.h),{i0e:Ze,k0e:dt}=Jt(W(se*e.drill/2,0));_+=Ve/(Math.PI*D.h)*Fe*Fe*X(Ze,dt)[0]}return _*(e.launchScale?.probe??1)},ks=P?Tn(Lr):b?Br(b):0,Cs=F?Tn(Or):h?Br(h):0,Ur=D=>e.diff?.5*vn(2*D,e.pitch)*(e.launchScale?.post??1):0,Ss=P?Ur(Lr):0,Ps=F?Ur(Or):0,_r=b&&!b.thru?Z.endHi*(e.launchScale?.end??1):0,zr=h&&!h.thru?Z.endLo*(e.launchScale?.end??1):0,vs=b?p-d[b.pU].bottom:0,Ts=h?s-d[h.pU].bottom:0,tn=D=>(D===l&&D!==a?e.padTo??e.pad:e.pad)/2,Vr=(D,_)=>_?_*Math.max(0,tn(D)-e.drill/2)*(e.launchScale?.cross??1):0,Hr=ke?Vr(a,e.traceL?.upper):0,Gr=ve?Vr(l,e.traceL?.lower):0,Kr=(D,_,q,se,Fe)=>{if(!(_>0))return{out:0,pad:0};let Ze=Fe?d[q].top-d[D].bottom:d[D].top-d[q].bottom,dt=se===void 0?50*Ze:Fe?d[se].top-d[q].top:d[q].bottom-d[se].bottom,_t=pa(_,Ze,e.drill/2,tn(D),e.antipad/2,dt),zt=e.launchScale?.open??1;return{out:_t.out*zt,pad:_t.pad*(e.launchScale?.openPad??ua)*zt}},jr=(D,_,q)=>{if(!(q>0))return{out:0,pad:0};let se=(d[D].top+d[D].bottom)/2,Fe=d[_.pD].top-d[_.pU].bottom,Ze=ht=>(d[ht].top+d[ht].bottom)/2<se?se-d[ht].bottom:-(d[ht].top-se),dt=[_.pU,_.pD].map(ht=>({y:Ze(ht),slotted:f(ht)})),_t=r.filter(ht=>ht<_.pU).pop(),zt=r.find(ht=>ht>_.pD);return f(_.pU)&&dt.push({y:_t!==void 0?Ze(_t):Ze(_.pU)+20*Fe,slotted:!1}),f(_.pD)&&dt.push({y:zt!==void 0?Ze(zt):Ze(_.pD)-20*Fe,slotted:!1}),{out:fa(q,dt,e.drill/2,tn(D),e.antipad/2)*(e.launchScale?.open??1),pad:0}},In=P?Kr(a,e.traceW?.upper,S(a),r.find(D=>D>S(a)),!0):b?jr(a,b,e.traceW?.upper):{out:0,pad:0},An=F?Kr(l,e.traceW?.lower,x(l),r.filter(D=>D<x(l)).pop(),!1):h?jr(l,h,e.traceW?.lower):{out:0,pad:0},Qn=(D,_)=>D>0?W(0,-1/(_*D)):W(1e6),Wr=Ee.map(D=>D.C>0?Ve*u[D.name].t/(2*Math.PI)*Math.log(e.antipad/e.drill):0),Fn=je.length,Is=(D,_)=>D===_?D.r:Math.hypot(D.x-_.x,D.y-_.y),As=m.filter(D=>D.kind==="signal"),Fs=m.filter(D=>D.kind==="ground"),Lt=W(1,-e.tanD),qn=D=>E&&D.hx>=D.h-1e-9,Jr=rt.map(D=>qn(D)?To(e.drill/2,e.antipad/2,D.h,D.er):null),Ds=Math.max(...rt.map(D=>D.er),...u.filter(D=>D.kind==="dielectric").map(D=>D.er)),er=1/0;for(let D of As)for(let _ of m)D!==_&&(er=Math.min(er,Is(D,_)));let tr=299792458/(4*(s-p)*Math.sqrt(Ds)),kt=5e10,nn="checked",Es=b&&!b.thru&&d[a].top-p>1e-6||h&&!h.thru&&s-d[l].bottom>1e-6,Dn=[P||F?"microstrip":null,w.some(D=>!D.thru)?Es?"backdrill":"stripline":null,w.some(D=>D.thru)?"striplineThru":null,e.diff&&(P||F||w.length>0)?"pair":null].filter(D=>D!==null),Xr=Math.min(1/0,...Dn.map(D=>fn[D]));Xr<kt&&(kt=Xr,nn="launch"),rt.forEach(D=>{if(D.hx<=0)return;let _=qn(D)?.9*Ao(D.h,D.er):tr;_<kt&&(kt=_,nn=qn(D)?"mode":"barrel")}),!rt.some(D=>D.hx>0)&&tr<kt&&(kt=tr,nn="barrel");let Zr=kr.filter(D=>D*1e9>kt*(1+1e-9)),nr=nn==="launch"&&t>kt*(1+1e-9)?Zr.filter((D,_)=>_===0||Zr[_-1]*1e9<t*(1-1e-9)).map(D=>({upTo:D,diff:Math.max(...Dn.map(_=>Cr[_].upTo[kr.indexOf(D)][1]))})):[],rr=[],Yr=[],Qr=NaN,Rs=Array.from({length:n},(D,_)=>t*(_+1)/n);for(let D of[1e6,...Rs]){let _=2*Math.PI*D,q=Array.from({length:Ae-1},()=>Array.from({length:Ae-1},()=>W(0))),se=(Y,me,Me)=>{Y!==He&&(q[pe(Y)][pe(Y)]=ge(q[pe(Y)][pe(Y)],Me)),me!==He&&(q[pe(me)][pe(me)]=ge(q[pe(me)][pe(me)],Me)),Y!==He&&me!==He&&(q[pe(Y)][pe(me)]=$e(q[pe(Y)][pe(me)],Me),q[pe(me)][pe(Y)]=$e(q[pe(me)][pe(Y)],Me))};for(let Y=1;Y<C;Y++)se(te(qe,Ke,Y),He,W(1));Ee.forEach((Y,me)=>{let Me=Wr[me]>0?W(0,-1/(_*Wr[me])):W(1e6);for(let We=0;We<C;We++)se(te(me,Re,We),te(me,Je,We),Me)});let Fe=(Y,me,Me,We,ut)=>{if(ut[0]===0&&ut[1]===0)return;let ot=Math.min(1,Math.max(0,We/me.h)),Le=[[Y,1],[te(Dt(me.pU),Je,Me),ot-1],[te(Dt(me.pD),Re,Me),-ot]];for(let[Pe,Be]of Le)for(let[xt,En]of Le)Pe!==He&&xt!==He&&(q[pe(Pe)][pe(xt)]=ge(q[pe(Pe)][pe(xt)],ee(ut,Be*En)))},Ze=(Y,me,Me,We)=>{if(!(We>0)){for(let Pe=0;Pe<C;Pe++)se(Y(Pe),me(Pe),Qn(Me,_));return}let ut=Me*Me-We*We,ot=[[Me/ut,-We/ut],[-We/ut,Me/ut]].map(Pe=>Pe.map(Be=>W(0,-Be/_))),Le=(Pe,Be,xt)=>{Pe!==He&&Be!==He&&(q[pe(Pe)][pe(Be)]=ge(q[pe(Pe)][pe(Be)],xt))};for(let Pe=0;Pe<2;Pe++)for(let Be=0;Be<2;Be++)Le(Y(Pe),Y(Be),ot[Pe][Be]),Le(Y(Pe),me(Be),ee(ot[Pe][Be],-1)),Le(me(Pe),Y(Be),ee(ot[Pe][Be],-1)),Le(me(Pe),me(Be),ot[Pe][Be])};if(ke){for(let Y=0;Y<C;Y++)se(xe(Y),he(Y),Qn(Hr/2+In.out,_));Ze(he,ne,Hr/2+In.pad+ks,Ss);for(let Y=0;Y<C;Y++)P?se(he(Y),te(qe,Ke,Y),X(W(0,_*Te),Lt)):(b.thru||Fe(he(Y),b,Y,vs,X(W(0,_*_r),Lt)),Fe(he(Y),b,Y,b.d,X(W(0,_*ye),Lt)))}if(ve){for(let Y=0;Y<C;Y++)se(Ce(Y),re(Y),Qn(Gr/2+An.out,_));Ze(re,ne,Gr/2+An.pad+Cs,Ps);for(let Y=0;Y<C;Y++)F?se(re(Y),te(ce,lt,Y),X(W(0,_*Ie),Lt)):(h.thru||Fe(re(Y),h,Y,Ts,X(W(0,_*zr),Lt)),Fe(re(Y),h,Y,h.d,X(W(0,_*be),Lt)))}Ee.forEach((Y,me)=>{for(let Me=0;Me<C;Me++)se(ne(Me),te(me,Re,Me),X(W(0,_*Y.Cup),Lt)),se(ne(Me),te(me,Je,Me),X(W(0,_*Y.Cdn),Lt))}),rt.forEach((Y,me)=>{let Me=Tt(W(_*_*Ve*ze*Y.er,-_*_*Ve*ze*Y.er*e.tanD));if(Y.hx<=0)return;let We=e.edge?{R:e.edge.radius,zeta:ee(Me,Math.sqrt(Ve/(ze*Y.er))/(_*Ve))}:void 0,ut=w.some(we=>!we.thru&&Y.top===we.pU&&Y.bottom===we.pD)?Y.h:Y.hx,ot=$r(Me,m,e.harmonics??2,We).map(we=>we.map(Ye=>ee(Ye,_*Ve*ut/4))),Le=me,Pe=me+1,Be=(we,Ye,et)=>{we!==He&&Ye!==He&&(q[pe(we)][pe(Ye)]=ge(q[pe(we)][pe(Ye)],et))},xt=(we,Ye,et)=>{for(let tt=0;tt<C;tt++)for(let st=0;st<C;st++){let mt=we[tt][st];Be(Ye(tt),Ye(st),mt),Be(Ye(tt),et(st),ee(mt,-1)),Be(et(tt),Ye(st),ee(mt,-1)),Be(et(tt),et(st),mt)}},En=Jr[me];if(!En){let we=ee(Me,e.drill/2),Ye=ee(De(pn(we),Gt(0,we).j[0]),_*Ve*ut/4);xt(dn(ot.map((et,tt)=>et.map((st,mt)=>tt===mt?ge(st,Ye):st))),et=>te(Le,Je,et),et=>te(Pe,Re,et));return}let Et=Io(D,e.drill/2,e.antipad/2,Y.h,Y.er,e.tanD,En,e.modeCoupling===!1?1/0:er),Os=dn(ot.map((we,Ye)=>we.map((et,tt)=>ge(X(Et.j0a,et),Ye===tt?Et.zss:W(0))))),Bs=De(X(Et.T,Et.T),Et.zss),Us=X(W(0,_),Et.cSeries),_s=ot.map((we,Ye)=>we.map((et,tt)=>{let st=W(0);for(let mt=0;mt<C;mt++)st=ge(st,X(we[mt],Os[mt][tt]));return $e(Ye===tt?ge(Et.y0,Us):W(0),X(Bs,st))}));xt(_s,we=>te(Le,Je,we),we=>te(Pe,Re,we));let qr=X(W(0,_),Et.cShuntDelta);for(let we=0;we<C;we++)se(ne(we),te(Le,Je,we),qr),se(ne(we),te(Pe,Re,we),qr);for(let we of Et.reach){let Ye=e.edge?{R:e.edge.radius,zeta:De(ee(W(ze*Y.er,0),_*Math.sqrt(Ve/(ze*Y.er))),we.kn)}:void 0,et=Ye&&-we.kn[1]*(Ye.R-Math.max(...m.map(at=>Math.hypot(at.x,at.y))))>12,tt=$r(we.kn,m,Math.min(e.harmonics??2,1),et?void 0:Ye),st=dn(tt.map((at,vt)=>at.map((rn,on)=>ge(X(we.j0a,rn),vt===on?we.h0a:W(0))))),mt=tt.map(at=>at.map((vt,rn)=>{let on=W(0);for(let Rn=0;Rn<C;Rn++)on=ge(on,X(at[Rn],st[Rn][rn]));return ee(X(we.coef,on),-1)})),eo=we.n%2===1;if(xt(mt.map(at=>at.map(vt=>ee(vt,eo?-1:1))),at=>te(Le,Je,at),at=>te(Pe,Re,at)),eo){let at=mt.map(vt=>vt.map(rn=>ee(rn,2)));xt(at,ne,vt=>te(Le,Je,vt)),xt(at,ne,vt=>te(Pe,Re,vt))}}});let dt=Array.from({length:Fn},()=>Array.from({length:Fn},()=>W(0)));for(let Y=0;Y<Fn;Y++){let me=Array.from({length:Ae-1},()=>W(0)),{pos:Me,neg:We}=je[Y];Me!==He&&(me[pe(Me)]=ge(me[pe(Me)],W(1)));for(let[Le,Pe]of We)Le!==He&&(me[pe(Le)]=$e(me[pe(Le)],W(Pe)));let ut=gr(q,me),ot=Le=>Le===He?W(0):ut[pe(Le)];for(let Le=0;Le<Fn;Le++)dt[Le][Y]=je[Le].neg.reduce((Pe,[Be,xt])=>$e(Pe,ee(ot(Be),xt)),ot(je[Le].pos))}if(D===1e6){Qr=$e(ge(dt[0][0],dt[C][C]),ge(dt[0][C],dt[C][0]))[1]/_;continue}let _t=dt.map((Y,me)=>Y.map((Me,We)=>me===We?$e(Me,W(e.z0)):Me)),zt=dt.map((Y,me)=>Y.map((Me,We)=>me===We?ge(Me,W(e.z0)):Me)),ht=dn(zt),Ct=_t.map(Y=>ht[0].map((me,Me)=>Y.reduce((We,ut,ot)=>ge(We,X(ut,ht[ot][Me])),W(0))));if(Yr.push({f:D,S:Ct}),!e.diff)rr.push({f:D,s11:ln(Ut(Ct[0][0])),s21:ln(Ut(Ct[1][0]))});else{let Y=ee($e(ge(Ct[0][0],Ct[1][1]),ge(Ct[0][1],Ct[1][0])),.5),me=ee($e(ge(Ct[2][0],Ct[3][1]),ge(Ct[2][1],Ct[3][0])),.5);rr.push({f:D,s11:ln(Ut(Y)),s21:ln(Ut(me))})}}Fs.length===0&&T.push("No stitching vias: the return current spreads into the plane pair and part of the power radiates away between the planes (shows up as loss).");let Ns={checked:"the model has not been compared with a 3D field solver",mode:"a second wave type starts to travel between the thickest pair of planes, and the model is not checked there",barrel:"the barrel is longer than a quarter wavelength where it ends inside a plane pair",launch:"the launch (pad and trace connection) differs from the 3D checks by more than about 0.035 in S"}[nn],or=new Set(Dn.flatMap(D=>Cr[D].cases)).size,Ls=nr.length?` Past that, the model's largest difference from 3D on ${or===1?"the one 3D case":`the ${da[or]??or} 3D cases`} of ${Dn.length>1?"these launches":"this launch"} (see Validation) is ${Eo(nr)}, in any S-parameter entry. 0.035 is about 0.3 dB on a through S21.`:"";t>kt&&T.push(`Above about ${(kt/1e9).toFixed(0)} GHz ${Ns}.${Ls} That part of the sweep is shaded as indicative.`),T.push("Planes are treated as infinite (no board-edge cavity resonances) and all reference planes are assumed tied together by the stitching vias.");let Ot=D=>D===a?"the upper layer":"the lower layer",sr={upper:P?"microstrip":b?"stripline":"barrel",lower:F?"microstrip":h?"stripline":"barrel"};if(e.launch){let D=P&&F;D&&T.push("Launch on both layers: the pad, the barrel between pad and plane and the current's path across the pad are included, and each port is on its trace at the pad edge.");for(let[_,q]of[[a,sr.upper],[l,sr.lower]]){if(q==="microstrip"){D||T.push(`Launch on ${Ot(_)}: the pad, the barrel between pad and plane and the current's path across the pad are included, and the port is on the trace at the pad edge.`);let se=e.antipad/2-tn(_),Fe=_===a?In:An;(_===a?e.traceW?.upper:e.traceW?.lower)>0?T.push(`On ${Ot(_)} the pad${se>1e-6?` and ${(se*1e6).toFixed(0)} \xB5m of trace`:""} run over the antipad opening, with no plane under them: ${((Fe.out+Fe.pad)*1e12).toFixed(0)} pH extra inductance, included.`):se>1e-6&&T.push(`On ${Ot(_)} the trace runs ${(se*1e6).toFixed(0)} \xB5m over the antipad opening. Without the trace width its extra inductance is not included.`)}else q==="stripline"&&!(_===a?b:h).thru?T.push(`Launch on ${Ot(_)}: the barrel ends on a stripline. Its return current through both planes, the barrel inside the plane pair, the pad and the path across it are included, and the port is on the trace at the pad edge.`):q==="stripline"?T.push(`Launch on ${Ot(_)}: a stripline on a barrel that runs on through the plane pair (the rest of the barrel is a stub). Its return current through both planes, the pad and the path across it are included, and the port is on the trace at the pad edge.`):e.diff||T.push(`No launch model for ${Ot(_)} in this stackup (no reference plane next to it on one side). That port is between the barrel and the nearest plane.`);if(q==="stripline"){let se=_===a?In:An,Fe=e.antipad/2-Math.max(tn(_),e.drill/2);se.out>0?T.push(`On ${Ot(_)} the first ${(Fe*1e6).toFixed(0)} \xB5m of trace run under the antipad opening before the stripline has both its planes: ${(se.out*1e12).toFixed(0)} pH extra inductance, included.`):Fe>1e-6&&!((_===a?e.traceW?.upper:e.traceW?.lower)>0)&&T.push(`On ${Ot(_)} the trace runs ${(Fe*1e6).toFixed(0)} \xB5m under the antipad opening. Without the trace width its extra inductance is not included.`)}}(b&&!(e.traceW?.upper>0)||h&&!(e.traceW?.lower>0))&&T.push("Stripline launch without a trace width: where the trace leaves the pad, the field the pad and the trace share is counted twice (5 to 15 fF too much at the pad). With the trace width given it is taken off."),ke&&ve&&T.push("Each 3D case behind the launch limits has a launch on one end only. With one on both ends, as here, the two ends' differences from 3D can add."),e.diff&&(ke||ve)&&T.push("Pair: each via has its own launch. The mutual inductance of the two barrels between pad and plane is included. The coupling of the two traces across their pads is not (weak at a practical via pitch)."),e.diff&&w.length&&T.push("A pair with a stripline launch has no 3D case of its own yet: the checks behind it are the single-via stripline cases and the pair with a microstrip launch."),e.traceL||T.push("No trace inductance given: the path across the pad is left out.")}return T.push(e.launch?"Pads on unconnected inner layers (assumed removed), conductor loss and copper roughness of the via are not modelled.":"Trace-to-via launch, pads on unconnected inner layers (assumed removed), conductor loss and copper roughness are not modelled."),E&&Jr.some((D,_)=>!D&&rt[_].hx>0)&&T.push(w.some(D=>!D.thru)?`A barrel that ends on its stripline is checked against 3D up to ${fn.stripline/1e9} GHz, one with a backdrill stub left in the pair up to ${fn.backdrill/1e9} GHz (see Validation). Above that the model and the 3D results part at the barrel's end: more of the end's and the pad's charge lands on the plane beyond than the model's depth rule gives.`:"Barrels that end inside a plane pair (backdrill, blind vias) are only checked against 3D with the stripline launch on. Treat this result as beta."),{ok:!0,fValid:kt,launchError:nr,points:rr,sparams:Yr,info:{planes:Ee.map(({name:D,depth:_,C:q})=>({name:D,depth:_,C:q})),cavities:rt.map(({h:D,hx:_,er:q})=>({h:D,hx:_,er:q})),positions:m},totalC:Ee.reduce((D,_)=>D+_.C,0)+Te+Ie+_r+zr+ye+be,ends:sr,loopL:Qr,method:`Physics-based via model (${E?"radial-mode":"lumped"} cavity method)${e.diff?", differential, mixed-mode Sdd":""}`,source:"R. Rimolo-Donadio et al., IEEE Trans. MTT 57(8), 2009, pp. 2072\u20132083, and Y.-J. Zhang, J. Fan, IEEE Trans. MTT 58(8), 2010, pp. 2251\u20132265. Static barrel-to-plane capacitance from Impedora\u2019s axisymmetric field solver.",notes:T}}var ba=2.5,xa=6;function $a(e,t,n){let o=e.flatMap(a=>a.polys).filter(a=>{let{x0:l,x1:p,y0:s,y1:r}=Un(a);return t.x>l-3&&t.x<p+3&&t.y>s-3&&t.y<r+3});if(!o.length)return null;let u=16,d=a=>{let l=0;for(let p=0;p<u;p++){let s=2*Math.PI*p/u,r={x:t.x+a*Math.cos(s),y:t.y+a*Math.sin(s)};o.some(f=>_e(r,f))&&l++}return l>=u*.6},i=Math.max(n/2,.05);for(let a=i+.1;a<=2.05;a+=.1){if(!d(a))continue;let l=Math.max(i,a-.1);for(let p=l+.02;p<=a+1e-9;p+=.02)if(d(p))return 2*(p-.01);return 2*(a-.01)}return null}var Xt=new Map;function Pr(e,t,n,o,u,d,i,a,l){let p=h=>t.findIndex(w=>w.kind==="copper"&&w.name===h),s=p(u[0]),r=p(u[u.length-1]);if(s<0||r<0||s===r||t[s].plane||t[r].plane)return null;let f=[];for(let[h,w]of Object.entries(n)){let v=$a(e.zones.filter(g=>g.layer===h&&g.net===w),o.at,o.size);v!==null&&f.push(v)}if(!f.length)return null;f.sort((h,w)=>h-w);let c=Math.round(f[Math.floor(f.length/2)]/.05)*.05,x=!!d&&Math.hypot(d.at.x-o.at.x,d.at.y-o.at.y)<2.5,S=h=>{let w=h?{x:(o.at.x+d.at.x)/2,y:(o.at.y+d.at.y)/2}:o.at,v=h?Math.hypot(d.at.x-o.at.x,d.at.y-o.at.y):0;if(h&&v<c)return"overlap";let g=h?Math.atan2(d.at.y-o.at.y,d.at.x-o.at.x):0,$=L=>{let H=L.x-w.x,U=L.y-w.y;return{x:H*Math.cos(-g)-U*Math.sin(-g),y:H*Math.sin(-g)+U*Math.cos(-g)}},y=new Set(Object.values(n)),T=e.vias.filter(L=>y.has(L.net)&&L.kind==="through").map(L=>({g:L,d:Math.hypot(L.at.x-w.x,L.at.y-w.y)})).filter(({d:L})=>L>(o.size+.1)/2+v/2&&L<=ba+v/2).sort((L,H)=>L.d-H.d).slice(0,xa).map(({g:L})=>$(L.at)),E=JSON.stringify([t.map(L=>[L.t,L.er,L.plane,L.tanD]),s,r,o.drill,o.size,c.toFixed(2),h,v.toFixed(2),T.map(L=>[L.x.toFixed(2),L.y.toFixed(2)]),i,a,Math.round(l/1e8)]);if(Xt.has(E))return Xt.get(E);let m=t.filter(L=>L.kind==="dielectric").map(L=>L.tanD??.02),C={layers:t.map(L=>({kind:L.kind,t:L.t,er:L.er,plane:!!L.plane})),from:s,to:r,drill:o.drill*.001,pad:o.size*.001,antipad:c*.001,backdrill:!1,tanD:m.reduce((L,H)=>L+H,0)/Math.max(m.length,1),diff:h,pitch:v*.001,ground:{n:0,dist:.001},groundExtra:T.map(L=>({x:L.x*.001,y:L.y*.001})),z0:d?i/2:a},k=Bo(C,Math.min(Math.max(2.5*l,1e10),5e10),50);if(!k.ok)return Xt.set(E,null),null;let I=L=>{let H=k.points,U=H.findIndex(O=>O.f>=L);U<=0&&(U=U<0?H.length-1:1);let P=H[U-1],F=H[U],V=(L-P.f)/(F.f-P.f||1);return{s11:P.s11+V*(F.s11-P.s11),s21:P.s21+V*(F.s21-P.s21)}},R=k.points.reduce((L,H)=>H.s21<L.s21?H:L,k.points[0]),N=I(l),A={loss:-N.s21,rl:-N.s11,notch:R.s21<-10?R.f:null,fValid:k.fValid,antipad:c,ground:T.length,diff:h,pitch:v,merged:x&&!h};return Xt.size>200&&Xt.clear(),Xt.set(E,A),A},M=S(!!x),b=M==="overlap"?S(!1):M;return b==="overlap"?null:b}function Rt(e){let t=e.replace(/^R_/i,"").replace(/_\d{4}.*$/,"").replace(/\s|Ω|ohms?/gi,""),n=t.match(/^(\d+)([RKM])(\d+)$/i);return n?+`${n[1]}.${n[3]}`*Uo(n[2]):(n=t.match(/^(\d+(?:\.\d+)?)([RKM]?)$/i),n?Number(n[1])*Uo(n[2]):null)}var Uo=e=>({k:1e3,m:1e6})[e.toLowerCase()]??1;function Yt(e){let t=e.replace(/^C_/i,"").replace(/[µμ]/g,"u").split(/[\s/_,]/)[0].replace(/F$/i,""),n=u=>({p:1e-12,n:1e-9,u:1e-6,m:.001})[u.toLowerCase()],o=t.match(/^(\d+)([pnum])(\d+)$/i);return o?+`${o[1]}.${o[3]}`*n(o[2]):(o=t.match(/^(\d+(?:\.\d+)?)([pnum])$/i),o?Number(o[1])*n(o[2]):null)}var Hn=/ESD|TVS|TPD\d|USBLC|PESD|RCLAMP|SP05|PRTR|NUP\d|ESDA|IP42|SRV0|SMF\d|CDSOT|ECMF/i,gn=e=>e>=1e3?`${+(e/1e3).toFixed(2)} k\u03A9`:`${e} \u03A9`;function Ma(e){return e.parts.filter(t=>/^(J|P|CN|CON|X|USB)\d/i.test(t.ref)&&/USB.?C|TYPE.?C|USB4[01]\d5|UJ3\d-C|632723|GCT_USB4/i.test(`${t.lib} ${t.value}`)&&!/PLUG/i.test(`${t.lib} ${t.value}`)&&t.pads.some(n=>n.num==="A5")&&t.pads.some(n=>n.num==="B5"))}function _o(e){let t=[],n=a=>a.pads.filter(l=>l.net).length===2,o=a=>/^(R|JP|NT|SB)\d+/.test(a.ref)&&n(a)&&Rt(a.value)===0,u=a=>{let l=new Set([a]);for(let p=!0;p;){p=!1;for(let s of e.parts.filter(o)){let r=s.pads.map(f=>f.net);r.some(f=>l.has(f))&&r.some(f=>f&&!l.has(f))&&(r.forEach(f=>f&&l.add(f)),p=!0)}}return l},d=new Set,i=Ma(e);for(let a of i){let l=v=>a.pads.filter(g=>g.num===v),p=v=>l(v).find(g=>g.net)?.net??"",s=v=>{if(!v||/^unconnected-/i.test(v))return{kind:"none"};let g=u(v),$=e.parts.filter(T=>/^R\d+/.test(T.ref)&&n(T)&&!o(T)&&T.pads.some(E=>g.has(E.net)));for(let T of $){let E=T.pads.find(C=>C.net&&!g.has(C.net))?.net??"",m=Rt(T.value);if(ue.test(B(E)))return{kind:"rd",r:T,v:m};if(Ge(B(E))||/VBUS|VCC|VDD/i.test(B(E)))return{kind:"rp",r:T,v:m,rail:B(E)}}let y=e.parts.find(T=>T!==a&&T.pads.length>=6&&!Hn.test(`${T.lib} ${T.value}`)&&T.pads.some(E=>g.has(E.net)));return y?{kind:"chip",chip:y}:$.length?{kind:"chip",chip:$[0]}:{kind:"none"}},r=p("A5"),f=p("B5"),c=s(r),x=s(f),S=l("A5")[0]?.at??a.at,M=[r,f].filter(Boolean);if(r&&r===f&&!/^unconnected-/i.test(r)){(c.kind==="rd"||c.kind==="rp")&&t.push({rule:"usbc",severity:"fail",title:`${a.ref}: CC1 and CC2 share one resistor`,detail:`Both CC pins of ${a.ref} are tied together on ${B(r)} with one resistor, ${c.r.ref}. Each CC pin needs its own: an e-marked USB-C cable adds its own load on the second CC line, and a charger then reads the pair as an audio adapter and gives no power (the Raspberry Pi 4's first revision had this fault). Give CC1 and CC2 a ${c.kind==="rd"?"5.1 k\u03A9 resistor to ground":"pull-up"} each.`,nets:M,at:S});continue}let b=[c.kind==="none"?"CC1":"",x.kind==="none"?"CC2":""].filter(Boolean);if(b.length===2)t.push({rule:"usbc",severity:"fail",title:`${a.ref}: no resistor or controller on CC1 or CC2`,detail:`Neither CC pin of ${a.ref} has a termination. A USB-C charger or a C-to-C cable from a laptop then sees nothing plugged in and gives no power or data: only a USB-A to C cable works. For a device, put a 5.1 k\u03A9 resistor from each CC pin to ground; for a host, a pull-up on each (or a Type-C controller).`,nets:M,at:S});else if(b.length===1){let v=b[0]==="CC1"?x:c;t.push({rule:"usbc",severity:"fail",title:`${a.ref}: ${b[0]} has no termination`,detail:`${b[0]==="CC1"?"CC2":"CC1"} of ${a.ref} has ${v.kind==="rd"?`a resistor to ground (${v.r.ref})`:v.kind==="rp"?`a pull-up (${v.r.ref})`:"a controller"}, but ${b[0]} has nothing. The plug only connects one CC line, the one on its side: turned the other way round, a USB-C charger or C-to-C cable sees nothing and gives no power. Give ${b[0]} the same ${v.kind==="rd"?"5.1 k\u03A9 to ground":"termination"}.`,nets:M,at:S})}for(let[v,g]of[["CC1",c],["CC2",x]])g.kind==="rd"&&g.v!=null&&(g.v<4600||g.v>5600)&&t.push({rule:"usbc",severity:"warn",title:`${a.ref} ${v}: ${g.r.ref} is ${gn(g.v)} to ground, not 5.1 k\u03A9`,detail:`A USB-C device marks itself with 5.1 k\u03A9 from each CC pin to ground (Rd, \xB110%). The host measures the voltage this sets to see what is attached and which way round: with ${gn(g.v)} it may read no device, or the wrong current.`,nets:[g.r.pads.find($=>$.net).net],at:g.r.at}),g.kind==="rp"&&g.v!=null&&([56e3,22e3,1e4,36e3,12e3,4700].some(y=>Math.abs(g.v-y)/y<=.06)||t.push({rule:"usbc",severity:"warn",title:`${a.ref} ${v}: ${g.r.ref} is ${gn(g.v)} to ${g.rail}`,detail:`A USB-C host or charger advertises its current with a pull-up on each CC pin (Rp): 56 k\u03A9, 22 k\u03A9 or 10 k\u03A9 to 5 V, or 36 k\u03A9, 12 k\u03A9 or 4.7 k\u03A9 to 3.3 V, for default USB, 1.5 A and 3 A. ${gn(g.v)} is none of those, so a device reads the wrong current or none.`,nets:[g.r.pads.find(y=>y.net).net],at:g.r.at}));let h=["A6","B6","A7","B7"].map(v=>{let g=p(v);return g&&!/^unconnected-/i.test(g)?g:""});if(h.some(Boolean))for(let[v,g,$]of[[0,1,"D+"],[2,3,"D-"]]){let y=h[v],T=h[g],E=["A6","B6","A7","B7"][v],m=["A6","B6","A7","B7"][g];!y||!T?t.push({rule:"usbc",severity:"fail",title:`${a.ref}: ${$} only on ${y?E:m}`,detail:`${a.ref} has ${$} on ${y?E:m} but nothing on ${y?m:E}. A USB-C plug carries data on one of the two only, depending on which way round it goes in: turned over, USB data does not work. Join ${E} and ${m} (a short trace or a via between the two pads).`,nets:[y||T],at:l(y?m:E)[0]?.at??a.at}):y!==T&&t.push({rule:"usbc",severity:"info",title:`${a.ref}: ${E} and ${m} on different nets`,detail:`${E} is on ${B(y)} and ${m} on ${B(T)}. Fine if a USB switch or hub picks between them; otherwise join them, or data works one way round only.`,nets:[y,T],at:l(m)[0]?.at??a.at})}let w=["A4","A9","B4","B9"].map(p).find(v=>v&&!/^unconnected-/i.test(v));if(w&&(c.kind==="rd"||x.kind==="rd")&&!d.has(w)){d.add(w);let v=i.filter(y=>y.pads.some(T=>T.net===w)).map(y=>y.ref),g=e.parts.filter(y=>/^C\d+/.test(y.ref)&&y.pads.some(T=>T.net===w)&&y.pads.some(T=>ue.test(B(T.net)))),$=g.reduce((y,T)=>y+(Yt(T.value)??0),0);$>105e-7&&t.push({rule:"usbc",severity:"warn",title:`${v.join(", ")}: ${+($*1e6).toFixed(1)} \xB5F straight on VBUS`,detail:`${g.map(y=>`${y.ref} (${y.value})`).join(", ")} sit on ${B(w)} with no switch or limiter in between. USB 2.0 lets a device put at most 10 \xB5F on VBUS: more draws an inrush spike at plug-in that can trip the host's port protection or reset it. Keep 10 \xB5F or less there, and put the bulk capacitance behind a load switch or an inrush limiter.`,nets:[w],at:g[0].at})}}return t}function wa(e,t,n,o,u,d){let i=0,a=1,l=t.x-e.x,p=t.y-e.y;for(let[s,r]of[[-l,e.x-n],[l,u-e.x],[-p,e.y-o],[p,d-e.y]]){if(s===0){if(r<0)return!1;continue}let f=r/s;if(s<0){if(f>a)return!1;f>i&&(i=f)}else{if(f<i)return!1;f<a&&(a=f)}}return!0}function zo(e){let t=[];for(let n of e.parts.filter(o=>/^(Y|X|XTAL|XT)\d+/i.test(o.ref)&&!/OSC|TCXO|VCXO|MEMS|SIT\d|DSC\d|ASDM|ASEM/i.test(`${o.lib} ${o.value}`))){let o=[...new Set(n.pads.map(g=>g.net).filter(g=>g&&!ue.test(B(g))&&!/^unconnected/i.test(g)))];if(o.length!==2||o.some(g=>Ge(B(g))))continue;let u=g=>[g,...e.parts.filter($=>/^R\d+/.test($.ref)&&$.pads.filter(y=>y.net).length===2&&$.pads.some(y=>y.net===g)).flatMap($=>$.pads.map(y=>y.net)).filter($=>$&&$!==g&&!ue.test(B($)))],d=[...new Set(o.flatMap(u))],i=e.parts.filter(g=>g!==n&&g.pads.length>=6&&g.pads.some($=>d.includes($.net))),a=i.find(g=>o.every($=>u($).some(y=>g.pads.some(T=>T.net===y))))??i[0],l=n.pads.filter(g=>o.includes(g.net)),p=`${n.ref} (${n.value})`;if(a){let g=a.pads.filter(y=>d.includes(y.net)),$=Math.min(...g.flatMap(y=>l.map(T=>de(y.at,T.at))));$>10&&t.push({rule:"clocks",severity:$>25?"fail":"warn",title:`${p}: ${$.toFixed(1)} mm from ${a.ref}`,detail:`The crystal's nearest pin is ${$.toFixed(1)} mm from ${a.ref} (${a.value}). The oscillator works at high impedance with a few picofarads of load: every millimetre of trace adds stray capacitance and picks up noise, so it can run off frequency, start late or not start. Put the crystal next to the chip's oscillator pins, within about 5 mm, with nothing else routed between them.`,nets:o,at:l[0].at})}let s=e.parts.filter(g=>/^C\d+/.test(g.ref)&&g.pads.some($=>o.includes($.net))&&g.pads.some($=>ue.test(B($.net)))&&(Yt(g.value)??1)<1e-9);for(let g of s){let $=g.pads.find(T=>o.includes(T.net)),y=Math.min(...l.filter(T=>T.net===$.net).map(T=>de(T.at,$.at)));y>7&&t.push({rule:"clocks",severity:"warn",title:`${p}: load capacitor ${g.ref} ${y.toFixed(1)} mm away`,detail:`${g.ref} (${g.value}) is a load capacitor of the crystal, but sits ${y.toFixed(1)} mm from its pin. The capacitors belong right at the crystal, their ground ends close together and straight into the ground plane, so the loop stays small and the trace between them adds as little stray capacitance as possible.`,nets:[$.net],at:$.at})}let r=l.map(g=>g.at.x),f=l.map(g=>g.at.y),c=.4,[x,S,M,b]=[Math.min(...r)-c,Math.min(...f)-c,Math.max(...r)+c,Math.max(...f)+c],h=n.side==="F",w=h?e.copper.slice(0,2):e.copper.slice(-2),v=[...new Set(e.tracks.filter(g=>w.includes(g.layer)&&g.net&&!o.includes(g.net)&&!ue.test(B(g.net))&&!Ge(B(g.net))&&!d.includes(g.net)&&wa(g.a,g.b,x,S,M,b)).map(g=>`${B(g.net)} on ${g.layer}`))];v.length&&t.push({rule:"clocks",severity:"warn",title:`${p}: ${v.length===1?"a signal runs":`${v.length} signals run`} under it`,detail:`${v.slice(0,4).join(", ")}${v.length>4?` and ${v.length-4} more`:""} pass${v.length===1?"es":""} under the crystal. Its pins sit at high impedance: a signal right below couples straight into the oscillator and shows up as jitter or a wrong frequency. Keep the area under the crystal clear, with solid ground on the layer below.`,nets:o,at:l[0].at})}return t}function ka(e,t){let n=e.edges??[];if(!n.length)return t.x>=e.outline.x0&&t.x<=e.outline.x1&&t.y>=e.outline.y0&&t.y<=e.outline.y1;let o=0;for(let[u,d]of n)u.y>t.y!=d.y>t.y&&t.x<u.x+(t.y-u.y)*(d.x-u.x)/(d.y-u.y)&&o++;return o%2===1}var Ca=/WROOM|WROVER|MINI-1|MINI-2|ESP-?12|ESP-?07|MDBT4|BMD-3|E73-|SOLO-1/i,Sa=/WROOM-32U|-1U\b|-1U[-_]|-IE\b|-IE[-_]|MINI-1U|NODEMCU|DEVKIT|-U[-_]N/i;function Vo(e){let t=[],n=e.zones.filter(o=>e.copper.includes(o.layer));for(let o of e.parts.filter(u=>Ca.test(`${u.lib} ${u.value}`)&&!Sa.test(`${u.lib} ${u.value}`)&&u.pads.length>=10)){let u=o.pads.map(S=>S.at.x),d=o.pads.map(S=>S.at.y),i={x0:Math.min(...u),y0:Math.min(...d),x1:Math.max(...u),y1:Math.max(...d)},a=null,l=7;if(o.body){let S={L:i.x0-o.body.x0,R:o.body.x1-i.x1,T:i.y0-o.body.y0,B:o.body.y1-i.y1},M={L:"R",R:"L",T:"B",B:"T"},b=Object.keys(S).sort((h,w)=>S[w]-S[h])[0];S[b]>=4&&S[b]>S[M[b]]+3&&(a=b,l=S[b])}if(!a&&/WROOM|WROVER/i.test(`${o.lib} ${o.value}`)){let S=M=>o.pads.filter(b=>(M==="L"?b.at.x-i.x0:M==="R"?i.x1-b.at.x:M==="T"?b.at.y-i.y0:i.y1-b.at.y)<1).length;a=["L","R","T","B"].sort((M,b)=>S(M)-S(b))[0]}if(!a)continue;let p=(S,M)=>{let h=[],[w,v]=a==="L"||a==="R"?[i.y0-.5,i.y1+.5]:[i.x0-.5,i.x1+.5];for(let g=S+.5/2;g<M;g+=.5)for(let $=w+.5/2;$<v;$+=.5)h.push(a==="L"?{x:i.x0-g,y:$}:a==="R"?{x:i.x1+g,y:$}:a==="T"?{x:$,y:i.y0-g}:{x:$,y:i.y1+g});return h},s=S=>{let M=new Map,b=0;for(let h of S.filter(w=>ka(e,w))){let w=n.filter($=>$.polys.some(y=>_e(h,y))),v=w.length?[]:e.tracks.filter($=>e.copper.includes($.layer)&&Ho(h,$.a,$.b)<$.w/2+.25),g=[...w.map($=>`${B($.net)||"unconnected"} on ${$.layer}`),...v.map($=>`${B($.net)} on ${$.layer}`)];if(g.length){b++;for(let $ of g)M.set($,(M.get($)??0)+1)}}return{frac:S.length?b/S.length:0,what:[...M.entries()].sort((h,w)=>w[1]-h[1]).map(([h])=>h)}},r=`${o.ref} (${o.value})`,f=p(2,Math.min(l,8)),c=s(f),x=a==="L"?{x:i.x0-3,y:(i.y0+i.y1)/2}:a==="R"?{x:i.x1+3,y:(i.y0+i.y1)/2}:a==="T"?{x:(i.x0+i.x1)/2,y:i.y0-3}:{x:(i.x0+i.x1)/2,y:i.y1+3};if(c.frac>.1)t.push({rule:"antenna",severity:c.frac>.3?"fail":"warn",title:`${r}: copper under the antenna`,detail:`About ${Math.round(c.frac*100)}% of the area under ${o.ref}'s printed antenna has copper on some layer (${c.what.slice(0,3).join(", ")}${c.what.length>3?", \u2026":""}). Copper there, a ground pour above all, detunes the antenna and can cut the range by half or more. Clear every layer under the antenna (a keep-out zone in KiCad), and put the antenna at the board edge or over it.`,nets:[],at:x});else if(l>9){let S=s(p(8,l));S.frac>.25&&t.push({rule:"antenna",severity:"warn",title:`${r}: copper in the antenna's clear area`,detail:`Past the antenna, ${o.ref}'s footprint marks a clear area that is about ${Math.round(S.frac*100)}% covered with copper (${S.what.slice(0,3).join(", ")}). The module maker asks for that area to stay clear: copper close to the antenna still pulls its tuning and range.`,nets:[],at:x})}}return t}function Ho(e,t,n){let o=n.x-t.x,u=n.y-t.y,d=o*o+u*u,i=d?Math.max(0,Math.min(1,((e.x-t.x)*o+(e.y-t.y)*u)/d)):0;return Math.hypot(e.x-(t.x+i*o),e.y-(t.y+i*u))}var Pa=/AMS1117|LM1117|AP211[2-4]|XC62(06|10|20)|MIC52(05|19)|MIC5504|RT90(13|80)|LP5907|LP2985|LP38\d{2}|TLV7(0\d{3}|1\d{2,3}|3[3-9]|4\d|5\d)|TPS7A|MCP170[0-3]|MCP1711|HT7[35]\d\d|ME62(06|11)|SPX3819|L?D1117|LDL1117|NCP1117|L78|LM78|LM317|AP73(33|61)|BL8555|SGM20(19|36)|RT9193|AZ1117|LP2992|LDO/i;function Go(e){let t=[],n=p=>p.pads.filter(s=>s.net).length===2,o=e.parts.filter(p=>/^C\d+/.test(p.ref)&&n(p)&&p.pads.some(s=>ue.test(B(s.net)))),u=(p,s=0)=>o.filter(r=>r.pads.some(f=>f.net===p)&&(Yt(r.value)??1e-6)>=s),d=(p,s,r=0)=>{let f=1/0,c="";for(let x of u(p,r))for(let S of x.pads.filter(M=>M.net===p))for(let M of s)de(M.at,S.at)<f&&(f=de(M.at,S.at),c=x.ref);return{d:f,ref:c}},i=e.parts.filter(p=>/^L\d+/.test(p.ref)&&n(p)),a=new Set(i.flatMap(p=>p.pads.filter(s=>s.net&&Ge(B(s.net))).map(s=>s.net))),l=new Set;for(let p of e.parts.filter(s=>/^(U|IC|PS|VR|Q)\d+/.test(s.ref)&&s.pads.length>=5&&s.pads.length<=60))for(let s of i){let[r,f]=s.pads.filter(c=>c.net);for(let[c,x]of[[r,f],[f,r]]){if(Ge(B(c.net))||ue.test(B(c.net))||!Ge(B(x.net))||/BEAD|BLM|FERRITE|^FB|\d+R@|OHM@|Ω@/i.test(`${s.value} ${s.lib}`)||u(c.net,1e-9).length)continue;let S=p.pads.filter(m=>m.net===c.net);if(!S.length||l.has(`${p.ref}|${s.ref}`))continue;l.add(`${p.ref}|${s.ref}`);let M=`${p.ref} (${p.value})`,b=m=>Ge(B(m))||/VIN|VBUS|VBAT|VSYS|PVIN|VCC|VDD|\d+V\d*|^\+/i.test(B(m)),h=m=>u(m,1e-6).reduce((C,k)=>C+(Yt(k.value)??1e-6),0),w=[...new Set(p.pads.map(m=>m.net))].filter(m=>m&&m!==c.net&&m!==x.net&&!a.has(m)&&!ue.test(B(m))&&b(m)&&!/OUT|EN$|ENABLE|PG$|PGOOD/i.test(B(m))&&u(m,1e-6).length).sort((m,C)=>h(C)-h(m)).slice(0,1);for(let m of w){let C=d(m,p.pads.filter(k=>k.net===m),1e-7);C.d>5&&t.push({rule:"power",severity:C.d>10?"fail":"warn",title:`${M}: input capacitor ${C.ref} ${C.d.toFixed(1)} mm from its ${B(m)} pin`,detail:`A buck converter's input capacitor carries the switched current: every cycle the current jumps between the capacitor and the chip, through the input pin and back through ground. ${C.d.toFixed(1)} mm of trace in that loop adds inductance that rings at each edge and radiates. Put a ceramic capacitor (100 nF to 10 \xB5F) right at the ${B(m)} pin, its ground pad straight to the chip's ground with vias (TI SLVA638).`,nets:[m],at:p.pads.find(k=>k.net===m).at})}let v=Math.min(...S.map(m=>Math.min(de(m.at,r.at),de(m.at,f.at))));v>6&&t.push({rule:"power",severity:v>10?"warn":"info",title:`${M}: inductor ${s.ref} ${v.toFixed(1)} mm from the switch pin`,detail:`The switch node (${B(c.net)}) swings the full input voltage at every edge: the longer the copper between the switch pin and the inductor, the more it radiates and couples into nearby traces. Put ${s.ref} right next to the switch pin and keep the switch node short and small.`,nets:[c.net],at:S[0].at});let g=e.parts.filter(m=>/^R\d+/.test(m.ref)&&n(m)),$=[...new Set(p.pads.map(m=>m.net))].filter(m=>m&&(/(^|_)V?FB\d?$/i.test(B(m))||g.some(C=>C.pads.some(k=>k.net===m)&&C.pads.some(k=>k.net===x.net))&&g.some(C=>C.pads.some(k=>k.net===m)&&C.pads.some(k=>ue.test(B(k.net)))))),y=[...e.tracks.filter(m=>m.net===c.net).map(m=>({a:m.a,b:m.b,w:m.w,layer:m.layer})),...e.parts.flatMap(m=>m.pads.filter(C=>C.net===c.net).map(C=>({a:C.at,b:C.at,w:Math.max(C.w,C.h),layer:C.layers.find(k=>e.copper.includes(k))??(m.side==="F"?e.copper[0]:e.copper[e.copper.length-1])})))],T=p.pads.map(m=>m.at),E=m=>T.every(C=>de(C,m)>1.5);for(let m of $){let C=1/0;for(let k of e.tracks.filter(I=>I.net===m)){let I=de(k.a,k.b),R=Math.max(1,Math.ceil(I/.25));for(let N=0;N<=R;N++){let A={x:k.a.x+(k.b.x-k.a.x)*N/R,y:k.a.y+(k.b.y-k.a.y)*N/R};if(E(A))for(let L of y)(L.layer===k.layer||L.layer==="*.Cu")&&(C=Math.min(C,Ho(A,L.a,L.b)-L.w/2-k.w/2))}}C<.5&&t.push({rule:"power",severity:"warn",title:`${M}: feedback trace ${C<.2?"right beside":`${Math.max(C,0).toFixed(1)} mm from`} the switch node`,detail:`${B(m)} sets the output voltage from a high-impedance divider: running next to the switch node (${B(c.net)}), it picks up the switching edges, and the output jitters or the converter misregulates. Route the feedback trace away from the switch node and the inductor, from the output capacitor's side, on a layer shielded by ground.`,nets:[m,c.net],at:p.pads.find(k=>k.net===m)?.at})}}}for(let p of e.parts.filter(s=>/^(U|IC|VR)\d+/.test(s.ref)&&Pa.test(s.value)&&s.pads.length>=3&&s.pads.length<=12)){let s=[...new Set(p.pads.map(r=>r.net))].filter(r=>r&&!ue.test(B(r))&&!/EN$|ENABLE|_EN\d?$|PG$|PGOOD|NR$|BYP/i.test(B(r))&&(Ge(B(r))||/VBUS|VIN|VOUT|VBAT|VSYS|^\+/i.test(B(r))));for(let r of s){let f=d(r,p.pads.filter(c=>c.net===r),47e-8);f.d>10&&t.push({rule:"power",severity:"warn",title:`${p.ref} (${p.value}): ${isFinite(f.d)?`nearest capacitor on ${B(r)} ${f.d.toFixed(1)} mm away`:`no capacitor on ${B(r)}`}`,detail:`An LDO needs a capacitor at its input and one at its output, close to the pins: most are only stable with a minimum output capacitance (often 1 \xB5F or more, some 10 \xB5F; the AMS1117 asks for 22 \xB5F on its output), and the input capacitor holds the supply up through load steps. ${isFinite(f.d)?`${f.ref} is ${f.d.toFixed(1)} mm from the ${B(r)} pin`:`${B(r)} has no capacitor of 0.47 \xB5F or more to ground`}: check the datasheet's minimum and put it right at the pin.`,nets:[r],at:p.pads.find(c=>c.net===r).at})}}return t}var It=e=>{let t=(e.fn??"").toUpperCase();return/^VCAP_\d$/.test(t)?t:t.replace(/_\d+$/,"")};function Ko(e){let t=[],n=s=>s.pads.filter(r=>r.net).length===2,o=s=>!s||/^unconnected-/i.test(s),u=e.parts.filter(s=>/^R\d+/.test(s.ref)&&n(s)),d=e.parts.filter(s=>/^C\d+/.test(s.ref)&&n(s)),i=(s,r)=>s.pads.find(f=>f.net&&f.net!==r)?.net??"",a=(s,r)=>r.filter(f=>f.pads.some(c=>c.net===s)&&ue.test(B(i(f,s)))),l=(s,r)=>r.filter(f=>f.pads.some(c=>c.net===s)&&Ge(B(i(f,s)))),p=/RPI_PICO|(^|[^A-Z])PICO([^A-Z]|$)|PRO_?MICRO|ELITE-?C|NICE.?NANO|NODEMCU|DEVKIT|ZERO|XIAO|TTGO|LILYGO|WEMOS|D1.?MINI|ARDUINO|TEENSY|FEATHER|QT.?PY|KB2040|BLACK.?PILL|BLUE.?PILL|BREAKOUT|MODULE|WROOM|WROVER|MINI-1|COMPUTE|CM[345]|SOM/i;for(let s of e.parts.filter(r=>/^(U|IC)\d+/.test(r.ref)&&!p.test(`${r.lib} ${r.value}`))){let r=s.pads.filter(x=>x.type==="power_in"&&o(x.net)&&!/^NC$|^DNC$|^N\.?C\.?$/i.test(It(x)));if(!r.length||r.length===s.pads.filter(x=>x.type==="power_in").length&&r.length>8)continue;let f=r.every(x=>/^(GND|VSS|EP|PAD|AGND|DGND|PGND)/.test(It(x))),c=[...new Set(r.map(x=>It(x)||x.num))];t.push({rule:"mcu",severity:f?"warn":"fail",title:`${s.ref} (${s.value}): ${r.length===1?`power pin ${c[0]} is`:`${r.length} power pins are`} not connected`,detail:`${c.slice(0,6).join(", ")}${c.length>6?" and more":""} on ${s.ref} ${r.length===1?"is a power pin":"are power pins"} with no net. Every supply and ground pin has to be connected: a chip fed through some of its pins only can run hot, misbehave or not start, and an analog supply pin (VDDA, AVDD) left open stops its ADC or PLL. ERC flags this too; check it was not waived.`,nets:[],at:r[0].at})}for(let s of e.parts.filter(r=>/^(U|IC)\d+/.test(r.ref)&&/STM32/i.test(r.value))){let r=`${s.ref} (${s.value})`;for(let f of s.pads.filter(c=>/(^|[-/])BOOT0($|[-/])/.test(It(c))))o(f.net)?t.push({rule:"mcu",severity:"fail",title:`${r}: BOOT0 is floating`,detail:"BOOT0 picks where the chip boots from at reset: left open, it floats, and the chip can start in its built-in bootloader instead of your program, at random. Tie it to ground through a 10 k\u03A9 resistor (with a button or jumper to 3.3 V if you want to reach the bootloader).",nets:[],at:f.at}):!ue.test(B(f.net))&&!a(f.net,u).length&&!e.parts.some(c=>/^(U|IC)\d+/.test(c.ref)&&c!==s&&c.pads.some(x=>x.net===f.net))&&t.push({rule:"mcu",severity:"warn",title:`${r}: BOOT0 has no pull-down`,detail:`BOOT0 (${B(f.net)}) has no resistor to ground. If nothing holds it low (a button or jumper alone does not, when open), it floats and the chip can start in its bootloader. Add 10 k\u03A9 to ground.`,nets:[f.net],at:f.at});for(let f of s.pads.filter(c=>/^VCAP/.test(It(c))))(o(f.net)||!a(f.net,d).length)&&t.push({rule:"mcu",severity:"fail",title:`${r}: ${It(f)} has no capacitor`,detail:`${It(f)} is the output of the chip's internal core regulator. Without its capacitor to ground (ST asks for 2.2 \xB5F ceramic, or 4.7 \xB5F on some parts: see the datasheet) the core supply is unstable and the chip does not run. Put the capacitor right at the pin.`,nets:o(f.net)?[]:[f.net],at:f.at});for(let f of s.pads.filter(c=>/^NRST/.test(It(c))))!o(f.net)&&!a(f.net,d).length&&t.push({rule:"mcu",severity:"info",title:`${r}: no capacitor on NRST`,detail:"ST recommends 100 nF from NRST to ground, so noise on the reset line cannot reset the chip. Optional, but cheap.",nets:[f.net],at:f.at});if(/STM32F10[23]/i.test(s.value))for(let f of s.pads.filter(c=>/(^|\/)PA12($|\/)/.test(It(c))&&/D\+|DP|USB/i.test(B(c.net)))){let c=new Set([f.net,...u.filter(M=>M.pads.some(b=>b.net===f.net)&&(Rt(M.value)??1e3)<=100).map(M=>i(M,f.net))]),x=u.filter(M=>M.pads.some(b=>c.has(b.net))&&(Rt(M.value)??0)>100&&!ue.test(B(M.pads.find(b=>!c.has(b.net))?.net??""))),S=x.map(M=>Rt(M.value)??0);x.length?S.every(M=>M<1200||M>1800)&&t.push({rule:"mcu",severity:"warn",title:`${r}: D+ pull-up is ${gn(S[0])}, not 1.5 k\u03A9`,detail:`USB asks for 1.5 k\u03A9 on D+ (the "Blue Pill" boards shipped with 10 k\u03A9, and some hosts then fail to see the device). ${x[0].ref} is ${x[0].value}: change it to 1.5 k\u03A9.`,nets:[f.net],at:x[0].at}):t.push({rule:"mcu",severity:"fail",title:`${r}: no pull-up on USB D+`,detail:"The STM32F103 has no pull-up on D+ inside: the host only sees a full-speed device when D+ is pulled to 3.3 V through 1.5 k\u03A9. Without it the board never enumerates. Add 1.5 k\u03A9 from D+ to 3.3 V (or to a GPIO, to control connection).",nets:[f.net],at:f.at})}}for(let s of e.parts.filter(r=>/ESP32|ESP8266|WROOM|WROVER|MINI-1/i.test(`${r.lib} ${r.value}`)&&!/NODEMCU|DEVKIT/i.test(`${r.lib} ${r.value}`)))for(let r of s.pads.filter(f=>/^(EN|CHIP_PU|CHIP_EN)$/.test(It(f)))){let f=`${s.ref} (${s.value})`;if(o(r.net)){t.push({rule:"mcu",severity:"fail",title:`${f}: EN is not connected`,detail:"EN (CHIP_PU) holds the chip in reset while low. Left open it floats and the chip may not start. Pull it to 3.3 V through 10 k\u03A9 with 1 \xB5F to ground (Espressif's reference design).",nets:[],at:r.at});continue}if(Ge(B(r.net)))continue;let c=a(r.net,d).some(S=>(Yt(S.value)??1e-6)>=1e-7),x=l(r.net,u).length>0;c||t.push({rule:"mcu",severity:"warn",title:`${f}: no RC delay on EN`,detail:`Espressif's reference design puts 1 \xB5F from EN to ground, with 10 k\u03A9 to 3.3 V: the chip then leaves reset only after the supply has settled. Without it, a slow-rising supply can leave it stuck or booting badly.${x?"":" There is no pull-up on EN either."}`,nets:[r.net],at:r.at})}return t}var Zt=e=>/^(J|P|CN|CON|TP|USB|EXT|UEXT|HDR|JTAG|SWD|PROG)\d/i.test(e.ref)||/Connector|TestPoint|Test_?Point|PinHeader|PinSocket|Conn_|Tag-?Connect|TC20[3-5]0|JTAG|SWD|Pogo|HN\dx\d|Header/i.test(e.lib),va=/CH34[0-3]|CH910\d|CP210\d|CP2104|FT23[01]X|FT232R|FT2232|FT4232|PL2303|MCP2200|MCP2221/i,Tr=/XIAO|-ZERO|ZERO\b|PICO|SEEED|DEVKIT|SUPERMINI|NODEMCU|PRO.?MICRO|NICE.?NANO|TTGO|-DIP\b|\bDIP\b|FEATHER|ITSYBITSY|QT.?PY|LOLIN|WEMOS/i,it=e=>`${e.value} ${e.lib.split(":").pop()}`,Ta=e=>(e.fn??"").toUpperCase().replace(/^NC\((.*)\)$/,"$1").split(/[/,\s]+/).map(t=>/^VCAP_\d$/.test(t)?t:t.replace(/_\d+$/,"")).filter(Boolean),jo=(e,t)=>Ta(e).some(n=>t.test(n)),Qt=e=>!!e&&!ue.test(B(e))&&(Ge(B(e))||/(^|_)(VCC|VDD|VIO|VDDIO|3V3|1V8|2V5|5V|VREF)(_|$)|I2C_VCC/i.test(B(e))),vr=e=>/^(R|RN|RA|RM|RP)\d/.test(e.ref),yn=e=>e.pads.filter(t=>t.net).length===2,Gn=e=>!!e&&!/^unconnected-/i.test(e);function Wo(e,t,n=1e3){let o=new Set([t]);for(let u=0;u<2;u++)for(let d of e.parts.filter(i=>/^R\d+/.test(i.ref)&&yn(i)&&(Rt(i.value)??1e9)<=n))if(d.pads.some(i=>o.has(i.net))&&d.pads.every(i=>!i.net||!Qt(i.net)&&!ue.test(B(i.net))))for(let i of d.pads)i.net&&o.add(i.net);return o}function Jo(e){let t=[],n=(a,l,p)=>{let s=a.pads.filter(r=>jo(r,l)&&Gn(r.net));return s.length?s.some(r=>{let f=Wo(e,r.net);return e.parts.some(c=>c!==a&&p(c)&&c.pads.some(x=>f.has(x.net)))}):!1},o=a=>/^(U|IC)\d/.test(a.ref)&&a.pads.length>=6&&!Hn.test(it(a)),u=a=>Zt(a)||o(a),d=a=>Zt(a)||o(a)||Hn.test(it(a)),i=(a,l,p)=>n(a,l,d)&&n(a,p,d);for(let a of e.parts.filter(l=>/^(U|IC)\d/.test(l.ref)&&l.pads.some(p=>p.fn)&&!Tr.test(it(l)))){let l=it(a),p=`${a.ref} (${a.value})`,s=null,r="";if(/STM32/i.test(l))s=n(a,/^PA13$|^SWDIO$/,u)&&n(a,/^PA14$|^SWCLK$/,u)||i(a,/^PA12$/,/^PA11$/)||n(a,/^PA9$/,u)&&n(a,/^PA10$/,u),r="Bring SWDIO (PA13), SWCLK (PA14), NRST and ground to a header or test pads for an ST-Link; or use the USB or UART bootloader (USB on PA11/PA12, or UART on PA9/PA10), with BOOT0 reachable.";else if(/RP2040|RP2350/i.test(l))s=i(a,/^USB_DP$/,/^USB_DM$/)||n(a,/^SWCLK$/,u)&&n(a,/^SWD(IO)?$/,u),r="Bring USB_DP and USB_DM to a USB connector (with QSPI_SS reachable for the BOOTSEL button), or SWCLK and SWD to a header or test pads.";else if(/ESP32|ESP8266|WROOM|WROVER/i.test(l)){let f=/S2|S3|C3|C5|C6|H2|P4/i.test(a.value),c=f&&i(a,/^(USB_D\+|IO20|GPIO20|IO19|GPIO19)$/,/^(USB_D-|IO19|GPIO19|IO18|GPIO18)$/),x=M=>Zt(M)||va.test(it(M)),S=n(a,/^(TXD0?|U0TXD)$/,x)&&n(a,/^(RXD0?|U0RXD)$/,x)&&n(a,/^(IO0|GPIO0|IO9|GPIO9|BOOT)$/,M=>x(M)||/^(SW|S|BTN|K|B)\d/i.test(M.ref)||/^(Q|T)\d/.test(M.ref)||/^D\d/.test(M.ref)||M.pads.some(b=>ue.test(B(b.net))));s=c||S,r=f?"Bring its native USB (D+ and D-) to a USB connector, or UART0 (TXD0, RXD0) to a header or a USB-UART chip with the boot pin (IO0, or IO9 on the C3) on a button or the chip's auto-reset.":"Bring UART0 (TXD0, RXD0) to a header or a USB-UART chip (CH340, CP2102), with IO0 on a BOOT button or the auto-reset transistors, and EN on a RESET button."}s===!1&&t.push({rule:"mcu",severity:"warn",title:`${p}: no way to program it found`,detail:`None of ${a.ref}'s programming paths reaches a connector, a test point or another chip on this board. A blank chip that cannot be flashed makes the whole board a brick. ${r}`,nets:[],at:a.at})}return t}function Ia(e,t){if(!Gn(t))return null;if(ue.test(B(t)))return"down";if(Qt(t))return"up";for(let n of e.parts.filter(o=>/^R\d+/.test(o.ref)&&yn(o)&&o.pads.some(u=>u.net===t)&&(Rt(o.value)??1e9)<=1e5)){let o=n.pads.find(u=>u.net&&u.net!==t)?.net??"";if(ue.test(B(o)))return"down";if(Qt(o))return"up"}return null}function Xo(e){let t=[];for(let n of e.parts.filter(o=>/ESP32|WROOM|WROVER/i.test(it(o))&&!Tr.test(it(o))&&o.pads.some(u=>u.fn))){let o=`${n.ref} (${n.value})`,u=n.value.toUpperCase(),d=/C3|C2|C6|C5|H2/.test(u)?"c3":/S2|S3/.test(u)?"s3":"esp32",i=(a,l,p,s,r)=>{let f=n.pads.find(c=>jo(c,a));f&&Ia(e,f.net)===l&&t.push({rule:"strapping",severity:p,title:`${o}: ${s}`,detail:`${r} (${B(f.net)} is ${ue.test(B(f.net))||Qt(f.net)?"tied":"pulled"} ${l==="up"?"up":"down"}.)`,nets:[f.net],at:f.at})};d==="esp32"?(i(/^(IO12|GPIO12|MTDI)$/,"up","fail","IO12 is pulled up","IO12 (MTDI) sets the flash voltage at reset: high selects 1.8 V, and modules with 3.3 V flash (the WROOM-32 and most WROVERs) then fail to boot. Leave IO12 low at reset, or burn the VDD_SDIO eFuse to fix the voltage."),i(/^(IO0|GPIO0)$/,"down","fail","IO0 is held low","IO0 low at reset starts the serial download mode instead of your program: held low, the chip never runs it. Pull IO0 up (10 k\u03A9) and put the BOOT button to ground."),i(/^(IO2|GPIO2)$/,"up","warn","IO2 is pulled up","IO2 must be low or floating to enter the download mode: pulled up, flashing over UART fails.")):d==="s3"?(i(/^(IO0|GPIO0)$/,"down","fail","IO0 is held low","IO0 low at reset starts the download mode instead of your program. Pull IO0 up and put the BOOT button to ground."),i(/^(IO46|GPIO46)$/,"up","warn","IO46 is pulled up","IO46 high at reset blocks the serial download mode (IO0 low with IO46 high is not a valid boot mode). Leave IO46 low or floating at reset."),i(/^(IO45|GPIO45)$/,"up","warn","IO45 is pulled up","IO45 sets the flash voltage at reset: high selects 1.8 V, which only modules with 1.8 V flash want. Leave it low for 3.3 V flash.")):(i(/^(IO9|GPIO9)$/,"down","fail","IO9 is held low","IO9 low at reset starts the download mode instead of your program. Pull IO9 up and put the BOOT button to ground."),i(/^(IO8|GPIO8)$/,"down","warn","IO8 is pulled down","IO8 must be high to enter the serial download mode: pulled down, flashing over UART fails. Pull it up, or leave it floating."))}return t}var Aa=/(^|[^A-Z])(SDA|SCL)(\d|[^A-Z]|$)/,Fa=/TXS0|TXB0|NTS0|NTB0|PCA930|PCA954|TCA954|PI4MSD|LSF0|TXU0|GTL200|TS3USB|TS5A|MAX1484|SOM|MODULE|BREAKOUT|PICO|XIAO|ZERO|WROOM|WROVER|QWIIC|STEMMA|TTGO|PRO.?MICRO|NICE|DEVKIT|CONN|SODIMM|M\.2/i;function Zo(e){let t=[],n=e.parts.filter(vr),o=new Set;for(let p of e.nets.filter(s=>Aa.test(B(s).toUpperCase())&&!/I3C/i.test(s))){if(o.has(p))continue;let s=Wo(e,p,47e3);s.forEach(S=>o.add(S));let r=e.parts.filter(S=>S.pads.some(M=>s.has(M.net))),f=r.filter(S=>/^(U|IC)\d/.test(S.ref)&&S.pads.length>=4);if(f.length<1||r.length<2||n.some(S=>S.pads.some(M=>s.has(M.net))&&S.pads.some(M=>Qt(M.net))))continue;let c=B(p).toUpperCase().replace(/S(DA|CL)\d*$/,"");if(c&&e.nets.some(S=>[`${c}DC`,`${c}CS`,`${c}RS`,`${c}MOSI`].includes(B(S).toUpperCase())))continue;let x=r.some(S=>Zt(S)||/^(SW|JP|S)\d/.test(S.ref)||Fa.test(it(S))||Tr.test(it(S)));t.push({rule:"basics",severity:x?"info":"warn",title:`${B(p)}: no I2C pull-up`,detail:`I2C lines are open drain: every part only pulls them low, and a resistor to the supply pulls them high. ${B(p)} has none on this board, so the bus cannot work${x?", unless a module, a level shifter or a board on the connector carries the pull-ups":""}. Microcontrollers' internal pull-ups (30 to 50 k\u03A9) are too weak for anything but a slow, short bus. Add 2.2 to 4.7 k\u03A9 to the bus supply on SDA and SCL.`,nets:[...s],at:f[0].pads.find(S=>s.has(S.net))?.at})}let u=p=>/^(U|IC)\d/.test(p.ref)&&/LED|TLC59|IS31|PCA96|AL\d{4}|LM3\d{3}|PT4115|BCR\d|NSI\d|CAT4|ULN|TPIC/i.test(it(p));for(let p of e.parts.filter(s=>/^(D|LED|DS)\d/i.test(s.ref)&&yn(s)&&/LED/i.test(it(s))&&!/WS28|SK68|APA10|SK98|NEOPIXEL/i.test(it(s)))){let s=p.pads.filter(x=>x.net).map(x=>x.net),r=x=>e.parts.filter(S=>S!==p&&S.pads.some(M=>M.net===x));if(s.some(x=>r(x).some(S=>vr(S)||/^(Q|T|FB|L)\d/.test(S.ref)||u(S)||/^(D|LED|DS)\d/.test(S.ref))))continue;let f=s.filter(x=>ue.test(B(x))||Qt(x)),c=s.find(x=>r(x).some(S=>/^(U|IC)\d/.test(S.ref)));f.length===2?t.push({rule:"basics",severity:"fail",title:`${p.ref}: LED straight across ${B(s[0])} and ${B(s[1])}`,detail:`${p.ref} (${p.value}) sits between two supplies with no resistor: nothing limits its current, and it burns out (or drags the supply down) at power-up. Put a resistor in series: (supply \u2212 LED voltage) / current, about 1 k\u03A9 for a few milliamps from 3.3 V.`,nets:s,at:p.at}):c&&t.push({rule:"basics",severity:"warn",title:`${p.ref}: LED with no series resistor`,detail:`${p.ref} (${p.value}) is driven from ${r(c).find(x=>/^(U|IC)\d/.test(x.ref)).ref} with no resistor in series: only the pin's own drive limits the current, which overloads the pin and can damage it. Add a resistor in series (about 1 k\u03A9 from 3.3 V).`,nets:s,at:p.at})}let d=p=>yn(p)&&(/^(F|FB|L|D|PTC)\d/.test(p.ref)||/^R\d/.test(p.ref)&&(Rt(p.value.split(/[±\s,]/)[0])??9)<=1)||/^R\d/.test(p.ref)&&/Sense|Shunt/i.test(p.lib)||/^(Q|T)\d/.test(p.ref)||/^(U|IC)\d/.test(p.ref)&&/CH21\d|TPS20|TPS25|AP2\d{3}|SY6280|MIC20|STMPS|LTC44|LM66|IDEAL|LOAD.?SW|TPS22|SiP3|RT97|AOZ13|MAX1456|NIS5|STUSB|FUSB30|CYPD|HUSB|IP27|CH22/i.test(it(p)),i=p=>{for(let s of e.parts.filter(r=>d(r)&&r.pads.some(f=>p.has(f.net))))s.pads.forEach(r=>Gn(r.net)&&!ue.test(B(r.net))&&p.add(r.net));return p},a=p=>e.parts.filter(s=>/^C\d+/.test(s.ref)&&yn(s)&&s.pads.some(r=>p.has(r.net))&&s.pads.some(r=>ue.test(B(r.net)))).reduce((s,r)=>s+(Yt(r.value)??1),0),l=e.parts.filter(p=>/USB/i.test(it(p))&&Zt(p));for(let p of e.parts.filter(s=>/^(J|P|CN|CON|X|USB)\d/i.test(s.ref))){let s=it(p),r="";if(/BARREL|DC_?JACK|JACK_DC|PJ-0\d\d|DCJ|DC-0\d\d|DC-IN/i.test(s)?r=p.pads.map(b=>b.net).find(b=>Gn(b)&&!ue.test(B(b)))??"":/USB/i.test(s)&&!/USB3?_A.*Receptacle|Receptacle.*USB3?_A|USB_A_Female/i.test(s)&&(r=p.pads.map(b=>b.net).find(b=>b&&/VBUS|USB_?5V|5V_?USB/i.test(B(b)))??""),!r||l.filter(b=>b.pads.some(h=>h.net===r)).length>1)continue;let f=i(i(i(new Set([r])))),c=a(f);if(c>=9e-7)continue;let x=e.parts.filter(b=>b!==p&&b.pads.some(h=>f.has(h.net))&&!/^(TP|C)\d/.test(b.ref)&&!Hn.test(it(b))&&!(/^D\d/.test(b.ref)&&b.pads.some(h=>ue.test(B(h.net))))&&!(vr(b)&&(Rt(b.value.split(/[±\s,]/)[0])??0)>1));if(!x.length)continue;let S=x.every(b=>Zt(b))||x.some(b=>/^(Q|T)\d/.test(b.ref)),M=/USB/i.test(s);t.push({rule:"basics",severity:c>0||S?"info":"warn",title:`${p.ref}: ${c>0?"under 1 \xB5F":"no capacitor"} on the input ${B(r)}`,detail:`The power coming in on ${p.ref} (${B(r)}) has ${c>0?"less than 1 \xB5F":"no capacitor"} near the input. The cable's inductance then rings at plug-in, and the supply sags at every load step${M?": USB asks a device for at least 1 \xB5F on VBUS (and at most 10 \xB5F)":""}. Put ${M?"4.7 to 10 \xB5F":"10 to 100 \xB5F"} on the input, close to the connector.`,nets:[r],at:p.at})}return t}var yt=e=>e.kind==="usb2"&&e.rate<1e8&&!e.netclass,Fr=" This USB runs at full speed (12 Mb/s, all its chip supports), where edges take 4 ns or more: impedance and matching start to matter only on runs of tens of centimetres.",Yo=/^(GND|AGND|DGND|PGND|SGND|CGND|GNDA|GNDD|GNDREF|GNDPWR|GND_?ISO|VSS|VSSA|VSSQ|GROUND|EARTH|0V)$/i;function nt(e){let t=e.outline,n=Math.max((t.x1-t.x0)*(t.y1-t.y0),1e-9),o={},u=e.copper.length<=2?e.copper:e.copper.slice(1,-1),d=new Map;for(let l of e.tracks)d.set(l.layer,(d.get(l.layer)??0)+Math.hypot(l.b.x-l.a.x,l.b.y-l.a.y));let i=Math.max(1e-9,...d.values());for(let l of u){let p=new Map;for(let r of e.zones)r.layer===l&&p.set(r.net,(p.get(r.net)??0)+r.polys.reduce((f,c)=>f+Bn(c),0));let s=[...p.entries()].sort((r,f)=>f[1]-r[1]||(Yo.test(B(f[0]))?1:0)-(Yo.test(B(r[0]))?1:0))[0];s&&s[1]/n>=.35&&(d.get(l)??0)<.3*i&&(o[l]=s[0])}return{layers:e.stackup.map((l,p)=>({id:p,kind:l.kind,name:l.name,t:l.t,er:l.er,plane:l.kind==="copper"?!!o[l.name]:!1,...l.tanD!==void 0?{tanD:l.tanD}:{}})),planeNet:o}}var bt=e=>Math.hypot(e.b.x-e.a.x,e.b.y-e.a.y);function qt(e){if(!e.mid)return[e];let{a:t,mid:n,b:o}=e,u=2*(t.x*(n.y-o.y)+n.x*(o.y-t.y)+o.x*(t.y-n.y));if(Math.abs(u)<1e-12)return[{...e,mid:void 0}];let d=((t.x**2+t.y**2)*(n.y-o.y)+(n.x**2+n.y**2)*(o.y-t.y)+(o.x**2+o.y**2)*(t.y-n.y))/u,i=((t.x**2+t.y**2)*(o.x-n.x)+(n.x**2+n.y**2)*(t.x-o.x)+(o.x**2+o.y**2)*(n.x-t.x))/u,a=Math.hypot(t.x-d,t.y-i),l=Math.atan2(t.y-i,t.x-d),p=S=>(S%(2*Math.PI)+2*Math.PI)%(2*Math.PI),s=p(Math.atan2(o.y-i,o.x-d)-l),f=p(Math.atan2(n.y-i,n.x-d)-l)<=s?s:s-2*Math.PI,c=Math.max(2,Math.min(256,Math.ceil(Math.abs(f)*a/.1))),x=S=>({x:d+a*Math.cos(l+f*S/c),y:i+a*Math.sin(l+f*S/c)});return Array.from({length:c},(S,M)=>({net:e.net,layer:e.layer,w:e.w,a:x(M),b:x(M+1)}))}var Qo=new WeakMap;function Dr(e,t){let n=Qo.get(e);n||Qo.set(e,n=new Map);let o=`${t.p}|${t.n}`;return n.get(o)??n.set(o,Da(e,t)).get(o)}function Da(e,t){let n=Cn(e),o=M=>n.some(b=>M.x>b.x0&&M.x<b.x1&&M.y>b.y0&&M.y<b.y1),u=new Map,d=0,i=0,a=e.tracks.filter(M=>M.net===t.p).flatMap(qt),l=e.tracks.filter(M=>M.net===t.n).flatMap(qt),p=.966,s=e.parts.flatMap(M=>M.pads).filter(M=>M.net===t.p||M.net===t.n).map(M=>({at:M.at,r:Math.max(M.w,M.h)/2+.5})),r=M=>s.some(b=>Math.abs(b.at.x-M.x)<b.r&&Math.abs(b.at.y-M.y)<b.r&&de(b.at,M)<b.r);for(let M of a){let b=bt(M);if(b<1e-6)continue;d+=b;let h=(M.b.x-M.a.x)/b,w=(M.b.y-M.a.y)/b,v=5*M.w+.5+M.w,g=Math.min(M.a.x,M.b.x)-v-1,$=Math.max(M.a.x,M.b.x)+v+1,y=Math.min(M.a.y,M.b.y)-v-1,T=Math.max(M.a.y,M.b.y)+v+1,E=l.filter(k=>k.layer===M.layer&&Math.max(k.a.x,k.b.x)>g&&Math.min(k.a.x,k.b.x)<$&&Math.max(k.a.y,k.b.y)>y&&Math.min(k.a.y,k.b.y)<T).map(k=>{let I=bt(k);return{u:k,M:I,vx:(k.b.x-k.a.x)/(I||1),vy:(k.b.y-k.a.y)/(I||1)}}).filter(k=>k.M>1e-6&&Math.abs(h*k.vx+w*k.vy)>=p);if(!E.length)continue;let m=Math.max(1,Math.ceil(b/.1)),C=b/m;for(let k=0;k<m;k++){let I={x:M.a.x+h*(k+.5)*C,y:M.a.y+w*(k+.5)*C},R=null;for(let H of E){let U=Math.max(0,Math.min(H.M,(I.x-H.u.a.x)*H.vx+(I.y-H.u.a.y)*H.vy)),F=Math.hypot(I.x-(H.u.a.x+H.vx*U),I.y-(H.u.a.y+H.vy*U))-(M.w+H.u.w)/2;F<=0||F>5*M.w+.5||(!R||F<R.gap)&&(R={gap:F,w:(M.w+H.u.w)/2})}if(!R)continue;i+=C;let N=o(I),A=`${r(I)?"F|":""}${N?"B|":""}${M.layer}|${Math.round(R.w*1e3)}|${Math.round(R.gap/.005)}`,L=u.get(A);L||u.set(A,L={layer:M.layer,length:0,wSum:0,gSum:0,at:I,all:[],bga:N}),L.length+=C,L.wSum+=R.w*C,L.gSum+=R.gap*C,L.all.length<400&&L.all.push(I)}}let f=[],c=[...u.entries()].filter(([M])=>!M.startsWith("F|")).map(([,M])=>M);for(let M of(c.length?c:[...u.values()]).sort((b,h)=>h.length-b.length)){let b=f.find(w=>w.layer===M.layer&&w.bga===M.bga&&Math.abs(w.wSum/w.length-M.wSum/M.length)<.0015&&Math.abs(w.gSum/w.length-M.gSum/M.length)<=.08*(w.gSum/w.length));if(!b){f.push(M);continue}let h=(b.length+M.length)/b.length;b.length+=M.length,b.wSum*=h,b.gSum*=h,b.all.length<400&&b.all.push(...M.all.slice(0,400-b.all.length))}let x=M=>Math.round(M*1e3)/1e3;return{sections:f.map(M=>({layer:M.layer,w:x(M.wSum/M.length),gap:x(M.gSum/M.length),length:M.length,at:M.at,pts:M.all.filter((b,h)=>h%Math.max(1,Math.ceil(M.all.length/12))===0)})).sort((M,b)=>b.length-M.length),total:d,coupled:i}}function wn(e){return Math.max(2,.15*(1e9/e)*(300/1.85))}var Ea={usb2:[90],usb3:[85,90],ethernet:[100],pcie:[85,100],sata:[85,100],hdmi:[100],dp:[85,100],lvds:[100],mipi:[85,100],pair:[85,90,100],rf:[50,100],ddr:[40,50,60],se:[50]},Er=e=>e.stackupName?` The file has no stackup of its own, so this is a rough figure on ${e.stackupName}, the likely one.`:" The file has no stackup of its own (none, or KiCad's untouched default), so this is a rough figure.";function cs(e,t,n){let o=t.findIndex(l=>l.name===n.layer),u=t.map(l=>l.kind==="copper"&&!l.plane&&l.name!==n.layer&&n.pts.filter(p=>e.zones.some(s=>s.layer===l.name&&s.polys.some(r=>_e(p,r)))).length*2>=n.pts.length?{...l,plane:!0}:l),d=o>=0?Kt(u,o):null,i=n.layer===e.copper[0]?e.mask.F:n.layer===e.copper[e.copper.length-1]?e.mask.B:void 0,a=i?{t:i.t*.001,tBase:2*i.t*.001,er:i.er,tanD:.025}:void 0;return{id:o,stack:d,mask:a}}var bn=new Map;function ls(e,t,n,o,u,d,i=0){let a=Math.round(n/.005)*.005,l=Math.round(o/.005)*.005,{names:p,...s}=e,r=`${a}|${l}|${u}|${i}|${JSON.stringify(s)}|${JSON.stringify(t??null)}`,f=bn.get(r)??(d?bn.get(`${r}|c`):void 0);if(f)return f;bn.size>4e3&&bn.clear();let c=(d?$o:xo)({stack:e,w:a*.001,t:u,s:l*.001,mask:t,...i>0&&u>0?{narrow:i*.001}:{}});return bn.set(d?`${r}|c`:r,c),c}var qo=e=>({usb2:"USB",usb3:"USB3",ethernet:"ETH",pcie:"PCIE",sata:"SATA",hdmi:"HDMI",dp:"DP",lvds:"LVDS",mipi:"MIPI",pair:"DIFF",rf:"RF",ddr:"DDR",se:"SE"})[e]??"DIFF";function Ra(e,t,n=.1){let{layers:o}=nt(e),u=[],d=Cn(e),i=new Map;for(let l of t.pairs){let{sections:p}=Dr(e,l);if(!p.length){u.push({rule:"impedance",severity:"info",title:`${l.name}: not routed as a coupled pair`,detail:"The two halves never run side by side, so there is no differential impedance to check.",nets:[l.p,l.n]});continue}let s=p.filter((r,f)=>r.length>=2&&(r.length>=5||p.findIndex(c=>c.layer===r.layer)===f));for(let r of s){let{id:f,stack:c,mask:x}=cs(e,o,r);if(!c){u.push({rule:"impedance",severity:yt(l.role)?"info":"warn",title:`${l.name} on ${r.layer}: no reference plane`,detail:`No copper pour covers most of the board next to ${r.layer}, so the pair has no plane to be referenced to and its impedance is not controlled.${yt(l.role)?Fr:""}`,nets:[l.p,l.n],layer:r.layer});continue}let S=wn(l.role.rate),M=r.pts.filter(N=>d.some(A=>N.x>A.x0&&N.x<A.x1&&N.y>A.y0&&N.y<A.y1)).length*2>r.pts.length,b=e.stackupFrom==="assumed"||r.length<S||M,h=ls(c,x,r.w,r.gap,o[f].t,b,e.etch),w=h.z,v=c.below[0]?.er??4.5,g=1+(h.eeff-1)*(3.9-1)/(v-1),$=e.stackupFrom==="default"&&v>3.9?w*Math.sqrt(h.eeff/g):w,y=Math.min(w,$),T=Math.max(w,$),m=(Math.min(T,Math.max(y,l.role.z))-l.role.z)/l.role.z,C=Math.abs(m)<=n?"pass":Math.abs(m)<=2*n?"warn":"fail",k=Ea[l.role.kind].every(N=>Math.abs(Math.min(T,Math.max(y,N))-N)/N>2*n),I=C==="pass"?C:yt(l.role)||e.stackupFrom==="assumed"||r.length<S||M?"info":!l.role.netclass&&C==="fail"&&!k?"warn":C,R=(M&&C!=="pass"?" It runs under a BGA, where pairs neck down to pass between the balls: fine if it widens back to the target once clear of the field.":"")+(e.stackupFrom==="file"||e.stackupFrom==="fab"?"":e.stackupFrom==="assumed"?Er(e):` The file's stackup has KiCad's default \u03B5r 4.5, so it is also solved at 3.9 (${$.toFixed(1)} \u03A9) and judged on the end nearer the target: check the stackup against your fabricator's.`)+(yt(l.role)&&C!=="pass"?Fr:"")+(l.role.netclass||C==="pass"||yt(l.role)?"":` The ${l.role.z} \u03A9 target is the usual one for ${l.role.label}: if you designed for another, name the netclass after its impedance (for example "${qo(l.role.kind)}_${l.role.z===100?90:100}R"), or set the interface in the fast-net list on the Board check page.`);if(I!=="pass"&&!l.role.netclass){let N=[r.layer,r.w,r.gap,w.toFixed(1),l.role.z,I].join("|");i.set(N,[...i.get(N)??[],{i:u.length,name:l.name,nets:[l.p,l.n],label:l.role.label,kind:l.role.kind,w:r.w,gap:r.gap,z:w,layer:r.layer,target:l.role.z,severity:I,offAll:k}])}u.push({rule:"impedance",severity:I,title:`${l.name} on ${r.layer}: ${w.toFixed(1)} \u03A9 differential, target ${l.role.z} \u03A9`,detail:`${r.w} mm traces, ${r.gap} mm gap, ${r.length.toFixed(1)} mm long${x?`, under ${(x.t*1e6).toFixed(0)} \xB5m of solder mask`:""}. ${Math.abs(m)<=n?"Within":"Outside"} \xB1${n*100}% of the ${l.role.netclass?`${l.role.netclass} netclass`:l.role.label} target (${m>=0?"+":""}${(m*100).toFixed(0)}%).${R}`,nets:[l.p,l.n],layer:r.layer})}}let a=new Set;for(let l of i.values()){if(l.length<3)continue;let p=l[0],s=l.map(f=>f.name),r=[...new Set(l.map(f=>f.label))];l.forEach(f=>a.add(f.i)),u.push({rule:"impedance",severity:p.severity,title:`${l.length} pairs on ${p.layer}: ${p.z.toFixed(1)} \u03A9 differential, target ${p.target} \u03A9`,detail:`${s.slice(0,4).join(", ")}${s.length>4?` and ${s.length-4} more`:""} (${r.join(", ")}) all use ${p.w} mm traces with a ${p.gap} mm gap, which solves to ${p.z.toFixed(1)} \u03A9. ${l.every(f=>f.offAll)?`That is far from every impedance ${r.join(" and ")} is built to, so the geometry was not set for impedance: work out the width and gap for this stackup on the Differential pair page.`:`The ${p.target} \u03A9 target is only the usual one for ${r.join(" and ")}: the same geometry on this many pairs is usually a deliberate impedance. ${e.project?`Their netclass in the .kicad_pro names no impedance: name it after one (for example "${qo(l[0].kind)}_${p.target===100?90:100}R") so each pair is checked against it, or set the interface in the fast-net list on the Board check page.`:"Add the board's .kicad_pro so each pair is checked against its netclass, or set the interface in the fast-net list on the Board check page."}`}`,nets:l.flatMap(f=>f.nets),layer:p.layer})}if(a.size){let l=u.filter((p,s)=>!a.has(s));u.length=0,u.push(...l)}return u}var Na=[{kind:"pcie",rate:8e9,system:10.3,card:6.5,source:"PCI-SIG: 22 dB end to end at 8 GT/s, less 3.5 dB root package, 1.7 dB connector and 6.5 dB add-in card"},{kind:"pcie",rate:16e9,system:13.5,card:8,source:"PCI-SIG: 28 dB end to end at 16 GT/s, less 5 dB root package, 1.5 dB connector and 8 dB add-in card"},{kind:"pcie",rate:32e9,system:16,card:9.5,source:"PCI-SIG: 36 dB end to end at 32 GT/s, less 9 dB root package, 1.5 dB connector and 9.5 dB add-in card"},{kind:"usb3",rate:5e9,system:8.5,source:"USB 3.2: 8.5 dB for a host or a device, die to connector, at 2.5 GHz"},{kind:"usb3",rate:1e10,system:8.5,source:"USB 3.2: 8.5 dB for a host or a device, die to connector, at 5 GHz"}],La=2e-6,Oa=6e-6;function Ba(e,t){let n=[],{layers:o,planeNet:u}=nt(e),d=new Map,i=new Set(Object.values(u)),a=e.parts.some(l=>{let p=`${l.lib} ${l.value}`;return/PCBEdge|BUS_PCI|PCI_?e(xpress)?.*(Edge|Finger|bracket)|(Edge|bracket).*PCI_?e|M\.?2.*(Card|Edge|Finger)/i.test(p)||/PCI_?express[_-]?x\d/i.test(p)&&!/slot|socket|receptacle|vertical|right.?angle|SMT|THT/i.test(p)});for(let l of t.pairs){if(/reference clock/.test(l.role.label))continue;let p=Na.filter(I=>I.kind===l.role.kind&&I.rate<=l.role.rate*1.01).pop();if(!p)continue;let{sections:s,total:r}=Dr(e,l);if(!s.length||r<1)continue;let f=p.rate/2,c=a&&p.card?p.card:p.system,x=0,S=0,M=0,b=0,h=0,w=!1,v=[];for(let I of s){if(I.length<.5)continue;let{id:R,stack:N,mask:A}=cs(e,o,I);if(!N)continue;let L=o[R].t,H=ls(N,A,I.w,I.gap,L,!0,e.etch),U=G=>G>0?G:.02,P=H.tanD.slice(1,-1).every(G=>!(G>0)||Math.abs(G-.02)<1e-6);w||=P;let F=(G,J)=>({er:H.er,tanD:H.tanD.map((j,Z)=>Z===0?0:Z===H.tanD.length-1?j:U(j)*J),fRef:1e9,w:I.w*.001,t:L,roughness:{model:"huray",rz:G}}),V=hr(H.mode,F(La,P?.8:1),f).loss*.001,O=hr(H.mode,F(Oa,1),f).loss*.001;x+=V*I.length,S+=O*I.length,M+=I.length,I===s[0]&&(b=V,h=O),v.length<3&&I.length>=1&&v.push(`${I.length.toFixed(0)} mm on ${I.layer} at ${(O*25.4).toFixed(2)} dB/in`)}if(!M)continue;let g=Math.max(0,r-M);x+=b*g,S+=h*g;let $=0,y=0,T=0,E=new Map;for(let I of e.vias.filter(R=>R.net===l.p)){let R=Jn(e,I);if(R.length<2)continue;let N=`${I.kind}|${R[0]}|${R[R.length-1]}|${I.drill}|${I.size}`,A=E.get(N);A?A.n++:E.set(N,{v:I,ls:R,n:1})}for(let{v:I,ls:R,n:N}of E.values()){y+=N;let A=e.vias.filter(P=>P.net===l.n&&P.kind===I.kind).sort((P,F)=>de(P.at,I.at)-de(F.at,I.at))[0]??null,L=e.vias.filter(P=>i.has(P.net)&&P.kind==="through").map(P=>de(P.at,I.at)).filter(P=>P<=2.5).sort((P,F)=>P-F),H=`${I.kind}|${R[0]}|${R[R.length-1]}|${I.drill}|${I.size}|${A?(Math.round(de(A.at,I.at)/.1)*.1).toFixed(1):"-"}|${L.length}|${L.length?Math.round(L[0]/.25):"-"}|${l.role.z}|${f}`,U=d.has(H)?d.get(H):I.kind==="through"?Pr(e,o,u,I,R,A,l.role.z,50,f):null;d.set(H,U),U?$+=U.loss*N:T+=N}x+=$,S+=$;let m=x>c?"fail":S>.75*c?"warn":"pass",C=m!=="pass"&&e.stackupFrom==="assumed"?"info":m,k=a&&p.card?"add-in card's share":"system board's share";n.push({rule:"loss",severity:C,title:`${l.name}: ${x.toFixed(1)} to ${S.toFixed(1)} dB of loss at ${(f/1e9).toFixed(f%1e9?1:0)} GHz`,detail:`${r.toFixed(0)} mm of route (${v.join(", ")})${y?`, and ${y} layer ${y===1?"change":"changes"}${$>0?` (${$.toFixed(1)} dB from the via model${T?`; ${T} with no plane around ${T===1?"it":"them"} to model against, not counted`:""})`:T?" with no plane around them to model against, not counted":""}`:""}. Solved for its own cross-section with the stackup's loss tangent${w?" (KiCad's default 0.02, so taken as 0.016 to 0.02, the span of ordinary FR-4)":""} and copper from very low profile (Rz 2 \xB5m) to standard foil (Rz 6 \xB5m). ${l.role.label} allows the ${k} ${c} dB at this frequency (${p.source}${a&&p.card?", the card figure including the endpoint package":""}). ${m==="fail"?"Even the low end is over it, before AC capacitors and connectors: shorten the route, use a lower-loss laminate, or add a redriver.":m==="warn"?"The high end is over three quarters of it, and AC capacitors and connector launches take more: check with your laminate's loss tangent and foil, or shorten the route.":"Well within it."}${e.stackupFrom==="assumed"?Er(e):""} If the link also runs on a module or another board, their routing shares the same budget.`,nets:[l.p,l.n],layer:s[0].layer})}return n}var Ua={rf:[50],ddr:[40,50,60],se:[50]};function _a(e,t,n,o,u){let d=[1/0,1/0];return[1,-1].forEach((i,a)=>{for(let l=.025;l<=u+1e-9;l+=.025)if(e({x:t.x+i*n.x*(o/2+l),y:t.y+i*n.y*(o/2+l)})){d[a]=l;break}}),d}function za(e,t,n=.1){let{layers:o,planeNet:u}=nt(e),d=Cn(e),i=new Map,a=new Set([...Object.values(u),...e.nets.filter(c=>ue.test(B(c)))]),l=new Map;for(let c of e.zones)a.has(c.net)&&l.set(c.layer,[...l.get(c.layer)??[],...c.polys]);let p=c=>c.ztarget.reduce((x,S)=>Math.abs(c.z-S)/S<Math.abs(c.z-x)/x?S:x),s=new Map,r=[],f=[...new Set(t.singles.filter(c=>c.role.netclass).map(c=>c.role.z))];for(let c of t.singles){let x=e.tracks.filter($=>$.net===c.net).flatMap(qt);if(!x.length)continue;let S=e.parts.flatMap($=>$.pads.filter(y=>y.net===c.net)),M=$=>S.some(y=>de(y.at,$)<Math.max(y.w,y.h)/2+.5),b=new Map;for(let $ of x){let y=bt($);if(y<1e-6)continue;let T=Math.round($.w/.005)*.005,E=`${$.layer}|${T}`,m=b.get(E)??b.set(E,{layer:$.layer,w:T,length:0,pts:[]}).get(E);m.length+=y;let C={x:-($.b.y-$.a.y)/y,y:($.b.x-$.a.x)/y};for(let k=.25;k<y;k+=.5){let I={x:$.a.x+($.b.x-$.a.x)*k/y,y:$.a.y+($.b.y-$.a.y)*k/y};M(I)||m.pts.push({q:I,n:C})}}let h=[...b.values()].sort(($,y)=>y.length-$.length),w=h.filter(($,y)=>$.length>=2&&$.pts.length>=2&&($.length>=5||h.findIndex(T=>T.layer===$.layer)===y)),v=c.role.netclass?[c.role.z]:Ua[c.role.kind]??[c.role.z],g=c.role.netclass?`${c.role.z} \u03A9`:v.length>1?`${v[0]} to ${v[v.length-1]} \u03A9`:`${v[0]} \u03A9`;for(let $ of w){let y=o.findIndex(Q=>Q.name===$.layer),T=$.pts.filter((Q,ye)=>ye%Math.max(1,Math.ceil($.pts.length/24))===0),E=o.map(Q=>Q.kind==="copper"&&!Q.plane&&Q.name!==$.layer&&T.filter(ye=>e.zones.some(be=>be.layer===Q.name&&be.polys.some(Ee=>_e(ye.q,Ee)))).length*2>=T.length?{...Q,plane:!0}:Q),m=y>=0?Kt(E,y):null,C=`${c.role.kind}|${c.role.netclass??""}|${$.layer}`;if(!m){let Q=`${C}|noplane`,ye=s.get(Q);if(ye){ye.nets.push(c.net),ye.len.push($.length);continue}s.set(Q,{ztarget:v,nets:[c.net],label:c.role.label,kind:c.role.kind,layer:$.layer,w:$.w,gapText:"",z:NaN,target:g,severity:"warn",len:[$.length],caveat:"",nc:c.role.netclass});continue}let k=m.below.reduce((Q,ye)=>Q+ye.h,0)*1e3,I=Q=>(l.get($.layer)??[]).some(ye=>_e(Q,ye)),R=T.map(Q=>_a(I,Q.q,Q.n,$.w,3*k)),N=Q=>{let ye=R.map(be=>be[Q]).filter(Number.isFinite);return ye.length*2>=R.length?Xn(ye):1/0},A=N(0),L=N(1),H=Q=>Q<=.2?Math.max(.025,Math.round(Q/.025)*.025):Math.round(Q/.05)*.05,U=$.layer===e.copper[0]?e.mask.F:$.layer===e.copper[e.copper.length-1]?e.mask.B:void 0,P=U?{t:U.t*.001,tBase:2*U.t*.001,er:U.er,tanD:.025}:void 0,F=Q=>{let{names:ye,...be}=m,Ee=`${$.w}|${Q??"-"}|${o[y].t}|${JSON.stringify(be)}|${JSON.stringify(P??null)}`,Qe=i.get(Ee);return Qe===void 0&&(Qe=Vn({stack:m,w:$.w*.001,t:o[y].t,mask:P,...Q?{coplanarGap:Q*.001}:{},...e.etch?{narrow:e.etch*.001}:{}}).z,i.set(Ee,Qe)),Qe},V,O;if(Number.isFinite(A)&&Number.isFinite(L)){let Q=H((A+L)/2);V=F(Q),O=`, ground pour ${Q.toFixed(3)} mm from both edges`}else if(Number.isFinite(A)||Number.isFinite(L)){let Q=H(Math.min(A,L)),ye=F(),be=F(Q);V=2/(1/ye+1/be),O=`, ground pour ${Q.toFixed(3)} mm from one edge`}else V=F(),O="";let G=v.reduce((Q,ye)=>Math.abs(V-ye)/ye<Math.abs(V-Q)/Q?ye:Q),J=(V-G)/G,j=Math.abs(J)<=n?"pass":Math.abs(J)<=2*n?"warn":"fail",Z=T.filter(Q=>d.some(ye=>Q.q.x>ye.x0&&Q.q.x<ye.x1&&Q.q.y>ye.y0&&Q.q.y<ye.y1)).length*2>T.length,ae=$.length<wn(c.role.rate),z=c.role.netclass?f.find(Q=>Q!==c.role.z&&Math.abs(V-Q)/Q<=n):void 0,oe=j==="pass"?j:e.stackupFrom==="assumed"||ae||Z?"info":z&&j==="fail"||e.stackupFrom==="default"&&j==="fail"&&Math.abs(J)<=2*n+.08?"warn":j,Te=(j==="pass"?"":ae?` At ${$.length.toFixed(1)} mm it is short against the edge rate, so a mismatch hardly shows.`:"")+(Z&&j!=="pass"?" It runs under a BGA, where traces neck down between the balls.":"")+(z&&j!=="pass"?` That is the ${z} \u03A9 of another netclass on this board: check which class the net belongs in.`:"")+(e.stackupFrom==="file"||e.stackupFrom==="fab"?"":e.stackupFrom==="assumed"?Er(e):" The file's stackup has KiCad's default \u03B5r (4.5); FR-4 runs down to about 3.9, a few percent higher in impedance: check it against your fabricator's."),Ie=`${C}|${$.w}|${O}|${V.toFixed(1)}|${oe}`,Ne=s.get(Ie);if(Ne){Ne.nets.push(c.net),Ne.len.push($.length);continue}s.set(Ie,{ztarget:v,nets:[c.net],label:c.role.label,kind:c.role.kind,layer:$.layer,w:$.w,gapText:O,z:V,target:g,severity:oe,len:[$.length],mask:P&&P.t*1e6,caveat:Te,nc:c.role.netclass})}}for(let c of s.values()){if(c.kind!=="ddr"||c.nc||Number.isNaN(c.z)||c.severity==="info")continue;let x=[...s.values()].filter(M=>M.kind==="ddr"&&!M.nc&&M.layer===c.layer&&!Number.isNaN(M.z)),S=x.reduce((M,b)=>b.nets.length>M.nets.length?b:M,x[0]);S!==c&&S.nets.length>=3&&S.nets.length>=3*c.nets.length&&Math.abs(c.z-S.z)/S.z>2*n&&(c.severity==="pass"&&(c.severity="warn"),c.caveat+=` The other ${S.nets.length} DDR nets on ${c.layer} are ${S.z.toFixed(1)} \u03A9 (${+S.w.toFixed(3)} mm): a memory bus is routed to one impedance, so check this net's width.`)}for(let c of s.values()){let x=c.nets.length>1,S=x?`${c.nets.length} ${c.label} nets`:c.nets[0],M=x?`${c.nets.slice(0,4).map(B).join(", ")}${c.nets.length>4?` and ${c.nets.length-4} more`:""}: `:"",b=c.len.length>1?`${Math.min(...c.len).toFixed(1)} to ${Math.max(...c.len).toFixed(1)} mm long`:`${c.len[0].toFixed(1)} mm long`,h=c.nc?`the ${c.nc} netclass`:c.kind==="ddr"?"DDR layout guides (40 \u03A9 from TI and NXP, 50 \u03A9 from TI, AMD and Micron, up to 60 \u03A9 point to point)":c.kind==="rf"?"RF practice":"the netclass";if(Number.isNaN(c.z)){r.push({rule:"impedance",severity:"warn",title:`${S} on ${c.layer}: no reference plane`,detail:`${M}No copper pour covers most of the board next to ${c.layer}, so ${x?"these traces have":"the trace has"} no plane to be referenced to and the impedance is not controlled.`,nets:c.nets,layer:c.layer});continue}r.push({rule:"impedance",severity:c.severity,title:`${S} on ${c.layer}: ${c.z.toFixed(1)} \u03A9, target ${c.target}`,detail:`${M}${+c.w.toFixed(3)} mm trace${x?"s":""}, ${b}${c.mask?`, under ${c.mask.toFixed(0)} \xB5m of solder mask`:""}${c.gapText}. ${Math.abs(c.z-p(c))/p(c)<=n?"Within":"Outside"} \xB1${n*100}% of ${c.target}, from ${h}.${c.caveat}${c.severity==="pass"||c.nc?"":` If you designed for another impedance, put the nets in a netclass named after it (for example "${c.label.replace(/[^A-Za-z0-9]/g,"")}_40R").`}`,nets:c.nets,layer:c.layer})}return r}var de=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),$n=299792458;function Jn(e,t){let n=Math.max(t.size/2,.05),o=new Set;for(let u of e.tracks)u.net===t.net&&(de(u.a,t.at)<=n||de(u.b,t.at)<=n)&&o.add(u.layer);return e.copper.filter(u=>o.has(u))}function kn(e,t,n){let o=e.copper.indexOf(n),u=e.copper.length;if(o<0)return;let d=o<u/2?[1,-1]:[-1,1],i=At(e),a=i[n],l=r=>a&&i[r]?Math.min(Math.abs(i[r].top-a.bottom),Math.abs(a.top-i[r].bottom)):1/0,p,s=1/0;for(let r=1;r<u;r++)for(let f of d){let c=o+f*r,x=e.copper[c];if(c<0||c>=u||!t[x])continue;let S=l(x)===1/0?r*1e3:l(x);S<s-1e-6&&(p=x,s=S)}return p}var Xn=e=>{let t=[...e].sort((n,o)=>n-o);return t.length?t[t.length>>1]:0};function Cn(e){return e.parts.filter(t=>t.pads.length>=49&&Xn(t.pads.map(n=>Math.max(n.w,n.h)))<=.8).map(t=>{let n=t.pads.map(u=>u.at.x),o=t.pads.map(u=>u.at.y);return{x0:Math.min(...n)-.5,x1:Math.max(...n)+.5,y0:Math.min(...o)-.5,y1:Math.max(...o)+.5}})}var es=new WeakMap;function At(e){let t=es.get(e);return t||es.set(e,t=ds(e)),t}function ds(e){let t={},n=0;for(let o of e.stackup)o.kind==="copper"&&(t[o.name]={top:n*1e3,bottom:(n+o.t)*1e3}),n+=o.t;return t}var Zn=e=>[...e.pairs.map(t=>({name:t.name,nets:[t.p,t.n],role:t.role})),...e.singles.map(t=>({name:t.net,nets:[t.net],role:t.role}))],Kn=e=>e==="ddr"||e==="se",ts=6.35,Ir=e=>e.toFixed(2),Pt=e=>e/1e9<10?(e/1e9).toFixed(1):(e/1e9).toFixed(0);function Va(e,t){let n=[],{layers:o,planeNet:u}=nt(e),d=ds(e),i=e.stackup.filter(p=>p.kind==="dielectric"),a=i.reduce((p,s)=>p+s.er*s.t,0)/Math.max(i.reduce((p,s)=>p+s.t,0),1e-12)||4.2,l=e.thickness;for(let p of Zn(t)){let s=p.role.kind==="rf"?p.role.rate:p.role.rate/2,r=null,f=0;for(let y of e.vias.filter(T=>p.nets.includes(T.net)&&T.kind==="through")){let T=Jn(e,y);if(T.length<2)continue;f++;let E=d[T[0]]?.top??0,m=d[T[T.length-1]]?.bottom??l,C=Math.max(E,l-m);(!r||C>r.stub)&&(r={stub:C,at:y.at,layers:T,v:y})}if(!r)continue;if(r.stub<.05){n.push({rule:"stubs",severity:"pass",title:`${p.name}: no via stubs`,detail:`All ${f} vias run between the outer layers, so no barrel is left unused.`,nets:p.nets});continue}let c=p.role.kind==="rf"?"carrier":"Nyquist frequency",x=r.layers[0],S=r.layers[r.layers.length-1],M=$n/(4*(r.stub/1e3)*Math.sqrt(a));if(M>=20*s){n.push({rule:"stubs",severity:"pass",title:`${p.name}: via stub ${r.stub.toFixed(2)} mm, too short to matter at ${Pt(s)} GHz`,detail:`The via from ${x} to ${S} leaves ${r.stub.toFixed(2)} mm of barrel unused. By the quarter-wave rule a stub this short resonates near ${Pt(M)} GHz, over twenty times the ${Pt(s)} GHz ${c} of ${p.role.label}, so it costs this signal next to nothing.`,nets:p.nets,layer:x,at:r.at});continue}let b=p.nets.find(y=>y!==r.v.net),h=b?e.vias.filter(y=>y.net===b&&y.kind==="through").sort((y,T)=>de(y.at,r.at)-de(T.at,r.at))[0]??null:null,w=Pr(e,o,u,r.v,r.layers,h,p.nets.length===2?p.role.z:100,p.nets.length===2?50:p.role.z,s);if(w){let y=w.notch!==null&&w.notch<1.3*s,T=w.notch!==null&&w.notch<2*s,E=y||w.loss>2?"fail":T||w.loss>.7?"warn":"pass",m=e.stackupFrom==="assumed"&&E!=="pass"?"info":E,C=w.notch===null?"no notch in the sweep":`its notch at ${Pt(w.notch)} GHz`,k=`${w.diff?`a pair of vias ${w.pitch.toFixed(2)} mm apart`:w.merged?"each via of the pair on its own, as their antipads merge":"a single via"}, ${Ir(r.v.drill)} mm drill, ${Ir(r.v.size)} mm pad, ${Ir(w.antipad)} mm antipad read from the planes, ${w.ground?`${w.ground} ground ${w.ground===1?"via":"vias"} nearby`:"no ground via nearby"}`,I=s>w.fValid?` The ${Pt(s)} GHz ${c} is past the ${Pt(w.fValid)} GHz this kind of via is checked to against 3D, so take the numbers as indicative.`:"";n.push({rule:"stubs",severity:m,title:`${p.name}: via stub ${r.stub.toFixed(2)} mm, ${w.loss.toFixed(1)} dB loss at ${Pt(s)} GHz`,detail:`The via from ${x} to ${S} leaves ${r.stub.toFixed(2)} mm of barrel unused. Impedora's via model (${k}) gives ${w.loss.toFixed(2)} dB insertion loss and ${w.rl.toFixed(0)} dB return loss at the ${Pt(s)} GHz ${c} of ${p.role.label}, with ${C}.${I}${e.stackupFrom==="assumed"?" The file has no stackup, so the layer depths are assumed.":""} ${m==="pass"?"Fine at this speed.":"Backdrill it, or route on layers that use the whole barrel. Open it on the Via page to try both."}`,nets:p.nets,layer:x,at:r.at});continue}let v=$n/(4*(r.stub/1e3)*Math.sqrt(a)),g=v/s,$=g>=3?"pass":g>=1.5?"warn":"fail";n.push({rule:"stubs",severity:$,title:`${p.name}: longest via stub ${r.stub.toFixed(2)} mm, notch near ${Pt(v)} GHz`,detail:`A via from ${x} to ${S} leaves ${r.stub.toFixed(2)} mm of barrel unused. With no plane around it to model it against, the quarter-wave rule puts its notch near ${Pt(v)} GHz, ${g.toFixed(0)}\xD7 the ${Pt(s)} GHz ${c} of ${p.role.label}. ${$==="pass"?"Far enough above.":"Real notches come lower than this rule: backdrill the via or route on layers that use the whole barrel."}`,nets:p.nets,layer:x,at:r.at})}return n}function ns(e,t,n){let o=e.zones.filter(i=>i.layer===t);if(!o.length)return null;let u=new Map;for(let i of[.6,1,1.5])for(let a=0;a<8;a++){let l={x:n.x+i*Math.cos(a*Math.PI/4),y:n.y+i*Math.sin(a*Math.PI/4)};for(let p of o)if(p.polys.some(s=>_e(l,s))){u.set(p.net,(u.get(p.net)??0)+1);break}}let d=[...u.entries()].sort((i,a)=>a[1]-i[1])[0];return d&&d[1]>=6?d[0]:null}function Ha(e,t){let{planeNet:n}=nt(e),o=[],u=e.parts.flatMap(s=>s.pads.filter(r=>r.layers.includes("*.Cu"))),d=e.parts.filter(s=>/^C\d/i.test(s.ref)&&s.pads.length===2&&s.pads[0].net&&s.pads[1].net&&s.pads[0].net!==s.pads[1].net).map(s=>({a:s.pads[0].net,b:s.pads[1].net,at:s.at})),i=s=>Kn(s)?ts:2.5,a=At(e),l=(s,r)=>{let f=e.copper.indexOf(s),c=a[s],x=b=>c&&a[b]?Math.min(Math.abs(a[b].top-c.bottom),Math.abs(c.top-a[b].bottom)):1/0,S=[e.copper[f-1],e.copper[f+1]].filter(b=>!!b).map(b=>({layer:b,net:ns(e,b,r)??n[b]})).filter(b=>!!b.net).sort((b,h)=>x(b.layer)-x(h.layer));if(S.length)return S;let M=kn(e,n,s);return M?[{layer:M,net:ns(e,M,r)??n[M]}]:[]};for(let s of Zn(t)){let r=s.role.rate>=1e9,f=s.nets.length===2?"The pair":"The trace",c=null;for(let h of e.vias.filter(w=>s.nets.includes(w.net))){let w=Jn(e,h);if(w.length<2)continue;let v=l(w[0],h.at),g=l(w[w.length-1],h.at);if(!v.length||!g.length||v.some(k=>g.some(I=>I.layer===k.layer)))continue;let $=v.map(k=>k.net).filter(k=>g.some(I=>I.net===k)).sort((k,I)=>Number(ue.test(B(I)))-Number(ue.test(B(k))))[0],y=($?v.find(k=>k.net===$):v[0]).layer,T=($?g.find(k=>k.net===$):g[0]).layer,E=$??v[0].net,m=$??g[0].net;if(E!==m){let k=d.filter(I=>I.a===E&&I.b===m||I.a===m&&I.b===E).reduce((I,R)=>Math.min(I,de(R.at,h.at)),1/0);if(k<=i(s.role.kind))continue;(!c||!c.diffNet||k>c.d)&&(c={d:k,at:h.at,from:y,to:T,net:`${E} \u2192 ${m}`,diffNet:!0});continue}let C=Math.min(e.vias.filter(k=>k.net===E).reduce((k,I)=>Math.min(k,de(I.at,h.at)),1/0),u.filter(k=>k.net===E).reduce((k,I)=>Math.min(k,de(I.at,h.at)),1/0));(!c||!c.diffNet&&C>c.d)&&(c={d:C,at:h.at,from:y,to:T,net:E,diffNet:!1})}if(!c)continue;if(c.diffNet){let[h,w]=c.net.split(" \u2192 ");o.push({rule:"return",severity:r?"warn":"info",title:`${s.name}: changes from a ${h} plane to a ${w} plane`,detail:`Where it changes layer, the return current has to cross from ${c.from} (${h}) to ${c.to} (${w}). No via can carry it between two different nets, and ${isFinite(c.d)?`the nearest capacitor between them is ${c.d.toFixed(1)} mm away`:"no capacitor joins them"}: put one within ${i(s.role.kind).toFixed(1)} mm of the via, or keep it on layers referenced to the same net.${r?"":` At ${s.role.label}${/speed$/.test(s.role.label)?"":" speeds"} this rarely matters.`}`,nets:s.nets,at:c.at});continue}let x=s.role.kind==="rf"?s.role.rate:s.role.rate/2*3,S=Kn(s.role.kind),M=S?ts:Math.min(2.5,Math.max(1.27,300/(x/1e9*1.85)/10)),b=c.d<=M?"pass":r?S?c.d<=2*M?"warn":"fail":c.d<=2.5*M||s.role.kind==="pair"?"warn":"fail":"info";o.push({rule:"return",severity:b,title:`${s.name}: nearest ${c.net} return via ${isFinite(c.d)?c.d.toFixed(1)+" mm":"missing"}`,detail:`${f} moves from a layer referenced to ${c.from} to one referenced to ${c.to}, both ${c.net}. Its return current jumps planes at the nearest ${c.net} via${isFinite(c.d)?`, ${c.d.toFixed(1)} mm away`:", and there is none"}. ${b==="pass"?`Close enough at ${s.role.label}${/speed$/.test(s.role.label)?"":" speeds"} (within ${M.toFixed(1)} mm).`:`Place a ${c.net} via within about ${M<=1.5?1:M.toFixed(1)} mm of each signal via.`}${S?" The limit is TI's DDR4 guide (\xB1250 mil); AMD asks for 50 mil.":""}${r||b==="pass"?"":` At ${s.role.label}${/speed$/.test(s.role.label)?"":" speeds"} it is a minor effect.`}`,nets:s.nets,at:c.at})}let p=new Map;for(let s of o)if(s.severity!=="pass"&&s.title.includes(" plane to a ")){let r=`${s.severity}|${s.title.split(": ")[1]}`;p.set(r,[...p.get(r)??[],s])}for(let[s,r]of p){if(r.length<3)continue;let f=r.map(c=>c.title.split(": ")[0]);for(let c of r)o.splice(o.indexOf(c),1);o.push({...r[0],title:`${r.length} ${r[0].nets.length===2?"pairs":"nets"} ${s.split("|")[1]}`,detail:`${f.slice(0,4).join(", ")}${f.length>4?` and ${f.length-4} more`:""}: ${r[0].detail}`,nets:r.flatMap(c=>c.nets)})}return o}var jn=e=>/^(J|P|CN|CON|USB|X)\d/i.test(e.ref)||/connector|receptacle|RJ45|USB|HDMI|SMA|U\.FL/i.test(e.lib),Ar=e=>/RJ45|MAGJACK|ISO|LAN.?TRANS|H1102|HX11|TRANSFORMER/i.test(`${e.lib} ${e.value}`);function Ga(e,t){let{planeNet:n}=nt(e),o=[],u=(h,w)=>w.some(v=>_e(h,v)),d=h=>{let w=new Map;return v=>(w.has(v)||w.set(v,h(v)),w.get(v))},i=d(h=>e.zones.filter(w=>w.layer===h).flatMap(w=>w.polys)),a=d(h=>new Set(e.zones.filter(w=>w.layer===h).map(w=>w.net))),l=e.parts.flatMap(h=>h.pads),p=e.parts.filter(jn).flatMap(h=>h.pads.map(w=>({at:w.at,r:Math.max(w.w,w.h)/2}))),s=d(h=>l.filter(w=>w.layers.includes("*.Cu")||w.layers.includes(h))),r=new Map,f=new Map;for(let h of l)(r.get(h.net)??r.set(h.net,[]).get(h.net)).push(h);for(let h of e.vias)(f.get(h.net)??f.set(h.net,[]).get(h.net)).push(h);let c=e.parts.filter(jn).flatMap(h=>h.pads).map(h=>({at:h.at,r:Math.max(.8,Math.max(h.w,h.h)/2+.3)})),x=2,S=new Map;for(let h of c)for(let w=Math.floor((h.at.x-h.r)/x);w<=Math.floor((h.at.x+h.r)/x);w++)for(let v=Math.floor((h.at.y-h.r)/x);v<=Math.floor((h.at.y+h.r)/x);v++)(S.get(`${w}|${v}`)??S.set(`${w}|${v}`,[]).get(`${w}|${v}`)).push(h);let M=h=>(S.get(`${Math.floor(h.x/x)}|${Math.floor(h.y/x)}`)??[]).some(w=>de(w.at,h)<w.r),b=Cn(e);for(let h of Zn(t)){let w=new Map;for(let z of e.tracks)h.nets.includes(z.net)&&n[z.layer]&&w.set(z.layer,(w.get(z.layer)??0)+de(z.a,z.b));let v=[...w.entries()].filter(([,z])=>z>=1),g=v.length?e.tracks.find(z=>h.nets.includes(z.net)&&z.layer===v[0][0])?.a:void 0,$=h.role.kind==="ethernet"&&!!g&&e.parts.some(z=>Ar(z)&&de(z.at,g)<15);v.length&&e.copper.length>2&&o.push({rule:"gaps",severity:$?"info":"warn",title:`${h.name}: routed inside ${v.map(([z])=>`the ${n[z]} plane on ${z}`).join(" and ")}`,detail:`${v.map(([z,oe])=>`${oe.toFixed(1)} mm on ${z}`).join(", ")}. Each trace there cuts a slot in a plane that other signals use as their return path, and the signals above or below it lose their reference. Keep fast signals on signal layers and the planes solid.`,nets:h.nets,layer:v[0][0]});let y=h.nets.flatMap(z=>f.get(z)??[]),T=h.nets.flatMap(z=>r.get(z)??[]),E=[...y.map(z=>({at:z.at,r:.8})),...T.map(z=>({at:z.at,r:Math.max(.8,Math.max(z.w,z.h)/2+.3)}))],m=0,C,k="",I="",R=0,N,A="",L="",H="",U=[],P=[...y.map(z=>({at:z.at,r:z.size/2})),...T.map(z=>({at:z.at,r:Math.max(z.w,z.h)/2})),...p],F=z=>P.some(oe=>Math.abs(oe.at.x-z.x)<oe.r+1.5&&Math.abs(oe.at.y-z.y)<oe.r+1.5&&de(oe.at,z)<oe.r+1.5),V=e.tracks.filter(z=>h.nets.includes(z.net)),O=new Map,G=z=>{if(O.has(z))return O.get(z);let oe=V.filter(be=>be.layer===z).flatMap(be=>[.1,.5,.9].map(Ee=>({x:be.a.x+(be.b.x-be.a.x)*Ee,y:be.a.y+(be.b.y-be.a.y)*Ee}))),Te=At(e),Ie=Te[z],Ne=be=>Ie&&Te[be]?Math.min(Math.abs(Te[be].top-Ie.bottom),Math.abs(Ie.top-Te[be].bottom)):1/0,Q=kn(e,n,z),ye=e.copper.indexOf(z);for(let be of[e.copper[ye-1],e.copper[ye+1]]){if(!be||be===Q)continue;oe.filter(Qe=>u(Qe,i(be))).length/Math.max(oe.length,1)>=.5&&(!Q||Ne(be)<Ne(Q)-1e-6)&&(Q=be)}return O.set(z,Q),Q},J=(z,oe)=>{let Te=V.filter(Ie=>Ie.layer===oe).flatMap(Ie=>[.1,.5,.9].map(Ne=>({x:Ie.a.x+(Ie.b.x-Ie.a.x)*Ne,y:Ie.a.y+(Ie.b.y-Ie.a.y)*Ne})));return Te.filter(Ie=>u(Ie,i(z))).length>=.5*Te.length};for(let z of V){let oe=G(z.layer);if(!oe)continue;let Te=e.copper.indexOf(z.layer),Ie=[e.copper[Te-1],e.copper[Te+1]].filter(fe=>fe&&fe!==oe),Ne=Math.abs(e.copper.indexOf(oe)-Te)===1,Q=i(oe),ye=Ie.flatMap(i),be=Ne?Ie.find(fe=>J(fe,z.layer)):void 0,Ee=be?i(be):[],Qe=a(oe),rt=s(oe),ft=de(z.a,z.b),qe=Math.max(1,Math.floor(ft/.2)),ce=ft/qe,Oe=(z.b.x-z.a.x)/(ft||1),Se=(z.b.y-z.a.y)/(ft||1),Xe=(fe,le)=>{if(le>=3)return!1;let xe={x:fe.x+Oe*le/2,y:fe.y+Se*le/2},he=(re,Ae)=>!h.nets.includes(re.net)&&!Qe.has(re.net)&&de(re.at,xe)<=Math.max(Ae,le/2+.6);if(!e.vias.some(re=>he(re,1.2))&&!rt.some(re=>he(re,1.2+Math.max(re.w,re.h)/2)))return!1;let Ce=re=>[1.2,2,2.8].some(Ae=>u({x:xe.x-re*Se*Ae,y:xe.y+re*Oe*Ae},Q));return Ce(1)&&Ce(-1)},Re=oe,Je=(fe,le)=>le===1?!u(fe,i(Re)):!u(fe,Q)&&!u(fe,ye),ne=(fe,le)=>{let xe=0;for(let he=0;he<180;he+=15){let Ce=Math.cos(he*Math.PI/180),re=Math.sin(he*Math.PI/180);if(Math.abs(Ce*Oe+re*Se)>.866)continue;let Ae=0;for(let ct of[1,-1])for(let Ke=.2;Ke<=15&&Je({x:fe.x+ct*Ce*Ke,y:fe.y+ct*re*Ke},le);Ke+=.2)Ae+=.2;xe=Math.max(xe,Ae)}return xe},te=[0,0,0],ke=[],ve=fe=>{let le=te[fe],xe=ke[fe];if(le>0&&xe){let he={x:xe.x+Oe*le/2,y:xe.y+Se*le/2},Ce=ne(he,fe),re=Ae=>!Ae||F(Ae.at)&&!F(he)||F(Ae.at)===F(he)&&Ce>Ae.ext;Ce>=4&&re(U[fe])&&(U[fe]={ext:Ce,at:he,layer:z.layer,plane:fe===1?Re:oe})}le>=1&&xe&&!Xe(xe,le)&&(fe===2?(m+=le,C||(C=xe,k=z.layer,I=oe)):(R+=le,N||(N=xe,A=z.layer,L=Re,H=Re===oe?Ie.find(he=>e.zones.some(Ce=>Ce.layer===he&&Ce.polys.some(re=>_e(xe,re))))??Ie[0]:oe))),te[fe]=0};for(let fe=0;fe<=qe;fe++){let le={x:z.a.x+(z.b.x-z.a.x)*fe/qe,y:z.a.y+(z.b.y-z.a.y)*fe/qe},xe=E.some(re=>de(re.at,le)<re.r)||M(le)||b.some(re=>le.x>re.x0&&le.x<re.x1&&le.y>re.y0&&le.y<re.y1),he=u(le,Q),Ce=xe?0:he?be&&!u(le,Ee)?1:0:u(le,ye)?Ne?1:0:2;Ce===1&&te[1]===0&&(Re=he?be:oe),Ce!==2&&ve(2),Ce===0&&ve(1),Ce>=1&&(te[1]===0&&(ke[1]=le),te[1]+=ce),Ce===2&&(te[2]===0&&(ke[2]=le),te[2]+=ce)}ve(2),ve(1)}let j=h.role.kind==="ethernet"&&C&&e.parts.some(z=>Ar(z)&&de(z.at,C)<15);if(m>=1&&j){o.push({rule:"gaps",severity:"info",title:`${h.name}: ${m.toFixed(1)} mm over a cleared area near the RJ45`,detail:"The plane is usually cleared around the RJ45 and the magnetics on purpose, to isolate the cable side. Check that the gap is only that isolation area.",nets:h.nets,layer:k,at:C});continue}let Z=U[2],ae=!!Z&&h.role.kind==="ethernet"&&e.parts.some(z=>Ar(z)&&de(z.at,Z.at)<15);if(m<1&&Z){let z=Z.ext>=15?"over 15":Z.ext.toFixed(0),oe=F(Z.at);o.push({rule:"gaps",severity:ae||oe||yt(h.role)?"info":h.role.rate>=25e8&&Z.ext>=10?"fail":"warn",title:`${h.name}: crosses a split in its reference plane`,detail:`On ${Z.layer} it crosses a gap in the plane on ${Z.plane} that runs ${z} mm across the trace. However narrow the split, the return current cannot cross it: it detours around the end of the split, and the loop it makes raises impedance, crosstalk and radiation. Route around the split, or bridge it with a stitching capacitor right next to the crossing.${ae?" Near the RJ45 and magnetics the planes are usually cleared on purpose, for isolation: check it is only that.":oe?" It is right at the pair's breakout from its pads or vias, or along a connector's pin row, where planes are often cut back: check the gap is no longer than that.":""}${yt(h.role)?" At USB full speed (12 Mb/s) this is mostly an emissions concern, not a signal one.":""}`,nets:h.nets,layer:Z.layer,at:Z.at});continue}if(m<1&&(R>=2||U[1]&&!F(U[1].at))){let z=U[1];!N&&z&&(N=z.at,A=z.layer,L=z.plane,H=e.copper.filter(Te=>Math.abs(e.copper.indexOf(Te)-e.copper.indexOf(z.layer))===1&&Te!==z.plane)[0]??"");let oe=Kn(h.role.kind)&&h.role.rate<25e8&&L!==G(A);o.push({rule:"gaps",severity:oe?"info":"warn",title:R>=2?`${h.name}: ${R.toFixed(1)} mm over a gap in one of its two planes`:`${h.name}: crosses a split in one of its two planes`,detail:`On ${A} it crosses a gap in the plane on ${L}. The pour on ${H}, on its other side, still carries part of the return current, so the impedance bumps rather than breaks there.${oe?` ${H} is the nearer plane and carries most of it, so at ${h.role.label}${/speed$/.test(h.role.label)?"":" speeds"} the bump is small.`:" Route around the gap or fill the plane under it."}`,nets:h.nets,layer:A,at:N});continue}m<1?o.push({rule:"gaps",severity:"pass",title:`${h.name}: solid reference plane all the way`,detail:"No part of it runs over a gap or void in the plane it is referenced to.",nets:h.nets}):o.push({rule:"gaps",severity:yt(h.role)?"info":m>2&&h.role.rate>=1e9&&h.role.kind!=="pair"?"fail":"warn",title:`${h.name}: ${m.toFixed(1)} mm over a gap in its reference plane`,detail:`On ${k} it crosses a gap in the plane on ${I}, where there is no copper under it for its return current. That raises impedance, crosstalk and radiation. Route around the gap or fill the plane under it.${yt(h.role)?" At USB full speed (12 Mb/s) this is mostly an emissions concern, not a signal one.":""}`,nets:h.nets,layer:k,at:C})}return o}function Ka(e,t){let n=[];for(let o of t.pairs){let{sections:u,total:d,coupled:i}=Dr(e,o);if(!u.length){d>=10&&n.push({rule:"coupling",severity:yt(o.role)?"info":o.role.rate>=25e8?"fail":"warn",title:`${o.name}: the two halves take separate routes`,detail:`None of its ${d.toFixed(1)} mm runs side by side with its partner. Apart, they are two single-ended lines with no differential impedance, they pick up noise differently, and their lengths and delays drift. Route them together with KiCad's differential pair router (6).`,nets:[o.p,o.n]});continue}let a=u[0],l=wn(o.role.rate),p=u.filter(M=>M.layer===a.layer&&Math.abs(M.w-a.w)<.005&&Math.abs(M.gap-a.gap)/a.gap>.3&&M.length>=l/2),s=d-i,r=o.role.rate>=1e9,f=new Set(e.tracks.filter(M=>M.net===o.p).map(M=>M.layer)),c=new Set(e.tracks.filter(M=>M.net===o.n).map(M=>M.layer)),x=[...f].filter(M=>!c.has(M)).concat([...c].filter(M=>!f.has(M)));if(d>=Math.max(10,l)&&i/d<.5){n.push({rule:"coupling",severity:yt(o.role)?"info":o.role.rate>=25e8?"fail":"warn",title:`${o.name}: the two halves take separate routes`,detail:`Only ${i.toFixed(1)} of ${d.toFixed(1)} mm run side by side${x.length?`, and they are on different layers (${x.join(", ")} carries one half only)`:""}. Apart, they are two single-ended lines with no differential impedance, they pick up noise differently, and their lengths and delays drift. Route them together with KiCad's differential pair router (6), keeping the gap constant and both halves on the same layers.`,nets:[o.p,o.n]});continue}if(d<5&&!p.length){n.push({rule:"coupling",severity:"pass",title:`${o.name}: short connection, ${d.toFixed(1)} mm`,detail:"Too short for its coupling to matter.",nets:[o.p,o.n]});continue}if(!p.length&&s<l){n.push({rule:"coupling",severity:"pass",title:`${o.name}: gap held at ${a.gap} mm`,detail:`${i.toFixed(1)} of ${d.toFixed(1)} mm run as a coupled pair${s>=1?`; the ${s.toFixed(1)} mm apart (breakouts) is short against the ${l.toFixed(0)} mm that matters at ${o.role.label}${/speed$/.test(o.role.label)?"":" speeds"}`:""}.`,nets:[o.p,o.n]});continue}let S=[...p.length?[`Its gap changes to ${p.map(M=>`${M.gap} mm for ${M.length.toFixed(1)} mm`).join(", ")} against the usual ${a.gap} mm, which changes its impedance there.`]:[],...s>=l?[`${s.toFixed(1)} mm of each trace runs apart from its partner (breakouts and detours), against about ${l.toFixed(0)} mm that starts to matter at ${o.role.label}${/speed$/.test(o.role.label)?"":" speeds"}.`]:[]];n.push({rule:"coupling",severity:r?"warn":"info",title:`${o.name}: ${p.length?"gap changes along the route":`${s.toFixed(1)} mm uncoupled`}`,detail:`${S.join(" ")} ${r?"Keep the gap constant and the uncoupled stretches short.":`At ${o.role.label}${/speed$/.test(o.role.label)?"":" speeds"} a few millimetres like this are harmless.`}`,nets:[o.p,o.n],layer:a.layer})}return n}var ja=/^(\+?\d+V\d*|\+?\d+V\d+|V(CC|DD|DDA|DDIO|DDQ|IO|CORE|BAT|IN|SYS|3V3|5V|1V8|1V2)[A-Z0-9_]*|\+[0-9A-Z_.]+|[0-9]+V[0-9]*_?[A-Z]*)$/i,ue=/^(GND|AGND|DGND|PGND|SGND|CGND|GNDA|GNDD|GNDREF|GNDPWR|GND_?ISO|VSS|VSSA|VSSQ|GROUND|EARTH|0V)$/i,Wa=/(^|_)(EN|ENA|ENABLE|PG|PGOOD|POK|PWRGD|GOOD|OK|FAULT|FLT|ALERT|SENSE|SNS|FB|MON|DET|CTRL)\d?$/i,Ge=e=>!Wa.test(e)&&(ja.test(e)||/^([A-Z]{1,4}_?)?\d{1,2}V\d{0,2}(_[A-Z0-9]+)*$/i.test(e)||/^([A-Z]{1,4}_?)?\d{1,2}P\d{1,2}V?(_[A-Z0-9]+)*$/i.test(e));function Ja(e,t){let n=[],o=e.parts.filter(c=>/^C\d+/.test(c.ref)&&new Set(c.pads.filter(x=>x.net).map(x=>x.net)).size===2&&c.pads.some(x=>ue.test(B(x.net)))).map(c=>({...c,pads:c.pads.filter(x=>x.net)})),u=/REG|LDO|BUCK|BOOST|DC-?DC|AMS1117|LM317|TPS6|TPS7|TLV7|LP59|LP38|LT1\d{3}|LT3\d{3}|MIC5|ADP1|ADP7|NCP1|XC62|RT9|AP21|LD11|SPX|TPS2[0-9]{3}|TPS25|LTC4|LT8|LM5|MP[0-9]{4}|SIC4|ISL8|RT[0-9]{4}|^ULS|^ULE|^UWE|^R-78|TRACO|EFUSE|HOT.?SWAP|POE|WROOM|WROVER|MODULE|-MINI|ESD|TVS|TPD\d|SRV0|USBLC|PESD|RCLAMP|SP05|PRTR|NUP\d|ESDA|IP42/i,d=/(^|_)(SW|LX|PHASE|BOOT|BST)\d?(_|$)/i,i=/(^|_)(SW|LX|PHASE|BOOT|BST|FB|EN|PG|PGOOD|SENSE|SNS|COMP|SS|ILIM|ISET|IREF|RSET|RT|CS|TRK|MODE|ADJ)\d?(_|$)/i,a=new Set(e.parts.filter(c=>/^L\d+/.test(c.ref)).flatMap(c=>c.pads.map(x=>x.net))),l=new Set(e.parts.filter(c=>/^C\d+/.test(c.ref)&&c.pads.some(x=>ue.test(B(x.net)))).flatMap(c=>c.pads.map(x=>x.net))),p=c=>c.pads.some(x=>x.net&&a.has(x.net)&&(d.test(B(x.net))||!Ge(B(x.net))&&!ue.test(B(x.net))&&/^NET-\(/i.test(B(x.net))&&!l.has(x.net))),s=c=>/CONN|SOCKET|HEADER|SODIMM|DIMM|SOM|MODULE|RECEPTACLE|BREAKOUT|RPI_PICO|(^|[^A-Z])PICO([^A-Z]|$)|PRO_?MICRO|ELITE-?C|NICE.?NANO|NODEMCU|DEVKIT|RP2040-ZERO|XIAO|TTGO|LILYGO|T-DISPLAY|WEMOS|D1.?MINI|ARDUINO|TEENSY|FEATHER|QT.?PY|KB2040|BLACK.?PILL|BLUE.?PILL|[-_]MINI([^A-Z]|$)|(^|[^A-Z])CORE([^A-Z]|$)/i.test(`${c.lib} ${c.value}`),r=new Set(t?[...t.pairs.filter(c=>c.role.rate>=1e9).flatMap(c=>[c.p,c.n]),...t.singles.map(c=>c.net)]:[]),f=c=>c.pads.filter(x=>!ue.test(B(x.net))).length>=49||c.pads.some(x=>r.has(x.net));for(let c of e.parts.filter(x=>/^(U|IC)\d+/.test(x.ref)&&x.pads.length>=6&&!u.test(x.value)&&!s(x)&&!p(x))){let x=new Map;for(let S of c.pads)S.net&&Ge(B(S.net))&&!ue.test(B(S.net))&&!i.test(B(S.net))&&x.set(S.net,[...x.get(S.net)??[],S.at]);for(let[S,M]of x){let b=o.flatMap(g=>g.pads.filter($=>$.net===S).map($=>({ref:g.ref,at:$.at})));if(!b.length){n.push({rule:"decoupling",severity:"warn",title:`${c.ref} ${B(S)}: no decoupling capacitor`,detail:`No capacitor to ground sits on ${B(S)}, which powers ${c.ref} (${c.value}).`,nets:[S],at:M[0]});continue}let h=0,w="";for(let g of M){let $=b.reduce((y,T)=>de(T.at,g)<y.d?{d:de(T.at,g),ref:T.ref}:y,{d:1/0,ref:""});$.d>h&&(h=$.d,w=$.ref)}let v=h<=5?"pass":f(c)?h<=10?"warn":"fail":h<=10?"info":"warn";v!=="pass"&&n.push({rule:"decoupling",severity:v,title:`${c.ref} ${B(S)}: nearest capacitor ${h.toFixed(1)} mm from a power pin`,detail:`The farthest ${B(S)} pin of ${c.ref} (${c.value}) has its closest capacitor, ${w}, ${h.toFixed(1)} mm away. The loop through a distant capacitor adds inductance, so it cannot supply fast current edges. Aim for under about 3 to 4 mm, with its vias right at the pads.`,nets:[S],at:M[0]})}}return n}function Xa(e,t,n){if(t.kind==="through")return!0;let o=e.copper.indexOf(n),u=e.copper.indexOf(t.from),d=e.copper.indexOf(t.to);return o>=Math.min(u,d)&&o<=Math.max(u,d)}function Za(e,t){let{planeNet:n}=nt(e),o=[],u=new Map,d=s=>u.get(s)??u.set(s,e.zones.filter(r=>r.layer===s).flatMap(r=>r.polys)).get(s),i=(s,r)=>r.some(f=>_e(s,f)),a=At(e),l=Cn(e),p=e.parts.filter(jn).flatMap(s=>s.pads.map(r=>({at:r.at,r:Math.max(r.w,r.h)/2})));for(let s of Zn(t)){if(s.role.kind==="rf"||/reference clock/.test(s.role.label))continue;let r=e.tracks.filter(g=>s.nets.includes(g.net)),f=[...e.vias.filter(g=>s.nets.includes(g.net)).map(g=>({at:g.at,r:g.size/2})),...e.parts.flatMap(g=>g.pads).filter(g=>s.nets.includes(g.net)).map(g=>({at:g.at,r:Math.max(g.w,g.h)/2})),...p],c=g=>f.some($=>Math.abs($.at.x-g.x)<$.r+2&&Math.abs($.at.y-g.y)<$.r+2&&de($.at,g)<$.r+2),x=0,S,M="",b="",h=0,w=1/0;for(let g of r){let $=kn(e,n,g.layer);if(!$||!a[$]||!a[g.layer])continue;let y=Math.min(Math.abs(a[$].top-a[g.layer].bottom),Math.abs(a[g.layer].top-a[$].bottom));if(!(y>0))continue;let T=d($),E=bt(g),m=Math.max(1,Math.floor(E/.25)),C=E/m,k=(g.b.x-g.a.x)/(E||1),I=(g.b.y-g.a.y)/(E||1);for(let R=0;R<m;R++){let N={x:g.a.x+k*(R+.5)*C,y:g.a.y+I*(R+.5)*C};if(c(N)||l.some(U=>N.x>U.x0&&N.x<U.x1&&N.y>U.y0&&N.y<U.y1)||!i(N,T))continue;let A=g.w/2+y,L=U=>i({x:N.x-U*I*A,y:N.y+U*k*A},T);if(L(1)&&L(-1))continue;let H=A;for(let U=g.w/2+.05;U<A;U+=.05)if(!i({x:N.x-I*U,y:N.y+k*U},T)||!i({x:N.x+I*U,y:N.y-k*U},T)){H=U;break}x+=C,H-g.w/2<w&&(w=H-g.w/2,S=N,M=g.layer,b=$,h=y)}}if(x<3)continue;let v=e.stackupFrom==="assumed"?"info":s.role.rate>=1e9&&x>=5?"warn":"info";o.push({rule:"emc",severity:v,title:`${s.name}: ${x.toFixed(0)} mm along the edge of its reference plane`,detail:`On ${M} the trace runs within ${h.toFixed(2)} mm (the dielectric height to ${b}) of where the plane on ${b} ends, ${Math.max(0,w).toFixed(2)} mm from its edge at the closest. The return current spreads about that far to each side of the trace; where the plane ends inside it, the current crowds onto the edge, which radiates. Keep at least the dielectric height, and more where you can, between the trace and the plane edge or the board edge (UMR EMC Laboratory guideline).${e.stackupFrom==="assumed"?" The file has no stackup of its own, so the height is assumed.":""}`,nets:s.nets,layer:M,at:S})}return o}function Ya(e){let t=[],{planeNet:n}=nt(e),o=At(e),u=e.parts.flatMap(h=>h.pads.filter(w=>w.layers.includes("*.Cu")).map(w=>({at:w.at,net:w.net}))),d=e.parts.flatMap(h=>h.pads.filter(w=>!w.layers.includes("*.Cu"))),i=(h,w)=>e.zones.some(v=>v.layer!==w&&ue.test(B(v.net))&&v.polys.some(g=>Math.abs(Bn(g))>100))||e.copper.length>2&&Object.keys(n).some(v=>v!==w),a=h=>{let w=e.stackup.filter($=>$.kind==="dielectric"),v=w.length?w.reduce(($,y)=>$+y.er,0)/w.length:4.3,g=h===e.copper[0]||h===e.copper[e.copper.length-1];return 299.8/Math.sqrt(g?(v+1)/2:v)/20},l=new Map,p=0,s=0,r,f="",c=0,x,S="",M=0;for(let h of e.zones){if(!ue.test(B(h.net))||n[h.layer]&&e.copper.length>2&&n[h.layer]===h.net&&h.polys.length===1)continue;let w=a(h.layer);for(let v of h.polys){let g=Un(v),$=Math.hypot(g.x1-g.x0,g.y1-g.y0),y=Math.abs(Bn(v));if(y<4)continue;let T=[...e.vias.filter(R=>R.net===h.net&&Xa(e,R,h.layer)&&_e(R.at,v)).map(R=>R.at),...u.filter(R=>R.net===h.net&&_e(R.at,v)).map(R=>R.at)],E=d.filter(R=>R.net===h.net&&R.layers.includes(h.layer)&&_e(R.at,v)),m=!E.length&&e.tracks.some(R=>R.net===h.net&&R.layer===h.layer&&(_e(R.a,v)||_e(R.b,v)));if(!T.length&&!E.length&&!m){y>=25&&(p++,y>s&&(s=y,r={x:(g.x0+g.x1)/2,y:(g.y0+g.y1)/2},f=h.layer));continue}if(!i(h.net,h.layer))continue;if(T.length<=1&&$>w&&y>=50){c++,$>M&&(M=$,x=T[0]??E[0]?.at??{x:(g.x0+g.x1)/2,y:(g.y0+g.y1)/2},S=h.layer);continue}if(!T.length||n[h.layer])continue;let C=Math.max(.5,Math.sqrt(y/2500)),k=0,I=T[0];for(let R=g.x0+C/2;R<g.x1;R+=C)for(let N=g.y0+C/2;N<g.y1;N+=C){let A={x:R,y:N};if(!_e(A,v))continue;let L=1/0;for(let H of T){let U=(H.x-R)**2+(H.y-N)**2;U<L&&(L=U)}L>k&&(k=L,I=A)}if(k=Math.sqrt(k),k>w){let R=h.layer,N=l.get(R);!N||k>N.worst?l.set(R,{n:(N?.n??0)+1,worst:k,at:I,layer:h.layer,area:y}):N.n++}}}let b="a twentieth of a wavelength at 1 GHz, the top of CISPR 32's radiated-emission range for most boards";p&&t.push({rule:"emc",severity:"warn",title:`${p} ground pour ${p===1?"island has":"islands have"} no via or pin`,detail:`The largest, ${s.toFixed(0)} mm\xB2 on ${f}, is copper on a ground net with no via, pin or pad tying it to anything: floating copper picks up and re-radiates noise. Stitch it to the ground plane with vias, or let KiCad remove islands (zone properties).`,nets:[],layer:f,at:r}),c&&t.push({rule:"emc",severity:"warn",title:`${c} ground pour ${c===1?"piece is":"pieces are"} tied at one point only`,detail:`The longest, ${M.toFixed(0)} mm across on ${S}, has at most one via or through-hole pin to the ground on the other layers. Copper held at one point is a stub antenna once it is longer than ${b} (about ${a(S).toFixed(0)} mm here). Add stitching vias along it.`,nets:[],layer:S,at:x});for(let h of l.values())t.push({rule:"emc",severity:"info",title:`Ground pour on ${h.layer}: a point ${h.worst.toFixed(0)} mm from the nearest stitching via`,detail:`${h.n===1?"One piece of the pour":`${h.n} pieces of the pour`} on ${h.layer} ${h.n===1?"has":"have"} copper farther from a via to ground than ${b} (about ${a(h.layer).toFixed(0)} mm here). Between vias the pour can resonate; stitch it on a grid that spacing or finer, and along the board edge.`,nets:[],layer:h.layer,at:h.at});return t}function us(e){let{layers:t}=nt(e),n=new Map;return(o,u)=>{let d=`${o}|${Math.round(u/.025)}`;if(n.has(d))return n.get(d);let i=t.findIndex(p=>p.name===o),a=i>=0?Kt(t,i):null,l=NaN;if(a)try{let p=Vn({stack:a,w:Math.max(u,.05)*.001,t:t[i].t});l=p.z*Math.sqrt(p.eeff)/$n*.001*1e9}catch{}return n.set(d,l),l}}function ps(e,t,n,o){if(e.zones.some(r=>r.net===n.net&&r.layer===t&&r.polys.some(f=>_e(n.at,f))))return null;let u=Math.max(n.w,n.h)/2;if(e.vias.some(r=>r.net===n.net&&de(r.at,n.at)<=u+r.size/2))return null;let d=e.tracks.filter(r=>r.net===n.net&&r.layer===t),i=r=>d.filter(f=>de(f.a,r)<.02||de(f.b,r)<.02),a=r=>e.vias.some(f=>f.net===n.net&&de(f.at,r)<=f.size/2+.02)||!!o&&o.pads.some(f=>f.net===n.net&&de(f.at,r)<=Math.max(f.w,f.h)/2+.02),l=d.filter(r=>de(r.a,n.at)<=u+r.w/2||de(r.b,n.at)<=u+r.w/2);if(!l.length)return null;let p=new Map,s=[];for(let r of l)for(let[f,c]of[[r.a,r.b],[r.b,r.a]])de(f,n.at)<=u+r.w/2&&s.push({q:c,d:Math.max(0,bt(r)-u),w:r.w});for(;s.length;){s.sort((c,x)=>c.d-x.d);let r=s.shift(),f=`${r.q.x.toFixed(3)}|${r.q.y.toFixed(3)}`;if(!((p.get(f)??1/0)<=r.d)){if(p.set(f,r.d),a(r.q))return{d:r.d,w:r.w};if(r.d>15)return null;for(let c of i(r.q)){let x=de(c.a,r.q)<.02?c.b:c.a;s.push({q:x,d:r.d+bt(c),w:Math.min(r.w,c.w)})}}}return null}function Qa(e,t){let n=[],{layers:o,planeNet:u}=nt(e),d=new Set(t?[...t.pairs.filter(r=>r.role.rate>=1e9).flatMap(r=>[r.p,r.n]),...t.singles.map(r=>r.net)]:[]),i=e.parts.filter(r=>/^(U|IC)\d+/.test(r.ref)&&(r.pads.length>=49||r.pads.some(f=>d.has(f.net))));if(!i.length)return n;let a=e.parts.filter(r=>/^C\d+/.test(r.ref)&&r.pads.filter(f=>f.net).length===2&&r.pads.some(f=>ue.test(B(f.net)))&&r.pads.some(f=>Ge(B(f.net))&&!ue.test(B(f.net)))),l=us(e),p=[];for(let r of a){let f=r.pads.filter(b=>b.net),c=f.find(b=>!ue.test(B(b.net))),x=i.find(b=>b.pads.some(h=>h.net===c.net&&de(h.at,c.at)<6));if(!x)continue;let S=r.side==="B"?e.copper[e.copper.length-1]:e.copper[0],M=null;for(let b of f){let h=ps(e,S,b,b.net===c.net?x:void 0);if(!h||h.d<.3)continue;let w=l(S,h.w);if(!isFinite(w))continue;let v=w*h.d;(!M||v>M.nh)&&(M={ref:r.ref,ic:x.ref,net:c.net,nh:v,len:h.d,w:h.w,layer:S,at:b.at})}M&&M.nh>1&&p.push(M)}let s=new Map;for(let r of p)s.set(`${r.ic}|${r.net}`,[...s.get(`${r.ic}|${r.net}`)??[],r]);for(let r of s.values()){let f=r.reduce((c,x)=>x.nh>c.nh?x:c);n.push({rule:"pdn",severity:e.stackupFrom==="assumed"?"info":"warn",title:`${f.ic} ${B(f.net)}: ${f.ref} reaches its via through ${f.len.toFixed(1)} mm of trace (+${f.nh.toFixed(1)} nH)`,detail:`${r.length===1?f.ref:`${r.length} of its capacitors, worst ${f.ref},`} ${r.length===1?"connects":"connect"} to the plane through a trace: ${f.len.toFixed(1)} mm of ${f.w.toFixed(2)} mm on ${f.layer}, which the field solver puts at ${f.nh.toFixed(1)} nH. A whole capacitor mounting is 0.5 to 3.5 nH (Intel's PDN guide), so this trace alone can double the inductance between the capacitor and ${f.ic}, and it stops supplying fast current edges. Put the vias at the pads, or in them (TI's PDN guide), with short wide traces.${e.stackupFrom==="assumed"?" The file has no stackup of its own, so the height to the plane is assumed.":""}`,nets:[f.net],layer:f.layer,at:f.at})}return n}function qa(e){let t=[],{planeNet:n}=nt(e),o=At(e),u=Object.entries(n).filter(([,a])=>ue.test(B(a))).map(([a])=>a),d=a=>e.zones.filter(l=>l.layer===a&&ue.test(B(l.net))).flatMap(l=>l.polys),i=e.parts.filter(a=>/^(U|IC)\d+/.test(a.ref)&&a.pads.length>=100&&Xn(a.pads.map(l=>Math.max(l.w,l.h)))<=.8);for(let a of i){let l=new Map;for(let p of a.pads)p.net&&Ge(B(p.net))&&!ue.test(B(p.net))&&l.set(p.net,[...l.get(p.net)??[],p.at]);for(let[p,s]of l){if(s.length<4)continue;let r=s.reduce((b,h)=>b+h.x,0)/s.length,f=s.reduce((b,h)=>b+h.y,0)/s.length,c=e.copper.filter(b=>e.zones.some(h=>h.net===p&&h.layer===b&&(s.filter(w=>h.polys.some(v=>_e(w,v))).length*4>=s.length||h.polys.some(w=>_e({x:r,y:f},w)))));if(!c.length){s.length>=8&&t.push({rule:"pdn",severity:e.stackupFrom==="assumed"?"info":"warn",title:`${a.ref} ${B(p)}: ${s.length} balls fed by traces, no plane or pour`,detail:`${B(p)} reaches its ${s.length} balls on ${a.ref} (${a.value}) only through traces: no copper area of the rail spreads under the part. Traces are far more inductive than a plane or pour, and every capacitor then feeds the balls through them. Give the rail a pour under the part, on a layer right next to a ground plane.`,nets:[p],at:{x:r,y:f}});continue}let x=1/0,S="",M="";for(let b of c)if(o[b])for(let h of e.copper){if(h===b||!o[h]||!(u.includes(h)||d(h).some(g=>_e({x:r,y:f},g))))continue;let v=Math.min(Math.abs(o[h].top-o[b].bottom),Math.abs(o[b].top-o[h].bottom));v<x&&(x=v,S=b,M=h)}!isFinite(x)||x<=1||t.push({rule:"pdn",severity:e.stackupFrom==="assumed"?"info":"warn",title:`${a.ref} ${B(p)}: its copper is ${x.toFixed(2)} mm from the nearest ground`,detail:`${B(p)} spreads under ${a.ref} (${a.value}) on ${c.join(" and ")}; the nearest ground, ${M}, is ${x.toFixed(2)} mm from ${S}. The rail and its ground form a plane pair whose spreading inductance is \u03BC0\xB7h, ${(1.2566*x).toFixed(1)} nH per square here against about 0.1 to 0.2 nH for a rail on the layer right next to its ground, and every capacitor feeds the balls through it. Move the rail next to a ground plane: on four layers that usually means six, or a ground pour right beside it.${e.stackupFrom==="assumed"?" The file has no stackup of its own, so the spacing is assumed.":""}`,nets:[p],layer:S,at:{x:r,y:f}})}}return t}var rs=/ESD|TVS|TPD\d|PESD|USBLC|RCLAMP|SP0[0-9]|SP3\d{3}|PRTR|IP4\d{3}|SRV05|NUP\d|ECMF|ESDA|PUSB|SM712|SMAJ|SMBJ|SMF\d|LXES|AZ\d{4}|D3V3|TVS\d|ESD\d|CDSOD|PGB\d|ULC\d|SZESD|SEMTECH/i;function ei(e){let t=[],n=e.parts.filter(d=>/^(D|U|TVS|ESD|IC|Z)\d/i.test(d.ref)&&rs.test(`${d.lib} ${d.value}`)&&d.pads.some(i=>ue.test(B(i.net))));if(!n.length)return t;let o=us(e),u=d=>ue.test(B(d))||Ge(B(d));for(let d of n){let i=[...new Set(d.pads.map(s=>s.net).filter(s=>s&&!u(s)))],a=null;for(let s of i){let r=en(e,s,u,!0),f=1/0,c="",x=1/0,S="";for(let[M,b]of r){let[h,w]=M.split("|");if(h!==d.ref&&w!==d.ref)continue;let v=e.parts.find(g=>g.ref===(h===d.ref?w:h));v&&(jn(v)&&b<f?(f=b,c=v.ref):/^(U|IC)\d/i.test(v.ref)&&!rs.test(`${v.lib} ${v.value}`)&&b<x&&(x=b,S=v.ref))}!isFinite(f)||!isFinite(x)||f>2*x&&f>=10&&(!a||f-x>a.conn-a.ic)&&(a={net:s,conn:f,ic:x,cref:c,iref:S})}a&&t.push({rule:"esd",severity:"warn",title:`${d.ref}: ${a.conn.toFixed(0)} mm from ${a.cref}, ${a.ic.toFixed(0)} mm from ${a.iref}`,detail:`On ${B(a.net)} the protection diode ${d.ref} (${d.value}) is closer to the part it protects, ${a.iref}, than to the connector the strike comes in on, ${a.cref}. The strike then reaches ${a.iref} through a shorter path than through ${d.ref}, and the long trace to the connector radiates onto its neighbours. TI's ESD layout guide: place the TVS as near the connector as design rules allow, with the protected IC much farther from it.`,nets:[a.net],at:d.pads[0].at});let l=d.side==="B"?e.copper[e.copper.length-1]:e.copper[0],p=null;for(let s of d.pads.filter(r=>ue.test(B(r.net)))){let r=ps(e,l,s);if(!r||r.d<.3)continue;let f=o(l,r.w);isFinite(f)&&(!p||f*r.d>p.nh)&&(p={nh:f*r.d,d:r.d,w:r.w,at:s.at})}p&&p.nh>=1&&t.push({rule:"esd",severity:e.stackupFrom==="assumed"?"info":"warn",title:`${d.ref}: ${p.d.toFixed(1)} mm of trace to its ground via (+${p.nh.toFixed(1)} nH)`,detail:`${d.ref} (${d.value}) reaches ground through ${p.d.toFixed(1)} mm of ${p.w.toFixed(2)} mm trace on ${l}, ${p.nh.toFixed(1)} nH by the field solver. An IEC 61000-4-2 8 kV strike rises at about 30 A in 0.8 ns (TI), so that inductance adds about ${(p.nh*37.5).toFixed(0)} V to the diode's clamp voltage at the protected pin. Put a ground via at the diode's ground pad, or in it.${e.stackupFrom==="assumed"?" The file has no stackup of its own, so the height to the plane is assumed.":""}`,nets:[],layer:l,at:p.at})}return t}function ti(e){let t=[],n=/REG|LDO|BUCK|BOOST|DC-?DC|TPS[2567]\d|TLV7|LT[CM]?\d{4}|MP[1-9]\d{3}|AP\d{4}|RT\d{4}|SY8\d|LM[235]\d{3}|SIC\d|TX41\d\d|DRV\d|DRIVER|TPA\d|PAM\d|MAX98|TMC\d|A49\d{2}|\bL6\d{3}|MOSFET|FET|BRIDGE|CHARG|BQ\d|IP5\d{3}|TP4056|EFUSE|HOT.?SWAP/i,o=new Set(e.parts.filter(d=>/^L\d+/.test(d.ref)).flatMap(d=>d.pads.map(i=>i.net))),u=/CONN|SOCKET|HEADER|SODIMM|DIMM|USB|MICRO.?SD|SD.?CARD|SIM|HDMI|RJ45|JACK|MODULE|WROOM|WROVER|SHIELD|Bus_/i;for(let d of e.parts){if(d.pads.length<3||!/^(U|IC|Q|VR|PS)\d/i.test(d.ref)||u.test(`${d.lib} ${d.value}`))continue;let i=new Map;for(let m of d.pads)m.num&&m.layers.some(C=>C.endsWith(".Cu"))&&i.set(m.num,[...i.get(m.num)??[],m]);let a=[...i.values()],l=a.map(m=>m.reduce((C,k)=>C+k.w*k.h,0)),p=Xn(l),s,r=0;if(a.forEach((m,C)=>{l[C]>r&&(r=l[C],s=m)}),!s||r<2||r<4*p||i.size<3)continue;let f=s[0].net;if(!f||/^unconnected-/i.test(f))continue;let c=Math.min(...s.map(m=>m.at.x-m.w/2)),x=Math.max(...s.map(m=>m.at.x+m.w/2)),S=Math.min(...s.map(m=>m.at.y-m.h/2)),M=Math.max(...s.map(m=>m.at.y+m.h/2));if((x-c)*(M-S)>2.5*r)continue;let b=e.vias.filter(m=>m.at.x>c&&m.at.x<x&&m.at.y>S&&m.at.y<M&&(m.net===f||!m.net)).length+d.pads.filter(m=>m.layers.includes("*.Cu")&&m.num===s[0].num&&m.w*m.h<1).length,h=d.side==="B"?e.copper[e.copper.length-1]:e.copper[0],v=e.zones.some(m=>m.net===f&&m.layer===h&&m.polys.some(C=>_e({x:(c+x)/2,y:(S+M)/2},C)))?e.vias.filter(m=>m.net===f&&m.at.x>c-2&&m.at.x<x+2&&m.at.y>S-2&&m.at.y<M+2&&!(m.at.x>c&&m.at.x<x&&m.at.y>S&&m.at.y<M)).length:0,g=b+v/2,$=Math.min(16,Math.max(1,Math.floor(x-c)*Math.floor(M-S))),y=n.test(`${d.value} ${d.lib}`)||d.pads.some(m=>m.net&&o.has(m.net)&&/(^|[-_(])(SW|LX|PHASE)\d?([-_)]|$)/i.test(B(m.net))),T=`${(x-c).toFixed(1)} \xD7 ${(M-S).toFixed(1)} mm`,E={x:(c+x)/2,y:(S+M)/2};y&&g<$/2?t.push({rule:"thermal",severity:"warn",title:`${d.ref}: ${b} ${b===1?"via":"vias"} under its ${T} exposed pad`,detail:`${d.ref} (${d.value}) sheds its heat through its exposed pad, and the pad reaches the inner and bottom copper only through vias. TI's QFN/SON attachment note puts thermal vias on a pitch of about 1.0 mm with 0.3 mm drills: about ${$} here${v?`; the ${v} vias in the pour around the pad count for half`:""}. With fewer the part runs hotter than its datasheet's thermal resistance, which assumes the full array.`,nets:[f],layer:h,at:E}):!y&&b===0&&!v&&r>=4&&t.push({rule:"thermal",severity:"info",title:`${d.ref}: no vias under its ${T} exposed pad`,detail:`${d.ref} (${d.value}) has an exposed pad with no via to the copper below, and none in a pour around it. If the part dissipates more than a little, give it the via array its datasheet shows (TI's QFN/SON note: about 1.0 mm pitch, 0.3 mm drills).`,nets:[f],layer:h,at:E})}return t}function ni(e){let t=B(e).toUpperCase().replace(/^(DDR\d?|LPDDR\d?|MEM|DRAM|SDRAM|M\d?)_?/,""),n=t.match(/(?:^|_)DQ_?(\d+)$/)??t.match(/(?:^|_)D(\d+)$/);return n&&!/DQS/.test(t)?{kind:"dq",i:Number(n[1])}:(n=t.match(/(?:^|_)(?:DM|DQM|DMI|DBI)_?(\d*)[LU]?$/),n?{kind:"dm",i:n[1]?Number(n[1]):/U$/.test(t)?1:0}:/(?:^|_)(A\d+|BA\d|BG\d|CA\d+|CS\d?(_?N)?|CS_?N\d?|RAS(_?N)?|CAS(_?N)?|WE(_?N)?|CKE\d?|ODT\d?|ACT(_?N)?|PAR(ITY)?)$/.test(t)?{kind:"ca",i:0}:null)}function ri(e,t){let n=[],o=e.parts.filter(f=>f.pads.length>=60&&!/^(J|P|CN|X|CON)\d/i.test(f.ref)&&!/DIMM|SOCKET|Bus_|CONN/i.test(f.lib)&&/DDR[34]|LPDDR|SDRAM|MT4[01]K|MT40A|MT53|AS4C\d+M\d+D[34]|K4[AB]\d|H5(TQ|AN)|NT5(CC|AD)|IS4[36](TR|QR)|W63|W97/i.test(`${f.lib} ${f.value}`));if(!o.length)return n;let{layers:u}=nt(e),d=f=>ue.test(B(f))||Ge(B(f)),i=new Map,a=(f,c)=>{if(i.has(f))return i.get(f);let x=u.findIndex(b=>b.name===f),S=x>=0?Kt(u,x):null,M=3.6;if(S)try{M=Vn({stack:S,w:c*.001,t:u[x].t}).eeff}catch{}return i.set(f,M),M},l=f=>{let c=e.tracks.filter(S=>S.net===f),x=c.reduce((S,M)=>S+Mn(M),0);return x?c.reduce((S,M)=>S+Mn(M)*Math.sqrt(a(M.layer,M.w)),0)/x/$n*1e9:Math.sqrt(3.6)/$n*1e9},p=f=>{let c=e.parts.find(x=>x.ref===f);return!!c&&/^(U|IC)\d/i.test(f)&&!o.includes(c)&&c.pads.length>=60},s=(f,c)=>{let x=en(e,f,d),S=1/0;for(let[M,b]of x){let[h,w]=M.split("|");(h===c&&p(w)||w===c&&p(h))&&(S=Math.min(S,b))}return isFinite(S)?S*l(f):NaN},r=t.pairs.filter(f=>f.role.kind==="ddr"||/DQS|CK|CLK/i.test(B(f.p)));for(let f of o){let c=[...new Set(f.pads.map(g=>g.net))].filter(g=>g&&f.pads.filter($=>$.net===g).length===1),x=r.filter(g=>/DQS/i.test(B(g.p))&&f.pads.some($=>$.net===g.p)).sort((g,$)=>B(g.p).localeCompare(B($.p),void 0,{numeric:!0})),S=r.find(g=>/(^|_)(CK|CLK)(_?T|0|_?P)?([^A-Z]|$)/i.test(B(g.p))&&!/DQS/i.test(B(g.p))&&f.pads.some($=>$.net===g.p)),M=c.map(g=>({n:g,r:ni(g)})).filter(g=>g.r),b=M.filter(g=>g.r.kind==="dq").sort((g,$)=>g.r.i-$.r.i),h=new Map;for(let g of b)h.set(Math.floor(g.r.i/8),[...h.get(Math.floor(g.r.i/8))??[],g.n]);let w=[...h.entries()].sort((g,$)=>g[0]-$[0]),v=M.filter(g=>g.r.kind==="dm").sort((g,$)=>B(g.n).localeCompare(B($.n),void 0,{numeric:!0}));if(w.length&&w.length===x.length&&w.forEach(([g,$],y)=>{let T=x[y],E=s(T.p,f.ref);if(!isFinite(E))return;let m=[...$,...v[y]?[v[y].n]:[]],C=0,k="";for(let R of m){let N=s(R,f.ref);isFinite(N)&&Math.abs(N-E)>Math.abs(C)&&(C=N-E,k=R)}if(!k)return;let I=Math.abs(C)>100?"fail":Math.abs(C)>20?"warn":"pass";n.push({rule:"ddr",severity:I,title:`${f.ref} byte ${g}: ${B(k)} ${C>=0?"+":""}${C.toFixed(0)} ps from ${B(T.p).replace(/_?(P|T|\+)$/,"")}`,detail:`The worst of ${m.length} data and mask lines in the byte against its strobe, in time (\u221A\u03B5eff of each layer from the field solver, via barrels included): ${(C/l(k)).toFixed(1)} mm of difference. ${I==="pass"?"Within 20 ps (Micron and Intel for DDR3).":I==="warn"?"Over 20 ps, the DDR3 limit from Micron and Intel.":"Over 100 ps, past even a controller with per-bit deskew (AMD Versal: \xB1100 ps)."} Controllers differ a lot: Intel's DDR4 guide asks for \xB13.5 ps and TI's AM62x for 2 ps, so match to your controller's own guide.`,nets:[k,T.p,T.n],at:f.pads.find(R=>R.net===k)?.at})}),S){let g=s(S.p,f.ref);if(isFinite(g)){let $=0,y="",T=0;for(let E of M.filter(m=>m.r.kind==="ca")){let m=s(E.n,f.ref);isFinite(m)&&(T++,Math.abs(m-g)>Math.abs($)&&($=m-g,y=E.n))}if(y){let E=Math.abs($)>100?"fail":Math.abs($)>20?"warn":"pass";n.push({rule:"ddr",severity:E,title:`${f.ref} address/command: ${B(y)} ${$>=0?"+":""}${$.toFixed(0)} ps from ${B(S.p).replace(/_?(P|T|\+)$/,"")}`,detail:`The worst of ${T} address, command and control lines against the clock at ${f.ref}, from the controller, in time: ${($/l(y)).toFixed(1)} mm of difference. ${E==="pass"?"Within \xB120 ps (Intel's DDR3 and DDR4 guides).":`Over ${E==="fail"?"100":"20"} ps; Intel's DDR3 and DDR4 guides ask for \xB120 ps to each chip.`} Your controller's guide may be tighter (TI's AM62x: 3 ps).`,nets:[y,S.p,S.n],at:f.pads.find(m=>m.net===y)?.at})}}}}return n}function Mn(e){if(!e.mid)return bt(e);let{a:t,mid:n,b:o}=e,u=2*(t.x*(n.y-o.y)+n.x*(o.y-t.y)+o.x*(t.y-n.y));if(Math.abs(u)<1e-12)return bt(e);let d=((t.x**2+t.y**2)*(n.y-o.y)+(n.x**2+n.y**2)*(o.y-t.y)+(o.x**2+o.y**2)*(t.y-n.y))/u,i=((t.x**2+t.y**2)*(o.x-n.x)+(n.x**2+n.y**2)*(t.x-o.x)+(o.x**2+o.y**2)*(n.x-t.x))/u,a=Math.hypot(t.x-d,t.y-i),l=f=>Math.atan2(f.y-i,f.x-d),p=f=>(f%(2*Math.PI)+2*Math.PI)%(2*Math.PI),s=p(l(o)-l(t)),r=p(l(n)-l(t));return a*(r<=s?s:2*Math.PI-s)}var oi={usb2:{mm:1.27,from:"TI's layout guideline of 50 mil"},usb3:{mm:.127,from:"TI's layout guideline of 5 mil"},pcie:{mm:.127,from:"TI's layout guideline of 5 mil"},sata:{mm:.127,from:"TI's layout guideline of 5 mil"},hdmi:{mm:.127,from:"TI's layout guideline of 5 mil"},dp:{mm:.127,from:"TI's layout guideline of 5 mil"},ethernet:{mm:1.27,from:"the usual 50 mil of Ethernet PHY layout guides"},lvds:{mm:.254,from:"the usual 10 mil of LVDS layout guides"},mipi:{mm:.254,from:"the usual 10 mil of MIPI layout guides"}};function si(e,t){let n=[],o=e.stackup.filter(c=>c.kind==="dielectric"),u=o.reduce((c,x)=>c+x.er*x.t,0)/Math.max(o.reduce((c,x)=>c+x.t,0),1e-12)||4.2,d=Math.sqrt(u*.85)/.2998,i=c=>e.tracks.filter(x=>x.net===c).reduce((x,S)=>x+Mn(S),0),a=c=>!c||ue.test(B(c))||Ge(B(c)),l=new Map;for(let c of e.parts)for(let x of c.pads)x.net&&l.set(x.net,(l.get(x.net)??0)+1);let p=At(e),s=c=>{let x=p[c];return x?(x.top+x.bottom)/2:0},r=c=>e.vias.filter(x=>x.net===c).reduce((x,S)=>{let M=Jn(e,S);return x+(M.length>=2?Math.abs(s(M[M.length-1])-s(M[0])):0)},0),f=c=>{let x=i(c.p)+r(c.p),S=i(c.n)+r(c.n);if((l.get(c.p)??0)<=2&&(l.get(c.n)??0)<=2)return[x,S];let M=en(e,c.p,a,!0),b=en(e,c.n,a,!0),h=[...M.keys()].filter($=>b.has($));if(!h.length)return[x,S];let w=h.sort(($,y)=>M.get(y)+b.get(y)-M.get($)-b.get($))[0],v=M.get(w),g=b.get(w);return v>=.5*x&&g>=.5*S?[v,g]:[x,S]};for(let c of t.pairs){let x=oi[c.role.kind];if(!x)continue;let[S,M]=f(c);if(S<5||M<5)continue;let b=Math.abs(S-M),h=S>M?c.p:c.n,w=b*d,v=1e12/c.role.rate,g=b>10*x.mm&&w>.05*v?"fail":b>x.mm?yt(c.role)?"info":"warn":"pass",$=y=>y<1?y.toFixed(3):y.toFixed(2);n.push({rule:"length",severity:g,title:g==="pass"?`${c.name}: halves matched within ${$(b)} mm`:`${c.name}: halves differ by ${$(b)} mm`,detail:`${B(c.p)} runs ${S.toFixed(2)} mm and ${B(c.n)} ${M.toFixed(2)} mm, ${$(b)} mm apart (about ${w.toFixed(1)} ps). The limit for ${yt(c.role)?"USB 2.0 high speed":c.role.label} is ${$(x.mm)} mm, from ${x.from}.${g==="info"&&yt(c.role)?Fr:g==="pass"?"":` Lengthen ${B(h===c.p?c.n:c.p)} with a small serpentine near the end where the two halves part, so the difference does not travel along the pair.`}`,nets:[c.p,c.n]})}return n}var fs=/^(R|RN|RA|RP|C|CN|L|FB|FL|CMC)\d/i,ai=e=>/^(D|TVS|ESD|TP)\d/i.test(e.ref)||/ESD|TVS|TPD\d/i.test(`${e.lib} ${e.value}`),Wn=e=>/(_?P|\+|_?p)$/.test(B(e))?"p":/(_?N|-|_?n)$/.test(B(e))?"n":"";function en(e,t,n,o=!1){let u=At(e),d=x=>{let S=u[x];return S?(S.top+S.bottom)/2:0},i=new Map,a=(x,S,M)=>{x!==S&&((i.get(x)??i.set(x,[]).get(x)).push([S,M]),(i.get(S)??i.set(S,[]).get(S)).push([x,M]))},l=(x,S)=>`${x}|${Math.round(S.x*1e3)}|${Math.round(S.y*1e3)}`,p=[],s=new Set([t]),r=[t],f=new Map(e.parts.map(x=>[x.ref,x]));for(;r.length&&s.size<=8;){let x=r.shift(),S=e.tracks.filter(b=>b.net===x),M=[];for(let b of S)a(l(b.layer,b.a),l(b.layer,b.b),Mn(b)),M.push({l:b.layer,q:b.a,w:b.w},{l:b.layer,q:b.b,w:b.w});for(let b of M)for(let h of S){if(h.layer!==b.l||h.mid)continue;let w=h.b.x-h.a.x,v=h.b.y-h.a.y,g=w*w+v*v;if(g<1e-9)continue;let $=((b.q.x-h.a.x)*w+(b.q.y-h.a.y)*v)/g;if($<=.001||$>=1-.001||Math.hypot(h.a.x+$*w-b.q.x,h.a.y+$*v-b.q.y)>h.w/2)continue;let y=Math.sqrt(g);a(l(b.l,b.q),l(h.layer,h.a),$*y),a(l(b.l,b.q),l(h.layer,h.b),(1-$)*y)}e.vias.forEach((b,h)=>{if(b.net!==x)return;let w=y=>de(y.q,b.at)<=b.size/2+y.w/2+.001,v=e.copper.indexOf(b.from),g=e.copper.indexOf(b.to),$=v<0||g<0?e.copper:e.copper.slice(Math.min(v,g),Math.max(v,g)+1);for(let y of M)$.includes(y.l)&&w(y)&&a(l(y.l,y.q),`V${h}|${y.l}`,de(y.q,b.at));for(let y=1;y<$.length;y++)a(`V${h}|${$[y-1]}`,`V${h}|${$[y]}`,Math.abs(d($[y])-d($[y-1])))});for(let b of e.parts)for(let h of b.pads){if(h.net!==x)continue;let w=`P|${b.ref}|${h.num}`,v=Math.max(h.w,h.h)/2+.001,g=T=>h.layers.includes(T)||h.layers.includes("*.Cu");for(let T of M)g(T.l)&&de(T.q,h.at)<=v+T.w/2&&a(w,l(T.l,T.q),0);if(e.vias.forEach((T,E)=>{if(T.net===x&&de(T.at,h.at)<=v+T.size/2)for(let m of e.copper)g(m)&&i.has(`V${E}|${m}`)&&a(w,`V${E}|${m}`,de(T.at,h.at))}),o){b.pads.filter(T=>T.net===x).length===1&&p.push({node:w,ref:b.ref});continue}if(!fs.test(b.ref)){ai(b)||p.push({node:w,ref:b.ref});continue}let $=b.pads.filter(T=>T!==h&&T.net&&T.net!==x&&!n(T.net)),y=b.pads.length===2?$[0]:void 0;if(!y&&b.pads.length>2){let T=$.filter(m=>Wn(m.net)===Wn(x)&&!s.has(m.net)),E=b.pads.find(m=>Number(m.num)===b.pads.length+1-Number(h.num));y=T.length===1?T[0]:E&&$.includes(E)?E:void 0}y&&(a(w,`P|${b.ref}|${y.num}`,de(h.at,y.at)),s.has(y.net)||(s.add(y.net),r.push(y.net)))}}let c=new Map;for(let x of p){let S=new Map([[x.node,0]]),M=new Set;for(;;){let b,h=1/0;for(let[w,v]of S)!M.has(w)&&v<h&&(b=w,h=v);if(b===void 0)break;M.add(b);for(let[w,v]of i.get(b)??[])h+v<(S.get(w)??1/0)&&S.set(w,h+v)}for(let b of p){if(b.ref===x.ref||!S.has(b.node))continue;let h=[x.ref,b.ref].sort().join("|");c.set(h,Math.min(c.get(h)??1/0,S.get(b.node)))}}return c}function ii(e){let t=B(e.p).replace(/(_?P|\+|_?p)$/,""),n=e.p.includes("/")?e.p.slice(0,e.p.lastIndexOf("/")+1):"",o=t.split(/[_.\s-]+/),u=r=>/^((TX|RX)D?|(TX|RX)?(D|DATA|DAT|LANE|LN|CH))\d{1,2}$/i.test(r),d=/^(TX|RX)?(CLK|CK|CLOCK|C)$/i,i=r=>{let f=d.exec(r);return!!f&&(f[2].toUpperCase()!=="C"||!!f[1]||!o.some(c=>u(c)||c!==r&&d.test(c)))},a,l=!1,p="",s=[];if(o.forEach(r=>{let f=u(r);if(!f&&!i(r)){s.push(r.toUpperCase());return}a=r,l=!f,p=/^(TX|RX)/i.exec(r)?.[1].toUpperCase()??p,!f&&/^(TX|RX)$/i.test(s[s.length-1]??"")&&(p=s.pop().toUpperCase()),s.push("#")}),!!a)return{bus:n+s.join("_"),lane:a,clock:l,dir:p}}var os={mipi:{mm:1.27,from:"the loosest of the vendor guides, Intel's \xB150 mil (TI and Microchip ask for 25 and 20 mil)",fails:!0},lvds:{ps:40,from:"the \xB140 ps inter-lane skew of TI's FPD-Link inputs (DLPC7540)",fails:!0},hdmi:{mm:3,from:"ADI's HDMI layout guideline of \xB13 mm",fails:!1}};function ci(e,t){let n=[],o=s=>!s||ue.test(B(s))||Ge(B(s)),u=e.stackup.filter(s=>s.kind==="dielectric"),d=u.reduce((s,r)=>s+r.er*r.t,0)/Math.max(u.reduce((s,r)=>s+r.t,0),1e-12)||4.2,i=Math.sqrt(d*.85)/.2998,a=new Map;for(let s of t.pairs){if(!os[s.role.kind])continue;let r=ii(s);if(!r)continue;let f=`${s.role.kind}|${r.bus}`;a.set(f,[...a.get(f)??[],{pair:s,lane:r.lane,clock:r.clock,dir:r.dir}])}for(let[s,r]of[...a]){let f=[...new Set(r.map(c=>c.dir).filter(Boolean))];if(!(f.length<2)){a.delete(s);for(let c of f)a.set(`${s}|${c}`,r.filter(x=>!x.dir||x.dir===c))}}let l=[],p=[...a.values()].filter(s=>s.length>=2).sort((s,r)=>Number(r.some(f=>f.clock))-Number(s.some(f=>f.clock))||r.length-s.length);for(let s of p){let r=s.map(A=>{let L=en(e,A.pair.p,o),H=en(e,A.pair.n,o),U=new Map;for(let[P,F]of L){let V=H.get(P);V!==void 0&&U.set(P,(F+V)/2)}return{...A,len:U}}),f=[...r[0].len.keys()].filter(A=>r.every(L=>L.len.has(A)));if(!f.length)continue;let c=A=>r.reduce((L,H)=>L+H.len.get(A),0)/r.length,x=f.sort((A,L)=>c(L)-c(A))[0];if(c(x)<5)continue;let S=new Set(s.flatMap(A=>[A.pair.p,A.pair.n]));if(l.some(A=>[...S].every(L=>A.has(L))))continue;let M=s[0].pair.role.kind,b=os[M],h=s[0].pair.role.rate,w=r.find(A=>A.clock),v=w?w.len.get(x):Math.min(...r.map(A=>A.len.get(x))),$=r.filter(A=>A!==w).reduce((A,L)=>Math.abs(L.len.get(x)-v)>Math.abs(A.len.get(x)-v)?L:A),y=Math.abs($.len.get(x)-v),T=y*i,E=1e12/h,m=b.mm??b.ps/i,C=y<=m?"pass":b.fails&&w&&T>.1*E?"fail":"warn",[k,I]=x.split("|"),R=r.map(A=>`${A.lane} ${A.len.get(x).toFixed(2)}`).join(", "),N=w?`its clock ${w.lane}`:"the shortest lane";l.push(new Set([...S,...r.flatMap(A=>[...ss(e,A.pair.p,o),...ss(e,A.pair.n,o)])])),n.push({rule:"skew",severity:C,title:C==="pass"?`${li($.pair,$.lane)}: ${r.length} lanes matched within ${y.toFixed(2)} mm`:`${$.pair.name}: ${y.toFixed(2)} mm ${$.len.get(x)>v?"longer":"shorter"} than ${N}`,detail:`From ${k} to ${I}, in mm: ${R}. ${$.lane} is ${y.toFixed(2)} mm (about ${T.toFixed(0)} ps) off ${N}; the limit for ${s[0].pair.role.label} is ${m.toFixed(2)} mm, from ${b.from}.${C==="fail"?` That is more than a tenth of a ${E.toFixed(0)} ps bit at ${(h/1e9).toFixed(1)} Gb/s, which the receiver's setup and hold margin cannot absorb.`:""}${C==="pass"?"":` Add a serpentine to the shorter ${w?"one":"lanes"} so the lanes arrive together.${w?"":" No clock lane was found in the names, so this compares the data lanes with each other."}`}`,nets:[...S]})}return n}function li(e,t){let n=e.name.lastIndexOf(t),o=(n<0?e.name:e.name.slice(0,n)+e.name.slice(n+t.length)).replace(/(_?P\/N|±|\+|_?P)$/,"").replace(/[_.]{2,}/g,"_").replace(/[_.]+$/,"");return o&&!o.endsWith("/")?o:`${e.role.label} bus`}function ss(e,t,n){let o=new Set([t]),u=[t];for(;u.length&&o.size<=8;){let d=u.shift();for(let i of e.parts)if(fs.test(i.ref)){for(let a of i.pads)if(a.net===d)for(let l of i.pads)l.net&&!n(l.net)&&!o.has(l.net)&&(i.pads.length===2||Wn(l.net)===Wn(d))&&(o.add(l.net),u.push(l.net))}}return[...o]}function as(e){let t=e.replace(/µ/g,"u"),n=/(\d*[.,]?\d+)\s*([pnu])\s*(\d*)/i.exec(t);return n?+(n[1].replace(",",".")+(n[3]&&!/[.,]/.test(n[1])?`.${n[3]}`:""))*{p:.001,n:1,u:1e3}[n[2].toLowerCase()]:void 0}var is=e=>/(?:^|[^0-9])(01005|0201|0402|0603|0805|1206|1210)(?:[^0-9]|$)/.exec(e)?.[1],xn=["01005","0201","0402","0603","0805","1206","1210"],di={usb3:{lo:75,hi:265,from:"the USB 3 specification (75 to 265 nF)"},sata:{lo:0,hi:12,from:"the SATA and SAS specifications (12 nF at most)"}};function ui(e,t){let n=[],o=l=>!l||ue.test(B(l))||Ge(B(l)),u=l=>e.parts.filter(p=>/^C\d/i.test(p.ref)&&p.pads.length===2&&p.pads.some(s=>s.net===l)&&p.pads.every(s=>s.net&&!o(s.net))&&p.pads[0].net!==p.pads[1].net),d=l=>e.tracks.filter(p=>p.net===l).reduce((p,s)=>p+Mn(s),0),i=new Set;for(let l of t.pairs.filter(p=>p.role.rate>=1e9&&!/(^|[^A-Z])(AUX|SBU)/i.test(B(p.p)))){let p=u(l.p),s=u(l.n);if(!p.length||!s.length)continue;let r=p[0],f=s.find(N=>!p.includes(N))??s[0];if(r===f||i.has(r.ref)||i.has(f.ref))continue;i.add(r.ref),i.add(f.ref);let c=[],x=l.role.rate>=5e9&&l.role.kind!=="pair",S=[is(r.lib),is(f.lib)],M=S.map(N=>N?xn.indexOf(N):-1).reduce((N,A)=>Math.max(N,A),-1);M>xn.indexOf("0603")?c.push({sev:x?"fail":"warn",short:`AC capacitors are ${xn[M]}`,text:`They are ${xn[M]}: TI allows 0603 at most on these lanes and strongly recommends 0402 or smaller, because a bigger pad is a bigger capacitive dip in the impedance.`}):M===xn.indexOf("0603")&&c.push({sev:l.role.rate>=8e9?"warn":"info",short:"AC capacitors are 0603",text:"They are 0603, the largest size TI allows on these lanes; it strongly recommends 0402 or smaller, whose pads disturb the impedance less."}),S[0]&&S[1]&&S[0]!==S[1]&&c.push({sev:"warn",short:"AC capacitors of two sizes",text:`${r.ref} is ${S[0]} and ${f.ref} ${S[1]}: use the same size on both halves, so they see the same discontinuity.`});let b=N=>{let A=N.pads[1].at.x-N.pads[0].at.x,L=N.pads[1].at.y-N.pads[0].at.y,H=Math.hypot(A,L)||1;return{x:A/H,y:L/H,L:H}},h=b(r),w=b(f),v=Math.abs((f.at.x-r.at.x)*h.x+(f.at.y-r.at.y)*h.y),g=Math.abs(h.x*w.x+h.y*w.y)>.94;r.side!==f.side?c.push({sev:"warn",short:"AC capacitors on opposite sides",text:`${r.ref} and ${f.ref} are on opposite sides of the board: put both halves' capacitors side by side on one side, so the halves stay symmetric.`}):(!g||v>Math.max(.3,h.L/2))&&c.push({sev:l.role.rate>=25e8&&l.role.kind!=="pair"?"warn":"info",short:"AC capacitors not side by side",text:`${r.ref} and ${f.ref} are ${g?`${v.toFixed(2)} mm apart along the route`:"turned to different angles"}, not side by side: place them next to each other, pads aligned, with symmetric fan-in and fan-out (TI, Intel).`});let $=d(r.pads[0].net),y=d(r.pads[1].net),T=$+y;if(T>0&&Math.min($,y)>10&&Math.min($,y)>.25*T&&c.push({sev:l.role.rate>=8e9?"warn":"info",short:"AC capacitors in the middle of the route",text:`${r.ref} sits ${Math.min($,y).toFixed(0)} mm from the nearer end of a ${T.toFixed(0)} mm route: Intel asks for AC capacitors at the device end or the connector end, not in the middle of the routing.`}),l.role.rate>=8e9){let N=r.side==="F"?1:e.copper.length-2,A=e.copper[N],L=U=>U.pads.reduce((P,F)=>{let V=[-.35,0,.35].flatMap(O=>[-.35,0,.35].map(G=>({x:F.at.x+O*F.w,y:F.at.y+G*F.h})));return P+V.filter(O=>e.zones.some(G=>G.layer===A&&G.polys.some(J=>_e(O,J)))).length/V.length},0)/U.pads.length,H=(L(r)+L(f))/2;A&&e.copper.length>2&&H>.5&&c.push({sev:"info",short:"Plane not voided under the AC capacitor pads",text:`The ${A} copper runs solid under ${r.ref} and ${f.ref}'s pads: TI recommends voiding the reference plane under them at these speeds, so the wide pads do not dip the impedance.`})}let E=[as(r.value),as(f.value)],m=/CLK/i.test(l.name),C=/GEN_?[1-6](?![0-9])/i.test(`${l.name} ${l.p}`),k=m?void 0:l.role.kind==="pcie"?{lo:75,hi:265,from:"the PCIe specification (75 to 265 nF)"}:di[l.role.kind];for(let[N,A]of[[r,E[0]],[f,E[1]]])!k||A===void 0||(A<k.lo||A>k.hi?c.push({sev:"warn",short:"AC capacitor value outside the specification",text:`${N.ref} is ${N.value}, outside ${k.from}.`}):l.role.kind==="pcie"&&A<176&&(l.role.rate>=8e9||!C)&&c.push({sev:C?"warn":"info",short:`${Math.round(A)} nF AC capacitors: PCIe Gen 1 and 2 only`,text:`${N.ref} is ${N.value}: right for PCIe Gen 1 and 2, but Gen 3 and later ask 176 to 265 nF (220 nF suits every generation).`}));E[0]!==void 0&&E[1]!==void 0&&Math.abs(E[0]-E[1])>.01*Math.max(E[0],E[1])&&c.push({sev:"warn",short:"AC capacitors of different values",text:`${r.ref} is ${r.value} and ${f.ref} ${f.value}: the two halves need the same value.`});let I={pass:0,info:1,warn:2,fail:3},R=c.reduce((N,A)=>I[A.sev]>I[N]?A.sev:N,"pass");n.push({rule:"accap",severity:R,title:R==="pass"?`${l.name}: ${r.ref} and ${f.ref} side by side${S[0]?`, ${S[0]}`:""}`:`${l.name}: ${c.find(N=>N.sev===R).short}`,detail:R==="pass"?`${r.ref} and ${f.ref}${r.value!=="x"?` (${r.value})`:""} are the same size, side by side and near one end of the route${k?`, with a value inside ${k.from}`:""}.`:[...new Set(c.map(N=>N.short))].map(N=>c.find(A=>A.short===N).text).join(" "),nets:[l.p,l.n],at:r.at})}let a=new Map;for(let l of n)if(l.severity!=="pass"){let p=`${l.severity}|${l.title.slice(l.title.indexOf(": ")+2)}`;a.set(p,[...a.get(p)??[],l])}for(let[l,p]of a){if(p.length<3)continue;for(let r of p)n.splice(n.indexOf(r),1);let s=p.map(r=>r.title.slice(0,r.title.indexOf(": ")));n.push({...p[0],title:`${p.length} pairs: ${l.split("|")[1]}`,detail:`${s.slice(0,4).join(", ")}${s.length>4?` and ${s.length-4} more`:""}. ${p[0].detail}`,nets:p.flatMap(r=>r.nets)})}return n}function pi(e,t,n,o){let u=e/t,d=n/t;return o?1.015*Math.max(.3,1+1.138*(d-1))*Math.exp(-1.341*u):.584*Math.max(.3,1+.555*(d-1))/(1+u*u)**1.088}var fi=/(^|_|~|\{)(N?EN|ENABLE|PWR_?EN|WAKE|N?RST|RESET|PRSNT|PRESENT|ALERT|INT|IRQ|LED|PG|PGOOD|PWRGD|ADDR|SEL|DET|DETECT|HPD|CEC|SDA|SCL|I2C|SMB|SMBUS|ALERT|BOOT|STRAP|CFG|MODE|GPIO|BTN|KEY|SW|OE|WP|CD|FAULT|OC|VBUS|ID)\d*(_?N|#|\})?(_|$)/i,hi=new Map;function mi(e,t){let n=[],{planeNet:o}=nt(e),u=At(e),d=y=>!y||ue.test(B(y))||Ge(B(y)),i=new Map;for(let y of t.pairs)i.set(y.p,{id:y.name,sign:1,pair:y}),i.set(y.n,{id:y.name,sign:-1,pair:y});let a=y=>{let T=y.name.toUpperCase();if(/C2M/.test(T))return"c2m";if(/M2C/.test(T))return"m2c";if(/(^|[^A-Z])(SS)?TX|PET[PN]?\d|(^|[^A-Z])TD([^A-Z]|$)/.test(T))return"tx";if(/(^|[^A-Z])(SS)?RX|PER[PN]?\d|(^|[^A-Z])RD([^A-Z]|$)/.test(T))return"rx";if(y.role.kind==="mipi")return/DSI/.test(T)?"dsi":/CSI|CAM/.test(T)?"csi":void 0;if(y.role.kind==="hdmi"||y.role.kind==="dp")return/IN([^A-Z]|$)/.test(T)?void 0:"out"},l=(y,T)=>{let E=a(T);return!!E&&E===a(y)&&y.role.kind===T.role.kind},p={tx:"rx",rx:"tx",c2m:"m2c",m2c:"c2m"},s=(y,T)=>{let E=a(y),m=a(T);return!!E&&!!m&&p[E]===m},r=[.5,1,2,4],f=hi,c=new Map,{layers:x}=nt(e),S=(y,T,E,m)=>{let C=Math.max(.05,Math.round(T/.025)*.025),k=`${y}|${C}|${E}`,I=c.get(k);I||(I=M(y,C,E),c.set(k,I));let R=Math.max(r[0],m/E);if(R>6)return 0;let N=r.findIndex(P=>P>=R);N<=0&&(N=N===0?1:r.length-1);let A=r[N-1],L=r[N],H=Math.log(I[N-1]),U=Math.log(I[N]);return Math.exp(H+(U-H)*(R-A)/(L-A))};function M(y,T,E){let m=x.findIndex(L=>L.name===y),C=m>=0?Kt(x,m):null,k=y===e.copper[0]?e.mask.F:e.mask.B,I=k?{t:k.t*.001,tBase:2*k.t*.001,er:k.er,tanD:.025}:void 0,R=C?(({names:L,...H})=>H)(C):null,N=`${T}|${E.toFixed(4)}|${m>=0?x[m].t:0}|${JSON.stringify(R)}|${JSON.stringify(I??null)}`,A=f.get(N);return A||(A=r.map(L=>{if(!C)return 0;let H=cn({stack:C,w:T*.001,t:x[m].t,s:L*E*.001,mask:I}).g;return Math.max(1e-6,(Math.sqrt(an(H,"even").eeff)-Math.sqrt(an(H,"odd").eeff))/.299792458)}),f.set(N,A)),A}let b=2,h=new Map,w=e.tracks.filter(y=>!d(y.net)).flatMap(qt);for(let y of w)for(let T=Math.floor(Math.min(y.a.x,y.b.x)/b);T<=Math.floor(Math.max(y.a.x,y.b.x)/b);T++)for(let E=Math.floor(Math.min(y.a.y,y.b.y)/b);E<=Math.floor(Math.max(y.a.y,y.b.y)/b);E++){let m=`${y.layer}|${T}|${E}`;(h.get(m)??h.set(m,[]).get(m)).push(y)}let v=(y,T,E)=>{let m=new Set;for(let C=Math.floor((T.x-E)/b);C<=Math.floor((T.x+E)/b);C++)for(let k=Math.floor((T.y-E)/b);k<=Math.floor((T.y+E)/b);k++)for(let I of h.get(`${y}|${C}|${k}`)??[])m.add(I);return m},g=(y,T)=>{let E=bt(T),m=(T.b.x-T.a.x)/(E||1),C=(T.b.y-T.a.y)/(E||1),k=Math.max(0,Math.min(E,(y.x-T.a.x)*m+(y.y-T.a.y)*C));return Math.hypot(y.x-(T.a.x+m*k),y.y-(T.a.y+C*k))},$=y=>t.pairs.some(T=>T.name===y)?y.replace(/^.*\/(?=[^/]*\/[^/]*$)/,""):B(y);for(let y of t.pairs.filter(T=>T.role.rate>=1e9)){let T=e.tracks.filter(P=>P.net===y.p).flatMap(qt),E=e.tracks.filter(P=>P.net===y.n).flatMap(qt);if(!T.length||!E.length)continue;let m=e.parts.flatMap(P=>P.pads).filter(P=>P.net===y.p||P.net===y.n).map(P=>({at:P.at,r:Math.max(P.w,P.h)/2+1.5})),C=P=>m.some(F=>Math.abs(F.at.x-P.x)<F.r&&Math.abs(F.at.y-P.y)<F.r&&de(F.at,P)<F.r),k=P=>/reference clock/.test(P.role.label),I=P=>{let F=t.pairs.find(V=>V.name===P);return F&&!k(F)?wn(F.role.rate):.5*(F?200:1e3)*(300/1.85)/1e3},R=new Map,N=new Map;for(let P of T){let F=kn(e,o,P.layer),V=u[P.layer],O=F?u[F]:void 0;if(!V||!O)continue;let G=Math.max(.03,Math.min(Math.abs(O.top-V.bottom),Math.abs(V.top-O.bottom))),J=P.layer!==e.copper[0]&&P.layer!==e.copper[e.copper.length-1],j=Ne=>pi(Ne,G,P.w,J),Z=bt(P);if(Z<1e-6)continue;let ae=(P.b.x-P.a.x)/Z,z=(P.b.y-P.a.y)/Z,oe=Math.max(1,Math.ceil(Z/.2)),Te=Z/oe,Ie=E.filter(Ne=>Ne.layer===P.layer);for(let Ne=0;Ne<oe;Ne++){let Q={x:P.a.x+ae*(Ne+.5)*Te,y:P.a.y+z*(Ne+.5)*Te},ye=null,be=1/0;for(let ce of Ie){let Oe=g(Q,ce);if(Oe<be){be=Oe;let Se=bt(ce),Xe=(ce.b.x-ce.a.x)/(Se||1),Re=(ce.b.y-ce.a.y)/(Se||1),Je=Math.max(0,Math.min(Se,(Q.x-ce.a.x)*Xe+(Q.y-ce.a.y)*Re));ye={x:ce.a.x+Xe*Je,y:ce.a.y+Re*Je}}}if(!ye||be>1.5||C(Q))continue;let Ee=new Map,Qe=new Map,rt=new Map;for(let ce of v(P.layer,Q,6*G+1)){if(ce.net===y.p||ce.net===y.n)continue;let Oe=bt(ce);if(Oe<.05||Math.abs(ae*(ce.b.x-ce.a.x)/Oe+z*(ce.b.y-ce.a.y)/Oe)<.94)continue;let Se=g(Q,ce),Xe=g(ye,ce);if(Math.min(Se,Xe)>6*G)continue;let Re=i.get(ce.net),Je=Re?.id??ce.net,ne=Re?.sign??1;if(!Re&&fi.test(B(ce.net)))continue;let te=`${Je}|${ce.net}`;if(!(Re&&l(Re.pair,y))){let ke=ne*(j(Se)-j(Xe));(!Ee.has(te)||Math.abs(ke)>Math.abs(Ee.get(te)))&&Ee.set(te,ke)}if(!J&&!(Re&&s(Re.pair,y))){let ke=ne*(S(P.layer,P.w,G,Se-(P.w+ce.w)/2)-S(P.layer,P.w,G,Xe-(P.w+ce.w)/2));(!rt.has(te)||Math.abs(ke)>Math.abs(rt.get(te)))&&rt.set(te,ke)}Qe.set(Je,Math.min(Qe.get(Je)??1/0,Math.min(Se,Xe)-(P.w+ce.w)/2))}let ft=new Map;for(let[ce,Oe]of Ee){let Se=ce.split("|")[0];ft.set(Se,(ft.get(Se)??0)+Oe)}for(let[ce,Oe]of ft){let Se=Math.abs(Oe);if(Se<.005)continue;let Xe=R.get(ce)??R.set(ce,{sum:0,len:0,at:Q,layer:P.layer,d:1/0}).get(ce);Xe.sum+=Se*Te,Xe.len+=Te,Xe.d=Math.min(Xe.d,Qe.get(ce)??1/0)}let qe=new Map;for(let[ce,Oe]of rt){let Se=ce.split("|")[0];qe.set(Se,(qe.get(Se)??0)+Oe)}for(let[ce,Oe]of qe){if(Math.abs(Oe)<1e-4)continue;let Se=N.get(ce)??N.set(ce,{dt:0,len:0,at:Q,layer:P.layer,d:1/0}).get(ce);Se.dt+=Oe*Te,Se.len+=Te,Se.d=Math.min(Se.d,Qe.get(ce)??1/0)}}}let A=null;for(let[P,F]of R){let V=F.sum/F.len*Math.min(1,F.len/I(P));(!A||V>A.next)&&(A={id:P,next:V,len:F.len,at:F.at,layer:F.layer,d:F.d})}let L=P=>{let F=t.pairs.find(V=>V.name===P);return F?k(F)?200:3e11/F.role.rate:1e3};for(let[P,F]of N){let V=.5*Math.min(1,Math.abs(F.dt)/L(P));(!A||V>A.next)&&(A={id:P,next:V,len:F.len,at:F.at,layer:F.layer,d:F.d,far:!0})}if(!A||A.next<.03){n.push({rule:"crosstalk",severity:"pass",title:`${y.name}: no signal close beside it`,detail:A?`The closest neighbour, ${$(A.id)}, adds about ${(A.next*100).toFixed(1)}% ${A.far?"far":"near"}-end crosstalk.`:"No other signal runs beside it within six times its height above the plane.",nets:[y.p,y.n]});continue}let H=(A.next*100).toFixed(1),U=e.stackupFrom==="assumed"?"info":A.next>=.06&&y.role.rate>=25e8&&y.role.kind!=="pair"?"fail":"warn";n.push({rule:"crosstalk",severity:U,title:`${y.name}: ${$(A.id)} runs ${A.d.toFixed(2)} mm beside it`,detail:`On ${A.layer}, ${$(A.id)} runs beside it for ${A.len.toFixed(1)} mm, ${A.d.toFixed(2)} mm from its edge, close against the height to the plane. That couples about ${H}% of its edges into the pair as ${A.far?"far-end crosstalk, which grows with the length run together on an outer layer, where the trace sits under air and mask":"near-end crosstalk"} (above about 3% eats into the eye). Move it away to about three times the height to the plane, or put a ground pour with vias between them.${e.stackupFrom==="assumed"?" The file has no stackup of its own, so the height to the plane is assumed.":""}`,nets:[y.p,y.n],layer:A.layer,at:A.at})}return n}function gi(e,t){let n=[],{planeNet:o}=nt(e),u=At(e),d=s=>!s||ue.test(B(s))||Ge(B(s)),i=e.tracks.filter(s=>!d(s.net)&&!s.mid),a=new Map;for(let s of e.zones)a.set(s.layer,[...a.get(s.layer)??[],...s.polys]);let l=(s,r)=>(a.get(s)??[]).some(f=>_e(r,f)),p=(s,r)=>{let f=u[s],c=u[r];return f&&c?Math.min(Math.abs(c.top-f.bottom),Math.abs(f.top-c.bottom)):1/0};for(let s of t.pairs.filter(r=>r.role.rate>=1e9)){let r=new Set([s.p,s.n]),f=new Map;for(let h of e.tracks.filter(w=>w.net===s.p&&!w.mid)){let w=e.copper.indexOf(h.layer);if(w<=0||w>=e.copper.length-1)continue;let v=kn(e,o,h.layer),g=v?p(h.layer,v):1/0,$=bt(h);if($<1e-6)continue;let y=(h.b.x-h.a.x)/$,T=(h.b.y-h.a.y)/$;for(let E of[e.copper[w-1],e.copper[w+1]]){if(o[E])continue;let m=p(h.layer,E);if(!(m<g)||m>.5)continue;let C=i.filter(R=>R.layer===E&&!r.has(R.net)),k=Math.max(1,Math.ceil($/.25)),I=$/k;for(let R=0;R<k;R++){let N={x:h.a.x+y*(R+.5)*I,y:h.a.y+T*(R+.5)*I};if(!l(E,N))for(let A of C){let L=bt(A);if(L<.05)continue;let H=(A.b.x-A.a.x)/L,U=(A.b.y-A.a.y)/L;if(Math.abs(y*H+T*U)<.94)continue;let P=Math.max(0,Math.min(L,(N.x-A.a.x)*H+(N.y-A.a.y)*U));if(Math.hypot(N.x-(A.a.x+H*P),N.y-(A.a.y+U*P))>m+(h.w+A.w)/2)continue;let V=f.get(A.net)??f.set(A.net,{len:0,layer:E,at:N,dz:m,h:g}).get(A.net);V.len+=I;break}}}}let c=Math.max(3,wn(s.role.rate)/2),x=[...f.entries()].filter(([h])=>!t.pairs.some(w=>w!==s&&(w.p===h||w.n===h)&&w.name===s.name)).sort((h,w)=>w[1].len-h[1].len)[0];if(!x||x[1].len<c)continue;let[S,M]=x,b=t.pairs.find(h=>h.p===S||h.n===S)?.name??B(S);n.push({rule:"crosstalk",severity:e.stackupFrom==="assumed"?"info":"warn",title:`${s.name}: ${b} runs over it on ${M.layer} for ${M.len.toFixed(1)} mm`,detail:`On the next layer, ${M.layer}, ${b} runs right over or under the pair for ${M.len.toFixed(1)} mm with no copper between them. The two layers are ${M.dz.toFixed(3)} mm apart, ${Number.isFinite(M.h)?`closer than the ${M.h.toFixed(3)} mm to the pair's plane, `:""}so they couple broadside, more strongly than traces side by side on one layer. Route them crossing at right angles, offset them sideways, or put a ground pour or plane between the two layers.${e.stackupFrom==="assumed"?" The file has no stackup of its own, so the layer spacing is assumed.":""}`,nets:[s.p,s.n],layer:M.layer,at:M.at})}return n}function yi(e,t){let n=new Map(t.singles.filter(i=>Kn(i.role.kind)).map(i=>[i.net,i.role.label])),o=new Map;for(let i of e){if(i.rule==="impedance"||i.nets.length!==1||!n.has(i.nets[0]))continue;let a=i.title.startsWith(`${i.nets[0]}: `)?i.title.slice(i.nets[0].length+2):null;if(a===null)continue;let l=`${i.rule}|${i.severity}|${n.get(i.nets[0])}|${a.replace(/[\d.]+/g,"#")}`;o.set(l,[...o.get(l)??[],i])}let u=new Set,d=[];for(let[i,a]of o){if(a.length<3)continue;a.forEach(p=>u.add(p));let l=a.map(p=>B(p.nets[0]));d.push({...a[0],title:`${a.length} ${i.split("|")[2]} nets, such as ${a[0].title}`,detail:`${l.slice(0,6).join(", ")}${l.length>6?` and ${l.length-6} more`:""}. ${a[0].detail}`,nets:a.flatMap(p=>p.nets)})}return[...e.filter(i=>!u.has(i)),...d]}function hs(e,t){return yi([...Ra(e,t),...za(e,t),...Ba(e,t),...Va(e,t),...Ha(e,t),...Ga(e,t),...Ka(e,t),...mi(e,t),...gi(e,t),...si(e,t),...ci(e,t),...ui(e,t),...Ja(e,t),...Qa(e,t),...qa(e),...Za(e,t),...Ya(e),...ei(e),...ti(e),...ri(e,t),..._o(e),...zo(e),...Vo(e),...Go(e),...Ko(e),...Jo(e),...Xo(e),...Zo(e)],t)}var bi=e=>{try{return typeof JSON.parse(e)=="object"}catch{return!1}};function ms(e,t){let n=ao(e);t&&(n.project=!0);let{planeNet:o}=nt(n),u=t?fo(t,n.nets):new Map;t&&!bi(t)&&n.warnings.push("The project file (.kicad_pro) could not be read, so each pair is checked against the usual target for its interface.");let d=ho(po(n),u),i={netclasses:d.pairs.filter(a=>a.role.netclass).length,copper:n.copper,planeNet:o,thickness:n.thickness,nets:n.nets.length,tracks:n.tracks.length,vias:n.vias.length,parts:n.parts.length,warnings:n.warnings};return{board:n,intent:d,summary:i}}function xi(e,t){if(t.at||!t.nets.length)return t;let n,o=0;for(let u of e.tracks)if(t.nets.includes(u.net)){let d=Math.hypot(u.b.x-u.a.x,u.b.y-u.a.y);d>o&&(o=d,n=u)}return n?{...t,at:{x:(n.a.x+n.b.x)/2,y:(n.a.y+n.b.y)/2},layer:t.layer??n.layer}:t}var gs=(e,t)=>hs(e,t).map(n=>xi(e,n));var $i=[{id:"usbc",name:"USB-C",none:"No USB-C receptacle was found."},{id:"clocks",name:"Crystals",none:"No crystal was found."},{id:"antenna",name:"Antennas",none:"No module with a printed antenna was found."},{id:"power",name:"Regulators",none:"No buck converter or LDO was found."},{id:"strapping",name:"ESP32 strapping pins",none:"No ESP32 strapping pin is pulled the wrong way."},{id:"basics",name:"I2C, LEDs and power input",none:"Every I2C line has a pull-up, every LED a resistor, and the power input its capacitor."},{id:"mcu",name:"Chip pins",none:"Every power pin is connected, and no STM32 or ESP32 boot pin was found to check."},{id:"impedance",name:"Impedance",none:"No coupled pairs or single-ended fast nets to solve."},{id:"loss",name:"Insertion loss",none:"No PCIe (8 GT/s and up) or USB 3 pairs to measure."},{id:"stubs",name:"Via stubs",none:"The fast nets have no through vias that change layer, so there are no stubs."},{id:"return",name:"Return vias",none:"The fast nets never change reference plane, so no return vias are needed."},{id:"gaps",name:"Reference plane",none:"No fast nets over a plane to check."},{id:"coupling",name:"Pair coupling",none:"No pairs to check."},{id:"crosstalk",name:"Crosstalk",none:"No fast pairs with a stackup to measure against."},{id:"length",name:"Length matching",none:"No pairs with a known length limit to compare."},{id:"accap",name:"AC capacitors",none:"No fast pair runs through series capacitors on both halves."},{id:"skew",name:"Lane skew",none:"No MIPI, LVDS or HDMI bus with two or more lanes routed between the same two parts."},{id:"pdn",name:"Power integrity",none:"No capacitor of a fast or large IC reaches its plane through a long trace."},{id:"emc",name:"EMC",none:"No fast net runs along a plane edge, and the ground pours are stitched."},{id:"esd",name:"ESD protection",none:"No protection diode on a connector line was found."},{id:"ddr",name:"DDR matching",none:"No DDR memory chip was found."},{id:"thermal",name:"Thermal vias",none:"No part with an exposed pad was found."},{id:"decoupling",name:"Decoupling",none:"Every IC power pin has a capacitor within about 4 mm."}],Sn=Object.fromEntries($i.map(e=>[e.id,e.name])),Rr={fail:"Fix",warn:"Check",pass:"Good",info:"Note"};var Pn="0.32.2",xs=`impedora ${Pn}: Board check for KiCad boards (https://impedora.com/board-check/)
3
+
4
+ Usage: impedora <board.kicad_pcb> [options]
5
+
6
+ Checks impedance, return paths, via stubs, loss, crosstalk and length on the fast nets, and the
7
+ mistakes that stop a first board working (USB-C, crystals, regulators, boot pins, I2C pull-ups...).
8
+ The .kicad_pro next to the board is read for netclass impedance targets.
9
+
10
+ Options:
11
+ --fail-on <level> exit 1 if any finding is at or above: fail (default), warn, or never
12
+ --notes list notes (info findings) too
13
+ --passed list passed checks too
14
+ --json print every finding as JSON instead of text
15
+ --markdown print a Markdown report (for a pull request comment)
16
+ --pro <file> the project file to read netclass targets from (default: next to the board)
17
+ --no-pro don't read a project file
18
+ --no-color plain text
19
+ -v, --version print the version
20
+ -h, --help this help
21
+
22
+ In GitHub Actions, findings also show as annotations and the report goes to the job summary.`;function ki(e){let t={failOn:"fail",notes:!1,passed:!1,json:!1,markdown:!1,noPro:!1,color:!!process.stdout.isTTY&&!process.env.NO_COLOR};for(let n=0;n<e.length;n++){let o=e[n];if(o==="-h"||o==="--help")return"help";if(o==="-v"||o==="--version")return"version";if(o==="--fail-on"){let u=e[++n];if(u!=="fail"&&u!=="warn"&&u!=="never")return`--fail-on takes fail, warn or never, not "${u??""}"`;t.failOn=u}else if(o==="--notes")t.notes=!0;else if(o==="--passed")t.passed=!0;else if(o==="--json")t.json=!0;else if(o==="--markdown")t.markdown=!0;else if(o==="--pro"){if(t.pro=e[++n],!t.pro)return"--pro takes a file"}else if(o==="--no-pro")t.noPro=!0;else if(o==="--no-color")t.color=!1;else{if(o==="check"&&!t.board)continue;if(o.startsWith("-"))return`Unknown option ${o}. Run impedora --help.`;if(!t.board)t.board=o;else return`One board at a time: got ${t.board} and ${o}.`}}return t}var Ci=["fail","warn","info","pass"],Yn={fail:3,warn:2,info:1,pass:0},Nt=(e,t)=>e.filter(n=>n.severity===t).length,Ft=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function Ms(e){let t=new Map;for(let n of[...e.pairs.map(o=>o.role.label),...e.singles.map(o=>o.role.label)])t.set(n,(t.get(n)??0)+1);return[...t].map(([n,o])=>o>1?`${n} \xD7${o}`:n).join(", ")}function $s(e,t,n){let o=[],u="";for(let d of e.split(/\s+/))u&&u.length+1+d.length>t-n.length?(o.push(n+u),u=d):u=u?`${u} ${d}`:d;return u&&o.push(n+u),o.join(`
23
+ `)}function Si(){let e=ki(process.argv.slice(2));if(e==="help")return console.log(xs),0;if(e==="version")return console.log(Pn),0;if(typeof e=="string")return console.error(e),2;if(!e.board)return console.error(xs),2;let t=bs(e.board);if(!Nr(t))return console.error(`No such file: ${e.board}`),2;if(!/\.kicad_pcb$/i.test(t))return console.error(`Board check reads KiCad board files (.kicad_pcb): ${e.board}`),2;let n=e.noPro?void 0:e.pro?bs(e.pro):t.replace(/\.kicad_pcb$/i,".kicad_pro");if(e.pro&&!Nr(n))return console.error(`No such file: ${e.pro}`),2;let o=Date.now(),u;try{u=ms(ys(t,"utf8"),n&&Nr(n)?ys(n,"utf8"):void 0)}catch(y){return console.error(`Could not read ${e.board}: ${y instanceof Error?y.message:String(y)}`),2}let{board:d,intent:i,summary:a}=u,l=gs(d,i).sort((y,T)=>Yn[T.severity]-Yn[y.severity]),p=Date.now()-o,s=e.failOn!=="never"&&l.some(y=>Yn[y.severity]>=Yn[e.failOn]),r=wi(t);if(process.env.GITHUB_ACTIONS==="true"&&Pi(l,e.board,r,i),e.json)return console.log(JSON.stringify({tool:"impedora",version:Pn,board:e.board,ms:p,summary:{copperLayers:a.copper.length,thickness:a.thickness,nets:a.nets,vias:a.vias,planes:a.planeNet,netclassTargets:a.netclasses,warnings:a.warnings},fastNets:[...i.pairs.map(y=>({net:y.name,interface:y.role.label,target:y.role.z,differential:!0,netclass:y.role.netclass})),...i.singles.map(y=>({net:y.net,interface:y.role.label,target:y.role.z,differential:!1,netclass:y.role.netclass}))],counts:Object.fromEntries(Ci.map(y=>[y,Nt(l,y)])),findings:l.map(y=>({severity:y.severity,rule:y.rule,section:Sn[y.rule]??y.rule,title:y.title,detail:y.detail,nets:y.nets,...y.at?{at:{x:+y.at.x.toFixed(3),y:+y.at.y.toFixed(3)}}:{},...y.layer?{layer:y.layer}:{}}))},null,2)),s?1:0;if(e.markdown)return console.log(ws(l,r,i,e)),s?1:0;let f=(y,T)=>e.color?`\x1B[${y}m${T}\x1B[0m`:T,c={fail:"1;31",warn:"1;33",info:"2",pass:"32"},x=Math.min(process.stdout.columns||100,110);console.log(f("1",`Impedora Board check ${Pn}`)+` ${r}`);let S=Object.entries(a.planeNet).map(([y,T])=>`${y} ${T}`).join(", ");console.log(f("2",`${a.copper.length} copper layers, ${a.thickness.toFixed(2)} mm, ${Ft(a.nets,"net")}, ${Ft(a.vias,"via")}. Planes: ${S||"none found"}.${a.netclasses?` Netclass targets for ${Ft(a.netclasses,"pair")}.`:""}`));let M=i.pairs.length+i.singles.length;console.log(f("2",M?`${Ft(M,"fast net")}: ${Ms(i)}`:"No differential pairs, RF nets or DDR memory found: the impedance and loss checks have nothing to measure."));for(let y of a.warnings)console.log(f("33",$s(y,x,"! ").slice(2)));console.log("");let b=l.filter(y=>y.severity==="fail"||y.severity==="warn"||e.notes&&y.severity==="info"||e.passed&&y.severity==="pass");for(let y of b)console.log(`${f(c[y.severity],Rr[y.severity].toUpperCase().padEnd(5))} ${f("2",(Sn[y.rule]??y.rule).padEnd(16))} ${f("1",y.title)}`),console.log($s(y.detail,x," ")),y.at&&console.log(f("2",` at x ${y.at.x.toFixed(2)}, y ${y.at.y.toFixed(2)} mm${y.layer?`, ${y.layer}`:""}`)),console.log("");let h=Nt(l,"fail"),w=Nt(l,"warn"),v=Nt(l,"info"),g=Nt(l,"pass"),$=h||w?[h?f(c.fail,`${h} to fix`):"",w?f(c.warn,`${w} to check`):""].filter(Boolean).join(", "):f(c.pass,"Nothing to fix or check");return console.log(`${$}. ${Ft(g,"check")} passed${v?`, ${Ft(v,"note")}${e.notes?"":" (--notes to list them)"}`:""}. ${(p/1e3).toFixed(1)} s.`),console.log(f("2","Estimates from the board file, not a sign-off. See it on the board: https://impedora.com/board-check/")),s?1:0}function ws(e,t,n,o){let u=Nt(e,"fail"),d=Nt(e,"warn"),i=Nt(e,"info"),a=Nt(e,"pass"),l=f=>f.replace(/\|/g,"\\|").replace(/\n/g," "),p=[`### Impedora Board check: \`${t}\``,"",u||d?`**${[u?`${u} to fix`:"",d?`${d} to check`:""].filter(Boolean).join(", ")}**, ${Ft(a,"check")} passed${i?`, ${Ft(i,"note")}`:""}.`:`**Nothing to fix or check.** ${Ft(a,"check")} passed${i?`, ${Ft(i,"note")}`:""}.`,""];n.pairs.length+n.singles.length&&p.push(`Fast nets: ${Ms(n)}.`,"");let r=e.filter(f=>f.severity==="fail"||f.severity==="warn"||o.notes&&f.severity==="info");if(r.length){p.push("| | Check | Finding |","|---|---|---|");for(let f of r)p.push(`| ${Rr[f.severity]} | ${l(Sn[f.rule]??f.rule)} | **${l(f.title)}**<br>${l(f.detail)}${f.at?`<br><sub>x ${f.at.x.toFixed(2)}, y ${f.at.y.toFixed(2)} mm${f.layer?`, ${f.layer}`:""}</sub>`:""} |`);p.push("")}return p.push(`<sub>Impedora ${Pn}. Estimates from the board file, not a sign-off. Open the board at [impedora.com/board-check](https://impedora.com/board-check/) to see each finding on it.</sub>`),p.join(`
24
+ `)}function Pi(e,t,n,o){let u=i=>i.replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A"),d=i=>u(i).replace(/:/g,"%3A").replace(/,/g,"%2C");for(let i of e.filter(a=>a.severity==="fail"||a.severity==="warn"))console.log(`::${i.severity==="fail"?"error":"warning"} file=${d(t)},title=${d(`${Sn[i.rule]??i.rule}: ${i.title}`)}::${u(i.detail)}`);process.env.GITHUB_STEP_SUMMARY&&Mi(process.env.GITHUB_STEP_SUMMARY,`${ws(e,n,o,{notes:!1})}
25
+ `)}process.exitCode=Si();
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "impedora",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.32.2",
4
+ "description": "Board check for KiCad boards: impedance, return paths, via stubs, loss and first-board mistakes, on the command line and in CI.",
5
+ "type": "module",
6
+ "bin": {
7
+ "impedora": "dist/impedora.mjs"
8
+ },
9
+ "files": [
10
+ "dist/impedora.mjs",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "keywords": [
17
+ "kicad",
18
+ "pcb",
19
+ "signal-integrity",
20
+ "impedance",
21
+ "drc",
22
+ "board-check",
23
+ "usb",
24
+ "ci"
25
+ ],
26
+ "homepage": "https://impedora.com/board-check/",
27
+ "license": "UNLICENSED"
28
+ }