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","../2d/engine/webgl/Geometry","./GeometryUtils","./Conflict"],function(v,r,t,h,E){Object.defineProperty(r,"__esModule",{value:!0});v=function(){return function(c,a,e,b,f){void 0===e&&(e=0);void 0===b&&(b=-1);void 0===f&&(f=D);this.x=c;this.y=a;this.angle=e;this.segment=b;this.minzoom=f}}();r.Anchor=v;v=function(){return function(c,a,e,b){this.glyph=c;this.x=a;this.y=e;this.glyphItem=b}}();r.ShapedGlyph=v;var P=function(){return function(c,a,e,b,f,g,l){void 0===f&&(f=!1);
  void 0===g&&(g=D);void 0===l&&(l=h.C_INFINITY);this.anchor=c;this.labelAngle=a;this.glyphAngle=e;this.page=b;this.upsideDown=f;this.minzoom=g;this.maxzoom=l}}(),Q=function(){return function(c,a,e,b,f,g,l,h,t,w){this.tl=c;this.tr=a;this.bl=e;this.br=b;this.mosaicRect=f;this.labelAngle=g;this.anchor=l;this.minzoom=h;this.maxzoom=t;this.page=w}}();r.PlacedSymbol=Q;var R=function(){return function(h,a){this.footprint=h;this.shapes=a}}();r.Placement=R;var D=.5;v=function(){function c(){this.mapAngle=0;
  this._conflictEngine=new E.ConflictEngine}c.prototype.reset=function(){this._conflictEngine.reset()};c.prototype.setAngle=function(a){this.mapAngle=a;this._conflictEngine.setAngle(a)};c.prototype.getIconPlacement=function(a,e,b,f,g,l,c){var I=b.width/(b.sdfRatio*b.pixelRatio),w=b.height/(b.sdfRatio*b.pixelRatio);g=l.offset[0]-I/2;var C=l.offset[1]-w/2,I=g+I,w=C+w,x=b.rect,n=(b.sdf?17:2)/b.sdfRatio,d=g-n,k=C-n,m=d+x.width/(b.pixelRatio*b.sdfRatio),q=k+x.height/(b.pixelRatio*b.sdfRatio);b=new t.Point(d,
  k);n=new t.Point(m,q);q=new t.Point(d,q);k=new t.Point(m,k);m=l.rotate*h.C_DEG_TO_RAD;d=1===l.rotationAlignment;0<=a.segment&&!d&&(m+=a.angle);if(0!==m){var p=Math.cos(m),z=Math.sin(m);b.rotate(p,z);n.rotate(p,z);q.rotate(p,z);k.rotate(p,z)}p=8*l.padding;z=new t.Point(a.x,a.y);a=new E.Footprint(this.mapAngle,p,d);a.addBox(z,new E.Box(g,C,I,w),f,m,e,D,h.C_INFINITY);e=new Q(b,k,q,n,x,0,z,D,h.C_INFINITY,0);e=new R(a,[e]);f=D;l.allowOverlap||(f=this._conflictEngine.getMinZoom(e.footprint,f,c,d));a.minzoom=
  f;return e};c.prototype.getTextPlacement=function(a,e,b,f,g,l,c,I){for(var w=new t.Point(a.x,a.y),C=c.rotate*h.C_DEG_TO_RAD,x=0===c.rotationAlignment,n=c.keepUpright,d=D,k=!x,m=k?0:a.angle,q=0<=a.segment&&x,p=new E.Footprint(this.mapAngle,8*c.padding,k),z=[],v=!q,F=Number.POSITIVE_INFINITY,G=Number.NEGATIVE_INFINITY,r=F,K=G,da=q?n:x&&n,S,T=0;T<f.length;T++){var A=f[T],u=A.glyphItem;if(u&&!u.rect.isEmpty){var U=u.rect,H=u.metrics,B=u.page;v&&(S&&S!==A.y&&(p.addBox(w,new E.Box(F,r,G,K),g,C,e,D,h.C_INFINITY),
  F=Number.POSITIVE_INFINITY,G=Number.NEGATIVE_INFINITY,r=F,K=G),S=A.y);var J=[];if(q){if(u=(b.x+A.x+H.left-4+.5*u.metrics.width)*g,d=this._placeGlyph(a,d,u,l,a.segment,1,B,J),n&&(d=this._placeGlyph(a,d,u,l,a.segment,-1,B,J)),2<=d)break}else J.push(new P(w,m,m,B)),x&&n&&J.push(new P(w,m+h.C_PI,m+h.C_PI,B,!0));for(var B=A.x+b.x+H.left,A=A.y+b.y-H.top,u=B+H.width,H=A+H.height,L=new t.Point(B-4,A-4),V=new t.Point(L.x+U.width,L.y+U.height),ea=new t.Point(L.x,V.y),fa=new t.Point(V.x,L.y),W=0;W<J.length;W++){var y=
  J[W],Z=L.clone(),aa=ea.clone(),ba=fa.clone(),ca=V.clone(),X=A,Y=H,M=y.glyphAngle+C;if(0!==M){var N=Math.cos(M),O=Math.sin(M);Z.rotate(N,O);ca.rotate(N,O);aa.rotate(N,O);ba.rotate(N,O)}z.push(new Q(Z,ba,aa,ca,U,y.labelAngle,y.anchor,y.minzoom,y.maxzoom,y.page));if(!da||this._legible(y.labelAngle))v?(B<F&&(F=B),X<r&&(r=X),u>G&&(G=u),Y>K&&(K=Y)):2>y.minzoom&&p.addBox(y.anchor,new E.Box(B,X,u,Y),g,M,e,y.minzoom,y.maxzoom)}}}if(2<=d)return null;v&&p.addBox(w,new E.Box(F,r,G,K),g,C,e,D,h.C_INFINITY);a=
  new R(p,z);c.allowOverlap||(d=this._conflictEngine.getMinZoom(a.footprint,d,I,k));p.minzoom=d;return a};c.prototype.add=function(a){this._conflictEngine.add(a.footprint)};c.prototype._legible=function(a){a=h.radToByte(a);return 65>a||193<=a};c.prototype._placeGlyph=function(a,c,b,f,g,l,r,v){var e=0>l?h.positiveMod(a.angle+h.C_PI,h.C_2PI):a.angle,C=this._legible(e),x=0;0>b&&(l*=-1,b*=-1,x=h.C_PI);0<l&&++g;a=new t.Point(a.x,a.y);var n=f[g],d=h.C_INFINITY;if(f.length<=g)return d;for(;;){var k=n.x-a.x,
  m=n.y-a.y,q=Math.sqrt(k*k+m*m),p=Math.max(b/q,c),k=h.positiveMod(Math.atan2(m/q,k/q)+x,h.C_2PI);v.push(new P(a,e,k,r,C,p,d));if(p<=c)return p;a=n.clone();do{g+=l;if(f.length<=g||0>g)return p;n=f[g]}while(a.isEqual(n));d=n.x-a.x;k=n.y-a.y;m=Math.sqrt(d*d+k*k);d*=q/m;k*=q/m;a.x-=d;a.y-=k;d=p}};return c}();r.PlacementEngine=v});