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