text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.6/esri/copyright.txt for details.
  //>>built
  define("require exports ../webgl/Texture ../2d/engine/webgl/Geometry ./Rect ./GeometryUtils ./RectangleBinPack".split(" "),function(J,K,H,I,E,F,D){function w(d){return d-Math.floor(d)}function G(d,a,c){0>d?d=0:.9999991<d&&(d=.9999991);var b=w(d*z[0]),g=w(d*z[1]),p=w(d*z[2]);d=w(d*z[3]);a[c+0]=256*(b-b*C[0]);a[c+1]=256*(g-b*C[1]);a[c+2]=256*(p-g*C[2]);a[c+3]=256*(d-p*C[3])}var z=[16777216,65536,256,1],C=[0,1/256,1/256,1/256];return function(){function d(a,c,b){void 0===b&&(b=0);this._size=[];this._mosaicsData=
  [];this._textures=[];this._dirties=[];this._pageHeight=this._pageWidth=this._currentPage=this._maxItemSize=0;this._mosaicRects={};this.pixelRatio=1;(0>=a||0>=c)&&console.error("Sprites mosaic defaultWidth and defaultHeight must be greater than zero!");this._pageWidth=a;this._pageHeight=c;0<b&&(this._maxItemSize=b);this._binPack=new D(a-4,c-4)}d.prototype.getWidth=function(a){return a>=this._size.length?-1:this._size[a][0]};d.prototype.getHeight=function(a){return a>=this._size.length?-1:this._size[a][1]};
  d.prototype.setSpriteSource=function(a){this.dispose();this.pixelRatio=a.devicePixelRatio;if(0===this._mosaicsData.length){this._binPack=new D(this._pageWidth-4,this._pageHeight-4);var c=new Uint32Array(Math.floor(this._pageWidth)*Math.floor(this._pageHeight));this._mosaicsData[0]=c;this._dirties.push(!0);this._size.push([this._pageWidth,this._pageHeight]);this._textures.push(void 0)}this._sprites=a};d.prototype.getSpriteItem=function(a,c){void 0===c&&(c=!1);var b=this._mosaicRects[a];if(b)return b;
  if(!this._sprites||"loaded"!==this._sprites.loadStatus)return null;b=this._sprites.getSpriteInfo(a);if(!b||!b.width||!b.height||0>b.width||0>b.height)return null;var g=b.width,p=b.height,k,f=1;if(b.cim){f=this._buildSDF(b.cim);k=f[0];var h=f[1],d=f[2],l=f[3],e=f[4],f=f[5];if(!k||0>=l||0>=e)return null;var m=this._allocateImage(h,d),e=m[0],l=m[1],m=m[2];if(0>=e.width)return null;(b.cim||b.sdf)&&this._clearRect(e,l,m,1);this._copy(e,{width:h,height:d,x:0,y:0},l,m,c,k);e.x+=4;e.y+=4;e.width-=8;e.height-=
  8;c=e;k=l;f*=.75;f=d/p;b.sdf=!0}else{d=this._allocateImage(g,p);e=d[0];l=d[1];m=d[2];if(0>=e.width)return null;this._copy(e,b,l,m,c);c=e;k=l}b={rect:c,width:g,height:p,sdf:b.sdf,pixelRatio:b.pixelRatio,page:k,sdfRatio:f};return this._mosaicRects[a]=b};d.prototype.preloadSpriteItems=function(){for(var a=0,c=this._sprites.spriteNames;a<c.length;a++)this.getSpriteItem(c[a],!0)};d.prototype.getSpriteItems=function(a){for(var c={},b=0;b<a.length;b++){var g=a[b];c[g]=this.getSpriteItem(g)}return c};d.prototype.getMosaicItemPosition=
  function(a,c){c=(a=this.getSpriteItem(a,c))&&a.rect;if(!c)return null;c.width=a.width;c.height=a.height;return{size:[a.width,a.height],tl:[(c.x+2)/this._size[a.page][0],(c.y+2)/this._size[a.page][1]],br:[(c.x+2+a.width)/this._size[a.page][0],(c.y+2+a.height)/this._size[a.page][1]],page:a.page}};d.prototype.bind=function(a,c,b,g){void 0===b&&(b=0);void 0===g&&(g=0);this._textures[b]||(this._textures[b]=new H(a,{pixelFormat:6408,dataType:5121,width:this._size[b][0],height:this._size[b][1]},new Uint8Array(this._mosaicsData[b].buffer)));
  var p=this._textures[b];p.setSamplingMode(c);this._dirties[b]&&p.setData(new Uint8Array(this._mosaicsData[b].buffer));a.bindTexture(p,g);this._dirties[b]=!1};d._copyBits=function(a,c,b,g,p,d,f,h,n,l,e){var k=g*c+b;f=h*d+f;if(e)for(f-=d,e=-1;e<=l;e++,k=((e+l)%l+g)*c+b,f+=d)for(h=-1;h<=n;h++)p[f+h]=a[k+(h+n)%n];else for(e=0;e<l;e++){for(h=0;h<n;h++)p[f+h]=a[k+h];k+=c;f+=d}};d.prototype._copy=function(a,c,b,g,p,k){if(this._sprites&&"loaded"===this._sprites.loadStatus&&!(b>=this._mosaicsData.length)){var f=
  new Uint32Array(k?k.buffer:this._sprites.image.buffer),h=this._mosaicsData[b];h&&f||console.error("Source or target images are uninitialized!");d._copyBits(f,k?c.width:this._sprites.width,c.x,c.y,h,g[0],a.x+2,a.y+2,c.width,c.height,p);this._dirties[b]=!0}};d.prototype._allocateImage=function(a,c){a+=2;c+=2;var b=Math.max(a,c);if(this._maxItemSize&&this._maxItemSize<b){var b=Math.pow(2,Math.ceil(F.log2(a))),g=Math.pow(2,Math.ceil(F.log2(c)));a=new E(0,0,a,c);this._mosaicsData.push(new Uint32Array(b*
  g));this._dirties.push(!0);this._size.push([b,g]);this._textures.push(void 0);return[a,this._mosaicsData.length-1,[b,g]]}b=a%4?4-a%4:4;g=c%4?4-c%4:4;1===b&&(b=5);1===g&&(g=5);b=this._binPack.allocate(a+b,c+g);return 0>=b.width?(this._dirties[this._currentPage]||(this._mosaicsData[this._currentPage]=null),this._currentPage=this._mosaicsData.length,this._mosaicsData.push(new Uint32Array(this._pageWidth*this._pageHeight)),this._dirties.push(!0),this._size.push([this._pageWidth,this._pageHeight]),this._textures.push(void 0),
  this._binPack=new D(this._pageWidth-4,this._pageHeight-4),this._allocateImage(a,c)):[b,this._currentPage,[this._pageWidth,this._pageHeight]]};d.prototype._clearRect=function(a,c,b,g){(c=this._mosaicsData[c])||console.error("Source image is uninitialized!");var d=[0,0,0,0];G(g,d,0);g=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|d[3]<<24;b=b[0];var d=a.y*b+a.x,k=a.width;a=a.height;for(var f=0;f<a;f++){for(var h=0;h<k;h++)c[d+h]=g;d+=b}};d.prototype.dispose=function(){this._binPack=null;this._mosaicRects={};
  for(var a=0,c=this._textures;a<c.length;a++){var b=c[a];b&&b.dispose()}this._textures.length=0};d.prototype._extractGeometry=function(a){if(!a)return null;a=a.symbolLayers;if(!a||1!==a.length)return null;a=a[0];if(!a)return null;a=a.markerGraphics;if(!a||1!==a.length)return null;a=a[0];if(!a)return null;var c=a.geometry;if(!c||!c.rings)return null;a=[];for(var b=0,c=c.rings;b<c.length;b++){for(var g=[],d=0,k=c[b];d<k.length;d++){var f=k[d];g.push(new I.Point(f[0],f[1]))}a.push(g)}return a};d.prototype._getEnvelope=
  function(a){for(var c=Infinity,b=-Infinity,g=Infinity,d=-Infinity,k=0;k<a.length;k++)for(var f=0,h=a[k];f<h.length;f++){var n=h[f];n.x<c&&(c=n.x);n.x>b&&(b=n.x);n.y<g&&(g=n.y);n.y>d&&(d=n.y)}return new E(c,g,b-c,d-g)};d.prototype._buildSDF=function(a){a=this._extractGeometry(a);if(!a)return null;var c=this._getEnvelope(a);if(0>=c.width||0>=c.height)return null;for(var b=86/Math.max(c.width,c.height),d=Math.round(c.width*b),p=Math.round(c.height*b),k=d+32,f=p+32,h=0;h<a.length;h++)for(var n=0,l=a[h];n<
  l.length;n++){var e=l[n];e.x-=c.x;e.y-=c.y;e.x*=b;e.y*=b;e.x+=15.5;e.y+=15.5}c=this._dist_map(a,k,f,16);this._sign_dist_map(a,k,f,16,c);return[this._encodeDistMap(c),k,f,d,p,b]};d.prototype._dist_map=function(a,c,b,d){for(var g=c*b,k=new Float32Array(g),f=d*d+1,h=0;h<g;++h)k[h]=f;for(f=0;f<a.length;f++)for(var n=a[f],l=n.length,h=1;h<l;++h){var e=n[h-1],m=n[h],t=void 0,q=void 0;e.x<m.x?(t=e.x,q=m.x):(t=m.x,q=e.x);var u=void 0,v=void 0;e.y<m.y?(u=e.y,v=m.y):(u=m.y,v=e.y);var r=Math.floor(t)-d,q=Math.floor(q)+
  d,u=Math.floor(u)-d,v=Math.floor(v)+d;0>r&&(r=0);q>c&&(q=c);0>u&&(u=0);v>b&&(v=b);for(var t=m.x-e.x,w=m.y-e.y,z=t*t+w*w;r<q;r++)for(var A=u;A<v;A++){var x=(r-e.x)*t+(A-e.y)*w,y=void 0,B=void 0;0>x?(y=e.x,B=e.y):x>z?(y=m.x,B=m.y):(x/=z,y=e.x+x*t,B=e.y+x*w);x=(r-y)*(r-y)+(A-B)*(A-B);y=(b-A-1)*c+r;x<k[y]&&(k[y]=x)}}for(h=0;h<g;++h)k[h]=Math.sqrt(k[h]);return k};d.prototype._sign_dist_map=function(a,c,b,d,p){for(var g=0;g<a.length;g++)for(var f=a[g],h=f.length,n=1;n<h;++n){var l=f[n-1],e=f[n],m=void 0,
  t=void 0;l.x<e.x?(m=l.x,t=e.x):(m=e.x,t=l.x);var q=void 0,u=void 0;l.y<e.y?(q=l.y,u=e.y):(q=e.y,u=l.y);m=Math.floor(m);t=Math.floor(t)+1;q=Math.floor(q);u=Math.floor(u)+1;m<d&&(m=d);t>c-d&&(t=c-d);q<d&&(q=d);for(u>b-d&&(u=b-d);q<u;++q)if(l.y>q!==e.y>q){for(var v=(b-q-1)*c,r=m;r<t;++r)r<(e.x-l.x)*(q-l.y)/(e.y-l.y)+l.x&&(p[v+r]=-p[v+r]);for(r=d;r<m;++r)p[v+r]=-p[v+r]}}};d.prototype._encodeDistMap=function(a){for(var c=a.length,b=new Uint8Array(4*c),d=0;d<c;++d)G(a[d]/16+.5,b,4*d);return b};return d}()});