/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{copy as t,set as r,add as e,length as o,normalize as i,cross as m}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as s,fromPositionAndNormal as a,intersectRay as p}from"../../../../geometry/support/plane.js";import{wrap as c}from"../../../../geometry/support/ray.js";import{makeOrthoBasisDirUpFallback as l}from"./GeometryUtil.js";function g(g,h){let n=null;const u=g.vertices.length,j=.99619469809,R=f(),y=f(),x=f(),b=f(),L=f(),q=f(),G=s();let M=g.vertices[0];t(y,h),r(R,0,1,0),l(M.vRight,y,R,R,x,y,j),t(M.frame.up,y),t(M.frame.right,x);const U=g.positions;let d=g.offset;n=M;for(let f=1;f<u;++f){M=g.vertices[f],e(L,M.vLeft,M.vRight);let s=o(L);s>0?(s=1/Math.sqrt(s),L[0]=L[0]*s,L[1]=L[1]*s,L[2]=L[2]*s):(L[0]=M.vRight[0],L[1]=M.vRight[1],L[2]=M.vRight[2]),q[0]=U[d]+n.frame.up[0],q[1]=U[d+1]+n.frame.up[1],q[2]=U[d+2]+n.frame.up[2],d+=3;const h=r(v,U[d],U[d+1],U[d+2]);a(h,L,G);p(G,c(q,M.vLeft),b)?(b[0]-=U[d],b[1]-=U[d+1],b[2]-=U[d+2],i(y,b),m(x,L,y),i(x,x)):l(L,n.frame.up,n.frame.right,R,x,y,j),t(M.frame.up,y),t(M.frame.right,x),n=M}}const v=f();export{g as computeMinimumRotationTangentFrame};
