/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{create as t}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as o}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as r}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{h as e,g as s,e as a,j as i,i as n,d as m,c,n as l,f}from"../../../../chunks/vec32.js";import{create as I}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as h}from"../../../../geometry/ellipsoidUtils.js";import{lonLatToWebMercatorComparable as N}from"../../../../geometry/projection/projectors.js";import{newDoubleArray as p}from"../../../../geometry/support/DoubleArray.js";import{fromArray as g,getNormal as u,create as b}from"../../../../geometry/support/plane.js";function j(t,r,e,s,a=1){if(e.isGeographic&&1===s){const t=p(r.length),o=r.length,s=h(e);for(let e=0;e<o;e+=3)N(r,e,t,e,s);r=t}o(_,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);for(let o=0;o<r.length;o+=3)_[0]=Math.min(_[0],r[o]),_[1]=Math.min(_[1],r[o+1]);const i=_[0]%a,n=_[1]%a,m=_[0]-i,c=_[1]-n;for(let o=0;o<r.length;o+=3){const e=o/3*4;t[e]=(r[o]-m)/a,t[e+1]=(r[o+1]-c)/a,t[e+2]=m/a,t[e+3]=c/a}}function T(t,r,m,c,l=1){e(F,1,0,0),e(V,0,1,0),e(Y,0,0,1),D(M,m),g(E,m)&&O(E,F,V,Y,c,M),o(_,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),o(y,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);for(let o=0;o<m.length;o+=3){e(x,m[o],m[o+1],m[o+2]);const t=s(F,x),r=s(V,x);_[0]=Math.min(_[0],t),_[1]=Math.min(_[1],r),y[0]=Math.max(y[0],t),y[1]=Math.max(y[1],r)}const f=s(Y,M);q(P,_[0],_[1],f,F,V,Y),q(v,y[0],_[1],f,F,V,Y),q(A,_[0],y[1],f,F,V,Y),a(v,v,P),i(v,v,.5),a(A,A,P),i(A,A,.5),n(P,P,v),n(P,P,A);const I=_[0]%l,h=_[1]%l,N=_[0]-I,p=_[1]-h;for(let o=0;o<m.length;o+=3){e(x,m[o],m[o+1],m[o+2]);const a=o/3,i=4*a;t[i]=(s(F,x)-N)/l,t[i+1]=(s(V,x)-p)/l,t[i+2]=N/l,t[i+3]=p/l;const n=9*a;for(let t=0;t<3;t++)r[n+t]=P[t],r[n+t+3]=v[t],r[n+t+6]=A[t]}}const M=I(),x=I(),E=b(),F=I(),V=I(),Y=I(),_=r(),y=r(),P=I(),v=I(),A=I();function O(t,o,r,a,n,I){null!=n?(n.basisMatrixAtPosition(I,S),e(G,S[0],S[1],S[2]),e(d,S[4],S[5],S[6]),e(k,S[8],S[9],S[10])):(e(G,1,0,0),e(d,0,1,0),e(k,0,0,1));const h=u(t);s(h,k)<0&&i(h,h,-1),m(a,h);const N=s(h,d),p=s(h,G);Math.abs(N)>Math.abs(p)?(c(o,G,h,-p),l(o,o),f(r,o,h),l(r,r),i(r,r,-1)):(c(r,d,h,-N),l(r,r),f(o,r,h),l(o,o))}const S=t(),G=I(),d=I(),k=I();function D(t,o){e(U,0,0,0);for(let r=0;r<o.length-3;r+=3)U[0]+=o[r],U[1]+=o[r+1],U[2]+=o[r+2];i(t,U,1/(o.length/3-1))}const U=I();function q(t,o,r,s,a,i,n){e(t,o*a[0]+r*i[0]+s*n[0],o*a[1]+r*i[1]+s*n[1],o*a[2]+r*i[2]+s*n[2])}export{T as createMapSpaceUVCoords,j as createMapSpaceUVCoordsDraped};
