/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../chunks/_rollupPluginBabelHelpers","../../../core/has","../../../core/maybe","../../../core/libs/rbush/PooledRBush","./georeference"],(function(e,t,n,r,o){"use strict";let s=function(){function s(){}var i=s.prototype;return i.createIndex=function(){var t=e._asyncToGenerator((function*(e,t){const o=new Array;if(!e.vertexAttributes||!e.vertexAttributes.position)return new r.PooledRBush;const s=this._createMeshData(e),a=n.isSome(t)?yield t.invoke("createIndexThread",s,{transferList:o}):this.createIndexThread(s).result;return this._createPooledRBush().fromJSON(a)}));function o(e,n){return t.apply(this,arguments)}return o}(),i.createIndexThread=function(e){const t=new Float64Array(e.position),n=this._createPooledRBush();return e.components?this._createIndexComponentsThread(n,t,e.components.map((e=>new Uint32Array(e)))):this._createIndexAllThread(n,t)},i._createIndexAllThread=function(e,t){const n=new Array(t.length/9);let r=0;for(let o=0;o<t.length;o+=9)n[r++]=a(t,o+0,o+3,o+6);return e.load(n),{result:e.toJSON()}},i._createIndexComponentsThread=function(e,t,n){let r=0;for(const a of n)r+=a.length/3;const o=new Array(r);let s=0;for(const i of n)for(let e=0;e<i.length;e+=3)o[s++]=a(t,3*i[e+0],3*i[e+1],3*i[e+2]);return e.load(o),{result:e.toJSON()}},i._createMeshData=function(e){const t=(e.transform?o.georeferenceApplyTransform({position:e.vertexAttributes.position,normal:null,tangent:null},e.transform,e.spatialReference).position:e.vertexAttributes.position).buffer;return!e.components||e.components.some((e=>!e.faces))?{position:t}:{position:t,components:e.components.map((e=>e.faces))}},i._createPooledRBush=function(){return new r.PooledRBush(9,t("esri-csp-restrictions")?e=>e:[".minX",".minY",".maxX",".maxY"])},s}();function a(e,t,n,r){return{minX:Math.min(e[t+0],e[n+0],e[r+0]),maxX:Math.max(e[t+0],e[n+0],e[r+0]),minY:Math.min(e[t+1],e[n+1],e[r+1]),maxY:Math.max(e[t+1],e[n+1],e[r+1]),p0:[e[t+0],e[t+1],e[t+2]],p1:[e[n+0],e[n+1],e[n+2]],p2:[e[r+0],e[r+1],e[r+2]]}}return s}));
