/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/maybe","../../../../chunks/mat4f64","../../../../chunks/vec2","../../../../chunks/vec2f64","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../geometry/projection","../../../../geometry/projectionEllipsoid","../../../../geometry/support/plane","../../../../geometry/support/buffer/BufferView","../../../ViewingMode"],(function(e,t,o,c,r,a,s,n,u,i,l,f){"use strict";function d(e,t,o,r,a=1){if(o.isGeographic&&r===f.ViewingMode.Global){const e=new Float64Array(t.typedBuffer.length),c=3*t.count,r=u.getReferenceEllipsoid(o);for(let o=0;o<c;o+=3)n.lonLatToWebMercatorComparable(t.typedBuffer,o,e,o,r);t=l.BufferViewVec3f64.fromTypedArray(e)}c.set(h,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);for(let c=0;c<t.count;c++)t.getVec(c,p),h[0]=Math.min(h[0],p[0]),h[1]=Math.min(h[1],p[1]);const s=h[0]%a,i=h[1]%a;T[0]=h[0]-s,T[1]=h[1]-i;for(let c=0;c<t.count;c++)t.getVec(c,p),e.setValues(c,(p[0]-T[0])/a,(p[1]-T[1])/a,T[0]/a,T[1]/a)}function m(e,t,o,r,s=1){a.set(V,1,0,0),a.set(M,0,1,0),a.set(b,0,0,1),k(I,t),S(t,N)&&_(N,V,M,b,o,I),c.set(h,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),c.set(g,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);for(let c=0;c<t.count;c++){t.getVec(c,p);const e=a.dot(V,p),o=a.dot(M,p);h[0]=Math.min(h[0],e),h[1]=Math.min(h[1],o),g[0]=Math.max(g[0],e),g[1]=Math.max(g[1],o)}const n=a.dot(b,I);O(y,h[0],h[1],n,V,M,b),O(A,g[0],h[1],n,V,M,b),O(E,h[0],g[1],n,V,M,b),a.subtract(A,A,y),a.scale(A,A,.5),a.subtract(E,E,y),a.scale(E,E,.5),a.add(y,y,A),a.add(y,y,E);const u=h[0]%s,i=h[1]%s;T[0]=h[0]-u,T[1]=h[1]-i;for(let c=0;c<t.count;c++){t.getVec(c,p),e.setValues(c,(a.dot(V,p)-T[0])/s,(a.dot(M,p)-T[1])/s,T[0]/s,T[1]/s);for(let e=0;e<3;e++)r.set(c,e,y[e]),r.set(c,e+3,A[e]),r.set(c,e+6,E[e])}}const I=s.create(),p=s.create(),N=i.create(),V=s.create(),M=s.create(),b=s.create(),h=r.create(),g=r.create(),T=r.create(),y=s.create(),A=s.create(),E=s.create();function S(e,t){const o=e.count-1;return i.fromManyPointsSampleAt(e,t,0,Math.floor(o/3),Math.floor(o*(2/3)))}function _(e,o,c,r,s,n){t.isSome(s)?(s.basisMatrixAtPosition(n,F),a.set(P,F[0],F[1],F[2]),a.set(v,F[4],F[5],F[6]),a.set(Y,F[8],F[9],F[10])):(a.set(P,1,0,0),a.set(v,0,1,0),a.set(Y,0,0,1));const u=i.normal(e);a.dot(u,Y)<0&&a.scale(u,u,-1),a.copy(r,u);const l=a.dot(u,v),f=a.dot(u,P);Math.abs(l)<Math.abs(f)?(a.scaleAndAdd(o,P,u,-f),a.normalize(o,o),a.cross(c,o,u),a.normalize(c,c),a.scale(c,c,-1)):(a.scaleAndAdd(c,v,u,-l),a.normalize(c,c),a.cross(o,c,u),a.normalize(o,o))}const F=o.create(),P=s.create(),v=s.create(),Y=s.create();function k(e,t){a.set(w,0,0,0);for(let o=0;o<t.count-1;o++)t.getVec(o,p),a.add(w,w,p);a.scale(e,w,1/(t.count-1))}const w=s.create();function O(e,t,o,c,r,s,n){a.set(e,t*r[0]+o*s[0]+c*n[0],t*r[1]+o*s[1]+c*n[1],t*r[2]+o*s[2]+c*n[2])}e.createMapSpaceUVCoords=m,e.createMapSpaceUVCoordsDraped=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
