/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{isSome as o}from"../../../../../core/arrayUtils.js";import{isAborted as n,throwIfAborted as t}from"../../../../../core/promiseUtils.js";import{create as e}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{empty as r,expandWithVec3 as i,center as s,diameter as c}from"../../../../../geometry/support/aaBoundingBox.js";import{LodComponentData as u}from"./LodComponentData.js";class a{static async create(e,r,i){const s=await Promise.allSettled(r.components.map(o=>e.controller.schedule(()=>new u(e,o.geometry),i))),c=s.map(o=>"fulfilled"===o.status?o.value:null).filter(o);if(n(i)||c.length!==s.length){c.forEach(o=>o.destroy()),t(i);for(const o of s)if("rejected"===o.status)throw o.reason}return new a(r.minScreenSpaceRadius,c)}constructor(o,n){this.minScreenSpaceRadius=o,this.components=n}destroy(){this.components.forEach(o=>o.destroy())}intersect(o,n,t,e,r,i,s){this.components.forEach(c=>c.intersect(o,n,t,e,r,i,this.boundingSphere,s))}get boundingBox(){if(null==this._boundingBox){const o=r();this.components.forEach(n=>{null!=n.boundingInfo&&(i(o,n.boundingInfo.bbMin),i(o,n.boundingInfo.bbMax))}),this._boundingBox=o}return this._boundingBox}get boundingSphere(){if(null==this._boundingSphere){const o=this.boundingBox,n=e();s(o,n),this._boundingSphere={center:n,radius:.5*c(o)}}return this._boundingSphere}get triangleCount(){return this.components.reduce((o,n)=>o+n.numTriangles,0)}}export{a as LodLevel};
