# all files / ol/ size.js

45.45% Statements 10/22
30% Branches 3/10
25% Functions 1/4
45.45% Lines 10/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×

    1×

    1×

    1×
    308×

    308×
    4×

    304×

    308×

     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) {
      Iif (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;
      }
    };