define(["./Matrix2-9aa31791","./AxisAlignedBoundingBox-07c6b7f2","./Transforms-d13cc04e","./when-4bbc8319","./RuntimeError-346a3079","./TerrainEncoding-ba779f11","./ComponentDatatype-93750d1a","./OrientedBoundingBox-4b932f63","./WebMercatorProjection-58801a11","./createTaskProcessorWorker","./combine-83860057","./AttributeCompression-af389d04","./WebGLConstants-1c8239cc","./EllipsoidTangentPlane-eecce7e8","./IntersectionTests-96a04219","./Plane-318d6937"],(function(e,t,a,i,r,n,s,l,o,f,u,c,d,h,m,g){"use strict";var p=Object.freeze({NONE:0,LERC:1}),x={};x.DEFAULT_STRUCTURE=Object.freeze({heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:256,isBigEndian:!1});var w=new e.Cartesian3,k=new e.Matrix4,y=new e.Cartesian3,I=new e.Cartesian3;x.computeVertices=function(r){var f,u,c,d,h=Math.cos,m=Math.sin,g=Math.sqrt,p=Math.atan,v=Math.exp,b=s.CesiumMath.PI_OVER_TWO,U=s.CesiumMath.toRadians,T=r.heightmap,M=r.width,V=r.height,A=r.skirtHeight,B=A>0,D=i.defaultValue(r.isGeographic,!0),S=i.defaultValue(r.ellipsoid,e.Ellipsoid.WGS84),P=1/S.maximumRadius,E=e.Rectangle.clone(r.nativeRectangle),C=e.Rectangle.clone(r.rectangle);i.defined(C)?(f=C.west,u=C.south,c=C.east,d=C.north):D?(f=U(E.west),u=U(E.south),c=U(E.east),d=U(E.north)):(f=E.west*P,u=b-2*p(v(-E.south*P)),c=E.east*P,d=b-2*p(v(-E.north*P)));var F=r.relativeToCenter,N=i.defined(F);F=N?F:e.Cartesian3.ZERO;var O=i.defaultValue(r.includeWebMercatorT,!1),R=i.defaultValue(r.exaggeration,1),L=i.defaultValue(r.exaggerationRelativeHeight,0),z=1!==R,H=i.defaultValue(r.structure,x.DEFAULT_STRUCTURE),_=i.defaultValue(H.heightScale,x.DEFAULT_STRUCTURE.heightScale),Y=i.defaultValue(H.heightOffset,x.DEFAULT_STRUCTURE.heightOffset),W=i.defaultValue(H.elementsPerHeight,x.DEFAULT_STRUCTURE.elementsPerHeight),X=i.defaultValue(H.stride,x.DEFAULT_STRUCTURE.stride),Z=i.defaultValue(H.elementMultiplier,x.DEFAULT_STRUCTURE.elementMultiplier),j=i.defaultValue(H.isBigEndian,x.DEFAULT_STRUCTURE.isBigEndian),G=e.Rectangle.computeWidth(E),q=e.Rectangle.computeHeight(E),Q=G/(M-1),J=q/(V-1);D||(G*=P,q*=P);var K,$,ee=S.radiiSquared,te=ee.x,ae=ee.y,ie=ee.z,re=65536,ne=-65536,se=a.Transforms.eastNorthUpToFixedFrame(F,S),le=e.Matrix4.inverseTransformation(se,k);O&&(K=o.WebMercatorProjection.geodeticLatitudeToMercatorAngle(u),$=1/(o.WebMercatorProjection.geodeticLatitudeToMercatorAngle(d)-K));var oe=y;oe.x=Number.POSITIVE_INFINITY,oe.y=Number.POSITIVE_INFINITY,oe.z=Number.POSITIVE_INFINITY;var fe=I;fe.x=Number.NEGATIVE_INFINITY,fe.y=Number.NEGATIVE_INFINITY,fe.z=Number.NEGATIVE_INFINITY;var ue=Number.POSITIVE_INFINITY,ce=M*V,de=ce+(A>0?2*M+2*V:0),he=new Array(de),me=new Array(de),ge=new Array(de),pe=O?new Array(de):[],xe=z?new Array(de):[],we=0,ke=V,ye=0,Ie=M;B&&(--we,++ke,--ye,++Ie);for(var ve=1e-5,be=we;be=V&&(Ue=V-1);var Te=E.north-J*Ue,Me=((Te=D?U(Te):b-2*p(v(-Te*P)))-u)/(d-u);Me=s.CesiumMath.clamp(Me,0,1);var Ve=be===we,Ae=be===ke-1;A>0&&(Ve?Te+=ve*q:Ae&&(Te-=ve*q));var Be,De=h(Te),Se=m(Te),Pe=ie*Se;O&&(Be=(o.WebMercatorProjection.geodeticLatitudeToMercatorAngle(Te)-K)*$);for(var Ee=ye;Ee=M&&(Ce=M-1);var Fe,Ne,Oe=Ue*(M*X)+Ce*X;if(1===W)Fe=T[Oe];else if(Fe=0,j)for(Ne=0;Ne=0;--Ne)Fe=Fe*Z+T[Oe+Ne];Fe=Fe*_+Y,ne=Math.max(ne,Fe),re=Math.min(re,Fe);var Re=E.west+Q*Ce;D?Re=U(Re):Re*=P;var Le=(Re-f)/(c-f);Le=s.CesiumMath.clamp(Le,0,1);var ze=Ue*M+Ce;if(A>0){var He=Ee===ye,_e=Ee===Ie-1,Ye=Ve||Ae||He||_e;if((Ve||Ae)&&(He||_e))continue;Ye&&(Fe-=A,He?(ze=ce+(V-Ue-1),Re-=ve*G):Ae?ze=ce+V+(M-Ce-1):_e?(ze=ce+V+M+Ue,Re+=ve*G):Ve&&(ze=ce+V+M+V+Ce))}var We=De*h(Re),Xe=De*m(Re),Ze=te*We,je=ae*Xe,Ge=1/g(Ze*We+je*Xe+Pe*Se),qe=Ze*Ge,Qe=je*Ge,Je=Pe*Ge,Ke=new e.Cartesian3;Ke.x=qe+We*Fe,Ke.y=Qe+Xe*Fe,Ke.z=Je+Se*Fe,e.Matrix4.multiplyByPoint(le,Ke,w),e.Cartesian3.minimumByComponent(w,oe,oe),e.Cartesian3.maximumByComponent(w,fe,fe),ue=Math.min(ue,Fe),he[ze]=Ke,ge[ze]=new e.Cartesian2(Le,Me),me[ze]=Fe,O&&(pe[ze]=Be),z&&(xe[ze]=S.geodeticSurfaceNormal(Ke))}}var $e,et,tt=a.BoundingSphere.fromPoints(he);(i.defined(C)&&($e=l.OrientedBoundingBox.fromRectangle(C,re,ne,S)),N)&&(et=new n.EllipsoidalOccluder(S).computeHorizonCullingPointPossiblyUnderEllipsoid(F,he,re));for(var at=new t.AxisAlignedBoundingBox(oe,fe,F),it=new n.TerrainEncoding(F,at,ue,ne,se,!1,O,z,R,L),rt=new Float32Array(de*it.stride),nt=0,st=0;st>3],M<<=7&V),p=0;p>3]),128&M?(o&&(o[V]=1),g=g>(n=B.encoding<2?b[U++]:T)?n:g,l[V++]=n):(o&&(o[V]=0),l[V++]=i),M<<=1;V+=A}else if(B.encoding<2)for(x=0;x(n=b[U++])?n:g,l[V++]=n;V+=A}else for(g=g>T?T:g,x=0;x0){var s=new Uint8Array(Math.ceil(i.width*i.height/8)),l=(n=new DataView(e,t,i.mask.numBytes)).getInt16(0,!0),o=2,f=0;do{if(l>0)for(;l--;)s[f++]=n.getUint8(o++);else{var u=n.getUint8(o++);for(l=-l;l--;)s[f++]=u}l=n.getInt16(o,!0),o+=2}while(o0?1:0),m=d+(i.height%d>0?1:0);i.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=n.getInt8(1),w++;else if(1===I)y.offset=n.getInt16(1,!0),w+=2;else{if(0!==I)throw"Invalid block offset type";y.offset=n.getFloat32(1,!0),w+=4}if(1===y.encoding)if(I=n.getUint8(w),w++,y.bitsPerPixel=63&I,I>>=6,y.numValidPixelsType=I,2===I)y.numValidPixels=n.getUint8(w),w++;else if(1===I)y.numValidPixels=n.getUint16(w,!0),w+=2;else{if(0!==I)throw"Invalid valid pixel count type";y.numValidPixels=n.getUint32(w,!0),w+=4}}var v;if(t+=w,3!==y.encoding)if(0===y.encoding){var b=(i.pixels.numBytes-1)/4;if(b!==Math.floor(b))throw"uncompressed block has invalid length";v=new ArrayBuffer(4*b),new Uint8Array(v).set(new Uint8Array(e,t,4*b));var U=new Float32Array(v);y.rawData=U,t+=4*b}else if(1===y.encoding){var T=Math.ceil(y.numValidPixels*y.bitsPerPixel/8),M=Math.ceil(T/4);v=new ArrayBuffer(4*M),new Uint8Array(v).set(new Uint8Array(e,t,T)),y.stuffedData=new Uint32Array(v),t+=T}}else t++}return i.eofOffset=t,i},s=function(e,t,a,i,r,n,s){var l,o,f,u=(1<=t)o=f>>>d-t&u,d-=t;else{var g=t-d;o=(f&u)<>>(d=32-g)}n[l]=o=a?(f=u>>>g-a&h,g-=a):(f=(u&h)<<(c=a-g)&h,f+=(u=e[m++])>>>(g=32-c)),t[o]=r[f];else for(d=Math.ceil((l-n)/s),o=0;o=a?(f=u>>>g-a&h,g-=a):(f=(u&h)<<(c=a-g)&h,f+=(u=e[m++])>>>(g=32-c)),t[o]=f=t?(d=s>>>c-t&l,c-=t):(d=(s&l)<<(u=t-c)&l,d+=(s=e[o++])>>>(c=32-u)),h[f]=d=a?(f=u>>>g&d,m-=a,g+=a):(f=u>>>g&d,m=32-(c=a-m),f|=((u=e[h++])&(1<=a?(f=u>>>g&d,m-=a,g+=a):(f=u>>>g&d,m=32-(c=a-m),f|=((u=e[h++])&(1<=t?(d=s>>>h&l,c-=t,h+=t):(d=s>>>h&l,c=32-(u=t-c),d|=((s=e[o++])&(1<=a?(n=s>>>u-a&o,u-=a):(n=(s&o)<<(l=a-u)&o,n+=(s=e[f++])>>>(u=32-l)),t[r]=n;return t},d=function(e,t,a,i){var r,n,s,l,o=(1<=a?(n=s>>>c&o,u-=a,c+=a):(n=s>>>c&o,u=32-(l=a-u),n|=((s=e[f++])&(1<=359?359:r;r-=s;do{t+=e[n++]<<8,a+=t+=e[n++]}while(--s);t=(65535&t)+(t>>>16),a=(65535&a)+(a>>>16)}return 1&i&&(a+=t+=e[n]<<8),((a=(65535&a)+(a>>>16))<<16|(t=(65535&t)+(t>>>16)))>>>0},readHeaderInfo:function(e,t){var a=t.ptr,i=new Uint8Array(e,a,6),r={};if(r.fileIdentifierString=String.fromCharCode.apply(null,i),0!==r.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+r.fileIdentifierString;a+=6;var n,s=new DataView(e,a,8),l=s.getInt32(0,!0);if(r.fileVersion=l,a+=4,l>=3&&(r.checksum=s.getUint32(4,!0),a+=4),s=new DataView(e,a,12),r.height=s.getUint32(0,!0),r.width=s.getUint32(4,!0),a+=8,l>=4?(r.numDims=s.getUint32(8,!0),a+=4):r.numDims=1,s=new DataView(e,a,40),r.numValidPixel=s.getUint32(0,!0),r.microBlockSize=s.getInt32(4,!0),r.blobSize=s.getInt32(8,!0),r.imageType=s.getInt32(12,!0),r.maxZError=s.getFloat64(16,!0),r.zMin=s.getFloat64(24,!0),r.zMax=s.getFloat64(32,!0),a+=40,t.headerInfo=r,t.ptr=a,l>=3&&(n=l>=4?52:48,this.computeChecksumFletcher32(new Uint8Array(e,a-n,r.blobSize-14))!==r.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var a=t.headerInfo,i=this.getDataTypeArray(a.imageType),r=a.numDims*this.getDataTypeSize(a.imageType),n=this.readSubArray(e,t.ptr,i,r),s=this.readSubArray(e,t.ptr+r,i,r);t.ptr+=2*r;var l,o=!0;for(l=0;l0){a=new Uint8Array(Math.ceil(s/8));var u=(o=new DataView(e,r,f.numBytes)).getInt16(0,!0),c=2,d=0,h=0;do{if(u>0)for(;u--;)a[d++]=o.getUint8(c++);else for(h=o.getUint8(c++),u=-u;u--;)a[d++]=h;u=o.getInt16(c,!0),c+=2}while(c>3],m<<=7&g):m=a[g>>3],128&m&&(i[g]=1);t.pixels.resultMask=i,f.bitset=a,r+=f.numBytes}return t.ptr=r,t.mask=f,!0},readDataOneSweep:function(e,t,a){var i,r=t.ptr,n=t.headerInfo,s=n.numDims,l=n.width*n.height,o=n.imageType,f=n.numValidPixel*h.getDataTypeSize(o)*s,u=t.pixels.resultMask;if(a===Uint8Array)i=new Uint8Array(e,r,f);else{var c=new ArrayBuffer(f);new Uint8Array(c).set(new Uint8Array(e,r,f)),i=new a(c)}if(i.length===l*s)t.pixels.resultPixels=i;else{t.pixels.resultPixels=new a(l*s);var d=0,m=0,g=0,p=0;if(s>1)for(g=0;g=s)return!1;var l=new Uint32Array(s-n);h.decodeBits(e,t,l);var o,f,u,c,d=[];for(o=n;o0&&(d[f].second=w<>>32-c,32-y>=c?32===(y+=c)&&(y=0,w=k[++I]):(y+=c-32,w=k[++I],d[f].second|=w>>>32-y));var v=0,b=0,U=new m;for(o=0;o=a?a:v,v>=30&&console.log("WARning, large NUM LUT BITS IS "+v);var T,M,V,A,B,D=[];for(o=n;o0)if(T=[c,f],c<=b)for(M=d[f].second<=0;A--)M>>>A&1?(B.right||(B.right=new m),B=B.right):(B.left||(B.left=new m),B=B.left),0!==A||B.val||(B.val=T[1]);return{decodeLut:D,numBitsLUTQick:b,numBitsLUT:v,tree:U,stuffedData:k,srcPtr:I,bitPos:y}},readHuffman:function(e,t,a){var i,r,n,s,l,o,f,u,c,d=t.headerInfo,h=d.numDims,m=t.headerInfo.height,g=t.headerInfo.width,p=g*m,x=this.readHuffmanTree(e,t),w=x.decodeLut,k=x.tree,y=x.stuffedData,I=x.srcPtr,v=x.bitPos,b=x.numBitsLUTQick,U=x.numBitsLUT,T=0===t.headerInfo.imageType?128:0,M=t.pixels.resultMask,V=0;v>0&&(I++,v=0);var A,B=y[I],D=1===t.encodeMode,S=new a(p*h),P=S;for(A=0;A1&&(P=new a(S.buffer,p*A,p),V=0),t.headerInfo.numValidPixel===g*m)for(u=0,o=0;o>>32-b,32-v>>64-v-b),w[l])r=w[l][1],v+=w[l][0];else for(l=s=B<>>32-U,32-v>>64-v-U),i=k,c=0;c>>U-c-1&1?i.right:i.left).left&&!i.right){r=i.val,v=v+c+1;break}v>=32&&(v-=32,B=y[++I]),n=r-T,D?(n+=f>0?V:o>0?P[u-g]:V,n&=255,P[u]=n,V=n):P[u]=n}else for(u=0,o=0;o>>32-b,32-v>>64-v-b),w[l])r=w[l][1],v+=w[l][0];else for(l=s=B<>>32-U,32-v>>64-v-U),i=k,c=0;c>>U-c-1&1?i.right:i.left).left&&!i.right){r=i.val,v=v+c+1;break}v>=32&&(v-=32,B=y[++I]),n=r-T,D?(f>0&&M[u-1]?n+=V:o>0&&M[u-g]?n+=P[u-g]:n+=V,n&=255,P[u]=n,V=n):P[u]=n}t.ptr=t.ptr+4*(I+1)+(v>0?4:0)}t.pixels.resultPixels=S},decodeBits:function(e,t,a,i,r){var n=t.headerInfo,s=n.fileVersion,h=0,m=new DataView(e,t.ptr,5),g=m.getUint8(0);h++;var p=g>>6,x=0===p?4:3-p,w=(32&g)>0,k=31&g,y=0;if(1===x)y=m.getUint8(h),h++;else if(2===x)y=m.getUint16(h,!0),h+=2;else{if(4!==x)throw"Invalid valid pixel count type";y=m.getUint32(h,!0),h+=4}var I,v,b,U,T,M,V,A,B,D=2*n.maxZError,S=n.numDims>1?n.maxValues[r]:n.zMax;if(w){for(t.counter.lut++,A=m.getUint8(h),h++,U=Math.ceil((A-1)*k/8),T=Math.ceil(U/4),v=new ArrayBuffer(4*T),b=new Uint8Array(v),t.ptr+=h,b.set(new Uint8Array(e,t.ptr,U)),V=new Uint32Array(v),t.ptr+=U,B=0;A-1>>>B;)B++;U=Math.ceil(y*B/8),T=Math.ceil(U/4),v=new ArrayBuffer(4*T),(b=new Uint8Array(v)).set(new Uint8Array(e,t.ptr,U)),I=new Uint32Array(v),t.ptr+=U,M=s>=3?u(V,k,A-1,i,D,S):o(V,k,A-1,i,D,S),s>=3?f(I,a,B,y,M):l(I,a,B,y,M)}else t.counter.bitstuffer++,B=k,t.ptr+=h,B>0&&(U=Math.ceil(y*B/8),T=Math.ceil(U/4),v=new ArrayBuffer(4*T),(b=new Uint8Array(v)).set(new Uint8Array(e,t.ptr,U)),I=new Uint32Array(v),t.ptr+=U,s>=3?null==i?d(I,a,B,y):f(I,a,B,y,!1,i,D,S):null==i?c(I,a,B,y):l(I,a,B,y,!1,i,D,S))},readTiles:function(e,t,a){var i=t.headerInfo,r=i.width,n=i.height,s=i.microBlockSize,l=i.imageType,o=h.getDataTypeSize(l),f=Math.ceil(r/s),u=Math.ceil(n/s);t.pixels.numBlocksY=u,t.pixels.numBlocksX=f,t.pixels.ptr=0;var c,d,m,g,p,x,w,k,y=0,I=0,v=0,b=0,U=0,T=0,M=0,V=0,A=0,B=0,D=0,S=0,P=0,E=0,C=0,F=new a(s*s),N=n%s||s,O=r%s||s,R=i.numDims,L=t.pixels.resultMask,z=t.pixels.resultPixels;for(v=0;v1&&(z=new a(t.pixels.resultPixels.buffer,r*n*k*o,r*n)),M=e.byteLength-t.ptr,d={},C=0,C++,A=(V=(c=new DataView(e,t.ptr,Math.min(10,M))).getUint8(0))>>6&255,(V>>2&15)!=(b*s>>3&15))throw"integrity issue";if((p=3&V)>3)throw t.ptr+=C,"Invalid block encoding ("+p+")";if(2!==p)if(0===p){if(t.counter.uncompressed++,t.ptr+=C,S=(S=U*T*o)<(P=e.byteLength-t.ptr)?S:P,m=new ArrayBuffer(S%o==0?S:S+o-S%o),new Uint8Array(m).set(new Uint8Array(e,t.ptr,S)),g=new a(m),E=0,L)for(y=0;y1)for(n=0;n=-128&&t<=127;break;case 1:a=t>=0&&t<=255;break;case 2:a=t>=-32768&&t<=32767;break;case 3:a=t>=0&&t<=65536;break;case 4:a=t>=-2147483648&&t<=2147483647;break;case 5:a=t>=0&&t<=4294967296;break;case 6:a=t>=-34027999387901484e22&&t<=34027999387901484e22;break;case 7:a=t>=5e-324&&t<=17976931348623157e292;break;default:a=!1}return a},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 a=e;switch(e){case 2:case 4:a=e-t;break;case 3:case 5:a=e-2*t;break;case 6:a=0===t?e:1===t?2:1;break;case 7:a=0===t?e:e-2*t+1;break;default:a=e}return a},getOnePixel:function(e,t,a,i){var r=0;switch(a){case 0:r=i.getInt8(t);break;case 1:r=i.getUint8(t);break;case 2:r=i.getInt16(t,!0);break;case 3:r=i.getUint16(t,!0);break;case 4:r=i.getInt32(t,!0);break;case 5:r=i.getUInt32(t,!0);break;case 6:r=i.getFloat32(t,!0);break;case 7:r=i.getFloat64(t,!0);break;default:throw"the decoder does not understand this pixel type"}return r}},m=function(e,t,a){this.val=e,this.left=t,this.right=a},{decode:function(e,t){var a=(t=t||{}).noDataValue,i=0,r={};r.ptr=t.inputOffset||0,r.pixels={},h.readHeaderInfo(e,r);var n=r.headerInfo,s=n.fileVersion,l=h.getDataTypeArray(n.imageType);h.readMask(e,r),n.numValidPixel===n.width*n.height||r.pixels.resultMask||(r.pixels.resultMask=t.maskData);var o,f=n.width*n.height;if(r.pixels.resultPixels=new l(f*n.numDims),r.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0},0!==n.numValidPixel)if(n.zMax===n.zMin)h.constructConstantSurface(r);else if(s>=4&&h.checkMinMaxRanges(e,r))h.constructConstantSurface(r);else{var u=new DataView(e,r.ptr,2),c=u.getUint8(0);if(r.ptr++,c)h.readDataOneSweep(e,r,l);else if(s>1&&n.imageType<=1&&Math.abs(n.maxZError-.5)<1e-5){var d=u.getUint8(1);if(r.ptr++,r.encodeMode=d,d>2||s<4&&d>1)throw"Invalid Huffman flag "+d;d?h.readHuffman(e,r,l):h.readTiles(e,r,l)}else h.readTiles(e,r,l)}r.eofOffset=r.ptr,t.inputOffset?(o=r.headerInfo.blobSize+t.inputOffset-r.ptr,Math.abs(o)>=1&&(r.eofOffset=t.inputOffset+r.headerInfo.blobSize)):(o=r.headerInfo.blobSize-r.ptr,Math.abs(o)>=1&&(r.eofOffset=r.headerInfo.blobSize));var m={width:n.width,height:n.height,pixelData:r.pixels.resultPixels,minValue:n.zMin,maxValue:n.zMax,validPixelCount:n.numValidPixel,dimCount:n.numDims,dimStats:{minValues:n.minValues,maxValues:n.maxValues},maskData:r.pixels.resultMask};if(r.pixels.resultMask&&h.isValidPixelValue(n.imageType,a)){var g=r.pixels.resultMask;for(i=0;i1&&y.fileInfo.mask&&y.fileInfo.mask.numBytes>0&&g.push(y.maskData),h++,p.pixels.push(y.pixelData),p.statistics.push({minValue:y.minValue,maxValue:y.maxValue,noDataValue:y.noDataValue,dimStats:y.dimStats})}if(i>1&&g.length>1){for(d=p.width*p.height,p.bandMasks=g,(f=new Uint8Array(d)).set(g[0]),u=1;u