/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{clone as m}from"../../core/lang.js";import{getExtent as e}from"./SDFHelper.js";import{EffectHelper as r}from"./effects/EffectHelper.js";const a=.01;function t(t){if(!t.frame)return t;const{markerGraphics:f}=t;if(!f||0===f.length)return t;let n=0,o=0,s=0,i=0;for(const m of f){const{geometry:a,symbol:t}=m;if(!a||!t||!("symbolLayers"in t))continue;const{symbolLayers:f}=t;if(f)for(const m of f){const{effects:t}=m,f=r.applyEffects(t,a),c=e(f);c&&(n=Math.min(n,c[0]),o=Math.min(o,c[1]),s=Math.max(s,c[2]),i=Math.max(i,c[3]))}}const{xmin:c,ymin:x,xmax:y,ymax:p}=t.frame,h=(y-c)/2,l=(p-x)/2,M=(y+c)/2,u=(p+x)/2;if(h<=0||l<=0)return t;const b=(M-n)/h,g=(s-M)/h,j=(u-o)/l,E=(i-u)/l,F=Math.max(Math.max(b,g),Math.max(j,E));return F<=1+a?t:(t=m(t)).frame?(t.frame.xmin=(t.frame.xmin-M)*F+M,t.frame.ymin=(t.frame.ymin-u)*F+u,t.frame.xmax=(t.frame.xmax-M)*F+M,t.frame.ymax=(t.frame.ymax-u)*F+u,!1!==t.respectFrame&&(t.size*=F),t):t}export{t as fitVectorMarker};
