define(["./Transforms-a6362ad2","./Matrix2-ae0e0b05","./RuntimeError-ffc802eb","./when-e3a49219","./ComponentDatatype-64cf6611","./ArcType-5c308c35","./arrayRemoveDuplicates-328bac4c","./EllipsoidGeodesic-524df442","./EllipsoidRhumbLine-b6518e5c","./EncodedCartesian3-f1386330","./GeometryAttribute-50aef525","./IntersectionTests-8be403d7","./Plane-2bf1bb80","./WebMercatorProjection-043b7eb3","./combine-c7a1ec8a","./PixelFormat-83d70a69","./WebGLConstants-1c8239cc"],(function(e,a,t,n,i,r,s,o,l,u,c,C,h,d,p,g,f){"use strict";function m(t){t=n.defaultValue(t,n.defaultValue.EMPTY_OBJECT),this._ellipsoid=n.defaultValue(t.ellipsoid,a.Ellipsoid.WGS84),this._rectangle=n.defaultValue(t.rectangle,a.Rectangle.MAX_VALUE),this._projection=new e.GeographicProjection(this._ellipsoid),this._numberOfLevelZeroTilesX=n.defaultValue(t.numberOfLevelZeroTilesX,2),this._numberOfLevelZeroTilesY=n.defaultValue(t.numberOfLevelZeroTilesY,1),this._tileInfo=t.tileInfo}Object.defineProperties(m.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},rectangle:{get:function(){return this._rectangle}},projection:{get:function(){return this._projection}}}),m.prototype.getNumberOfXTilesAtLevel=function(e){if(!n.defined(this._tileInfo))return this._numberOfLevelZeroTilesX<=o&&(h=o-1);var d=(s.north-e.latitude)/c|0;return d>=l&&(d=l-1),n.defined(r)?(r.x=h,r.y=d,r):new a.Cartesian2(h,d)}};var w=new a.Cartesian3,v=new a.Cartesian3,y=new a.Cartographic,M=new a.Cartesian3,T=new a.Cartesian3,E=new e.BoundingSphere,_=new m,O=[new a.Cartographic,new a.Cartographic,new a.Cartographic,new a.Cartographic],b=new a.Cartesian2,P={};function A(e){a.Cartographic.fromRadians(e.east,e.north,0,O[0]),a.Cartographic.fromRadians(e.west,e.north,0,O[1]),a.Cartographic.fromRadians(e.east,e.south,0,O[2]),a.Cartographic.fromRadians(e.west,e.south,0,O[3]);var t,n=0,i=0,r=0,s=0,o=P._terrainHeightsMaxLevel;for(t=0;t<=o;++t){for(var l=!1,u=0;u<4;++u){var c=O[u];if(_.positionToTileXY(c,t,b),0===u)r=b.x,s=b.y;else if(r!==b.x||s!==b.y){l=!0;break}}if(l)break;n=r,i=s}if(0!==t)return{x:n,y:i,level:t>o?o:t-1}}P.initialize=function(){var a=P._initPromise;return n.defined(a)||(a=e.Resource.fetchJson(e.buildModuleUrl("Assets/approximateTerrainHeights.json")).then((function(e){P._terrainHeights=e})),P._initPromise=a),a},P.getMinimumMaximumHeights=function(e,t){t=n.defaultValue(t,a.Ellipsoid.WGS84);var i=A(e),r=P._defaultMinTerrainHeight,s=P._defaultMaxTerrainHeight;if(n.defined(i)){var o=i.level+"-"+i.x+"-"+i.y,l=P._terrainHeights[o];n.defined(l)&&(r=l[0],s=l[1]),t.cartographicToCartesian(a.Rectangle.northeast(e,y),w),t.cartographicToCartesian(a.Rectangle.southwest(e,y),v),a.Cartesian3.midpoint(v,w,M);var u=t.scaleToGeodeticSurface(M,T);if(n.defined(u)){var c=a.Cartesian3.distance(M,u);r=Math.min(r,-c)}else r=P._defaultMinTerrainHeight}return{minimumTerrainHeight:r=Math.max(P._defaultMinTerrainHeight,r),maximumTerrainHeight:s}},P.getBoundingSphere=function(t,i){i=n.defaultValue(i,a.Ellipsoid.WGS84);var r=A(t),s=P._defaultMaxTerrainHeight;if(n.defined(r)){var o=r.level+"-"+r.x+"-"+r.y,l=P._terrainHeights[o];n.defined(l)&&(s=l[1])}var u=e.BoundingSphere.fromRectangle3D(t,i,0);return e.BoundingSphere.fromRectangle3D(t,i,s,E),e.BoundingSphere.union(u,E,u)},P._terrainHeightsMaxLevel=6,P._defaultMaxTerrainHeight=9e3,P._defaultMinTerrainHeight=-1e5,P._terrainHeights=void 0,P._initPromise=void 0,Object.defineProperties(P,{initialized:{get:function(){return n.defined(P._terrainHeights)}}});var k=[e.GeographicProjection,d.WebMercatorProjection],I=k.length,L=Math.cos(i.CesiumMath.toRadians(30)),S=Math.cos(i.CesiumMath.toRadians(150));function x(e){var t=(e=n.defaultValue(e,n.defaultValue.EMPTY_OBJECT)).positions;this.width=n.defaultValue(e.width,1),this._positions=t,this.granularity=n.defaultValue(e.granularity,9999),this.loop=n.defaultValue(e.loop,!1),this.arcType=n.defaultValue(e.arcType,r.ArcType.GEODESIC),this._ellipsoid=a.Ellipsoid.WGS84,this._projectionIndex=0,this._workerName="createGroundPolylineGeometry",this._scene3DOnly=!1}Object.defineProperties(x.prototype,{packedLength:{get:function(){return 1+3*this._positions.length+1+1+1+a.Ellipsoid.packedLength+1+1}}}),x.setProjectionAndEllipsoid=function(e,a){for(var t=0,n=0;n65535?new Uint32Array(T):new Uint16Array(T),_=new Float64Array(3*y),O=new Float32Array(M),b=new Float32Array(M),A=new Float32Array(M),k=new Float32Array(M),I=new Float32Array(M);C&&(p=new Float32Array(M),g=new Float32Array(M),f=new Float32Array(M),m=new Float32Array(2*y));var S=l.length/2,x=0,N=Te;N.height=0;var R=Ee;R.height=0;var D=_e,z=Oe;if(C)for(d=0,h=1;hL?(ae=ge(n,N,re,$,He),te=ge(n,R,Z,ee,Be)):1===se?(te=ge(n,R,Z,ee,Be),ae.x=0,ae.y=i.CesiumMath.sign(N.longitude-Math.abs(R.longitude)),ae.z=0):(ae=ge(n,N,re,$,He),te.x=0,te.y=i.CesiumMath.sign(N.longitude-R.longitude),te.z=0)}var le=a.Cartesian3.distance(ie,U),ue=u.EncodedCartesian3.fromCartesian(ne,Xe),ce=a.Cartesian3.subtract(W,ne,je),he=a.Cartesian3.normalize(ce,Ye),de=a.Cartesian3.subtract(ie,ne,Ge);de=a.Cartesian3.normalize(de,de);var pe=a.Cartesian3.cross(he,de,Ye);pe=a.Cartesian3.normalize(pe,pe);var fe=a.Cartesian3.cross(de,re,Fe);fe=a.Cartesian3.normalize(fe,fe);var me=a.Cartesian3.subtract(U,W,Ve);me=a.Cartesian3.normalize(me,me);var ve=a.Cartesian3.cross(Z,me,qe);ve=a.Cartesian3.normalize(ve,ve);var aa,ta,na,ia=le/j,ra=J/j,sa=0,oa=0,la=0;if(C){sa=a.Cartesian3.distance($,ee),aa=u.EncodedCartesian3.fromCartesian($,We),ta=a.Cartesian3.subtract(ee,$,Ue);var ua=(na=a.Cartesian3.normalize(ta,Ze)).x;na.x=na.y,na.y=-ua,oa=sa/x,la=Q/x}for(B=0;B<8;B++){var ca=F+4*B,Ca=V+2*B,ha=ca+3,da=B<4?1:-1,pa=2===B||3===B||6===B||7===B?1:-1;a.Cartesian3.pack(ue.high,O,ca),O[ha]=ce.x,a.Cartesian3.pack(ue.low,b,ca),b[ha]=ce.y,a.Cartesian3.pack(fe,A,ca),A[ha]=ce.z,a.Cartesian3.pack(ve,k,ca),k[ha]=ia*da,a.Cartesian3.pack(pe,I,ca);var ga=ra*pa;0===ga&&pa<0&&(ga=9),I[ha]=ga,C&&(p[ca]=aa.high.x,p[ca+1]=aa.high.y,p[ca+2]=aa.low.x,p[ca+3]=aa.low.y,f[ca]=-ae.y,f[ca+1]=ae.x,f[ca+2]=te.y,f[ca+3]=-te.x,g[ca]=ta.x,g[ca+1]=ta.y,g[ca+2]=na.x,g[ca+3]=na.y,m[Ca]=oa*da,0===(ga=la*pa)&&pa<0&&(ga=9),m[Ca+1]=ga)}var fa=Ne,ma=Re,wa=Se,va=xe,ya=a.Rectangle.fromCartographicArray(Ie,Le),Ma=P.getMinimumMaximumHeights(ya,w),Ta=Ma.minimumTerrainHeight,Ea=Ma.maximumTerrainHeight;K+=Ta,K+=Ea,we(ne,ie,Ta,Ea,fa,wa),we(W,U,Ta,Ea,ma,va);var _a=a.Cartesian3.multiplyByScalar(pe,i.CesiumMath.EPSILON5,Je);a.Cartesian3.add(fa,_a,fa),a.Cartesian3.add(ma,_a,ma),a.Cartesian3.add(wa,_a,wa),a.Cartesian3.add(va,_a,va),ye(fa,ma),ye(wa,va),a.Cartesian3.pack(fa,_,Y),a.Cartesian3.pack(ma,_,Y+3),a.Cartesian3.pack(va,_,Y+6),a.Cartesian3.pack(wa,_,Y+9),_a=a.Cartesian3.multiplyByScalar(pe,-2*i.CesiumMath.EPSILON5,Je),a.Cartesian3.add(fa,_a,fa),a.Cartesian3.add(ma,_a,ma),a.Cartesian3.add(wa,_a,wa),a.Cartesian3.add(va,_a,va),ye(fa,ma),ye(wa,va),a.Cartesian3.pack(fa,_,Y+12),a.Cartesian3.pack(ma,_,Y+15),a.Cartesian3.pack(va,_,Y+18),a.Cartesian3.pack(wa,_,Y+21),G+=2,d+=3,V+=16,Y+=24,F+=32,J+=le,Q+=sa}d=0;var Oa=0;for(h=0;hL||li.CesiumMath.PI_OVER_TWO&&(u=!0,l=a.Cartesian3.subtract(o,n,pe),C=c.cartesianToCartographic(l,he)),C.height=0;var h=e.project(C,s);return(s=a.Cartesian3.subtract(h,r,s)).z=0,s=a.Cartesian3.normalize(s,s),u&&a.Cartesian3.negate(s,s),s}var fe=new a.Cartesian3,me=new a.Cartesian3;function we(e,t,n,i,r,s){var o=a.Cartesian3.subtract(t,e,fe);a.Cartesian3.normalize(o,o);var l=n-0,u=a.Cartesian3.multiplyByScalar(o,l,me);a.Cartesian3.add(e,u,r);var c=i-1e3;u=a.Cartesian3.multiplyByScalar(o,c,me),a.Cartesian3.add(t,u,s)}var ve=new a.Cartesian3;function ye(e,t){var n=h.Plane.getPointDistance(K,e),r=h.Plane.getPointDistance(K,t),s=ve;i.CesiumMath.equalsEpsilon(n,0,i.CesiumMath.EPSILON2)?(s=q(t,e,s),a.Cartesian3.multiplyByScalar(s,i.CesiumMath.EPSILON2,s),a.Cartesian3.add(e,s,e)):i.CesiumMath.equalsEpsilon(r,0,i.CesiumMath.EPSILON2)&&(s=q(e,t,s),a.Cartesian3.multiplyByScalar(s,i.CesiumMath.EPSILON2,s),a.Cartesian3.add(t,s,t))}function Me(e,a){var t=Math.abs(e.longitude),n=Math.abs(a.longitude);if(i.CesiumMath.equalsEpsilon(t,i.CesiumMath.PI,i.CesiumMath.EPSILON11)){var r=i.CesiumMath.sign(a.longitude);return e.longitude=r*(t-i.CesiumMath.EPSILON11),1}if(i.CesiumMath.equalsEpsilon(n,i.CesiumMath.PI,i.CesiumMath.EPSILON11)){var s=i.CesiumMath.sign(e.longitude);return a.longitude=s*(n-i.CesiumMath.EPSILON11),2}return 0}var Te=new a.Cartographic,Ee=new a.Cartographic,_e=new a.Cartesian3,Oe=new a.Cartesian3,be=new a.Cartesian3,Pe=new a.Cartesian3,Ae=new a.Cartesian3,ke=new a.Cartesian3,Ie=[Te,Ee],Le=new a.Rectangle,Se=new a.Cartesian3,xe=new a.Cartesian3,Ne=new a.Cartesian3,Re=new a.Cartesian3,De=new a.Cartesian3,ze=new a.Cartesian3,He=new a.Cartesian3,Be=new a.Cartesian3,je=new a.Cartesian3,Ge=new a.Cartesian3,Ve=new a.Cartesian3,Ye=new a.Cartesian3,Fe=new a.Cartesian3,qe=new a.Cartesian3,Xe=new u.EncodedCartesian3,We=new u.EncodedCartesian3,Ue=new a.Cartesian3,Ze=new a.Cartesian3,Je=new a.Cartesian3,Qe=[new e.BoundingSphere,new e.BoundingSphere],Ke=[0,2,1,0,3,2,0,7,3,0,4,7,0,5,4,0,1,5,5,7,4,5,6,7,5,2,6,5,1,2,3,6,2,3,7,6],$e=Ke.length;function ea(e){return new c.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:4,normalize:!1,values:e})}return x._projectNormal=ge,function(e,a){return P.initialize().then((function(){return n.defined(a)&&(e=x.unpack(e,a)),x.createGeometry(e)}))}}));