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

89.66% Statements 26/29
80% Branches 8/10
100% Functions 1/1
89.66% Lines 26/29

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

    1×
    3×
    3×
    3×
    3×
    3×
    3×
    3×
    3×
    9×
    9×
    9×
    9×
    9×
    9×
    6×
    6×
    6×
    2×

    2×
    2×

    9×
    9×
    9×

    3×

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

    /**
     * @param {number} angleDelta Maximum acceptable angle delta between segments.
     * @param {number} length Required length of the resulting chung.
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @return {Array.<number>} Offset and end of the longest suitable chunk of the
     * given `flatCoordinates`, or `null` if there is none.
     */
    ol.geom.flat.straightchunk.lineString = function(angleDelta, length, flatCoordinates, offset, end, stride) {
      var x1 = flatCoordinates[offset];
      var y1 = flatCoordinates[offset + 1];
      var chunkOffset = offset;
      var chunkLength = 0;
      var chunk = [];
      var m = 0;
      var acos, i, m12, x21, y21;
      for (i = offset + stride; i < end; i += stride) {
        var x2 = flatCoordinates[i];
        var y2 = flatCoordinates[i + 1];
        var x32 = x2 - x1;
        var y32 = y2 - y1;
        var m23 = Math.sqrt(x32 * x32 + y32 * y32);
        if (m12 !== undefined) {
          m += m23;
          acos = Math.acos((x21 * x32 + y21 * y32) / (m12 * m23));
          if (acos > angleDelta) {
            Iif (m >= chunkLength && m >= length) {
              chunk[0] = chunkOffset;
              chunk[1] = i + stride;
              chunkLength = m;
            }
            m = 0;
            chunkOffset = i;
          }
        }
        x21 = x32;
        y21 = y32;
        m12 = m23;
      }
      return chunk.length == 2 ? chunk : null;
    };