define(["./when-54c2dc71","./Check-6c0211bc","./Math-fc8cecf5","./Cartesian2-bddc1162","./Transforms-ec27f304","./RuntimeError-2109023a","./WebGLConstants-76bb35d1","./ComponentDatatype-6d99a1ee","./AttributeCompression-9fc99391","./IntersectionTests-2626c9e9","./Plane-231f1723","./WebMercatorProjection-df58d479","./createTaskProcessorWorker","./EllipsoidTangentPlane-ed172748","./OrientedBoundingBox-c9ad91c4","./TerrainEncoding-b34235ca"],function(Ye,e,We,Xe,Ze,n,t,a,i,r,s,je,l,Ge,qe,Qe){"use strict";var o=Object.freeze({NONE:0,LERC:1}),Je={};Je.DEFAULT_STRUCTURE=Object.freeze({heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:256,isBigEndian:!1});var Ke=new Xe.Cartesian3,$e=new Ze.Matrix4,et=new Xe.Cartesian3,tt=new Xe.Cartesian3;Je.computeVertices=function(e){var t,a,i,r=Math.cos,n=Math.sin,s=Math.sqrt,l=Math.atan,o=Math.exp,f=We.CesiumMath.PI_OVER_TWO,u=We.CesiumMath.toRadians,c=e.heightmap,d=e.width,h=e.height,m=e.skirtHeight,g=Ye.defaultValue(e.isGeographic,!0),p=Ye.defaultValue(e.ellipsoid,Xe.Ellipsoid.WGS84),w=1/p.maximumRadius,x=e.nativeRectangle,k=e.rectangle,y=Ye.defined(k)?(t=k.west,a=k.south,i=k.east,k.north):g?(t=u(x.west),a=u(x.south),i=u(x.east),u(x.north)):(t=x.west*w,a=f-2*l(o(-x.south*w)),i=x.east*w,f-2*l(o(-x.north*w))),I=e.relativeToCenter,b=Ye.defined(I),I=b?I:Xe.Cartesian3.ZERO,U=Ye.defaultValue(e.exaggeration,1),v=Ye.defaultValue(e.includeWebMercatorT,!1),T=Ye.defaultValue(e.structure,Je.DEFAULT_STRUCTURE),M=Ye.defaultValue(T.heightScale,Je.DEFAULT_STRUCTURE.heightScale),V=Ye.defaultValue(T.heightOffset,Je.DEFAULT_STRUCTURE.heightOffset),A=Ye.defaultValue(T.elementsPerHeight,Je.DEFAULT_STRUCTURE.elementsPerHeight),B=Ye.defaultValue(T.stride,Je.DEFAULT_STRUCTURE.stride),D=Ye.defaultValue(T.elementMultiplier,Je.DEFAULT_STRUCTURE.elementMultiplier),S=Ye.defaultValue(T.isBigEndian,Je.DEFAULT_STRUCTURE.isBigEndian),P=Xe.Rectangle.computeWidth(x),E=Xe.Rectangle.computeHeight(x),C=P/(d-1),F=E/(h-1);g||(P*=w,E*=w);var L,O,N=p.radiiSquared,z=N.x,R=N.y,_=N.z,H=65536,Y=-65536,W=Ze.Transforms.eastNorthUpToFixedFrame(I,p),X=Ze.Matrix4.inverseTransformation(W,$e);v&&(L=je.WebMercatorProjection.geodeticLatitudeToMercatorAngle(a),O=1/(je.WebMercatorProjection.geodeticLatitudeToMercatorAngle(y)-L));var Z=et;Z.x=Number.POSITIVE_INFINITY,Z.y=Number.POSITIVE_INFINITY,Z.z=Number.POSITIVE_INFINITY;var j=tt;j.x=Number.NEGATIVE_INFINITY,j.y=Number.NEGATIVE_INFINITY,j.z=Number.NEGATIVE_INFINITY;var G=Number.POSITIVE_INFINITY,q=d*h,Q=q+(0>3],T<<=7&M),g=0;g>3]),128&T?(l&&(l[M]=1),m=(n=A.encoding<2?b[U++]:v)>=6,2===(y.offsetType=v))y.offset=n.getInt8(1),x++;else if(1===v)y.offset=n.getInt16(1,!0),x+=2;else{if(0!==v)throw"Invalid block offset type";y.offset=n.getFloat32(1,!0),x+=4}if(1===y.encoding)if(v=n.getUint8(x),x++,y.bitsPerPixel=63&v,v>>=6,2===(y.numValidPixelsType=v))y.numValidPixels=n.getUint8(x),x++;else if(1===v)y.numValidPixels=n.getUint16(x,!0),x+=2;else{if(0!==v)throw"Invalid valid pixel count type";y.numValidPixels=n.getUint32(x,!0),x+=4}}if(t+=x,3!==y.encoding)if(0===y.encoding){var T=(i.pixels.numBytes-1)/4;if(T!==Math.floor(T))throw"uncompressed block has invalid length";U=new ArrayBuffer(4*T),new Uint8Array(U).set(new Uint8Array(e,t,4*T));var M=new Float32Array(U);y.rawData=M,t+=4*T}else{1===y.encoding&&(I=Math.ceil(y.numValidPixels*y.bitsPerPixel/8),b=Math.ceil(I/4),U=new ArrayBuffer(4*b),new Uint8Array(U).set(new Uint8Array(e,t,I)),y.stuffedData=new Uint32Array(U),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},E=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,s=new DataView(e,a,8),l=s.getInt32(0,!0);if(a+=4,3<=(r.fileVersion=l)&&(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,4<=l?(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,3<=l&&(n=4<=l?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;for(var l=!0,o=0;o>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*R.getDataTypeSize(o)*s,u=t.pixels.resultMask,c=a===Uint8Array?new Uint8Array(e,r,f):(i=new ArrayBuffer(f),new Uint8Array(i).set(new Uint8Array(e,r,f)),new a(i));if(c.length===l*s)t.pixels.resultPixels=c;else{t.pixels.resultPixels=new a(l*s);var d,h=0,m=0,g=0;if(1>>32-u,u<=32-w?32===(w+=u)&&(w=0,k=p[++x]):(w+=u-32,k=p[++x],c[o].second|=k>>>32-w));var y=0,I=0,b=new C;for(d=0;d>>M&1?(V.right||(V.right=new C),V.right):(V.left||(V.left=new C),V.left),0!==M||V.val||(V.val=U[1]);return{decodeLut:A,numBitsLUTQick:I,numBitsLUT:y,tree:b,stuffedData:p,srcPtr:x,bitPos:w}},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,w=this.readHuffmanTree(e,t),x=w.decodeLut,k=w.tree,y=w.stuffedData,I=w.srcPtr,b=w.bitPos,U=w.numBitsLUTQick,v=w.numBitsLUT,T=0===t.headerInfo.imageType?128:0,M=t.pixels.resultMask,V=0;0>>32-U,32-b>>64-b-U),x[l])r=x[l][1],b+=x[l][0];else for(l=s=A<>>32-v,32-b>>64-b-v),i=k,c=0;c>>v-c-1&1?i.right:i.left).left&&!i.right){r=i.val,b=b+c+1;break}32<=b&&(b-=32,A=y[++I]),n=r-T,B?(n+=!(0>>32-U,32-b>>64-b-U),x[l])r=x[l][1],b+=x[l][0];else for(l=s=A<>>32-v,32-b>>64-b-v),i=k,c=0;c>>v-c-1&1?i.right:i.left).left&&!i.right){r=i.val,b=b+c+1;break}32<=b&&(b-=32,A=y[++I]),n=r-T,B?(!(0>6,d=0==c?4:3-c,h=0<(32&u),m=31&u,g=0;if(1==d)g=f.getUint8(l),l++;else if(2==d)g=f.getUint16(l,!0),l+=2;else{if(4!=d)throw"Invalid valid pixel count type";g=f.getUint32(l,!0),l+=4}var p,w,x,k,y,I,b,U,v,T=2*n.maxZError,M=1>>v;)v++;k=Math.ceil(g*v/8),y=Math.ceil(k/4),w=new ArrayBuffer(4*y),(x=new Uint8Array(w)).set(new Uint8Array(e,t.ptr,k)),p=new Uint32Array(w),t.ptr+=k,I=(3<=s?S:A)(b,m,U-1,i,T,M),(3<=s?D:V)(p,a,v,g,I)}else t.counter.bitstuffer++,v=m,t.ptr+=l,0>6&255,(m>>2&15)!=(B*s>>3&15))throw"integrity issue";if(3<(b=3&m))throw t.ptr+=E,"Invalid block encoding ("+b+")";if(2!=b)if(0==b){if(t.counter.uncompressed++,t.ptr+=E,S=(S=c*d*o)<(w=e.byteLength-t.ptr)?S:w,y=new ArrayBuffer(S%o==0?S:S+o-S%o),new Uint8Array(y).set(new Uint8Array(e,t.ptr,S)),I=new a(y),P=0,N)for(M=0;M