/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/floatRGBA","../../geometry/support/jsonUtils","./Rect"],(function(t,n,o,e){"use strict";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":{var n;const o=t.markerGraphics;if(!o||1!==o.length)return null;const e=o[0];if(!e)return null;const r=e.geometry;if(!r)return null;const l=e.symbol;return!l||"CIMPolygonSymbol"!==l.type&&"CIMLineSymbol"!==l.type||null!=(n=l.symbolLayers)&&n.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 e=o.symbol;return!e||"CIMPolygonSymbol"!==e.type&&"CIMLineSymbol"!==e.type?null:e}function i(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,o=-1/0,r=1/0,l=-1/0;for(const e of t)for(const t of e)t[0]<n&&(n=t[0]),t[0]>o&&(o=t[0]),t[1]<r&&(r=t[1]),t[1]>l&&(l=t[1]);return new e(n,r,o-n,l-r)}function f(t){let n=1/0,o=-1/0,e=1/0,r=-1/0;for(const l of t)for(const t of l)t[0]<n&&(n=t[0]),t[0]>o&&(o=t[0]),t[1]<e&&(e=t[1]),t[1]>r&&(r=t[1]);return[n,e,o,r]}function a(t){return t?t.rings?f(t.rings):t.paths?f(t.paths):o.isExtent(t)?[t.xmin,t.ymin,t.xmax,t.ymax]:null:null}function u(t,n,o,e,r){const[l,i,s,f]=t;if(s<l||f<i)return[0,0,0];const a=s-l,u=f-i,c=128,m=1,y=Math.floor(.5*(.5*c-m)),h=(c-2*(y+m))/Math.max(a,u),x=Math.round(a*h)+2*y,M=Math.round(u*h)+2*y;let g=1;if(n){g=M/h/(n.ymax-n.ymin)}let p=0,d=0;if(e)if(r){if(n&&o&&n.ymax-n.ymin>0){const t=(n.xmax-n.xmin)/(n.ymax-n.ymin);p=e.x/(o*t),d=e.y/o}}else p=e.x,d=e.y;p=.5*(n.xmax+n.xmin)+p*(n.xmax-n.xmin),d=.5*(n.ymax+n.ymin)+d*(n.ymax-n.ymin),p-=l,d-=i,p*=h,d*=h,p+=y,d+=y;return[g,p/x-.5,-(d/M-.5)]}function c(t){const n=i(t.geom),o=s(n),e=128,r=1,l=Math.floor(.5*(.5*e-r)),f=(e-2*(l+r))/Math.max(o.width,o.height),a=Math.round(o.width*f)+2*l,u=Math.round(o.height*f)+2*l,c=[];for(const i of n)if(i&&i.length>1){const n=[];for(const e of i){let[r,i]=e;r-=o.x,i-=o.y,r*=f,i*=f,r+=l-.5,i+=l-.5,t.asFill?n.push([r,i]):n.push([Math.round(r),Math.round(i)])}if(t.asFill){const t=n.length-1;n[0][0]===n[t][0]&&n[0][1]===n[t][1]||n.push(n[0])}c.push(n)}const x=m(c,a,u,l);return t.asFill&&y(c,a,u,l,x),[h(x,l),a,u]}function m(t,n,o,e){const r=n*o,l=new Array(r),i=e*e+1;for(let s=0;s<r;++s)l[s]=i;for(const s of t){const t=s.length;for(let r=1;r<t;++r){const t=s[r-1],i=s[r];let f,a,u,c;t[0]<i[0]?(f=t[0],a=i[0]):(f=i[0],a=t[0]),t[1]<i[1]?(u=t[1],c=i[1]):(u=i[1],c=t[1]);let m=Math.floor(f)-e,y=Math.floor(a)+e,h=Math.floor(u)-e,x=Math.floor(c)+e;m<0&&(m=0),y>n&&(y=n),h<0&&(h=0),x>o&&(x=o);const M=i[0]-t[0],g=i[1]-t[1],p=M*M+g*g;for(let e=m;e<y;e++)for(let r=h;r<x;r++){let s,f,a=(e-t[0])*M+(r-t[1])*g;a<0?(s=t[0],f=t[1]):a>p?(s=i[0],f=i[1]):(a/=p,s=t[0]+a*M,f=t[1]+a*g);const u=(e-s)*(e-s)+(r-f)*(r-f),c=(o-r-1)*n+e;u<l[c]&&(l[c]=u)}}}for(let s=0;s<r;++s)l[s]=Math.sqrt(l[s]);return l}function y(t,n,o,e,r){for(const l of t){const t=l.length;for(let i=1;i<t;++i){const t=l[i-1],s=l[i];let f,a,u,c;t[0]<s[0]?(f=t[0],a=s[0]):(f=s[0],a=t[0]),t[1]<s[1]?(u=t[1],c=s[1]):(u=s[1],c=t[1]);let m=Math.floor(f),y=Math.floor(a)+1,h=Math.floor(u),x=Math.floor(c)+1;m<e&&(m=e),y>n-e&&(y=n-e),h<e&&(h=e),x>o-e&&(x=o-e);for(let l=h;l<x;++l){if(t[1]>l==s[1]>l)continue;const i=(o-l-1)*n;for(let n=m;n<y;++n)n<(s[0]-t[0])*(l-t[1])/(s[1]-t[1])+t[0]&&(r[i+n]=-r[i+n]);for(let t=e;t<m;++t)r[i+t]=-r[i+t]}}}}function h(t,o){const e=2*o,r=t.length,l=new Uint8Array(4*r);for(let i=0;i<r;++i){const o=.5-t[i]/e;n.packFloatRGBA(o,l,4*i)}return l}t.buildSDF=c,t.getExtent=a,t.getSDFInfo=r,t.getSDFMetrics=u,t.getSDFSymbol=l,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
