12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{packFloatRGBA as t}from"../../core/floatRGBA.js";import{isExtent as o}from"../../geometry/support/jsonUtils.js";import n from"./Rect.js";function r(t){if(!t)return null;switch(t.type){case"CIMPointSymbol":{const o=t.symbolLayers;return o&&1===o.length?r(o[0]):null}case"CIMVectorMarker":{const o=t.markerGraphics;if(!o||1!==o.length)return null;const n=o[0];if(!n)return null;const r=n.geometry;if(!r)return null;const l=n.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){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 e(t){let o=1/0,r=-1/0,l=1/0,e=-1/0;for(const n of t)for(const t of n)t[0]<o&&(o=t[0]),t[0]>r&&(r=t[0]),t[1]<l&&(l=t[1]),t[1]>e&&(e=t[1]);return new n(o,l,r-o,e-l)}function s(t){let o=1/0,n=-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[0]>n&&(n=t[0]),t[1]<r&&(r=t[1]),t[1]>l&&(l=t[1]);return[o,r,n,l]}function i(t){return t?t.rings?s(t.rings):t.paths?s(t.paths):o(t)?[t.xmin,t.ymin,t.xmax,t.ymax]:null:null}function f(t,o,n,r,l){const[e,s,i,f]=t;if(i<e||f<s)return[0,0,0];const a=i-e,m=f-s,u=128,c=1,h=Math.floor(.5*(.5*u-c)),y=(u-2*(h+c))/Math.max(a,m),x=Math.round(a*y)+2*h,M=Math.round(m*y)+2*h;let g=1;if(o){g=M/y/(o.ymax-o.ymin)}let p=0,d=0,b=1;r&&(l?o&&n&&o.ymax-o.ymin>0&&(b=(o.xmax-o.xmin)/(o.ymax-o.ymin),p=r.x/(n*b),d=r.y/n):(p=r.x,d=r.y)),p=.5*(o.xmax+o.xmin)+p*(o.xmax-o.xmin),d=.5*(o.ymax+o.ymin)+d*(o.ymax-o.ymin),p-=e,d-=s,p*=y,d*=y,p+=h,d+=h;let w=p/x-.5,F=d/M-.5;return l&&(w*=n*b,F*=n),[g,w,F]}function a(t){const o=l(t.geom),n=e(o),r=128,s=1,i=Math.floor(.5*(.5*r-s)),f=(r-2*(i+s))/Math.max(n.width,n.height),a=Math.round(n.width*f)+2*i,h=Math.round(n.height*f)+2*i,y=[];for(const l of o)if(l&&l.length>1){const o=[];for(const r of l){let[l,e]=r;l-=n.x,e-=n.y,l*=f,e*=f,l+=i-.5,e+=i-.5,t.asFill?o.push([l,e]):o.push([Math.round(l),Math.round(e)])}if(t.asFill){const t=o.length-1;o[0][0]===o[t][0]&&o[0][1]===o[t][1]||o.push(o[0])}y.push(o)}const x=m(y,a,h,i);return t.asFill&&u(y,a,h,i,x),[c(x,i),a,h]}function m(t,o,n,r){const l=o*n,e=new Array(l),s=r*r+1;for(let i=0;i<l;++i)e[i]=s;for(const i of t){const t=i.length;for(let l=1;l<t;++l){const t=i[l-1],s=i[l];let f,a,m,u;t[0]<s[0]?(f=t[0],a=s[0]):(f=s[0],a=t[0]),t[1]<s[1]?(m=t[1],u=s[1]):(m=s[1],u=t[1]);let c=Math.floor(f)-r,h=Math.floor(a)+r,y=Math.floor(m)-r,x=Math.floor(u)+r;c<0&&(c=0),h>o&&(h=o),y<0&&(y=0),x>n&&(x=n);const M=s[0]-t[0],g=s[1]-t[1],p=M*M+g*g;for(let r=c;r<h;r++)for(let l=y;l<x;l++){let i,f,a=(r-t[0])*M+(l-t[1])*g;a<0?(i=t[0],f=t[1]):a>p?(i=s[0],f=s[1]):(a/=p,i=t[0]+a*M,f=t[1]+a*g);const m=(r-i)*(r-i)+(l-f)*(l-f),u=(n-l-1)*o+r;m<e[u]&&(e[u]=m)}}}for(let i=0;i<l;++i)e[i]=Math.sqrt(e[i]);return e}function u(t,o,n,r,l){for(const e of t){const t=e.length;for(let s=1;s<t;++s){const t=e[s-1],i=e[s];let f,a,m,u;t[0]<i[0]?(f=t[0],a=i[0]):(f=i[0],a=t[0]),t[1]<i[1]?(m=t[1],u=i[1]):(m=i[1],u=t[1]);let c=Math.floor(f),h=Math.floor(a)+1,y=Math.floor(m),x=Math.floor(u)+1;c<r&&(c=r),h>o-r&&(h=o-r),y<r&&(y=r),x>n-r&&(x=n-r);for(let e=y;e<x;++e){if(t[1]>e==i[1]>e)continue;const s=(n-e-1)*o;for(let o=c;o<h;++o)o<(i[0]-t[0])*(e-t[1])/(i[1]-t[1])+t[0]&&(l[s+o]=-l[s+o]);for(let t=r;t<c;++t)l[s+t]=-l[s+t]}}}}function c(o,n){const r=2*n,l=o.length,e=new Uint8Array(4*l);for(let s=0;s<l;++s){const n=.5-o[s]/r;t(n,e,4*s)}return e}export{a as buildSDF,i as getExtent,r as getSDFInfo,f as getSDFMetrics};
|