/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as t}from"tslib";import i from"../../Viewpoint.js";import{JSONSupport as e}from"../../core/JSONSupport.js";import{property as s,subclass as o}from"../../core/accessorSupport/decorators.js";import{toRadian as r}from"../../core/libs/gl-matrix-2/math/common.js";import{fromTranslation as a,rotate as n,translate as p,invert as h}from"../../core/libs/gl-matrix-2/math/mat2d.js";import{create as l}from"../../core/libs/gl-matrix-2/factories/mat2df32.js";import{create as m}from"../../core/libs/gl-matrix-2/factories/mat2df64.js";import{set as c,identity as f,translate as v,rotate as w,multiply as d}from"../../core/libs/gl-matrix-2/math/mat3.js";import{create as x}from"../../core/libs/gl-matrix-2/factories/mat3f32.js";import{copy as u,transformMat2d as y}from"../../core/libs/gl-matrix-2/math/vec2.js";import{fromValues as g}from"../../core/libs/gl-matrix-2/factories/vec2f32.js";import{create as R}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{isVec2 as j}from"../../core/libs/gl-matrix-2/types/vec2.js";import _ from"../../geometry/Extent.js";import M from"../../geometry/Point.js";import{getClosestDenormalizedXToReference as z}from"../../geometry/support/normalizeUtils.js";import{copy as b,getWorldWidth as S,getMatrix as N,getResolution as T,getExtent as D,getTransform as V,getTransformNoRotation as A,getWorldScreenWidth as O}from"./viewpointUtils.js";var W;const C=[0,0];let G=W=class extends e{constructor(t){super(t),this._viewpoint2D={center:R(),rotation:0,scale:0,spatialReference:void 0},this.center=[0,0],this.extent=new _,this.id=0,this.inverseTransform=m(),this.resolution=0,this.rotation=0,this.scale=0,this.transform=m(),this.transformNoRotation=m(),this.displayMat3=x(),this.displayViewMat3=x(),this.viewMat3=x(),this.viewMat2d=l(),this.worldScreenWidth=0,this.size=[0,0]}set pixelRatio(t){this._set("pixelRatio",t),this._update()}set size(t){this._set("size",t),this._update()}set viewpoint(t){if(t){const i=this._viewpoint2D,e=t.targetGeometry;i.center[0]=e.x,i.center[1]=e.y,i.rotation=t.rotation,i.scale=t.scale,i.spatialReference=e.spatialReference}this._update()}get visibleArea(){const[t,i]=this.size;return[this.toMap([0,0],0,0),this.toMap([0,0],0,i),this.toMap([0,0],t,i),this.toMap([0,0],t,0)]}copy(t){const i=this.size,e=this.viewpoint;return e&&i?(this.viewpoint=b(e,t.viewpoint),this._set("size",u(i,t.size))):(this.viewpoint=t.viewpoint.clone(),this._set("size",[t.size[0],t.size[1]])),this._set("pixelRatio",t.pixelRatio),this}clone(){return new W({size:this.size,viewpoint:this.viewpoint.clone(),pixelRatio:this.pixelRatio})}toMap(t,i,e){return j(i)?y(t,i,this.inverseTransform):(C[0]=i,C[1]=e,y(t,C,this.inverseTransform))}toScreen(t,i,e){return j(i)?y(t,i,this.transform):(C[0]=i,C[1]=e,y(t,C,this.transform))}toScreenNoRotation(t,i,e){return j(i)?y(t,i,this.transformNoRotation):(C[0]=i,C[1]=e,y(t,C,this.transformNoRotation))}wrapMapCoordinate(t,i){u(t,i);const[e]=i,[s]=this.center,{extent:o,spatialReference:r}=this;let{xmin:a,xmax:n}=o;if(r.isWrappable){const t=S(r)/2;a=Math.max(a,s-t),n=Math.min(n,s+t)}return(e<a||e>n)&&(t[0]=z(e,s,r)),t}getScreenTransform(t,i){const{center:e}=this._viewpoint2D,s=this._get("pixelRatio")||1,o=this._get("size");return N(t,e,o,i,0,s),t}_update(){const{center:t,spatialReference:e,scale:s,rotation:o}=this._viewpoint2D,l=this._get("pixelRatio")||1,m=this._get("size"),x=new i({targetGeometry:new M(t[0],t[1],e),scale:s,rotation:o});if(this._set("viewpoint",x),!m||!e||!s)return;this.resolution=T(x),this.rotation=o,this.scale=s,this.spatialReference=e,u(this.center,t);const y=0!==m[0]?2/m[0]:0,R=0!==m[1]?-2/m[1]:0;c(this.displayMat3,y,0,0,0,R,0,-1,1,1);const j=f(this.viewMat3),_=g(m[0]/2,m[1]/2),z=g(-m[0]/2,-m[1]/2),b=r(o);v(j,j,_),w(j,j,b),v(j,j,z),d(this.displayViewMat3,this.displayMat3,j);const S=a(this.viewMat2d,_);return n(S,S,b),p(S,S,z),D(this.extent,x,m),V(this.transform,x,m,l),h(this.inverseTransform,this.transform),A(this.transformNoRotation,x,m,l),this.worldScreenWidth=O(this.spatialReference,this.resolution),this._set("id",this.id+1),this.notifyChange("visibleArea"),this}};t([s({readOnly:!0})],G.prototype,"id",void 0),t([s({value:1,json:{write:!0}})],G.prototype,"pixelRatio",null),t([s({json:{write:!0}})],G.prototype,"size",null),t([s()],G.prototype,"spatialReference",void 0),t([s({type:i,json:{write:!0}})],G.prototype,"viewpoint",null),t([s({readOnly:!0})],G.prototype,"visibleArea",null),G=W=t([o("esri.views.2d.ViewState")],G);const U=G;export{U as default};
