@wafertools/wafermap 0.35.1 → 0.36.0

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.
Files changed (73) hide show
  1. package/AGENTS.md +11 -8
  2. package/CHANGELOG.md +117 -0
  3. package/README.md +3 -3
  4. package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
  5. package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
  6. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  8. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  9. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  10. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  11. package/dist/packages/canvas-adapter/index.js +1 -1
  12. package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
  13. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  14. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  15. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  16. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
  17. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  18. package/dist/packages/canvas-adapter/summaryPanel.d.ts +7 -4
  19. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  20. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  21. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  22. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  23. package/dist/packages/canvas-adapter/toolbar.d.ts +0 -6
  24. package/dist/packages/canvas-adapter/toolbar.js +1 -1
  25. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  26. package/dist/packages/canvas-adapter/userGuideHtml.js +10 -3
  27. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  28. package/dist/packages/canvas-adapter/version.js +1 -1
  29. package/dist/packages/canvas-adapter/warnings.js +1 -1
  30. package/dist/packages/core/aggregates.d.ts +10 -0
  31. package/dist/packages/core/aggregates.js +1 -1
  32. package/dist/packages/core/dieTable.d.ts +5 -0
  33. package/dist/packages/core/dieTable.js +1 -1
  34. package/dist/packages/core/wafer.d.ts +10 -1
  35. package/dist/packages/core/wafer.js +1 -1
  36. package/dist/packages/renderer/buildView.d.ts +5 -0
  37. package/dist/packages/renderer/buildView.js +1 -1
  38. package/dist/packages/renderer/buildWaferMap.d.ts +19 -4
  39. package/dist/packages/renderer/buildWaferMap.js +1 -1
  40. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  41. package/dist/packages/renderer/fmt.d.ts +10 -0
  42. package/dist/packages/renderer/fmt.js +1 -1
  43. package/dist/packages/renderer/index.d.ts +1 -0
  44. package/dist/packages/renderer/index.js +1 -1
  45. package/dist/packages/renderer/valueFilter.d.ts +1 -1
  46. package/dist/packages/renderer/valueFilter.js +1 -1
  47. package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
  48. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  49. package/dist/packages/stats/analyzeWaferMap.d.ts +18 -1
  50. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  51. package/dist/packages/stats/clusterDetection.js +1 -1
  52. package/dist/packages/stats/connectedComponents.js +1 -1
  53. package/dist/packages/stats/correlation.d.ts +36 -4
  54. package/dist/packages/stats/correlation.js +1 -1
  55. package/dist/packages/stats/filterFindings.d.ts +1 -1
  56. package/dist/packages/stats/filterFindings.js +1 -1
  57. package/dist/packages/stats/findingText.d.ts +8 -0
  58. package/dist/packages/stats/findingText.js +2 -2
  59. package/dist/packages/stats/index.d.ts +2 -1
  60. package/dist/packages/stats/index.js +1 -1
  61. package/dist/packages/stats/lotDrift.js +1 -1
  62. package/dist/packages/stats/mergeTestDefs.js +1 -1
  63. package/dist/packages/stats/plotData.js +1 -1
  64. package/dist/packages/stats/renderSummaryReport.js +27 -27
  65. package/dist/packages/stats/reportHtml.d.ts +5 -12
  66. package/dist/packages/stats/reportHtml.js +96 -34
  67. package/dist/packages/stats/synthesis.d.ts +4 -0
  68. package/dist/packages/stats/synthesis.js +1 -1
  69. package/dist/packages/stats/testPassRate.js +1 -1
  70. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  71. package/dist/packages/stats/testValueBudget.js +1 -0
  72. package/dist/packages/stats/types.d.ts +77 -22
  73. package/package.json +1 -1
@@ -72,7 +72,7 @@ export const USER_GUIDE_HTML=`<div class="wmap-guide">
72
72
  .wmap-guide-toc{display:none!important}
73
73
  }
74
74
  </style>
75
- <h1 id="wafer-map-user-guide">Wafer Map \u2014 User Guide<span class="wmap-guide-version" title="Built 2026-10-09T18:16:23.713Z">v0.35.1</span></h1>
75
+ <h1 id="wafer-map-user-guide">Wafer Map \u2014 User Guide<span class="wmap-guide-version" title="Built 2026-10-13T15:00:36.302Z">v0.36.0</span></h1>
76
76
  <p class="wmap-guide-online-link">This is a quick reference. <a href="https://wafertools.github.io/wafermap/user-guide/" target="_blank" rel="noopener">View the full illustrated guide online \u2197</a></p>
77
77
  <p>This guide describes the display and analysis features of the wafer map viewer.
78
78
  It is written for users who may be semiconductor test engineers, device engineers, and yield engineers
@@ -232,7 +232,9 @@ outside the test limits are marked with a triangle \u2014 pointing <strong>down
232
232
  for above the high limit</strong> \u2014 so they stand out without leaving the distribution. The
233
233
  triangle is drawn black or white per die for contrast against its own colour, so
234
234
  it stays visible under any colour scheme, and its shape (not colour) carries the
235
- below/above-limit meaning.</li>
235
+ below/above-limit meaning. On dies too small to carry one (under 5 pixels, as on a dense
236
+ wafer zoomed out) the triangles are left off and the colour bar says <strong>\u25BD\u25B3 limit marks: zoom
237
+ in</strong>; zoom in and they appear.</li>
236
238
  <li><strong>Limit pass/fail</strong>: when active, dies within the test limits are shown in
237
239
  a pass colour and dies outside them are highlighted \u2014 <strong>blue for below the
238
240
  low limit</strong>, <strong>red for above the high limit</strong>. Both flags apply
@@ -698,6 +700,11 @@ have both a very low adjusted p-value and a large effect size \u2014 they are re
698
700
  important. <em>Notable</em> findings are statistically significant with a meaningful
699
701
  effect but not as extreme. <em>Info</em> findings pass the significance threshold at
700
702
  lower strength and are worth reviewing but may reflect smaller or noisier patterns.</p>
703
+ <p><strong>Test-value findings</strong> (a region reading high or low on a test) take the longest to compute, so
704
+ they are included automatically only when the data is small enough to take about a second. On
705
+ more data the panel says they are not included, with the number of tests and dies and roughly
706
+ how long they would take, and an <strong>Analyse</strong> button that adds them. For a lot, one click analyses
707
+ every wafer. Findings about tests failing their limits are included either way.</p>
701
708
  <div data-wmap-demo="findings" class="wmap-demo"></div><p><em>Findings panel open showing a detected edge-ring pattern. Click any row to
702
709
  highlight the affected dies on the map.</em></p>
703
710
  <h3 id="finding-types">Finding types</h3>
@@ -1098,7 +1105,7 @@ them, for example &quot;412 dies in hard bin 3, across 13 wafers&quot;. A mark t
1098
1105
  Right-click on any wafer&#39;s bar, box or point opens the same menu for the whole wafer.</p>
1099
1106
  <h3 id="data-tables">Data tables</h3>
1100
1107
  <p>The <strong>Data</strong> sub-tab shows the wafers Insights is scoped to as tables, one at a
1101
- time, chosen with the <strong>Statistics | Dies | Wafers</strong> control. It follows the
1108
+ time, chosen with the <strong>Statistics | Wafers | Dies</strong> control. It follows the
1102
1109
  same &quot;Group by&quot; and &quot;Show&quot; scope as the charts.</p>
1103
1110
  <ul>
1104
1111
  <li><strong>Statistics</strong> \u2014 the <strong>Test Values</strong> table (count, min, quartiles, mean, \u03C3,
@@ -1,3 +1,3 @@
1
- export declare const WMAP_VERSION = "0.35.1";
2
- export declare const WMAP_BUILD_TIME = "2026-10-09T18:19:45.271Z";
1
+ export declare const WMAP_VERSION = "0.36.0";
2
+ export declare const WMAP_BUILD_TIME = "2026-10-13T15:03:19.319Z";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- export const WMAP_VERSION="0.35.1",WMAP_BUILD_TIME="2026-10-09T18:19:45.271Z";
1
+ export const WMAP_VERSION="0.36.0",WMAP_BUILD_TIME="2026-10-13T15:03:19.319Z";
@@ -1 +1 @@
1
- import{SHADOW as C,TRACKING as O,SPACE as r,RADIUS as v,FONT as y,CLR as d,Z_BASE as B}from"./toolbar.js";const E={error:0,warning:1,info:2};export function severityOf(t){return t.severity??"warning"}export function collectWarnings(t){const s=[],i=new Set,n=e=>{if(!e?.message)return;const o=`${e.code}\0${e.message}`;i.has(o)||(i.add(o),s.push(e))};for(const e of t.result?.warnings??[])n(e);for(const e of t.statsSummary?.stats.warnings??[])n(e);for(const e of t.lotStatsSummary?.perWafer??[])for(const o of e.summary.stats.warnings??[])n(o);for(const e of t.extra??[])n(e);return s.sort((e,o)=>E[severityOf(e)]-E[severityOf(o)])}function $(t){return t==="error"?{bg:d.errBg,border:d.errBorder,text:d.errText}:{bg:d.warnBg,border:d.warnBorder,text:d.warnText}}function S(t){return t==="error"?"\u26D4":t==="info"?"\u24D8":"\u26A0"}export const SHORT_LABEL={"partial-coverage":"Partial wafer coverage","geometry-conflict":"Geometry conflict","non-standard-diameter":"Non-standard wafer diameter","diameter-exceeds-die-extent":"Diameter exceeds die extent","edge-exclusion-exceeds-radius":"Edge exclusion exceeds radius","test-count-capped":"Test analysis skipped","test-def-collision":"Test definitions disagree","analysis-option-corrected":"Analysis option corrected","bin-colors-shared":"Bins share a colour","pass-bins-mixed":"Pass bins differ by wafer","ring-count-mixed":"Ring counts differ by wafer","input-field-removed":"Removed input name ignored","input-values-not-numbers":"Bins or test values are text","input-values-outside-stdf":"Values outside STDF ranges","retests-by-part-id":"Retests matched by part ID","derived-test-invalid":"Derived test not applied","values-excluded":"Values excluded by limits"};function w(t){const s=t.code?SHORT_LABEL[t.code]:void 0;if(s)return s;const i=t.message.split(/(?<=\.)\s/)[0]??t.message;return i.length>60?`${i.slice(0,57)}\u2026`:i}export function buildWarningsBanner(t,s=document){const i=s.createElement("div");Object.assign(i.style,{marginBottom:r.lg});for(const n of t){const e=severityOf(n),o=$(e),u=s.createElement("div");Object.assign(u.style,{background:o.bg,border:`1px solid ${o.border}`,borderRadius:v.control,marginBottom:r.sm,fontSize:y.body,color:o.text,lineHeight:"1.5"}),u.setAttribute("role","status");const a=s.createElement("button");a.type="button",Object.assign(a.style,{display:"flex",alignItems:"center",gap:r.sm,width:"100%",background:"none",border:"none",font:"inherit",color:"inherit",textAlign:"left",padding:`${r.sm} ${r.lg}`,cursor:"pointer"});const p=s.createElement("span");Object.assign(p.style,{flex:"1",minWidth:"0"}),p.textContent=`${S(e)} ${w(n)}`;const l=s.createElement("span");Object.assign(l.style,{flexShrink:"0"}),a.append(p,l);const g=s.createElement("div");Object.assign(g.style,{padding:`0 ${r.lg} ${r.sm}`}),g.textContent=n.message;let c=!1;const f=()=>{l.textContent=c?"\u25B4":"\u25BE",g.style.display=c?"block":"none",a.setAttribute("aria-expanded",String(c)),a.setAttribute("aria-label",`${w(n)}. ${c?"Click to collapse.":"Click to expand for detail."}`)};f(),a.addEventListener("click",()=>{c=!c,f()}),a.addEventListener("mouseenter",()=>{l.style.opacity="0.65"}),a.addEventListener("mouseleave",()=>{l.style.opacity="1"}),u.append(a,g),i.appendChild(u)}return i}export function buildWarningsMenuEl(t,s,i=window){const n=i.document,e=n.createElement("div"),o=280,a=t.left+o<=(i.innerWidth??1/0)?t.left:Math.max(4,t.right-o);Object.assign(e.style,{position:"fixed",top:`${t.bottom+4}px`,left:`${a}px`,background:d.menuBg,border:`1px solid ${d.menuBorder}`,borderRadius:v.control,boxShadow:C.menu,zIndex:B,width:`${o}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),e.setAttribute("role","dialog"),e.setAttribute("aria-label","Data warnings");const p=n.createElement("div");Object.assign(p.style,{padding:`${r.sm} ${r.xl} ${r.xs}`,fontSize:y.body,fontWeight:"700",letterSpacing:O,textTransform:"uppercase",color:d.label}),p.textContent=s.length===1?"1 warning":`${s.length} warnings`,e.appendChild(p);for(const l of s){const g=severityOf(l),c=$(g),f=n.createElement("div");Object.assign(f.style,{display:"flex",gap:r.md,padding:`${r.md} ${r.xl}`,fontSize:y.body,lineHeight:"1.5",color:d.text,borderTop:`1px solid ${d.menuBorder}`,alignItems:"flex-start"});const m=n.createElement("span");Object.assign(m.style,{color:c.text,flexShrink:"0"}),m.textContent=S(g),f.appendChild(m);const x=n.createElement("div"),b=n.createElement("div");Object.assign(b.style,{fontWeight:"700",color:c.text,marginBottom:r.xxs}),b.textContent=l.code,x.appendChild(b);const h=n.createElement("div");h.textContent=l.message,x.appendChild(h),f.appendChild(x),e.appendChild(f)}return e}
1
+ import{SHADOW as C,TRACKING as O,SPACE as r,RADIUS as v,FONT as y,CLR as d,Z_BASE as B}from"./toolbar.js";const E={error:0,warning:1,info:2};export function severityOf(t){return t.severity??"warning"}export function collectWarnings(t){const s=[],i=new Set,n=e=>{if(!e?.message)return;const o=`${e.code}\0${e.message}`;i.has(o)||(i.add(o),s.push(e))};for(const e of t.result?.warnings??[])n(e);for(const e of t.statsSummary?.stats.warnings??[])n(e);for(const e of t.lotStatsSummary?.perWafer??[])for(const o of e.summary.stats.warnings??[])n(o);for(const e of t.extra??[])n(e);return s.sort((e,o)=>E[severityOf(e)]-E[severityOf(o)])}function $(t){return t==="error"?{bg:d.errBg,border:d.errBorder,text:d.errText}:{bg:d.warnBg,border:d.warnBorder,text:d.warnText}}function S(t){return t==="error"?"\u26D4":t==="info"?"\u24D8":"\u26A0"}export const SHORT_LABEL={"partial-coverage":"Partial wafer coverage","geometry-conflict":"Geometry conflict","non-standard-diameter":"Non-standard wafer diameter","diameter-exceeds-die-extent":"Diameter exceeds die extent","implausible-center":"Wafer centre ignored","edge-exclusion-exceeds-radius":"Edge exclusion exceeds radius","test-count-capped":"Test-value comparisons skipped","test-def-collision":"Test definitions disagree","analysis-option-corrected":"Analysis option corrected","bin-colors-shared":"Bins share a colour","pass-bins-mixed":"Pass bins differ by wafer","ring-count-mixed":"Ring counts differ by wafer","input-field-removed":"Removed input name ignored","input-values-not-numbers":"Bins or test values are text","input-values-outside-stdf":"Values outside STDF ranges","retests-by-part-id":"Retests matched by part ID","derived-test-invalid":"Derived test not applied","values-excluded":"Values excluded by limits"};function w(t){const s=t.code?SHORT_LABEL[t.code]:void 0;if(s)return s;const i=t.message.split(/(?<=\.)\s/)[0]??t.message;return i.length>60?`${i.slice(0,57)}\u2026`:i}export function buildWarningsBanner(t,s=document){const i=s.createElement("div");Object.assign(i.style,{marginBottom:r.lg});for(const n of t){const e=severityOf(n),o=$(e),u=s.createElement("div");Object.assign(u.style,{background:o.bg,border:`1px solid ${o.border}`,borderRadius:v.control,marginBottom:r.sm,fontSize:y.body,color:o.text,lineHeight:"1.5"}),u.setAttribute("role","status");const a=s.createElement("button");a.type="button",Object.assign(a.style,{display:"flex",alignItems:"center",gap:r.sm,width:"100%",background:"none",border:"none",font:"inherit",color:"inherit",textAlign:"left",padding:`${r.sm} ${r.lg}`,cursor:"pointer"});const p=s.createElement("span");Object.assign(p.style,{flex:"1",minWidth:"0"}),p.textContent=`${S(e)} ${w(n)}`;const l=s.createElement("span");Object.assign(l.style,{flexShrink:"0"}),a.append(p,l);const g=s.createElement("div");Object.assign(g.style,{padding:`0 ${r.lg} ${r.sm}`}),g.textContent=n.message;let c=!1;const f=()=>{l.textContent=c?"\u25B4":"\u25BE",g.style.display=c?"block":"none",a.setAttribute("aria-expanded",String(c)),a.setAttribute("aria-label",`${w(n)}. ${c?"Click to collapse.":"Click to expand for detail."}`)};f(),a.addEventListener("click",()=>{c=!c,f()}),a.addEventListener("mouseenter",()=>{l.style.opacity="0.65"}),a.addEventListener("mouseleave",()=>{l.style.opacity="1"}),u.append(a,g),i.appendChild(u)}return i}export function buildWarningsMenuEl(t,s,i=window){const n=i.document,e=n.createElement("div"),o=280,a=t.left+o<=(i.innerWidth??1/0)?t.left:Math.max(4,t.right-o);Object.assign(e.style,{position:"fixed",top:`${t.bottom+4}px`,left:`${a}px`,background:d.menuBg,border:`1px solid ${d.menuBorder}`,borderRadius:v.control,boxShadow:C.menu,zIndex:B,width:`${o}px`,maxHeight:"320px",overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),e.setAttribute("role","dialog"),e.setAttribute("aria-label","Data warnings");const p=n.createElement("div");Object.assign(p.style,{padding:`${r.sm} ${r.xl} ${r.xs}`,fontSize:y.body,fontWeight:"700",letterSpacing:O,textTransform:"uppercase",color:d.label}),p.textContent=s.length===1?"1 warning":`${s.length} warnings`,e.appendChild(p);for(const l of s){const g=severityOf(l),c=$(g),f=n.createElement("div");Object.assign(f.style,{display:"flex",gap:r.md,padding:`${r.md} ${r.xl}`,fontSize:y.body,lineHeight:"1.5",color:d.text,borderTop:`1px solid ${d.menuBorder}`,alignItems:"flex-start"});const m=n.createElement("span");Object.assign(m.style,{color:c.text,flexShrink:"0"}),m.textContent=S(g),f.appendChild(m);const x=n.createElement("div"),b=n.createElement("div");Object.assign(b.style,{fontWeight:"700",color:c.text,marginBottom:r.xxs}),b.textContent=l.code,x.appendChild(b);const h=n.createElement("div");h.textContent=l.message,x.appendChild(h),f.appendChild(x),e.appendChild(f)}return e}
@@ -5,6 +5,16 @@ export type AggregationMethod = 'mean' | 'median' | 'stddev' | 'min' | 'max' | '
5
5
  * count is a tally, so the test's limits say nothing about them.
6
6
  */
7
7
  export declare function stackHoldsMeasurements(method: string): boolean;
8
+ /**
9
+ * Whether the bins on a stack's dies are data. On a wafer and on a 'mode' stack
10
+ * (each position's most frequent bin) they are. A bin-occurrence stack
11
+ * ('countBin', 'percent') stamps the counted bin on every die so the map can name
12
+ * it; its data is the count in test 0, so it has no yield and no bin findings.
13
+ * A value stack ('mean' and the rest) keeps its template dies' bins, which
14
+ * describe one wafer, not the stack. The one rule for the build's yield and the
15
+ * analysis.
16
+ */
17
+ export declare function stackBinsAreData(isLotStack: boolean | undefined, method: string | undefined): boolean;
8
18
  /** Minimal die shape required by aggregation functions — satisfied by both Die and DieResult. */
9
19
  export interface DieLike {
10
20
  x: number;
@@ -1 +1 @@
1
- import{copyDie as p,testValue as m}from"./dieTable.js";import{minOf as M,maxOf as V}from"./utils.js";import{positionKey as d}from"./dies.js";export function stackHoldsMeasurements(n){return n!=="stddev"&&n!=="count"}export function aggregateValues(n,o,c=0){if(!n.length)return[];const a=new Map,f=new Map;for(const g of n)for(const t of g){const e=d(t),s=m(t,c);s!==void 0?(a.has(e)||(a.set(e,[]),f.set(e,t)),a.get(e).push(s)):f.has(e)||f.set(e,t)}const r=[];for(const[g,t]of f){const e=a.get(g);if(!e?.length){r.push(p(t,{testValues:void 0,testPass:void 0}));continue}let s;if(o==="mean")s=e.reduce((i,u)=>i+u,0)/e.length;else if(o==="median"){const i=[...e].sort((l,h)=>l-h),u=Math.floor(i.length/2);s=i.length%2?i[u]:(i[u-1]+i[u])/2}else if(o==="stddev"){if(e.length<2){r.push(p(t,{testValues:{0:0},testPass:void 0}));continue}const i=e.reduce((u,l)=>u+l,0)/e.length;s=Math.sqrt(e.reduce((u,l)=>u+(l-i)**2,0)/(e.length-1))}else o==="min"?s=M(e):o==="max"?s=V(e):s=e.length;r.push(p(t,{testValues:{0:s},testPass:void 0}))}return r}export function aggregateBinCounts(n,o,c="hard"){if(!n.length)return[];const a=new Map;for(const f of n)for(const r of f)if((c==="soft"?r.sbin:r.hbin)===o){const t=d(r);a.set(t,(a.get(t)??0)+1)}return(n[0]??[]).map(f=>p(f,{testValues:{0:a.get(d(f))??0},testPass:void 0,...c==="soft"?{sbin:o}:{hbin:o}}))}
1
+ import{copyDie as p,testValue as m}from"./dieTable.js";import{minOf as M,maxOf as x}from"./utils.js";import{positionKey as d}from"./dies.js";export function stackHoldsMeasurements(t){return t!=="stddev"&&t!=="count"}export function stackBinsAreData(t,s){return!t||s==="mode"}export function aggregateValues(t,s,l=0){if(!t.length)return[];const u=new Map,f=new Map;for(const g of t)for(const n of g){const e=d(n),o=m(n,l);o!==void 0?(u.has(e)||(u.set(e,[]),f.set(e,n)),u.get(e).push(o)):f.has(e)||f.set(e,n)}const a=[];for(const[g,n]of f){const e=u.get(g);if(!e?.length){a.push(p(n,{testValues:void 0,testPass:void 0}));continue}let o;if(s==="mean")o=e.reduce((i,r)=>i+r,0)/e.length;else if(s==="median"){const i=[...e].sort((c,h)=>c-h),r=Math.floor(i.length/2);o=i.length%2?i[r]:(i[r-1]+i[r])/2}else if(s==="stddev"){if(e.length<2){a.push(p(n,{testValues:{0:0},testPass:void 0}));continue}const i=e.reduce((r,c)=>r+c,0)/e.length;o=Math.sqrt(e.reduce((r,c)=>r+(c-i)**2,0)/(e.length-1))}else s==="min"?o=M(e):s==="max"?o=x(e):o=e.length;a.push(p(n,{testValues:{0:o},testPass:void 0}))}return a}export function aggregateBinCounts(t,s,l="hard"){if(!t.length)return[];const u=new Map;for(const f of t)for(const a of f)if((l==="soft"?a.sbin:a.hbin)===s){const n=d(a);u.set(n,(u.get(n)??0)+1)}return(t[0]??[]).map(f=>p(f,{testValues:{0:u.get(d(f))??0},testPass:void 0,...l==="soft"?{sbin:s}:{hbin:s}}))}
@@ -69,6 +69,11 @@ export declare function excludedCounts(dies: readonly DieData[]): {
69
69
  counts: Map<number, number>;
70
70
  by: 'validity' | 'spec' | 'test';
71
71
  } | undefined;
72
+ /** How many of `dies` lost their value for `testNumber` to the value filter, and the limit set; `undefined` when none did. One column, not every test. */
73
+ export declare function excludedCountFor(dies: readonly DieData[], testNumber: number): {
74
+ count: number;
75
+ by: 'validity' | 'spec' | 'test';
76
+ } | undefined;
72
77
  /** The limit set the value filter excluded `die`'s values against, when it excluded any in its table. */
73
78
  export declare function excludedBy(die: DieData): 'validity' | 'spec' | 'test' | undefined;
74
79
  /** The value the filter excluded from `die` for `testNumber`, or `undefined` when none was. */
@@ -1 +1 @@
1
- import{hasAnyKey as P}from"./utils.js";const O=NaN;export const VERDICT_NONE=-1,VERDICT_FAIL=0,VERDICT_PASS=1,HAS_VALUES=1,HAS_VERDICTS=2;const l=Symbol("wmap.dieTable"),a=Symbol("wmap.dieRow");export function linkDie(e,t,s){return e[l]=t,e[a]=s,e}export function dieLink(e){const t=e[l];return t===void 0?void 0:{table:t,row:e[a]}}export function tableFromRows(e){const t=e.length,s=new Map,o=new Map,r=new Uint8Array(t),n=g(s,()=>new Float64Array(t).fill(O)),c=g(o,()=>new Int8Array(t).fill(VERDICT_NONE));for(let u=0;u<t;u++){const f=e[u].testValues;if(f){r[u]|=HAS_VALUES;const d=n(f),w=Object.values(f);for(let b=0;b<d.length;b++)d[b][u]=w[b]}const i=e[u].testPass;if(i){r[u]|=HAS_VERDICTS;const d=c(i),w=Object.values(i);for(let b=0;b<d.length;b++)d[b][u]=w[b]?VERDICT_PASS:VERDICT_FAIL}}return{rows:t,values:m(s),verdicts:m(o),fields:r}}function g(e,t){let s=[],o=[];return r=>{const n=Object.keys(r);let c=n.length===s.length;for(let u=0;c&&u<n.length;u++)c=n[u]===s[u];return c||(s=n,o=n.map(u=>{let f=e.get(u);return f===void 0&&e.set(u,f=t()),f})),o}}function m(e){return new Map([...e].map(([t,s])=>[Number(t),s]).sort((t,s)=>t[0]-s[0]))}export function extendTable(e,t,s){const o=new Map(e.values),r=new Map(e.verdicts);for(const[n,c]of t)o.set(n,c);for(const[n,c]of s)r.set(n,c);return{rows:e.rows,values:new Map([...o].sort((n,c)=>n[0]-c[0])),verdicts:new Map([...r].sort((n,c)=>n[0]-c[0])),fields:e.fields.slice(),...e.excluded?{excluded:e.excluded,excludedBy:e.excludedBy}:{}}}export function withExcluded(e,t,s,o){const r=new Map(e.values);for(const[c,u]of t)r.set(c,u);const n=new Map(e.excluded??[]);for(const[c,u]of s)n.set(c,u);return{...e,values:r,excluded:n,excludedBy:o}}export function excludedCounts(e){const t=new Map;let s;for(const o of e){const r=o[l];if(r?.excluded===void 0)continue;const n=o[a];for(const[c,u]of r.excluded)Number.isNaN(u[n])||(t.set(c,(t.get(c)??0)+1),s??=r.excludedBy)}return t.size===0||s===void 0?void 0:{counts:t,by:s}}export function excludedBy(e){return e[l]?.excludedBy}export function excludedValue(e,t){const o=e[l]?.excluded?.get(t)?.[e[a]];return o===void 0||Number.isNaN(o)?void 0:o}export function rowView(e){const t=linkDie({},e,0);return s=>(t[a]=s,t)}function v(e,t){const s={},o=[...e.values];for(let r=o.length-1;r>=0;r--){const n=o[r][1][t];Number.isNaN(n)||(s[o[r][0]]=n)}return s}function x(e,t){const s={},o=[...e.verdicts];for(let r=o.length-1;r>=0;r--){const n=o[r][1][t];n!==VERDICT_NONE&&(s[o[r][0]]=n===VERDICT_PASS)}return s}function j(){return Object.freeze(v(this[l],this[a]))}function k(){return Object.freeze(x(this[l],this[a]))}function N(e){return function(){throw new TypeError(`wafermap: die.${e} is read-only on a die built by buildWaferMap (die ${this.id}). Pass the values you want to buildWaferMap, or copy the die: { ...die, ${e}: yours }.`)}}const V={get:j,set:N("testValues"),enumerable:!0,configurable:!0},y={get:k,set:N("testPass"),enumerable:!0,configurable:!0},p=e=>({value:e,writable:!0,enumerable:!1,configurable:!0});export function finaliseDie(e){const t=e[l];if(t===void 0)return e;const s=e[a],o=t.fields[s],r=e.testValues!==void 0&&!(o&HAS_VALUES)||e.testPass!==void 0&&!(o&HAS_VERDICTS),n={};for(const c of Object.keys(e))c==="testValues"&&o&HAS_VALUES||c==="testPass"&&o&HAS_VERDICTS||(n[c]=e[c]);return r?(o&HAS_VALUES&&(n.testValues=v(t,s)),o&HAS_VERDICTS&&(n.testPass=x(t,s)),n):(Object.defineProperty(n,l,p(t)),Object.defineProperty(n,a,p(s)),o&HAS_VALUES&&Object.defineProperty(n,"testValues",V),o&HAS_VERDICTS&&Object.defineProperty(n,"testPass",y),n)}export function copyDie(e,t){const s=e[l];if(s===void 0)return{...e,...t};const o=e[a],r=s.fields[o],n={};for(const c of Object.keys(e))c!=="testValues"&&c!=="testPass"&&(n[c]=e[c]);return"testValues"in t||"testPass"in t?(r&HAS_VALUES&&!("testValues"in t)&&(n.testValues=v(s,o)),r&HAS_VERDICTS&&!("testPass"in t)&&(n.testPass=x(s,o)),Object.assign(n,t)):(Object.assign(n,t),Object.defineProperty(n,l,p(s)),Object.defineProperty(n,a,p(o)),r&HAS_VALUES&&Object.defineProperty(n,"testValues",V),r&HAS_VERDICTS&&Object.defineProperty(n,"testPass",y),n)}export function detachTables(e){const t=[],s=new Map,o=e.reduce((u,f)=>u+f.length,0),r=new Int32Array(o*2);let n=0;for(const u of e)for(const f of u){const i=dieLink(f);if(i===void 0){r[n++]=-1,r[n++]=0;continue}let d=s.get(i.table);d===void 0&&(s.set(i.table,d=t.length),t.push(i.table)),r[n++]=d,r[n++]=i.row,delete f.testValues,delete f.testPass}const c=new Set;for(const u of t){for(const f of u.values.values())c.add(f.buffer);for(const f of u.verdicts.values())c.add(f.buffer);if(c.add(u.fields.buffer),u.excluded)for(const f of u.excluded.values())c.add(f.buffer)}return{tables:t,links:r,transfer:[...c]}}export function attachTables(e,t){let s=0;for(const o of e)for(const r of o){const n=t.links[s++],c=t.links[s++];if(n<0)continue;const u=t.tables[n],f=u.fields[c];Object.defineProperty(r,l,p(u)),Object.defineProperty(r,a,p(c)),f&HAS_VALUES&&Object.defineProperty(r,"testValues",V),f&HAS_VERDICTS&&Object.defineProperty(r,"testPass",y)}}export function testValue(e,t){const s=e[l];if(s===void 0)return e.testValues?.[t];const o=s.values.get(t)?.[e[a]];return o===void 0||Number.isNaN(o)?void 0:o}export function recordedVerdict(e,t){const s=e[l];if(s===void 0)return e.testPass?.[t];const o=s.verdicts.get(t)?.[e[a]];return o===void 0||o===VERDICT_NONE?void 0:o===VERDICT_PASS}export function dieHasAnyTestData(e){return dieHasValues(e)||dieHasVerdicts(e)}export function dieHasValues(e){const t=dieLink(e);if(t===void 0)return P(e.testValues);for(const s of t.table.values.values())if(!Number.isNaN(s[t.row]))return!0;return!1}export function dieHasVerdicts(e){const t=dieLink(e);if(t===void 0)return P(e.testPass);for(const s of t.table.verdicts.values())if(s[t.row]!==VERDICT_NONE)return!0;return!1}export function dieValueEntries(e){const t=dieLink(e);if(t===void 0){const o=e.testValues;return o===void 0?[]:Object.keys(o).map(r=>[Number(r),o[Number(r)]])}const s=[];for(const[o,r]of t.table.values){const n=r[t.row];Number.isNaN(n)||s.push([o,n])}return s}export function dieVerdictEntries(e){const t=dieLink(e);if(t===void 0){const o=e.testPass;return o===void 0?[]:Object.keys(o).map(r=>[Number(r),o[Number(r)]])}const s=[];for(const[o,r]of t.table.verdicts){const n=r[t.row];n!==VERDICT_NONE&&s.push([o,n===VERDICT_PASS])}return s}export function testValuesReader(e){let t,s=[];return function(r,n){const c=dieLink(r);if(c===void 0){const u=r.testValues;for(let f=0;f<e.length;f++){const i=u?.[e[f]];n[f]=i===void 0?NaN:i}return n}c.table!==t&&(t=c.table,s=e.map(u=>c.table.values.get(u)));for(let u=0;u<s.length;u++){const f=s[u];n[u]=f===void 0?NaN:f[c.row]}return n}}export function recordedVerdictsReader(e){let t,s=[];return function(r,n){const c=dieLink(r);if(c===void 0){const u=r.testPass;for(let f=0;f<e.length;f++){const i=u?.[e[f]];n[f]=i===void 0?VERDICT_NONE:i?VERDICT_PASS:VERDICT_FAIL}return n}c.table!==t&&(t=c.table,s=e.map(u=>c.table.verdicts.get(u)));for(let u=0;u<s.length;u++){const f=s[u];n[u]=f===void 0?VERDICT_NONE:f[c.row]}return n}}export function testsPresent(e,t="all"){const s=new Set,o=new Map;for(const r of e){const n=dieLink(r);if(n===void 0){if(r.testValues)for(const u in r.testValues)s.add(Number(u));if(t==="all"&&r.testPass)for(const u in r.testPass)s.add(Number(u));continue}let c=o.get(n.table);c===void 0&&o.set(n.table,c=[]),c.push(n.row)}for(const[r,n]of o){for(const[c,u]of r.values)!s.has(c)&&n.some(f=>!Number.isNaN(u[f]))&&s.add(c);if(t!=="values")for(const[c,u]of r.verdicts)!s.has(c)&&n.some(f=>u[f]!==VERDICT_NONE)&&s.add(c)}return[...s].sort((r,n)=>r-n)}
1
+ import{hasAnyKey as N}from"./utils.js";const O=NaN;export const VERDICT_NONE=-1,VERDICT_FAIL=0,VERDICT_PASS=1,HAS_VALUES=1,HAS_VERDICTS=2;const l=Symbol("wmap.dieTable"),a=Symbol("wmap.dieRow");export function linkDie(e,t,s){return e[l]=t,e[a]=s,e}export function dieLink(e){const t=e[l];return t===void 0?void 0:{table:t,row:e[a]}}export function tableFromRows(e){const t=e.length,s=new Map,o=new Map,r=new Uint8Array(t),n=P(s,()=>new Float64Array(t).fill(O)),c=P(o,()=>new Int8Array(t).fill(VERDICT_NONE));for(let u=0;u<t;u++){const f=e[u].testValues;if(f){r[u]|=HAS_VALUES;const d=n(f),x=Object.values(f);for(let b=0;b<d.length;b++)d[b][u]=x[b]}const i=e[u].testPass;if(i){r[u]|=HAS_VERDICTS;const d=c(i),x=Object.values(i);for(let b=0;b<d.length;b++)d[b][u]=x[b]?VERDICT_PASS:VERDICT_FAIL}}return{rows:t,values:g(s),verdicts:g(o),fields:r}}function P(e,t){let s=[],o=[];return r=>{const n=Object.keys(r);let c=n.length===s.length;for(let u=0;c&&u<n.length;u++)c=n[u]===s[u];return c||(s=n,o=n.map(u=>{let f=e.get(u);return f===void 0&&e.set(u,f=t()),f})),o}}function g(e){return new Map([...e].map(([t,s])=>[Number(t),s]).sort((t,s)=>t[0]-s[0]))}export function extendTable(e,t,s){const o=new Map(e.values),r=new Map(e.verdicts);for(const[n,c]of t)o.set(n,c);for(const[n,c]of s)r.set(n,c);return{rows:e.rows,values:new Map([...o].sort((n,c)=>n[0]-c[0])),verdicts:new Map([...r].sort((n,c)=>n[0]-c[0])),fields:e.fields.slice(),...e.excluded?{excluded:e.excluded,excludedBy:e.excludedBy}:{}}}export function withExcluded(e,t,s,o){const r=new Map(e.values);for(const[c,u]of t)r.set(c,u);const n=new Map(e.excluded??[]);for(const[c,u]of s)n.set(c,u);return{...e,values:r,excluded:n,excludedBy:o}}export function excludedCounts(e){const t=new Map;let s;for(const o of e){const r=o[l];if(r?.excluded===void 0)continue;const n=o[a];for(const[c,u]of r.excluded)Number.isNaN(u[n])||(t.set(c,(t.get(c)??0)+1),s??=r.excludedBy)}return t.size===0||s===void 0?void 0:{counts:t,by:s}}export function excludedCountFor(e,t){let s=0,o;for(const r of e){const n=r[l],c=n?.excluded?.get(t);c===void 0||Number.isNaN(c[r[a]])||(s++,o??=n.excludedBy)}return s>0&&o!==void 0?{count:s,by:o}:void 0}export function excludedBy(e){return e[l]?.excludedBy}export function excludedValue(e,t){const o=e[l]?.excluded?.get(t)?.[e[a]];return o===void 0||Number.isNaN(o)?void 0:o}export function rowView(e){const t=linkDie({},e,0);return s=>(t[a]=s,t)}function w(e,t){const s={},o=[...e.values];for(let r=o.length-1;r>=0;r--){const n=o[r][1][t];Number.isNaN(n)||(s[o[r][0]]=n)}return s}function v(e,t){const s={},o=[...e.verdicts];for(let r=o.length-1;r>=0;r--){const n=o[r][1][t];n!==VERDICT_NONE&&(s[o[r][0]]=n===VERDICT_PASS)}return s}function j(){return Object.freeze(w(this[l],this[a]))}function k(){return Object.freeze(v(this[l],this[a]))}function m(e){return function(){throw new TypeError(`wafermap: die.${e} is read-only on a die built by buildWaferMap (die ${this.id}). Pass the values you want to buildWaferMap, or copy the die: { ...die, ${e}: yours }.`)}}const y={get:j,set:m("testValues"),enumerable:!0,configurable:!0},V={get:k,set:m("testPass"),enumerable:!0,configurable:!0},p=e=>({value:e,writable:!0,enumerable:!1,configurable:!0});export function finaliseDie(e){const t=e[l];if(t===void 0)return e;const s=e[a],o=t.fields[s],r=e.testValues!==void 0&&!(o&HAS_VALUES)||e.testPass!==void 0&&!(o&HAS_VERDICTS),n={};for(const c of Object.keys(e))c==="testValues"&&o&HAS_VALUES||c==="testPass"&&o&HAS_VERDICTS||(n[c]=e[c]);return r?(o&HAS_VALUES&&(n.testValues=w(t,s)),o&HAS_VERDICTS&&(n.testPass=v(t,s)),n):(Object.defineProperty(n,l,p(t)),Object.defineProperty(n,a,p(s)),o&HAS_VALUES&&Object.defineProperty(n,"testValues",y),o&HAS_VERDICTS&&Object.defineProperty(n,"testPass",V),n)}export function copyDie(e,t){const s=e[l];if(s===void 0)return{...e,...t};const o=e[a],r=s.fields[o],n={};for(const c of Object.keys(e))c!=="testValues"&&c!=="testPass"&&(n[c]=e[c]);return"testValues"in t||"testPass"in t?(r&HAS_VALUES&&!("testValues"in t)&&(n.testValues=w(s,o)),r&HAS_VERDICTS&&!("testPass"in t)&&(n.testPass=v(s,o)),Object.assign(n,t)):(Object.assign(n,t),Object.defineProperty(n,l,p(s)),Object.defineProperty(n,a,p(o)),r&HAS_VALUES&&Object.defineProperty(n,"testValues",y),r&HAS_VERDICTS&&Object.defineProperty(n,"testPass",V),n)}export function detachTables(e){const t=[],s=new Map,o=e.reduce((u,f)=>u+f.length,0),r=new Int32Array(o*2);let n=0;for(const u of e)for(const f of u){const i=dieLink(f);if(i===void 0){r[n++]=-1,r[n++]=0;continue}let d=s.get(i.table);d===void 0&&(s.set(i.table,d=t.length),t.push(i.table)),r[n++]=d,r[n++]=i.row,delete f.testValues,delete f.testPass}const c=new Set;for(const u of t){for(const f of u.values.values())c.add(f.buffer);for(const f of u.verdicts.values())c.add(f.buffer);if(c.add(u.fields.buffer),u.excluded)for(const f of u.excluded.values())c.add(f.buffer)}return{tables:t,links:r,transfer:[...c]}}export function attachTables(e,t){let s=0;for(const o of e)for(const r of o){const n=t.links[s++],c=t.links[s++];if(n<0)continue;const u=t.tables[n],f=u.fields[c];Object.defineProperty(r,l,p(u)),Object.defineProperty(r,a,p(c)),f&HAS_VALUES&&Object.defineProperty(r,"testValues",y),f&HAS_VERDICTS&&Object.defineProperty(r,"testPass",V)}}export function testValue(e,t){const s=e[l];if(s===void 0)return e.testValues?.[t];const o=s.values.get(t)?.[e[a]];return o===void 0||Number.isNaN(o)?void 0:o}export function recordedVerdict(e,t){const s=e[l];if(s===void 0)return e.testPass?.[t];const o=s.verdicts.get(t)?.[e[a]];return o===void 0||o===VERDICT_NONE?void 0:o===VERDICT_PASS}export function dieHasAnyTestData(e){return dieHasValues(e)||dieHasVerdicts(e)}export function dieHasValues(e){const t=dieLink(e);if(t===void 0)return N(e.testValues);for(const s of t.table.values.values())if(!Number.isNaN(s[t.row]))return!0;return!1}export function dieHasVerdicts(e){const t=dieLink(e);if(t===void 0)return N(e.testPass);for(const s of t.table.verdicts.values())if(s[t.row]!==VERDICT_NONE)return!0;return!1}export function dieValueEntries(e){const t=dieLink(e);if(t===void 0){const o=e.testValues;return o===void 0?[]:Object.keys(o).map(r=>[Number(r),o[Number(r)]])}const s=[];for(const[o,r]of t.table.values){const n=r[t.row];Number.isNaN(n)||s.push([o,n])}return s}export function dieVerdictEntries(e){const t=dieLink(e);if(t===void 0){const o=e.testPass;return o===void 0?[]:Object.keys(o).map(r=>[Number(r),o[Number(r)]])}const s=[];for(const[o,r]of t.table.verdicts){const n=r[t.row];n!==VERDICT_NONE&&s.push([o,n===VERDICT_PASS])}return s}export function testValuesReader(e){let t,s=[];return function(r,n){const c=dieLink(r);if(c===void 0){const u=r.testValues;for(let f=0;f<e.length;f++){const i=u?.[e[f]];n[f]=i===void 0?NaN:i}return n}c.table!==t&&(t=c.table,s=e.map(u=>c.table.values.get(u)));for(let u=0;u<s.length;u++){const f=s[u];n[u]=f===void 0?NaN:f[c.row]}return n}}export function recordedVerdictsReader(e){let t,s=[];return function(r,n){const c=dieLink(r);if(c===void 0){const u=r.testPass;for(let f=0;f<e.length;f++){const i=u?.[e[f]];n[f]=i===void 0?VERDICT_NONE:i?VERDICT_PASS:VERDICT_FAIL}return n}c.table!==t&&(t=c.table,s=e.map(u=>c.table.verdicts.get(u)));for(let u=0;u<s.length;u++){const f=s[u];n[u]=f===void 0?VERDICT_NONE:f[c.row]}return n}}export function testsPresent(e,t="all"){const s=new Set,o=new Map;for(const r of e){const n=dieLink(r);if(n===void 0){if(r.testValues)for(const u in r.testValues)s.add(Number(u));if(t==="all"&&r.testPass)for(const u in r.testPass)s.add(Number(u));continue}let c=o.get(n.table);c===void 0&&o.set(n.table,c=[]),c.push(n.row)}for(const[r,n]of o){for(const[c,u]of r.values)!s.has(c)&&n.some(f=>!Number.isNaN(u[f]))&&s.add(c);if(t!=="values")for(const[c,u]of r.verdicts)!s.has(c)&&n.some(f=>u[f]!==VERDICT_NONE)&&s.add(c)}return[...s].sort((r,n)=>r-n)}
@@ -23,6 +23,13 @@ export interface WaferReticle {
23
23
  }
24
24
  export interface WaferSpec {
25
25
  diameter: number;
26
+ /**
27
+ * What `diameter` is measured in. `'normalized'` (die pitches, when no physical
28
+ * size is known) keeps the orientation mark's direction but gives it length 0:
29
+ * the SEMI flat and notch sizes are millimetres, and a millimetre table applied
30
+ * to a pitch count cut a third of a small wafer off. Default `'mm'`.
31
+ */
32
+ units?: 'mm' | 'normalized';
26
33
  center?: {
27
34
  x: number;
28
35
  y: number;
@@ -41,7 +48,9 @@ export interface Wafer {
41
48
  };
42
49
  /**
43
50
  * Resolved orientation mark. `length` is the standard chord length (flat) or
44
- * half-width (V-notch), derived from the wafer diameter by `createWafer`.
51
+ * half-width (V-notch), derived from the wafer diameter by `createWafer`. 0 when
52
+ * the diameter is not in millimetres: the mark's side is known, its size is
53
+ * not, so nothing is cut into the outline (the side is still drawn as a marker).
45
54
  */
46
55
  notch?: {
47
56
  type: 'top' | 'bottom' | 'left' | 'right';
@@ -1 +1 @@
1
- function t(e){return e<=100?32.5:e<=150?57.5:1.75}export function createWafer(e){if(e.diameter<=0)throw new RangeError(`createWafer: diameter must be > 0 (got ${e.diameter})`);return{diameter:e.diameter,radius:e.diameter/2,center:e.center??{x:0,y:0},notch:e.notch?{type:e.notch.type,length:t(e.diameter)}:void 0,orientation:e.orientation??0,metadata:e.metadata,...e.reticle?{reticle:e.reticle}:{}}}
1
+ function t(e){return e<=100?32.5:e<=150?57.5:1.75}export function createWafer(e){if(e.diameter<=0)throw new RangeError(`createWafer: diameter must be > 0 (got ${e.diameter})`);return{diameter:e.diameter,radius:e.diameter/2,center:e.center??{x:0,y:0},notch:e.notch?{type:e.notch.type,length:e.units==="normalized"?0:t(e.diameter)}:void 0,orientation:e.orientation??0,metadata:e.metadata,...e.reticle?{reticle:e.reticle}:{}}}
@@ -115,6 +115,11 @@ export interface ViewOverlay {
115
115
  export interface View {
116
116
  /** Die rectangles to fill, in draw order, already carrying their resolved colour. */
117
117
  rectangles: ViewRect[];
118
+ /**
119
+ * The visual kerf between dies, in mm: each rectangle is its die's pitch less this.
120
+ * The drawer needs it to tile dies edge to edge when the kerf is too small to draw.
121
+ */
122
+ dieGap: number;
118
123
  /**
119
124
  * Transformed centre of each die, index-parallel with {@link dies}. Separate
120
125
  * from `rectangles` because a die always has a centre for hit-testing and
@@ -1 +1 @@
1
- import{requirePassBins as ge}from"../core/passBins.js";import{requireRingCount as ye}from"../core/ringCount.js";import{hasPosition as be}from"../core/dies.js";import{dieValueEntries as xe,dieVerdictEntries as Me,excludedBy as Se,excludedValue as ve,recordedVerdict as Be,testsPresent as Ot}from"../core/dieTable.js";import{limitSetName as $e}from"./valueFilter.js";import{getReticleCell as ke}from"../core/reticle.js";import{metadataCategoricalValue as Ie,metadataDisplayValue as Te}from"../core/metadata.js";import{affineRotation as xt,affineMirror as wt,affineCompose as ot,affinePoint as G,affineVector as De,affineSwapsAxes as Ve}from"../core/transforms.js";import{contrastTextColor as Q,SPEC_PASS_FILL as Mt,SPEC_FAIL_LOW as Ce,SPEC_FAIL_HIGH as St}from"./colorMap.js";import{resolveValueColorFn as Fe}from"./colorSchemes.js";import{resolveBinColors as Le,binColorsCover as Re}from"./binColors.js";import{NO_DATA_FILL as z}from"./colorMap.js";import{diePassStatus as Pe}from"../core/dies.js";import{compactView as Ne}from"./compactView.js";import{buildXYIndicator as Ee}from"./xyIndicator.js";import{getDieTestValue as L,getTestPassStatus as U,isParametricTest as vt}from"./buildWaferMap.js";import{classifySpec as rt}from"./spec.js";export{rt as classifySpec};import{fmt as lt,fmtColorbarAxis as Bt,fmtAggregationMethod as qt}from"./fmt.js";import{metadataValueColor as Ae}from"./colorMap.js";import{asList as Kt,clamp01 as Wt,compareNatural as He,escHtml as R}from"../core/utils.js";import{prettyKey as zt}from"../core/utils.js";import{testLabel as ct,markedTestLabel as J,derivedTestNote as jt,isDerivedTest as _e,DERIVED_MARK as Oe,DERIVED_KEY as we}from"./testLabel.js";export function resolveTestNumber(t,e){return e?.length?{testNumber:(findTestDef(e,t)??e[0]).testNumber}:{testNumber:t}}export function collectMetadataValues(t,e){const n=new Set;for(const i of t){if(i.partial||i.edgeExcluded)continue;const s=ut(i,e);s!==void 0&&n.add(s)}return[...n].sort(He)}export function findTestDef(t,e){return t?.find(n=>n.testNumber===e)}export function getUniqueTestNumbers(t){return Ot(t,"values")}const qe="#d3d6db",Xt="#e8e9ea",Ke="#aab0ba";function ut(t,e){return e?Ie(t.metadata?.[e]):void 0}function We(t,e,n){const{x:i,y:s}=t.center,a=xt(t.orientation,i,s),o=ot(wt(e?.x??!1,e?.y??!1,i,s),xt(t.orientation,i,s)),r=ot(wt(n?.flipX??!1,n?.flipY??!1,i,s),xt(n?.rotation??0,i,s));return{bakedToScreen:r,physicalToScreen:ot(r,a),gridToScreen:ot(r,o)}}function Y(t,e=!1){return{points:[t],closed:e}}function ze(t,e){const{center:n,radius:i,notch:s}=t;let a=n.x+i*Math.cos(e),o=n.y+i*Math.sin(e);if(!s)return{x:a,y:o};const r=Math.sqrt(i**2-(s.length/2)**2),d=s.length/2,p=a-n.x,x=o-n.y;return s.type==="bottom"&&x<-r?(o=n.y-r,a=n.x+Math.max(-d,Math.min(d,p))):s.type==="top"&&x>r?(o=n.y+r,a=n.x+Math.max(-d,Math.min(d,p))):s.type==="left"&&p<-r?(a=n.x-r,o=n.y+Math.max(-d,Math.min(d,x))):s.type==="right"&&p>r&&(a=n.x+r,o=n.y+Math.max(-d,Math.min(d,x))),{x:a,y:o}}function Yt(t,e){return t.map(e).join(" / ")}function je(t,e=256){const n=Array.from({length:e},(i,s)=>t(s/(e-1)));return i=>n[Math.min(e-1,Math.max(0,Math.round(i*(e-1))))]}function Xe(t,e){const n=Math.max(1,Math.min(t.width,t.height)),i=t.width/Math.max(e.length,1);return Math.max(8,Math.min(16,Math.round(Math.min(n*.55,i*1.8))))}function Ye(t,e,n){if(e?.length){const a=e.flatMap(o=>{const r=o.testNumber;if(!vt(o)){const p=U(t,r,o);return p===void 0?[]:[{key:r,label:J(o,r),value:p?"Pass":"Fail"}]}const d=L(t,r);if(d===void 0){const p=ve(t,r);return p===void 0?[]:[{key:r,label:J(o,r),value:lt(p,o.unit,n),excludedBy:Se(t)}]}return[{key:r,label:J(o,r),value:lt(d,o.unit,n),recordedFail:Be(t,r)===!1}]});if(a.length)return a}const i=xe(t);if(i.length)return i.map(([a,o])=>({key:a,label:ct(void 0,a),value:lt(o,void 0,n)}));const s=Me(t);return s.length?s.map(([a,o])=>({key:a,label:ct(void 0,a),value:o?"Pass":"Fail"})):[]}export function buildHoverText(t,e,n={}){const{testDefs:i,hbinDefs:s,sbinDefs:a,fallbackFormat:o,aggrMethod:r,lotSize:d,activeTest:p,reticleConfig:x,metadataFields:$}=n,V=s?new Map(s.map(f=>[f.bin,f])):null,I=a?new Map(a.map(f=>[f.bin,f])):null,y=[R(`Die (${t.x}, ${t.y})`)];if(x&&be(t)){const f=ke(t,x);y.push(R(`Reticle (${f.column}, ${f.row})`))}if(e==="stackedValues"){const f=L(t,0);if(f!==void 0){const u=i?.[0],m=u?J(u,u.testNumber):"Value",S=r?` (${r})`:"";y.push(R(`${m}${S}: ${lt(f,u?.unit,o)}`));const h=jt(u);h&&y.push(`<i>${R(h)}</i>`)}}else if(e==="stackedBins"||e==="stackedSoftBins"){const f=L(t,0),u=e==="stackedSoftBins"?t.sbin:t.hbin;if(f!==void 0){const m=e==="stackedSoftBins"?I:V,S=u!==void 0?m?.get(u)?.name?`${u} \xB7 ${m.get(u).name}`:`Bin ${u}`:"Bin";let h;if(r==="percent")h=`${f.toFixed(0)}%`;else{const D=d?` (${(f/d*100).toFixed(0)}% of stacked wafers)`:"";h=`${f}${D}`}const b=r?` [${qt(r)}]`:"";y.push(R(`${S}: ${h}${b}`))}}else{const f=Ye(t,i,o);if(e==="value"&&f.length){const{testNumber:u}=resolveTestNumber(p??0,i),m=findTestDef(i,u),S=L(t,u);let h=f.findIndex(A=>A.key===u);h<0&&(h=0);const b=f[h];let D=`<b>${R(`${b.label}: ${b.value}`)}${b.recordedFail?" <i>(recorded fail)</i>":""}</b>`;if(b.key===u&&m){const A=rt(S,m);(A==="failLow"||A==="failHigh")&&(D+=" <i>(outside test limits)</i>")}b.excludedBy&&(D+=` <i>(outside ${$e(b.excludedBy)}, excluded)</i>`),y.push(D);const E=jt(findTestDef(i,b.key));E&&y.push(`<i>${R(E)}</i>`);const g=f.length-1;g>0&&y.push(`<i>+${g} more test${g===1?"":"s"}</i>`)}else if(f.length){const u=f.length;y.push(`<i>${u} test result${u===1?"":"s"} recorded</i>`)}if(t.hbin!==void 0||t.sbin!==void 0){const u=[];if(t.hbin!==void 0){const m=V?.get(t.hbin)?.name,S=m?`${t.hbin} \xB7 ${m}`:String(t.hbin);u.push(`HBin: ${S}`)}if(t.sbin!==void 0){const m=I?.get(t.sbin)?.name,S=m?`${t.sbin} \xB7 ${m}`:String(t.sbin);u.push(`SBin: ${S}`)}y.push(u.map(R).join(" &nbsp;\xB7&nbsp; "))}}t.retestCount!==void 0&&y.push(R(`Retests: ${t.retestCount}`)),t.siteNum!==void 0&&y.push(R(`Site: ${t.siteNum}`)),t.partId!==void 0&&y.push(R(`Part ID: ${t.partId}`)),t.partial&&y.push("<i>partial die</i>"),t.probeIndex!==void 0&&y.push(R(`Probe: #${t.probeIndex}`));const B={...t.metadata??{}};for(const[f,u]of Object.entries(B)){const m=Te(u);if(m===void 0)continue;const S=$?.find(h=>h.key===f)?.label??zt(f);y.push(R(`${S}: ${m}`))}return y.join("<br>")}function $t(t){return t?.name?J(t,t.testNumber):void 0}function kt(t){return _e(t)?{note:`${Oe} ${we}`}:{}}export function buildMapTitle(t,e="engineering",n){const i=t.isLotStack&&t.lotSize!==void 0?`stacked (${t.lotSize} ${t.lotSize===1?"wafer":"wafers"})`:"stacked",s=a=>{const o=n?.length===1?n[0]:void 0;return o===void 0?`${a} Bin`:o.name?`${a} Bin ${o.bin} \xB7 ${o.name}`:`${a} Bin ${o.bin}`};switch(t.plotMode){case"hardBin":return{primary:"Hard Bin",secondary:""};case"softBin":return{primary:"Soft Bin",secondary:""};case"stackedBins":return{primary:s("Hard"),secondary:i};case"stackedSoftBins":return{primary:s("Soft"),secondary:i};case"metadata":{const a=t.metadataFields?.find(r=>r.key===t.activeMetadataKey),o=t.activeMetadataKey?zt(t.activeMetadataKey):"Metadata";return{primary:a?.label??o,secondary:""}}case"stackedValues":{const a=t.testDefs?.[0],o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=Bt(o,$t(a),a?.unit,e),d=r||"Value",p=t.aggrMethod?` \xB7 ${qt(t.aggrMethod)}`:"";return{primary:`${d}${p}`,secondary:i,...kt(a)}}default:{const a=findTestDef(t.testDefs,t.activeTest),o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=Bt(o,$t(a),a?.unit,e),d=r||$t(a);if(t.passFailDisplay!=="off"){const p=a?.testNumber??t.activeTest,x=d?`${d} \xB7 #${p}`:ct(void 0,p),$=t.passFailDisplay==="spec"?"Limit pass/fail":a!==void 0&&!vt(a)?"Functional pass/fail":"Tester pass/fail";return{primary:x,secondary:$,...kt(a)}}return{primary:d??ct(void 0,t.activeTest),secondary:"",...kt(a)}}}}export function generateTextOverlay(t,e,n){const{plotMode:i,colorFns:s,normalize:a,activeTest:o,valueRange:r,testDefs:d,fallbackFormat:p,passFailDisplay:x="off",activeMetadataKey:$,metadataColorMap:V,allIntegerValues:I}=n,y=findTestDef(d,o),{tickFmt:B}=Bt(r[1],y?.name,y?.unit,p),f=I?m=>String(Math.round(m)):B,{testNumber:u}=resolveTestNumber(o,d);return t.flatMap((m,S)=>{let h="",b="#111111";if(i==="value"&&x==="test"){const g=U(m,u,y);if(g===void 0)return[];h=g?"P":"F",b=Q(g?Mt:St)}else if(i==="value"){const g=L(m,u);if(g===void 0)return[];h=Yt([g],f),b=Q(s.forValue(a(g)))}else if(i==="hardBin"||i==="softBin"){const g=i==="softBin"?m.sbin:m.hbin;if(g===void 0)return[];h=String(g),b=Q(s.forBin(g))}else if(i==="metadata"){const g=ut(m,$);if(g===void 0)return[];h=g,b=Q(V?.get(h)??z)}else{const g=L(m,0);if(g===void 0)return[];h=Yt([g],f),b=Q(s.forValue(a(g)))}const D=e?e[S*2]:m.physX,E=e?e[S*2+1]:m.physY;return[{x:D,y:E,text:h,fontSize:Xe(m,h),color:b,align:"center"}]})}function Gt(t){return t==="top"?Math.PI/2:t==="bottom"?-Math.PI/2:t==="left"?Math.PI:0}function Ge(t,e,n=720){const{center:i,radius:s,notch:a}=t,o=B=>G(e,B.x,B.y);if(!(a!==void 0&&t.diameter>150)){const B=[];for(let f=0;f<=n;f++){const u=2*Math.PI*f/n;B.push(o(ze(t,u)))}return[{kind:"wafer-boundary",...Y(B,!0),lineColor:"#888888",lineWidth:1}]}const d=1.25,p=a.length,x=Gt(a.type),$=Math.atan2(p,s),V=s-d,I=[];let y=!1;for(let B=0;B<=n;B++){const f=2*Math.PI*B/n;let u=f-x;for(;u>Math.PI;)u-=2*Math.PI;for(;u<-Math.PI;)u+=2*Math.PI;if(Math.abs(u)<=$){if(!y){y=!0;const m={x:i.x+s*Math.cos(x-$),y:i.y+s*Math.sin(x-$)},S={x:i.x+V*Math.cos(x),y:i.y+V*Math.sin(x)},h={x:i.x+s*Math.cos(x+$),y:i.y+s*Math.sin(x+$)};I.push(o(m),o(S),o(h))}continue}I.push(o({x:i.x+s*Math.cos(f),y:i.y+s*Math.sin(f)}))}return[{kind:"wafer-boundary",...Y(I,!0),lineColor:"#888888",lineWidth:1}]}function Qe(t,e,n,i=360){const s=[],a=Math.max(1,Math.floor(n));for(let o=1;o<a;o++){const r=t.radius*o/a,d=[];for(let p=0;p<=i;p++){const x=2*Math.PI*p/i,$={x:t.center.x+r*Math.cos(x),y:t.center.y+r*Math.sin(x)};d.push(G(e,$.x,$.y))}s.push({kind:"ring-boundary",...Y(d,!0),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5})}return s}function Ue(t,e,n,i){const{x:s,y:a}=t.center,o=t.radius,r=(f,u)=>G(e,f,u),d=n-s,p=Math.sqrt(Math.max(0,o*o-d*d)),x=r(n,a-p),$=r(n,a+p),V=i-a,I=Math.sqrt(Math.max(0,o*o-V*V)),y=r(s-I,i),B=r(s+I,i);return[{kind:"quadrant-boundary",...Y([x,$]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5},{kind:"quadrant-boundary",...Y([y,B]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5}]}function Je(t,e){return t.map(n=>{const i=n.width/2,s=n.height/2;return{kind:"reticle",points:[[[n.x-i,n.y-s],[n.x+i,n.y-s],[n.x+i,n.y+s],[n.x-i,n.y+s]].map(([o,r])=>G(e,o,r))],closed:!0,lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5,fill:"rgba(0,0,0,0)"}})}function Ze(t){const e=t.filter(n=>n.probeIndex!==void 0).sort((n,i)=>(n.probeIndex??0)-(i.probeIndex??0));return e.length?[{kind:"probe-path",...Y(e.map(n=>({x:n.physX,y:n.physY}))),lineColor:"rgba(220,80,0,0.55)",lineWidth:1}]:[]}function tn(t,e,n,i,s,a,o,r,d,p,x,$,V,I,y="off",B,f,u){const m=e.width-o,S=e.height-o,h=a?S:m,b=a?m:S,D=M=>s==="softBin"?M.sbin:M.hbin,E=M=>ut(M,B);if(e.partial){t.push({x:n,y:i,width:h,height:b,fill:qe,type:"stacked",metadata:e.metadata});return}if(e.edgeExcluded){t.push({x:n,y:i,width:h,height:b,fill:Ke,type:"stacked",metadata:e.metadata});return}if(d!==void 0&&(s==="hardBin"||s==="softBin")&&!d.has(D(e))){t.push({x:n,y:i,width:h,height:b,fill:Xt,type:"hardBin",metadata:e.metadata});return}if(u!==void 0&&s==="metadata"&&!u.has(E(e))){t.push({x:n,y:i,width:h,height:b,fill:Xt,type:"metadata",metadata:e.metadata});return}if(s==="value"){if(y==="test"){const q=U(e,x,I),ft=q===void 0?z:q?Mt:St;t.push({x:n,y:i,width:h,height:b,fill:ft,type:"value",metadata:e.metadata});return}const M=L(e,x),P=rt(M,I);let w,Z;M===void 0?w=z:y==="spec"?w=P==="failLow"?Ce:P==="failHigh"?St:Mt:(w=r.forValue(p(M)),(P==="failLow"||P==="failHigh")&&(Z=P)),t.push({x:n,y:i,width:h,height:b,fill:w,type:"value",specMark:Z,metadata:e.metadata});return}if(s==="hardBin"||s==="softBin"){const M=D(e),P=M!=null?r.forBin(M):z,w=M!=null&&Pe(e,V)===!1?!0:void 0;t.push({x:n,y:i,width:h,height:b,fill:P,type:s,binFail:w,metadata:e.metadata});return}if(s==="metadata"){const M=E(e),P=M!==void 0?f?.get(M)??z:z;t.push({x:n,y:i,width:h,height:b,fill:P,type:"metadata",metadata:e.metadata});return}const g=L(e,0),A=g!==void 0?r.forValue(p(g)):z;t.push({x:n,y:i,width:h,height:b,fill:A,type:"value",metadata:e.metadata})}function en(t,e,n){const i=t.radius;return Ee(e,i*.15,(s,a)=>({x:t.center.x+s*i*.9,y:t.center.y+a*i*.9}),n).overlays}export function buildView(t,e,n={},i){const s=n.reticles??[],{plotMode:a="value",showDieLabels:o=!1,showReticle:r=!1,showProbePath:d=!1,ringCount:p,showRingBoundaries:x=!1,showQuadrantBoundaries:$=!1,showXYIndicator:V=!1,binColorScheme:I="default",valueColorScheme:y="default",reverseValueScheme:B=!1,useDefinedBinColors:f=!0,binColors:u,passBins:m,highlightBin:S,highlightMetadataValue:h,interactiveTransform:b,valueRange:D,metadataValueOrder:E,testDefs:g,activeTest:A=0,activeMetadataKey:M,fallbackFormat:P="engineering",aggregationMethod:w,lotSize:Z,dataAxisFlip:q,isLotStack:ft=!1,logScale:Qt,colorbarRangeMode:Ut="spec",passFailDisplay:Jt}=n,It=Jt??"off",dt=i?.hbinDefs,ht=i?.sbinDefs,Tt=i?.metadataFields,Zt=Tt?.find(l=>l.key===M),te={x:(q?.x??!1)!==(b?.flipX??!1),y:(q?.y??!1)!==(b?.flipY??!1)},ee=dt?new Map(dt.map(l=>[l.bin,l])):null,ne=ht?new Map(ht.map(l=>[l.bin,l])):null,ae=a==="softBin"?ne:ee,Dt=ge({passBins:m},"buildView"),ie=new Set(Dt),mt=u&&Re(u,e)?u:Le(e,{passBins:Dt,binColorScheme:I,hbinDefs:dt,sbinDefs:ht,useDefinedBinColors:f}),se=a==="softBin"?mt.soft:mt.hard,Vt={forValue:je(Fe(y,B)),forBin:l=>se.get(l)??z};let{testNumber:H}=resolveTestNumber(A,g);if(!g?.length&&a==="value"){const l=Ot(e,"values");!l.includes(H)&&l.length&&(H=l[0])}let tt;if(Array.isArray(D))tt=D;else if(D){const{testNumber:l}=resolveTestNumber(D.test,g);tt=l===H?D.range:void 0}const T=findTestDef(g,H),Ct=a==="value"&&T!==void 0&&!vt(T),oe=T!==void 0&&(T.limitLow!==void 0||T.limitHigh!==void 0);let O="off";a==="value"&&(Ct?O="test":It==="spec"&&oe?O="spec":It==="test"&&e.some(l=>U(l,H,T)!==void 0)&&(O="test"));const Ft=O==="spec"?"spec":Ut,pt=a==="stackedValues"||a==="stackedBins"||a==="stackedSoftBins";let N,_,et=!1;if(tt){[N,_]=tt;let l=!0,c=!1;for(const v of e){const F=pt?L(v,0):L(v,H);if(F!==void 0&&(c=!0,!Number.isInteger(F))){l=!1;break}}et=c&&l}else{const l=!pt&&a==="value"&&Ft==="spec"&&T&&(T.limitLow!==void 0||T.limitHigh!==void 0);let c=1/0,v=-1/0,F=!0;for(const k of e){const W=pt?L(k,0):L(k,H);W!==void 0&&(W<c&&(c=W),W>v&&(v=W),Number.isInteger(W)||(F=!1))}isFinite(c)||(F=!1),et=F,l?(N=T.limitLow!==void 0?T.limitLow:isFinite(c)?c:0,_=T.limitHigh!==void 0?T.limitHigh:isFinite(v)?v:1):(N=isFinite(c)?c:0,_=isFinite(v)?v:1)}N===_&&(_=N+1);const Lt=Ct?!1:Qt??T?.logScale??!1,Rt=Lt&&N>0&&_>0,re=Rt;let nt;if(Rt){const l=Math.log10(N),c=Math.log10(_)-l;nt=v=>v<=0?0:Wt((Math.log10(v)-l)/c)}else nt=l=>Wt((l-N)/(_-N));const C=We(t,q,b);let Pt=null;if(t.notch){const l=Gt(t.notch.type),c=De(C.physicalToScreen,Math.cos(l)*t.radius,Math.sin(l)*t.radius),v=Math.hypot(c.x,c.y);v>0&&(Pt={x:c.x/v,y:c.y/v})}let j=1/0;for(let l=0;l<e.length;l++){const c=e[l];c.width<j&&(j=c.width),c.height<j&&(j=c.height)}const Nt=1,le=j!==1/0?Math.min(Nt,j*.12):Nt,Et=[],gt=[],ce=C.bakedToScreen.a===1&&C.bakedToScreen.b===0&&C.bakedToScreen.c===0&&C.bakedToScreen.d===1&&C.bakedToScreen.e===0&&C.bakedToScreen.f===0;let K=null;if(!ce){K=new Float64Array(e.length*2);for(let l=0;l<e.length;l++){const c=G(C.bakedToScreen,e[l].physX,e[l].physY);K[l*2]=c.x,K[l*2+1]=c.y}}const ue=Ve(C.gridToScreen),fe=a==="hardBin"||a==="softBin"||a==="stackedBins"||a==="stackedSoftBins",de=a==="softBin"||a==="stackedSoftBins";let at=fe?new Map:void 0;const yt=a==="value"&&O==="spec"?{pass:0,failHigh:0,failLow:0}:void 0,bt=a==="value"&&O==="test"?{pass:0,fail:0}:void 0,At=a==="metadata";let it=At?new Map:void 0,st=null;if(At&&M){const l=collectMetadataValues(e,M),c=E?.key===M?E.values:void 0,v=c?[...c,...l.filter(F=>!c.includes(F))]:l;st=new Map(v.map((F,k)=>[F,Zt?.values?.find(W=>W.value===F)?.color??Ae(k)]))}const he=S===void 0?void 0:new Set(Kt(S)),me=h===void 0?void 0:new Set(Kt(h));for(let l=0;l<e.length;l++){const c=e[l],v=K?K[l*2]:c.physX,F=K?K[l*2+1]:c.physY;if(gt.push({x:v,y:F}),at&&!c.partial&&!c.edgeExcluded){const k=de?c.sbin:c.hbin;k!=null&&at.set(k,(at.get(k)??0)+1)}if(yt&&!c.partial&&!c.edgeExcluded){const k=rt(L(c,H),T);k&&yt[k]++}if(bt&&!c.partial&&!c.edgeExcluded){const k=U(c,H,T);k!==void 0&&bt[k?"pass":"fail"]++}if(it&&!c.partial&&!c.edgeExcluded){const k=ut(c,M);k!==void 0&&it.set(k,(it.get(k)??0)+1)}tn(Et,c,v,F,a,ue,le,Vt,he,nt,H,ae,ie,T,O,M,st,me)}const Ht=o?generateTextOverlay(e,K,{plotMode:a,colorFns:Vt,normalize:nt,activeTest:A,valueRange:[N,_],testDefs:g,fallbackFormat:P,passFailDisplay:O,activeMetadataKey:M,metadataColorMap:st,allIntegerValues:et}):[],X=Ge(t,C.physicalToScreen);x&&X.push(...Qe(t,C.physicalToScreen,ye({ringCount:p},"buildView"))),$&&X.push(...Ue(t,C.physicalToScreen,t.center.x,t.center.y)),r&&X.push(...Je(s,C.gridToScreen)),d&&X.push(...Ze(e)),V&&X.push(...en(t,C.gridToScreen,Ht));const pe=gt.length>0?{minX:t.center.x-t.radius,maxX:t.center.x+t.radius,minY:t.center.y-t.radius,maxY:t.center.y+t.radius}:null,_t={rectangles:Et,hoverPoints:gt,texts:Ht,overlays:X,plotMode:a,binColorScheme:I,valueColorScheme:y,reverseValueScheme:B,binColors:mt,metadata:t.metadata??null,dies:e,valueRange:[N,_],allIntegerValues:et,testDefs:g,activeTest:A,logScale:re,logScaleRequested:Lt,aggrMethod:w,lotSize:Z,axisFlip:te,dataAxisFlip:{x:q?.x??!1,y:q?.y??!1},gridToScreen:C.gridToScreen,rotation:((t.orientation+(b?.rotation??0))%360+360)%360,hasReticle:s.length>0,isLotStack:ft,passFailDisplay:O,colorbarRangeMode:Ft,waferCenter:t.center,waferRadius:t.radius,notchDir:Pt,binCounts:at,metadataCounts:it,metadataColorMap:st,activeMetadataKey:M,metadataFields:Tt,specCounts:yt,passFailCounts:bt,dieBounds:pe};return n.compact?Ne(_t,n.compact,{showXYIndicator:V}):_t}export{getDieKey}from"../core/dies.js";
1
+ import{requirePassBins as ge}from"../core/passBins.js";import{requireRingCount as ye}from"../core/ringCount.js";import{hasPosition as be}from"../core/dies.js";import{dieValueEntries as xe,dieVerdictEntries as Me,excludedBy as Se,excludedValue as ve,recordedVerdict as Be,testsPresent as wt}from"../core/dieTable.js";import{limitSetName as $e}from"./valueFilter.js";import{getReticleCell as ke}from"../core/reticle.js";import{metadataCategoricalValue as Ie,metadataDisplayValue as Te}from"../core/metadata.js";import{affineRotation as xt,affineMirror as qt,affineCompose as ot,affinePoint as Y,affineVector as De,affineSwapsAxes as Ve}from"../core/transforms.js";import{contrastTextColor as Q,SPEC_PASS_FILL as Mt,SPEC_FAIL_LOW as Ce,SPEC_FAIL_HIGH as St}from"./colorMap.js";import{resolveValueColorFn as Fe}from"./colorSchemes.js";import{resolveBinColors as Le,binColorsCover as Re}from"./binColors.js";import{NO_DATA_FILL as z}from"./colorMap.js";import{diePassStatus as Pe}from"../core/dies.js";import{compactView as Ne}from"./compactView.js";import{buildXYIndicator as Ee}from"./xyIndicator.js";import{getDieTestValue as L,getTestPassStatus as U,isParametricTest as vt}from"./buildWaferMap.js";import{classifySpec as rt}from"./spec.js";export{rt as classifySpec};import{fmt as lt,fmtColorbarAxis as Bt,fmtAggregationMethod as Kt}from"./fmt.js";import{metadataValueColor as Ae}from"./colorMap.js";import{asList as Wt,clamp01 as zt,compareNatural as He,escHtml as R}from"../core/utils.js";import{prettyKey as jt}from"../core/utils.js";import{testLabel as ct,markedTestLabel as J,derivedTestNote as Gt,isDerivedTest as _e,DERIVED_MARK as Oe,DERIVED_KEY as we}from"./testLabel.js";export function resolveTestNumber(t,e){return e?.length?{testNumber:(findTestDef(e,t)??e[0]).testNumber}:{testNumber:t}}export function collectMetadataValues(t,e){const n=new Set;for(const i of t){if(i.partial||i.edgeExcluded)continue;const s=ut(i,e);s!==void 0&&n.add(s)}return[...n].sort(He)}export function findTestDef(t,e){return t?.find(n=>n.testNumber===e)}export function getUniqueTestNumbers(t){return wt(t,"values")}const qe="#d3d6db",Xt="#e8e9ea",Ke="#aab0ba";function ut(t,e){return e?Ie(t.metadata?.[e]):void 0}function We(t,e,n){const{x:i,y:s}=t.center,a=xt(t.orientation,i,s),o=ot(qt(e?.x??!1,e?.y??!1,i,s),xt(t.orientation,i,s)),r=ot(qt(n?.flipX??!1,n?.flipY??!1,i,s),xt(n?.rotation??0,i,s));return{bakedToScreen:r,physicalToScreen:ot(r,a),gridToScreen:ot(r,o)}}function X(t,e=!1){return{points:[t],closed:e}}function ze(t,e){const{center:n,radius:i,notch:s}=t;let a=n.x+i*Math.cos(e),o=n.y+i*Math.sin(e);if(!s)return{x:a,y:o};const r=Math.sqrt(i**2-(s.length/2)**2),d=s.length/2,p=a-n.x,x=o-n.y;return s.type==="bottom"&&x<-r?(o=n.y-r,a=n.x+Math.max(-d,Math.min(d,p))):s.type==="top"&&x>r?(o=n.y+r,a=n.x+Math.max(-d,Math.min(d,p))):s.type==="left"&&p<-r?(a=n.x-r,o=n.y+Math.max(-d,Math.min(d,x))):s.type==="right"&&p>r&&(a=n.x+r,o=n.y+Math.max(-d,Math.min(d,x))),{x:a,y:o}}function Yt(t,e){return t.map(e).join(" / ")}function je(t,e=256){const n=Array.from({length:e},(i,s)=>t(s/(e-1)));return i=>n[Math.min(e-1,Math.max(0,Math.round(i*(e-1))))]}function Ge(t,e){const n=Math.max(1,Math.min(t.width,t.height)),i=t.width/Math.max(e.length,1);return Math.max(8,Math.min(16,Math.round(Math.min(n*.55,i*1.8))))}function Xe(t,e,n){if(e?.length){const a=e.flatMap(o=>{const r=o.testNumber;if(!vt(o)){const p=U(t,r,o);return p===void 0?[]:[{key:r,label:J(o,r),value:p?"Pass":"Fail"}]}const d=L(t,r);if(d===void 0){const p=ve(t,r);return p===void 0?[]:[{key:r,label:J(o,r),value:lt(p,o.unit,n),excludedBy:Se(t)}]}return[{key:r,label:J(o,r),value:lt(d,o.unit,n),recordedFail:Be(t,r)===!1}]});if(a.length)return a}const i=xe(t);if(i.length)return i.map(([a,o])=>({key:a,label:ct(void 0,a),value:lt(o,void 0,n)}));const s=Me(t);return s.length?s.map(([a,o])=>({key:a,label:ct(void 0,a),value:o?"Pass":"Fail"})):[]}export function buildHoverText(t,e,n={}){const{testDefs:i,hbinDefs:s,sbinDefs:a,fallbackFormat:o,aggrMethod:r,lotSize:d,activeTest:p,reticleConfig:x,metadataFields:$}=n,V=s?new Map(s.map(f=>[f.bin,f])):null,I=a?new Map(a.map(f=>[f.bin,f])):null,y=[R(`Die (${t.x}, ${t.y})`)];if(x&&be(t)){const f=ke(t,x);y.push(R(`Reticle (${f.column}, ${f.row})`))}if(e==="stackedValues"){const f=L(t,0);if(f!==void 0){const u=i?.[0],m=u?J(u,u.testNumber):"Value",S=r?` (${r})`:"";y.push(R(`${m}${S}: ${lt(f,u?.unit,o)}`));const h=Gt(u);h&&y.push(`<i>${R(h)}</i>`)}}else if(e==="stackedBins"||e==="stackedSoftBins"){const f=L(t,0),u=e==="stackedSoftBins"?t.sbin:t.hbin;if(f!==void 0){const m=e==="stackedSoftBins"?I:V,S=u!==void 0?m?.get(u)?.name?`${u} \xB7 ${m.get(u).name}`:`Bin ${u}`:"Bin";let h;if(r==="percent")h=`${f.toFixed(0)}%`;else{const D=d?` (${(f/d*100).toFixed(0)}% of stacked wafers)`:"";h=`${f}${D}`}const b=r?` [${Kt(r)}]`:"";y.push(R(`${S}: ${h}${b}`))}}else{const f=Xe(t,i,o);if(e==="value"&&f.length){const{testNumber:u}=resolveTestNumber(p??0,i),m=findTestDef(i,u),S=L(t,u);let h=f.findIndex(A=>A.key===u);h<0&&(h=0);const b=f[h];let D=`<b>${R(`${b.label}: ${b.value}`)}${b.recordedFail?" <i>(recorded fail)</i>":""}</b>`;if(b.key===u&&m){const A=rt(S,m);(A==="failLow"||A==="failHigh")&&(D+=" <i>(outside test limits)</i>")}b.excludedBy&&(D+=` <i>(outside ${$e(b.excludedBy)}, excluded)</i>`),y.push(D);const E=Gt(findTestDef(i,b.key));E&&y.push(`<i>${R(E)}</i>`);const g=f.length-1;g>0&&y.push(`<i>+${g} more test${g===1?"":"s"}</i>`)}else if(f.length){const u=f.length;y.push(`<i>${u} test result${u===1?"":"s"} recorded</i>`)}if(t.hbin!==void 0||t.sbin!==void 0){const u=[];if(t.hbin!==void 0){const m=V?.get(t.hbin)?.name,S=m?`${t.hbin} \xB7 ${m}`:String(t.hbin);u.push(`HBin: ${S}`)}if(t.sbin!==void 0){const m=I?.get(t.sbin)?.name,S=m?`${t.sbin} \xB7 ${m}`:String(t.sbin);u.push(`SBin: ${S}`)}y.push(u.map(R).join(" &nbsp;\xB7&nbsp; "))}}t.retestCount!==void 0&&y.push(R(`Retests: ${t.retestCount}`)),t.siteNum!==void 0&&y.push(R(`Site: ${t.siteNum}`)),t.partId!==void 0&&y.push(R(`Part ID: ${t.partId}`)),t.partial&&y.push("<i>partial die</i>"),t.probeIndex!==void 0&&y.push(R(`Probe: #${t.probeIndex}`));const B={...t.metadata??{}};for(const[f,u]of Object.entries(B)){const m=Te(u);if(m===void 0)continue;const S=$?.find(h=>h.key===f)?.label??jt(f);y.push(R(`${S}: ${m}`))}return y.join("<br>")}function $t(t){return t?.name?J(t,t.testNumber):void 0}function kt(t){return _e(t)?{note:`${Oe} ${we}`}:{}}export function buildMapTitle(t,e="engineering",n){const i=t.isLotStack&&t.lotSize!==void 0?`stacked (${t.lotSize} ${t.lotSize===1?"wafer":"wafers"})`:"stacked",s=a=>{const o=n?.length===1?n[0]:void 0;return o===void 0?`${a} Bin`:o.name?`${a} Bin ${o.bin} \xB7 ${o.name}`:`${a} Bin ${o.bin}`};switch(t.plotMode){case"hardBin":return{primary:"Hard Bin",secondary:""};case"softBin":return{primary:"Soft Bin",secondary:""};case"stackedBins":return{primary:s("Hard"),secondary:i};case"stackedSoftBins":return{primary:s("Soft"),secondary:i};case"metadata":{const a=t.metadataFields?.find(r=>r.key===t.activeMetadataKey),o=t.activeMetadataKey?jt(t.activeMetadataKey):"Metadata";return{primary:a?.label??o,secondary:""}}case"stackedValues":{const a=t.testDefs?.[0],o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=Bt(o,$t(a),a?.unit,e),d=r||"Value",p=t.aggrMethod?` \xB7 ${Kt(t.aggrMethod)}`:"";return{primary:`${d}${p}`,secondary:i,...kt(a)}}default:{const a=findTestDef(t.testDefs,t.activeTest),o=t.valueRange[1]||t.valueRange[0]||0,{axisLabel:r}=Bt(o,$t(a),a?.unit,e),d=r||$t(a);if(t.passFailDisplay!=="off"){const p=a?.testNumber??t.activeTest,x=d?`${d} \xB7 #${p}`:ct(void 0,p),$=t.passFailDisplay==="spec"?"Limit pass/fail":a!==void 0&&!vt(a)?"Functional pass/fail":"Tester pass/fail";return{primary:x,secondary:$,...kt(a)}}return{primary:d??ct(void 0,t.activeTest),secondary:"",...kt(a)}}}}export function generateTextOverlay(t,e,n){const{plotMode:i,colorFns:s,normalize:a,activeTest:o,valueRange:r,testDefs:d,fallbackFormat:p,passFailDisplay:x="off",activeMetadataKey:$,metadataColorMap:V,allIntegerValues:I}=n,y=findTestDef(d,o),{tickFmt:B}=Bt(r[1],y?.name,y?.unit,p),f=I?m=>String(Math.round(m)):B,{testNumber:u}=resolveTestNumber(o,d);return t.flatMap((m,S)=>{let h="",b="#111111";if(i==="value"&&x==="test"){const g=U(m,u,y);if(g===void 0)return[];h=g?"P":"F",b=Q(g?Mt:St)}else if(i==="value"){const g=L(m,u);if(g===void 0)return[];h=Yt([g],f),b=Q(s.forValue(a(g)))}else if(i==="hardBin"||i==="softBin"){const g=i==="softBin"?m.sbin:m.hbin;if(g===void 0)return[];h=String(g),b=Q(s.forBin(g))}else if(i==="metadata"){const g=ut(m,$);if(g===void 0)return[];h=g,b=Q(V?.get(h)??z)}else{const g=L(m,0);if(g===void 0)return[];h=Yt([g],f),b=Q(s.forValue(a(g)))}const D=e?e[S*2]:m.physX,E=e?e[S*2+1]:m.physY;return[{x:D,y:E,text:h,fontSize:Ge(m,h),color:b,align:"center"}]})}function Qt(t){return t==="top"?Math.PI/2:t==="bottom"?-Math.PI/2:t==="left"?Math.PI:0}function Ye(t,e,n=720){const{center:i,radius:s,notch:a}=t,o=B=>Y(e,B.x,B.y);if(!(a!==void 0&&a.length>0&&t.diameter>150)){const B=[];for(let f=0;f<=n;f++){const u=2*Math.PI*f/n;B.push(o(ze(t,u)))}return[{kind:"wafer-boundary",...X(B,!0),lineColor:"#888888",lineWidth:1}]}const d=1.25,p=a.length,x=Qt(a.type),$=Math.atan2(p,s),V=s-d,I=[];let y=!1;for(let B=0;B<=n;B++){const f=2*Math.PI*B/n;let u=f-x;for(;u>Math.PI;)u-=2*Math.PI;for(;u<-Math.PI;)u+=2*Math.PI;if(Math.abs(u)<=$){if(!y){y=!0;const m={x:i.x+s*Math.cos(x-$),y:i.y+s*Math.sin(x-$)},S={x:i.x+V*Math.cos(x),y:i.y+V*Math.sin(x)},h={x:i.x+s*Math.cos(x+$),y:i.y+s*Math.sin(x+$)};I.push(o(m),o(S),o(h))}continue}I.push(o({x:i.x+s*Math.cos(f),y:i.y+s*Math.sin(f)}))}return[{kind:"wafer-boundary",...X(I,!0),lineColor:"#888888",lineWidth:1}]}function Qe(t,e,n,i=360){const s=[],a=Math.max(1,Math.floor(n));for(let o=1;o<a;o++){const r=t.radius*o/a,d=[];for(let p=0;p<=i;p++){const x=2*Math.PI*p/i,$={x:t.center.x+r*Math.cos(x),y:t.center.y+r*Math.sin(x)};d.push(Y(e,$.x,$.y))}s.push({kind:"ring-boundary",...X(d,!0),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5})}return s}function Ue(t,e,n,i){const{x:s,y:a}=t.center,o=t.radius,r=(f,u)=>Y(e,f,u),d=n-s,p=Math.sqrt(Math.max(0,o*o-d*d)),x=r(n,a-p),$=r(n,a+p),V=i-a,I=Math.sqrt(Math.max(0,o*o-V*V)),y=r(s-I,i),B=r(s+I,i);return[{kind:"quadrant-boundary",...X([x,$]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5},{kind:"quadrant-boundary",...X([y,B]),lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5}]}function Je(t,e){return t.map(n=>{const i=n.width/2,s=n.height/2;return{kind:"reticle",points:[[[n.x-i,n.y-s],[n.x+i,n.y-s],[n.x+i,n.y+s],[n.x-i,n.y+s]].map(([o,r])=>Y(e,o,r))],closed:!0,lineColor:"rgba(255,255,255,0.7)",lineWidth:1.5,fill:"rgba(0,0,0,0)"}})}function Ze(t){const e=t.filter(n=>n.probeIndex!==void 0).sort((n,i)=>(n.probeIndex??0)-(i.probeIndex??0));return e.length?[{kind:"probe-path",...X(e.map(n=>({x:n.physX,y:n.physY}))),lineColor:"rgba(220,80,0,0.55)",lineWidth:1}]:[]}function tn(t,e,n,i,s,a,o,r,d,p,x,$,V,I,y="off",B,f,u){const m=e.width-o,S=e.height-o,h=a?S:m,b=a?m:S,D=M=>s==="softBin"?M.sbin:M.hbin,E=M=>ut(M,B);if(e.partial){t.push({x:n,y:i,width:h,height:b,fill:qe,type:"stacked",metadata:e.metadata});return}if(e.edgeExcluded){t.push({x:n,y:i,width:h,height:b,fill:Ke,type:"stacked",metadata:e.metadata});return}if(d!==void 0&&(s==="hardBin"||s==="softBin")&&!d.has(D(e))){t.push({x:n,y:i,width:h,height:b,fill:Xt,type:"hardBin",metadata:e.metadata});return}if(u!==void 0&&s==="metadata"&&!u.has(E(e))){t.push({x:n,y:i,width:h,height:b,fill:Xt,type:"metadata",metadata:e.metadata});return}if(s==="value"){if(y==="test"){const q=U(e,x,I),ft=q===void 0?z:q?Mt:St;t.push({x:n,y:i,width:h,height:b,fill:ft,type:"value",metadata:e.metadata});return}const M=L(e,x),P=rt(M,I);let w,Z;M===void 0?w=z:y==="spec"?w=P==="failLow"?Ce:P==="failHigh"?St:Mt:(w=r.forValue(p(M)),(P==="failLow"||P==="failHigh")&&(Z=P)),t.push({x:n,y:i,width:h,height:b,fill:w,type:"value",specMark:Z,metadata:e.metadata});return}if(s==="hardBin"||s==="softBin"){const M=D(e),P=M!=null?r.forBin(M):z,w=M!=null&&Pe(e,V)===!1?!0:void 0;t.push({x:n,y:i,width:h,height:b,fill:P,type:s,binFail:w,metadata:e.metadata});return}if(s==="metadata"){const M=E(e),P=M!==void 0?f?.get(M)??z:z;t.push({x:n,y:i,width:h,height:b,fill:P,type:"metadata",metadata:e.metadata});return}const g=L(e,0),A=g!==void 0?r.forValue(p(g)):z;t.push({x:n,y:i,width:h,height:b,fill:A,type:"value",metadata:e.metadata})}function en(t,e,n){const i=t.radius;return Ee(e,i*.15,(s,a)=>({x:t.center.x+s*i*.9,y:t.center.y+a*i*.9}),n).overlays}export function buildView(t,e,n={},i){const s=n.reticles??[],{plotMode:a="value",showDieLabels:o=!1,showReticle:r=!1,showProbePath:d=!1,ringCount:p,showRingBoundaries:x=!1,showQuadrantBoundaries:$=!1,showXYIndicator:V=!1,binColorScheme:I="default",valueColorScheme:y="default",reverseValueScheme:B=!1,useDefinedBinColors:f=!0,binColors:u,passBins:m,highlightBin:S,highlightMetadataValue:h,interactiveTransform:b,valueRange:D,metadataValueOrder:E,testDefs:g,activeTest:A=0,activeMetadataKey:M,fallbackFormat:P="engineering",aggregationMethod:w,lotSize:Z,dataAxisFlip:q,isLotStack:ft=!1,logScale:Ut,colorbarRangeMode:Jt="spec",passFailDisplay:Zt}=n,It=Zt??"off",dt=i?.hbinDefs,ht=i?.sbinDefs,Tt=i?.metadataFields,te=Tt?.find(l=>l.key===M),ee={x:(q?.x??!1)!==(b?.flipX??!1),y:(q?.y??!1)!==(b?.flipY??!1)},ne=dt?new Map(dt.map(l=>[l.bin,l])):null,ae=ht?new Map(ht.map(l=>[l.bin,l])):null,ie=a==="softBin"?ae:ne,Dt=ge({passBins:m},"buildView"),se=new Set(Dt),mt=u&&Re(u,e)?u:Le(e,{passBins:Dt,binColorScheme:I,hbinDefs:dt,sbinDefs:ht,useDefinedBinColors:f}),oe=a==="softBin"?mt.soft:mt.hard,Vt={forValue:je(Fe(y,B)),forBin:l=>oe.get(l)??z};let{testNumber:H}=resolveTestNumber(A,g);if(!g?.length&&a==="value"){const l=wt(e,"values");!l.includes(H)&&l.length&&(H=l[0])}let tt;if(Array.isArray(D))tt=D;else if(D){const{testNumber:l}=resolveTestNumber(D.test,g);tt=l===H?D.range:void 0}const T=findTestDef(g,H),Ct=a==="value"&&T!==void 0&&!vt(T),re=T!==void 0&&(T.limitLow!==void 0||T.limitHigh!==void 0);let O="off";a==="value"&&(Ct?O="test":It==="spec"&&re?O="spec":It==="test"&&e.some(l=>U(l,H,T)!==void 0)&&(O="test"));const Ft=O==="spec"?"spec":Jt,pt=a==="stackedValues"||a==="stackedBins"||a==="stackedSoftBins";let N,_,et=!1;if(tt){[N,_]=tt;let l=!0,c=!1;for(const v of e){const F=pt?L(v,0):L(v,H);if(F!==void 0&&(c=!0,!Number.isInteger(F))){l=!1;break}}et=c&&l}else{const l=!pt&&a==="value"&&Ft==="spec"&&T&&(T.limitLow!==void 0||T.limitHigh!==void 0);let c=1/0,v=-1/0,F=!0;for(const k of e){const W=pt?L(k,0):L(k,H);W!==void 0&&(W<c&&(c=W),W>v&&(v=W),Number.isInteger(W)||(F=!1))}isFinite(c)||(F=!1),et=F,l?(N=T.limitLow!==void 0?T.limitLow:isFinite(c)?c:0,_=T.limitHigh!==void 0?T.limitHigh:isFinite(v)?v:1):(N=isFinite(c)?c:0,_=isFinite(v)?v:1)}N===_&&(_=N+1);const Lt=Ct?!1:Ut??T?.logScale??!1,Rt=Lt&&N>0&&_>0,le=Rt;let nt;if(Rt){const l=Math.log10(N),c=Math.log10(_)-l;nt=v=>v<=0?0:zt((Math.log10(v)-l)/c)}else nt=l=>zt((l-N)/(_-N));const C=We(t,q,b);let Pt=null;if(t.notch){const l=Qt(t.notch.type),c=De(C.physicalToScreen,Math.cos(l)*t.radius,Math.sin(l)*t.radius),v=Math.hypot(c.x,c.y);v>0&&(Pt={x:c.x/v,y:c.y/v})}let j=1/0;for(let l=0;l<e.length;l++){const c=e[l];c.width<j&&(j=c.width),c.height<j&&(j=c.height)}const Nt=1,Et=j!==1/0?Math.min(Nt,j*.12):Nt,At=[],gt=[],ce=C.bakedToScreen.a===1&&C.bakedToScreen.b===0&&C.bakedToScreen.c===0&&C.bakedToScreen.d===1&&C.bakedToScreen.e===0&&C.bakedToScreen.f===0;let K=null;if(!ce){K=new Float64Array(e.length*2);for(let l=0;l<e.length;l++){const c=Y(C.bakedToScreen,e[l].physX,e[l].physY);K[l*2]=c.x,K[l*2+1]=c.y}}const ue=Ve(C.gridToScreen),fe=a==="hardBin"||a==="softBin"||a==="stackedBins"||a==="stackedSoftBins",de=a==="softBin"||a==="stackedSoftBins";let at=fe?new Map:void 0;const yt=a==="value"&&O==="spec"?{pass:0,failHigh:0,failLow:0}:void 0,bt=a==="value"&&O==="test"?{pass:0,fail:0}:void 0,Ht=a==="metadata";let it=Ht?new Map:void 0,st=null;if(Ht&&M){const l=collectMetadataValues(e,M),c=E?.key===M?E.values:void 0,v=c?[...c,...l.filter(F=>!c.includes(F))]:l;st=new Map(v.map((F,k)=>[F,te?.values?.find(W=>W.value===F)?.color??Ae(k)]))}const he=S===void 0?void 0:new Set(Wt(S)),me=h===void 0?void 0:new Set(Wt(h));for(let l=0;l<e.length;l++){const c=e[l],v=K?K[l*2]:c.physX,F=K?K[l*2+1]:c.physY;if(gt.push({x:v,y:F}),at&&!c.partial&&!c.edgeExcluded){const k=de?c.sbin:c.hbin;k!=null&&at.set(k,(at.get(k)??0)+1)}if(yt&&!c.partial&&!c.edgeExcluded){const k=rt(L(c,H),T);k&&yt[k]++}if(bt&&!c.partial&&!c.edgeExcluded){const k=U(c,H,T);k!==void 0&&bt[k?"pass":"fail"]++}if(it&&!c.partial&&!c.edgeExcluded){const k=ut(c,M);k!==void 0&&it.set(k,(it.get(k)??0)+1)}tn(At,c,v,F,a,ue,Et,Vt,he,nt,H,ie,se,T,O,M,st,me)}const _t=o?generateTextOverlay(e,K,{plotMode:a,colorFns:Vt,normalize:nt,activeTest:A,valueRange:[N,_],testDefs:g,fallbackFormat:P,passFailDisplay:O,activeMetadataKey:M,metadataColorMap:st,allIntegerValues:et}):[],G=Ye(t,C.physicalToScreen);x&&G.push(...Qe(t,C.physicalToScreen,ye({ringCount:p},"buildView"))),$&&G.push(...Ue(t,C.physicalToScreen,t.center.x,t.center.y)),r&&G.push(...Je(s,C.gridToScreen)),d&&G.push(...Ze(e)),V&&G.push(...en(t,C.gridToScreen,_t));const pe=gt.length>0?{minX:t.center.x-t.radius,maxX:t.center.x+t.radius,minY:t.center.y-t.radius,maxY:t.center.y+t.radius}:null,Ot={rectangles:At,dieGap:Et,hoverPoints:gt,texts:_t,overlays:G,plotMode:a,binColorScheme:I,valueColorScheme:y,reverseValueScheme:B,binColors:mt,metadata:t.metadata??null,dies:e,valueRange:[N,_],allIntegerValues:et,testDefs:g,activeTest:A,logScale:le,logScaleRequested:Lt,aggrMethod:w,lotSize:Z,axisFlip:ee,dataAxisFlip:{x:q?.x??!1,y:q?.y??!1},gridToScreen:C.gridToScreen,rotation:((t.orientation+(b?.rotation??0))%360+360)%360,hasReticle:s.length>0,isLotStack:ft,passFailDisplay:O,colorbarRangeMode:Ft,waferCenter:t.center,waferRadius:t.radius,notchDir:Pt,binCounts:at,metadataCounts:it,metadataColorMap:st,activeMetadataKey:M,metadataFields:Tt,specCounts:yt,passFailCounts:bt,dieBounds:pe};return n.compact?Ne(Ot,n.compact,{showXYIndicator:V}):Ot}export{getDieKey}from"../core/dies.js";
@@ -583,9 +583,15 @@ export interface WaferWarning {
583
583
  * lands in ring 1 — and ring/quadrant/edge findings then describe the assumed
584
584
  * wafer, not the probed area. A genuinely partial map looks identical and is
585
585
  * equally worth reporting, so the message names both causes.
586
- * - `'test-count-capped'` — raised by `analyzeWaferMap`: more tests were found in
587
- * the die data than the analysis cap allows, so test-value analysis was skipped
588
- * entirely and NO test findings were produced. Pass `testNumbers` to scope it.
586
+ * - `'implausible-center'` — a supplied `waferConfig.center`, with no diameter, lies
587
+ * more than the dies' own span outside their bounding box on either axis. It
588
+ * was ignored and the centre inferred from the dies, since sizing the wafer to
589
+ * reach the dies from it would draw a wafer many times the die extent. Typical
590
+ * source: a placeholder centre in a tester's WCR record. Supply
591
+ * `waferConfig.diameter` too if the centre is real.
592
+ * - `'test-count-capped'` — no longer raised. A skipped test-value analysis is
593
+ * recorded in `StatsSummary.stats.testValueAnalysis` and offered in the
594
+ * renderers' Findings section instead.
589
595
  * - `'analysis-option-corrected'` — raised by `analyzeWaferMap` (or `buildWaferMap`, for `ringCount`): a numeric option
590
596
  * was outside the range that can produce a meaningful analysis and was clamped.
591
597
  * The message names each correction. Only reachable from untyped callers now
@@ -641,7 +647,7 @@ export interface WaferWarning {
641
647
  * The union is intentionally open to string so future advisory codes can be
642
648
  * added without a breaking change; switch with a `default` branch.
643
649
  */
644
- code: 'partial-coverage' | 'geometry-conflict' | 'non-standard-diameter' | 'diameter-exceeds-die-extent' | 'test-count-capped' | 'edge-exclusion-exceeds-radius' | 'analysis-option-corrected' | 'bin-colors-shared' | 'pass-bins-mixed' | 'ring-count-mixed' | 'input-field-removed' | 'input-values-not-numbers' | 'input-values-outside-stdf' | 'retests-by-part-id' | 'derived-test-invalid' | 'values-excluded' | (string & {});
650
+ code: 'partial-coverage' | 'geometry-conflict' | 'non-standard-diameter' | 'diameter-exceeds-die-extent' | 'test-count-capped' | 'edge-exclusion-exceeds-radius' | 'analysis-option-corrected' | 'bin-colors-shared' | 'pass-bins-mixed' | 'ring-count-mixed' | 'input-field-removed' | 'input-values-not-numbers' | 'input-values-outside-stdf' | 'retests-by-part-id' | 'derived-test-invalid' | 'values-excluded' | 'implausible-center' | (string & {});
645
651
  /** Human-readable explanation, suitable for direct display. */
646
652
  message: string;
647
653
  /**
@@ -830,6 +836,15 @@ export declare function testPassStatusReader(testDefs: readonly TestDef[]): (die
830
836
  * availability checks.
831
837
  */
832
838
  export declare function dieHasTestData(die: Pick<Die, 'testValues' | 'testPass'>): boolean;
839
+ /**
840
+ * The bin mode a map opens in when it has no test values: hard bins when any die has one, else soft bins
841
+ * when any die has one, else hard bins. The one rule for `buildWaferMap`'s own mode and for the renderers
842
+ * (single map and gallery), over one or several die lists.
843
+ */
844
+ export declare function defaultBinMode(dieLists: ReadonlyArray<ReadonlyArray<{
845
+ hbin?: number | null;
846
+ sbin?: number | null;
847
+ }>>): 'hardBin' | 'softBin';
833
848
  /**
834
849
  * Nominal wafer diameters in mm, used to sanity-check an *inferred* diameter.
835
850
  * Override per build with {@link WaferMapInputBase.standardDiameters}.
@@ -1 +1 @@
1
- import{createWafer as q}from"../core/wafer.js";import{isYieldEligibleDie as De,getDieKey as Y,hasPosition as E}from"../core/dies.js";import{applyOrientation as ne,transformDies as ve,clipDiesToWafer as Me}from"../core/transforms.js";import{generateDies as Se}from"../core/dies.js";import{dieHasAnyTestData as Ce,dieLink as K,finaliseDie as H,linkDie as ke,recordedVerdict as Oe,recordedVerdictsReader as Ae,tableFromRows as Ne,testValue as J,testsPresent as $e,VERDICT_FAIL as Fe,VERDICT_NONE as Re,VERDICT_PASS as Te}from"../core/dieTable.js";import{isDieColumns as Ee,linkColumns as We,linkRows as ie,relink as se}from"./columnarInput.js";import{affineRotation as Ie,affineMirror as _e,affineCompose as Pe,affinePoint as Ve}from"../core/transforms.js";import{inferWaferFromXY as Be}from"../core/inference/wafer.js";import{resolveGridPitch as Le}from"../core/inference/pitch.js";import{assignGridIndices as Ye}from"../core/inference/grid.js";import{generateReticleGrid as Xe}from"../core/reticle.js";import{applyDerivedTests as je}from"./derivedTests/apply.js";import{isStdfBin as Ke,isStdfCoord as re,isStdfTestNumber as oe,isStdfSite as He,STDF_BIN_MAX as ze,STDF_COORD_MAX as ae,STDF_TEST_NUM_MAX as Ue,STDF_SITE_MAX as Ge}from"../core/stdf.js";import{hasAnyKey as qe,maxOf as Q,minOf as de,modeOf as Je}from"../core/utils.js";import{aggregateValues as fe,aggregateBinCounts as Qe,stackHoldsMeasurements as Ze}from"../core/aggregates.js";import{normalizePassBins as le}from"../core/passBins.js";import{defaultRingCount as Z}from"../core/ringCount.js";import{applyValueFilter as et,mergeValueFilterTests as tt,valueFilterWarning as nt}from"./valueFilter.js";export function isParametricTest(t){return t?.testType!=="F"}export function isBuiltMap(t){return"wafer"in t&&"dies"in t&&"dataAxisFlip"in t}function it(t){const e=(i,d)=>({ringCount:i,ringCountWarning:{code:"analysis-option-corrected",severity:"warning",message:`ringCount=${String(t)} ${d} (using ${i}).`}});if(t===void 0)return{ringCount:Z(),ringCountWarning:void 0};if(typeof t!="number"||!Number.isFinite(t))return e(Z(),"is not a finite number");const n=Math.max(1,Math.round(t));return n===t?{ringCount:t,ringCountWarning:void 0}:e(n,"is not a whole number of at least 1")}function st(t,e){const n=Array.isArray(t)?{}:t,i={hbin:0,sbin:0,siteNum:0,testValues:0,testPass:0};let d;const r=(c,S)=>{i[c]++,d??=`${c} ${JSON.stringify(S)}`},a={bins:0,positions:0,values:0,sites:0,orientation:0},s=new Set;let h=0;if(e){i.testValues+=e.wrongValues,i.testPass+=e.wrongVerdicts,e.example!==void 0&&(d??=e.example),a.values+=e.nonFinite;for(const c of e.badTestNumbers)s.add(c)}const p=c=>c==null?!0:typeof c!="number"?!1:Number.isNaN(c)?(h++,!1):Ke(c)?!0:(a.bins++,!1);function u(c){const S=new Set,D=new Set;for(let $=0;$<c.length;$+=$<50?1:100){const A=c[$];if(!(A===null||typeof A!="object")){if(A.testValues&&typeof A.testValues=="object")for(const w of Object.keys(A.testValues))S.add(w);if(A.testPass&&typeof A.testPass=="object")for(const w of Object.keys(A.testPass))D.add(w)}}const m=[...S],b=[...D],O=$=>oe(Number($));for(const $ of new Set([...m,...b]))O($)||s.add($);const F=m.map(O),M=b.map(O),W=m.map(Number),T=b.map(Number);let P;for(let $=0;$<c.length;$++){const A=c[$];if(A===null||typeof A!="object")continue;const w=A;let B;const I=()=>B??={...w};w.hbin!=null&&typeof w.hbin!="number"&&r("hbin",w.hbin),w.sbin!=null&&typeof w.sbin!="number"&&r("sbin",w.sbin),p(w.hbin)||(I().hbin=void 0),p(w.sbin)||(I().sbin=void 0);const X=typeof w.x=="number"&&!re(w.x),L=typeof w.y=="number"&&!re(w.y);if(X||L){a.positions+=(X?1:0)+(L?1:0);const x=I();x.x=void 0,x.y=void 0}w.siteNum!=null&&typeof w.siteNum!="number"?(r("siteNum",w.siteNum),I().siteNum=void 0):typeof w.siteNum=="number"&&!He(w.siteNum)&&(a.sites++,I().siteNum=void 0);const o=w.testValues;if(o&&typeof o=="object"){let x;for(let k=0;k<m.length;k++){const R=m[k],N=o[W[k]];if(N!=null){if(!F[k]){x??={...o},delete x[R];continue}typeof N!="number"?(r("testValues",N),x??={...o},delete x[R]):Number.isFinite(N)||(a.values++,x??={...o},delete x[R])}}x&&(I().testValues=x)}const C=w.testPass;if(C&&typeof C=="object"){let x;for(let k=0;k<b.length;k++){const R=b[k],N=C[T[k]];if(N!=null){if(!M[k]){x??={...C},delete x[R];continue}typeof N!="boolean"&&(r("testPass",N),x??={...C},delete x[R])}}x&&(I().testPass=x)}B&&((P??=c.slice())[$]=B)}return P}const l={warnings:[]};if(Array.isArray(t))l.results=u(t);else{Array.isArray(n.results)&&(l.results=u(n.results)),Array.isArray(n.dies)&&(l.dies=u(n.dies));const c=n.lotStack?.results;if(Array.isArray(c)){const S=c.map(D=>Array.isArray(D)?u(D):void 0);S.some(Boolean)&&(l.stackResults=S.map((D,m)=>D??c[m]))}}if(Array.isArray(n.testDefs)){const c=n.testDefs,S=c.filter(D=>D==null||typeof D.testNumber!="number"||oe(D.testNumber));for(const D of c)S.includes(D)||s.add(String(D.testNumber));S.length!==c.length&&(l.testDefs=S)}const g=n.waferConfig?.orientation;if(typeof g=="number"){const c=Number.isFinite(g)?(g%360+360)%360:NaN;c===0||c===90||c===180||c===270?l.orientation=c:(a.orientation++,l.orientation=0)}const f=(c,S,D=`${S}s`)=>`${c} ${c===1?S:D}`,y=[];if(i.hbin&&y.push(f(i.hbin,"hard bin")),i.sbin&&y.push(f(i.sbin,"soft bin")),i.siteNum&&y.push(f(i.siteNum,"site number")),i.testValues&&y.push(f(i.testValues,"test value")),i.testPass&&y.push(f(i.testPass,"pass/fail verdict")),y.length){const c=`buildWaferMap received ${y.join(", ")} of the wrong type (for example ${d}), treated as missing. Bins, sites and test values must be numbers and verdicts true/false \u2014 a bin of "1" is not pass bin 1 \u2014 so those dies have no bin, no site, no value or no verdict, and yield and every chart leave them out. Convert them with Number() (and verdicts to booleans) and rebuild.`;console.warn(`[wafermap] ${c}`),l.warnings.push({code:"input-values-not-numbers",message:c,severity:"error"})}const v=[];if(a.bins&&v.push(`${f(a.bins,"bin")} (legal: whole numbers 0\u2013${ze}) \u2014 those dies have no bin`),a.positions&&v.push(`${f(a.positions,"coordinate")} (legal: whole numbers \u2212${ae} to ${ae}) \u2014 those dies have no position`),s.size&&v.push(`${f(s.size,"test number")} (legal: whole numbers 0\u2013${Ue}) \u2014 those tests are left out`),a.values&&v.push(`${f(a.values,"test value")} that ${a.values===1?"is":"are"} not finite \u2014 left out`),a.sites&&v.push(`${f(a.sites,"site number")} (legal: 0\u2013${Ge}) \u2014 those dies have no site`),a.orientation&&v.push("a waferConfig.orientation other than 0, 90, 180 or 270 \u2014 the map is built at 0"),v.length||h){const c=[];v.length&&c.push(`buildWaferMap received values outside the STDF V4 ranges, treated as missing: ${v.join("; ")}.`),h&&c.push(`${f(h,"bin was","bins were")} NaN and ${h===1?"is":"are"} treated as no bin.`);const S=c.join(" ");console.warn(`[wafermap] ${S}`),l.warnings.push({code:"input-values-outside-stdf",message:S,severity:"warning"})}return l}function ue(t){const e=(p,u)=>p!==null&&typeof p=="object"&&p[u]!==void 0,n=Array.isArray(t)?{}:t,i=[],d=(p,u,l)=>{p&&i.push(`\`${u}\` (now \`${l}\`)`)};d(e(n,"data"),"data","results"),d(e(n,"die"),"die","dieConfig"),d(e(n,"stack"),"stack","lotStack"),d(e(n.dieConfig,"origin"),"dieConfig.origin","dieConfig.coordinateOrigin"),d(e(n.waferConfig,"flat"),"waferConfig.flat","waferConfig.notch"),d(e(n.reticleConfig,"anchor"),"reticleConfig.anchor","reticleConfig.anchorDie"),d(e(n.lotStack,"aggr"),"lotStack.aggr","lotStack.method"),d(Array.isArray(n.testDefs)&&n.testDefs.some(p=>e(p,"index")&&!e(p,"testNumber")),"TestDef.index","TestDef.testNumber");const r=e(n.lotStack,"results")?n.lotStack.results:[],a=(Array.isArray(t)?[t]:[n.results,...Array.isArray(r)?r:[]]).filter(p=>Array.isArray(p));if(d(a.some(p=>p.slice(0,100).some(u=>e(u,"values"))),"values","testValues"),!i.length)return;const s=i.length>1,h=`buildWaferMap ignored ${i.join(", ")}: ${s?"these names were":"that name was"} removed in an earlier release, so what ${s?"they":"it"} described is not on this map. Rename and rebuild.`;return console.warn(`[wafermap] ${h}`),{code:"input-field-removed",message:h,severity:"error"}}function rt(t){if(t.results!==void 0||t.lotStack!==void 0)throw new Error("buildWaferMap: pass `layout`, `results` or `lotStack` \u2014 only one.");const e=t.waferConfig?.diameter,n=t.dieConfig?.width,i=t.dieConfig?.height;if(!(e>0&&n>0&&i>0))throw new Error("buildWaferMap: `layout` needs waferConfig.diameter and dieConfig.width and height, all positive.");const d=q({diameter:e,notch:t.waferConfig?.notch,orientation:0}),r=Me(Se(d,{width:n,height:i}),d,{width:n,height:i}).filter(u=>!u.partial),{flipX:a,flipY:s}=ce(t.dieConfig,{type:"center"}),{layout:h,...p}=t;return{...p,results:r.map(u=>({x:a?-u.x:u.x,y:s?-u.y:u.y})),waferConfig:{...t.waferConfig,center:{x:0,y:0}},dieConfig:{...t.dieConfig,coordinateOrigin:{type:"center"}}}}function ot(t){if(!Array.isArray(t)&&"results"in t&&t.results!==void 0&&"lotStack"in t&&t.lotStack!==void 0)throw new Error("buildWaferMap: pass either `results` or `lotStack`, not both.");const e={wrongVerdicts:0,wrongValues:0,nonFinite:0,badTestNumbers:[]},n=!Array.isArray(t)&&Ee(t.results)?{...t,results:We(t.results,e).records}:t,i=st(n,e);return Array.isArray(n)?{results:ee(i.results??n),waferOpts:void 0,dieOpts:void 0,explicitDies:void 0,reticleOpts:void 0,lotStackOpts:void 0,passBins:le(void 0),ringCount:Z(),valueFilter:"validity",ringCountWarning:void 0,removedFieldWarning:ue(n),inputValueWarnings:i.warnings,standardDiameters:void 0,testDefs:void 0,hbinDefs:void 0,sbinDefs:void 0,metadataFields:void 0,derivedTests:void 0,retestPolicy:"last",edgeDieYieldMode:"exclude"}:{results:ee(i.results??n.results??[]),waferOpts:i.orientation===void 0||n.waferConfig===void 0?n.waferConfig:{...n.waferConfig,orientation:i.orientation},dieOpts:n.dieConfig,explicitDies:i.dies??n.dies,reticleOpts:n.reticleConfig,lotStackOpts:n.lotStack?{...n.lotStack,results:(i.stackResults??n.lotStack.results).map(ee)}:void 0,passBins:le(n.passBins),valueFilter:n.valueFilter??"validity",...it(n.ringCount),removedFieldWarning:ue(n),inputValueWarnings:i.warnings,standardDiameters:n.standardDiameters,testDefs:(i.testDefs??n.testDefs)?.length?i.testDefs??n.testDefs:void 0,hbinDefs:n.hbinDefs,sbinDefs:n.sbinDefs,metadataFields:n.metadataFields,derivedTests:n.derivedTests?.length?n.derivedTests:void 0,retestPolicy:n.retestPolicy??"last",edgeDieYieldMode:n.edgeDieYieldMode??"exclude"}}function ee(t){return t.length>0&&K(t[0])!==void 0?t:ie(t).records}function at(t,e){return e?.coordinateOrigin?e.coordinateOrigin:{type:"center"}}function dt(t,e,n){if(e.type==="custom"&&e.offset)return{offsetX:e.offset.x,offsetY:e.offset.y};if(e.type!=="center"){let i=1/0,d=-1/0,r=1/0,a=-1/0;for(const s of t)s.x<i&&(i=s.x),s.x>d&&(d=s.x),s.y<r&&(r=s.y),s.y>a&&(a=s.y);return{offsetX:Math.round((d+i)/2),offsetY:Math.round((a+r)/2)}}return{offsetX:n.offsetX,offsetY:n.offsetY}}function ft(t,e,n,i,d,r){if(r)return{colMidX:(Math.round(r.x)-e)*i,colMidY:(Math.round(r.y)-n)*d,anchored:!0};if(t.length===0)return{colMidX:0,colMidY:0,anchored:!1};let a=1/0,s=-1/0,h=1/0,p=-1/0;for(const u of t){const l=Math.round(u.x)-e,g=Math.round(u.y)-n;l<a&&(a=l),l>s&&(s=l),g<h&&(h=g),g>p&&(p=g)}return{colMidX:(a+s)/2*i,colMidY:(h+p)/2*d,anchored:!1}}function lt(t,e,n){let i=1/0,d=-1/0,r=1/0,a=-1/0,s=0,h=0;for(const l of t){const g=Math.round(l.x)-e,f=Math.round(l.y)-n;s+=g,h+=f,g<i&&(i=g),g>d&&(d=g),f<r&&(r=f),f>a&&(a=f)}const p=t.length,u=(l,g,f)=>{const y=(f-g)/2;return y<=0?0:Math.abs(l/p-(g+f)/2)/y};return u(s,i,d)>.11||u(h,r,a)>.11}function ce(t,e){let n=t?.xAxisDirection==="left",i=t?.yAxisDirection==="down";return(e.type==="UL"||e.type==="UR")&&(i=!0),(e.type==="LR"||e.type==="UR")&&(n=!0),{flipX:n,flipY:i}}function ut(t){const e={...t};return delete e.limitLow,delete e.limitHigh,delete e.limitLowInclusive,delete e.limitHighInclusive,delete e.specLow,delete e.specHigh,e}function ct(t,e){const{method:n,targetBin:i}=t,d=t.results.map(r=>r.filter(E));if(n==="mean"||n==="median"||n==="stddev"||n==="min"||n==="max"||n==="count"){const r=new Set((e??[]).filter(u=>!isParametricTest(u)).map(u=>u.testNumber)),a=new Set;for(const u of d)for(const l of $e(u,"values"))r.has(l)||a.add(l);if(a.size===0)return fe(d,n);const s=[...a],h=s.map(u=>fe(d,n,u)),p=new Map;for(let u=0;u<s.length;u++){const l=s[u];for(const g of h[u]){const f=Y(g);p.has(f)||p.set(f,{template:g,testValues:{}});const y=p.get(f),v=g.testValues?.[0];v!==void 0&&(y.testValues[l]=v)}}return[...p.values()].map(({template:u,testValues:l})=>({...u,testValues:qe(l)?l:void 0}))}if(n==="countBin"||n==="percent"){if(i===void 0)return[];const r=Qe(d,i,"hard");if(n==="countBin")return r;const a=d.length;return r.map(s=>({...s,testValues:{0:a>0?(s.testValues?.[0]??0)/a*100:0}}))}if(n==="mode"){const r=new Map;for(const s of d)for(const h of s){const p=Y(h);r.has(p)||r.set(p,[]),r.get(p).push(h)}const a=[];for(const[s,h]of r){const p=s.split(","),u=Number(p[0]),l=Number(p[1]),g=h.map(y=>y.hbin).filter(y=>y!==void 0),f=Je(g);f!==null&&a.push({x:u,y:l,hbin:f})}return a}return[]}function pe(t){const e=t.filter(E),n=e.length,i=e.filter(r=>r.edgeExcluded).length,d=e.filter(r=>r.hbin!==void 0||r.sbin!==void 0||dieHasTestData(r)).length;return{filledDies:d,totalDies:n,edgeExcludedDies:i,unpositionedDies:t.length-e.length,ratio:n>0?d/n:0}}function he(t,e,n="exclude"){const i=new Set(e),r=t.filter(f=>!f.partial).filter(f=>f.edgeExcluded).length,a=t.filter(f=>f.partial).length;let s=0,h=0,p=!1;for(const f of t){if(!De(f))continue;const y=f.hbin??f.sbin;y!==void 0&&(p=!0,i.has(y)?s++:h++)}const u=s+h,l=p&&u>0?s/u*100:null;let g=null;if(n==="denominator-only"){const f=u+r;g=p&&f>0?s/f*100:null}return{passDies:s,failDies:h,edgeExcludedDies:r,partialDies:a,totalDies:u,yieldPercent:l,yieldPercentGross:g}}function me(t,e,n,i,d,r=0,a=0,s=0,h=0,p=0,u=!1,l=!1){if(!t)return[];const g=t.anchorDie??{x:0,y:0},f=Xe(e,{width:t.width,height:t.height,diePitchX:i,diePitchY:d,anchorDie:{x:g.x-r,y:g.y-a},gridOrigin:{x:-s,y:-h}}),y=Pe(_e(u,l,e.center.x,e.center.y),Ie(p,e.center.x,e.center.y));return f.filter(v=>{const c=v.width/2,S=v.height/2,D=[[v.x-c,v.y-S],[v.x+c,v.y-S],[v.x+c,v.y+S],[v.x-c,v.y+S]].map(([M,W])=>Ve(y,M,W)),m=de(D.map(M=>M.x)),b=Q(D.map(M=>M.x)),O=de(D.map(M=>M.y)),F=Q(D.map(M=>M.y));return n.some(M=>M.physX>=m&&M.physX<b&&M.physY>=O&&M.physY<F)})}function pt(t,e,n){const d=Math.max(0,e.radius-n)**2;return t.map(r=>{const a=r.physX-e.center.x,s=r.physY-e.center.y;return a*a+s*s>d?{...r,edgeExcluded:!0}:r})}const ht=.2;function mt(t,e,n){const i=new Set(n);function d(m,b){if(e==="last")return!0;if(e==="first")return!1;const O=z(m.hbin),F=z(b.hbin);if(O===void 0||F===void 0)return!1;const M=i.has(O),W=i.has(F);return e==="best"?W!==M?W:F<O:W!==M?M:F>O}const r=(m,b)=>b.supersedes!==void 0||d(m,b),a=m=>{const b=m.partId===void 0?"":String(m.partId).trim();return b===""?void 0:b},s=t.filter(m=>!E(m)),h=new Map;for(const m of s){const b=a(m);b!==void 0&&h.set(b,(h.get(b)??0)+1)}const u=(s.length===0?0:Math.max(0,...h.values())/s.length)<=ht,l=new Map,g=[],f=new Map;let y=0,v=0;for(const m of t){const b=a(m);let O;if(E(m)?O=`p:${Y(m)}`:u&&b!==void 0?O=`i:${b}`:O=`u:${v++}`,m.supersedes==="partId"&&b!==void 0){const M=f.get(b);M!==void 0&&M!==O&&l.has(M)&&l.delete(M)}const F=l.get(O);F===void 0?(l.set(O,{winner:m,count:1}),g.push(O)):(F.count++,O.startsWith("i:")&&y++,r(F.winner,m)&&(F.winner=m)),b!==void 0&&f.set(b,O)}const c=[],S=[...g.filter(m=>m.startsWith("p:")),...g.filter(m=>!m.startsWith("p:"))];for(const m of S){const b=l.get(m);b!==void 0&&c.push(b.count>1?{...b.winner,retestCount:b.count}:b.winner)}const D=y>0?{code:"retests-by-part-id",severity:"info",message:`${y} record${y===1?"":"s"} with no position shared a part ID with an earlier record and ${y===1?"was":"were"} treated as a retest of it.`}:void 0;return{results:c,warning:D}}export function getDieTestValue(t,e){return J(t,e)}export function getTestPassStatus(t,e,n){const i=Oe(t,e);return i!==void 0?i:n!==void 0&&!isParametricTest(n)?ge(J(t,e)):void 0}function ge(t){return t===0||t===1?t===1:void 0}export function testPassStatusReader(t){const e=t.map(d=>d.testNumber),n=Ae(e),i=t.map(d=>!isParametricTest(d));return function(r,a){n(r,a);for(let s=0;s<a.length;s++){if(a[s]!==Re||!i[s])continue;const h=ge(J(r,e[s]));h!==void 0&&(a[s]=h?Te:Fe)}return a}}export function dieHasTestData(t){return Ce(t)}function z(t){return t===void 0||Number.isNaN(t)?void 0:t}function U(t,e){const n={},i=z(e.hbin),d=z(e.sbin);i!==void 0&&(n.hbin=i),d!==void 0&&(n.sbin=d),e.retestCount!==void 0&&(n.retestCount=e.retestCount),e.siteNum!==void 0&&(n.siteNum=e.siteNum),e.partId!==void 0&&(n.partId=e.partId),e.metadata!==void 0&&(n.metadata=e.metadata);const r=K(e);return ke({...t,...n},r.table,r.row)}function ye(t){return t.some(dieHasTestData)?"value":t.some(e=>e.hbin!==void 0&&e.hbin!==null)?"hardBin":t.some(e=>e.sbin!==void 0&&e.sbin!==null)?"softBin":"hardBin"}function be(t,e){return t.map(({code:n,message:i})=>({code:n,message:i,severity:n==="non-standard-diameter"||n==="diameter-exceeds-die-extent"?"warning":"error",confidence:e.wafer.confidence}))}const gt="do not fit inside the supplied",yt="Inferred wafer diameter",bt="The probed dies reach only",wt=.75,xt=20;export const STANDARD_WAFER_DIAMETERS_MM=[100,125,150,200,300];const Dt=.02;function we(t,e){return e.reduce((n,i)=>Math.abs(i-t)<Math.abs(n-t)?i:n)}function vt(t,e){if(!e.length)return!0;const n=we(t,e);return Math.abs(n-t)/n<=Dt}function Mt(t){return t===void 0?STANDARD_WAFER_DIAMETERS_MM:t.filter(e=>Number.isFinite(e)&&e>0)}export function buildWaferMap(t){const e=ot(!Array.isArray(t)&&t.layout?rt(t):t),n=[];let i;if(e.valueFilter!=="none"&&e.testDefs){const o=e.valueFilter,C=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(k=>{const R=k.length>0?K(k[0]):void 0;if(!R)return[];const N=et(R.table,e.testDefs,o);return N.tests.length>0&&se(k,N.table),N.tests}),x=tt(C);if(x.length>0){i={mode:o,tests:x};const k=nt(o,x,e.testDefs);k&&n.push(k)}}if(e.derivedTests){const o=new Set(e.passBins),C=R=>{const N=R.length>0?K(R[0]):void 0,j=je(R,N?.table??Ne([]),e.testDefs,e.derivedTests,o);return N&&se(R,j.table),j},k=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(C);e.testDefs=k[0]?.testDefs??e.testDefs,n.push(...k[0]?.warnings??[])}e.lotStackOpts&&!Ze(e.lotStackOpts.method)&&(e.testDefs=e.testDefs?.map(ut));const d=e.lotStackOpts?ie(ct(e.lotStackOpts,e.testDefs)).records:e.results;for(let o=0;o<Math.min(5,d.length);o++){const C=d[o];if(typeof C.x=="string"||typeof C.y=="string")throw new TypeError("buildWaferMap: x and y must be numbers, received strings. Did you forget to cast CSV values? e.g. { x: +row.x, y: +row.y }")}for(const o of d)if(o.x==null!=(o.y==null))throw new TypeError(`buildWaferMap: die has only one of x/y set (x=${String(o.x)}, y=${String(o.y)}). A die must be either fully positioned (both x and y) or fully unpositioned (neither) \u2014 omit both to mark a die as having no reported position.`);const{results:r,warning:a}=mt(d,e.retestPolicy,e.passBins),s={wafer:{confidence:1,method:"provided"},diePitch:{confidence:1,units:"mm"},grid:{confidence:1}},h=[];if(e.explicitDies){let o=e.explicitDies.filter(E);const C=e.explicitDies.filter(V=>!E(V)),x=r.filter(E),k=r.filter(V=>!E(V));if(x.length>0){const V=new Map(x.map(_=>[Y(_),_]));o=o.map(_=>{const te=V.get(Y(_));return te?U(_,te):_})}const R=e.waferOpts?.diameter??300,N=q({diameter:R,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});N.orientation!==0&&(o=ne(o,N)),o=o.map(H);const j=me(e.reticleOpts,N,o,1,1,0,0,0,0,N.orientation),xe=k.map((V,_)=>H(U({id:`unpositioned_${_}`,width:o[0]?.width??1,height:o[0]?.height??1},V))),G=[...o,...C,...xe];return{wafer:N,dies:G,dataAxisFlip:{x:!1,y:!1},reticleConfig:e.reticleOpts,units:"mm",inference:s,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...a?[a]:[],...be(h,s),...n,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:ye(r),metadata:N.metadata??null,isLotStack:!1,dataCoverage:pe(G),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:he(G,e.passBins,e.edgeDieYieldMode),reticles:j,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields}}const p=r.filter(E),u=r.filter(o=>!E(o)),l=p.map(o=>({x:o.x,y:o.y})),g=Le(l,e.dieOpts,e.waferOpts?.diameter);s.diePitch={confidence:g.confidence,units:g.units};const{pitchX:f,pitchY:y}=g,v=g.units,c=at(p,e.dieOpts),S=Ye(l);s.grid={confidence:S.confidence};const{offsetX:D,offsetY:m}=dt(l,c,S),{flipX:b,flipY:O}=ce(e.dieOpts,c),{colMidX:F,colMidY:M,anchored:W}=ft(l,D,m,f,y,e.waferOpts?.center);let T=e.waferOpts?.diameter;const P=l.map(o=>({x:(Math.round(o.x)-D)*f-F,y:(Math.round(o.y)-m)*y-M})),$=Q(P.map(({x:o,y:C})=>Math.hypot(Math.abs(o)+f/2,Math.abs(C)+y/2)));if(T===void 0)if(l.length>0)if(v==="mm"){const o=Be(P,{minRadius:$});T=o.diameter,s.wafer={confidence:o.confidence,method:o.method};const C=Mt(e.standardDiameters);if(!vt(T,C)){const x=we(T,C);h.push({code:"non-standard-diameter",message:`${yt} ${T.toFixed(1)} mm is not a standard wafer size (nearest is ${x} mm). The diameter was derived from the die extent, which assumes the probed grid reaches the wafer edge \u2014 a non-standard result usually means it does not, because the outer dies were never probed. Every die is then placed against a wafer that is too small, which moves dies between rings and changes ring and edge findings. Supply waferConfig.diameter.`})}}else T=$*2,s.wafer={confidence:g.confidence*.8,method:"extent"};else T=v==="mm"?300:30,s.wafer={confidence:0,method:"default"};if(!W&&l.length>0&&lt(l,D,m)&&(s.wafer.method="inferred-partial",h.push({code:"partial-coverage",message:"Wafer geometry was inferred from die positions alone. The data does not span a full symmetric wafer, so the inferred diameter and centre may be wrong and dies may be mis-positioned relative to the true wafer boundary. Supply waferConfig.diameter and waferConfig.center (the prober coordinate of the wafer centre) to position partial data correctly."})),e.waferOpts?.diameter!==void 0&&e.waferOpts.center===void 0&&$>0&&l.length>=xt){const o=$/(T/2);o<wt&&h.push({code:"diameter-exceeds-die-extent",message:`${bt} ${(o*100).toFixed(0)}% of the ${T} mm wafer's radius. Either the diameter is larger than the real one, or this is a partial map covering only part of the wafer. Ring bands are equal-radius, so the outer rings are mostly or entirely empty and ring, quadrant and edge findings describe the assumed wafer rather than the probed area. Check waferConfig.diameter, or drop it and let the diameter be inferred from the die extent.`})}if(e.waferOpts?.diameter!==void 0){const o=e.dieOpts?.width!==void 0&&e.dieOpts?.height!==void 0;if(o&&$>T/2+1e-9){const C=P.filter(({x,y:k})=>Math.hypot(Math.abs(x)+f/2,Math.abs(k)+y/2)>T/2+1e-9).length;h.push({code:"geometry-conflict",message:`${C} of ${P.length} probed die positions ${gt} ${T} mm wafer at the supplied die pitch of ${f} \xD7 ${y} mm. A die with test results is a real prober position and is always fully on the wafer, so one of the two supplied values must be wrong: containing these dies at this pitch would need a diameter of at least ${($*2).toFixed(1)} mm. Check waferConfig.diameter and dieConfig.width/height against the real device.`})}}const A=q({diameter:T,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});let w=p.map(o=>{const C=Math.round(o.x)-D,x=Math.round(o.y)-m,k={id:`${C}_${x}`,x:C,y:x,physX:C*f-F,physY:x*y-M,width:f,height:y,insideWafer:!0,partial:!1};return U(k,o)});(D!==0||m!==0)&&(w=w.map(o=>({...o,x:o.x+D,y:o.y+m,id:`${o.x+D}_${o.y+m}`}))),w=ne(w,A),(b||O)&&(w=ve(w,{flipX:b,flipY:O},A.center));const B=[];e.waferOpts?.edgeExclusion&&e.waferOpts.edgeExclusion>0&&(w=pt(w,A,e.waferOpts.edgeExclusion),e.waferOpts.edgeExclusion>A.radius&&B.push({code:"edge-exclusion-exceeds-radius",message:`edgeExclusion (${e.waferOpts.edgeExclusion}mm) exceeds the resolved wafer radius (${A.radius}mm) \u2014 the entire wafer is excluded.`,severity:"warning"})),w=w.map(H);const I=me(e.reticleOpts,A,w,f,y,D,m,F,M,A.orientation,b,O),X=u.map((o,C)=>H(U({id:`unpositioned_${C}`,width:f,height:y},o))),L=[...w,...X];return{wafer:A,dies:L,dataAxisFlip:{x:b,y:O},reticleConfig:e.reticleOpts,units:v,inference:s,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...a?[a]:[],...be(h,s),...B,...n,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:ye(r),metadata:A.metadata??null,isLotStack:e.lotStackOpts!==void 0,dataCoverage:pe(L),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:he(L,e.passBins,e.edgeDieYieldMode),reticles:I,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields,aggrMethod:e.lotStackOpts?.method,lotSize:e.lotStackOpts?.results.length}}
1
+ import{createWafer as Q}from"../core/wafer.js";import{isYieldEligibleDie as Ce,getDieKey as X,hasPosition as W,positionKey as ke}from"../core/dies.js";import{applyOrientation as se,transformDies as Oe,clipDiesToWafer as Ae}from"../core/transforms.js";import{generateDies as $e}from"../core/dies.js";import{dieHasAnyTestData as Ne,dieLink as U,finaliseDie as z,linkDie as Re,recordedVerdict as Fe,recordedVerdictsReader as Ee,tableFromRows as Te,testValue as Z,testsPresent as We,VERDICT_FAIL as Ie,VERDICT_NONE as _e,VERDICT_PASS as Pe}from"../core/dieTable.js";import{isDieColumns as Ve,linkColumns as Be,linkRows as re,relink as oe}from"./columnarInput.js";import{affineRotation as Le,affineMirror as Ye,affineCompose as Xe,affinePoint as Ke}from"../core/transforms.js";import{inferWaferFromXY as je}from"../core/inference/wafer.js";import{resolveGridPitch as He}from"../core/inference/pitch.js";import{assignGridIndices as Ue}from"../core/inference/grid.js";import{generateReticleGrid as ze}from"../core/reticle.js";import{applyDerivedTests as Ge}from"./derivedTests/apply.js";import{isStdfBin as qe,isStdfCoord as ae,isStdfTestNumber as de,isStdfSite as Je,STDF_BIN_MAX as Qe,STDF_COORD_MAX as fe,STDF_TEST_NUM_MAX as Ze,STDF_SITE_MAX as et}from"../core/stdf.js";import{hasAnyKey as tt,maxOf as ee,minOf as le,modeOf as nt}from"../core/utils.js";import{aggregateValues as ue,aggregateBinCounts as it,stackHoldsMeasurements as st,stackBinsAreData as rt}from"../core/aggregates.js";import{normalizePassBins as ce}from"../core/passBins.js";import{defaultRingCount as te}from"../core/ringCount.js";import{applyValueFilter as ot,mergeValueFilterTests as at,valueFilterWarning as dt}from"./valueFilter.js";export function isParametricTest(n){return n?.testType!=="F"}export function isBuiltMap(n){return"wafer"in n&&"dies"in n&&"dataAxisFlip"in n}function ft(n){const e=(i,a)=>({ringCount:i,ringCountWarning:{code:"analysis-option-corrected",severity:"warning",message:`ringCount=${String(n)} ${a} (using ${i}).`}});if(n===void 0)return{ringCount:te(),ringCountWarning:void 0};if(typeof n!="number"||!Number.isFinite(n))return e(te(),"is not a finite number");const t=Math.max(1,Math.round(n));return t===n?{ringCount:n,ringCountWarning:void 0}:e(t,"is not a whole number of at least 1")}function lt(n,e){const t=Array.isArray(n)?{}:n,i={hbin:0,sbin:0,siteNum:0,testValues:0,testPass:0};let a;const d=(u,C)=>{i[u]++,a??=`${u} ${JSON.stringify(C)}`},o={bins:0,positions:0,values:0,sites:0,orientation:0},r=new Set;let p=0;if(e){i.testValues+=e.wrongValues,i.testPass+=e.wrongVerdicts,e.example!==void 0&&(a??=e.example),o.values+=e.nonFinite;for(const u of e.badTestNumbers)r.add(u)}const h=u=>u==null?!0:typeof u!="number"?!1:Number.isNaN(u)?(p++,!1):qe(u)?!0:(o.bins++,!1);function l(u){const C=new Set,D=new Set;for(let S=0;S<u.length;S+=S<50?1:100){const N=u[S];if(!(N===null||typeof N!="object")){if(N.testValues&&typeof N.testValues=="object")for(const M of Object.keys(N.testValues))C.add(M);if(N.testPass&&typeof N.testPass=="object")for(const M of Object.keys(N.testPass))D.add(M)}}const g=[...C],b=[...D],k=S=>de(Number(S));for(const S of new Set([...g,...b]))k(S)||r.add(S);const R=g.map(k),v=b.map(k),T=g.map(Number),L=b.map(Number);let K;for(let S=0;S<u.length;S++){const N=u[S];if(N===null||typeof N!="object")continue;const M=N;let F;const $=()=>F??={...M};M.hbin!=null&&typeof M.hbin!="number"&&d("hbin",M.hbin),M.sbin!=null&&typeof M.sbin!="number"&&d("sbin",M.sbin),h(M.hbin)||($().hbin=void 0),h(M.sbin)||($().sbin=void 0);const Y=typeof M.x=="number"&&!ae(M.x),j=typeof M.y=="number"&&!ae(M.y);if(Y||j){o.positions+=(Y?1:0)+(j?1:0);const s=$();s.x=void 0,s.y=void 0}M.siteNum!=null&&typeof M.siteNum!="number"?(d("siteNum",M.siteNum),$().siteNum=void 0):typeof M.siteNum=="number"&&!Je(M.siteNum)&&(o.sites++,$().siteNum=void 0);const P=M.testValues;if(P&&typeof P=="object"){let s;for(let x=0;x<g.length;x++){const A=g[x],O=P[T[x]];if(O!=null){if(!R[x]){s??={...P},delete s[A];continue}typeof O!="number"?(d("testValues",O),s??={...P},delete s[A]):Number.isFinite(O)||(o.values++,s??={...P},delete s[A])}}s&&($().testValues=s)}const I=M.testPass;if(I&&typeof I=="object"){let s;for(let x=0;x<b.length;x++){const A=b[x],O=I[L[x]];if(O!=null){if(!v[x]){s??={...I},delete s[A];continue}typeof O!="boolean"&&(d("testPass",O),s??={...I},delete s[A])}}s&&($().testPass=s)}F&&((K??=u.slice())[S]=F)}return K}const f={warnings:[]};if(Array.isArray(n))f.results=l(n);else{Array.isArray(t.results)&&(f.results=l(t.results)),Array.isArray(t.dies)&&(f.dies=l(t.dies));const u=t.lotStack?.results;if(Array.isArray(u)){const C=u.map(D=>Array.isArray(D)?l(D):void 0);C.some(Boolean)&&(f.stackResults=C.map((D,g)=>D??u[g]))}}if(Array.isArray(t.testDefs)){const u=t.testDefs,C=u.filter(D=>D==null||typeof D.testNumber!="number"||de(D.testNumber));for(const D of u)C.includes(D)||r.add(String(D.testNumber));C.length!==u.length&&(f.testDefs=C)}const y=t.waferConfig?.orientation;if(typeof y=="number"){const u=Number.isFinite(y)?(y%360+360)%360:NaN;u===0||u===90||u===180||u===270?f.orientation=u:(o.orientation++,f.orientation=0)}const m=(u,C,D=`${C}s`)=>`${u} ${u===1?C:D}`,c=[];if(i.hbin&&c.push(m(i.hbin,"hard bin")),i.sbin&&c.push(m(i.sbin,"soft bin")),i.siteNum&&c.push(m(i.siteNum,"site number")),i.testValues&&c.push(m(i.testValues,"test value")),i.testPass&&c.push(m(i.testPass,"pass/fail verdict")),c.length){const u=`buildWaferMap received ${c.join(", ")} of the wrong type (for example ${a}), treated as missing. Bins, sites and test values must be numbers and verdicts true/false \u2014 a bin of "1" is not pass bin 1 \u2014 so those dies have no bin, no site, no value or no verdict, and yield and every chart leave them out. Convert them with Number() (and verdicts to booleans) and rebuild.`;console.warn(`[wafermap] ${u}`),f.warnings.push({code:"input-values-not-numbers",message:u,severity:"error"})}const w=[];if(o.bins&&w.push(`${m(o.bins,"bin")} (legal: whole numbers 0\u2013${Qe}) \u2014 those dies have no bin`),o.positions&&w.push(`${m(o.positions,"coordinate")} (legal: whole numbers \u2212${fe} to ${fe}) \u2014 those dies have no position`),r.size&&w.push(`${m(r.size,"test number")} (legal: whole numbers 0\u2013${Ze}) \u2014 those tests are left out`),o.values&&w.push(`${m(o.values,"test value")} that ${o.values===1?"is":"are"} not finite \u2014 left out`),o.sites&&w.push(`${m(o.sites,"site number")} (legal: 0\u2013${et}) \u2014 those dies have no site`),o.orientation&&w.push("a waferConfig.orientation other than 0, 90, 180 or 270 \u2014 the map is built at 0"),w.length||p){const u=[];w.length&&u.push(`buildWaferMap received values outside the STDF V4 ranges, treated as missing: ${w.join("; ")}.`),p&&u.push(`${m(p,"bin was","bins were")} NaN and ${p===1?"is":"are"} treated as no bin.`);const C=u.join(" ");console.warn(`[wafermap] ${C}`),f.warnings.push({code:"input-values-outside-stdf",message:C,severity:"warning"})}return f}function pe(n){const e=(h,l)=>h!==null&&typeof h=="object"&&h[l]!==void 0,t=Array.isArray(n)?{}:n,i=[],a=(h,l,f)=>{h&&i.push(`\`${l}\` (now \`${f}\`)`)};a(e(t,"data"),"data","results"),a(e(t,"die"),"die","dieConfig"),a(e(t,"stack"),"stack","lotStack"),a(e(t.dieConfig,"origin"),"dieConfig.origin","dieConfig.coordinateOrigin"),a(e(t.waferConfig,"flat"),"waferConfig.flat","waferConfig.notch"),a(e(t.reticleConfig,"anchor"),"reticleConfig.anchor","reticleConfig.anchorDie"),a(e(t.lotStack,"aggr"),"lotStack.aggr","lotStack.method"),a(Array.isArray(t.testDefs)&&t.testDefs.some(h=>e(h,"index")&&!e(h,"testNumber")),"TestDef.index","TestDef.testNumber");const d=e(t.lotStack,"results")?t.lotStack.results:[],o=(Array.isArray(n)?[n]:[t.results,...Array.isArray(d)?d:[]]).filter(h=>Array.isArray(h));if(a(o.some(h=>h.slice(0,100).some(l=>e(l,"values"))),"values","testValues"),!i.length)return;const r=i.length>1,p=`buildWaferMap ignored ${i.join(", ")}: ${r?"these names were":"that name was"} removed in an earlier release, so what ${r?"they":"it"} described is not on this map. Rename and rebuild.`;return console.warn(`[wafermap] ${p}`),{code:"input-field-removed",message:p,severity:"error"}}function ut(n){if(n.results!==void 0||n.lotStack!==void 0)throw new Error("buildWaferMap: pass `layout`, `results` or `lotStack` \u2014 only one.");const e=n.waferConfig?.diameter,t=n.dieConfig?.width,i=n.dieConfig?.height;if(!(e>0&&t>0&&i>0))throw new Error("buildWaferMap: `layout` needs waferConfig.diameter and dieConfig.width and height, all positive.");const a=Q({diameter:e,notch:n.waferConfig?.notch,orientation:0}),d=Ae($e(a,{width:t,height:i}),a,{width:t,height:i}).filter(l=>!l.partial),{flipX:o,flipY:r}=me(n.dieConfig,{type:"center"}),{layout:p,...h}=n;return{...h,results:d.map(l=>({x:o?-l.x:l.x,y:r?-l.y:l.y})),waferConfig:{...n.waferConfig,center:{x:0,y:0}},dieConfig:{...n.dieConfig,coordinateOrigin:{type:"center"}}}}function ct(n){if(!Array.isArray(n)&&"results"in n&&n.results!==void 0&&"lotStack"in n&&n.lotStack!==void 0)throw new Error("buildWaferMap: pass either `results` or `lotStack`, not both.");const e={wrongVerdicts:0,wrongValues:0,nonFinite:0,badTestNumbers:[]},t=!Array.isArray(n)&&Ve(n.results)?{...n,results:Be(n.results,e).records}:n,i=lt(t,e);return Array.isArray(t)?{results:ne(i.results??t),waferOpts:void 0,dieOpts:void 0,explicitDies:void 0,reticleOpts:void 0,lotStackOpts:void 0,passBins:ce(void 0),ringCount:te(),valueFilter:"validity",ringCountWarning:void 0,removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:void 0,testDefs:void 0,hbinDefs:void 0,sbinDefs:void 0,metadataFields:void 0,derivedTests:void 0,retestPolicy:"last",edgeDieYieldMode:"exclude"}:{results:ne(i.results??t.results??[]),waferOpts:i.orientation===void 0||t.waferConfig===void 0?t.waferConfig:{...t.waferConfig,orientation:i.orientation},dieOpts:t.dieConfig,explicitDies:i.dies??t.dies,reticleOpts:t.reticleConfig,lotStackOpts:t.lotStack?{...t.lotStack,results:(i.stackResults??t.lotStack.results).map(ne)}:void 0,passBins:ce(t.passBins),valueFilter:t.valueFilter??"validity",...ft(t.ringCount),removedFieldWarning:pe(t),inputValueWarnings:i.warnings,standardDiameters:t.standardDiameters,testDefs:(i.testDefs??t.testDefs)?.length?i.testDefs??t.testDefs:void 0,hbinDefs:t.hbinDefs,sbinDefs:t.sbinDefs,metadataFields:t.metadataFields,derivedTests:t.derivedTests?.length?t.derivedTests:void 0,retestPolicy:t.retestPolicy??"last",edgeDieYieldMode:t.edgeDieYieldMode??"exclude"}}function ne(n){return n.length>0&&U(n[0])!==void 0?n:re(n).records}function pt(n,e){return e?.coordinateOrigin?e.coordinateOrigin:{type:"center"}}function ht(n,e,t){if(e.type==="custom"&&e.offset)return{offsetX:e.offset.x,offsetY:e.offset.y};if(e.type!=="center"){let i=1/0,a=-1/0,d=1/0,o=-1/0;for(const r of n)r.x<i&&(i=r.x),r.x>a&&(a=r.x),r.y<d&&(d=r.y),r.y>o&&(o=r.y);return{offsetX:Math.round((a+i)/2),offsetY:Math.round((o+d)/2)}}return{offsetX:t.offsetX,offsetY:t.offsetY}}function mt(n,e){if(n.length<Me)return!1;const t=he(n),i=(a,d,o)=>{const r=o-d+1;return a<d-r||a>o+r};return i(Math.round(e.x),t.xMin,t.xMax)||i(Math.round(e.y),t.yMin,t.yMax)}function he(n){let e=1/0,t=-1/0,i=1/0,a=-1/0;for(const d of n){const o=Math.round(d.x),r=Math.round(d.y);o<e&&(e=o),o>t&&(t=o),r<i&&(i=r),r>a&&(a=r)}return{xMin:e,xMax:t,yMin:i,yMax:a}}const gt="The supplied wafer centre";function yt(n,e){const t=he(n);return`${gt} (${e.x}, ${e.y}) is far outside the probed dies (X ${t.xMin}\u2026${t.xMax}, Y ${t.yMin}\u2026${t.yMax}), so it was ignored and the centre was inferred from the dies. Used as given, it would draw a wafer many times the die extent with the dies in one corner. If it is the real centre, supply waferConfig.diameter as well.`}function bt(n,e,t,i,a,d){if(d)return{colMidX:(Math.round(d.x)-e)*i,colMidY:(Math.round(d.y)-t)*a,anchored:!0};if(n.length===0)return{colMidX:0,colMidY:0,anchored:!1};let o=1/0,r=-1/0,p=1/0,h=-1/0;for(const l of n){const f=Math.round(l.x)-e,y=Math.round(l.y)-t;f<o&&(o=f),f>r&&(r=f),y<p&&(p=y),y>h&&(h=y)}return{colMidX:(o+r)/2*i,colMidY:(p+h)/2*a,anchored:!1}}function wt(n,e,t){let i=1/0,a=-1/0,d=1/0,o=-1/0,r=0,p=0;for(const f of n){const y=Math.round(f.x)-e,m=Math.round(f.y)-t;r+=y,p+=m,y<i&&(i=y),y>a&&(a=y),m<d&&(d=m),m>o&&(o=m)}const h=n.length,l=(f,y,m)=>{const c=(m-y)/2;return c<=0?0:Math.abs(f/h-(y+m)/2)/c};return l(r,i,a)>.11||l(p,d,o)>.11}function me(n,e){let t=n?.xAxisDirection==="left",i=n?.yAxisDirection==="down";return(e.type==="UL"||e.type==="UR")&&(i=!0),(e.type==="LR"||e.type==="UR")&&(t=!0),{flipX:t,flipY:i}}function xt(n){const e={...n};return delete e.limitLow,delete e.limitHigh,delete e.limitLowInclusive,delete e.limitHighInclusive,delete e.specLow,delete e.specHigh,e}function Dt(n,e){const{method:t,targetBin:i}=n,a=n.results.map(d=>d.filter(W));if(t==="mean"||t==="median"||t==="stddev"||t==="min"||t==="max"||t==="count"){const d=new Set((e??[]).filter(l=>!isParametricTest(l)).map(l=>l.testNumber)),o=new Set;for(const l of a)for(const f of We(l,"values"))d.has(f)||o.add(f);if(o.size===0)return ue(a,t);const r=[...o],p=r.map(l=>ue(a,t,l)),h=new Map;for(let l=0;l<r.length;l++){const f=r[l];for(const y of p[l]){const m=X(y);h.has(m)||h.set(m,{template:y,testValues:{}});const c=h.get(m),w=y.testValues?.[0];w!==void 0&&(c.testValues[f]=w)}}return[...h.values()].map(({template:l,testValues:f})=>({...l,testValues:tt(f)?f:void 0}))}if(t==="countBin"||t==="percent"){if(i===void 0)return[];const d=it(a,i,"hard");if(t==="countBin")return d;const o=a.length;return d.map(r=>({...r,testValues:{0:o>0?(r.testValues?.[0]??0)/o*100:0}}))}if(t==="mode"){const d=new Map;for(const r of a)for(const p of r){const h=X(p);d.has(h)||d.set(h,[]),d.get(h).push(p)}const o=[];for(const[r,p]of d){const h=r.split(","),l=Number(h[0]),f=Number(h[1]),y=p.map(c=>c.hbin).filter(c=>c!==void 0),m=nt(y);m!==null&&o.push({x:l,y:f,hbin:m})}return o}return[]}function ge(n){const e=n.filter(W),t=e.length,i=e.filter(d=>d.edgeExcluded).length,a=e.filter(d=>d.hbin!==void 0||d.sbin!==void 0||dieHasTestData(d)).length;return{filledDies:a,totalDies:t,edgeExcludedDies:i,unpositionedDies:n.length-e.length,ratio:t>0?a/t:0}}function ye(n,e,t="exclude",i=!0){const a=new Set(e),o=n.filter(c=>!c.partial).filter(c=>c.edgeExcluded).length,r=n.filter(c=>c.partial).length;if(!i)return{passDies:0,failDies:0,edgeExcludedDies:o,partialDies:r,totalDies:0,yieldPercent:null,yieldPercentGross:null};let p=0,h=0,l=!1;for(const c of n){if(!Ce(c))continue;const w=c.hbin??c.sbin;w!==void 0&&(l=!0,a.has(w)?p++:h++)}const f=p+h,y=l&&f>0?p/f*100:null;let m=null;if(t==="denominator-only"){const c=f+o;m=l&&c>0?p/c*100:null}return{passDies:p,failDies:h,edgeExcludedDies:o,partialDies:r,totalDies:f,yieldPercent:y,yieldPercentGross:m}}function be(n,e,t,i,a,d=0,o=0,r=0,p=0,h=0,l=!1,f=!1){if(!n)return[];const y=n.anchorDie??{x:0,y:0},m=ze(e,{width:n.width,height:n.height,diePitchX:i,diePitchY:a,anchorDie:{x:y.x-d,y:y.y-o},gridOrigin:{x:-r,y:-p}}),c=Xe(Ye(l,f,e.center.x,e.center.y),Le(h,e.center.x,e.center.y));return m.filter(w=>{const u=w.width/2,C=w.height/2,D=[[w.x-u,w.y-C],[w.x+u,w.y-C],[w.x+u,w.y+C],[w.x-u,w.y+C]].map(([v,T])=>Ke(c,v,T)),g=le(D.map(v=>v.x)),b=ee(D.map(v=>v.x)),k=le(D.map(v=>v.y)),R=ee(D.map(v=>v.y));return t.some(v=>v.physX>=g&&v.physX<b&&v.physY>=k&&v.physY<R)})}function Mt(n,e,t){const a=Math.max(0,e.radius-t)**2;return n.map(d=>{const o=d.physX-e.center.x,r=d.physY-e.center.y;return o*o+r*r>a?{...d,edgeExcluded:!0}:d})}const vt=.2;function St(n){const e=new Set;for(const t of n){if(t.supersedes!==void 0||!W(t))return!1;const i=ke(t);if(e.has(i))return!1;e.add(i)}return!0}function Ct(n,e,t){if(St(n))return{results:n.slice(),warning:void 0};const i=new Set(t);function a(g,b){if(e==="last")return!0;if(e==="first")return!1;const k=G(g.hbin),R=G(b.hbin);if(k===void 0||R===void 0)return!1;const v=i.has(k),T=i.has(R);return e==="best"?T!==v?T:R<k:T!==v?v:R>k}const d=(g,b)=>b.supersedes!==void 0||a(g,b),o=g=>{const b=g.partId===void 0?"":String(g.partId).trim();return b===""?void 0:b},r=n.filter(g=>!W(g)),p=new Map;for(const g of r){const b=o(g);b!==void 0&&p.set(b,(p.get(b)??0)+1)}const l=(r.length===0?0:Math.max(0,...p.values())/r.length)<=vt,f=new Map,y=[],m=new Map;let c=0,w=0;for(const g of n){const b=o(g);let k;if(W(g)?k=`p:${X(g)}`:l&&b!==void 0?k=`i:${b}`:k=`u:${w++}`,g.supersedes==="partId"&&b!==void 0){const v=m.get(b);v!==void 0&&v!==k&&f.has(v)&&f.delete(v)}const R=f.get(k);R===void 0?(f.set(k,{winner:g,count:1}),y.push(k)):(R.count++,k.startsWith("i:")&&c++,d(R.winner,g)&&(R.winner=g)),b!==void 0&&m.set(b,k)}const u=[],C=[...y.filter(g=>g.startsWith("p:")),...y.filter(g=>!g.startsWith("p:"))];for(const g of C){const b=f.get(g);b!==void 0&&u.push(b.count>1?{...b.winner,retestCount:b.count}:b.winner)}const D=c>0?{code:"retests-by-part-id",severity:"info",message:`${c} record${c===1?"":"s"} with no position shared a part ID with an earlier record and ${c===1?"was":"were"} treated as a retest of it.`}:void 0;return{results:u,warning:D}}export function getDieTestValue(n,e){return Z(n,e)}export function getTestPassStatus(n,e,t){const i=Fe(n,e);return i!==void 0?i:t!==void 0&&!isParametricTest(t)?we(Z(n,e)):void 0}function we(n){return n===0||n===1?n===1:void 0}export function testPassStatusReader(n){const e=n.map(a=>a.testNumber),t=Ee(e),i=n.map(a=>!isParametricTest(a));return function(d,o){t(d,o);for(let r=0;r<o.length;r++){if(o[r]!==_e||!i[r])continue;const p=we(Z(d,e[r]));p!==void 0&&(o[r]=p?Pe:Ie)}return o}}export function dieHasTestData(n){return Ne(n)}function G(n){return n===void 0||Number.isNaN(n)?void 0:n}function q(n,e){const t={},i=G(e.hbin),a=G(e.sbin);i!==void 0&&(t.hbin=i),a!==void 0&&(t.sbin=a),e.retestCount!==void 0&&(t.retestCount=e.retestCount),e.siteNum!==void 0&&(t.siteNum=e.siteNum),e.partId!==void 0&&(t.partId=e.partId),e.metadata!==void 0&&(t.metadata=e.metadata);const d=U(e);return Re({...n,...t},d.table,d.row)}function xe(n){return n.some(dieHasTestData)?"value":defaultBinMode([n])}export function defaultBinMode(n){const e=t=>n.some(i=>i.some(a=>t(a)!=null));return e(t=>t.hbin)?"hardBin":e(t=>t.sbin)?"softBin":"hardBin"}function De(n,e){return n.map(({code:t,message:i})=>({code:t,message:i,severity:t==="non-standard-diameter"||t==="diameter-exceeds-die-extent"||t==="implausible-center"?"warning":"error",confidence:e.wafer.confidence}))}const kt="do not fit inside the supplied",Ot="Inferred wafer diameter",At="The probed dies reach only",$t=.75,Me=20;export const STANDARD_WAFER_DIAMETERS_MM=[100,125,150,200,300];const Nt=.02;function ve(n,e){return e.reduce((t,i)=>Math.abs(i-n)<Math.abs(t-n)?i:t)}function Rt(n,e){if(!e.length)return!0;const t=ve(n,e);return Math.abs(t-n)/t<=Nt}function Ft(n){return n===void 0?STANDARD_WAFER_DIAMETERS_MM:n.filter(e=>Number.isFinite(e)&&e>0)}export function buildWaferMap(n){const e=ct(!Array.isArray(n)&&n.layout?ut(n):n),t=[];let i;if(e.valueFilter!=="none"&&e.testDefs){const s=e.valueFilter,x=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(O=>{const _=O.length>0?U(O[0]):void 0;if(!_)return[];const E=ot(_.table,e.testDefs,s);return E.tests.length>0&&oe(O,E.table),E.tests}),A=at(x);if(A.length>0){i={mode:s,tests:A};const O=dt(s,A,e.testDefs);O&&t.push(O)}}if(e.derivedTests){const s=new Set(e.passBins),x=_=>{const E=_.length>0?U(_[0]):void 0,H=Ge(_,E?.table??Te([]),e.testDefs,e.derivedTests,s);return E&&oe(_,H.table),H},O=(e.lotStackOpts?e.lotStackOpts.results:[e.results]).map(x);e.testDefs=O[0]?.testDefs??e.testDefs,t.push(...O[0]?.warnings??[])}e.lotStackOpts&&!st(e.lotStackOpts.method)&&(e.testDefs=e.testDefs?.map(xt));const a=e.lotStackOpts?re(Dt(e.lotStackOpts,e.testDefs)).records:e.results;for(let s=0;s<Math.min(5,a.length);s++){const x=a[s];if(typeof x.x=="string"||typeof x.y=="string")throw new TypeError("buildWaferMap: x and y must be numbers, received strings. Did you forget to cast CSV values? e.g. { x: +row.x, y: +row.y }")}for(const s of a)if(s.x==null!=(s.y==null))throw new TypeError(`buildWaferMap: die has only one of x/y set (x=${String(s.x)}, y=${String(s.y)}). A die must be either fully positioned (both x and y) or fully unpositioned (neither) \u2014 omit both to mark a die as having no reported position.`);const{results:d,warning:o}=Ct(a,e.retestPolicy,e.passBins),r={wafer:{confidence:1,method:"provided"},diePitch:{confidence:1,units:"mm"},grid:{confidence:1}},p=[];if(e.explicitDies){let s=e.explicitDies.filter(W);const x=e.explicitDies.filter(B=>!W(B)),A=d.filter(W),O=d.filter(B=>!W(B));if(A.length>0){const B=new Map(A.map(V=>[X(V),V]));s=s.map(V=>{const ie=B.get(X(V));return ie?q(V,ie):V})}const _=e.waferOpts?.diameter??300,E=Q({diameter:_,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});E.orientation!==0&&(s=se(s,E)),s=s.map(z);const H=be(e.reticleOpts,E,s,1,1,0,0,0,0,E.orientation),Se=O.map((B,V)=>z(q({id:`unpositioned_${V}`,width:s[0]?.width??1,height:s[0]?.height??1},B))),J=[...s,...x,...Se];return{wafer:E,dies:J,dataAxisFlip:{x:!1,y:!1},reticleConfig:e.reticleOpts,units:"mm",inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...De(p,r),...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:xe(d),metadata:E.metadata??null,isLotStack:!1,dataCoverage:ge(J),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:ye(J,e.passBins,e.edgeDieYieldMode),reticles:H,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields}}const h=d.filter(W),l=d.filter(s=>!W(s)),f=h.map(s=>({x:s.x,y:s.y})),y=He(f,e.dieOpts,e.waferOpts?.diameter);r.diePitch={confidence:y.confidence,units:y.units};const{pitchX:m,pitchY:c}=y,w=y.units,u=pt(h,e.dieOpts),C=Ue(f);r.grid={confidence:C.confidence};const{offsetX:D,offsetY:g}=ht(f,u,C),{flipX:b,flipY:k}=me(e.dieOpts,u),R=e.waferOpts?.diameter===void 0&&e.waferOpts?.center!==void 0&&mt(f,e.waferOpts.center),v=R?void 0:e.waferOpts?.center;R&&p.push({code:"implausible-center",message:yt(f,e.waferOpts.center)});const{colMidX:T,colMidY:L,anchored:K}=bt(f,D,g,m,c,v);let S=e.waferOpts?.diameter;const N=f.map(s=>({x:(Math.round(s.x)-D)*m-T,y:(Math.round(s.y)-g)*c-L})),M=ee(N.map(({x:s,y:x})=>Math.hypot(Math.abs(s)+m/2,Math.abs(x)+c/2)));if(S===void 0)if(f.length>0)if(w==="mm"){const s=je(N,{minRadius:M});S=s.diameter,r.wafer={confidence:s.confidence,method:s.method};const x=Ft(e.standardDiameters);if(!Rt(S,x)){const A=ve(S,x);p.push({code:"non-standard-diameter",message:`${Ot} ${S.toFixed(1)} mm is not a standard wafer size (nearest is ${A} mm). The diameter was derived from the die extent, which assumes the probed grid reaches the wafer edge \u2014 a non-standard result usually means it does not, because the outer dies were never probed. Every die is then placed against a wafer that is too small, which moves dies between rings and changes ring and edge findings. Supply waferConfig.diameter.`})}}else S=M*2,r.wafer={confidence:y.confidence*.8,method:"extent"};else S=w==="mm"?300:30,r.wafer={confidence:0,method:"default"};if(!K&&f.length>0&&wt(f,D,g)&&(r.wafer.method="inferred-partial",p.push({code:"partial-coverage",message:"Wafer geometry was inferred from die positions alone. The data does not span a full symmetric wafer, so the inferred diameter and centre may be wrong and dies may be mis-positioned relative to the true wafer boundary. Supply waferConfig.diameter and waferConfig.center (the prober coordinate of the wafer centre) to position partial data correctly."})),e.waferOpts?.diameter!==void 0&&v===void 0&&M>0&&f.length>=Me){const s=M/(S/2);s<$t&&p.push({code:"diameter-exceeds-die-extent",message:`${At} ${(s*100).toFixed(0)}% of the ${S} mm wafer's radius. Either the diameter is larger than the real one, or this is a partial map covering only part of the wafer. Ring bands are equal-radius, so the outer rings are mostly or entirely empty and ring, quadrant and edge findings describe the assumed wafer rather than the probed area. Check waferConfig.diameter, or drop it and let the diameter be inferred from the die extent.`})}if(e.waferOpts?.diameter!==void 0){const s=e.dieOpts?.width!==void 0&&e.dieOpts?.height!==void 0;if(s&&M>S/2+1e-9){const x=N.filter(({x:A,y:O})=>Math.hypot(Math.abs(A)+m/2,Math.abs(O)+c/2)>S/2+1e-9).length;p.push({code:"geometry-conflict",message:`${x} of ${N.length} probed die positions ${kt} ${S} mm wafer at the supplied die pitch of ${m} \xD7 ${c} mm. A die with test results is a real prober position and is always fully on the wafer, so one of the two supplied values must be wrong: containing these dies at this pitch would need a diameter of at least ${(M*2).toFixed(1)} mm. Check waferConfig.diameter and dieConfig.width/height against the real device.`})}}const F=Q({diameter:S,units:w,notch:e.waferOpts?.notch,orientation:e.waferOpts?.orientation??0,metadata:e.waferOpts?.metadata,reticle:e.reticleOpts});let $=h.map(s=>{const x=Math.round(s.x)-D,A=Math.round(s.y)-g,O={id:`${x}_${A}`,x,y:A,physX:x*m-T,physY:A*c-L,width:m,height:c,insideWafer:!0,partial:!1};return q(O,s)});(D!==0||g!==0)&&($=$.map(s=>({...s,x:s.x+D,y:s.y+g,id:`${s.x+D}_${s.y+g}`}))),$=se($,F),(b||k)&&($=Oe($,{flipX:b,flipY:k},F.center));const Y=[];e.waferOpts?.edgeExclusion&&e.waferOpts.edgeExclusion>0&&($=Mt($,F,e.waferOpts.edgeExclusion),e.waferOpts.edgeExclusion>F.radius&&Y.push({code:"edge-exclusion-exceeds-radius",message:`edgeExclusion (${e.waferOpts.edgeExclusion}mm) exceeds the resolved wafer radius (${F.radius}mm) \u2014 the entire wafer is excluded.`,severity:"warning"})),$=$.map(z);const j=be(e.reticleOpts,F,$,m,c,D,g,T,L,F.orientation,b,k),P=l.map((s,x)=>z(q({id:`unpositioned_${x}`,width:m,height:c},s))),I=[...$,...P];return{wafer:F,dies:I,dataAxisFlip:{x:b,y:k},reticleConfig:e.reticleOpts,units:w,inference:r,warnings:[...e.removedFieldWarning?[e.removedFieldWarning]:[],...e.inputValueWarnings,...o?[o]:[],...De(p,r),...Y,...t,...e.ringCountWarning?[e.ringCountWarning]:[]],plotMode:xe(d),metadata:F.metadata??null,isLotStack:e.lotStackOpts!==void 0,dataCoverage:ge(I),passBins:e.passBins,...i?{valueFilter:i}:{},ringCount:e.ringCount,yield:ye(I,e.passBins,e.edgeDieYieldMode,rt(e.lotStackOpts!==void 0,e.lotStackOpts?.method)),reticles:j,hbinDefs:e.hbinDefs,sbinDefs:e.sbinDefs,testDefs:e.testDefs,metadataFields:e.metadataFields,aggrMethod:e.lotStackOpts?.method,lotSize:e.lotStackOpts?.results.length}}
@@ -1,2 +1,2 @@
1
1
  import{isParametricTest as c}from"../buildWaferMap.js";import{hasSpecLimits as l}from"../spec.js";export const DIE_FIELD_CALLS={dieX:"x",dieY:"y",hbin:"hbin",sbin:"sbin",site:"site"},FUNCTIONS={abs:[{arity:1,returns:"number"}],sqrt:[{arity:1,returns:"number"}],ln:[{arity:1,returns:"number"}],log10:[{arity:1,returns:"number"}],exp:[{arity:1,returns:"number"}],floor:[{arity:1,returns:"number"}],ceil:[{arity:1,returns:"number"}],round:[{arity:1,returns:"number"}],sign:[{arity:1,returns:"number"}],pow:[{arity:2,returns:"number"}],min:[{vecOf:"numberVec",returns:"number"},{variadic:!0,returns:"number"}],max:[{vecOf:"numberVec",returns:"number"},{variadic:!0,returns:"number"}],if:[{arity:3,returns:"number"}],all:[{vecOf:"boolVec",returns:"boolean"}],any:[{vecOf:"boolVec",returns:"boolean"}],none:[{vecOf:"boolVec",returns:"boolean"}],countTrue:[{vecOf:"boolVec",returns:"number"}],countFalse:[{vecOf:"boolVec",returns:"number"}],mean:[{vecOf:"numberVec",returns:"number"}],sum:[{vecOf:"numberVec",returns:"number"}],countKnown:[{vecOf:"any",returns:"number"}]};const d=["t","testPass","specPass"],b=["<=",">=","==","!=","..","+","-","*","/","%","^","<",">"],m=["(",")","[","]",","];class o extends Error{position;constructor(t,e){super(t),this.position=e}}function h(r){const t=[];let e=0;for(;e<r.length;){const n=r[e];if(n===" "||n===" "||n===`
2
- `||n==="\r"){e++;continue}if(n>="0"&&n<="9"){const s=e;for(;e<r.length&&r[e]>="0"&&r[e]<="9";)e++;if(r[e]==="."&&r[e+1]!==".")for(e++;e<r.length&&r[e]>="0"&&r[e]<="9";)e++;if(r[e]==="e"||r[e]==="E"){const a=e;if(e++,(r[e]==="+"||r[e]==="-")&&e++,r[e]>="0"&&r[e]<="9")for(;e<r.length&&r[e]>="0"&&r[e]<="9";)e++;else e=a}const u=r.slice(s,e);t.push({kind:"num",text:u,pos:s,value:Number(u)});continue}if(/[A-Za-z_]/.test(n)){const s=e;for(;e<r.length&&/[A-Za-z0-9_]/.test(r[e]);)e++;t.push({kind:"ident",text:r.slice(s,e),pos:s});continue}const i=b.find(s=>r.startsWith(s,e));if(i){t.push({kind:"op",text:i,pos:e}),e+=i.length;continue}if(m.includes(n)){t.push({kind:"punc",text:n,pos:e}),e++;continue}throw new o(`Unexpected character ${JSON.stringify(n)} at position ${e}`,e)}return t.push({kind:"eof",text:"",pos:r.length}),t}class f{toks;ctx;p=0;reads=[];usesDiePass=!1;constructor(t,e){this.toks=t,this.ctx=e}peek(){return this.toks[this.p]}next(){return this.toks[this.p++]}at(t){const e=this.peek();return(e.kind==="op"||e.kind==="punc"||e.kind==="ident")&&e.text===t}eat(t){return this.at(t)?(this.p++,!0):!1}expect(t){if(!this.at(t)){const e=this.peek();throw new o(`Expected ${JSON.stringify(t)} but found ${e.kind==="eof"?"end of expression":JSON.stringify(e.text)} at position ${e.pos}`,e.pos)}return this.next()}parse(){const t=this.parseOr();return this.expectEnd(),t}parseTestRefOnly(){const t=this.parseTestRef(this.peek().pos);return this.expectEnd(),t}expectEnd(){const t=this.peek();if(t.kind!=="eof")throw new o(`Unexpected ${JSON.stringify(t.text)} at position ${t.pos}`,t.pos)}requireScalar(t,e,n){if(t.type==="numberVec"||t.type==="boolVec")throw new o(`${e} cannot be applied to a test range at position ${n} \u2014 a range must be reduced first, e.g. mean(t[1010..1015]) or all(testPass[1010..1015])`,n);return t.type}parseOr(){let t=this.parseAnd();for(;this.at("or");){const e=this.next().pos,n=this.parseAnd();this.requireBool(t,"or",e),this.requireBool(n,"or",e),t={node:{k:"binary",op:"or",left:t.node,right:n.node},type:"boolean"}}return t}parseAnd(){let t=this.parseNot();for(;this.at("and");){const e=this.next().pos,n=this.parseNot();this.requireBool(t,"and",e),this.requireBool(n,"and",e),t={node:{k:"binary",op:"and",left:t.node,right:n.node},type:"boolean"}}return t}requireBool(t,e,n){if(this.requireScalar(t,`Operator ${JSON.stringify(e)}`,n),t.type!=="boolean")throw new o(`Operator ${JSON.stringify(e)} needs a true/false operand at position ${n}, but got a number \u2014 compare it first, e.g. t[1020] > 5`,n)}parseNot(){if(this.at("not")){const t=this.next().pos,e=this.parseNot();return this.requireBool(e,"not",t),{node:{k:"unary",op:"not",arg:e.node},type:"boolean"}}return this.parseCompare()}parseCompare(){const t=this.parseAdd(),e=this.peek();if(e.kind==="op"&&["<","<=",">",">=","==","!="].includes(e.text)){this.next();const n=this.parseAdd(),i=this.requireScalar(t,`Operator ${JSON.stringify(e.text)}`,e.pos),s=this.requireScalar(n,`Operator ${JSON.stringify(e.text)}`,e.pos);if(i!==s)throw new o(`Cannot compare a ${i} with a ${s} at position ${e.pos}`,e.pos);if(i==="boolean"&&e.text!=="=="&&e.text!=="!=")throw new o(`Operator ${JSON.stringify(e.text)} cannot order true/false values at position ${e.pos}`,e.pos);return{node:{k:"binary",op:e.text,left:t.node,right:n.node},type:"boolean"}}return t}parseAdd(){let t=this.parseMul();for(;;){const e=this.peek();if(e.kind!=="op"||e.text!=="+"&&e.text!=="-")return t;this.next();const n=this.parseMul();this.requireNum(t,e.text,e.pos),this.requireNum(n,e.text,e.pos),t={node:{k:"binary",op:e.text,left:t.node,right:n.node},type:"number"}}}parseMul(){let t=this.parsePow();for(;;){const e=this.peek();if(e.kind!=="op"||!["*","/","%"].includes(e.text))return t;this.next();const n=this.parsePow();this.requireNum(t,e.text,e.pos),this.requireNum(n,e.text,e.pos),t={node:{k:"binary",op:e.text,left:t.node,right:n.node},type:"number"}}}parsePow(){const t=this.parseUnary(),e=this.peek();if(e.kind==="op"&&e.text==="^"){this.next();const n=this.parsePow();return this.requireNum(t,"^",e.pos),this.requireNum(n,"^",e.pos),{node:{k:"binary",op:"^",left:t.node,right:n.node},type:"number"}}return t}requireNum(t,e,n){if(this.requireScalar(t,`Operator ${JSON.stringify(e)}`,n),t.type!=="number")throw new o(`Operator ${JSON.stringify(e)} needs a numeric operand at position ${n}, but got a true/false value`,n)}parseUnary(){const t=this.peek();if(t.kind==="op"&&t.text==="-"){this.next();const e=this.parseUnary();return this.requireNum(e,"-",t.pos),{node:{k:"unary",op:"-",arg:e.node},type:"number"}}return this.parsePrimary()}parsePrimary(){const t=this.next();if(t.kind==="num")return{node:{k:"num",value:t.value},type:"number"};if(t.kind==="punc"&&t.text==="("){const e=this.parseOr();return this.expect(")"),e}if(t.kind==="ident"){if(d.includes(t.text))return this.parseAccessor(t.text,t.pos);if(t.text==="diePass")return this.expect("("),this.expect(")"),this.usesDiePass=!0,{node:{k:"diePass"},type:"boolean"};if(Object.prototype.hasOwnProperty.call(DIE_FIELD_CALLS,t.text)){if(!this.at("("))throw new o(`${JSON.stringify(t.text)} at position ${t.pos} reads a die's own field and is written with parentheses: ${t.text}().`,t.pos);return this.expect("("),this.expect(")"),{node:{k:"dieField",field:DIE_FIELD_CALLS[t.text]},type:"number"}}if(this.at("("))return this.parseCall(t.text,t.pos);if(Object.prototype.hasOwnProperty.call(this.ctx.constants,t.text)){const e=this.ctx.constants[t.text];if(typeof e!="number"||!Number.isFinite(e))throw new o(`Constant ${JSON.stringify(t.text)} at position ${t.pos} is not a finite number`,t.pos);return{node:{k:"num",value:e},type:"number"}}throw new o(`Unknown name ${JSON.stringify(t.text)} at position ${t.pos}. Test values are read as t[1020], verdicts as testPass[1020] or specPass[1020], a die's own fields as dieX(), dieY(), hbin(), sbin() or site(); other names must be declared in \`constants\`.`,t.pos)}throw new o(`Unexpected ${t.kind==="eof"?"end of expression":JSON.stringify(t.text)} at position ${t.pos}`,t.pos)}parseAccessor(t,e){this.expect("[");const{tests:n,range:i}=this.parseTestRef(e);this.expect("]");for(const u of n)this.checkAccessible(t,u,e);for(const u of n)this.reads.push({kind:t,test:u});const s=t==="t"?"number":"boolean";return i?{node:{k:"vec",kind:t,tests:n},type:s==="number"?"numberVec":"boolVec"}:{node:{k:"acc",kind:t,test:n[0]},type:s}}checkAccessible(t,e,n){const i=this.ctx.testDefs.get(e);if(i===void 0)throw new o(`Test ${e} at position ${n} is not declared in \`testDefs\``,n);if(t==="t"&&!c(i))throw new o(`t[${e}] at position ${n} reads a measured value, but test ${e} is functional (testType 'F') and has no measured value \u2014 use testPass[${e}] for its verdict`,n);if(t==="specPass"){if(!c(i))throw new o(`specPass[${e}] at position ${n} needs test limits, but test ${e} is functional (testType 'F') \u2014 use testPass[${e}] for its recorded verdict`,n);if(!l(i))throw new o(`specPass[${e}] at position ${n} needs \`limitLow\` or \`limitHigh\` on test ${e}, which declares neither`,n)}}parseTestRef(t){const e=this.expectInt();if(!this.eat(".."))return{tests:[e],range:!1};const n=this.expectInt();if(n<e)throw new o(`Test range ${e}..${n} at position ${t} runs backwards`,t);const i=[...this.ctx.testDefs.keys()].filter(s=>s>=e&&s<=n).sort((s,u)=>s-u);if(i.length===0)throw new o(`Test range ${e}..${n} at position ${t} matches no declared test`,t);return{tests:i,range:!0}}expectInt(){const t=this.peek();if(t.kind!=="num"||!Number.isInteger(t.value))throw new o(`Expected a test number at position ${t.pos}`,t.pos);return this.next(),t.value}parseCall(t,e){const n=FUNCTIONS[t];if(n===void 0)throw new o(`Unknown function ${JSON.stringify(t)} at position ${e}. Available: ${Object.keys(FUNCTIONS).sort().join(", ")}`,e);this.expect("(");const i=[];if(!this.at(")"))do i.push(this.parseOr());while(this.eat(","));this.expect(")");const s=i.map(a=>a.type),u={k:"call",name:t,args:i.map(a=>a.node)};for(const a of n){if(a.vecOf!==void 0){if(s.length!==1)continue;const p=s[0];if(!(p==="numberVec"||p==="boolVec")||a.vecOf!=="any"&&a.vecOf!==p)continue;return{node:u,type:a.returns}}if(a.variadic){if(s.length<2||!s.every(p=>p==="number"))continue;return{node:u,type:a.returns}}if(a.arity!==void 0){if(s.length!==a.arity)continue;if(t==="if"){if(s[0]!=="boolean"||s[1]!=="number"||s[2]!=="number")continue;return{node:u,type:"number"}}if(!s.every(p=>p==="number"))continue;return{node:u,type:a.returns}}}throw new o(`${t}(${s.join(", ")}) at position ${e} is not a valid call \u2014 ${x(t,n)}`,e)}}function x(r,t){return`expected ${t.map(n=>n.vecOf==="boolVec"?`${r}(<true/false test range>)`:n.vecOf==="numberVec"?`${r}(<value test range>)`:n.vecOf==="any"?`${r}(<test range>)`:n.variadic?`${r}(number, number, \u2026)`:r==="if"?"if(<true/false>, number, number)":`${r}(${Array.from({length:n.arity??0},()=>"number").join(", ")})`).join(" or ")}`}export function parseExpression(r,t){try{if(r.length>MAX_EXPRESSION_LENGTH)return{ok:!1,message:`Expression is ${r.length} characters, over the ${MAX_EXPRESSION_LENGTH} limit`,position:MAX_EXPRESSION_LENGTH};const e=new f(h(r),t),{node:n,type:i}=e.parse();return i==="numberVec"||i==="boolVec"?{ok:!1,message:"Expression results in a test range, not a single value \u2014 reduce it, e.g. mean(t[1010..1015]) or all(testPass[1010..1015])",position:0}:{ok:!0,ast:n,type:i,reads:e.reads,usesDiePass:e.usesDiePass}}catch(e){if(e instanceof o)return{ok:!1,message:e.message,position:e.position};throw e}}export function parseTestReference(r,t){try{if(r.length>MAX_EXPRESSION_LENGTH)return{ok:!1,message:`Test reference is ${r.length} characters, over the ${MAX_EXPRESSION_LENGTH} limit`,position:MAX_EXPRESSION_LENGTH};const{tests:e,range:n}=new f(h(r),{testDefs:t,constants:{}}).parseTestRefOnly();return{ok:!0,tests:e,range:n}}catch(e){if(e instanceof o)return{ok:!1,message:e.message,position:e.position};throw e}}export const MAX_EXPRESSION_LENGTH=2e3;
2
+ `||n==="\r"){e++;continue}if(n>="0"&&n<="9"){const s=e;for(;e<r.length&&r[e]>="0"&&r[e]<="9";)e++;if(r[e]==="."&&r[e+1]!==".")for(e++;e<r.length&&r[e]>="0"&&r[e]<="9";)e++;if(r[e]==="e"||r[e]==="E"){const a=e;if(e++,(r[e]==="+"||r[e]==="-")&&e++,r[e]>="0"&&r[e]<="9")for(;e<r.length&&r[e]>="0"&&r[e]<="9";)e++;else e=a}const u=r.slice(s,e);t.push({kind:"num",text:u,pos:s,value:Number(u)});continue}if(/[A-Za-z_]/.test(n)){const s=e;for(;e<r.length&&/[A-Za-z0-9_]/.test(r[e]);)e++;t.push({kind:"ident",text:r.slice(s,e),pos:s});continue}const i=b.find(s=>r.startsWith(s,e));if(i){t.push({kind:"op",text:i,pos:e}),e+=i.length;continue}if(m.includes(n)){t.push({kind:"punc",text:n,pos:e}),e++;continue}throw new o(`Unexpected character ${JSON.stringify(n)} at position ${e}`,e)}return t.push({kind:"eof",text:"",pos:r.length}),t}class f{toks;ctx;p=0;reads=[];usesDiePass=!1;constructor(t,e){this.toks=t,this.ctx=e}peek(){return this.toks[this.p]}next(){return this.toks[this.p++]}at(t){const e=this.peek();return(e.kind==="op"||e.kind==="punc"||e.kind==="ident")&&e.text===t}eat(t){return this.at(t)?(this.p++,!0):!1}expect(t){if(!this.at(t)){const e=this.peek();throw new o(`Expected ${JSON.stringify(t)} but found ${e.kind==="eof"?"end of expression":JSON.stringify(e.text)} at position ${e.pos}`,e.pos)}return this.next()}parse(){const t=this.parseOr();return this.expectEnd(),t}parseTestRefOnly(){const t=this.parseTestRef(this.peek().pos);return this.expectEnd(),t}expectEnd(){const t=this.peek();if(t.kind!=="eof")throw new o(`Unexpected ${JSON.stringify(t.text)} at position ${t.pos}`,t.pos)}requireScalar(t,e,n){if(t.type==="numberVec"||t.type==="boolVec")throw new o(`${e} cannot be applied to a test range at position ${n} \u2014 a range must be reduced first, e.g. mean(t[1010..1015]) or all(testPass[1010..1015])`,n);return t.type}parseOr(){let t=this.parseAnd();for(;this.at("or");){const e=this.next().pos,n=this.parseAnd();this.requireBool(t,"or",e),this.requireBool(n,"or",e),t={node:{k:"binary",op:"or",left:t.node,right:n.node},type:"boolean"}}return t}parseAnd(){let t=this.parseNot();for(;this.at("and");){const e=this.next().pos,n=this.parseNot();this.requireBool(t,"and",e),this.requireBool(n,"and",e),t={node:{k:"binary",op:"and",left:t.node,right:n.node},type:"boolean"}}return t}requireBool(t,e,n){if(this.requireScalar(t,`Operator ${JSON.stringify(e)}`,n),t.type!=="boolean")throw new o(`Operator ${JSON.stringify(e)} needs a true/false operand at position ${n}, but got a number \u2014 compare it first, e.g. t[1020] > 5`,n)}parseNot(){if(this.at("not")){const t=this.next().pos,e=this.parseNot();return this.requireBool(e,"not",t),{node:{k:"unary",op:"not",arg:e.node},type:"boolean"}}return this.parseCompare()}parseCompare(){const t=this.parseAdd(),e=this.peek();if(e.kind==="op"&&["<","<=",">",">=","==","!="].includes(e.text)){this.next();const n=this.parseAdd(),i=this.requireScalar(t,`Operator ${JSON.stringify(e.text)}`,e.pos),s=this.requireScalar(n,`Operator ${JSON.stringify(e.text)}`,e.pos);if(i!==s)throw new o(`Cannot compare a ${i} with a ${s} at position ${e.pos}`,e.pos);if(i==="boolean"&&e.text!=="=="&&e.text!=="!=")throw new o(`Operator ${JSON.stringify(e.text)} cannot order true/false values at position ${e.pos}`,e.pos);return{node:{k:"binary",op:e.text,left:t.node,right:n.node},type:"boolean"}}return t}parseAdd(){let t=this.parseMul();for(;;){const e=this.peek();if(e.kind!=="op"||e.text!=="+"&&e.text!=="-")return t;this.next();const n=this.parseMul();this.requireNum(t,e.text,e.pos),this.requireNum(n,e.text,e.pos),t={node:{k:"binary",op:e.text,left:t.node,right:n.node},type:"number"}}}parseMul(){let t=this.parsePow();for(;;){const e=this.peek();if(e.kind!=="op"||!["*","/","%"].includes(e.text))return t;this.next();const n=this.parsePow();this.requireNum(t,e.text,e.pos),this.requireNum(n,e.text,e.pos),t={node:{k:"binary",op:e.text,left:t.node,right:n.node},type:"number"}}}parsePow(){const t=this.parseUnary(),e=this.peek();if(e.kind==="op"&&e.text==="^"){this.next();const n=this.parsePow();return this.requireNum(t,"^",e.pos),this.requireNum(n,"^",e.pos),{node:{k:"binary",op:"^",left:t.node,right:n.node},type:"number"}}return t}requireNum(t,e,n){if(this.requireScalar(t,`Operator ${JSON.stringify(e)}`,n),t.type!=="number")throw new o(`Operator ${JSON.stringify(e)} needs a numeric operand at position ${n}, but got a true/false value`,n)}parseUnary(){const t=this.peek();if(t.kind==="op"&&t.text==="-"){this.next();const e=this.parseUnary();return this.requireNum(e,"-",t.pos),{node:{k:"unary",op:"-",arg:e.node},type:"number"}}return this.parsePrimary()}parsePrimary(){const t=this.next();if(t.kind==="num")return{node:{k:"num",value:t.value},type:"number"};if(t.kind==="punc"&&t.text==="("){const e=this.parseOr();return this.expect(")"),e}if(t.kind==="ident"){if(d.includes(t.text))return this.parseAccessor(t.text,t.pos);if(t.text==="diePass")return this.expect("("),this.expect(")"),this.usesDiePass=!0,{node:{k:"diePass"},type:"boolean"};if(Object.prototype.hasOwnProperty.call(DIE_FIELD_CALLS,t.text)&&(this.at("(")||!Object.prototype.hasOwnProperty.call(this.ctx.constants,t.text))){if(!this.at("("))throw new o(`${JSON.stringify(t.text)} at position ${t.pos} reads a die's own field and is written with parentheses: ${t.text}().`,t.pos);return this.expect("("),this.expect(")"),{node:{k:"dieField",field:DIE_FIELD_CALLS[t.text]},type:"number"}}if(this.at("("))return this.parseCall(t.text,t.pos);if(Object.prototype.hasOwnProperty.call(this.ctx.constants,t.text)){const e=this.ctx.constants[t.text];if(typeof e!="number"||!Number.isFinite(e))throw new o(`Constant ${JSON.stringify(t.text)} at position ${t.pos} is not a finite number`,t.pos);return{node:{k:"num",value:e},type:"number"}}throw new o(`Unknown name ${JSON.stringify(t.text)} at position ${t.pos}. Test values are read as t[1020], verdicts as testPass[1020] or specPass[1020], a die's own fields as dieX(), dieY(), hbin(), sbin() or site(); other names must be declared in \`constants\`.`,t.pos)}throw new o(`Unexpected ${t.kind==="eof"?"end of expression":JSON.stringify(t.text)} at position ${t.pos}`,t.pos)}parseAccessor(t,e){this.expect("[");const{tests:n,range:i}=this.parseTestRef(e);this.expect("]");for(const u of n)this.checkAccessible(t,u,e);for(const u of n)this.reads.push({kind:t,test:u});const s=t==="t"?"number":"boolean";return i?{node:{k:"vec",kind:t,tests:n},type:s==="number"?"numberVec":"boolVec"}:{node:{k:"acc",kind:t,test:n[0]},type:s}}checkAccessible(t,e,n){const i=this.ctx.testDefs.get(e);if(i===void 0)throw new o(`Test ${e} at position ${n} is not declared in \`testDefs\``,n);if(t==="t"&&!c(i))throw new o(`t[${e}] at position ${n} reads a measured value, but test ${e} is functional (testType 'F') and has no measured value \u2014 use testPass[${e}] for its verdict`,n);if(t==="specPass"){if(!c(i))throw new o(`specPass[${e}] at position ${n} needs test limits, but test ${e} is functional (testType 'F') \u2014 use testPass[${e}] for its recorded verdict`,n);if(!l(i))throw new o(`specPass[${e}] at position ${n} needs \`limitLow\` or \`limitHigh\` on test ${e}, which declares neither`,n)}}parseTestRef(t){const e=this.expectInt();if(!this.eat(".."))return{tests:[e],range:!1};const n=this.expectInt();if(n<e)throw new o(`Test range ${e}..${n} at position ${t} runs backwards`,t);const i=[...this.ctx.testDefs.keys()].filter(s=>s>=e&&s<=n).sort((s,u)=>s-u);if(i.length===0)throw new o(`Test range ${e}..${n} at position ${t} matches no declared test`,t);return{tests:i,range:!0}}expectInt(){const t=this.peek();if(t.kind!=="num"||!Number.isInteger(t.value))throw new o(`Expected a test number at position ${t.pos}`,t.pos);return this.next(),t.value}parseCall(t,e){const n=FUNCTIONS[t];if(n===void 0)throw new o(`Unknown function ${JSON.stringify(t)} at position ${e}. Available: ${Object.keys(FUNCTIONS).sort().join(", ")}`,e);this.expect("(");const i=[];if(!this.at(")"))do i.push(this.parseOr());while(this.eat(","));this.expect(")");const s=i.map(a=>a.type),u={k:"call",name:t,args:i.map(a=>a.node)};for(const a of n){if(a.vecOf!==void 0){if(s.length!==1)continue;const p=s[0];if(!(p==="numberVec"||p==="boolVec")||a.vecOf!=="any"&&a.vecOf!==p)continue;return{node:u,type:a.returns}}if(a.variadic){if(s.length<2||!s.every(p=>p==="number"))continue;return{node:u,type:a.returns}}if(a.arity!==void 0){if(s.length!==a.arity)continue;if(t==="if"){if(s[0]!=="boolean"||s[1]!=="number"||s[2]!=="number")continue;return{node:u,type:"number"}}if(!s.every(p=>p==="number"))continue;return{node:u,type:a.returns}}}throw new o(`${t}(${s.join(", ")}) at position ${e} is not a valid call \u2014 ${x(t,n)}`,e)}}function x(r,t){return`expected ${t.map(n=>n.vecOf==="boolVec"?`${r}(<true/false test range>)`:n.vecOf==="numberVec"?`${r}(<value test range>)`:n.vecOf==="any"?`${r}(<test range>)`:n.variadic?`${r}(number, number, \u2026)`:r==="if"?"if(<true/false>, number, number)":`${r}(${Array.from({length:n.arity??0},()=>"number").join(", ")})`).join(" or ")}`}export function parseExpression(r,t){try{if(r.length>MAX_EXPRESSION_LENGTH)return{ok:!1,message:`Expression is ${r.length} characters, over the ${MAX_EXPRESSION_LENGTH} limit`,position:MAX_EXPRESSION_LENGTH};const e=new f(h(r),t),{node:n,type:i}=e.parse();return i==="numberVec"||i==="boolVec"?{ok:!1,message:"Expression results in a test range, not a single value \u2014 reduce it, e.g. mean(t[1010..1015]) or all(testPass[1010..1015])",position:0}:{ok:!0,ast:n,type:i,reads:e.reads,usesDiePass:e.usesDiePass}}catch(e){if(e instanceof o)return{ok:!1,message:e.message,position:e.position};throw e}}export function parseTestReference(r,t){try{if(r.length>MAX_EXPRESSION_LENGTH)return{ok:!1,message:`Test reference is ${r.length} characters, over the ${MAX_EXPRESSION_LENGTH} limit`,position:MAX_EXPRESSION_LENGTH};const{tests:e,range:n}=new f(h(r),{testDefs:t,constants:{}}).parseTestRefOnly();return{ok:!0,tests:e,range:n}}catch(e){if(e instanceof o)return{ok:!1,message:e.message,position:e.position};throw e}}export const MAX_EXPRESSION_LENGTH=2e3;
@@ -19,6 +19,16 @@ export declare function fmtAggregationMethod(method: string | undefined): string
19
19
  * compact internal terms (they're also machine-consumed and test-asserted).
20
20
  */
21
21
  export declare function plainBinTerms(text: string): string;
22
+ /**
23
+ * A stored number as text, in the fewest digits that are still exactly it. STDF
24
+ * stores limits and results as 32-bit floats, so a limit written as 1.6 arrives as
25
+ * 1.600000023841858; a value that is exactly a float32 is written in the shortest
26
+ * digits that are still that float32 ("1.6", "2.0087667"), any other number as it
27
+ * is. For a value shown as itself — a limit, a category of a discrete X — where
28
+ * `fmt`'s rounding to a few figures would hide a real difference. Display only:
29
+ * comparisons keep the exact value.
30
+ */
31
+ export declare function fmtExact(v: number): string;
22
32
  /**
23
33
  * Format a numeric value for display (tooltips, overlays, single-value labels).
24
34
  *