/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import r from"../../../core/ObjectPool.js";import s from"../../../core/PooledArray.js";import{property as i,subclass as o}from"../../../core/accessorSupport/decorators.js";import{copy as u}from"../../../core/libs/gl-matrix-2/math/vec4.js";import{create as l}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";class n{constructor(){this.extent=l(),this.minLevel=0,this.maxLevel=0,this.callback=null}}let a=class extends t{constructor(){super(...arguments),this._queries=new s({initialSize:10}),this._queriesInvPtr=0,this._queryQueue=new s({initialSize:30}),this._queryPool=new r(()=>new n)}queryVisibleLevelRange(e,t,r,s){const i=this._queryPool.acquire();u(i.extent,e),i.minLevel=t??-Number.MAX_VALUE,i.maxLevel=r??Number.MAX_VALUE,i.callback=s,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 r=0;for(;r<this._queriesInvPtr;){const s=this._queries.data[r],i=s.extent;t>=s.minLevel&&t<=s.maxLevel&&i[0]<=e.extent[2]&&i[2]>=e.extent[0]&&i[1]<=e.extent[3]&&i[3]>=e.extent[1]?(this._queries.swapElements(r,this._queriesInvPtr-1),this._queriesInvPtr--):r++}}};e([i()],a.prototype,"updating",null),a=e([o("esri.views.3d.terrain.ScaleRangeQueries")],a);export{a as ScaleRangeQueries};
