/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{equals as t}from"../../../core/arrayUtils.js";import{rad2deg as n}from"../../../core/mathUtils.js";import{create as r,center as o}from"../../../geometry/support/aaBoundingRect.js";import{getRingsOrPathsBounds as e}from"../../../geometry/support/boundsUtils.js";import{geometryToCoordinates as i}from"../../../geometry/support/coordsUtils.js";import{toEllipticArc7 as s}from"../../../geometry/support/curves/circularArcUtils.js";import{isCurvedGeometry as c,getEndpoint as u,isCoordinate as a,isBezierCurve as m,isCircularArc as l}from"../../../geometry/support/curves/curveUtils.js";import{transformEllipticArc as p}from"../../../geometry/support/curves/ellipticArc7Utils.js";import{getScaleTransform as f}from"../../interactive/editGeometry/operations/curveOperationUtils.js";function y(t,n,r,o){if(null==o||t.hasZ||(o=void 0),"point"===t.type)return t.x+=n,t.y+=r,t.hasZ&&null!=o&&(t.z+=o),t;if("multipoint"===t.type){const e=t.points;for(let t=0;t<e.length;t++)e[t]=g(e[t],n,r,o);return t}if("extent"===t.type)return t.xmin+=n,t.xmax+=n,t.ymin+=r,t.ymax+=r,null!=o&&(t.zmin??=0,t.zmin+=o,t.zmax??=0,t.zmax+=o),t;const e="polyline"===t.type?t.curvePaths??t.paths:t.curveRings??t.rings,i=c(t);for(let s=0;s<e.length;s++){const t=e[s];for(let e=0;e<t.length;e++)t[e]=v(t[e],n,r,o)}return"paths"in t?i?t.curvePaths=e:t.paths=e:i?t.curveRings=e:t.rings=e,t}function x(t,n,r,o,e){const i=t.clone();if(e){const{resolution:t}=o;y(i,n*t,-r*t)}else{const{dxMap:t,dyMap:e}=h(n,r,o);y(i,t,e)}return i}function h(t,n,r){const o=r.state.inverseTransform;return{dxMap:o[0]*t+o[2]*n,dyMap:o[1]*t+o[3]*n}}function g(t,n,r,o){return z(t,t[0]+n,t[1]+r,null!=t[2]&&null!=o?t[2]+o:void 0)}function v(t,n,r,o){const e=g(u(t),n,r,o);if(a(t))return e;if(m(t)){const[,o,i]=t.b;return{b:[e,[o[0]+n,o[1]+r],[i[0]+n,i[1]+r]]}}if(l(t)){const[,o]=t.c;return{c:[e,[o[0]+n,o[1]+r]]}}const[,i,...s]=t.a;return{a:[e,[i[0]+n,i[1]+r],...s]}}function M(n,s,c,a){if("point"===n.type){const{x:t,y:r}=n,o=a?a[0]:t,e=a?a[1]:r,i=n.clone(),u=(t-o)*s+o,m=(r-e)*c+e;return i.x=u,i.y=m,i}if("extent"===n.type){const{xmin:t,xmax:r,ymin:o,ymax:e}=n,i=a?a[0]:(t+r)/2,u=a?a[1]:(e+o)/2,m=n.clone();if(m.xmin=(t-i)*s+i,m.ymax=(e-u)*c+u,m.xmax=(r-i)*s+i,m.ymin=(o-u)*c+u,m.xmin>m.xmax){const t=m.xmin,n=m.xmax;m.xmin=n,m.xmax=t}if(m.ymin>m.ymax){const t=m.ymin,n=m.ymax;m.ymin=n,m.ymax=t}return m}let m=null;if(!a){m=i(n);const t=r(),o=e(t,m);if(!o)return n.clone();const[s,c,u,l]=o;a=[(s+u)/2,(c+l)/2]}const[l,p]=a;if("multipoint"===n.type){const t=n.clone(),r=t.points;for(let n=0;n<r.length;n++){const t=r[n],[o,e]=t,i=(o-l)*s+l,u=(e-p)*c+p;r[n]=z(t,i,u,void 0)}return t.points=r,t}const f=n.clone();m??=i(n);const y="polygon"===f.type,x=y?f.curveRings??f.rings:f.curvePaths??f.paths;if(!a){const t=r(),n=e(t,x,!1,!1);if(!n)return f;a=o(n)}for(const r of x){let n=null;const o=y&&r.length>0&&t(u(r[0]),u(r.at(-1)));for(let t=0;t<r.length;t++){const o=r[t];r[t]=j(o,s,c,l,p,n),n=o}o&&(r[0]=[...u(r.at(-1))])}return f}function d(t,n,r,o,e){const[i,s,...c]=t;return[(i-o)*n+o,(s-e)*r+e,...c]}function j(t,n,r,o,e,i){if(a(t))return d(t,n,r,o,e);if(m(t)){const[i,s,c]=t.b.map(t=>d(t,n,r,o,e));return{b:[i,s,c]}}if(!i)return t;const c=u(i),y=l(t)?s(c,t):t,[x,h,g,v,M,j,U]=y.a,b=M??0,z=j??Math.hypot(x[0]-h[0],x[1]-h[1]),R=U??1,P=f(o,e,1,0,0,1,n,r);return p(c,{a:[[...x],[...h],g,v,b,z,R]},P)}function U(t,n,r,o,e,i){const s=Math.sqrt((r-t)*(r-t)+(o-n)*(o-n));return Math.sqrt((e-t)*(e-t)+(i-n)*(i-n))/s}function b(t,r,o,e=!1){const i=Math.atan2(r.y-o.y,r.x-o.x)-Math.atan2(t.y-o.y,t.x-o.x),s=Math.atan2(Math.sin(i),Math.cos(i));return e?s:n(s)}function z(t,n,r,o){const e=[n,r];return t.length>2&&e.push(null!=o?o:t[2]),t.length>3&&e.push(t[3]),e}export{x as cloneMove,b as getRotationAngle,U as getScaleRatio,y as move,M as scale,h as screenDeltaToMapDelta};
