/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{getReferenceEllipsoid as t}from"../../../../geometry/ellipsoidUtils.js";import{lonLatToWebMercatorComparable as r}from"../../../../geometry/projection/projectors.js";import{newDoubleArray as e}from"../../../../geometry/support/DoubleArray.js";import{computeUVCellStart as o,UVWorkspace as n}from"./UVWorkspace.js";import{computeVertexConnectedTriangleComponents as i}from"../../support/meshProcessing.js";function s(n,i,s,p,c=1){if(0===i.length)return;if(s.isGeographic&&1===p){const o=e(i.length),n=i.length,p=t(s);for(let t=0;t<n;t+=3)r(i,t,o,t,p);i=o}let f=Number.POSITIVE_INFINITY,l=Number.POSITIVE_INFINITY;for(let t=0;t<i.length;t+=3)f=Math.min(f,i[t]),l=Math.min(l,i[t+1]);const[m,u]=o(f,l,c);for(let t=0;t<i.length;t+=3){const r=t/3*4;n[r]=(i[t]-m)/c,n[r+1]=(i[t+1]-u)/c,n[r+2]=m/c,n[r+3]=u/c}}function p(t,r,e,o,n=1){if(0===e.length)return;const i=m,[s,p]=i.prepareUVFrame(e,o,n);i.writeMapSpaceUVs(t,e,s,p,n),i.writeBoundingRect(r,0)}function c(t,r,e,o,n,s,p=1){const c=o.length/3,u=Math.floor(n.length/3);if(0===c||0===u)return 0;const a=m,[g,h]=i(n,u,c),I=new Array;for(let i=0;i<h;++i)I[i]=[];for(let i=0;i<c;++i)e[i]=-1;for(let i=0;i<u;++i){const t=g[i],r=n[3*i],o=n[3*i+1],s=n[3*i+2];f(e,I[t],r,t),f(e,I[t],o,t),f(e,I[t],s,t)}for(let i=0;i<c;++i)e[i]<0&&(e[i]=0,I[0].push(i));for(let i=0;i<h;++i)l(o,I[i],t,r,i,s,p,a);return h}function f(t,r,e,o){-1===t[e]&&(t[e]=o,r.push(e))}function l(t,r,e,o,n,i,s,p){const[c,f]=p.prepareUVFrame(t,i,s,r);p.writeMapSpaceUVs(e,t,c,f,s,r),p.writeBoundingRect(o,9*n)}const m=new n;export{p as writeMapSpaceUVCoords,s as writeMapSpaceUVCoordsDraped,c as writeMapSpaceUVCoordsPerConnectedPart};
