/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import s from"../../../core/ObjectPool.js";import r from"../../../core/PooledArray.js";import{property as i,subclass as o}from"../../../core/accessorSupport/decorators.js";import{f as u}from"../../../chunks/vec42.js";import{create as n}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";class l{constructor(){this.extent=n(),this.minLevel=0,this.maxLevel=0,this.callback=null}}let a=class extends t{constructor(){super(...arguments),this._queries=new r({initialSize:10}),this._queriesInvPtr=0,this._queryQueue=new r({initialSize:30}),this._queryPool=new s(()=>new l)}queryVisibleLevelRange(e,t,s,r){const i=this._queryPool.acquire();u(i.extent,e),i.minLevel=t??-Number.MAX_VALUE,i.maxLevel=s??Number.MAX_VALUE,i.callback=r,this._queryQueue.push(i),this.notifyChange("updating")}get updating(){return 0!==this._queryQueue.length}prepare(){for(;this._queries.length<this._queries.data.length&&this._queryQueue.length>0;){const e=this._queryQueue.pop();this._queries.push(e)}this._queriesInvPtr=this._queries.length}process(){for(let e=0;e<this._queries.length;e++){const t=this._queries.data[e];this._queryPool.release(t),t.callback(e>=this._queriesInvPtr),t.callback=null}this._queries.clear(),this.notifyChange("updating")}queriesForTile(e){const t=e.level;let s=0;for(;s<this._queriesInvPtr;){const r=this._queries.data[s],i=r.extent;t>=r.minLevel&&t<=r.maxLevel&&i[0]<=e.extent[2]&&i[2]>=e.extent[0]&&i[1]<=e.extent[3]&&i[3]>=e.extent[1]?(this._queries.swapElements(s,this._queriesInvPtr-1),this._queriesInvPtr--):s++}}};e([i()],a.prototype,"updating",null),a=e([o("esri.views.3d.terrain.ScaleRangeQueries")],a);export{a as ScaleRangeQueries};
