/*
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/maybe","../../../../chunks/common","../../../../chunks/mat3","../../../../chunks/mat3f32","../../../../chunks/vec2f64","../../../../chunks/vec3","../../../../chunks/vec3f64","./VertexStream","./shaders/StencilPrograms","../../../webgl/enums","../../../webgl/ProgramTemplate"],(function(t,e,i,n,s,r,a,o,c,h,d,l){"use strict";const u=r.fromValues(-.5,-.5);let _=function(){function t(){this._centerNdc=o.create(),this._pxToNdc=o.create(),this._worldDimensionsPx=o.create(),this._mat3=s.create(),this._initialized=!1}var r=t.prototype;return r.dispose=function(){this._program=e.disposeMaybe(this._program),this._quad=e.disposeMaybe(this._quad)},r.render=function(t,e){const{context:i}=t;return!!this._updateGeometry(t,e)&&(this._initialized||this._initialize(i),i.setDepthWriteEnabled(!1),i.setDepthTestEnabled(!1),i.setColorMask(!1,!1,!1,!1),i.setBlendingEnabled(!1),i.setStencilOp(d.StencilOperation.KEEP,d.StencilOperation.KEEP,d.StencilOperation.REPLACE),i.setStencilFunction(d.CompareFunction.ALWAYS,1,255),i.setStencilTestEnabled(!0),i.useProgram(this._program),this._program.setUniformMatrix3fv("u_worldExtent",this._mat3),this._quad.draw(),this._quad.unbind(),!0)},r._initialize=function(t){if(this._initialized)return;const e=l.createProgram(t,h.stencil);e&&(this._program=e,this._quad=new c(t,[0,0,1,0,0,1,1,1]),this._initialized=!0)},r._updateGeometry=function(t,e){const{state:s,pixelRatio:r}=t,{size:o,rotation:c}=s,h=Math.round(o[0]*r),d=Math.round(o[1]*r);if(!s.spatialReference.isWrappable)return!1;const l=i.toRadian(c),_=Math.abs(Math.cos(l)),m=Math.abs(Math.sin(l)),p=Math.round(h*_+d*m),f=Math.round(s.worldScreenWidth);if(p<=f)return!1;const b=h*m+d*_,g=f*r,M=(e.left-e.right)*r/h,x=(e.bottom-e.top)*r/d;a.set(this._worldDimensionsPx,g,b,1),a.set(this._pxToNdc,2/h,-2/d,1),a.set(this._centerNdc,M,x,1);const E=this._mat3;return n.fromTranslation(E,this._centerNdc),n.scale(E,E,this._pxToNdc),0!==c&&n.rotate(E,E,l),n.scale(E,E,this._worldDimensionsPx),n.translate(E,E,u),!0},t}();t.WorldExtentClipRenderer=_,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
