# all files / ol/ tilerange.js

46.15% Statements 18/39
3.85% Branches 1/26
18.18% Functions 2/11
46.15% Lines 18/39

    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
    1531×

    1×

    152×

    152×

    152×

    152×

    1×
    152×

    152×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

     goog.provide('ol.TileRange');

    /**
     * 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 {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) {
      Iif (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) {
      if (tileRange.minX < this.minX) {
        this.minX = tileRange.minX;
      }
      if (tileRange.maxX > this.maxX) {
        this.maxX = tileRange.maxX;
      }
      if (tileRange.minY < this.minY) {
        this.minY = tileRange.minY;
      }
      if (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;
    };