/**
 * @license
 * Cesium - https://github.com/CesiumGS/cesium
 * Version 1.122
 *
 * Copyright 2011-2022 Cesium Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Columbus View (Pat. Pend.)
 *
 * Portions licensed separately.
 * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
 */
import{a as Gt,b as Xt}from"./chunk-KSXVI5EG.js";import{a as kt}from"./chunk-JQWRUZSV.js";import{a as lt}from"./chunk-ZPNGL6DU.js";import{a as Dt}from"./chunk-VEZ5ALJU.js";import"./chunk-FG53NUCJ.js";import"./chunk-5ONJK4IB.js";import{a as qt}from"./chunk-6IAPD5DZ.js";import"./chunk-354SKS6C.js";import"./chunk-H5GL2A6Z.js";import{d as Lt}from"./chunk-EWTFJ46X.js";import{b as $,g as Ot,i as zt}from"./chunk-5IUXF6I3.js";import"./chunk-27UWHT4D.js";import{a as P,b as N,c as wt,d as Ht}from"./chunk-RFPX772U.js";import{a as r}from"./chunk-RAYRECQS.js";import"./chunk-2NAI7YQ3.js";import{a as Vt}from"./chunk-QE3ZUOZY.js";import{a as Ut}from"./chunk-6KLVDWWE.js";import"./chunk-6P5KAIBX.js";import{e as ht}from"./chunk-4FSVUTPL.js";var te=Uint16Array.BYTES_PER_ELEMENT,mt=Int32Array.BYTES_PER_ELEMENT,Pt=Uint32Array.BYTES_PER_ELEMENT,ee=Float32Array.BYTES_PER_ELEMENT,H=Float64Array.BYTES_PER_ELEMENT;function tt(t,e,n){n=Ut(n,r);let i=t.length;for(let o=0;o<i;++o)if(n.equalsEpsilon(t[o],e,r.EPSILON12))return o;return-1}function oe(t,e){t.ellipsoid=Ht.clone(t.ellipsoid),t.rectangle=zt.clone(t.rectangle);let n=se(t.buffer,t.relativeToCenter,t.ellipsoid,t.rectangle,t.nativeRectangle,t.exaggeration,t.exaggerationRelativeHeight,t.skirtHeight,t.includeWebMercatorT,t.negativeAltitudeExponentBias,t.negativeElevationThreshold),i=n.vertices;e.push(i.buffer);let r=n.indices;return e.push(r.buffer),{vertices:i.buffer,indices:r.buffer,numberOfAttributes:n.encoding.stride,minimumHeight:n.minimumHeight,maximumHeight:n.maximumHeight,boundingSphere3D:n.boundingSphere3D,orientedBoundingBox:n.orientedBoundingBox,occludeePointInScaledSpace:n.occludeePointInScaledSpace,encoding:n.encoding,vertexCountWithoutSkirts:n.vertexCountWithoutSkirts,indexCountWithoutSkirts:n.indexCountWithoutSkirts,westIndicesSouthToNorth:n.westIndicesSouthToNorth,southIndicesEastToWest:n.southIndicesEastToWest,eastIndicesNorthToSouth:n.eastIndicesNorthToSouth,northIndicesWestToEast:n.northIndicesWestToEast}}var u=new N,G=new P,ne=new P,ie=new P,re=new $;function se(t,e,n,i,o,a,s,l,h,c,d){let m,g,p,I,E,f;ht(i)?(m=i.west,g=i.south,p=i.east,I=i.north,E=i.width,f=i.height):(m=r.toRadians(o.west),g=r.toRadians(o.south),p=r.toRadians(o.east),I=r.toRadians(o.north),E=r.toRadians(i.width),f=r.toRadians(i.height));let T,S,x=[g,I],w=[m,p],A=Ot.eastNorthUpToFixedFrame(e,n),k=$.inverseTransformation(A,re);h&&(T=lt.geodeticLatitudeToMercatorAngle(g),S=1/(lt.geodeticLatitudeToMercatorAngle(I)-T));let b=1!==a,R=new DataView(t),y=Number.POSITIVE_INFINITY,F=Number.NEGATIVE_INFINITY,v=ne;v.x=Number.POSITIVE_INFINITY,v.y=Number.POSITIVE_INFINITY,v.z=Number.POSITIVE_INFINITY;let B=ie;B.x=Number.NEGATIVE_INFINITY,B.y=Number.NEGATIVE_INFINITY,B.z=Number.NEGATIVE_INFINITY;let U,_,M=0,W=0,j=0;for(_=0;_<4;++_){let t=M;U=R.getUint32(t,!0),t+=Pt;let e=r.toRadians(180*R.getFloat64(t,!0));t+=H,-1===tt(w,e)&&w.push(e);let n=r.toRadians(180*R.getFloat64(t,!0));t+=H,-1===tt(x,n)&&x.push(n),t+=2*H;let i=R.getInt32(t,!0);t+=mt,W+=i,i=R.getInt32(t,!0),j+=3*i,M+=U+Pt}let V=[],C=[],L=new Array(W),Y=new Array(W),O=new Array(W),D=h?new Array(W):[],X=b?new Array(W):[],Z=new Array(j),z=[],J=[],K=[],Q=[],q=0,et=0;for(M=0,_=0;_<4;++_){U=R.getUint32(M,!0),M+=Pt;let t=M,e=r.toRadians(180*R.getFloat64(M,!0));M+=H;let i=r.toRadians(180*R.getFloat64(M,!0));M+=H;let o=r.toRadians(180*R.getFloat64(M,!0)),a=.5*o;M+=H;let s=r.toRadians(180*R.getFloat64(M,!0)),l=.5*s;M+=H;let E=R.getInt32(M,!0);M+=mt;let f=R.getInt32(M,!0);M+=mt,M+=mt;let A=new Array(E);for(let t=0;t<E;++t){let E=e+R.getUint8(M++)*o;u.longitude=E;let f=i+R.getUint8(M++)*s;u.latitude=f;let H=R.getFloat32(M,!0);if(M+=ee,0!==H&&H<d&&(H*=-Math.pow(2,c)),H*=6371010,u.height=H,-1!==tt(w,E)||-1!==tt(x,f)){let e=tt(V,u,N);if(-1!==e){A[t]=C[e];continue}V.push(N.clone(u)),C.push(q)}A[t]=q,Math.abs(E-m)<a?z.push({index:q,cartographic:N.clone(u)}):Math.abs(E-p)<a?K.push({index:q,cartographic:N.clone(u)}):Math.abs(f-g)<l?J.push({index:q,cartographic:N.clone(u)}):Math.abs(f-I)<l&&Q.push({index:q,cartographic:N.clone(u)}),y=Math.min(H,y),F=Math.max(H,F),O[q]=H;let U=n.cartographicToCartesian(u);if(L[q]=U,h&&(D[q]=(lt.geodeticLatitudeToMercatorAngle(f)-T)*S),b){let t=n.geodeticSurfaceNormal(U);X[q]=t}$.multiplyByPoint(k,U,G),P.minimumByComponent(G,v,v),P.maximumByComponent(G,B,B);let _=(E-m)/(p-m);_=r.clamp(_,0,1);let W=(f-g)/(I-g);W=r.clamp(W,0,1),Y[q]=new wt(_,W),++q}let _=3*f;for(let t=0;t<_;++t,++et)Z[et]=A[R.getUint16(M,!0)],M+=te;if(U!==M-t)throw new Vt("Invalid terrain tile.")}L.length=q,Y.length=q,O.length=q,h&&(D.length=q),b&&(X.length=q);let nt=q,it=et,rt={hMin:y,lastBorderPoint:void 0,skirtHeight:l,toENU:k,ellipsoid:n,minimum:v,maximum:B};z.sort((function(t,e){return e.cartographic.latitude-t.cartographic.latitude})),J.sort((function(t,e){return t.cartographic.longitude-e.cartographic.longitude})),K.sort((function(t,e){return t.cartographic.latitude-e.cartographic.latitude})),Q.sort((function(t,e){return e.cartographic.longitude-t.cartographic.longitude}));let ot=1e-5;if(gt(L,O,Y,D,X,Z,rt,z,-ot*E,!0,-ot*f),gt(L,O,Y,D,X,Z,rt,J,-ot*f,!1),gt(L,O,Y,D,X,Z,rt,K,ot*E,!0,ot*f),gt(L,O,Y,D,X,Z,rt,Q,ot*f,!1),z.length>0&&Q.length>0){let t=z[0].index,e=nt,n=Q[Q.length-1].index,i=L.length-1;Z.push(n,i,e,e,t,n)}W=L.length;let at,ut=Lt.fromPoints(L);ht(i)&&(at=Dt.fromRectangle(i,y,F,n));let st=new Gt(n).computeHorizonCullingPointPossiblyUnderEllipsoid(e,L,y),ct=new qt(v,B,e),dt=new Xt(e,ct,rt.hMin,F,A,!1,h,b,a,s),pt=new Float32Array(W*dt.stride),It=0;for(let t=0;t<W;++t)It=dt.encode(pt,It,L[t],Y[t],O[t],void 0,D[t],X[t]);let Et=z.map((function(t){return t.index})).reverse(),ft=J.map((function(t){return t.index})).reverse(),Nt=K.map((function(t){return t.index})).reverse(),Tt=Q.map((function(t){return t.index})).reverse();return ft.unshift(Nt[Nt.length-1]),ft.push(Et[0]),Tt.unshift(Et[Et.length-1]),Tt.push(Nt[0]),{vertices:pt,indices:new Uint16Array(Z),maximumHeight:F,minimumHeight:y,encoding:dt,boundingSphere3D:ut,orientedBoundingBox:at,occludeePointInScaledSpace:st,vertexCountWithoutSkirts:nt,indexCountWithoutSkirts:it,westIndicesSouthToNorth:Et,southIndicesEastToWest:ft,eastIndicesNorthToSouth:Nt,northIndicesWestToEast:Tt}}function gt(t,e,n,i,o,a,s,l,h,c,d){let m=l.length;for(let g=0;g<m;++g){let p=l[g],I=p.cartographic,E=p.index,f=t.length,T=I.longitude,S=I.latitude;S=r.clamp(S,-r.PI_OVER_TWO,r.PI_OVER_TWO);let x=I.height-s.skirtHeight;s.hMin=Math.min(s.hMin,x),N.fromRadians(T,S,x,u),c&&(u.longitude+=h),c?g===m-1?u.latitude+=d:0===g&&(u.latitude-=d):u.latitude+=h;let w=s.ellipsoid.cartographicToCartesian(u);t.push(w),e.push(x),n.push(wt.clone(n[E])),i.length>0&&i.push(i[E]),o.length>0&&o.push(o[E]),$.multiplyByPoint(s.toENU,w,G);let A=s.minimum,k=s.maximum;P.minimumByComponent(G,A,A),P.maximumByComponent(G,k,k);let b=s.lastBorderPoint;if(ht(b)){let t=b.index;a.push(t,f-1,f,f,E,t)}s.lastBorderPoint=p}}var Ae=kt(oe);export{Ae as default};