/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{clamp as t}from"../../core/mathUtils.js";import{dot as r,add as n,scale as o,exactEquals as e,subtract as c,normalize as i,cross as u,set as f,copy as s}from"../../core/libs/gl-matrix-2/math/vec3.js";import{create as a}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{equals as m,exactEquals as g}from"../../core/libs/gl-matrix-2/math/vec4.js";import{projectPointSignedLength as l}from"./vector.js";import{sv3d as h,sv4d as p}from"./vectorStacks.js";import{tangentFrame as M}from"../../views/3d/support/mathUtils.js";function v(t=$){return[t[0],t[1],t[2],t[3]]}const b=g,j=m;function x(t=$[0],r=$[1],n=$[2],o=$[3]){return d(t,r,n,o,p.get())}function q(t,r){return d(r[0],r[1],r[2],r[3],t)}function y(t){return t}function d(t,r,n,o,e=v()){return e[0]=t,e[1]=r,e[2]=n,e[3]=o,e}function E(t,r,n){return s(n,t),n[3]=r,n}function U(t,r,n){const o=r[0]*r[0]+r[1]*r[1]+r[2]*r[2],e=Math.abs(o-1)>1e-5&&o>1e-12?1/Math.sqrt(o):1;return n[0]=r[0]*e,n[1]=r[1]*e,n[2]=r[2]*e,n[3]=-(n[0]*t[0]+n[1]*t[1]+n[2]*t[2]),n}function k(t,r,n,o=v()){const e=n[0]-r[0],c=n[1]-r[1],i=n[2]-r[2],u=t[0]-r[0],f=t[1]-r[1],s=t[2]-r[2],a=c*s-i*f,m=i*u-e*s,g=e*f-c*u,l=a*a+m*m+g*g,h=Math.abs(l-1)>1e-5&&l>1e-12?1/Math.sqrt(l):1;return o[0]=a*h,o[1]=m*h,o[2]=g*h,o[3]=-(o[0]*t[0]+o[1]*t[1]+o[2]*t[2]),o}function w(t,n,o,u=0,f=Math.floor(o*(1/3)),s=Math.floor(o*(2/3))){if(o<3)return!1;n(A,u);let a=f,m=!1;for(;a<o-1&&!m;)n(B,a),a++,m=!e(A,B);if(!m)return!1;for(a=Math.max(a,s),m=!1;a<o&&!m;)n(C,a),a++,c(D,A,B),i(D,D),c(F,B,C),i(F,F),m=!e(A,C)&&!e(B,C)&&Math.abs(r(D,F))<z;return m?(k(A,B,C,t),!0):(0!==u||1!==f||2!==s)&&w(t,n,o,0,1,2)}function S(t,r,n=!0){const o=r.length/3;return w(t,(t,n)=>f(t,r[3*n+0],r[3*n+1],r[3*n+2]),n?o-1:o)}const z=.99619469809,A=a(),B=a(),C=a(),D=a(),F=a();function G(t,n,o){return n!==t&&q(t,n),t[3]=-r(y(t),o),t}function H(t,r){return r[0]=-t[0],r[1]=-t[1],r[2]=-t[2],r[3]=-t[3],r}function I(t,r,n,o){return u(C,r,t),U(n,C,o)}function J(t,r,n,o){return Y(Z(t,r,c(h.get(),n,r),_,o))}function K(t,r,n){return null!=r&&Y(Z(t,r.origin,r.direction,tt,n))}function L(t,r,n){return Y(Z(t,r.origin,r.vector,0,n))}function N(t,r,n){return Y(Z(t,r.origin,r.vector,1,n))}function O(t,r){return X(t,r)>=0}function P(t,n){const o=r(y(t),n.ray.direction),e=-X(t,n.ray.origin);if(e<0&&o>=0)return!1;if(o>-1e-6&&o<1e-6)return e>0;if((e<0||o<0)&&!(e<0&&o<0))return!0;const c=e/o;return o>0?c<n.c1&&(n.c1=c):c>n.c0&&(n.c0=c),n.c0<=n.c1}function Q(t,n){const o=r(y(t),n.ray.direction),e=-X(t,n.ray.origin);if(o>-1e-6&&o<1e-6)return e>0;const c=e/o;return o>0?c<n.c1&&(n.c1=c):c>n.c0&&(n.c0=c),n.c0<=n.c1}function R(t,r,e){const i=o(h.get(),y(t),-t[3]),u=V(t,c(h.get(),r,i),h.get());return n(e,u,i),e}function T(t,r,n,o){const e=y(t),i=h.get(),u=h.get();M(e,i,u);const s=c(h.get(),n,r),a=l(i,s),m=l(u,s),g=l(e,s);return f(o,a,m,g)}function V(t,n,e){const i=o(h.get(),y(t),r(y(t),n));return c(e,n,i),e}function W(t,r){return Math.abs(X(t,r))}function X(t,n){return r(y(t),n)+t[3]}function Y(t){return 0===t||1===t}function Z(e,c,i,u,f){const s=r(y(e),i),a=X(e,c);if(0===s)return a>=0?2:3;let m=-a/s;return 1&u&&(m=t(m,0,1)),!(4&u)&&m<0||!(8&u)&&m>1?a>=0?2:3:(n(f,c,o(f,i,m)),a>=0?0:1)}const $=[0,0,1,0],_=12,tt=8;export{P as clip,Q as clipInfinite,q as copy,v as create,W as distance,j as equals,b as exactEquals,S as fromArray,w as fromManyPoints,E as fromNormalAndOffset,k as fromPoints,U as fromPositionAndNormal,d as fromValues,I as fromVectorsAndPoint,y as getNormal,J as intersectLine,Z as intersectLineOrRay,L as intersectLineSegment,N as intersectLineSegmentClamp,K as intersectRay,O as isPointInside,H as negate,R as projectPoint,T as projectPointLocal,V as projectVector,G as setOffsetFromPoint,X as signedDistance,$ as up,x as wrap};
