define(["./Matrix2-fc7e9822","./AxisAlignedBoundingBox-7a3018c0","./Transforms-3ac41eb6","./defaultValue-94c3e563","./RuntimeError-c581ca93","./TerrainEncoding-229275c2","./ComponentDatatype-4a60b8d6","./OrientedBoundingBox-1e0d2855","./WebMercatorProjection-843df830","./_commonjsHelpers-3aae1032-f55dc0c4","./createTaskProcessorWorker","./combine-761d9c3f","./AttributeCompression-4d18cc04","./WebGLConstants-7dccdc96","./EllipsoidTangentPlane-53e32153","./IntersectionTests-68fbc42d","./Plane-e20fba8c"],(function(e,t,i,n,a,r,s,l,o,f,u,c,d,h,m,g,p){"use strict";const w={NONE:0,LERC:1};var x=Object.freeze(w);const k={};k.DEFAULT_STRUCTURE=Object.freeze({heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:256,isBigEndian:!1});const y=new e.Cartesian3,I=new e.Matrix4,U=new e.Cartesian3,b=new e.Cartesian3;k.computeVertices=function(f){if(!n.defined(f)||!n.defined(f.heightmap))throw new a.DeveloperError("options.heightmap is required.");if(!n.defined(f.width)||!n.defined(f.height))throw new a.DeveloperError("options.width and options.height are required.");if(!n.defined(f.nativeRectangle))throw new a.DeveloperError("options.nativeRectangle is required.");if(!n.defined(f.skirtHeight))throw new a.DeveloperError("options.skirtHeight is required.");const u=Math.cos,c=Math.sin,d=Math.sqrt,h=Math.atan,m=Math.exp,g=s.CesiumMath.PI_OVER_TWO,p=s.CesiumMath.toRadians,w=f.heightmap,x=f.width,v=f.height,T=f.skirtHeight,M=T>0,V=n.defaultValue(f.isGeographic,!0),A=n.defaultValue(f.ellipsoid,e.Ellipsoid.WGS84),B=1/A.maximumRadius,D=e.Rectangle.clone(f.nativeRectangle),S=e.Rectangle.clone(f.rectangle);let P,E,C,F;n.defined(S)?(P=S.west,E=S.south,C=S.east,F=S.north):V?(P=p(D.west),E=p(D.south),C=p(D.east),F=p(D.north)):(P=D.west*B,E=g-2*h(m(-D.south*B)),C=D.east*B,F=g-2*h(m(-D.north*B)));let L=f.relativeToCenter;const R=n.defined(L);L=R?L:e.Cartesian3.ZERO;const N=n.defaultValue(f.includeWebMercatorT,!1),O=n.defaultValue(f.exaggeration,1),z=n.defaultValue(f.exaggerationRelativeHeight,0),H=1!==O,_=H,Y=n.defaultValue(f.structure,k.DEFAULT_STRUCTURE),W=n.defaultValue(Y.heightScale,k.DEFAULT_STRUCTURE.heightScale),X=n.defaultValue(Y.heightOffset,k.DEFAULT_STRUCTURE.heightOffset),Z=n.defaultValue(Y.elementsPerHeight,k.DEFAULT_STRUCTURE.elementsPerHeight),j=n.defaultValue(Y.stride,k.DEFAULT_STRUCTURE.stride),q=n.defaultValue(Y.elementMultiplier,k.DEFAULT_STRUCTURE.elementMultiplier),G=n.defaultValue(Y.isBigEndian,k.DEFAULT_STRUCTURE.isBigEndian);let Q=e.Rectangle.computeWidth(D),J=e.Rectangle.computeHeight(D);const K=Q/(x-1),$=J/(v-1);V||(Q*=B,J*=B);const ee=A.radiiSquared,te=ee.x,ie=ee.y,ne=ee.z;let ae=65536,re=-65536;const se=i.Transforms.eastNorthUpToFixedFrame(L,A),le=e.Matrix4.inverseTransformation(se,I);let oe,fe;N&&(oe=o.WebMercatorProjection.geodeticLatitudeToMercatorAngle(E),fe=1/(o.WebMercatorProjection.geodeticLatitudeToMercatorAngle(F)-oe));const ue=U;ue.x=Number.POSITIVE_INFINITY,ue.y=Number.POSITIVE_INFINITY,ue.z=Number.POSITIVE_INFINITY;const ce=b;ce.x=Number.NEGATIVE_INFINITY,ce.y=Number.NEGATIVE_INFINITY,ce.z=Number.NEGATIVE_INFINITY;let de=Number.POSITIVE_INFINITY;const he=x*v,me=T>0?2*x+2*v:0,ge=he+me,pe=new Array(ge),we=new Array(ge),xe=new Array(ge),ke=N?new Array(ge):[],ye=_?new Array(ge):[];let Ie=0,Ue=v,be=0,ve=x;M&&(--Ie,++Ue,--be,++ve);const Te=1e-5;for(let t=Ie;t=v&&(i=v-1);let n=D.north-$*i;n=V?p(n):g-2*h(m(-n*B));let a=(n-E)/(F-E);a=s.CesiumMath.clamp(a,0,1);const r=t===Ie,l=t===Ue-1;T>0&&(r?n+=Te*J:l&&(n-=Te*J));const f=u(n),k=c(n),I=ne*k;let U;N&&(U=(o.WebMercatorProjection.geodeticLatitudeToMercatorAngle(n)-oe)*fe);for(let t=be;t=x&&(n=x-1);const o=i*(x*j)+n*j;let h;if(1===Z)h=w[o];else{let e;if(h=0,G)for(e=0;e=0;--e)h=h*q+w[o+e]}h=h*W+X,re=Math.max(re,h),ae=Math.min(ae,h);let m=D.west+K*n;V?m=p(m):m*=B;let g=(m-P)/(C-P);g=s.CesiumMath.clamp(g,0,1);let b=i*x+n;if(T>0){const e=t===be,a=t===ve-1,s=r||l||e||a,o=(r||l)&&(e||a);if(o)continue;s&&(h-=T,e?(b=he+(v-i-1),m-=Te*Q):l?b=he+v+(x-n-1):a?(b=he+v+x+i,m+=Te*Q):r&&(b=he+v+x+v+n))}const M=f*u(m),S=f*c(m),E=te*M,F=ie*S,L=d(E*M+F*S+I*k),R=1/L,O=E*R,z=F*R,H=I*R,Y=new e.Cartesian3;Y.x=O+M*h,Y.y=z+S*h,Y.z=H+k*h,e.Matrix4.multiplyByPoint(le,Y,y),e.Cartesian3.minimumByComponent(y,ue,ue),e.Cartesian3.maximumByComponent(y,ce,ce),de=Math.min(de,h),pe[b]=Y,xe[b]=new e.Cartesian2(g,a),we[b]=h,N&&(ke[b]=U),_&&(ye[b]=A.geodeticSurfaceNormal(Y))}}const Me=i.BoundingSphere.fromPoints(pe);let Ve,Ae;if(n.defined(S)&&(Ve=l.OrientedBoundingBox.fromRectangle(S,ae,re,A)),R){const e=new r.EllipsoidalOccluder(A);Ae=e.computeHorizonCullingPointPossiblyUnderEllipsoid(L,pe,ae)}const Be=new t.AxisAlignedBoundingBox(ue,ce,L),De=new r.TerrainEncoding(L,Be,de,re,se,!1,N,_,O,z),Se=new Float32Array(ge*De.stride);let Pe=0;for(let e=0;e>3],M<<=7&V),p=0;p>3]),128&M?(o&&(o[V]=1),s=B.encoding<2?b[v++]:T,g=g>s?s:g,l[V++]=s):(o&&(o[V]=0),l[V++]=n),M<<=1;V+=A}else if(B.encoding<2)for(w=0;ws?s:g,l[V++]=s;V+=A}else for(g=g>T?T:g,w=0;w0){var s=new Uint8Array(Math.ceil(n.width*n.height/8));r=new DataView(e,t,n.mask.numBytes);var l=r.getInt16(0,!0),o=2,f=0;do{if(l>0)while(l--)s[f++]=r.getUint8(o++);else{var u=r.getUint8(o++);l=-l;while(l--)s[f++]=u}l=r.getInt16(o,!0),o+=2}while(o0?1:0),m=d+(n.height%d>0?1:0);n.pixels.blocks=new Array(h*m);for(var g=0,p=0;p3)throw"Invalid block encoding ("+y.encoding+")";if(2!==y.encoding){if(0!==I&&2!==I){if(I>>=6,y.offsetType=I,2===I)y.offset=r.getInt8(1),x++;else if(1===I)y.offset=r.getInt16(1,!0),x+=2;else{if(0!==I)throw"Invalid block offset type";y.offset=r.getFloat32(1,!0),x+=4}if(1===y.encoding)if(I=r.getUint8(x),x++,y.bitsPerPixel=63&I,I>>=6,y.numValidPixelsType=I,2===I)y.numValidPixels=r.getUint8(x),x++;else if(1===I)y.numValidPixels=r.getUint16(x,!0),x+=2;else{if(0!==I)throw"Invalid valid pixel count type";y.numValidPixels=r.getUint32(x,!0),x+=4}}var U,b;if(t+=x,3!==y.encoding)if(0===y.encoding){var v=(n.pixels.numBytes-1)/4;if(v!==Math.floor(v))throw"uncompressed block has invalid length";U=new ArrayBuffer(4*v),b=new Uint8Array(U),b.set(new Uint8Array(e,t,4*v));var T=new Float32Array(U);y.rawData=T,t+=4*v}else if(1===y.encoding){var M=Math.ceil(y.numValidPixels*y.bitsPerPixel/8),V=Math.ceil(M/4);U=new ArrayBuffer(4*V),b=new Uint8Array(U),b.set(new Uint8Array(e,t,M)),y.stuffedData=new Uint32Array(U),t+=M}}else t++}return n.eofOffset=t,n},r=function(e,t,i,n,a,r,s){var l,o,f,u=(1<=t)o=f>>>d-t&u,d-=t;else{var g=t-d;o=(f&u)<>>d}r[l]=o=i?(f=u>>>g-i&h,g-=i):(c=i-g,f=(u&h)<>>g),t[o]=a[f];else for(d=Math.ceil((l-r)/s),o=0;o=i?(f=u>>>g-i&h,g-=i):(c=i-g,f=(u&h)<>>g),t[o]=f=t?(d=s>>>c-t&l,c-=t):(u=t-c,d=(s&l)<>>c),h[f]=d=i?(f=u>>>g&d,m-=i,g+=i):(c=i-m,f=u>>>g&d,u=e[h++],m=32-c,f|=(u&(1<=i?(f=u>>>g&d,m-=i,g+=i):(c=i-m,f=u>>>g&d,u=e[h++],m=32-c,f|=(u&(1<=t?(d=s>>>h&l,c-=t,h+=t):(u=t-c,d=s>>>h&l,s=e[o++],c=32-u,d|=(s&(1<=i?(r=s>>>u-i&o,u-=i):(l=i-u,r=(s&o)<>>u),t[a]=r;return t},originalUnstuff2:function(e,t,i,n){var a,r,s,l,o=(1<=i?(r=s>>>c&o,u-=i,c+=i):(l=i-u,r=s>>>c&o,s=e[f++],u=32-l,r|=(s&(1<=359?359:a;a-=s;do{t+=e[r++]<<8,i+=t+=e[r++]}while(--s);t=(65535&t)+(t>>>16),i=(65535&i)+(i>>>16)}return 1&n&&(i+=t+=e[r]<<8),t=(65535&t)+(t>>>16),i=(65535&i)+(i>>>16),(i<<16|t)>>>0},readHeaderInfo:function(e,t){var i=t.ptr,n=new Uint8Array(e,i,6),a={};if(a.fileIdentifierString=String.fromCharCode.apply(null,n),0!==a.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+a.fileIdentifierString;i+=6;var r,s,l=new DataView(e,i,8),o=l.getInt32(0,!0);if(a.fileVersion=o,i+=4,o>=3&&(a.checksum=l.getUint32(4,!0),i+=4),l=new DataView(e,i,12),a.height=l.getUint32(0,!0),a.width=l.getUint32(4,!0),i+=8,o>=4?(a.numDims=l.getUint32(8,!0),i+=4):a.numDims=1,l=new DataView(e,i,40),a.numValidPixel=l.getUint32(0,!0),a.microBlockSize=l.getInt32(4,!0),a.blobSize=l.getInt32(8,!0),a.imageType=l.getInt32(12,!0),a.maxZError=l.getFloat64(16,!0),a.zMin=l.getFloat64(24,!0),a.zMax=l.getFloat64(32,!0),i+=40,t.headerInfo=a,t.ptr=i,o>=3&&(s=o>=4?52:48,r=this.computeChecksumFletcher32(new Uint8Array(e,i-s,a.blobSize-14)),r!==a.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var i=t.headerInfo,n=this.getDataTypeArray(i.imageType),a=i.numDims*this.getDataTypeSize(i.imageType),r=this.readSubArray(e,t.ptr,n,a),s=this.readSubArray(e,t.ptr+a,n,a);t.ptr+=2*a;var l,o=!0;for(l=0;l0){i=new Uint8Array(Math.ceil(s/8)),o=new DataView(e,a,f.numBytes);var u=o.getInt16(0,!0),c=2,d=0,h=0;do{if(u>0)while(u--)i[d++]=o.getUint8(c++);else{h=o.getUint8(c++),u=-u;while(u--)i[d++]=h}u=o.getInt16(c,!0),c+=2}while(c>3],m<<=7&g):m=i[g>>3],128&m&&(n[g]=1);t.pixels.resultMask=n,f.bitset=i,a+=f.numBytes}return t.ptr=a,t.mask=f,!0},readDataOneSweep:function(e,i,n){var a,r=i.ptr,s=i.headerInfo,l=s.numDims,o=s.width*s.height,f=s.imageType,u=s.numValidPixel*t.getDataTypeSize(f)*l,c=i.pixels.resultMask;if(n===Uint8Array)a=new Uint8Array(e,r,u);else{var d=new ArrayBuffer(u),h=new Uint8Array(d);h.set(new Uint8Array(e,r,u)),a=new n(d)}if(a.length===o*l)i.pixels.resultPixels=a;else{i.pixels.resultPixels=new n(o*l);var m=0,g=0,p=0,w=0;if(l>1)for(p=0;p=f)return!1;var u=new Uint32Array(f-o);t.decodeBits(e,n,u);var c,d,h,m,g=[];for(c=o;c0&&(g[d].second=y<>>32-m,32-U>=m?(U+=m,32===U&&(U=0,b++,y=I[b])):(U+=m-32,b++,y=I[b],g[d].second|=y>>>32-U));var v=0,T=0,M=new i;for(c=0;c=a?a:v,v>=30&&console.log("WARning, large NUM LUT BITS IS "+v);var V,A,B,D,S,P,E=[];for(c=o;c0)if(V=[m,d],m<=T)for(A=g[d].second<=0;D--)S=A>>>D&1,S?(P.right||(P.right=new i),P=P.right):(P.left||(P.left=new i),P=P.left),0!==D||P.val||(P.val=V[1]);return{decodeLut:E,numBitsLUTQick:T,numBitsLUT:v,tree:M,stuffedData:I,srcPtr:b,bitPos:U}},readHuffman:function(e,t,i){var n,a,r,s,l,o,f,u,c,d,h=t.headerInfo,m=h.numDims,g=t.headerInfo.height,p=t.headerInfo.width,w=p*g,x=this.readHuffmanTree(e,t),k=x.decodeLut,y=x.tree,I=x.stuffedData,U=x.srcPtr,b=x.bitPos,v=x.numBitsLUTQick,T=x.numBitsLUT,M=0===t.headerInfo.imageType?128:0,V=t.pixels.resultMask,A=0;b>0&&(U++,b=0);var B,D=I[U],S=1===t.encodeMode,P=new i(w*m),E=P;for(B=0;B1&&(E=new i(P.buffer,w*B,w),A=0),t.headerInfo.numValidPixel===p*g)for(c=0,f=0;f>>32-v,l=s,32-b>>64-b-v,l=s),k[l])a=k[l][1],b+=k[l][0];else for(s=D<>>32-T,l=s,32-b>>64-b-T,l=s),n=y,d=0;d>>T-d-1&1,n=o?n.right:n.left,!n.left&&!n.right){a=n.val,b=b+d+1;break}b>=32&&(b-=32,U++,D=I[U]),r=a-M,S?(r+=u>0?A:f>0?E[c-p]:A,r&=255,E[c]=r,A=r):E[c]=r}else for(c=0,f=0;f>>32-v,l=s,32-b>>64-b-v,l=s),k[l])a=k[l][1],b+=k[l][0];else for(s=D<>>32-T,l=s,32-b>>64-b-T,l=s),n=y,d=0;d>>T-d-1&1,n=o?n.right:n.left,!n.left&&!n.right){a=n.val,b=b+d+1;break}b>=32&&(b-=32,U++,D=I[U]),r=a-M,S?(u>0&&V[c-1]?r+=A:f>0&&V[c-p]?r+=E[c-p]:r+=A,r&=255,E[c]=r,A=r):E[c]=r}t.ptr=t.ptr+4*(U+1)+(b>0?4:0)}t.pixels.resultPixels=P},decodeBits:function(t,i,n,a,r){var s=i.headerInfo,l=s.fileVersion,o=0,f=new DataView(t,i.ptr,5),u=f.getUint8(0);o++;var c=u>>6,d=0===c?4:3-c,h=(32&u)>0,m=31&u,g=0;if(1===d)g=f.getUint8(o),o++;else if(2===d)g=f.getUint16(o,!0),o+=2;else{if(4!==d)throw"Invalid valid pixel count type";g=f.getUint32(o,!0),o+=4}var p,w,x,k,y,I,U,b,v,T=2*s.maxZError,M=s.numDims>1?s.maxValues[r]:s.zMax;if(h){i.counter.lut++,b=f.getUint8(o),o++,k=Math.ceil((b-1)*m/8),y=Math.ceil(k/4),w=new ArrayBuffer(4*y),x=new Uint8Array(w),i.ptr+=o,x.set(new Uint8Array(t,i.ptr,k)),U=new Uint32Array(w),i.ptr+=k,v=0;while(b-1>>>v)v++;k=Math.ceil(g*v/8),y=Math.ceil(k/4),w=new ArrayBuffer(4*y),x=new Uint8Array(w),x.set(new Uint8Array(t,i.ptr,k)),p=new Uint32Array(w),i.ptr+=k,I=l>=3?e.unstuffLUT2(U,m,b-1,a,T,M):e.unstuffLUT(U,m,b-1,a,T,M),l>=3?e.unstuff2(p,n,v,g,I):e.unstuff(p,n,v,g,I)}else i.counter.bitstuffer++,v=m,i.ptr+=o,v>0&&(k=Math.ceil(g*v/8),y=Math.ceil(k/4),w=new ArrayBuffer(4*y),x=new Uint8Array(w),x.set(new Uint8Array(t,i.ptr,k)),p=new Uint32Array(w),i.ptr+=k,l>=3?null==a?e.originalUnstuff2(p,n,v,g):e.unstuff2(p,n,v,g,!1,a,T,M):null==a?e.originalUnstuff(p,n,v,g):e.unstuff(p,n,v,g,!1,a,T,M))},readTiles:function(e,i,n){var a=i.headerInfo,r=a.width,s=a.height,l=a.microBlockSize,o=a.imageType,f=t.getDataTypeSize(o),u=Math.ceil(r/l),c=Math.ceil(s/l);i.pixels.numBlocksY=c,i.pixels.numBlocksX=u,i.pixels.ptr=0;var d,h,m,g,p,w,x,k,y,I=0,U=0,b=0,v=0,T=0,M=0,V=0,A=0,B=0,D=0,S=0,P=0,E=0,C=0,F=0,L=0,R=new n(l*l),N=s%l||l,O=r%l||l,z=a.numDims,H=i.pixels.resultMask,_=i.pixels.resultPixels;for(b=0;b1&&(_=new n(i.pixels.resultPixels.buffer,r*s*y*f,r*s)),V=e.byteLength-i.ptr,d=new DataView(e,i.ptr,Math.min(10,V)),h={},L=0,A=d.getUint8(0),L++,B=A>>6&255,D=A>>2&15,D!==(v*l>>3&15))throw"integrity issue";if(w=3&A,w>3)throw i.ptr+=L,"Invalid block encoding ("+w+")";if(2!==w)if(0===w){if(i.counter.uncompressed++,i.ptr+=L,E=T*M*f,C=e.byteLength-i.ptr,E=E1)for(r=0;r=-128&&t<=127;break;case 1:i=t>=0&&t<=255;break;case 2:i=t>=-32768&&t<=32767;break;case 3:i=t>=0&&t<=65536;break;case 4:i=t>=-2147483648&&t<=2147483647;break;case 5:i=t>=0&&t<=4294967296;break;case 6:i=t>=-34027999387901484e22&&t<=34027999387901484e22;break;case 7:i=t>=5e-324&&t<=17976931348623157e292;break;default:i=!1}return i},getDataTypeSize:function(e){var t=0;switch(e){case 0:case 1:t=1;break;case 2:case 3:t=2;break;case 4:case 5:case 6:t=4;break;case 7:t=8;break;default:t=e}return t},getDataTypeUsed:function(e,t){var i=e;switch(e){case 2:case 4:i=e-t;break;case 3:case 5:i=e-2*t;break;case 6:i=0===t?e:1===t?2:1;break;case 7:i=0===t?e:e-2*t+1;break;default:i=e;break}return i},getOnePixel:function(e,t,i,n){var a=0;switch(i){case 0:a=n.getInt8(t);break;case 1:a=n.getUint8(t);break;case 2:a=n.getInt16(t,!0);break;case 3:a=n.getUint16(t,!0);break;case 4:a=n.getInt32(t,!0);break;case 5:a=n.getUInt32(t,!0);break;case 6:a=n.getFloat32(t,!0);break;case 7:a=n.getFloat64(t,!0);break;default:throw"the decoder does not understand this pixel type"}return a}},i=function(e,t,i){this.val=e,this.left=t,this.right=i},n={decode:function(e,i){i=i||{};var n=i.noDataValue,a=0,r={};r.ptr=i.inputOffset||0,r.pixels={},t.readHeaderInfo(e,r);var s=r.headerInfo,l=s.fileVersion,o=t.getDataTypeArray(s.imageType);t.readMask(e,r),s.numValidPixel===s.width*s.height||r.pixels.resultMask||(r.pixels.resultMask=i.maskData);var f,u=s.width*s.height;if(r.pixels.resultPixels=new o(u*s.numDims),r.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0},0!==s.numValidPixel)if(s.zMax===s.zMin)t.constructConstantSurface(r);else if(l>=4&&t.checkMinMaxRanges(e,r))t.constructConstantSurface(r);else{var c=new DataView(e,r.ptr,2),d=c.getUint8(0);if(r.ptr++,d)t.readDataOneSweep(e,r,o);else if(l>1&&s.imageType<=1&&Math.abs(s.maxZError-.5)<1e-5){var h=c.getUint8(1);if(r.ptr++,r.encodeMode=h,h>2||l<4&&h>1)throw"Invalid Huffman flag "+h;h?t.readHuffman(e,r,o):t.readTiles(e,r,o)}else t.readTiles(e,r,o)}r.eofOffset=r.ptr,i.inputOffset?(f=r.headerInfo.blobSize+i.inputOffset-r.ptr,Math.abs(f)>=1&&(r.eofOffset=i.inputOffset+r.headerInfo.blobSize)):(f=r.headerInfo.blobSize-r.ptr,Math.abs(f)>=1&&(r.eofOffset=r.headerInfo.blobSize));var m={width:s.width,height:s.height,pixelData:r.pixels.resultPixels,minValue:s.zMin,maxValue:s.zMax,validPixelCount:s.numValidPixel,dimCount:s.numDims,dimStats:{minValues:s.minValues,maxValues:s.maxValues},maskData:r.pixels.resultMask};if(r.pixels.resultMask&&t.isValidPixelValue(s.imageType,n)){var g=r.pixels.resultMask;for(a=0;a1&&y.fileInfo.mask&&y.fileInfo.mask.numBytes>0&&x.push(y.maskData),p++,k.pixels.push(y.pixelData),k.statistics.push({minValue:y.minValue,maxValue:y.maxValue,noDataValue:y.noDataValue,dimStats:y.dimStats})}if(s>1&&x.length>1){for(g=k.width*k.height,k.bandMasks=x,d=new Uint8Array(g),d.set(x[0]),h=1;h