/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{rad2deg as r,clamp as e}from"../../../../core/mathUtils.js";import{fromRotation as t}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{transformMat4 as n,normalize as i,copy as a,angle as s,dot as c,sub as m,add as p,scale as l}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as d}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getNormal as f,fromPositionAndNormal as g,create as u}from"../../../../geometry/support/plane.js";import{viewshedToolManipulatorConfiguration as h}from"./ViewshedConfiguration.js";import{calculateTranslateRotateFromBases as j,calculateInputRotationTransform as b}from"../../interactive/manipulatorUtils.js";import{screenToRenderPlane as x}from"../../interactive/editingTools/dragEventPipeline3D.js";import{headingTiltToDirectionUp as v}from"../../support/cameraUtils.js";import{createDirectionUp as S}from"../../support/cameraUtilsInternal.js";function R({tiltedUpVector:r,rightVector:e,observerRenderSpace:t},o){const n=j(r,e,t,o);return n[12]=0,n[13]=0,n[14]=0,n}function U(t,o,n,s){const j=d(),v=f(n.plane),S=E(o,v);let R;if(Math.abs(S)>h.viewAngleThreshold)R=t.next(x(o,n.plane));else{const r=g(s.targetRenderSpace,n.basis1,u()),a=i(D,n.basis1),f=i(M,n.basis2);R=t.next(x(o,r)).next(r=>{const t=r=>{const t=c(m(V,r,n.origin),f),o=Math.acos(e(t/s.farDistanceRenderSpace,-1,1)),i=Math.sin(o)*s.farDistanceRenderSpace;return p(d(),n.origin,p(d(),l(V,a,i),l(w,f,t)))},o=t(r.renderStart),i=t(r.renderEnd);return{...r,renderStart:o,renderEnd:i}})}return R.next(e=>{"start"===e.action&&a(j,e.renderStart);const t=r(b(j,e.renderEnd,n.origin,v));return{...e,deltaAngle:t}})}function E(e,t){const o=D;e.renderCoordsHelper.toRenderCoords(e.camera.position,o);const n=v(e,o,e.camera.heading,e.camera.tilt,S()).direction;return r(s(n,t))-90}function C(r,e,o,i){return t(A,o,i),n(r,e,A)}const D=d(),M=d(),V=d(),w=d(),A=o();export{R as getViewshedRotationMatrix,C as rotateBy,U as screenToCircleAngle};
