/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import{packFloatRGBA as t}from"../../core/floatRGBA.js";import{isExtent as n}from"../../geometry/support/jsonUtils.js";import o from"./Rect.js";function r(t){if(!t)return null;switch(t.type){case"CIMPointSymbol":{const n=t.symbolLayers;return n&&1===n.length?r(n[0]):null}case"CIMVectorMarker":{const n=t.markerGraphics;if(!n||1!==n.length)return null;const o=n[0];if(!o)return null;const r=o.geometry;if(!r)return null;const l=o.symbol;return!l||"CIMPolygonSymbol"!==l.type&&"CIMLineSymbol"!==l.type||l.symbolLayers?.some((t=>!!t.effects))?null:{geom:r,asFill:"CIMPolygonSymbol"===l.type}}case"sdf":return{geom:t.geom,asFill:t.asFill}}return null}function l(t){const n=t.markerGraphics;if(!n||1!==n.length)return null;const o=n[0];if(!o)return null;const r=o.symbol;return!r||"CIMPolygonSymbol"!==r.type&&"CIMLineSymbol"!==r.type?null:r}function e(t){return t?t.rings?t.rings:t.paths?t.paths:void 0!==t.xmin&&void 0!==t.ymin&&void 0!==t.xmax&&void 0!==t.ymax?[[[t.xmin,t.ymin],[t.xmin,t.ymax],[t.xmax,t.ymax],[t.xmax,t.ymin],[t.xmin,t.ymin]]]:null:null}function s(t){let n=1/0,r=-1/0,l=1/0,e=-1/0;for(const o of t)for(const t of o)t[0]r&&(r=t[0]),t[1]e&&(e=t[1]);return new o(n,l,r-n,e-l)}function i(t){let n=1/0,o=-1/0,r=1/0,l=-1/0;for(const e of t)for(const t of e)t[0]o&&(o=t[0]),t[1]l&&(l=t[1]);return[n,r,o,l]}function f(t){return t?t.rings?i(t.rings):t.paths?i(t.paths):n(t)?[t.xmin,t.ymin,t.xmax,t.ymax]:null:null}function m(t,n,o,r,l){const[e,s,i,f]=t;if(i0){const t=(n.xmax-n.xmin)/(n.ymax-n.ymin);p=r.x/(o*t),d=r.y/o}}else p=r.x,d=r.y;p=.5*(n.xmax+n.xmin)+p*(n.xmax-n.xmin),d=.5*(n.ymax+n.ymin)+d*(n.ymax-n.ymin),p-=e,d-=s,p*=h,d*=h,p+=y,d+=y;return[g,p/x-.5,-(d/M-.5)]}function a(t){const n=e(t.geom),o=s(n),r=128,l=1,i=Math.floor(.5*(.5*r-l)),f=(r-2*(i+l))/Math.max(o.width,o.height),m=Math.round(o.width*f)+2*i,a=Math.round(o.height*f)+2*i,h=[];for(const e of n)if(e&&e.length>1){const n=[];for(const r of e){let[l,e]=r;l-=o.x,e-=o.y,l*=f,e*=f,l+=i-.5,e+=i-.5,t.asFill?n.push([l,e]):n.push([Math.round(l),Math.round(e)])}if(t.asFill){const t=n.length-1;n[0][0]===n[t][0]&&n[0][1]===n[t][1]||n.push(n[0])}h.push(n)}const x=u(h,m,a,i);return t.asFill&&c(h,m,a,i,x),[y(x,i),m,a]}function u(t,n,o,r){const l=n*o,e=new Array(l),s=r*r+1;for(let i=0;in&&(y=n),h<0&&(h=0),x>o&&(x=o);const M=s[0]-t[0],g=s[1]-t[1],p=M*M+g*g;for(let r=c;rp?(i=s[0],f=s[1]):(m/=p,i=t[0]+m*M,f=t[1]+m*g);const a=(r-i)*(r-i)+(l-f)*(l-f),u=(o-l-1)*n+r;an-r&&(y=n-r),ho-r&&(x=o-r);for(let e=h;ee==i[1]>e)continue;const s=(o-e-1)*n;for(let n=c;n