define(["exports","./Cartesian2-2b41fabe","./Check-2514d21d","./when-d186add7","./Rectangle-f841217d","./buildModuleUrl-d920237a","./Math-7f5f2992"],(function(e,t,i,s,n,o,r){"use strict";function h(e){e=s.u(e,{}),this._ellipsoid=s.u(e.ellipsoid,n.t.WGS84),this._rectangle=s.u(e.rectangle,n.h.MAX_VALUE),this._projection=new o.n(this._ellipsoid),this._numberOfLevelZeroTilesX=s.u(e.numberOfLevelZeroTilesX,2),this._numberOfLevelZeroTilesY=s.u(e.numberOfLevelZeroTilesY,1),this._customDPI=e.customDPI,this._scaleDenominators=e.scaleDenominators,this._tileWidth=s.u(e.tileWidth,256),this._tileHeight=s.u(e.tileHeight,256),this._beginLevel=s.u(e.beginLevel,0),this._origin=s.u(e.origin,void 0)}Object.defineProperties(h.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},rectangle:{get:function(){return this._rectangle}},projection:{get:function(){return this._projection}},beginLevel:{get:function(){return this._beginLevel}},origin:{get:function(){return this._origin}}}),h.prototype.getNumberOfXTilesAtLevel=function(e){if(s.e(this._customDPI)&&s.e(this._scaleDenominators)){var t=this.calculateResolution(e),i=this._tileWidth*t.x;return Math.ceil(this._rectangle.width/i)}return this._numberOfLevelZeroTilesX<<e-this._beginLevel},h.prototype.getNumberOfYTilesAtLevel=function(e){if(s.e(this._customDPI)&&s.e(this._scaleDenominators)){var t=this.calculateResolution(e),i=this._tileHeight*t.y;return Math.ceil(this._rectangle.height/i)}return this._numberOfLevelZeroTilesY<<e-this._beginLevel},h.prototype.rectangleToNativeRectangle=function(e,t){i.o.defined("rectangle",e);var o=r.e.toDegrees(e.west),h=r.e.toDegrees(e.south),l=r.e.toDegrees(e.east),u=r.e.toDegrees(e.north);return s.e(t)?(t.west=o,t.south=h,t.east=l,t.north=u,t):new n.h(o,h,l,u)},h.prototype.tileXYToNativeRectangle=function(e,t,i,s){var n=this.tileXYToRectangle(e,t,i,s);return n.west=r.e.toDegrees(n.west),n.south=r.e.toDegrees(n.south),n.east=r.e.toDegrees(n.east),n.north=r.e.toDegrees(n.north),n},h.prototype.tileXYToRectangle=function(e,t,i,o){var r=this._rectangle,h=s.e(this._origin)?this._origin.longitude:r.west,l=s.e(this._origin)?this._origin.latitude:r.north;if(s.e(this._customDPI)&&s.e(this._scaleDenominators)){var u=this.calculateResolution(i),a=h+e*this._tileWidth*u.x,g=h+(e+1)*this._tileWidth*u.x,c=l-t*this._tileHeight*u.y,_=l-(t+1)*this._tileHeight*u.y;return s.e(o)?(o.west=a,o.south=_,o.east=g,o.north=c,o):new n.h(a,_,g,c)}var d=this.getNumberOfXTilesAtLevel(i),f=this.getNumberOfYTilesAtLevel(i),v=r.width/d,m=(a=e*v+r.west,g=(e+1)*v+r.west,r.height/f);c=r.north-t*m,_=r.north-(t+1)*m;return s.e(o)||(o=new n.h(a,_,g,c)),o.west=a,o.south=_,o.east=g,o.north=c,o},h.prototype.positionToTileXY=function(e,i,o){var h=this._rectangle;if(n.h.contains(h,e)){var l=this.getNumberOfXTilesAtLevel(i),u=this.getNumberOfYTilesAtLevel(i),a=s.e(this._origin)?this._origin.longitude:h.west,g=s.e(this._origin)?this._origin.latitude:h.north,c=h.width/l,_=h.height/u;if(s.e(this._customDPI)&&s.e(this._scaleDenominators)){var d=this.calculateResolution(i);c=this._tileWidth*d.x,_=this._tileHeight*d.y}var f=e.longitude;h.east<h.west&&(f+=r.e.TWO_PI),s.e(this._origin)&&(l+=this._origin.longitude!=h.west?Math.ceil((e.longitude-this._origin.longitude)/c):0,u+=this._origin.latitude!=h.north?Math.ceil((this._origin.latitude-e.latitude)/_):0);var v=(f-a)/c|0;v>=l&&(v=l-1);var m=(g-e.latitude)/_|0;return m>=u&&(m=u-1),s.e(o)?(o.x=v,o.y=m,o):new t.o(v,m)}},h.prototype.calculateResolution=function(e){var i=Math.min(e-this._beginLevel,this._scaleDenominators.length-1),s=.0254*this._scaleDenominators[i]/this._customDPI.x,o=.0254*this._scaleDenominators[i]/this._customDPI.y,r=n.t.WGS84.maximumRadius;return new t.o(s/r,o/r)},e.g=h}));
