/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{clamp as t}from"../../core/mathUtils.js";import{exactEquals as r,subtract as n,normalize as o,dot as e,add as c,scale 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,c,i,u=0,f=Math.floor(i*(1/3)),s=Math.floor(i*(2/3))){if(i<3)return!1;c(A,u);let a=f,m=!1;for(;a<i-1&&!m;)c(B,a),a++,m=!r(A,B);if(!m)return!1;for(a=Math.max(a,s),m=!1;a<i&&!m;)c(C,a),a++,n(D,A,B),o(D,D),n(F,B,C),o(F,F),m=!r(A,C)&&!r(B,C)&&Math.abs(e(D,F))<z;return m?(k(A,B,C,t),!0):(0!==u||1!==f||2!==s)&&w(t,c,i,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,r,n){return r!==t&&q(t,r),t[3]=-e(y(t),n),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,o,e){return Y(Z(t,r,n(h.get(),o,r),_,e))}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,r){const n=e(y(t),r.ray.direction),o=-X(t,r.ray.origin);if(o<0&&n>=0)return!1;if(n>-1e-6&&n<1e-6)return o>0;if((o<0||n<0)&&!(o<0&&n<0))return!0;const c=o/n;return n>0?c<r.c1&&(r.c1=c):c>r.c0&&(r.c0=c),r.c0<=r.c1}function Q(t,r){const n=e(y(t),r.ray.direction),o=-X(t,r.ray.origin);if(n>-1e-6&&n<1e-6)return o>0;const c=o/n;return n>0?c<r.c1&&(r.c1=c):c>r.c0&&(r.c0=c),r.c0<=r.c1}function R(t,r,o){const e=i(h.get(),y(t),-t[3]),u=V(t,n(h.get(),r,e),h.get());return c(o,u,e),o}function T(t,r,o,e){const c=y(t),i=h.get(),u=h.get();M(c,i,u);const s=n(h.get(),o,r),a=l(i,s),m=l(u,s),g=l(c,s);return f(e,a,m,g)}function V(t,r,o){const c=i(h.get(),y(t),e(y(t),r));return n(o,r,c),o}function W(t,r){return Math.abs(X(t,r))}function X(t,r){return e(y(t),r)+t[3]}function Y(t){return 0===t||1===t}function Z(r,n,o,u,f){const s=e(y(r),o),a=X(r,n);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:(c(f,n,i(f,o,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};
