BoundingBox.fromCoordinates constructor
BoundingBox.fromCoordinates(
- List<
Coordinate> coordinates
Creates a BoundingBox from a List of Coordinates.
The List must contain at least two Coordinates.
It's very similar to BoundingBox.fromPoints
, but it's designed for use with Coordinates.
Example:
BoundingBox.fromCoordinates([
Coordinate(1, 2),
Coordinate(3, 4),
]); // BoundingBox(1, 2, 3, 4)
Implementation
factory BoundingBox.fromCoordinates(List<Coordinate> coordinates) {
double minX = double.infinity;
double minY = double.infinity;
double maxX = double.negativeInfinity;
double maxY = double.negativeInfinity;
for (var coordinate in coordinates) {
minX = math.min(minX, coordinate.longitude);
minY = math.min(minY, coordinate.latitude);
maxX = math.max(maxX, coordinate.longitude);
maxY = math.max(maxY, coordinate.latitude);
}
return BoundingBox(minX, minY, maxX, maxY);
}