/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import e from"../../../../analysis/LineOfSightAnalysisObserver.js";import n from"../../../../analysis/LineOfSightAnalysisTarget.js";import{length as o,normalize as t,scaleAndAdd as l}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as r,create as u}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{absoluteHeightElevationInfo as i,getGraphicEffectiveElevationInfo as s,getConvertedElevation as a}from"../../../../support/elevationInfoUtils.js";import c from"../../../../symbols/support/ElevationInfo.js";function f(e){return e?.clone()??null}function p(e){return e?.clone()??null}function d(n,o=null){return m(n,o,()=>new e)}function v(e,o=null){return m(e,o,()=>new n)}function m(e,n,o){if(null==e)return null;const t=n??o();return t.position=e.position?.clone()??null,t.elevationInfo=e.elevationInfo?.clone()??null,t.feature=e.feature??null,t}function I(e,n,o=null){const t=n.clone();return t.z=a(e,n,o??i,i),t}function g(e,n,o,t=null){const l=I(n,o,t);try{return e.getMapPointIntersection(l)}catch{return null}}function h(e,n,o,{sourceElevationInfo:t=i,preservedIntersection:l=null,useSnappedAbsoluteHeight:r=!1,preferPreservedIntersection:u=!1}){const s=I(n,o,t);return null!=l&&u||null!=l&&!r||l?.mapPoint?.equals(s)?l:g(e,n,o,t)??l}function b(e,n,o,t,{defaultElevationInfo:l=null,sourceElevationInfo:r=i,preservedIntersection:u=null,useSnappedAbsoluteHeight:s=!1,preferPreservedIntersection:a=!1}={}){const c=h(o,e,t,{sourceElevationInfo:r,preservedIntersection:u,useSnappedAbsoluteHeight:s,preferPreservedIntersection:a});return null!=c&&(P(e,n,c,{snappedMapPoint:t,defaultElevationInfo:l,sourceElevationInfo:r,useSnappedAbsoluteHeight:s||!c.mapPoint?.equals(t)}),!0)}function P(e,n,o,{snappedMapPoint:t=o.mapPoint,defaultElevationInfo:l=null,sourceElevationInfo:r=i,useSnappedAbsoluteHeight:u=!1}={}){if(null==t)return n.position=null,n.elevationInfo=null,void(n.feature=null);const f=I(e,t,r),p=!("relative-to-ground"===r?.mode||"on-the-ground"===r?.mode)&&(u||"ground"!==o.context?.type&&!o.mapPoint?.equals(f));switch(o.context?.type){case"graphic":{const e=o.context.graphic,t=s(e);"on-the-ground"===t.mode&&(t.mode="relative-to-ground",t.offset=0),n.elevationInfo=new c(t),n.feature=e;break}case"gaussian-splat":return n.elevationInfo=l?.clone()??null,n.feature=null,p&&(n.elevationInfo=null),void(n.position=y(e,f,n.elevationInfo,o.normal));case"ground":n.elevationInfo=l?.clone()??new c({mode:"on-the-ground"}),n.feature=null;break;default:n.elevationInfo=l?.clone()??null,n.feature=null}p&&(n.elevationInfo=null);const d=f.clone();d.z=a(e,f,i,n.elevationInfo),n.position=d}function y(e,n,s,c){const f=n.clone(),p=r(n.x,n.y,n.z??0);if(!e.renderCoordsHelper.toRenderCoords(p,n.spatialReference,p)||0===o(c))return f.z=a(e,f,i,s),f;const d=4,v=e.state.camera.computeScreenPixelSizeAt(p)*d,m=t(u(),c);l(p,p,m,v);const I=e.renderCoordsHelper.fromRenderCoords(p,f);return null==I?(f.z=a(e,f,i,s),f):(I.z=a(e,I,i,s),I)}export{y as getGaussianSplatOffsetPosition,g as getLineOfSightMapPointIntersection,d as restoreLineOfSightObserverState,v as restoreLineOfSightTargetState,f as snapshotLineOfSightObserverState,p as snapshotLineOfSightTargetState,b as updateLineOfSightItemFromAuthoredPoint,P as updateLineOfSightItemFromIntersection};
