/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{a as e,n as i}from"../../../../chunks/vec32.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Tiles3DTarget as t}from"../i3s/Intersector.js";import{ElevationRange as s}from"../../support/ElevationRange.js";import{IntersectorResult as r}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as o,computeInvDir as l,intersectAabbInvDir as a}from"../../webgl-engine/lib/RayIntersections.js";class c{constructor(e){this.layerView=e,this.type=8,this.slicePlaneEnabled=!1,this.isGround=!0,this.layerViewUid=e.uid}intersect(s,c,d,m,p,f){if(s.options.filteredLayerViewUids.includes(this.layerView.uid))return;const{results:g,tolerance:h}=s,w=2===s.options.store,{componentObjectCollection:b}=this.layerView.view.stage.renderView,y=new o(h,f,s.options.normalRequired),V=l(d,m,u),R=e(n(),m,d),j=i(n(),R),v=(e,i,n)=>{if(i>=0){if(null!=c&&!c(d,m,i))return;const e=e=>{const s=new t(this.layerView.layer.uid);e.set(this.type,s,i,n)};if(this.isGround&&(null==g.ground.distance||i<g.ground.distance)&&e(g.ground),s.options.isFiltered)return;if((null==g.min.distance||i<g.min.distance)&&e(g.min),(null==g.max.distance||i>g.max.distance)&&e(g.max),w){const i=new r(s.ray);e(i),s.results.all.push(i)}}};this.layerView.forEachVisibleTile(e=>{if(!e.boundingVolumeIntersectsRay(d,j))return;const{componentObjects:i}=e;for(const n of i)a(n.aabbInWorldCoordinates,d,V,0)&&b.intersect(n,d,m,null,y,v)})}getElevationRange(e){let i=null;return this.layerView.forEachVisibleTile(n=>{i?.contains(n.elevationRange)||n.boundingVolumeIntersectsSphere(e)&&(i||(i=new s),i.expandElevationRange(n.elevationRange))}),i||(i=new s(0,0)),i}}const u=n();export{c as Tiles3DIntersectionHandler};
