extendMeters method

BoundingBox extendMeters(
  1. int meters
)

Creates a BoundingBox that is a fixed meter amount larger on all sides (but does not cross date line/poles).

@param meters extension (must be >= 0) @return an extended BoundingBox or this (if meters == 0)

Implementation

BoundingBox extendMeters(int meters) {
  if (meters == 0) {
    return this;
  } else if (meters < 0) {
    throw new Exception("BoundingBox extend operation does not accept negative values");
  }

  double verticalExpansion = LatLongUtils.latitudeDistance(meters);
  double horizontalExpansion = LatLongUtils.longitudeDistance(meters, max(minLatitude.abs(), maxLatitude.abs()));

  double minLat = max(MercatorProjectionImpl.LATITUDE_MIN, this.minLatitude - verticalExpansion);
  double minLon = max(-180, this.minLongitude - horizontalExpansion);
  double maxLat = min(MercatorProjectionImpl.LATITUDE_MAX, this.maxLatitude + verticalExpansion);
  double maxLon = min(180, this.maxLongitude + horizontalExpansion);

  return new BoundingBox(minLat, minLon, maxLat, maxLon);
}