/*
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/maybe","../support/mathUtils","./TerrainConst"],(function(t,e,a,i,l){"use strict";let o=function(){function t(t,e,a){this.type="elevation",this.samplerData=null,this.level=t[0],this.i=t[1],this.j=t[2],this.extent=e;const i=a.noDataValue,l=a.values;let o=1/0,n=-1/0,s=!0,r=!1;for(let h=0;h<l.length;h++){const t=l[h];t!==i?(o=t<o?t:o,n=t>n?t:n,s=!1):r=!0}s&&(o=0,n=0),n=n>-3e38?n:0,this.samplerData={pixelData:a.values,width:a.width,height:a.height,noDataValue:i,safeWidth:.99999999*(a.width-1),dx:(a.width-1)/(e[2]-e[0]),dy:(a.width-1)/(e[3]-e[1]),x0:e[0],y1:e[3]},this.bounds=[o,n],this.hasNoDataValues=r}var e=t.prototype;return e.release=function(){this.samplerData=null,this.bounds=null},e.computeMinMaxValue=function(t,e,a,o){o.min=1/0,o.max=-1/0,o.hasNoDataValues=!1;const n=t-this.level;if(n<=0)return o;const s=2**n;if(!(Math.floor(e/s)===this.i&&Math.floor(a/s)===this.j))return o;let r=1/0,h=-1/0;const u=this.samplerData.width,f=this.samplerData.pixelData,c=.5*l.ELEVATION_NODATA_VALUE;let m=(u-1)/s,p=(a-this.j*s)*m,d=(e-this.i*s)*m;if(m<1){const t=Math.floor(p),e=Math.floor(d),a=t+e*u,l=f[a],n=f[a+1],s=f[a+u],r=f[a+u+1];if(l+n+s+r<c){const a=p-t,h=d-e,u=i.bilerp(l,n,s,r,a,h),f=i.bilerp(l,n,s,r,a+m,h),c=i.bilerp(l,n,s,r,a,h+m),M=i.bilerp(l,n,s,r,a+m,h+m);return o.min=Math.min(u,f,c,M),o.max=Math.max(u,f,c,M),o}p=t,d=e,m=1}else p=Math.floor(p),d=Math.floor(d),m=Math.ceil(m);for(let i=p;i<=p+m;i++)for(let t=d;t<=d+m;t++){const e=f[i+t*u];e<c?(r=Math.min(r,e),h=Math.max(h,e)):o.hasNoDataValues=!0}return o.min=r,o.max=h,o},t}();function n(t,i,o){if(a.isNone(o))return null;for(const a of o){if(!a)continue;const o=a.safeWidth;let n=e.clamp(a.dy*(a.y1-i),0,o),s=e.clamp(a.dx*(t-a.x0),0,o);const r=Math.floor(n),h=Math.floor(s),u=a.width,f=r*u+h,c=a.pixelData,m=c[f],p=c[f+1],d=f+u,M=c[d],D=c[d+1];if(m+M+p+D<.5*l.ELEVATION_NODATA_VALUE){n-=r,s-=h;const t=m+(p-m)*s;return t+(M+(D-M)*s-t)*n}}return null}function s(t,e,i){const l=n(t,e,i);return a.isSome(l)?l:0}t.ElevationData=o,t.sampleElevation=n,t.sampleElevationOrZero=s,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
