/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
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 n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{p as o,n as a,d as i,k as s,g as c,a as m,i as p,j as d}from"../../../../chunks/vec32.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getNormal as f,fromPositionAndNormal as u,create as g}from"../../../../geometry/support/plane.js";import{viewshedToolManipulatorConfiguration as j}from"./ViewshedConfiguration.js";import{calculateTranslateRotateFromBases as h,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},n){const o=h(r,e,t,n);return o[12]=0,o[13]=0,o[14]=0,o}function U(t,n,o,s){const h=l(),v=f(o.plane),S=E(n,v);let R;if(Math.abs(S)>j.viewAngleThreshold)R=t.next(x(n,o.plane));else{const r=u(s.targetRenderSpace,o.basis1,g()),i=a(D,o.basis1),f=a(M,o.basis2);R=t.next(x(n,r)).next(r=>{const t=r=>{const t=c(m(V,r,o.origin),f),n=Math.acos(e(t/s.farDistanceRenderSpace,-1,1)),a=Math.sin(n)*s.farDistanceRenderSpace;return p(l(),o.origin,p(l(),d(V,i,a),d(k,f,t)))},n=t(r.renderStart),a=t(r.renderEnd);return{...r,renderStart:n,renderEnd:a}})}return R.next(e=>{"start"===e.action&&i(h,e.renderStart);const t=r(b(h,e.renderEnd,o.origin,v));return{...e,deltaAngle:t}})}function E(e,t){const n=D;e.renderCoordsHelper.toRenderCoords(e.camera.position,n);const o=v(e,n,e.camera.heading,e.camera.tilt,S()).direction;return r(s(o,t))-90}function C(r,e,n,a){return t(w,n,a),o(r,e,w)}const D=l(),M=l(),V=l(),k=l(),w=n();export{R as getViewshedRotationMatrix,C as rotateBy,U as screenToCircleAngle};
