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