/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as t}from"tslib";import{rad2deg as e,scale as r}from"../../core/mathUtils.js";import{createScreenPoint as o}from"../../core/screenUtils.js";import{property as n,subclass as s}from"../../core/accessorSupport/decorators.js";import{toRadian as i}from"../../core/libs/gl-matrix-2/math/common.js";import l from"../../geometry/Extent.js";import a from"../../geometry/Polygon.js";import{projectOrLoad as m}from"../../geometry/projectionUtils.js";import c from"./GeoreferenceBase.js";let x=class extends c{constructor(t){super(t),this.extent=null,this.rotation=0,this.type="extent-and-rotation"}get coords(){if(null==this.extent)return null;const{xmin:t,ymin:e,xmax:r,ymax:o,spatialReference:n}=this.extent;let s;if(this.rotation){const{x:n,y:i}=this.extent.center,l=p(n,i,this.rotation);s=[l(t,e),l(t,o),l(r,o),l(r,e)],s.push(s[0])}else s=[[t,e],[t,o],[r,o],[r,e],[t,e]];return new a({rings:[s],spatialReference:n})}set coords(t){if(null==t||null==this.extent)return;const r=this.extent.spatialReference;if(t=this.projectOrWarn(t,r),null==t?.extent)return;const{rings:[[o,n,s]],extent:{center:{x:i,y:a}}}=t,m=e(Math.PI/2-Math.atan2(n[1]-o[1],n[0]-o[0])),c=p(i,a,-m),[x,u]=c(o[0],o[1]),[f,y]=c(s[0],s[1]);this.extent=new l({xmin:x,ymin:u,xmax:f,ymax:y,spatialReference:r}),this.rotation=m}toSourceNormalized(t){const{extent:e,rotation:n}=this;if(null==t||null==e)return null;const{xmin:s,ymin:i,xmax:l,ymax:a,center:c,spatialReference:x}=e;t=t.normalize();const u=m(t,x).geometry;if(null==u)return null;let f=u.x,y=u.y;return n&&([f,y]=p(c.x,c.y,-n)(f,y)),o(r(f,s,l,0,1),r(y,a,i,0,1))}};function p(t,e,r){const o=i(r),n=Math.cos(o),s=Math.sin(o);return(r,o)=>[n*(r-t)+s*(o-e)+t,n*(o-e)-s*(r-t)+e]}t([n({clonable:!1})],x.prototype,"coords",null),t([n({type:l})],x.prototype,"extent",void 0),t([n({type:Number})],x.prototype,"rotation",void 0),x=t([s("esri.layers.support.ExtentAndRotationGeoreference")],x);const u=x;export{u as default};
