/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import t from"../../../core/PooledArray.js";import{isImageryTileLayerView as e}from"./terrainUtils.js";class n{constructor(){this._queue=new t,this.remove=()=>{}}get done(){return 0===this._queue.length&&(!this._last||this._last.leaf)}resetOne(t){this._queue.clear(),this._queue.push(t),this._last=void 0}reset(t=null){this._queue.clear(),null!=t&&this._queue.pushArray(t),this._last=void 0}skipSubtree(){this._last=void 0}next(){const t=this._last?.children;return t?.[0]&&this._queue.pushArray(t),this._last=this._queue.pop(),this._last}}class r{constructor(){this._q=new t}get done(){return 0===this._q.length}reset(t){if(this._q.clear(),null!=t){this._q.pushArray(t);for(let t=0;t<this._q.length;++t){const e=this._q.data[t];e.leaf||this._q.pushArray(e.children)}}}next(){return this._q.pop()}}function l(t,e,n=()=>!0){if(Array.isArray(t))for(let r=0;r<t.length;r++)i(t[r],e,n);else i(t,e,n)}function i(t,e,n=()=>!0){if(e(t),!t.leaf&&n(t))for(const r of t.children)i(r,e)}function s(t,e){const n=t.extent;return!(e.xmin>n[2]||e.ymin>n[3]||e.xmax<n[0]||e.ymax<n[1])}const u=1e-8;function o(t,e,n){const r=t.surface.tilingScheme.levels[t.level].scale;return!(e&&e>0&&r>e*(1+u))&&!(n&&n>0&&r<n*(1-u))}function c(t,e){if(null==e||e.destroyed)return!1;const n=a(e);return null!=n?.fullExtent&&(!!s(t,n.fullExtent)&&!!o(t,n.minScale,n.maxScale))}function a(t){return e(t)?{fullExtent:t.fullExtent,minScale:t.layer.minScale,maxScale:t.layer.maxScale}:t.layer}function f(t){return!e(t)&&t.layer&&"tilemapCache"in t.layer?t.layer.tilemapCache:null}function h(t,e){const n=t.lij,r=e.lij;return n[0]-r[0]||n[1]-r[1]||n[2]-r[2]}function p(t,e=null){return null==e||0===e.length?t.sort(_):t.sort((t,n)=>d(t,n,e))}function _(t,e){const n=t.screenDepth-e.screenDepth;if(0!==n)return n;const r=t.lij,l=e.lij;return r[0]-l[0]||r[1]-l[1]||r[2]-l[2]}function m(t,e){const n=t.screenDepth,r=e.screenDepth;return n<r?-1:n>r?1:h(t,e)}function d(t,e,n){return y(t,n)===y(e,n)?m(t,e):t?1:-1}function y(t,e){for(const n of e)if(t.intersectsExtent(n))return!0;return!1}function q(t,e){const n=t.distanceToPOI-e.distanceToPOI;if(0!==n)return n;const r=t.lij,l=e.lij;return r[0]-l[0]||r[1]-l[1]||r[2]-l[2]}function x(t,e){const n=t.length;for(let r=0;r<n;++r){t.at(r).updateDistanceToPOI(e)}t.sort(q)}function g(t,e,n){let r=1,l=0,i=0;for(;t!==e;)if(r*=.5,l*=.5,i*=.5,1&t.lij[2]&&(l+=.5),1&t.lij[1]||(i+=.5),null==(t=t.parent))throw new Error("tile was not a descendant of upsampleTile");n.init(e,l,i,r)}function j(t){for(let e=0;e<t.length;e++){const n=t[e],r=n.parent;if(r)for(let t=0;t<4;t++){const e=r.children[t];if(e&&e!==n)return!0}}return!1}function A(t,e){if(!t||!e||t[0]===e[0])return!1;const n=t[0]<e[0],r=n?t:e,l=n?e:t,i=1<<l[0]-r[0];return Math.floor(l[1]/i)===r[1]&&Math.floor(l[2]/i)===r[2]}function S(t,e){if(e<=t[0])return[[...t]];const n=1<<e-t[0],r=new Array,l=t[1]*n,i=t[2]*n;for(let s=0;s<n;++s)for(let t=0;t<n;++t)r.push([e,s+l,t+i]);return r}export{r as IteratorPostorder,n as IteratorPreorder,m as compareTiles,h as compareTilesByLij,d as compareTilesWithStencil,g as computeUpsampleInfo,S as descendantsAtLevel,c as fallsWithinLayerView,f as getTileMapCache,j as hasLoadableSiblings,p as sortTiles,x as sortTilesByPOI,A as tilesAreRelated,l as traverseTilesPreorder};
