/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{rad2deg as t,acosClamped as o}from"../../../core/mathUtils.js";import{normalize as r,dot as e,copy as i,scale as n,subtract as s,length as m,cross as c}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as l}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{wrap as a}from"../../../geometry/support/lineSegment.js";import{intersectLineSegment as p}from"../../../geometry/support/plane.js";const f=l(),u=l();function g(){return{direction:l(),up:l()}}function h(l,a,p,g,h){let j=r(f,l),b=e(j,g);const d=b>0;b=Math.abs(b),b>.99&&(b=Math.abs(e(a,g)),b<.99?(i(j,a),d&&n(j,j,-1)):j=null);let x=0;if(j){n(u,g,e(g,j)),s(j,j,u);const r=e(j,h)/(m(j)*m(h));c(u,j,h);x=(e(u,g)>0?1:-1)*t(o(r))}const v=t(o(-e(g,l)/m(l)));return p?(p.heading=x,p.tilt=v,p):{heading:x,tilt:v}}function j(t,o,r,e){s(b,r,o),p(e,a(o,b),t)||t===r||i(t,r)}const b=l();export{j as clampLineSegmentToPlane,g as createDirectionUp,h as directionToHeadingTilt};
