/**
 * @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 R}from"./chunk-GKS4EDRQ.js";import{a as It}from"./chunk-BC3RBQRQ.js";import{a as M}from"./chunk-REP6L7BH.js";import{a as bt}from"./chunk-MNEOPOLK.js";import"./chunk-EP544XEE.js";import"./chunk-MDIGQ5JT.js";import"./chunk-26PPBGHW.js";import"./chunk-FMJWH3RL.js";import{a as W}from"./chunk-E25VRLIZ.js";import"./chunk-E2NX4UJ2.js";import{h as z}from"./chunk-JBPQP6LH.js";import"./chunk-NLPIV6OK.js";import{a as o,b as nt,d as j}from"./chunk-IIT3SHXK.js";import{a as et}from"./chunk-DLCTHPIV.js";import"./chunk-GMF7KJHC.js";import"./chunk-NYFH7JC3.js";import"./chunk-I2ICH2LD.js";import"./chunk-R6A52HT4.js";import{e as A}from"./chunk-D32DZSEC.js";var kt=new o,Bt=new j,Nt=new z,E={min:void 0,max:void 0,indexBytesPerElement:void 0};function Pt(t){let e=new Float64Array(t),n=0;E.indexBytesPerElement=e[n++],E.min=e[n++],E.max=e[n++],o.unpack(e,n,kt),n+=o.packedLength,j.unpack(e,n,Bt),n+=j.packedLength,z.unpack(e,n,Nt)}function Tt(t){let e=t.length,n=0;for(let r=0;r<e;++r)n+=R.packedLength+3+t[r].batchIds.length;return n}function Ct(t,e,n){let r=e.length,o=2+r*M.packedLength+1+Tt(n),a=new Float64Array(o),i=0;a[i++]=t,a[i++]=r;for(let f=0;f<r;++f)M.pack(e[f],a,i),i+=M.packedLength;let s=n.length;a[i++]=s;for(let f=0;f<s;++f){let t=n[f];R.pack(t.color,a,i),i+=R.packedLength,a[i++]=t.offset,a[i++]=t.count;let e=t.batchIds,r=e.length;a[i++]=r;for(let n=0;n<r;++n)a[i++]=e[n]}return a}var yt=32767,wt=new o,Ht=new o,St=new o,Ut=new o,Ft=new o,Lt=new nt,Mt=new z;function Rt(t,e){let n;Pt(t.packedBuffer),n=2===E.indexBytesPerElement?new Uint16Array(t.indices):new Uint32Array(t.indices);let r=new Uint16Array(t.positions),a=new Uint32Array(t.counts),i=new Uint32Array(t.indexCounts),s=new Uint32Array(t.batchIds),f=new Uint32Array(t.batchTableColors),c=new Array(a.length),h=kt,l=Bt,u=Nt,m=E.min,p=E.max,d=t.minimumHeights,I=t.maximumHeights;A(d)&&A(I)&&(d=new Float32Array(d),I=new Float32Array(I));let k,g,w,b=r.length/2,y=r.subarray(0,b),N=r.subarray(b,2*b);bt.zigZagDeltaDecode(y,N);let L=new Float64Array(3*b);for(k=0;k<b;++k){let t=y[k],e=N[k],n=et.lerp(u.west,u.east,t/yt),r=et.lerp(u.south,u.north,e/yt),a=nt.fromRadians(n,r,0,Lt),i=l.cartographicToCartesian(a,wt);o.pack(i,L,3*k)}let j=a.length,x=new Array(j),T=new Array(j),P=0,B=0;for(k=0;k<j;++k)x[k]=P,T[k]=B,P+=a[k],B+=i[k];let F=new Float32Array(3*b*2),H=new Uint16Array(2*b),S=new Uint32Array(T.length),U=new Uint32Array(i.length),O=[],C={};for(k=0;k<j;++k)w=f[k],A(C[w])?(C[w].positionLength+=a[k],C[w].indexLength+=i[k],C[w].batchIds.push(k)):C[w]={positionLength:a[k],indexLength:i[k],offset:0,indexOffset:0,batchIds:[k]};let D,G=0,J=0;for(w in C)if(C.hasOwnProperty(w)){D=C[w],D.offset=G,D.indexOffset=J;let t=2*D.positionLength,e=2*D.indexLength+6*D.positionLength;G+=t,J+=e,D.indexLength=e}let _=[];for(w in C)C.hasOwnProperty(w)&&(D=C[w],_.push({color:R.fromRgba(parseInt(w)),offset:D.indexOffset,count:D.indexLength,batchIds:D.batchIds}));for(k=0;k<j;++k){w=f[k],D=C[w];let t=D.offset,e=3*t,r=t,b=x[k],y=a[k],E=s[k],N=m,j=p;A(d)&&A(I)&&(N=d[k],j=I[k]);let P=Number.POSITIVE_INFINITY,R=Number.NEGATIVE_INFINITY,B=Number.POSITIVE_INFINITY,G=Number.NEGATIVE_INFINITY;for(g=0;g<y;++g){let t=o.unpack(L,3*b+3*g,wt);l.scaleToGeodeticSurface(t,t);let n=l.cartesianToCartographic(t,Lt),a=n.latitude,i=n.longitude;P=Math.min(a,P),R=Math.max(a,R),B=Math.min(i,B),G=Math.max(i,G);let s=l.geodeticSurfaceNormal(t,Ht),f=o.multiplyByScalar(s,N,St),c=o.add(t,f,Ut);f=o.multiplyByScalar(s,j,f);let u=o.add(t,f,Ft);o.subtract(u,h,u),o.subtract(c,h,c),o.pack(u,F,e),o.pack(c,F,e+3),H[r]=E,H[r+1]=E,e+=6,r+=2}u=Mt,u.west=B,u.east=G,u.south=P,u.north=R,c[k]=M.fromRectangle(u,m,p,l);let J=D.indexOffset,_=T[k],V=i[k];for(S[k]=J,g=0;g<V;g+=3){let e=n[_+g]-b,r=n[_+g+1]-b,o=n[_+g+2]-b;O[J++]=2*e+t,O[J++]=2*r+t,O[J++]=2*o+t,O[J++]=2*o+1+t,O[J++]=2*r+1+t,O[J++]=2*e+1+t}for(g=0;g<y;++g){let e=g,n=(g+1)%y;O[J++]=2*e+1+t,O[J++]=2*n+t,O[J++]=2*e+t,O[J++]=2*e+1+t,O[J++]=2*n+1+t,O[J++]=2*n+t}D.offset+=2*y,D.indexOffset=J,U[k]=J-S[k]}O=W.createTypedArray(F.length/3,O);let V=_.length;for(let o=0;o<V;++o){let t=_[o].batchIds,e=0,n=t.length;for(let r=0;r<n;++r)e+=U[t[r]];_[o].count=e}let v=2===O.BYTES_PER_ELEMENT?W.UNSIGNED_SHORT:W.UNSIGNED_INT,Y=Ct(v,c,_);return e.push(F.buffer,O.buffer,S.buffer,U.buffer,H.buffer,Y.buffer),{positions:F.buffer,indices:O.buffer,indexOffsets:S.buffer,indexCounts:U.buffer,batchIds:H.buffer,packedBuffer:Y.buffer}}var Jt=It(Rt);export{Jt as default};