/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{earth as t}from"../../../geometry/support/Ellipsoid.js";import{distance as e}from"../../../geometry/support/pointUtils.js";import a from"./ExposurePoint.js";function i(t){const{camera:e,features:a,selectedPoint:i}=t;if(!a.length)return[];t.currentImage??={attributes:{cameraHeading:0,cameraPitch:0}};const r=s(e,i,t.currentImage);return a.map(r)}function s(a,i,s){const h=i.clone();return h.z??=0,h.elevation=i.elevation??0,i=>{const{hfovWeight:n,vfovWeight:o,distanceWeight:c}=r(i.attributes,a?"3d":"2d"),l=i.attributes,{cameraHeight:g,cameraHeading:M,cameraPitch:u,farDistance:f,horizontalFieldOfView:b,verticalFieldOfView:d,isOblique:v}=l,m=l.geometry,W=180*Math.atan2(m.y-h.y,m.x-h.x)/Math.PI,p=e(h,m);let y,x,P=b,I=d,q=!1;a?(y=a.heading,x=a.tilt,P=180,I=180,q=!0):!v||u<10?(y=M,x=u,q=!1):(y=s.attributes.cameraHeading,x=u,q=!0,P=180),y>180&&(y-=360);let H=1;m.spatialReference.isWebMercator&&(H=1/Math.cos(Math.PI/2-2*Math.atan(Math.exp(-1*m.y/t.radius))));const O=Math.sqrt((Math.sqrt((h.x-m.x)**2+(h.y-m.y)**2)/H)**2+((h.z??0)-(h.elevation??0)-g)**2),z=90-180*Math.atan2(h.y-m.y,h.x-m.x)/Math.PI;let j=(Math.abs(z-y)>180?Math.abs(360-Math.abs(z-y)):Math.abs(z-y))/P;j=4*j+1;const w=180*Math.acos((l.cameraHeight-(h.z??0)+(h.elevation??0))/O)/Math.PI;let E=Math.abs(w-x)/I;E=4*E+1;let F=O/Math.sqrt(f**2+g**2);F=4*F+1;const S=n*j+o*E+c*F;let V;if(q){const t=M>180?M-360:M;V=n*((Math.abs(z-t)>180?Math.abs(360-Math.abs(z-t)):Math.abs(z-t))/b*4+1)+o*(Math.abs(w-u)/d*4+1)+c*F}else V=S;return{suitability:S,trueSuitability:V,feature:i,angle:W,distance:p,verticalAngle:Math.abs(180*Math.atan(p/g)/Math.PI)}}}function r(t,e){const i="isOblique"in t?t:new a(t),{isOblique:s,isSpherical:r,isNadir:h}=i;return r?{hfovWeight:"2d"===e?0:1,vfovWeight:"2d"===e?0:.6,distanceWeight:"2d"===e?1:.5}:h?{hfovWeight:.25,vfovWeight:1,distanceWeight:1}:s?{hfovWeight:1,vfovWeight:.25,distanceWeight:1}:{hfovWeight:1,vfovWeight:1,distanceWeight:1}}export{i as calculateSuitabilities};
