# all files / ol/ tilerange.js

96.67% Statements 58/60
84.62% Branches 22/26
100% Functions 12/12
96.67% Lines 58/60

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    1861×

    1×
    1×
    1×

    1×

    3691×

    3691×

    3691×

    3691×

    1×
    2×
    2×
    2×
    2×
    2×

    2×
    2×
    2×
    2×
    2×
    2×
    2×

    1×
    1×
    1×
    1×

    1×

    1×
    3566×
    14×
    14×
    14×
    14×
    14×

    3552×

    1×
    25×

    1×
    22×

    1×
    88×

    1×
    5×

    1×
    1×
    1×

    1×

    1×

    1×
    1×

    1×
    14×

    1×
    1×

    1×
    13×

    1×
    8×

     goog.provide('ol.TileRange');

    goog.require('goog.asserts');
    goog.require('ol.Size');
    goog.require('ol.TileCoord');

    /**
     * A representation of a contiguous block of tiles.  A tile range is specified
     * by its min/max tile coordinates and is inclusive of coordinates.
     *
     * @constructor
     * @param {number} minX Minimum X.
     * @param {number} maxX Maximum X.
     * @param {number} minY Minimum Y.
     * @param {number} maxY Maximum Y.
     * @struct
     */
    ol.TileRange = function(minX, maxX, minY, maxY) {

      /**
       * @type {number}
       */
      this.minX = minX;

      /**
       * @type {number}
       */
      this.maxX = maxX;

      /**
       * @type {number}
       */
      this.minY = minY;

      /**
       * @type {number}
       */
      this.maxY = maxY;

    };

    /**
     * @param {...ol.TileCoord} var_args Tile coordinates.
     * @return {!ol.TileRange} Bounding tile box.
     */
    ol.TileRange.boundingTileRange = function(var_args) {
      var tileCoord0 = /** @type {ol.TileCoord} */ (arguments[0]);
      var tileCoord0Z = tileCoord0[0];
      var tileCoord0X = tileCoord0[1];
      var tileCoord0Y = tileCoord0[2];
      var tileRange = new ol.TileRange(tileCoord0X, tileCoord0X,
                                       tileCoord0Y, tileCoord0Y);
      var i, ii, tileCoord, tileCoordX, tileCoordY, tileCoordZ;
      for (i = 1, ii = arguments.length; i < ii; ++i) {
        tileCoord = /** @type {ol.TileCoord} */ (arguments[i]);
        tileCoordZ = tileCoord[0];
        tileCoordX = tileCoord[1];
        tileCoordY = tileCoord[2];
        goog.asserts.assert(tileCoordZ == tileCoord0Z,
            'passed tilecoords all have the same Z-value');
        tileRange.minX = Math.min(tileRange.minX, tileCoordX);
        tileRange.maxX = Math.max(tileRange.maxX, tileCoordX);
        tileRange.minY = Math.min(tileRange.minY, tileCoordY);
        tileRange.maxY = Math.max(tileRange.maxY, tileCoordY);
      }
      return tileRange;
    };

    /**
     * @param {number} minX Minimum X.
     * @param {number} maxX Maximum X.
     * @param {number} minY Minimum Y.
     * @param {number} maxY Maximum Y.
     * @param {ol.TileRange|undefined} tileRange TileRange.
     * @return {ol.TileRange} Tile range.
     */
    ol.TileRange.createOrUpdate = function(minX, maxX, minY, maxY, tileRange) {
      if (tileRange !== undefined) {
        tileRange.minX = minX;
        tileRange.maxX = maxX;
        tileRange.minY = minY;
        tileRange.maxY = maxY;
        return tileRange;
      } else {
        return new ol.TileRange(minX, maxX, minY, maxY);
      }
    };

    /**
     * @param {ol.TileCoord} tileCoord Tile coordinate.
     * @return {boolean} Contains tile coordinate.
     */
    ol.TileRange.prototype.contains = function(tileCoord) {
      return this.containsXY(tileCoord[1], tileCoord[2]);
    };

    /**
     * @param {ol.TileRange} tileRange Tile range.
     * @return {boolean} Contains.
     */
    ol.TileRange.prototype.containsTileRange = function(tileRange) {
      return this.minX <= tileRange.minX && tileRange.maxX <= this.maxX &&
          this.minY <= tileRange.minY && tileRange.maxY <= this.maxY;
    };

    /**
     * @param {number} x Tile coordinate x.
     * @param {number} y Tile coordinate y.
     * @return {boolean} Contains coordinate.
     */
    ol.TileRange.prototype.containsXY = function(x, y) {
      return this.minX <= x && x <= this.maxX && this.minY <= y && y <= this.maxY;
    };

    /**
     * @param {ol.TileRange} tileRange Tile range.
     * @return {boolean} Equals.
     */
    ol.TileRange.prototype.equals = function(tileRange) {
      return this.minX == tileRange.minX && this.minY == tileRange.minY &&
          this.maxX == tileRange.maxX && this.maxY == tileRange.maxY;
    };

    /**
     * @param {ol.TileRange} tileRange Tile range.
     */
    ol.TileRange.prototype.extend = function(tileRange) {
      Eif (tileRange.minX < this.minX) {
        this.minX = tileRange.minX;
      }
      Iif (tileRange.maxX > this.maxX) {
        this.maxX = tileRange.maxX;
      }
      Iif (tileRange.minY < this.minY) {
        this.minY = tileRange.minY;
      }
      Eif (tileRange.maxY > this.maxY) {
        this.maxY = tileRange.maxY;
      }
    };

    /**
     * @return {number} Height.
     */
    ol.TileRange.prototype.getHeight = function() {
      return this.maxY - this.minY + 1;
    };

    /**
     * @return {ol.Size} Size.
     */
    ol.TileRange.prototype.getSize = function() {
      return [this.getWidth(), this.getHeight()];
    };

    /**
     * @return {number} Width.
     */
    ol.TileRange.prototype.getWidth = function() {
      return this.maxX - this.minX + 1;
    };

    /**
     * @param {ol.TileRange} tileRange Tile range.
     * @return {boolean} Intersects.
     */
    ol.TileRange.prototype.intersects = function(tileRange) {
      return this.minX <= tileRange.maxX &&
          this.maxX >= tileRange.minX &&
          this.minY <= tileRange.maxY &&
          this.maxY >= tileRange.minY;
    };