BoundingBox.fromPoints constructor

BoundingBox.fromPoints(
  1. List<Point> points
)

Creates a BoundingBox for a List of Coordinates. The List must contain at least two Coordinates.

Example:

BoundingBox.fromPoints([
  Point(Coordinate(1, 2)),
  Point(Coordinate(3, 4)),
]); // BoundingBox(1, 2, 3, 4)

Implementation

factory BoundingBox.fromPoints(List<Point> points) {
  double minX = double.infinity;
  double minY = double.infinity;

  double maxX = double.negativeInfinity;
  double maxY = double.negativeInfinity;

  for (var point in points) {
    minX = math.min(minX, point.coordinate.longitude);
    minY = math.min(minY, point.coordinate.latitude);

    maxX = math.max(maxX, point.coordinate.longitude);
    maxY = math.max(maxY, point.coordinate.latitude);
  }

  return BoundingBox(minX, minY, maxX, maxY);
}