/**
 * @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 sr,b as fr}from"./chunk-4RP6ACF6.js";import{a as tr}from"./chunk-BC3RBQRQ.js";import{a as Ue}from"./chunk-TRWH7IZP.js";import{a as ar}from"./chunk-REP6L7BH.js";import"./chunk-MNEOPOLK.js";import"./chunk-EP544XEE.js";import{a as nr}from"./chunk-MDIGQ5JT.js";import"./chunk-26PPBGHW.js";import"./chunk-FMJWH3RL.js";import{d as ir}from"./chunk-E2NX4UJ2.js";import{b as xe,g as rr,h as ae}from"./chunk-JBPQP6LH.js";import"./chunk-NLPIV6OK.js";import{a as ie,c as er,d as Ie}from"./chunk-IIT3SHXK.js";import{a as ge}from"./chunk-DLCTHPIV.js";import"./chunk-GMF7KJHC.js";import{a as He}from"./chunk-NYFH7JC3.js";import{a as Y}from"./chunk-I2ICH2LD.js";import{a as he}from"./chunk-R6A52HT4.js";import{c as Ir,d as xr,e as G}from"./chunk-D32DZSEC.js";var ur=Ir(((e,t)=>{/* Copyright 2015-2018 Esri. 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 @preserve */(function(){var e=function(){var e={defaultNoDataValue:-34027999387901484e22,decode:function(n,s){s=s||{};var l=s.encodedMaskData||null===s.encodedMaskData,o=a(n,s.inputOffset||0,l),f=null!==s.noDataValue?s.noDataValue:e.defaultNoDataValue,u=t(o,s.pixelType||Float32Array,s.encodedMaskData,f,s.returnMask),h={width:o.width,height:o.height,pixelData:u.resultPixels,minValue:u.minValue,maxValue:o.pixels.maxValue,noDataValue:f};return u.resultMask&&(h.maskData=u.resultMask),s.returnEncodedMask&&o.mask&&(h.encodedMaskData=o.mask.bitset?o.mask.bitset:null),s.returnFileInfo&&(h.fileInfo=i(o),s.computeUsedBitDepths&&(h.fileInfo.bitDepths=r(o))),h}},t=function(e,t,i,r,a){var s,l,o,f=0,u=e.pixels.numBlocksX,h=e.pixels.numBlocksY,c=Math.floor(e.width/u),m=Math.floor(e.height/h),d=2*e.maxZError,g=Number.MAX_VALUE;i=i||(e.mask?e.mask.bitset:null),l=new t(e.width*e.height),a&&i&&(o=new Uint8Array(e.width*e.height));for(var p,w,k=new Float32Array(c*m),x=0;x<=h;x++){var y=x!==h?m:e.height%h;if(0!==y)for(var I=0;I<=u;I++){var U=I!==u?c:e.width%u;if(0!==U){var b,v,T,M,A=x*e.width*m+I*c,V=e.width-U,D=e.pixels.blocks[f];if(D.encoding<2?(0===D.encoding?b=D.rawData:(n(D.stuffedData,D.bitsPerPixel,D.numValidPixels,D.offset,d,k,e.pixels.maxValue),b=k),v=0):T=2===D.encoding?0:D.offset,i)for(w=0;w<y;w++){for(7&A&&(M=i[A>>3],M<<=7&A),p=0;p<U;p++)7&A||(M=i[A>>3]),128&M?(o&&(o[A]=1),s=D.encoding<2?b[v++]:T,g=g>s?s:g,l[A++]=s):(o&&(o[A]=0),l[A++]=r),M<<=1;A+=V}else if(D.encoding<2)for(w=0;w<y;w++){for(p=0;p<U;p++)s=b[v++],g=g>s?s:g,l[A++]=s;A+=V}else for(g=g>T?T:g,w=0;w<y;w++){for(p=0;p<U;p++)l[A++]=T;A+=V}if(1===D.encoding&&v!==D.numValidPixels)throw"Block and Mask do not match";f++}}}return{resultPixels:l,resultMask:o,minValue:g}},i=function(e){return{fileIdentifierString:e.fileIdentifierString,fileVersion:e.fileVersion,imageType:e.imageType,height:e.height,width:e.width,maxZError:e.maxZError,eofOffset:e.eofOffset,mask:e.mask?{numBlocksX:e.mask.numBlocksX,numBlocksY:e.mask.numBlocksY,numBytes:e.mask.numBytes,maxValue:e.mask.maxValue}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,numBytes:e.pixels.numBytes,maxValue:e.pixels.maxValue,noDataValue:e.noDataValue}}},r=function(e){for(var t=e.pixels.numBlocksX*e.pixels.numBlocksY,i={},r=0;r<t;r++){var a=e.pixels.blocks[r];0===a.encoding?i.float32=!0:1===a.encoding?i[a.bitsPerPixel]=!0:i[0]=!0}return Object.keys(i)},a=function(e,t,i){var r={},a=new Uint8Array(e,t,10);if(r.fileIdentifierString=String.fromCharCode.apply(null,a),"CntZImage"!==r.fileIdentifierString.trim())throw"Unexpected file identifier string: "+r.fileIdentifierString;t+=10;var n=new DataView(e,t,24);if(r.fileVersion=n.getInt32(0,!0),r.imageType=n.getInt32(4,!0),r.height=n.getUint32(8,!0),r.width=n.getUint32(12,!0),r.maxZError=n.getFloat64(16,!0),t+=24,!i)if(n=new DataView(e,t,16),r.mask={},r.mask.numBlocksY=n.getUint32(0,!0),r.mask.numBlocksX=n.getUint32(4,!0),r.mask.numBytes=n.getUint32(8,!0),r.mask.maxValue=n.getFloat32(12,!0),t+=16,r.mask.numBytes>0){var s=new Uint8Array(Math.ceil(r.width*r.height/8));n=new DataView(e,t,r.mask.numBytes);var l=n.getInt16(0,!0),o=2,f=0;do{if(l>0)for(;l--;)s[f++]=n.getUint8(o++);else{var u=n.getUint8(o++);for(l=-l;l--;)s[f++]=u}l=n.getInt16(o,!0),o+=2}while(o<r.mask.numBytes);if(-32768!==l||f<s.length)throw"Unexpected end of mask RLE encoding";r.mask.bitset=s,t+=r.mask.numBytes}else r.mask.numBytes|r.mask.numBlocksY|r.mask.maxValue||(r.mask.bitset=new Uint8Array(Math.ceil(r.width*r.height/8)));n=new DataView(e,t,16),r.pixels={},r.pixels.numBlocksY=n.getUint32(0,!0),r.pixels.numBlocksX=n.getUint32(4,!0),r.pixels.numBytes=n.getUint32(8,!0),r.pixels.maxValue=n.getFloat32(12,!0),t+=16;var h=r.pixels.numBlocksX,c=r.pixels.numBlocksY,m=h+(r.width%h>0?1:0),d=c+(r.height%c>0?1:0);r.pixels.blocks=new Array(m*d);for(var g=0,p=0;p<d;p++)for(var w=0;w<m;w++){var k=0,x=e.byteLength-t;n=new DataView(e,t,Math.min(10,x));var y={};r.pixels.blocks[g++]=y;var I=n.getUint8(0);if(k++,y.encoding=63&I,y.encoding>3)throw"Invalid block encoding ("+y.encoding+")";if(2!==y.encoding){if(0!==I&&2!==I){if(I>>=6,y.offsetType=I,2===I)y.offset=n.getInt8(1),k++;else if(1===I)y.offset=n.getInt16(1,!0),k+=2;else{if(0!==I)throw"Invalid block offset type";y.offset=n.getFloat32(1,!0),k+=4}if(1===y.encoding)if(I=n.getUint8(k),k++,y.bitsPerPixel=63&I,I>>=6,y.numValidPixelsType=I,2===I)y.numValidPixels=n.getUint8(k),k++;else if(1===I)y.numValidPixels=n.getUint16(k,!0),k+=2;else{if(0!==I)throw"Invalid valid pixel count type";y.numValidPixels=n.getUint32(k,!0),k+=4}}var U,b;if(t+=k,3!==y.encoding)if(0===y.encoding){var v=(r.pixels.numBytes-1)/4;if(v!==Math.floor(v))throw"uncompressed block has invalid length";U=new ArrayBuffer(4*v),b=new Uint8Array(U),b.set(new Uint8Array(e,t,4*v));var T=new Float32Array(U);y.rawData=T,t+=4*v}else if(1===y.encoding){var M=Math.ceil(y.numValidPixels*y.bitsPerPixel/8),A=Math.ceil(M/4);U=new ArrayBuffer(4*A),b=new Uint8Array(U),b.set(new Uint8Array(e,t,M)),y.stuffedData=new Uint32Array(U),t+=M}}else t++}return r.eofOffset=t,r},n=function(e,t,i,r,a,n,s){var l,o,f,u=(1<<t)-1,h=0,c=0,m=Math.ceil((s-r)/a),d=4*e.length-Math.ceil(t*i/8);for(e[e.length-1]<<=8*d,l=0;l<i;l++){if(0===c&&(f=e[h++],c=32),c>=t)o=f>>>c-t&u,c-=t;else{var g=t-c;o=(f&u)<<g&u,f=e[h++],c=32-g,o+=f>>>c}n[l]=o<m?r+o*a:s}return n};return e}(),i=function(){"use strict";var e={unstuff:function(e,t,i,r,a,n,s,l){var o,f,u,h,c,m=(1<<i)-1,d=0,g=0,p=4*e.length-Math.ceil(i*r/8);if(e[e.length-1]<<=8*p,a)for(o=0;o<r;o++)0===g&&(u=e[d++],g=32),g>=i?(f=u>>>g-i&m,g-=i):(h=i-g,f=(u&m)<<h&m,u=e[d++],g=32-h,f+=u>>>g),t[o]=a[f];else for(c=Math.ceil((l-n)/s),o=0;o<r;o++)0===g&&(u=e[d++],g=32),g>=i?(f=u>>>g-i&m,g-=i):(h=i-g,f=(u&m)<<h&m,u=e[d++],g=32-h,f+=u>>>g),t[o]=f<c?n+f*s:l},unstuffLUT:function(e,t,i,r,a,n){var s,l=(1<<t)-1,o=0,f=0,u=0,h=0,c=0,m=[],d=4*e.length-Math.ceil(t*i/8);e[e.length-1]<<=8*d;var g=Math.ceil((n-r)/a);for(f=0;f<i;f++)0===h&&(s=e[o++],h=32),h>=t?(c=s>>>h-t&l,h-=t):(u=t-h,c=(s&l)<<u&l,s=e[o++],h=32-u,c+=s>>>h),m[f]=c<g?r+c*a:n;return m.unshift(r),m},unstuff2:function(e,t,i,r,a,n,s,l){var o,f,u,h,c=(1<<i)-1,m=0,d=0,g=0;if(a)for(o=0;o<r;o++)0===d&&(u=e[m++],d=32,g=0),d>=i?(f=u>>>g&c,d-=i,g+=i):(h=i-d,f=u>>>g&c,u=e[m++],d=32-h,f|=(u&(1<<h)-1)<<i-h,g=h),t[o]=a[f];else{var p=Math.ceil((l-n)/s);for(o=0;o<r;o++)0===d&&(u=e[m++],d=32,g=0),d>=i?(f=u>>>g&c,d-=i,g+=i):(h=i-d,f=u>>>g&c,u=e[m++],d=32-h,f|=(u&(1<<h)-1)<<i-h,g=h),t[o]=f<p?n+f*s:l}return t},unstuffLUT2:function(e,t,i,r,a,n){var s,l=(1<<t)-1,o=0,f=0,u=0,h=0,c=0,m=0,d=[],g=Math.ceil((n-r)/a);for(f=0;f<i;f++)0===h&&(s=e[o++],h=32,m=0),h>=t?(c=s>>>m&l,h-=t,m+=t):(u=t-h,c=s>>>m&l,s=e[o++],h=32-u,c|=(s&(1<<u)-1)<<t-u,m=u),d[f]=c<g?r+c*a:n;return d.unshift(r),d},originalUnstuff:function(e,t,i,r){var a,n,s,l,o=(1<<i)-1,f=0,u=0,h=4*e.length-Math.ceil(i*r/8);for(e[e.length-1]<<=8*h,a=0;a<r;a++)0===u&&(s=e[f++],u=32),u>=i?(n=s>>>u-i&o,u-=i):(l=i-u,n=(s&o)<<l&o,s=e[f++],u=32-l,n+=s>>>u),t[a]=n;return t},originalUnstuff2:function(e,t,i,r){var a,n,s,l,o=(1<<i)-1,f=0,u=0,h=0;for(a=0;a<r;a++)0===u&&(s=e[f++],u=32,h=0),u>=i?(n=s>>>h&o,u-=i,h+=i):(l=i-u,n=s>>>h&o,s=e[f++],u=32-l,n|=(s&(1<<l)-1)<<i-l,h=l),t[a]=n;return t}},t={HUFFMAN_LUT_BITS_MAX:12,computeChecksumFletcher32:function(e){for(var t=65535,i=65535,r=e.length,a=Math.floor(r/2),n=0;a;){var s=a>=359?359:a;a-=s;do{t+=e[n++]<<8,i+=t+=e[n++]}while(--s);t=(65535&t)+(t>>>16),i=(65535&i)+(i>>>16)}return 1&r&&(i+=t+=e[n]<<8),t=(65535&t)+(t>>>16),i=(65535&i)+(i>>>16),(i<<16|t)>>>0},readHeaderInfo:function(e,t){var i=t.ptr,r=new Uint8Array(e,i,6),a={};if(a.fileIdentifierString=String.fromCharCode.apply(null,r),0!==a.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+a.fileIdentifierString;i+=6;var n,s,l=new DataView(e,i,8),o=l.getInt32(0,!0);if(a.fileVersion=o,i+=4,o>=3&&(a.checksum=l.getUint32(4,!0),i+=4),l=new DataView(e,i,12),a.height=l.getUint32(0,!0),a.width=l.getUint32(4,!0),i+=8,o>=4?(a.numDims=l.getUint32(8,!0),i+=4):a.numDims=1,l=new DataView(e,i,40),a.numValidPixel=l.getUint32(0,!0),a.microBlockSize=l.getInt32(4,!0),a.blobSize=l.getInt32(8,!0),a.imageType=l.getInt32(12,!0),a.maxZError=l.getFloat64(16,!0),a.zMin=l.getFloat64(24,!0),a.zMax=l.getFloat64(32,!0),i+=40,t.headerInfo=a,t.ptr=i,o>=3&&(s=o>=4?52:48,n=this.computeChecksumFletcher32(new Uint8Array(e,i-s,a.blobSize-14)),n!==a.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var i=t.headerInfo,r=this.getDataTypeArray(i.imageType),a=i.numDims*this.getDataTypeSize(i.imageType),n=this.readSubArray(e,t.ptr,r,a),s=this.readSubArray(e,t.ptr+a,r,a);t.ptr+=2*a;var l,o=!0;for(l=0;l<i.numDims;l++)if(n[l]!==s[l]){o=!1;break}return i.minValues=n,i.maxValues=s,o},readSubArray:function(e,t,i,r){var a;if(i===Uint8Array)a=new Uint8Array(e,t,r);else{var n=new ArrayBuffer(r),s=new Uint8Array(n);s.set(new Uint8Array(e,t,r)),a=new i(n)}return a},readMask:function(e,t){var i,r,a=t.ptr,n=t.headerInfo,s=n.width*n.height,l=n.numValidPixel,o=new DataView(e,a,4),f={};if(f.numBytes=o.getUint32(0,!0),a+=4,(0===l||s===l)&&0!==f.numBytes)throw"invalid mask";if(0===l)i=new Uint8Array(Math.ceil(s/8)),f.bitset=i,r=new Uint8Array(s),t.pixels.resultMask=r,a+=f.numBytes;else if(f.numBytes>0){i=new Uint8Array(Math.ceil(s/8)),o=new DataView(e,a,f.numBytes);var u=o.getInt16(0,!0),h=2,c=0,m=0;do{if(u>0)for(;u--;)i[c++]=o.getUint8(h++);else for(m=o.getUint8(h++),u=-u;u--;)i[c++]=m;u=o.getInt16(h,!0),h+=2}while(h<f.numBytes);if(-32768!==u||c<i.length)throw"Unexpected end of mask RLE encoding";r=new Uint8Array(s);var d=0,g=0;for(g=0;g<s;g++)7&g?(d=i[g>>3],d<<=7&g):d=i[g>>3],128&d&&(r[g]=1);t.pixels.resultMask=r,f.bitset=i,a+=f.numBytes}return t.ptr=a,t.mask=f,!0},readDataOneSweep:function(e,i,r){var a,n=i.ptr,s=i.headerInfo,l=s.numDims,o=s.width*s.height,f=s.imageType,u=s.numValidPixel*t.getDataTypeSize(f)*l,h=i.pixels.resultMask;if(r===Uint8Array)a=new Uint8Array(e,n,u);else{var c=new ArrayBuffer(u),m=new Uint8Array(c);m.set(new Uint8Array(e,n,u)),a=new r(c)}if(a.length===o*l)i.pixels.resultPixels=a;else{i.pixels.resultPixels=new r(o*l);var d=0,g=0,p=0,w=0;if(l>1)for(p=0;p<l;p++)for(w=p*o,g=0;g<o;g++)h[g]&&(i.pixels.resultPixels[w+g]=a[d++]);else for(g=0;g<o;g++)h[g]&&(i.pixels.resultPixels[g]=a[d++])}return n+=u,i.ptr=n,!0},readHuffmanTree:function(e,r){var a=this.HUFFMAN_LUT_BITS_MAX,n=new DataView(e,r.ptr,16);r.ptr+=16;var s=n.getInt32(0,!0);if(s<2)throw"unsupported Huffman version";var l=n.getInt32(4,!0),o=n.getInt32(8,!0),f=n.getInt32(12,!0);if(o>=f)return!1;var u=new Uint32Array(f-o);t.decodeBits(e,r,u);var h,c,m,d,g=[];for(h=o;h<f;h++)c=h-(h<l?0:l),g[c]={first:u[h-o],second:null};var p=e.byteLength-r.ptr,w=Math.ceil(p/4),k=new ArrayBuffer(4*w),x=new Uint8Array(k);x.set(new Uint8Array(e,r.ptr,p));var y,I=new Uint32Array(k),U=0,b=0;for(y=I[0],h=o;h<f;h++)c=h-(h<l?0:l),d=g[c].first,d>0&&(g[c].second=y<<U>>>32-d,32-U>=d?(U+=d,32===U&&(U=0,b++,y=I[b])):(U+=d-32,b++,y=I[b],g[c].second|=y>>>32-U));var v=0,T=0,M=new i;for(h=0;h<g.length;h++)void 0!==g[h]&&(v=Math.max(v,g[h].first));T=v>=a?a:v,v>=30&&console.log("WARning, large NUM LUT BITS IS "+v);var A,V,D,B,S,P,E=[];for(h=o;h<f;h++)if(c=h-(h<l?0:l),d=g[c].first,d>0)if(A=[d,c],d<=T)for(V=g[c].second<<T-d,D=1<<T-d,m=0;m<D;m++)E[V|m]=A;else for(V=g[c].second,P=M,B=d-1;B>=0;B--)S=V>>>B&1,S?(P.right||(P.right=new i),P=P.right):(P.left||(P.left=new i),P=P.left),0===B&&!P.val&&(P.val=A[1]);return{decodeLut:E,numBitsLUTQick:T,numBitsLUT:v,tree:M,stuffedData:I,srcPtr:b,bitPos:U}},readHuffman:function(e,t,i){var r,a,n,s,l,o,f,u,h,c,m=t.headerInfo,d=m.numDims,g=t.headerInfo.height,p=t.headerInfo.width,w=p*g,k=this.readHuffmanTree(e,t),x=k.decodeLut,y=k.tree,I=k.stuffedData,U=k.srcPtr,b=k.bitPos,v=k.numBitsLUTQick,T=k.numBitsLUT,M=0===t.headerInfo.imageType?128:0,A=t.pixels.resultMask,V=0;b>0&&(U++,b=0);var D,B=I[U],S=1===t.encodeMode,P=new i(w*d),E=P;for(D=0;D<m.numDims;D++){if(d>1&&(E=new i(P.buffer,w*D,w),V=0),t.headerInfo.numValidPixel===p*g)for(h=0,f=0;f<g;f++)for(u=0;u<p;u++,h++){if(a=0,s=B<<b>>>32-v,l=s,32-b<v&&(s|=I[U+1]>>>64-b-v,l=s),x[l])a=x[l][1],b+=x[l][0];else for(s=B<<b>>>32-T,l=s,32-b<T&&(s|=I[U+1]>>>64-b-T,l=s),r=y,c=0;c<T;c++)if(o=s>>>T-c-1&1,r=o?r.right:r.left,!r.left&&!r.right){a=r.val,b=b+c+1;break}b>=32&&(b-=32,U++,B=I[U]),n=a-M,S?(n+=u>0?V:f>0?E[h-p]:V,n&=255,E[h]=n,V=n):E[h]=n}else for(h=0,f=0;f<g;f++)for(u=0;u<p;u++,h++)if(A[h]){if(a=0,s=B<<b>>>32-v,l=s,32-b<v&&(s|=I[U+1]>>>64-b-v,l=s),x[l])a=x[l][1],b+=x[l][0];else for(s=B<<b>>>32-T,l=s,32-b<T&&(s|=I[U+1]>>>64-b-T,l=s),r=y,c=0;c<T;c++)if(o=s>>>T-c-1&1,r=o?r.right:r.left,!r.left&&!r.right){a=r.val,b=b+c+1;break}b>=32&&(b-=32,U++,B=I[U]),n=a-M,S?(u>0&&A[h-1]?n+=V:f>0&&A[h-p]?n+=E[h-p]:n+=V,n&=255,E[h]=n,V=n):E[h]=n}t.ptr=t.ptr+4*(U+1)+(b>0?4:0)}t.pixels.resultPixels=P},decodeBits:function(t,i,r,a,n){var s=i.headerInfo,l=s.fileVersion,o=0,f=new DataView(t,i.ptr,5),u=f.getUint8(0);o++;var h=u>>6,c=0===h?4:3-h,m=(32&u)>0,d=31&u,g=0;if(1===c)g=f.getUint8(o),o++;else if(2===c)g=f.getUint16(o,!0),o+=2;else{if(4!==c)throw"Invalid valid pixel count type";g=f.getUint32(o,!0),o+=4}var p,w,k,x,y,I,U,b,v,T=2*s.maxZError,M=s.numDims>1?s.maxValues[n]:s.zMax;if(m){for(i.counter.lut++,b=f.getUint8(o),d,o++,x=Math.ceil((b-1)*d/8),y=Math.ceil(x/4),w=new ArrayBuffer(4*y),k=new Uint8Array(w),i.ptr+=o,k.set(new Uint8Array(t,i.ptr,x)),U=new Uint32Array(w),i.ptr+=x,v=0;b-1>>>v;)v++;x=Math.ceil(g*v/8),y=Math.ceil(x/4),w=new ArrayBuffer(4*y),k=new Uint8Array(w),k.set(new Uint8Array(t,i.ptr,x)),p=new Uint32Array(w),i.ptr+=x,I=l>=3?e.unstuffLUT2(U,d,b-1,a,T,M):e.unstuffLUT(U,d,b-1,a,T,M),l>=3?e.unstuff2(p,r,v,g,I):e.unstuff(p,r,v,g,I)}else i.counter.bitstuffer++,v=d,i.ptr+=o,v>0&&(x=Math.ceil(g*v/8),y=Math.ceil(x/4),w=new ArrayBuffer(4*y),k=new Uint8Array(w),k.set(new Uint8Array(t,i.ptr,x)),p=new Uint32Array(w),i.ptr+=x,l>=3?null==a?e.originalUnstuff2(p,r,v,g):e.unstuff2(p,r,v,g,!1,a,T,M):null==a?e.originalUnstuff(p,r,v,g):e.unstuff(p,r,v,g,!1,a,T,M))},readTiles:function(e,i,r){var a=i.headerInfo,n=a.width,s=a.height,l=a.microBlockSize,o=a.imageType,f=t.getDataTypeSize(o),u=Math.ceil(n/l),h=Math.ceil(s/l);i.pixels.numBlocksY=h,i.pixels.numBlocksX=u,i.pixels.ptr=0;var c,m,d,g,p,w,k,x,y,I=0,U=0,b=0,v=0,T=0,M=0,A=0,V=0,D=0,B=0,S=0,P=0,E=0,F=0,L=0,N=0,H=new r(l*l),C=s%l||l,O=n%l||l,R=a.numDims,Y=i.pixels.resultMask,z=i.pixels.resultPixels;for(b=0;b<h;b++)for(T=b!==h-1?l:C,v=0;v<u;v++)for(M=v!==u-1?l:O,S=b*n*l+v*l,P=n-M,y=0;y<R;y++){if(R>1&&(z=new r(i.pixels.resultPixels.buffer,n*s*y*f,n*s)),A=e.byteLength-i.ptr,c=new DataView(e,i.ptr,Math.min(10,A)),m={},N=0,V=c.getUint8(0),N++,D=V>>6&255,B=V>>2&15,B!==(v*l>>3&15))throw"integrity issue";if(w=3&V,w>3)throw i.ptr+=N,"Invalid block encoding ("+w+")";if(2!==w)if(0===w){if(i.counter.uncompressed++,i.ptr+=N,E=T*M*f,F=e.byteLength-i.ptr,E=E<F?E:F,d=new ArrayBuffer(E%f===0?E:E+f-E%f),g=new Uint8Array(d),g.set(new Uint8Array(e,i.ptr,E)),p=new r(d),L=0,Y)for(I=0;I<T;I++){for(U=0;U<M;U++)Y[S]&&(z[S]=p[L++]),S++;S+=P}else for(I=0;I<T;I++){for(U=0;U<M;U++)z[S++]=p[L++];S+=P}i.ptr+=L*f}else if(k=t.getDataTypeUsed(o,D),x=t.getOnePixel(m,N,k,c),N+=t.getDataTypeSize(k),3===w)if(i.ptr+=N,i.counter.constantoffset++,Y)for(I=0;I<T;I++){for(U=0;U<M;U++)Y[S]&&(z[S]=x),S++;S+=P}else for(I=0;I<T;I++){for(U=0;U<M;U++)z[S++]=x;S+=P}else if(i.ptr+=N,t.decodeBits(e,i,H,x,y),N=0,Y)for(I=0;I<T;I++){for(U=0;U<M;U++)Y[S]&&(z[S]=H[N++]),S++;S+=P}else for(I=0;I<T;I++){for(U=0;U<M;U++)z[S++]=H[N++];S+=P}else i.counter.constant++,i.ptr+=N}},formatFileInfo:function(e){return{fileIdentifierString:e.headerInfo.fileIdentifierString,fileVersion:e.headerInfo.fileVersion,imageType:e.headerInfo.imageType,height:e.headerInfo.height,width:e.headerInfo.width,numValidPixel:e.headerInfo.numValidPixel,microBlockSize:e.headerInfo.microBlockSize,blobSize:e.headerInfo.blobSize,maxZError:e.headerInfo.maxZError,pixelType:t.getPixelType(e.headerInfo.imageType),eofOffset:e.eofOffset,mask:e.mask?{numBytes:e.mask.numBytes}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,maxValue:e.headerInfo.zMax,minValue:e.headerInfo.zMin,noDataValue:e.noDataValue}}},constructConstantSurface:function(e){var t=e.headerInfo.zMax,i=e.headerInfo.numDims,r=e.headerInfo.height*e.headerInfo.width,a=r*i,n=0,s=0,l=0,o=e.pixels.resultMask;if(o)if(i>1)for(n=0;n<i;n++)for(l=n*r,s=0;s<r;s++)o[s]&&(e.pixels.resultPixels[l+s]=t);else for(s=0;s<r;s++)o[s]&&(e.pixels.resultPixels[s]=t);else if(e.pixels.resultPixels.fill)e.pixels.resultPixels.fill(t);else for(s=0;s<a;s++)e.pixels.resultPixels[s]=t},getDataTypeArray:function(e){var t;switch(e){case 0:t=Int8Array;break;case 1:t=Uint8Array;break;case 2:t=Int16Array;break;case 3:t=Uint16Array;break;case 4:t=Int32Array;break;case 5:t=Uint32Array;break;case 6:t=Float32Array;break;case 7:t=Float64Array;break;default:t=Float32Array}return t},getPixelType:function(e){var t;switch(e){case 0:t="S8";break;case 1:t="U8";break;case 2:t="S16";break;case 3:t="U16";break;case 4:t="S32";break;case 5:t="U32";break;case 6:t="F32";break;case 7:t="F64";break;default:t="F32"}return t},isValidPixelValue:function(e,t){if(null==t)return!1;var i;switch(e){case 0:i=t>=-128&&t<=127;break;case 1:i=t>=0&&t<=255;break;case 2:i=t>=-32768&&t<=32767;break;case 3:i=t>=0&&t<=65536;break;case 4:i=t>=-2147483648&&t<=2147483647;break;case 5:i=t>=0&&t<=4294967296;break;case 6:i=t>=-34027999387901484e22&&t<=34027999387901484e22;break;case 7:i=t>=5e-324&&t<=17976931348623157e292;break;default:i=!1}return i},getDataTypeSize:function(e){var t=0;switch(e){case 0:case 1:t=1;break;case 2:case 3:t=2;break;case 4:case 5:case 6:t=4;break;case 7:t=8;break;default:t=e}return t},getDataTypeUsed:function(e,t){var i=e;switch(e){case 2:case 4:i=e-t;break;case 3:case 5:i=e-2*t;break;case 6:i=0===t?e:1===t?2:1;break;case 7:i=0===t?e:e-2*t+1;break;default:i=e;break}return i},getOnePixel:function(e,t,i,r){var a=0;switch(i){case 0:a=r.getInt8(t);break;case 1:a=r.getUint8(t);break;case 2:a=r.getInt16(t,!0);break;case 3:a=r.getUint16(t,!0);break;case 4:a=r.getInt32(t,!0);break;case 5:a=r.getUInt32(t,!0);break;case 6:a=r.getFloat32(t,!0);break;case 7:a=r.getFloat64(t,!0);break;default:throw"the decoder does not understand this pixel type"}return a}},i=function(e,t,i){this.val=e,this.left=t,this.right=i},r={decode:function(e,i){i=i||{};var r=i.noDataValue,a=0,n={};if(n.ptr=i.inputOffset||0,n.pixels={},t.readHeaderInfo(e,n)){var s=n.headerInfo,l=s.fileVersion,o=t.getDataTypeArray(s.imageType);t.readMask(e,n),s.numValidPixel!==s.width*s.height&&!n.pixels.resultMask&&(n.pixels.resultMask=i.maskData);var f,u=s.width*s.height;if(n.pixels.resultPixels=new o(u*s.numDims),n.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0},0!==s.numValidPixel)if(s.zMax===s.zMin)t.constructConstantSurface(n);else if(l>=4&&t.checkMinMaxRanges(e,n))t.constructConstantSurface(n);else{var h=new DataView(e,n.ptr,2),c=h.getUint8(0);if(n.ptr++,c)t.readDataOneSweep(e,n,o);else if(l>1&&s.imageType<=1&&Math.abs(s.maxZError-.5)<1e-5){var m=h.getUint8(1);if(n.ptr++,n.encodeMode=m,m>2||l<4&&m>1)throw"Invalid Huffman flag "+m;m?t.readHuffman(e,n,o):t.readTiles(e,n,o)}else t.readTiles(e,n,o)}n.eofOffset=n.ptr,i.inputOffset?(f=n.headerInfo.blobSize+i.inputOffset-n.ptr,Math.abs(f)>=1&&(n.eofOffset=i.inputOffset+n.headerInfo.blobSize)):(f=n.headerInfo.blobSize-n.ptr,Math.abs(f)>=1&&(n.eofOffset=n.headerInfo.blobSize));var d={width:s.width,height:s.height,pixelData:n.pixels.resultPixels,minValue:s.zMin,maxValue:s.zMax,validPixelCount:s.numValidPixel,dimCount:s.numDims,dimStats:{minValues:s.minValues,maxValues:s.maxValues},maskData:n.pixels.resultMask};if(n.pixels.resultMask&&t.isValidPixelValue(s.imageType,r)){var g=n.pixels.resultMask;for(a=0;a<u;a++)g[a]||(d.pixelData[a]=r);d.noDataValue=r}return n.noDataValue=r,i.returnFileInfo&&(d.fileInfo=t.formatFileInfo(n)),d}},getBandCount:function(e){for(var i=0,r=0,a={ptr:0,pixels:{}};r<e.byteLength-58;)t.readHeaderInfo(e,a),r+=a.headerInfo.blobSize,i++,a.ptr=r;return i}};return r}(),r=function(){var e=new ArrayBuffer(4),t=new Uint8Array(e),i=new Uint32Array(e);return i[0]=1,1===t[0]}(),a={decode:function(t,a){if(!r)throw"Big endian system is not supported.";a=a||{};var n,s,l,o,f,u=a.inputOffset||0,h=new Uint8Array(t,u,10),c=String.fromCharCode.apply(null,h);if("CntZImage"===c.trim())n=e,s=1;else{if("Lerc2"!==c.substring(0,5))throw"Unexpected file identifier string: "+c;n=i,s=2}for(var m,d,g,p=0,w=t.byteLength-10,k=[],x={width:0,height:0,pixels:[],pixelType:a.pixelType,mask:null,statistics:[]};u<w;){var y=n.decode(t,{inputOffset:u,encodedMaskData:m,maskData:g,returnMask:0===p,returnEncodedMask:0===p,returnFileInfo:!0,pixelType:a.pixelType||null,noDataValue:a.noDataValue||null});u=y.fileInfo.eofOffset,0===p&&(m=y.encodedMaskData,g=y.maskData,x.width=y.width,x.height=y.height,x.dimCount=y.dimCount||1,x.pixelType=y.pixelType||y.fileInfo.pixelType,x.mask=y.maskData),s>1&&y.fileInfo.mask&&y.fileInfo.mask.numBytes>0&&k.push(y.maskData),p++,x.pixels.push(y.pixelData),x.statistics.push({minValue:y.minValue,maxValue:y.maxValue,noDataValue:y.noDataValue,dimStats:y.dimStats})}if(s>1&&k.length>1){for(f=x.width*x.height,x.bandMasks=k,g=new Uint8Array(f),g.set(k[0]),l=1;l<k.length;l++)for(d=k[l],o=0;o<f;o++)g[o]=g[o]&d[o];x.maskData=g}return x}};"function"==typeof define&&define.amd?define([],(function(){return a})):typeof t<"u"&&t.exports?t.exports=a:this.Lerc=a})()})),Ur={NONE:0,LERC:1},or=Object.freeze(Ur),Q={};Q.DEFAULT_STRUCTURE=Object.freeze({heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:256,isBigEndian:!1});var Ye=new ie,Tr=new xe,kr=new ie,yr=new ie;Q.computeVertices=function(e){if(!G(e)||!G(e.heightmap))throw new he("options.heightmap is required.");if(!G(e.width)||!G(e.height))throw new he("options.width and options.height are required.");if(!G(e.nativeRectangle))throw new he("options.nativeRectangle is required.");if(!G(e.skirtHeight))throw new he("options.skirtHeight is required.");let t,i,r,a,n=Math.cos,s=Math.sin,l=Math.sqrt,o=Math.atan,f=Math.exp,u=ge.PI_OVER_TWO,h=ge.toRadians,c=e.heightmap,m=e.width,d=e.height,g=e.skirtHeight,p=g>0,w=Y(e.isGeographic,!0),k=Y(e.ellipsoid,Ie.default),x=1/k.maximumRadius,y=ae.clone(e.nativeRectangle),I=ae.clone(e.rectangle);G(I)?(t=I.west,i=I.south,r=I.east,a=I.north):w?(t=h(y.west),i=h(y.south),r=h(y.east),a=h(y.north)):(t=y.west*x,i=u-2*o(f(-y.south*x)),r=y.east*x,a=u-2*o(f(-y.north*x)));let U=e.relativeToCenter,b=G(U);U=b?U:ie.ZERO;let v=Y(e.includeWebMercatorT,!1),T=Y(e.exaggeration,1),M=Y(e.exaggerationRelativeHeight,0),A=1!==T,V=Y(e.structure,Q.DEFAULT_STRUCTURE),D=Y(V.heightScale,Q.DEFAULT_STRUCTURE.heightScale),B=Y(V.heightOffset,Q.DEFAULT_STRUCTURE.heightOffset),S=Y(V.elementsPerHeight,Q.DEFAULT_STRUCTURE.elementsPerHeight),P=Y(V.stride,Q.DEFAULT_STRUCTURE.stride),E=Y(V.elementMultiplier,Q.DEFAULT_STRUCTURE.elementMultiplier),F=Y(V.isBigEndian,Q.DEFAULT_STRUCTURE.isBigEndian),L=ae.computeWidth(y),N=ae.computeHeight(y),H=L/(m-1),C=N/(d-1);w||(L*=x,N*=x);let O,R,z=k.radiiSquared,_=z.x,j=z.y,X=z.z,Z=65536,W=-65536,q=rr.eastNorthUpToFixedFrame(U,k),J=xe.inverseTransformation(q,Tr);v&&(O=Ue.geodeticLatitudeToMercatorAngle(i),R=1/(Ue.geodeticLatitudeToMercatorAngle(a)-O));let K=kr;K.x=Number.POSITIVE_INFINITY,K.y=Number.POSITIVE_INFINITY,K.z=Number.POSITIVE_INFINITY;let $=yr;$.x=Number.NEGATIVE_INFINITY,$.y=Number.NEGATIVE_INFINITY,$.z=Number.NEGATIVE_INFINITY;let ee=Number.POSITIVE_INFINITY,te=m*d,re=g>0?2*m+2*d:0,ne=te+re,se=new Array(ne),le=new Array(ne),oe=new Array(ne),fe=v?new Array(ne):[],ue=A?new Array(ne):[],ce=0,me=d,de=0,pe=m;p&&(--ce,++me,--de,++pe);let we=1e-5;for(let Y=ce;Y<me;++Y){let e=Y;e<0&&(e=0),e>=d&&(e=d-1);let p=y.north-C*e;p=w?h(p):u-2*o(f(-p*x));let I=(p-i)/(a-i);I=ge.clamp(I,0,1);let U=Y===ce,b=Y===me-1;g>0&&(U?p+=we*N:b&&(p-=we*N));let T,M=n(p),V=s(p),z=X*V;v&&(T=(Ue.geodeticLatitudeToMercatorAngle(p)-O)*R);for(let i=de;i<pe;++i){let a=i;a<0&&(a=0),a>=m&&(a=m-1);let o,f=e*(m*P)+a*P;if(1===S)o=c[f];else{let e;if(o=0,F)for(e=0;e<S;++e)o=o*E+c[f+e];else for(e=S-1;e>=0;--e)o=o*E+c[f+e]}o=o*D+B,W=Math.max(W,o),Z=Math.min(Z,o);let u=y.west+H*a;w?u=h(u):u*=x;let p=(u-t)/(r-t);p=ge.clamp(p,0,1);let N=e*m+a;if(g>0){let t=i===de,r=i===pe-1,n=U||b||t||r;if((U||b)&&(t||r))continue;n&&(o-=g,t?(N=te+(d-e-1),u-=we*L):b?N=te+d+(m-a-1):r?(N=te+d+m+e,u+=we*L):U&&(N=te+d+m+d+a))}let C=M*n(u),O=M*s(u),R=_*C,Y=j*O,X=1/l(R*C+Y*O+z*V),G=R*X,Q=Y*X,q=z*X,re=new ie;re.x=G+C*o,re.y=Q+O*o,re.z=q+V*o,xe.multiplyByPoint(J,re,Ye),ie.minimumByComponent(Ye,K,K),ie.maximumByComponent(Ye,$,$),ee=Math.min(ee,o),se[N]=re,oe[N]=new er(p,I),le[N]=o,v&&(fe[N]=T),A&&(ue[N]=k.geodeticSurfaceNormal(re))}}let ke,ye,be=ir.fromPoints(se);G(I)&&(ke=ar.fromRectangle(I,Z,W,k)),b&&(ye=new sr(k).computeHorizonCullingPointPossiblyUnderEllipsoid(U,se,Z));let ve=new nr(K,$,U),Te=new fr(U,ve,ee,W,q,!1,v,A,T,M),Me=new Float32Array(ne*Te.stride),Ae=0;for(let Y=0;Y<ne;++Y)Ae=Te.encode(Me,Ae,se[Y],oe[Y],le[Y],void 0,fe[Y],ue[Y]);return{vertices:Me,maximumHeight:W,minimumHeight:Z,encoding:Te,boundingSphere3D:be,orientedBoundingBox:ke,occludeePointInScaledSpace:ye}};var lr=Q,cr=xr(ur(),1);function Mr(e,t){if(e.encoding===or.LERC){let t;try{t=cr.default.decode(e.heightmap)}catch(a){throw new He(a)}if(t.statistics[0].minValue===Number.MAX_VALUE)throw new He("Invalid tile data");e.heightmap=t.pixels[0],e.width=t.width,e.height=t.height}e.ellipsoid=Ie.clone(e.ellipsoid),e.rectangle=ae.clone(e.rectangle);let i=lr.computeVertices(e),r=i.vertices;return t.push(r.buffer),{vertices:r.buffer,numberOfAttributes:i.encoding.stride,minimumHeight:i.minimumHeight,maximumHeight:i.maximumHeight,gridWidth:e.width,gridHeight:e.height,boundingSphere3D:i.boundingSphere3D,orientedBoundingBox:i.orientedBoundingBox,occludeePointInScaledSpace:i.occludeePointInScaledSpace,encoding:i.encoding,westIndicesSouthToNorth:i.westIndicesSouthToNorth,southIndicesEastToWest:i.southIndicesEastToWest,eastIndicesNorthToSouth:i.eastIndicesNorthToSouth,northIndicesWestToEast:i.northIndicesWestToEast}}var Pr=tr(Mr);export{Pr as default};