// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define(["../../../geometry/support/spatialReferenceUtils","./TileKey"],function(t,u){function l(a,b,c){a[0]=b;a[1]=c;return a}const f=new u("0/0/0/0");class r{static create(a,b,c=null){var d=t.getInfo(a.spatialReference);const e=b.origin||[a.origin.x,a.origin.y],k=[a.size[0]*b.resolution,a.size[1]*b.resolution],g=[-Infinity,-Infinity],h=[Infinity,Infinity],m=[Infinity,Infinity];null!=c&&(l(g,Math.max(0,Math.floor((c.xmin-e[0])/k[0])),Math.max(0,Math.floor((e[1]-c.ymax)/k[1]))),l(h,Math.max(0,Math.floor((c.xmax- e[0])/k[0])),Math.max(0,Math.floor((e[1]-c.ymin)/k[1]))),l(m,h[0]-g[0]+1,h[1]-g[1]+1));const {cols:n,rows:p}=b;!c&&n&&p&&(l(g,n[0],p[0]),l(h,n[1],p[1]),l(m,n[1]-n[0]+1,p[1]-p[0]+1));let q;a.isWrappable?(a=[Math.ceil(Math.round((d.valid[1]-d.valid[0])/b.resolution)/a.size[0]),m[1]],d=[Math.floor((d.origin[0]-e[0])/k[0]),g[1]],c=[a[0]+d[0]-1,h[1]],q=!0):(d=g,c=h,a=m,q=!1);return new r(b.level,b.resolution,b.scale,e,g,h,m,k,d,c,a,q)}constructor(a,b,c,d,e,k,g,h,m,n,p,q){this.level=a;this.resolution=b; this.scale=c;this.origin=d;this.first=e;this.last=k;this.size=g;this.norm=h;this.worldStart=m;this.worldEnd=n;this.worldSize=p;this.wrap=q}normalizeCol(a){if(!this.wrap)return a;const b=this.worldSize[0];return 0>a?b-1-Math.abs((a+1)%b):a%b}denormalizeCol(a,b){return this.wrap?this.worldSize[0]*b+a:a}getWorldForColumn(a){return this.wrap?Math.floor(a/this.worldSize[0]):0}getFirstColumnForWorld(a){return a*this.worldSize[0]+this.first[0]}getLastColumnForWorld(a){return a*this.worldSize[0]+this.first[0]+ this.size[0]-1}getColumnForX(a){return(a-this.origin[0])/this.norm[0]}getXForColumn(a){return this.origin[0]+a*this.norm[0]}getRowForY(a){return(this.origin[1]-a)/this.norm[1]}getYForRow(a){return this.origin[1]-a*this.norm[1]}getTileBounds(a,b,c=!1){f.set(b);var d=c?f.col:this.denormalizeCol(f.col,f.world),e=f.row;b=this.getXForColumn(d);c=this.getYForRow(e+1);d=this.getXForColumn(d+1);e=this.getYForRow(e);a[0]=b;a[1]=c;a[2]=d;a[3]=e;return a}getTileCoords(a,b,c=!1){f.set(b);b=c?f.col:this.denormalizeCol(f.col, f.world);Array.isArray(a)?l(a,this.getXForColumn(b),this.getYForRow(f.row)):(a.x=this.getXForColumn(b),a.y=this.getYForRow(f.row));return a}}return r});