/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../core/maybe","../../../../core/screenUtils","../../../../chunks/mat3","../../../../chunks/mat3f32","../../../../chunks/vec2f32","../../../../chunks/vec3f32","../../../../geometry/support/normalizeUtils","../../../../geometry/support/spatialReferenceUtils","../../viewpointUtils","../brushes","./enums","./WGLContainer"],(function(e,t,r,s,a,o,i,n,c,l,u,d,h){"use strict";let p=function(h){function p(){var e;return(e=h.apply(this,arguments)||this)._localOrigin=r.createScreenPoint(0,0),e._viewStateId=-1,e._dvsMat3=a.create(),e.requiresDedicatedFBO=!1,e}e._inheritsLoose(p,h);var f=p.prototype;return f.beforeRender=function(e){this._updateMatrices(e),this._updateOverlays(e,this.children);for(const t of this.children)t.beforeRender(e)},f.prepareRenderPasses=function(e){const t=e.registerRenderPass({name:"overlay",brushes:[u.brushes.overlay],target:()=>this.children,drawPhase:d.WGLDrawPhase.MAP});return[...h.prototype.prepareRenderPasses.call(this,e),t]},f._updateMatrices=function(e){const{state:t}=e,{id:r,size:a,pixelRatio:c,resolution:l,rotation:u,viewpoint:d,displayMat3:h}=t;if(this._viewStateId===r)return;const p=Math.PI/180*u,f=c*a[0],v=c*a[1],{x:y,y:M}=d.targetGeometry,_=n.normalizeMapX(y,t.spatialReference);this._localOrigin.x=_,this._localOrigin.y=M;const m=l*f,g=l*v,w=s.identity(this._dvsMat3);s.multiply(w,w,h),s.translate(w,w,o.fromValues(f/2,v/2)),s.scale(w,w,i.fromValues(f/m,-v/g,1)),s.rotate(w,w,-p),this._viewStateId=r},f._updateOverlays=function(e,r){const{state:s}=e,{rotation:a,spatialReference:o,worldScreenWidth:i,size:n,viewpoint:u}=s,d=this._localOrigin;let h=0;if(o.isWrappable){const e=n[0],p=n[1],f=180/Math.PI*a,v=Math.abs(Math.cos(f)),y=Math.abs(Math.sin(f)),M=Math.round(e*v+p*y),[_,m]=c.getInfo(o).valid,g=l.getWorldWidth(o),{x:w,y:b}=u.targetGeometry,P=[w,b],R=[0,0];s.toScreen(R,P);const O=[0,0];let k;k=M>i?.5*i:.5*M;const C=Math.floor((w+.5*g)/g),D=_+C*g,I=m+C*g,S=[R[0]+k,0];s.toMap(O,S),O[0]>I&&(h=g),S[0]=R[0]-k,s.toMap(O,S),O[0]<D&&(h=-g);for(const s of r){const e=s.elementView.bounds;if(t.isNone(e))continue;const[r,,a]=e;r<_&&a>_?s.updateDrawCoords(d,g):a>m&&r<m?s.updateDrawCoords(d,-g):s.updateDrawCoords(d,h)}}else for(const t of r)t.updateDrawCoords(d,h)},e._createClass(p,[{key:"dvsMat3",get:function(){return this._dvsMat3}}]),p}(h);return p}));
