/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/mathUtils","../../core/screenUtils","../../chunks/vec4","../../chunks/vec4f64"],(function(t,e,n,r,a){"use strict";const o=2.4;function i(t){return n.px2pt(t*o)}function u(t){return n.pt2px(t)/o}function c(t,n,a,o){let{color:i,ratio:u}=n,{color:c,ratio:s}=a;if(s===u){const t=1e-6;1===s?u-=t:s+=t}const f=e.clamp((o-u)/(s-u),0,1);r.lerp(t,i.toArray(),c.toArray(),f)}function s(t){const e=512,n=new Uint8ClampedArray(4*e);if(t=t.filter((({ratio:t})=>t>=0&&t<=1)).sort(((t,e)=>t.ratio-e.ratio)).map((({color:t,ratio:e})=>({color:t,ratio:Math.max(e,.001)}))),t.length<1)return n;let r=t[0],o=t[0],i=1;const u=a.create();for(let a=0;a<e;a++){const s=(a+.5)/e;for(;s>o.ratio&&i<t.length;)r=o,o=t[i++];c(u,r,o,s),n.set(u,4*a)}return n}function f(t,e,r,a){const{radius:o,fieldOffset:i,field:u}=e,c=n.pt2px(o),s=new Float64Array(r*a);let f,l=Number.NEGATIVE_INFINITY;const d=h(u,i);for(const{geometry:n,attributes:m}of t){const t=Math.max(0,n.x-c),e=Math.max(0,n.y-c),o=Math.min(a,n.y+c),i=Math.min(r,n.x+c),u=+d(m);for(let a=e;a<o;a++)for(let e=t;e<i;e++){const t=a*r+e,o=y(n.x-e,n.y-a,c);f=s[t]+=o*u,f>l&&(l=f)}}return{matrix:s.buffer,max:l}}function l(t,e,r,a){const{radius:o,fieldOffset:i,field:u}=e,c=Math.round(n.pt2px(o)),s=new Float64Array(r*a);let f,l=Number.NEGATIVE_INFINITY;const d=x(u,i),m=new Set;for(const n of t){const t=n.getCursor();for(;t.next();){const e=t.getObjectId();if(m.has(e))continue;m.add(e);const n=t.readLegacyPointGeometry(),o=128;if(n.x<-o||n.x>=r+o||n.y<-o||n.y>a+o)continue;const i=+d(t),u=Math.max(0,Math.round(n.x)-c),h=Math.max(0,Math.round(n.y)-c),x=Math.min(a,Math.round(n.y)+c),p=Math.min(r,Math.round(n.x)+c);for(let t=h;t<x;t++)for(let e=u;e<p;e++){const a=t*r+e,o=y(n.x-e,n.y-t,c);f=s[a]+=o*i,f>l&&(l=f)}}}return{matrix:s.buffer,max:l}}function d(t,e,n,r,a,o){t.canvas.width=t.canvas.height=e,t.clearRect(0,0,e,e);const i=t.getImageData(0,0,e,e);n&&r&&i.data.set(new Uint8ClampedArray(m(e,n,r,a,o))),t.putImageData(i,0,0)}function m(t,n,r,a,o){const i=new Uint32Array(t*t),u="buffer"in n?n:new Float64Array(n),c="buffer"in r?new Uint32Array(r.buffer):new Uint32Array(new Uint8Array(r).buffer),s=c.length/(o-a);for(let f=0;f<u.length;f++){const t=u[f],n=Math.floor((t-a)*s);i[f]=c[e.clamp(n,0,c.length-1)]}return i.buffer}function y(t,e,n){const r=Math.sqrt(t**2+e**2)/n;return r>1?0:3/(Math.PI*n**2)*(1-r**2)**2}function h(t,e){return"function"==typeof t?t:t?"string"==typeof e?e=>-1*+e[t]:n=>+n[t]+e:()=>1}function x(t,e){return null!=t?"string"==typeof e?e=>-1*+e.readAttribute(t):n=>+n.readAttribute(t)+e:t=>1}t.MAGIC_KERNEL_DENSITY_RADIUS_INFLATION_FACTOR=o,t.calculateHeatmapIntensityInfo=f,t.calculateHeatmapIntensityInfoReaders=l,t.createHeatmapImageData=m,t.createValueFunction=h,t.createValueFunctionCursor=x,t.drawHeatmap=d,t.evaluateDensityKernel=y,t.gaussianBlurRadiusPxToKernelDensityRadiusPt=i,t.generateGradient=s,t.kernelDensityRadiusPtToGaussianBlurRadiusPx=u,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
