intersectsArea method

bool intersectsArea(
  1. List<List<ILatLong>> latLongs
)

Returns if an area built from the latLongs intersects with a bias towards returning true. The method returns fast if any of the points lie within the bbox. If none of the points lie inside the box, it constructs the outer bbox for all the points and tests for intersection (so it is possible that the area defined by the points does not actually intersect)

@param latLongs the points that define an area @return false if there is no intersection, true if there could be an intersection

Implementation

bool intersectsArea(List<List<ILatLong>> latLongs) {
  if (latLongs.length == 0 || latLongs[0].length == 0) {
    return false;
  }
  for (List<ILatLong> outer in latLongs) {
    for (ILatLong latLong in outer) {
      if (this.containsLatLong(latLong)) {
        // if any of the points is inside the bbox return early
        return true;
      }
    }
  }

  // no fast solution, so accumulate boundary points
  double tmpMinLat = latLongs[0][0].latitude;
  double tmpMinLon = latLongs[0][0].longitude;
  double tmpMaxLat = latLongs[0][0].latitude;
  double tmpMaxLon = latLongs[0][0].longitude;

  for (List<ILatLong> outer in latLongs) {
    for (ILatLong latLong in outer) {
      tmpMinLat = min(tmpMinLat, latLong.latitude);
      tmpMaxLat = max(tmpMaxLat, latLong.latitude);
      tmpMinLon = min(tmpMinLon, latLong.longitude);
      tmpMaxLon = max(tmpMaxLon, latLong.longitude);
    }
  }
  return this.intersects(new BoundingBox(tmpMinLat, tmpMinLon, tmpMaxLat, tmpMaxLon));
}