/*
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/RandomLCG","../CIMPlacements","../enums"],(function(t,i,s,e){"use strict";function n(t){return void 0!==t.rings}let h=function(){function t(){}return t.local=function(){return null===t.instance&&(t.instance=new t),t.instance},t.prototype.execute=function(t,i,s,e){return new _(t,i,s,e)},t}();h.instance=null;let _=function(){function t(t,h,_,r){var o,a,l;if(this._xMin=0,this._xMax=0,this._yMin=0,this._yMax=0,this._currentX=0,this._currentY=0,this._stepX=Math.abs(null!=(o=h.stepX)?o:16)*_,this._stepY=Math.abs(null!=(a=h.stepY)?a:16)*_,0!==this._stepX&&0!==this._stepY&&t&&n(t)&&t.rings){if(this._gridType=null!=(l=h.gridType)?l:e.PlacementGridType.Fixed,this._gridType===e.PlacementGridType.Random){var f,c;const t=null!=(f=h.seed)?f:13,s=1;this._randomLCG=new i(t*s),this._randomness=(null!=(c=h.randomness)?c:100)/100,this._gridAngle=0,this._shiftOddRows=!1,this._cosAngle=1,this._sinAngle=0,this._offsetX=0,this._offsetY=0}else{var g,u,p,d;if(this._randomness=0,this._gridAngle=null!=(g=h.gridAngle)?g:0,this._shiftOddRows=null!=(u=h.shiftOddRows)&&u,this._offsetX=(null!=(p=h.offsetX)?p:0)*_,this._offsetY=(null!=(d=h.offsetY)?d:0)*_,this._cosAngle=Math.cos(this._gridAngle/180*Math.PI),this._sinAngle=-Math.sin(this._gridAngle/180*Math.PI),this._stepX)if(this._offsetX<0)for(;this._offsetX<-.5*this._stepX;)this._offsetX+=this._stepX;else for(;this._offsetX>=.5*this._stepX;)this._offsetX-=this._stepX;if(this._stepY)if(this._offsetY<0)for(;this._offsetY<-.5*this._stepY;)this._offsetY+=this._stepY;else for(;this._offsetY>=.5*this._stepY;)this._offsetY-=this._stepY}this._graphicOriginX=0,this._graphicOriginY=0,this._internalPlacement=new s.Placement,this._calculateMinMax(t),this._geometry=t}}var h=t.prototype;return h.next=function(){return this._geometry?this._nextInside():null},h._calculateMinMax=function(t){let i,s,e,n,h,_,r,o;this._xMin=0,this._xMax=0,this._yMin=0,this._yMax=0,h=_=Number.MAX_VALUE,r=o=-Number.MAX_VALUE;for(const a of t.rings){const t=a?a.length:0;for(let l=0;l<t;++l)i=a[l][0]-this._graphicOriginX-this._offsetX,s=a[l][1]-this._graphicOriginY-this._offsetY,e=this._cosAngle*i-this._sinAngle*s,n=this._sinAngle*i+this._cosAngle*s,h=Math.min(h,e),r=Math.max(r,e),_=Math.min(_,n),o=Math.max(o,n)}h+=this._graphicOriginX,r+=this._graphicOriginX,_+=this._graphicOriginY,o+=this._graphicOriginY,this._xMin=Math.round(h/this._stepX),this._xMax=Math.round(r/this._stepX),this._yMin=Math.round(_/this._stepY),this._yMax=Math.round(o/this._stepY),this._currentX=this._xMax+1,this._currentY=this._yMin-1},h._nextInside=function(){for(;;){if(this._currentX>this._xMax){if(this._currentY++,this._currentY>this._yMax)return null;this._currentX=this._xMin,this._shiftOddRows&&this._currentY%2&&this._currentX--}let t=this._currentX*this._stepX+this._offsetX;this._shiftOddRows&&this._currentY%2&&(t+=.5*this._stepX);const i=this._currentY*this._stepY+this._offsetY;let s,n;return this._currentX++,this._gridType===e.PlacementGridType.Random?(s=this._graphicOriginX+t+this._stepX*this._randomness*(.5-this._randomLCG.getFloat())*2/3,n=this._graphicOriginY+i+this._stepY*this._randomness*(.5-this._randomLCG.getFloat())*2/3):(s=this._graphicOriginX+this._cosAngle*t+this._sinAngle*i,n=this._graphicOriginY-this._sinAngle*t+this._cosAngle*i),this._internalPlacement.setTranslate(s,n),this._internalPlacement}},t}();t.PlacementInsidePolygon=h,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
