/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{getScale as r}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{diameter as e}from"../../../../geometry/support/aaBoundingBox.js";import{isGaussianSplatLayer as n}from"../../../../layers/support/layerUtils.js";import{isGaussianSplatIntersectorResult as i,isPclIntersectorResult as l,isVoxelIntersectorResult as a,isI3sIntersectorResult as u}from"../../layers/i3s/Intersector.js";import{isOverlayIntersectorResult as o,isTerrainIntersectorResult as c}from"../../terrain/Intersector.js";import{isHUDIntersectorResult as s}from"./HUDIntersectorResult.js";import{isObjectIntersectorResult as g}from"./ObjectIntersectorResult.js";import{isLodIntersectorResult as p}from"./lodRendering/Intersector.js";function f(r,t){return g(r)||s(r)?b(r.target?.object,t):c(r)?t.map?.ground:r.target&&"layerViewUid"in r.target?b(r.target,t):null}function d(r,t){const e=m(r,t);return"graphic"===e?.type?e.graphic:null}function m(r,t,e={}){if(null==r)return null;if(g(r)||s(r))return y(r.target?.object,t,e);if(i(r))return w(U(r.target,t));if(l(r)){const t=r.target.createGraphic();return{type:"graphic",graphic:t,layer:t.layer}}if(a(r)){const t=r.target.createVoxelGraphic();return{type:"graphic",graphic:t,layer:t.layer}}return o(r)||p(r)?y(r.target,t,e):u(r)?h(r.target,t,e):null}function y(r,t,e){if(null==r?.graphicUid)return null;const n=b(r,t);if(null==n)return null;if(n===t.graphics)return null==t.graphicsView||"number"!=typeof r.graphicUid?null:t.graphicsView.getHit(r.graphicUid,e);const i=t.allLayerViews.find(r=>r.layer===n);return!i||i.suspended||null==r.graphicUid?null:"getHit"in i?i.getHit(r.graphicUid,e):null}function h(r,t,e){const n=b(r,t);if(null==n)return null;const i=t.allLayerViews.find(r=>r.layer===n);if(!i||i.suspended||!("getGraphicFromIntersectorTarget"in i))return null;const l=e.defer;return j(i.getGraphicFromIntersectorTarget(r,{defer:l?r=>l(async()=>j(await r())):void 0}))}function V(r,t){const e=b(r,t);if(null==e)return null;const n=t.allLayerViews.find(r=>r.layer===e);return n&&!n.suspended&&"getAABBFromIntersectorTarget"in n?n.getAABBFromIntersectorTarget(r):null}function j(r){return null!=r?{type:"graphic",graphic:r,layer:r.layer}:null}function w(r){return n(r)?{type:"layer",layer:r}:null}function U(r,t){const e=b(r,t);return null!=e&&"type"in e?e:null}function b(r,t){return null==r?.layerViewUid?null:null!=t.graphicsView&&r.layerViewUid===t.graphicsView.uid?t.graphics:t.allLayerViews.find(t=>t.uid===r.layerViewUid)?.layer}function I(t,n){if(g(t)||s(t))return t.target.object.boundingVolumeWorldSpace.bounds.radius;if(p(t)){r(x,t.transformation);const e=Math.max(x[0],x[1],x[2]);return t.target.baseBoundingSphere.radius*e}if(u(t)){const r=V(t.target,n);return r?.5*e(r):null}return null}function B(r){return!g(r)&&!s(r)&&(p(r)?r.target.numLodLevels>1:!!u(r))}const x=t();export{I as getIntersectedFeatureBSRadius,B as hasLod,d as toGraphic,m as toHit,f as toOwner};
