/**
 * @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 R}from"./chunk-XHJOIQBC.js";import{a as It}from"./chunk-JQWRUZSV.js";import{a as M}from"./chunk-VEZ5ALJU.js";import{a as bt}from"./chunk-FG53NUCJ.js";import"./chunk-5ONJK4IB.js";import"./chunk-6IAPD5DZ.js";import"./chunk-354SKS6C.js";import"./chunk-H5GL2A6Z.js";import{a as W}from"./chunk-UGB43LJM.js";import"./chunk-EWTFJ46X.js";import{i as z}from"./chunk-5IUXF6I3.js";import"./chunk-27UWHT4D.js";import{a as o,b as nt,d as j}from"./chunk-RFPX772U.js";import{a as et}from"./chunk-RAYRECQS.js";import"./chunk-2NAI7YQ3.js";import"./chunk-QE3ZUOZY.js";import"./chunk-6KLVDWWE.js";import"./chunk-6P5KAIBX.js";import{e as A}from"./chunk-4FSVUTPL.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 t=0;t<r;++t)M.pack(e[t],a,i),i+=M.packedLength;let s=n.length;a[i++]=s;for(let t=0;t<s;++t){let e=n[t];R.pack(e.color,a,i),i+=R.packedLength,a[i++]=e.offset,a[i++]=e.count;let r=e.batchIds,o=r.length;a[i++]=o;for(let t=0;t<o;++t)a[i++]=r[t]}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),l=kt,h=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=h.cartographicToCartesian(a,wt);o.pack(i,L,3*k)}let j=a.length,x=new Array(j),U=new Array(j),T=0,F=0;for(k=0;k<j;++k)x[k]=T,U[k]=F,T+=a[k],F+=i[k];let S=new Float32Array(3*b*2),B=new Uint16Array(2*b),O=new Uint32Array(U.length),P=new Uint32Array(i.length),C=[],J={};for(k=0;k<j;++k)w=f[k],A(J[w])?(J[w].positionLength+=a[k],J[w].indexLength+=i[k],J[w].batchIds.push(k)):J[w]={positionLength:a[k],indexLength:i[k],offset:0,indexOffset:0,batchIds:[k]};let D,G=0,H=0;for(w in J)if(J.hasOwnProperty(w)){D=J[w],D.offset=G,D.indexOffset=H;let t=2*D.positionLength,e=2*D.indexLength+6*D.positionLength;G+=t,H+=e,D.indexLength=e}let V=[];for(w in J)J.hasOwnProperty(w)&&(D=J[w],V.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=J[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 T=Number.POSITIVE_INFINITY,F=Number.NEGATIVE_INFINITY,R=Number.POSITIVE_INFINITY,W=Number.NEGATIVE_INFINITY;for(g=0;g<y;++g){let t=o.unpack(L,3*b+3*g,wt);h.scaleToGeodeticSurface(t,t);let n=h.cartesianToCartographic(t,Lt),a=n.latitude,i=n.longitude;T=Math.min(a,T),F=Math.max(a,F),R=Math.min(i,R),W=Math.max(i,W);let s=h.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,l,u),o.subtract(c,l,c),o.pack(u,S,e),o.pack(c,S,e+3),B[r]=E,B[r+1]=E,e+=6,r+=2}u=Mt,u.west=R,u.east=W,u.south=T,u.north=F,c[k]=M.fromRectangle(u,m,p,h);let G=D.indexOffset,H=U[k],V=i[k];for(O[k]=G,g=0;g<V;g+=3){let e=n[H+g]-b,r=n[H+g+1]-b,o=n[H+g+2]-b;C[G++]=2*e+t,C[G++]=2*r+t,C[G++]=2*o+t,C[G++]=2*o+1+t,C[G++]=2*r+1+t,C[G++]=2*e+1+t}for(g=0;g<y;++g){let e=g,n=(g+1)%y;C[G++]=2*e+1+t,C[G++]=2*n+t,C[G++]=2*e+t,C[G++]=2*e+1+t,C[G++]=2*n+1+t,C[G++]=2*n+t}D.offset+=2*y,D.indexOffset=G,P[k]=G-O[k]}C=W.createTypedArray(S.length/3,C);let Y=V.length;for(let t=0;t<Y;++t){let e=V[t].batchIds,n=0,r=e.length;for(let t=0;t<r;++t)n+=P[e[t]];V[t].count=n}let _=Ct(2===C.BYTES_PER_ELEMENT?W.UNSIGNED_SHORT:W.UNSIGNED_INT,c,V);return e.push(S.buffer,C.buffer,O.buffer,P.buffer,B.buffer,_.buffer),{positions:S.buffer,indices:C.buffer,indexOffsets:O.buffer,indexCounts:P.buffer,batchIds:B.buffer,packedBuffer:_.buffer}}var Jt=It(Rt);export{Jt as default};