/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{d as t,h as e,i as r,b as s,n as o,f as i}from"../../../../chunks/vec32.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as m,fromPositionAndNormal as a,intersectRay as p}from"../../../../geometry/support/plane.js";import{wrap as c}from"../../../../geometry/support/ray.js";import{makeOrthoBasisDirUpFallback as g}from"./GeometryUtil.js";function h(h,n){let v=null;const u=h.vertices.length,j=.99619469809,R=f(),y=f(),b=f(),x=f(),L=f(),d=f(),k=m();let q=h.vertices[0];t(y,n),e(R,0,1,0),g(q.vRight,y,R,R,b,y,j),t(q.frame.up,y),t(q.frame.right,b);const G=h.positions;let M=h.offset;v=q;for(let f=1;f<u;++f){q=h.vertices[f],r(L,q.vLeft,q.vRight);let m=s(L);m>0?(m=1/Math.sqrt(m),L[0]=L[0]*m,L[1]=L[1]*m,L[2]=L[2]*m):(L[0]=q.vRight[0],L[1]=q.vRight[1],L[2]=q.vRight[2]),d[0]=G[M]+v.frame.up[0],d[1]=G[M+1]+v.frame.up[1],d[2]=G[M+2]+v.frame.up[2],M+=3;const n=e(l,G[M],G[M+1],G[M+2]);a(n,L,k);p(k,c(d,q.vLeft),x)?(x[0]-=G[M],x[1]-=G[M+1],x[2]-=G[M+2],o(y,x),i(b,L,y),o(b,b)):g(L,v.frame.up,v.frame.right,R,b,y,j),t(q.frame.up,y),t(q.frame.right,b),v=q}}const l=f();export{h as computeMinimumRotationTangentFrame};
