/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{acosClamped as t}from"../../../core/mathUtils.js";import{dot as n,set as r,normalize as o,length as c,scale as s,add as a,lerp as i,cross as u,subtract as e}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as h}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";function f(t,n){return t>n?Math.cos(n):Math.cos(t)}function M(t,n,r){return 2*Math.atan(r*Math.tan(.5*t)/n)}function l(t,n,r){return 2*Math.atan(n*Math.tan(.5*t)/r)}function m(t){const n=t[0]*t[0]+t[4]*t[4]+t[8]*t[8],r=t[1]*t[1]+t[5]*t[5]+t[9]*t[9],o=t[2]*t[2]+t[6]*t[6]+t[10]*t[10];return Math.sqrt(Math.max(n,r,o))}function g(t,n){const o=Math.sqrt(n[0]*n[0]+n[4]*n[4]+n[8]*n[8]),c=Math.sqrt(n[1]*n[1]+n[5]*n[5]+n[9]*n[9]),s=Math.sqrt(n[2]*n[2]+n[6]*n[6]+n[10]*n[10]);return r(t,o,c,s),t}function b(t,c,s){s=s||t;const a=n(t,c);r(s,t[0]-a*c[0],t[1]-a*c[1],t[2]-a*c[2]),o(s,s)}function p(t,n,c){Math.abs(t[0])>Math.abs(t[1])?r(n,0,1,0):r(n,1,0,0),u(c,t,n),u(n,c,t),o(c,c),o(n,n)}function q(t,n,r,o,c,s){const a=t+(n-t)*c;return a+(r+(o-r)*c-a)*s}function x(t,r,o,u=h()){const e=c(t),f=c(r),M=n(t,r)/(e*f);if(M<.9999999999999999){const n=Math.acos(M),c=((1-o)*e+o*f)/Math.sin(n),i=c/e*Math.sin((1-o)*n),h=c/f*Math.sin(o*n);return s(A,t,i),s(B,r,h),a(u,A,B)}return i(u,t,r,o)}function j(t,r,u,f=h(),M=h()){const l=c(t),m=c(r),g=n(t,r)/(l*m);if(g<.9999999999999999){const n=Math.acos(g),o=Math.sin(n),c=Math.sin(u*n),i=Math.sin((1-u)*n),e=(1-u)*l+u*m;{const n=e/o,u=n/m*c;s(A,t,n/l*i),s(B,r,u),a(f,A,B)}{const h=1/l*(-Math.cos((1-u)*n)*n*e+i*(-l+m));s(A,t,h);const f=1/m*(Math.cos(u*n)*n*e+c*(-l+m));s(B,r,f),a(M,A,B),s(M,M,1/o)}return M}return i(f,t,r,u),e(M,r,t),o(M,M),M}function v(r,c,s){r=o(A,r),c=o(B,c);const a=t(n(r,c));if(s){const t=u(z,r,c);if(n(t,s)<0)return-a}return a}function U(t){const n=t.length;return r=>{if(r<=t[0][0])return t[0][1];if(r>=t[n-1][0])return t[n-1][1];let o=1;for(;r>t[o][0];)o++;const c=t[o-1][0],s=t[o][0],a=(s-r)/(s-c);return a*t[o-1][1]+(1-a)*t[o][1]}}function d(t,r,c,s){e(w,r,t),e(y,c,t),u(s,w,y),o(s,s),s[3]=-n(t,s)}function k(t,n){if(r(n,0,0,0),t.length>0){for(let r=0;r<t.length;++r)a(n,n,t[r]);s(n,n,1/t.length)}}const w=h(),y=h(),z=h(),A=h(),B=h();export{v as angle,q as bilerp,f as cosCapped,M as fovx2fovy,l as fovy2fovx,b as makeOrthonormal,U as makePiecewiseLinearFunction,m as maxScale,k as midpoint3d,d as planeFromPoints,g as scaleFromMatrix,x as slerp,j as slerpTangent,p as tangentFrame};
