boundingBox property

  1. @override
Rectangle get boundingBox
override

The smallest axis-aligned rectangle that completely encloses the shape.

Implementation

@override
Rectangle get boundingBox {
  double minX = vertices.first.x.toDouble();
  double maxX = minX;
  double minY = vertices.first.y.toDouble();
  double maxY = minY;

  for (final p in vertices.skip(1)) {
    if (p.x < minX) minX = p.x.toDouble();
    if (p.x > maxX) maxX = p.x.toDouble();
    if (p.y < minY) minY = p.y.toDouble();
    if (p.y > maxY) maxY = p.y.toDouble();
  }

  return Rectangle(
    width: maxX - minX,
    height: maxY - minY,
    center: Point(x: (minX + maxX) / 2, y: (minY + maxY) / 2)
  );
}