# all files / ol/ size.js

100% Statements 22/22
100% Branches 10/10
100% Functions 4/4
100% Lines 22/22

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

    1×
    11×
    1×

    11×
    11×
    11×

    1×
    518×

    1×
    7×
    1×

    7×
    7×
    7×

    1×
    26065×
    1661×

    24404×
    239×

    24165×

    24404×

     goog.provide('ol.size');

    /**
     * Returns a buffered size.
     * @param {ol.Size} size Size.
     * @param {number} buffer Buffer.
     * @param {ol.Size=} opt_size Optional reusable size array.
     * @return {ol.Size} The buffered size.
     */
    ol.size.buffer = function(size, buffer, opt_size) {
      if (opt_size === undefined) {
        opt_size = [0, 0];
      }
      opt_size[0] = size[0] + 2 * buffer;
      opt_size[1] = size[1] + 2 * buffer;
      return opt_size;
    };

    /**
     * Determines if a size has a positive area.
     * @param {ol.Size} size The size to test.
     * @return {boolean} The size has a positive area.
     */
    ol.size.hasArea = function(size) {
      return size[0] > 0 && size[1] > 0;
    };

    /**
     * Returns a size scaled by a ratio. The result will be an array of integers.
     * @param {ol.Size} size Size.
     * @param {number} ratio Ratio.
     * @param {ol.Size=} opt_size Optional reusable size array.
     * @return {ol.Size} The scaled size.
     */
    ol.size.scale = function(size, ratio, opt_size) {
      if (opt_size === undefined) {
        opt_size = [0, 0];
      }
      opt_size[0] = (size[0] * ratio + 0.5) | 0;
      opt_size[1] = (size[1] * ratio + 0.5) | 0;
      return opt_size;
    };

    /**
     * Returns an `ol.Size` array for the passed in number (meaning: square) or
     * `ol.Size` array.
     * (meaning: non-square),
     * @param {number|ol.Size} size Width and height.
     * @param {ol.Size=} opt_size Optional reusable size array.
     * @return {ol.Size} Size.
     * @api
     */
    ol.size.toSize = function(size, opt_size) {
      if (Array.isArray(size)) {
        return size;
      } else {
        if (opt_size === undefined) {
          opt_size = [size, size];
        } else {
          opt_size[0] = opt_size[1] = /** @type {number} */ (size);
        }
        return opt_size;
      }
    };