bounds method

(Point, Point)? bounds(
  1. dynamic geoJson
)

Calculates the bounding box of a geometry.

Implementation

(Point, Point)? bounds(dynamic geoJson) {
  final paths = generate(geoJson);
  if (paths.isEmpty) return null;

  double minX = double.infinity, minY = double.infinity;
  double maxX = double.negativeInfinity, maxY = double.negativeInfinity;

  for (final path in paths) {
    for (final point in path) {
      if (point.x < minX) minX = point.x;
      if (point.y < minY) minY = point.y;
      if (point.x > maxX) maxX = point.x;
      if (point.y > maxY) maxY = point.y;
    }
  }

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