/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{rotate as t}from"../../../arcade/geometry/operators.js";import e from"../../../geometry/Polygon.js";import{e as o}from"../../../chunks/intersectionOperator.js";import{g as r}from"../../../chunks/proximityOperator.js";function n(n){const{viewpoint:i,containerWidth:m,containerHeight:a,rotation:s,constraints:c,imageExtent:x,viewportExtent:p}=n,{targetGeometry:f,scale:y}=i;if("point"!==f?.type)return;const g=x.center,{extent:h}=t(e.fromExtent(x),s,...g.toArray()),{width:l,height:E}=h,d=c.scaleToZoom(y);if(d<=0)return void(i.targetGeometry=g.clone());const u=1/2**d,j=m/a;let v=u*l,w=u*E;l/m>E/a?w=v/j:v=w*j;const G=h.clone();G.xmin+=v/2,G.xmax-=v/2,G.ymin+=w/2,G.ymax-=w/2;let k=o(e.fromExtent(h),e.fromExtent(G));k=k&&p.intersects(x)?o(t(k,s,...g.toArray()),e.fromExtent(x)):e.fromExtent(h),i.targetGeometry=r(k,f).coordinate}export{n as constrainViewpoint};
