boundingBox property

PRectangle? get boundingBox

Implementation

PRectangle? get boundingBox {
  var length = this.length;
  if (length == 0) return null;

  var p0 = this[0];

  num minX, minY, maxX, maxY;

  minX = maxX = p0.x;
  minY = maxY = p0.y;

  for (var i = 1; i < length; ++i) {
    var p = this[i];

    var x = p.x;
    var y = p.y;

    if (x < minX) minX = x;
    if (y < minY) minY = y;

    if (x > maxX) maxX = x;
    if (y > maxY) maxY = y;
  }

  return PRectangle.fromCoordinates(minX, minY, maxX, maxY);
}