/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{width as t,height as e,intersects as r}from"../../../../geometry/support/aaBoundingRect.js";import{newDoubleArray as o}from"../../../../geometry/support/DoubleArray.js";import{newFloatArray as n}from"../../../../geometry/support/FloatArray.js";import{Attribute as i}from"../../webgl-engine/lib/Attribute.js";import{Geometry as m}from"../../webgl-engine/lib/Geometry.js";import{createSquareGeometry as h}from"../../webgl-engine/lib/GeometryUtil.js";function u(r,o,n){const i=t(r)/e(r),m={width:n,height:n};return i>1.0001?m.height=n/i:i<.9999&&(m.width=n*i),m.width=Math.round(m.width/(t(r)/t(o))),m.height=Math.round(m.height/(e(r)/e(o))),m}function a(t,e){return h(t,[[e[0],e[1],-1],[e[2],e[1],-1],[e[2],e[3],-1],[e[0],e[3],-1]])}function s(t,e,h){if(!r(e,h))return a(t,h);const u=[e[1]-h[1],Math.min(e[3],h[3])-Math.max(e[1],h[1]),h[3]-e[3],123456],s=[e[0]-h[0],Math.min(e[2],h[2])-Math.max(e[0],h[0]),h[2]-e[2],123456],l=h[2]-h[0],p=h[3]-h[1],f=s[0]>0&&s[2]>0?3:2,w=u[0]>0&&u[2]>0?3:2,c=(w+1)*(f+1),y=o(3*c),b=n(2*c),d=new Array(6*(w*f-1));let j=0,M=0,A=0,x=0,G=0;for(let r=0;r<4;r++){const t=u[r];if(t<=0)continue;let e=0;for(let o=0;o<4;o++){const t=s[o];t<=0||(y[M++]=h[0]+e,y[M++]=h[1]+j,y[M++]=-1,b[A++]=e/l,b[A++]=j/p,o<3&&r<3&&(1!==o||1!==r)&&(d[G++]=x,d[G++]=x+1,d[G++]=x+f+1,d[G++]=x+1,d[G++]=x+f+2,d[G++]=x+f+1),x++,e+=t)}j+=t}const v=new Array(d.length);return new m(t,[["position",new i(y,d,3,!0)],["normal",new i(g,v,3,!0)],["uv0",new i(b,d,2,!0)]])}const g=[0,0,1];export{u as computeImageExportSize,a as createGeometryForExtent,s as createOuterImageGeometry};
