/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/PooledArray","../../../../chunks/vec3","../../../../chunks/vec3f64","./Util"],(function(i,t,e,n,s){"use strict";let r=function(){function i(i,t,r,a){this.primitiveIndices=i,this._numIndexPerPrimitive=t,this.indices=r,this.position=a,this.center=n.create(),s.assert(i.length>=1),s.assert(r.length%this._numIndexPerPrimitive==0),s.assert(r.length>=i.length*this._numIndexPerPrimitive),s.assert(3===a.size||4===a.size);const{data:b,size:c}=a,o=i.length;let u=c*r[this._numIndexPerPrimitive*i[0]];h.clear(),h.push(u),this.bbMin=n.fromValues(b[u],b[u+1],b[u+2]),this.bbMax=n.clone(this.bbMin);for(let e=0;e<o;++e){const t=this._numIndexPerPrimitive*i[e];for(let i=0;i<this._numIndexPerPrimitive;++i){u=c*r[t+i],h.push(u);let e=b[u];this.bbMin[0]=Math.min(e,this.bbMin[0]),this.bbMax[0]=Math.max(e,this.bbMax[0]),e=b[u+1],this.bbMin[1]=Math.min(e,this.bbMin[1]),this.bbMax[1]=Math.max(e,this.bbMax[1]),e=b[u+2],this.bbMin[2]=Math.min(e,this.bbMin[2]),this.bbMax[2]=Math.max(e,this.bbMax[2])}}e.lerp(this.center,this.bbMin,this.bbMax,.5),this.radius=.5*Math.max(Math.max(this.bbMax[0]-this.bbMin[0],this.bbMax[1]-this.bbMin[1]),this.bbMax[2]-this.bbMin[2]);let l=this.radius*this.radius;for(let e=0;e<h.length;++e){u=h.getItemAt(e);const i=b[u]-this.center[0],t=b[u+1]-this.center[1],n=b[u+2]-this.center[2],s=i*i+t*t+n*n;if(s<=l)continue;const r=Math.sqrt(s),a=.5*(r-this.radius);this.radius=this.radius+a,l=this.radius*this.radius;const c=a/r;this.center[0]+=i*c,this.center[1]+=t*c,this.center[2]+=n*c}h.clear()}var t=i.prototype;return t.getCenter=function(){return this.center},t.getBSRadius=function(){return this.radius},t.getBBMin=function(){return this.bbMin},t.getBBMax=function(){return this.bbMax},t.getChildren=function(){if(this._children)return this._children;if(e.squaredDistance(this.bbMin,this.bbMax)>1){const t=e.lerp(n.create(),this.bbMin,this.bbMax,.5),s=this.primitiveIndices.length,r=new Uint8Array(s),h=new Array(8);for(let i=0;i<8;++i)h[i]=0;const{data:a,size:b}=this.position;for(let i=0;i<s;++i){let e=0;const n=this._numIndexPerPrimitive*this.primitiveIndices[i];let s=b*this.indices[n],c=a[s],o=a[s+1],u=a[s+2];for(let i=1;i<this._numIndexPerPrimitive;++i){s=b*this.indices[n+i];const t=a[s],e=a[s+1],r=a[s+2];t<c&&(c=t),e<o&&(o=e),r<u&&(u=r)}c<t[0]&&(e|=1),o<t[1]&&(e|=2),u<t[2]&&(e|=4),r[i]=e,++h[e]}let c=0;for(let i=0;i<8;++i)h[i]>0&&++c;if(c<2)return;const o=new Array(8);for(let i=0;i<8;++i)o[i]=h[i]>0?new Uint32Array(h[i]):void 0;for(let i=0;i<8;++i)h[i]=0;for(let i=0;i<s;++i){const t=r[i];o[t][h[t]++]=this.primitiveIndices[i]}this._children=new Array(8);for(let e=0;e<8;++e)void 0!==o[e]&&(this._children[e]=new i(o[e],this._numIndexPerPrimitive,this.indices,this.position))}return this._children},i.prune=function(){h.prune()},i}();const h=new t({deallocator:null});i.BoundingInfo=r,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
