/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{clamp as t}from"../../core/mathUtils.js";import{g as n,i as r,j as o,f as e,e as c,m as u,n as i,h as s,d as f}from"../../chunks/vec32.js";import{create as a}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{a as m,e as g}from"../../chunks/vec42.js";import{projectPointSignedLength as h}from"./vector.js";import{sv4d as l,sv3d as p}from"./vectorStacks.js";import{tangentFrame as M}from"../../views/3d/support/mathUtils.js";function j(t=$){return[t[0],t[1],t[2],t[3]]}const v=m,b=g;function d(t=$[0],n=$[1],r=$[2],o=$[3]){return x(t,n,r,o,l.get())}function y(t,n){return x(n[0],n[1],n[2],n[3],t)}function k(t){return t}function x(t,n,r,o,e=j()){return e[0]=t,e[1]=n,e[2]=r,e[3]=o,e}function q(t,n,r){return f(r,t),r[3]=n,r}function U(t,n,r){const o=n[0]*n[0]+n[1]*n[1]+n[2]*n[2],e=Math.abs(o-1)>1e-5&&o>1e-12?1/Math.sqrt(o):1;return r[0]=n[0]*e,r[1]=n[1]*e,r[2]=n[2]*e,r[3]=-(r[0]*t[0]+r[1]*t[1]+r[2]*t[2]),r}function w(t,n,r,o=j()){const e=r[0]-n[0],c=r[1]-n[1],u=r[2]-n[2],i=t[0]-n[0],s=t[1]-n[1],f=t[2]-n[2],a=c*f-u*s,m=u*i-e*f,g=e*s-c*i,h=a*a+m*m+g*g,l=Math.abs(h-1)>1e-5&&h>1e-12?1/Math.sqrt(h):1;return o[0]=a*l,o[1]=m*l,o[2]=g*l,o[3]=-(o[0]*t[0]+o[1]*t[1]+o[2]*t[2]),o}function S(t,r,o,e=0,s=Math.floor(o*(1/3)),f=Math.floor(o*(2/3))){if(o<3)return!1;r(B,e);let a=s,m=!1;for(;a<o-1&&!m;)r(C,a),a++,m=!u(B,C);if(!m)return!1;for(a=Math.max(a,f),m=!1;a<o&&!m;)r(D,a),a++,c(E,B,C),i(E,E),c(F,C,D),i(F,F),m=!u(B,D)&&!u(C,D)&&Math.abs(n(E,F))<A;return m?(w(B,C,D,t),!0):(0!==e||1!==s||2!==f)&&S(t,r,o,0,1,2)}function z(t,n,r=!0){const o=n.length/3;return S(t,(t,r)=>s(t,n[3*r+0],n[3*r+1],n[3*r+2]),r?o-1:o)}const A=.99619469809,B=a(),C=a(),D=a(),E=a(),F=a();function G(t,r,o){return r!==t&&y(t,r),t[3]=-n(k(t),o),t}function H(t,n){return n[0]=-t[0],n[1]=-t[1],n[2]=-t[2],n[3]=-t[3],n}function I(t,n,r,o){return e(D,n,t),U(r,D,o)}function J(t,n,r,o){return Y(Z(t,n,c(p.get(),r,n),_,o))}function K(t,n,r){return null!=n&&Y(Z(t,n.origin,n.direction,tt,r))}function L(t,n,r){return Y(Z(t,n.origin,n.vector,0,r))}function N(t,n,r){return Y(Z(t,n.origin,n.vector,1,r))}function O(t,n){return X(t,n)>=0}function P(t,r){const o=n(k(t),r.ray.direction),e=-X(t,r.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<r.c1&&(r.c1=c):c>r.c0&&(r.c0=c),r.c0<=r.c1}function Q(t,r){const o=n(k(t),r.ray.direction),e=-X(t,r.ray.origin);if(o>-1e-6&&o<1e-6)return e>0;const c=e/o;return o>0?c<r.c1&&(r.c1=c):c>r.c0&&(r.c0=c),r.c0<=r.c1}function R(t,n,e){const u=o(p.get(),k(t),-t[3]),i=V(t,c(p.get(),n,u),p.get());return r(e,i,u),e}function T(t,n,r,o){const e=k(t),u=p.get(),i=p.get();M(e,u,i);const f=c(p.get(),r,n),a=h(u,f),m=h(i,f),g=h(e,f);return s(o,a,m,g)}function V(t,r,e){const u=o(p.get(),k(t),n(k(t),r));return c(e,r,u),e}function W(t,n){return Math.abs(X(t,n))}function X(t,r){return n(k(t),r)+t[3]}function Y(t){return 0===t||1===t}function Z(e,c,u,i,s){const f=n(k(e),u),a=X(e,c);if(0===f)return a>=0?2:3;let m=-a/f;return 1&i&&(m=t(m,0,1)),!(4&i)&&m<0||!(8&i)&&m>1?a>=0?2:3:(r(s,c,o(s,u,m)),a>=0?0:1)}const $=[0,0,1,0],_=12,tt=8;export{P as clip,Q as clipInfinite,y as copy,j as create,W as distance,b as equals,v as exactEquals,z as fromArray,S as fromManyPoints,q as fromNormalAndOffset,w as fromPoints,U as fromPositionAndNormal,x as fromValues,I as fromVectorsAndPoint,k 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,d as wrap};
