/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{equals as i}from"../../core/arrayUtils.js";import{ObjectStack as r}from"../../core/ObjectStack.js";import{set as t,invert as n}from"../../core/libs/gl-matrix-2/math/mat3.js";import{create as o}from"../../core/libs/gl-matrix-2/factories/mat3f64.js";import{copy as e,subtract as c,dot as s,normalize as u,cross as a,sub as f,set as m,add as g,scale as l}from"../../core/libs/gl-matrix-2/math/vec3.js";import{clone as d,create as p}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{sv3d as j}from"./vectorStacks.js";function b(i){return i?x(d(i.origin),d(i.direction)):x(p(),p())}function x(i,r){return{origin:i,direction:r}}function h(r,t){return i(r.origin,t.origin)&&i(r.direction,t.direction)}function v(i,r){const t=O.get();return t.origin=i,t.direction=r,t}function k(i,r=b()){return S(i.origin,i.direction,r)}function y(i,r,t=b()){return e(t.origin,i),c(t.direction,r,i),t}function S(i,r,t=b()){return e(t.origin,i),e(t.direction,r),t}function q(i,r){const t=a(j.get(),u(j.get(),i.direction),c(j.get(),r,i.origin));return s(t,t)}function w(i,r,t){const n=s(i.direction,c(t,r,i.origin));return g(t,i.origin,l(t,i.direction,n)),t}function M(i,r,o,e){const c=i.origin,d=r.origin,p=i.direction,j=r.direction,b=s(u(z,p),u(A,j));if(Math.abs(b)>=1)return null;const x=a(z,p,j),h=f(U,d,c),v=t(B,p[0],p[1],p[2],-j[0],-j[1],-j[2],x[0],x[1],x[2]),k=n(B,v);if(null==k)return[o,e];const y=s(m(z,k[0],k[3],k[6]),h),S=s(m(A,k[1],k[4],k[7]),h);return g(o,c,l(U,p,y)),g(e,d,l(U,j,S)),[o,e]}const O=new r(()=>b()),U=p(),z=p(),A=p(),B=o();export{w as closestPoint,M as closestPoints,k as copy,b as create,q as distance2,h as equals,y as fromPoints,S as fromValues,v as wrap};
