define(["./when-cbf8cd21","./Check-35e1a91d","./Math-e66fad2a","./Cartesian2-44433f55","./Matrix3-146a3f23","./Transforms-fc4c03e8","./RuntimeError-f4c64df1","./WebGLConstants-95ceb4e9","./ComponentDatatype-7ee14e67","./AttributeCompression-170b3be0","./IndexDatatype-66caba23","./IntersectionTests-caa0ba1a","./Plane-e04c899a","./WebMercatorProjection-c689ba4a","./createTaskProcessorWorker","./EllipsoidTangentPlane-d27aa001","./OrientedBoundingBox-6e047f5d","./TerrainEncoding-5829782a"],function(ye,e,fe,ve,t,Ne,r,n,i,we,xe,Me,o,Ce,a,Se,be,Ae){"use strict";function Pe(){e.DeveloperError.throwInstantiationError()}Object.defineProperties(Pe.prototype,{errorEvent:{get:e.DeveloperError.throwInstantiationError},credit:{get:e.DeveloperError.throwInstantiationError},tilingScheme:{get:e.DeveloperError.throwInstantiationError},ready:{get:e.DeveloperError.throwInstantiationError},readyPromise:{get:e.DeveloperError.throwInstantiationError},hasWaterMask:{get:e.DeveloperError.throwInstantiationError},hasVertexNormals:{get:e.DeveloperError.throwInstantiationError},availability:{get:e.DeveloperError.throwInstantiationError}});var s=[];Pe.getRegularGridIndices=function(e,t){var r=s[e];ye.defined(r)||(s[e]=r=[]);var n=r[t];return ye.defined(n)||p(e,t,n=e*t<fe.CesiumMath.SIXTY_FOUR_KILOBYTES?r[t]=new Uint16Array((e-1)*(t-1)*6):r[t]=new Uint32Array((e-1)*(t-1)*6),0),n};var h=[];Pe.getRegularGridIndicesAndEdgeIndices=function(e,t){var r=h[e];ye.defined(r)||(h[e]=r=[]);var n,i,o,a,s,c,d=r[t];return ye.defined(d)||(n=Pe.getRegularGridIndices(e,t),o=(i=T(e,t)).westIndicesSouthToNorth,a=i.southIndicesEastToWest,s=i.eastIndicesNorthToSouth,c=i.northIndicesWestToEast,d=r[t]={indices:n,westIndicesSouthToNorth:o,southIndicesEastToWest:a,eastIndicesNorthToSouth:s,northIndicesWestToEast:c}),d};var g=[];function T(e,t){for(var r=new Array(t),n=new Array(e),i=new Array(t),o=new Array(e),a=0;a<e;++a)n[o[a]=a]=e*t-1-a;for(a=0;a<t;++a)i[a]=(a+1)*e-1,r[a]=(t-a-1)*e;return{westIndicesSouthToNorth:r,southIndicesEastToWest:n,eastIndicesNorthToSouth:i,northIndicesWestToEast:o}}function p(e,t,r,n){for(var i=0,o=0;o<t-1;++o){for(var a=0;a<e-1;++a){var s=i+e,c=s+1,d=i+1;r[n++]=i,r[n++]=s,r[n++]=d,r[n++]=d,r[n++]=s,r[n++]=c,++i}++i}}function c(e,t,r,n){for(var i=e[0],o=e.length,a=1;a<o;++a){var s=e[a];r[n++]=i,r[n++]=s,r[n++]=t,r[n++]=t,r[n++]=s,r[n++]=t+1,i=s,++t}return n}Pe.getRegularGridAndSkirtIndicesAndEdgeIndices=function(e,t){var r=g[e];ye.defined(r)||(g[e]=r=[]);var n,i,o,a,s,c,d,h,u,l,I,m=r[t];return ye.defined(m)||(a=(n=e*t)+(o=2*e+2*t),s=(i=(e-1)*(t-1)*6)+6*Math.max(0,o-4),d=(c=T(e,t)).westIndicesSouthToNorth,h=c.southIndicesEastToWest,u=c.eastIndicesNorthToSouth,l=c.northIndicesWestToEast,p(e,t,I=xe.IndexDatatype.createTypedArray(a,s),0),Pe.addSkirtIndices(d,h,u,l,n,I,i),m=r[t]={indices:I,westIndicesSouthToNorth:d,southIndicesEastToWest:h,eastIndicesNorthToSouth:u,northIndicesWestToEast:l,indexCountWithoutSkirts:i}),m},Pe.addSkirtIndices=function(e,t,r,n,i,o,a){var s=i;a=c(e,s,o,a),a=c(t,s+=e.length,o,a),a=c(r,s+=t.length,o,a),c(n,s+=r.length,o,a)},Pe.heightmapTerrainQuality=.25,Pe.getEstimatedLevelZeroGeometricErrorForAHeightmap=function(e,t,r){return 2*e.maximumRadius*Math.PI*Pe.heightmapTerrainQuality/(t*r)},Pe.prototype.requestTileGeometry=e.DeveloperError.throwInstantiationError,Pe.prototype.getLevelMaximumGeometricError=e.DeveloperError.throwInstantiationError,Pe.prototype.getTileDataAvailable=e.DeveloperError.throwInstantiationError,Pe.prototype.loadTileDataAvailability=e.DeveloperError.throwInstantiationError;var We=32767,Fe=new ve.Cartesian3,De=new ve.Cartesian3,Be=new ve.Cartesian3,ke=new ve.Cartographic,Oe=new ve.Cartesian2,Ve=new ve.Cartesian3,He=new Ne.Matrix4,_e=new Ne.Matrix4;function Re(e,t,r,n,i,o,a,s,c){var d=Number.POSITIVE_INFINITY,h=i.north,u=i.south,l=i.east,I=i.west;l<I&&(l+=fe.CesiumMath.TWO_PI);for(var m=e.length,g=0;g<m;++g){var T=e[g],p=r[T],E=n[T];ke.longitude=fe.CesiumMath.lerp(I,l,E.x),ke.latitude=fe.CesiumMath.lerp(u,h,E.y),ke.height=p-t;var y=o.cartographicToCartesian(ke,Fe);Ne.Matrix4.multiplyByPoint(a,y,y),ve.Cartesian3.minimumByComponent(y,s,s),ve.Cartesian3.maximumByComponent(y,c,c),d=Math.min(d,ke.height)}return d}function Ge(e,t,r,n,i,o,a,s,c,d,h,u,l,I,m){var g=ye.defined(a),T=c.north,p=c.south,E=c.east,y=c.west;E<y&&(E+=fe.CesiumMath.TWO_PI);for(var f=r.length,v=0;v<f;++v){var N=r[v],w=i[N],x=o[N];ke.longitude=fe.CesiumMath.lerp(y,E,x.x)+I,ke.latitude=fe.CesiumMath.lerp(p,T,x.y)+m,ke.height=w-d;var M,C,S,b,A,P=s.cartographicToCartesian(ke,Fe);g&&(M=2*N,Oe.x=a[M],Oe.y=a[1+M],1!==h&&(C=we.AttributeCompression.octDecode(Oe.x,Oe.y,Ve),S=Ne.Transforms.eastNorthUpToFixedFrame(Fe,s,_e),b=Ne.Matrix4.inverseTransformation(S,He),Ne.Matrix4.multiplyByPointAsVector(b,C,C),C.z*=h,ve.Cartesian3.normalize(C,C),Ne.Matrix4.multiplyByPointAsVector(S,C,C),ve.Cartesian3.normalize(C,C),we.AttributeCompression.octEncode(C,Oe))),n.hasWebMercatorT&&(A=(Ce.WebMercatorProjection.geodeticLatitudeToMercatorAngle(ke.latitude)-u)*l),t=n.encode(e,t,P,x,ke.height,Oe,A)}}function Ye(e,t){var r;return"function"==typeof e.slice&&"function"!=typeof(r=e.slice()).sort&&(r=void 0),ye.defined(r)||(r=Array.prototype.slice.call(e)),r.sort(t),r}return a(function(e,t){var r,n,i=e.quantizedVertices,o=i.length/3,a=e.octEncodedNormals,s=e.westIndices.length+e.eastIndices.length+e.southIndices.length+e.northIndices.length,c=e.includeWebMercatorT,d=ve.Rectangle.clone(e.rectangle),h=d.west,u=d.south,l=d.east,I=d.north,m=e.constraintRegions,g=Me.IntersectionTests.intersetRectangleWithConstraintRegion(d,m),T=ve.Ellipsoid.clone(e.ellipsoid),p=e.exaggeration,E=e.minimumHeight*p,y=e.maximumHeight*p,f=e.relativeToCenter,v=Ne.Transforms.eastNorthUpToFixedFrame(f,T),N=Ne.Matrix4.inverseTransformation(v,new Ne.Matrix4);c&&(r=Ce.WebMercatorProjection.geodeticLatitudeToMercatorAngle(u),n=1/(Ce.WebMercatorProjection.geodeticLatitudeToMercatorAngle(I)-r));var w=i.subarray(0,o),x=i.subarray(o,2*o),M=i.subarray(2*o,3*o),C=ye.defined(a),S=new Array(o),b=new Array(o),A=new Array(o),P=c?new Array(o):[],W=De;W.x=Number.POSITIVE_INFINITY,W.y=Number.POSITIVE_INFINITY,W.z=Number.POSITIVE_INFINITY;var F=Be;F.x=Number.NEGATIVE_INFINITY,F.y=Number.NEGATIVE_INFINITY,F.z=Number.NEGATIVE_INFINITY;for(var D=Number.POSITIVE_INFINITY,B=Number.NEGATIVE_INFINITY,k=Number.POSITIVE_INFINITY,O=Number.NEGATIVE_INFINITY,V=0;V<o;++V){var H,_=w[V],R=x[V],G=_/We,Y=R/We,z=fe.CesiumMath.lerp(E,y,M[V]/We);ke.longitude=fe.CesiumMath.lerp(h,l,G),ke.latitude=fe.CesiumMath.lerp(u,I,Y),ke.height=z,-1===g||-1!==(H=Me.IntersectionTests.isCartographicInConstraintRegion(ke,g,m))&&("ERASE"===m[H].eraseType?z=m[H].height:"OFFSET"===m[H].eraseType?z+=m[H].height:"SMOOTH"===m[H].eraseType&&(z=Me.IntersectionTests.interoplateCartographicWhenSmooth(ke,m[H]))<m[H].height&&(z=m[H].height),ke.height=z),D=Math.min(ke.longitude,D),B=Math.max(ke.longitude,B),k=Math.min(ke.latitude,k),O=Math.max(ke.latitude,O);var L=T.cartographicToCartesian(ke);S[V]=new ve.Cartesian2(G,Y),b[V]=z,A[V]=L,c&&(P[V]=(Ce.WebMercatorProjection.geodeticLatitudeToMercatorAngle(ke.latitude)-r)*n),Ne.Matrix4.multiplyByPoint(N,L,Fe),ve.Cartesian3.minimumByComponent(Fe,W,W),ve.Cartesian3.maximumByComponent(Fe,F,F)}var U,j,q,Q=Ye(e.westIndices,function(e,t){return S[e].y-S[t].y}),K=Ye(e.eastIndices,function(e,t){return S[t].y-S[e].y}),X=Ye(e.southIndices,function(e,t){return S[t].x-S[e].x}),Z=Ye(e.northIndices,function(e,t){return S[e].x-S[t].x});1!==p&&(j=Ne.BoundingSphere.fromPoints(A),U=be.OrientedBoundingBox.fromRectangle(d,E,y,T)),(1!==p||E<0)&&(q=new Ae.EllipsoidalOccluder(T).computeHorizonCullingPointPossiblyUnderEllipsoid(f,A,E));var J=E,J=Math.min(J,Re(e.westIndices,e.westSkirtHeight,b,S,d,T,N,W,F));J=Math.min(J,Re(e.southIndices,e.southSkirtHeight,b,S,d,T,N,W,F)),J=Math.min(J,Re(e.eastIndices,e.eastSkirtHeight,b,S,d,T,N,W,F)),J=Math.min(J,Re(e.northIndices,e.northSkirtHeight,b,S,d,T,N,W,F));for(var $,ee,te,re,ne=new Se.AxisAlignedBoundingBox(W,F,f),ie=new Ae.TerrainEncoding(ne,J,y,v,C,c),oe=ie.getStride(),ae=new Float32Array(o*oe+s*oe),se=0,ce=0;ce<o;++ce){C&&($=2*ce,Oe.x=a[$],Oe.y=a[1+$],1!==p&&(ee=we.AttributeCompression.octDecode(Oe.x,Oe.y,Ve),te=Ne.Transforms.eastNorthUpToFixedFrame(A[ce],T,_e),re=Ne.Matrix4.inverseTransformation(te,He),Ne.Matrix4.multiplyByPointAsVector(re,ee,ee),ee.z*=p,ve.Cartesian3.normalize(ee,ee),Ne.Matrix4.multiplyByPointAsVector(te,ee,ee),ve.Cartesian3.normalize(ee,ee),we.AttributeCompression.octEncode(ee,Oe))),se=ie.encode(ae,se,A[ce],S[ce],b[ce],Oe,P[ce])}var de=Math.max(0,2*(s-4)),he=e.indices.length+3*de,ue=xe.IndexDatatype.createTypedArray(o+s,he);ue.set(e.indices,0);var le=1e-4*(B-D),Ie=1e-4*(O-k),me=-le,ge=le,Te=Ie,pe=-Ie,Ee=o*oe;return Ge(ae,Ee,Q,ie,b,S,a,T,d,e.westSkirtHeight,p,r,n,me,0),Ge(ae,Ee+=e.westIndices.length*oe,X,ie,b,S,a,T,d,e.southSkirtHeight,p,r,n,0,pe),Ge(ae,Ee+=e.southIndices.length*oe,K,ie,b,S,a,T,d,e.eastSkirtHeight,p,r,n,ge,0),Ge(ae,Ee+=e.eastIndices.length*oe,Z,ie,b,S,a,T,d,e.northSkirtHeight,p,r,n,0,Te),Pe.addSkirtIndices(Q,X,K,Z,o,ue,e.indices.length),t.push(ae.buffer,ue.buffer),{vertices:ae.buffer,indices:ue.buffer,westIndicesSouthToNorth:Q,southIndicesEastToWest:X,eastIndicesNorthToSouth:K,northIndicesWestToEast:Z,vertexStride:oe,center:f,minimumHeight:E,maximumHeight:y,boundingSphere:j,orientedBoundingBox:U,occludeePointInScaledSpace:q,encoding:ie,indexCountWithoutSkirts:e.indices.length}})});