/**
 * @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 Ct,b as vt}from"./chunk-4RP6ACF6.js";import{a as Mt}from"./chunk-BC3RBQRQ.js";import{a as z}from"./chunk-TRWH7IZP.js";import"./chunk-MNEOPOLK.js";import{a as Wt}from"./chunk-MDIGQ5JT.js";import{a as X}from"./chunk-E25VRLIZ.js";import"./chunk-E2NX4UJ2.js";import{b as U,g as bt,h as At}from"./chunk-JBPQP6LH.js";import"./chunk-NLPIV6OK.js";import{a as P,b as wt,c as lt,d as pt}from"./chunk-IIT3SHXK.js";import{a as f}from"./chunk-DLCTHPIV.js";import"./chunk-GMF7KJHC.js";import"./chunk-NYFH7JC3.js";import"./chunk-I2ICH2LD.js";import{a as m}from"./chunk-R6A52HT4.js";import{e as w}from"./chunk-D32DZSEC.js";function T(){m.throwInstantiationError()}Object.defineProperties(T.prototype,{errorEvent:{get:m.throwInstantiationError},credit:{get:m.throwInstantiationError},tilingScheme:{get:m.throwInstantiationError},hasWaterMask:{get:m.throwInstantiationError},hasVertexNormals:{get:m.throwInstantiationError},availability:{get:m.throwInstantiationError}});var Ot=[];T.getRegularGridIndices=function(t,e){if(t*e>=f.FOUR_GIGABYTES)throw new m("The total number of vertices (width * height) must be less than 4,294,967,296.");let r=Ot[t];w(r)||(Ot[t]=r=[]);let n=r[e];return w(n)||(n=t*e<f.SIXTY_FOUR_KILOBYTES?r[e]=new Uint16Array((t-1)*(e-1)*6):r[e]=new Uint32Array((t-1)*(e-1)*6),Pt(t,e,n,0)),n};var Gt=[];T.getRegularGridIndicesAndEdgeIndices=function(t,e){if(t*e>=f.FOUR_GIGABYTES)throw new m("The total number of vertices (width * height) must be less than 4,294,967,296.");let r=Gt[t];w(r)||(Gt[t]=r=[]);let n=r[e];if(!w(n)){let i=T.getRegularGridIndices(t,e),o=Lt(t,e),a=o.westIndicesSouthToNorth,s=o.southIndicesEastToWest,h=o.eastIndicesNorthToSouth,u=o.northIndicesWestToEast;n=r[e]={indices:i,westIndicesSouthToNorth:a,southIndicesEastToWest:s,eastIndicesNorthToSouth:h,northIndicesWestToEast:u}}return n};var kt=[];function Lt(t,e){let r,n=new Array(e),i=new Array(t),o=new Array(e),a=new Array(t);for(r=0;r<t;++r)a[r]=r,i[r]=t*e-1-r;for(r=0;r<e;++r)o[r]=(r+1)*t-1,n[r]=(e-r-1)*t;return{westIndicesSouthToNorth:n,southIndicesEastToWest:i,eastIndicesNorthToSouth:o,northIndicesWestToEast:a}}function Pt(t,e,r,n){let i=0;for(let o=0;o<e-1;++o){for(let e=0;e<t-1;++e){let e=i,o=e+t,a=o+1,s=e+1;r[n++]=e,r[n++]=o,r[n++]=s,r[n++]=s,r[n++]=o,r[n++]=a,++i}++i}}function Z(t,e,r,n){let i=t[0],o=t.length;for(let a=1;a<o;++a){let o=t[a];r[n++]=i,r[n++]=o,r[n++]=e,r[n++]=e,r[n++]=o,r[n++]=e+1,i=o,++e}return n}T.getRegularGridAndSkirtIndicesAndEdgeIndices=function(t,e){if(t*e>=f.FOUR_GIGABYTES)throw new m("The total number of vertices (width * height) must be less than 4,294,967,296.");let r=kt[t];w(r)||(kt[t]=r=[]);let n=r[e];if(!w(n)){let i=t*e,o=(t-1)*(e-1)*6,a=2*t+2*e,s=6*Math.max(0,a-4),h=i+a,u=o+s,c=Lt(t,e),l=c.westIndicesSouthToNorth,I=c.southIndicesEastToWest,d=c.eastIndicesNorthToSouth,m=c.northIndicesWestToEast,g=X.createTypedArray(h,u);Pt(t,e,g,0),T.addSkirtIndices(l,I,d,m,i,g,o),n=r[e]={indices:g,westIndicesSouthToNorth:l,southIndicesEastToWest:I,eastIndicesNorthToSouth:d,northIndicesWestToEast:m,indexCountWithoutSkirts:o}}return n},T.addSkirtIndices=function(t,e,r,n,i,o,a){let s=i;a=Z(t,s,o,a),s+=t.length,a=Z(e,s,o,a),s+=e.length,a=Z(r,s,o,a),s+=r.length,Z(n,s,o,a)},T.heightmapTerrainQuality=.25,T.getEstimatedLevelZeroGeometricErrorForAHeightmap=function(t,e,r){return 2*t.maximumRadius*Math.PI*T.heightmapTerrainQuality/(e*r)},T.prototype.requestTileGeometry=m.throwInstantiationError,T.prototype.getLevelMaximumGeometricError=m.throwInstantiationError,T.prototype.getTileDataAvailable=m.throwInstantiationError,T.prototype.loadTileDataAvailability=m.throwInstantiationError;var Vt=T,ht=32767,D=new P,Xt=new P,Zt=new P,u=new wt,Y=new lt;function Jt(t,e){let r,n,i=t.quantizedVertices,o=i.length/3,a=t.octEncodedNormals,s=t.westIndices.length+t.eastIndices.length+t.southIndices.length+t.northIndices.length,h=t.includeWebMercatorT,c=t.exaggeration,l=t.exaggerationRelativeHeight,I=1!==c,d=At.clone(t.rectangle),m=d.west,T=d.south,g=d.east,p=d.north,N=pt.clone(t.ellipsoid),E=t.minimumHeight,y=t.maximumHeight,S=t.relativeToCenter,A=bt.eastNorthUpToFixedFrame(S,N),b=U.inverseTransformation(A,new U);h&&(r=z.geodeticLatitudeToMercatorAngle(T),n=1/(z.geodeticLatitudeToMercatorAngle(p)-r));let k=i.subarray(0,o),x=i.subarray(o,2*o),M=i.subarray(2*o,3*o),G=w(a),H=new Array(o),v=new Array(o),F=new Array(o),W=h?new Array(o):[],C=I?new Array(o):[],O=Xt;O.x=Number.POSITIVE_INFINITY,O.y=Number.POSITIVE_INFINITY,O.z=Number.POSITIVE_INFINITY;let V=Zt;V.x=Number.NEGATIVE_INFINITY,V.y=Number.NEGATIVE_INFINITY,V.z=Number.NEGATIVE_INFINITY;let _=Number.POSITIVE_INFINITY,j=Number.NEGATIVE_INFINITY,L=Number.POSITIVE_INFINITY,R=Number.NEGATIVE_INFINITY;for(let w=0;w<o;++w){let t=k[w],e=x[w],i=t/ht,o=e/ht,a=f.lerp(E,y,M[w]/ht);u.longitude=f.lerp(m,g,i),u.latitude=f.lerp(T,p,o),u.height=a,_=Math.min(u.longitude,_),j=Math.max(u.longitude,j),L=Math.min(u.latitude,L),R=Math.max(u.latitude,R);let s=N.cartographicToCartesian(u);H[w]=new lt(i,o),v[w]=a,F[w]=s,h&&(W[w]=(z.geodeticLatitudeToMercatorAngle(u.latitude)-r)*n),I&&(C[w]=N.geodeticSurfaceNormal(s)),U.multiplyByPoint(b,s,D),P.minimumByComponent(D,O,O),P.maximumByComponent(D,V,V)}let B,Z=tt(t.westIndices,(function(t,e){return H[t].y-H[e].y})),Q=tt(t.eastIndices,(function(t,e){return H[e].y-H[t].y})),K=tt(t.southIndices,(function(t,e){return H[e].x-H[t].x})),q=tt(t.northIndices,(function(t,e){return H[t].x-H[e].x}));E<0&&(B=new Ct(N).computeHorizonCullingPointPossiblyUnderEllipsoid(S,F,E));let et=E;et=Math.min(et,J(t.westIndices,t.westSkirtHeight,v,H,d,N,b,O,V)),et=Math.min(et,J(t.southIndices,t.southSkirtHeight,v,H,d,N,b,O,V)),et=Math.min(et,J(t.eastIndices,t.eastSkirtHeight,v,H,d,N,b,O,V)),et=Math.min(et,J(t.northIndices,t.northSkirtHeight,v,H,d,N,b,O,V));let rt=new Wt(O,V,S),nt=new vt(S,rt,et,y,A,G,h,I,c,l),it=nt.stride,ot=o*it+s*it,at=new Float32Array(ot),st=0;for(let u=0;u<o;++u){if(G){let t=2*u;Y.x=a[t],Y.y=a[t+1]}st=nt.encode(at,st,F[u],H[u],v[u],Y,W[u],C[u])}let ut=Math.max(0,2*(s-4)),ct=t.indices.length+3*ut,It=X.createTypedArray(o+s,ct);It.set(t.indices,0);let dt=1e-4,mt=(j-_)*dt,Tt=(R-L)*dt,gt=-mt,ft=0,wt=mt,Nt=0,Et=0,yt=Tt,St=0,kt=-Tt,Pt=o*it;return $(at,Pt,Z,nt,v,H,a,N,d,t.westSkirtHeight,r,n,gt,ft),Pt+=t.westIndices.length*it,$(at,Pt,K,nt,v,H,a,N,d,t.southSkirtHeight,r,n,St,kt),Pt+=t.southIndices.length*it,$(at,Pt,Q,nt,v,H,a,N,d,t.eastSkirtHeight,r,n,wt,Nt),Pt+=t.eastIndices.length*it,$(at,Pt,q,nt,v,H,a,N,d,t.northSkirtHeight,r,n,Et,yt),Vt.addSkirtIndices(Z,K,Q,q,o,It,t.indices.length),e.push(at.buffer,It.buffer),{vertices:at.buffer,indices:It.buffer,westIndicesSouthToNorth:Z,southIndicesEastToWest:K,eastIndicesNorthToSouth:Q,northIndicesWestToEast:q,vertexStride:it,center:S,minimumHeight:E,maximumHeight:y,occludeePointInScaledSpace:B,encoding:nt,indexCountWithoutSkirts:t.indices.length}}function J(t,e,r,n,i,o,a,s,h){let c=Number.POSITIVE_INFINITY,l=i.north,I=i.south,d=i.east,m=i.west;d<m&&(d+=f.TWO_PI);let T=t.length;for(let g=0;g<T;++g){let i=t[g],T=r[i],w=n[i];u.longitude=f.lerp(m,d,w.x),u.latitude=f.lerp(I,l,w.y),u.height=T-e;let p=o.cartographicToCartesian(u,D);U.multiplyByPoint(a,p,p),P.minimumByComponent(p,s,s),P.maximumByComponent(p,h,h),c=Math.min(c,u.height)}return c}function $(t,e,r,n,i,o,a,s,h,c,l,I,d,m){let T=w(a),g=h.north,p=h.south,N=h.east,E=h.west;N<E&&(N+=f.TWO_PI);let y=r.length;for(let w=0;w<y;++w){let h=r[w],y=i[h],S=o[h];u.longitude=f.lerp(E,N,S.x)+d,u.latitude=f.lerp(p,g,S.y)+m,u.height=y-c;let A,b,k=s.cartographicToCartesian(u,D);if(T){let t=2*h;Y.x=a[t],Y.y=a[t+1]}n.hasWebMercatorT&&(A=(z.geodeticLatitudeToMercatorAngle(u.latitude)-l)*I),n.hasGeodeticSurfaceNormals&&(b=s.geodeticSurfaceNormal(k)),e=n.encode(t,e,k,S,u.height,Y,A,b)}}function tt(t,e){let r;return"function"==typeof t.slice&&(r=t.slice(),"function"!=typeof r.sort&&(r=void 0)),w(r)||(r=Array.prototype.slice.call(t)),r.sort(e),r}var Se=Mt(Jt);export{Se as default};