# all files / ol/geom/flat/ transform.js

92.98% Statements 53/57
75% Branches 18/24
100% Functions 4/4
92.98% Lines 53/57

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

    1×
    7018×
    7018×
    7018×
    7018×
    92502×
    92502×
    92502×
    92502×

    7018×
    1×

    7018×

    1×
    3×
    3×
    3×
    3×
    3×
    3×
    3×
    20×
    20×
    20×
    20×
    20×
    10×

    3×

    3×

    1×
    24×
    24×
    24×
    24×
    24×
    66×
    66×
    66×
    66×
    66×

    24×

    24×

    1×
    39×
    39×
    39×
    39×
    98×
    98×
    98×
    10×

    39×

    39×

     goog.provide('ol.geom.flat.transform');

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @param {ol.Transform} transform Transform.
     * @param {Array.<number>=} opt_dest Destination.
     * @return {Array.<number>} Transformed coordinates.
     */
    ol.geom.flat.transform.transform2D = function(flatCoordinates, offset, end, stride, transform, opt_dest) {
      var dest = opt_dest ? opt_dest : [];
      var i = 0;
      var j;
      for (j = offset; j < end; j += stride) {
        var x = flatCoordinates[j];
        var y = flatCoordinates[j + 1];
        dest[i++] = transform[0] * x + transform[2] * y + transform[4];
        dest[i++] = transform[1] * x + transform[3] * y + transform[5];
      }
      if (opt_dest && dest.length != i) {
        dest.length = i;
      }
      return dest;
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @param {number} angle Angle.
     * @param {Array.<number>} anchor Rotation anchor point.
     * @param {Array.<number>=} opt_dest Destination.
     * @return {Array.<number>} Transformed coordinates.
     */
    ol.geom.flat.transform.rotate = function(flatCoordinates, offset, end, stride, angle, anchor, opt_dest) {
      var dest = opt_dest ? opt_dest : [];
      var cos = Math.cos(angle);
      var sin = Math.sin(angle);
      var anchorX = anchor[0];
      var anchorY = anchor[1];
      var i = 0;
      for (var j = offset; j < end; j += stride) {
        var deltaX = flatCoordinates[j] - anchorX;
        var deltaY = flatCoordinates[j + 1] - anchorY;
        dest[i++] = anchorX + deltaX * cos - deltaY * sin;
        dest[i++] = anchorY + deltaX * sin + deltaY * cos;
        for (var k = j + 2; k < j + stride; ++k) {
          dest[i++] = flatCoordinates[k];
        }
      }
      Iif (opt_dest && dest.length != i) {
        dest.length = i;
      }
      return dest;
    };

    /**
     * Scale the coordinates.
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @param {number} sx Scale factor in the x-direction.
     * @param {number} sy Scale factor in the y-direction.
     * @param {Array.<number>} anchor Scale anchor point.
     * @param {Array.<number>=} opt_dest Destination.
     * @return {Array.<number>} Transformed coordinates.
     */
    ol.geom.flat.transform.scale = function(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_dest) {
      var dest = opt_dest ? opt_dest : [];
      var anchorX = anchor[0];
      var anchorY = anchor[1];
      var i = 0;
      for (var j = offset; j < end; j += stride) {
        var deltaX = flatCoordinates[j] - anchorX;
        var deltaY = flatCoordinates[j + 1] - anchorY;
        dest[i++] = anchorX + sx * deltaX;
        dest[i++] = anchorY + sy * deltaY;
        for (var k = j + 2; k < j + stride; ++k) {
          dest[i++] = flatCoordinates[k];
        }
      }
      Iif (opt_dest && dest.length != i) {
        dest.length = i;
      }
      return dest;
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @param {number} deltaX Delta X.
     * @param {number} deltaY Delta Y.
     * @param {Array.<number>=} opt_dest Destination.
     * @return {Array.<number>} Transformed coordinates.
     */
    ol.geom.flat.transform.translate = function(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) {
      var dest = opt_dest ? opt_dest : [];
      var i = 0;
      var j, k;
      for (j = offset; j < end; j += stride) {
        dest[i++] = flatCoordinates[j] + deltaX;
        dest[i++] = flatCoordinates[j + 1] + deltaY;
        for (k = j + 2; k < j + stride; ++k) {
          dest[i++] = flatCoordinates[k];
        }
      }
      Iif (opt_dest && dest.length != i) {
        dest.length = i;
      }
      return dest;
    };