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

92.86% Statements 52/56
87.5% Branches 28/32
100% Functions 6/6
92.86% Lines 52/56

    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
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    1551×

    1×
    1×
    1×
    1×

    1×

    46×

    46×
    8×

    38×
    7×

    31×

    1×

    30×

    30×

    49×

    1×

    2×
    2×
    3×

    1×

    2×

    1×

    1×

    23×

    7×

    16×

    8×

    8×

    8×

    8×

    8×

    1×

    20×
    20×

    7×

    13×
    2×

    11×
    11×
    15×

    4×

    7×

    1×

    3×
    3×
    3×
    5×
    5×

    2×

    3×

    1×

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

    goog.require('goog.asserts');
    goog.require('ol.extent');
    goog.require('ol.geom.flat.contains');
    goog.require('ol.geom.flat.segments');

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @param {ol.Extent} extent Extent.
     * @return {boolean} True if the geometry and the extent intersect.
     */
    ol.geom.flat.intersectsextent.lineString =
        function(flatCoordinates, offset, end, stride, extent) {
      var coordinatesExtent = ol.extent.extendFlatCoordinates(
          ol.extent.createEmpty(), flatCoordinates, offset, end, stride);
      if (!ol.extent.intersects(extent, coordinatesExtent)) {
        return false;
      }
      if (ol.extent.containsExtent(extent, coordinatesExtent)) {
        return true;
      }
      if (coordinatesExtent[0] >= extent[0] &&
          coordinatesExtent[2] <= extent[2]) {
        return true;
      }
      Iif (coordinatesExtent[1] >= extent[1] &&
          coordinatesExtent[3] <= extent[3]) {
        return true;
      }
      return ol.geom.flat.segments.forEach(flatCoordinates, offset, end, stride,
          /**
           * @param {ol.Coordinate} point1 Start point.
           * @param {ol.Coordinate} point2 End point.
           * @return {boolean} `true` if the segment and the extent intersect,
           *     `false` otherwise.
           */
          function(point1, point2) {
            return ol.extent.intersectsSegment(extent, point1, point2);
          });
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {Array.<number>} ends Ends.
     * @param {number} stride Stride.
     * @param {ol.Extent} extent Extent.
     * @return {boolean} True if the geometry and the extent intersect.
     */
    ol.geom.flat.intersectsextent.lineStrings =
        function(flatCoordinates, offset, ends, stride, extent) {
      var i, ii;
      for (i = 0, ii = ends.length; i < ii; ++i) {
        if (ol.geom.flat.intersectsextent.lineString(
            flatCoordinates, offset, ends[i], stride, extent)) {
          return true;
        }
        offset = ends[i];
      }
      return false;
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {number} end End.
     * @param {number} stride Stride.
     * @param {ol.Extent} extent Extent.
     * @return {boolean} True if the geometry and the extent intersect.
     */
    ol.geom.flat.intersectsextent.linearRing =
        function(flatCoordinates, offset, end, stride, extent) {
      if (ol.geom.flat.intersectsextent.lineString(
          flatCoordinates, offset, end, stride, extent)) {
        return true;
      }
      if (ol.geom.flat.contains.linearRingContainsXY(
          flatCoordinates, offset, end, stride, extent[0], extent[1])) {
        return true;
      }
      Iif (ol.geom.flat.contains.linearRingContainsXY(
          flatCoordinates, offset, end, stride, extent[0], extent[3])) {
        return true;
      }
      Iif (ol.geom.flat.contains.linearRingContainsXY(
          flatCoordinates, offset, end, stride, extent[2], extent[1])) {
        return true;
      }
      Iif (ol.geom.flat.contains.linearRingContainsXY(
          flatCoordinates, offset, end, stride, extent[2], extent[3])) {
        return true;
      }
      return false;
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {Array.<number>} ends Ends.
     * @param {number} stride Stride.
     * @param {ol.Extent} extent Extent.
     * @return {boolean} True if the geometry and the extent intersect.
     */
    ol.geom.flat.intersectsextent.linearRings =
        function(flatCoordinates, offset, ends, stride, extent) {
      goog.asserts.assert(ends.length > 0, 'ends should not be an empty array');
      if (!ol.geom.flat.intersectsextent.linearRing(
          flatCoordinates, offset, ends[0], stride, extent)) {
        return false;
      }
      if (ends.length === 1) {
        return true;
      }
      var i, ii;
      for (i = 1, ii = ends.length; i < ii; ++i) {
        if (ol.geom.flat.contains.linearRingContainsExtent(
            flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
          return false;
        }
      }
      return true;
    };

    /**
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     * @param {number} offset Offset.
     * @param {Array.<Array.<number>>} endss Endss.
     * @param {number} stride Stride.
     * @param {ol.Extent} extent Extent.
     * @return {boolean} True if the geometry and the extent intersect.
     */
    ol.geom.flat.intersectsextent.linearRingss =
        function(flatCoordinates, offset, endss, stride, extent) {
      goog.asserts.assert(endss.length > 0, 'endss should not be an empty array');
      var i, ii;
      for (i = 0, ii = endss.length; i < ii; ++i) {
        var ends = endss[i];
        if (ol.geom.flat.intersectsextent.linearRings(
            flatCoordinates, offset, ends, stride, extent)) {
          return true;
        }
        offset = ends[ends.length - 1];
      }
      return false;
    };