BoundingBox constructor

BoundingBox(
  1. BitMatrix _image,
  2. ResultPoint? topLeft,
  3. ResultPoint? bottomLeft,
  4. ResultPoint? topRight,
  5. ResultPoint? bottomRight,
)

Implementation

BoundingBox(
  this._image,
  ResultPoint? topLeft,
  ResultPoint? bottomLeft,
  ResultPoint? topRight,
  ResultPoint? bottomRight,
) {
  final leftUnspecified = topLeft == null || bottomLeft == null;
  final rightUnspecified = topRight == null || bottomRight == null;
  if (leftUnspecified && rightUnspecified) {
    throw NotFoundException.instance;
  }
  if (leftUnspecified) {
    topLeft = ResultPoint(0, topRight!.y);
    bottomLeft = ResultPoint(0, bottomRight!.y);
  } else if (rightUnspecified) {
    topRight = ResultPoint(_image.width - 1, topLeft.y);
    bottomRight = ResultPoint(_image.width - 1, bottomLeft.y);
  }
  _topLeft = topLeft;
  _bottomLeft = bottomLeft;
  _topRight = topRight;
  _bottomRight = bottomRight;
  _minX = math.min(topLeft.x.toInt(), bottomLeft.x.toInt());
  _maxX = math.max(topRight.x.toInt(), bottomRight.x.toInt());
  _minY = math.min(topLeft.y.toInt(), topRight.y.toInt());
  _maxY = math.max(bottomLeft.y.toInt(), bottomRight.y.toInt());
}