/**
 * @license
 * Cesium - https://github.com/CesiumGS/cesium
 * Version 1.126
 *
 * 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-4RP6ACF6.js";import{a as kt}from"./chunk-BC3RBQRQ.js";import{a as lt}from"./chunk-TRWH7IZP.js";import{a as Dt}from"./chunk-REP6L7BH.js";import"./chunk-MNEOPOLK.js";import"./chunk-EP544XEE.js";import{a as qt}from"./chunk-MDIGQ5JT.js";import"./chunk-26PPBGHW.js";import"./chunk-FMJWH3RL.js";import{d as Lt}from"./chunk-E2NX4UJ2.js";import{b as $,g as Ot,h as zt}from"./chunk-JBPQP6LH.js";import"./chunk-NLPIV6OK.js";import{a as P,b as N,c as wt,d as Ht}from"./chunk-IIT3SHXK.js";import{a as r}from"./chunk-DLCTHPIV.js";import"./chunk-GMF7KJHC.js";import{a as Vt}from"./chunk-NYFH7JC3.js";import{a as Ut}from"./chunk-I2ICH2LD.js";import"./chunk-R6A52HT4.js";import{e as ht}from"./chunk-D32DZSEC.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,x,S=[g,I],w=[m,p],k=Ot.eastNorthUpToFixedFrame(e,n),R=$.inverseTransformation(k,re);h&&(T=lt.geodeticLatitudeToMercatorAngle(g),x=1/(lt.geodeticLatitudeToMercatorAngle(I)-T));let b=1!==a,A=new DataView(t),B=Number.POSITIVE_INFINITY,y=Number.NEGATIVE_INFINITY,M=ne;M.x=Number.POSITIVE_INFINITY,M.y=Number.POSITIVE_INFINITY,M.z=Number.POSITIVE_INFINITY;let F=ie;F.x=Number.NEGATIVE_INFINITY,F.y=Number.NEGATIVE_INFINITY,F.z=Number.NEGATIVE_INFINITY;let v,_,C=0,j=0,L=0;for(_=0;_<4;++_){let t=C;v=A.getUint32(t,!0),t+=Pt;let e=r.toRadians(180*A.getFloat64(t,!0));t+=H,-1===tt(w,e)&&w.push(e);let n=r.toRadians(180*A.getFloat64(t,!0));t+=H,-1===tt(S,n)&&S.push(n),t+=2*H;let i=A.getInt32(t,!0);t+=mt,j+=i,i=A.getInt32(t,!0),L+=3*i,C+=v+Pt}let W=[],O=[],U=new Array(j),V=new Array(j),Y=new Array(j),D=h?new Array(j):[],J=b?new Array(j):[],z=new Array(L),X=[],K=[],Q=[],q=[],Z=0,et=0;for(C=0,_=0;_<4;++_){v=A.getUint32(C,!0),C+=Pt;let t=C,e=r.toRadians(180*A.getFloat64(C,!0));C+=H;let i=r.toRadians(180*A.getFloat64(C,!0));C+=H;let o=r.toRadians(180*A.getFloat64(C,!0)),a=.5*o;C+=H;let s=r.toRadians(180*A.getFloat64(C,!0)),l=.5*s;C+=H;let E=A.getInt32(C,!0);C+=mt;let f=A.getInt32(C,!0);C+=mt,C+=mt;let k=new Array(E);for(let H=0;H<E;++H){let t=e+A.getUint8(C++)*o;u.longitude=t;let E=i+A.getUint8(C++)*s;u.latitude=E;let f=A.getFloat32(C,!0);if(C+=ee,0!==f&&f<d&&(f*=-Math.pow(2,c)),f*=6371010,u.height=f,-1!==tt(w,t)||-1!==tt(S,E)){let t=tt(W,u,N);if(-1!==t){k[H]=O[t];continue}W.push(N.clone(u)),O.push(Z)}k[H]=Z,Math.abs(t-m)<a?X.push({index:Z,cartographic:N.clone(u)}):Math.abs(t-p)<a?Q.push({index:Z,cartographic:N.clone(u)}):Math.abs(E-g)<l?K.push({index:Z,cartographic:N.clone(u)}):Math.abs(E-I)<l&&q.push({index:Z,cartographic:N.clone(u)}),B=Math.min(f,B),y=Math.max(f,y),Y[Z]=f;let v=n.cartographicToCartesian(u);if(U[Z]=v,h&&(D[Z]=(lt.geodeticLatitudeToMercatorAngle(E)-T)*x),b){let t=n.geodeticSurfaceNormal(v);J[Z]=t}$.multiplyByPoint(R,v,G),P.minimumByComponent(G,M,M),P.maximumByComponent(G,F,F);let _=(t-m)/(p-m);_=r.clamp(_,0,1);let j=(E-g)/(I-g);j=r.clamp(j,0,1),V[Z]=new wt(_,j),++Z}let _=3*f;for(let n=0;n<_;++n,++et)z[et]=k[A.getUint16(C,!0)],C+=te;if(v!==C-t)throw new Vt("Invalid terrain tile.")}U.length=Z,V.length=Z,Y.length=Z,h&&(D.length=Z),b&&(J.length=Z);let nt=Z,it=et,rt={hMin:B,lastBorderPoint:void 0,skirtHeight:l,toENU:R,ellipsoid:n,minimum:M,maximum:F};X.sort((function(t,e){return e.cartographic.latitude-t.cartographic.latitude})),K.sort((function(t,e){return t.cartographic.longitude-e.cartographic.longitude})),Q.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(U,Y,V,D,J,z,rt,X,-ot*E,!0,-ot*f),gt(U,Y,V,D,J,z,rt,K,-ot*f,!1),gt(U,Y,V,D,J,z,rt,Q,ot*E,!0,ot*f),gt(U,Y,V,D,J,z,rt,q,ot*f,!1),X.length>0&&q.length>0){let t=X[0].index,e=nt,n=q[q.length-1].index,i=U.length-1;z.push(n,i,e,e,t,n)}j=U.length;let at,ut=Lt.fromPoints(U);ht(i)&&(at=Dt.fromRectangle(i,B,y,n));let st=new Gt(n).computeHorizonCullingPointPossiblyUnderEllipsoid(e,U,B),ct=new qt(M,F,e),dt=new Xt(e,ct,rt.hMin,y,k,!1,h,b,a,s),pt=new Float32Array(j*dt.stride),It=0;for(let r=0;r<j;++r)It=dt.encode(pt,It,U[r],V[r],Y[r],void 0,D[r],J[r]);let Et=X.map((function(t){return t.index})).reverse(),ft=K.map((function(t){return t.index})).reverse(),Nt=Q.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:y,minimumHeight:B,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,x=I.latitude;x=r.clamp(x,-r.PI_OVER_TWO,r.PI_OVER_TWO);let S=I.height-s.skirtHeight;s.hMin=Math.min(s.hMin,S),N.fromRadians(T,x,S,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(S),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 H=s.minimum,k=s.maximum;P.minimumByComponent(G,H,H),P.maximumByComponent(G,k,k);let R=s.lastBorderPoint;if(ht(R)){let t=R.index;a.push(t,f-1,f,f,E,t)}s.lastBorderPoint=p}}var Ae=kt(oe);export{Ae as default};