define(["./Matrix2-ccd5b911","./AxisAlignedBoundingBox-883f9c89","./Transforms-d5c6ad6e","./when-4bbc8319","./RuntimeError-346a3079","./TerrainEncoding-bccee540","./ComponentDatatype-93750d1a","./OrientedBoundingBox-0a826a8b","./WebMercatorProjection-b29097b4","./createTaskProcessorWorker","./combine-83860057","./AttributeCompression-1f045b73","./WebGLConstants-1c8239cc","./EllipsoidTangentPlane-e000bae1","./IntersectionTests-4d6f5c54","./Plane-18bb00f8"],function(Ce,Fe,Ne,Oe,r,Re,Le,ze,He,e,t,a,i,n,s,l){"use strict";var o=Object.freeze({NONE:0,LERC:1}),_e={};_e.DEFAULT_STRUCTURE=Object.freeze({heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:256,isBigEndian:!1});var Ye=new Ce.Cartesian3,We=new Ce.Matrix4,Xe=new Ce.Cartesian3,Ze=new Ce.Cartesian3;_e.computeVertices=function(e){var t,a,i,r=Math.cos,n=Math.sin,s=Math.sqrt,l=Math.atan,o=Math.exp,f=Le.CesiumMath.PI_OVER_TWO,u=Le.CesiumMath.toRadians,c=e.heightmap,d=e.width,h=e.height,m=e.skirtHeight,g=0>3],T<<=7&M),g=0;g>3]:T)?(l&&(l[M]=1),m=(n=A.encoding<2?b[U++]:v)>=6,2===(w.offsetType=x))w.offset=n.getInt8(1),p++;else if(1===x)w.offset=n.getInt16(1,!0),p+=2;else{if(0!==x)throw"Invalid block offset type";w.offset=n.getFloat32(1,!0),p+=4}if(1===w.encoding)if(x=n.getUint8(p),p++,w.bitsPerPixel=63&x,x>>=6,2===(w.numValidPixelsType=x))w.numValidPixels=n.getUint8(p),p++;else if(1===x)w.numValidPixels=n.getUint16(p,!0),p+=2;else{if(0!==x)throw"Invalid valid pixel count type";w.numValidPixels=n.getUint32(p,!0),p+=4}}if(t+=p,3!==w.encoding)if(0===w.encoding){var y=(i.pixels.numBytes-1)/4;if(y!==Math.floor(y))throw"uncompressed block has invalid length";k=new ArrayBuffer(4*y),new Uint8Array(k).set(new Uint8Array(e,t,4*y));var I=new Float32Array(k);w.rawData=I,t+=4*y}else 1===w.encoding&&(I=Math.ceil(w.numValidPixels*w.bitsPerPixel/8),y=Math.ceil(I/4),k=new ArrayBuffer(4*y),new Uint8Array(k).set(new Uint8Array(e,t,I)),w.stuffedData=new Uint32Array(k),t+=I)}else t++}return i.eofOffset=t,i},B=function(e,t,a,i,r,n,s){var l,o,f,u,c=(1<>>h-t&c,h-=t):(f=(u&c)<<(o=t-h)&c,f+=(u=e[d++])>>>(h=32-o)),n[l]=f>>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>>g-a&h,g-=a):(f=(u&h)<<(c=a-g)&h,f+=(u=e[m++])>>>(g=32-c)),t[o]=f>>c-t&o,c-=t):(d=(l&o)<<(s=t-c)&o,d+=(l=e[f++])>>>(c=32-s)),h[u]=d>>m&c,h-=a,m+=a):(o=f>>>m&c,h=32-(u=a-h),o|=((f=e[d++])&(1<>>m&c,h-=a,m+=a):(o=f>>>m&c,h=32-(u=a-h),o|=((f=e[d++])&(1<>>h&o,c-=t,h+=t):(d=l>>>h&o,c=32-(s=t-c),d|=((l=e[f++])&(1<>>u-a&o,u-=a):(n=(s&o)<<(l=a-u)&o,n+=(s=e[f++])>>>(u=32-l)),t[r]=n;return t},T=function(e,t,a,i){for(var r,n,s,l=(1<>>u&l,f-=a,u+=a):(r=n>>>u&l,f=32-(s=a-f),r|=((n=e[o++])&(1<>>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=new DataView(e,a,8),i=n.getInt32(0,!0);if(a+=4,3<=(r.fileVersion=i)&&(r.checksum=n.getUint32(4,!0),a+=4),n=new DataView(e,a,12),r.height=n.getUint32(0,!0),r.width=n.getUint32(4,!0),a+=8,4<=i?(r.numDims=n.getUint32(8,!0),a+=4):r.numDims=1,n=new DataView(e,a,40),r.numValidPixel=n.getUint32(0,!0),r.microBlockSize=n.getInt32(4,!0),r.blobSize=n.getInt32(8,!0),r.imageType=n.getInt32(12,!0),r.maxZError=n.getFloat64(16,!0),r.zMin=n.getFloat64(24,!0),r.zMax=n.getFloat64(32,!0),a+=40,t.headerInfo=r,t.ptr=a,3<=i&&this.computeChecksumFletcher32(new Uint8Array(e,a-(4<=i?52:48),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;for(var l=!0,o=0;o>3],h<<=7&m):h=o[m>>3],128&h&&(d[m]=1);t.pixels.resultMask=d,s.bitset=o,a+=s.numBytes}return t.ptr=a,t.mask=s,!0},readDataOneSweep:function(e,t,a){var i=t.ptr,r=t.headerInfo,n=r.numDims,s=r.width*r.height,l=r.imageType,r=r.numValidPixel*L.getDataTypeSize(l)*n,o=t.pixels.resultMask,f=a===Uint8Array?new Uint8Array(e,i,r):(l=new ArrayBuffer(r),new Uint8Array(l).set(new Uint8Array(e,i,r)),new a(l));if(f.length===s*n)t.pixels.resultPixels=f;else{t.pixels.resultPixels=new a(s*n);var u,c=0,d=0,h=0;if(1>>32-u,u<=32-g?32===(g+=u)&&(g=0,x=m[++p]):(x=m[++p],c[o].second|=x>>>32-(g+=u-32)));var w=0,k=0,y=new V;for(d=0;d>>v&1?(T.right||(T.right=new V),T.right):(T.left||(T.left=new V),T.left),0!==v||T.val||(T.val=I[1]);return{decodeLut:M,numBitsLUTQick:k,numBitsLUT:w,tree:y,stuffedData:m,srcPtr:p,bitPos:g}},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,e=this.readHuffmanTree(e,t),x=e.decodeLut,w=e.tree,k=e.stuffedData,y=e.srcPtr,I=e.bitPos,b=e.numBitsLUTQick,U=e.numBitsLUT,v=0===t.headerInfo.imageType?128:0,T=t.pixels.resultMask,M=0;0>>32-b,x[l=32-I>>64-I-b:l])r=x[l][1],I+=x[l][0];else for(l=s=V<>>32-U,32-I>>64-I-U),i=w,c=0;c>>U-c-1&1?i.right:i.left).left&&!i.right){r=i.val,I=I+c+1;break}32<=I&&(I-=32,V=k[++y]),n=r-v,A?(n+=!(0>>32-b,x[l=32-I>>64-I-b:l])r=x[l][1],I+=x[l][0];else for(l=s=V<>>32-U,32-I>>64-I-U),i=w,c=0;c>>U-c-1&1?i.right:i.left).left&&!i.right){r=i.val,I=I+c+1;break}32<=I&&(I-=32,V=k[++y]),n=r-v,A?(!(0>6,c=0==u?4:3-u,d=0<(32&f),u=31&f,f=0;if(1==c)f=o.getUint8(l),l++;else if(2==c)f=o.getUint16(l,!0),l+=2;else{if(4!=c)throw"Invalid valid pixel count type";f=o.getUint32(l,!0),l+=4}var h,m,g,p,x,w,k,c=2*n.maxZError,n=1>>k;)k++;p=Math.ceil(f*k/8),x=Math.ceil(p/4),m=new ArrayBuffer(4*x),(g=new Uint8Array(m)).set(new Uint8Array(e,t.ptr,p)),h=new Uint32Array(m),t.ptr+=p,o=(3<=s?U:I)(o,u,w-1,i,c,n),(3<=s?b:y)(h,a,k,f,o)}else t.counter.bitstuffer++,k=u,t.ptr+=l,0>6&255,(m>>2&15)!=(A*s>>3&15))throw"integrity issue";if(3<(I=3&m))throw t.ptr+=P,"Invalid block encoding ("+I+")";if(2!=I)if(0==I){if(t.counter.uncompressed++,t.ptr+=P,D=(D=c*d*o)<(x=e.byteLength-t.ptr)?D:x,b=new ArrayBuffer(D%o==0?D:D+o-D%o),new Uint8Array(b).set(new Uint8Array(e,t.ptr,D)),y=new a(b),S=0,O)for(T=0;T