"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeographicTilingScheme = void 0;
var Math_1 = require("../../src/math/Math");
var Rectangle_1 = require("../core/Rectangle");
/**
 * 地理学块
 */
var GeographicTilingScheme = /** @class */ (function () {
    function GeographicTilingScheme(options) {
        if (options === void 0) { options = {}; }
        this._rectangle = GeographicTilingScheme.MAX_VALUE;
        this._numberOfLevelZeroTilesX = options.numberOfLevelZeroTilesX || 2;
        this._numberOfLevelZeroTilesY = options.numberOfLevelZeroTilesY || 2;
    }
    GeographicTilingScheme.prototype.tileXYToRectangle = function (x, y, level, result) {
        var rectangle = this._rectangle;
        var xTiles = this.getNumberOfXTilesAtLevel(level);
        var yTiles = this.getNumberOfYTilesAtLevel(level);
        var xTileWidth = rectangle.width / xTiles;
        var west = x * xTileWidth + rectangle.west;
        var east = (x + 1) * xTileWidth + rectangle.west;
        var yTileHeight = rectangle.height / yTiles;
        var north = rectangle.north - y * yTileHeight;
        var south = rectangle.north - (y + 1) * yTileHeight;
        if (!result) {
            result = new Rectangle_1.Rectangle(west, south, east, north);
        }
        result.west = west;
        result.south = south;
        result.east = east;
        result.north = north;
        return result;
    };
    GeographicTilingScheme.prototype.getNumberOfXTilesAtLevel = function (level) {
        return this._numberOfLevelZeroTilesX << level;
    };
    ;
    GeographicTilingScheme.prototype.getNumberOfYTilesAtLevel = function (level) {
        return this._numberOfLevelZeroTilesY << level;
    };
    ;
    GeographicTilingScheme.MAX_VALUE = Object.freeze(new Rectangle_1.Rectangle(-Math.PI, -Math_1.PI_TWO, Math.PI, Math_1.PI_TWO));
    return GeographicTilingScheme;
}());
exports.GeographicTilingScheme = GeographicTilingScheme;
