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

75% Statements 21/28
100% Branches 0/0
66.67% Functions 2/3
75% Lines 21/28

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

    1×
    4×
    4×
    4×
    4×
    15×
    15×
    15×
    15×
    15×

    4×

    1×

    1×
    1×
    1×
    2×
    2×
    2×

    1×

    1×

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

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @return {number} Area.
     */
    ol.geom.flat.area.linearRing = function(flatCoordinates, offset, end, stride) {
      var twiceArea = 0;
      var x1 = flatCoordinates[end - stride];
      var y1 = flatCoordinates[end - stride + 1];
      for (; offset < end; offset += stride) {
        var x2 = flatCoordinates[offset];
        var y2 = flatCoordinates[offset + 1];
        twiceArea += y1 * x2 - x1 * y2;
        x1 = x2;
        y1 = y2;
      }
      return twiceArea / 2;
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {Array.<number>} ends Ends.
     * @param {number} stride Stride.
     * @return {number} Area.
     */
    ol.geom.flat.area.linearRings =
        function(flatCoordinates, offset, ends, stride) {
      var area = 0;
      var i, ii;
      for (i = 0, ii = ends.length; i < ii; ++i) {
        var end = ends[i];
        area += ol.geom.flat.area.linearRing(flatCoordinates, offset, end, stride);
        offset = end;
      }
      return area;
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {Array.<Array.<number>>} endss Endss.
     * @param {number} stride Stride.
     * @return {number} Area.
     */
    ol.geom.flat.area.linearRingss =
        function(flatCoordinates, offset, endss, stride) {
      var area = 0;
      var i, ii;
      for (i = 0, ii = endss.length; i < ii; ++i) {
        var ends = endss[i];
        area +=
            ol.geom.flat.area.linearRings(flatCoordinates, offset, ends, stride);
        offset = ends[ends.length - 1];
      }
      return area;
    };