getBoundingBox static method
Computes the bounding rectangle that encloses all the artifacts
in the provided list.
If the list of artifacts is empty, this method returns Rect.zero. Otherwise, it iterates through the artifacts, finding the minimum and maximum x and y coordinates, and returns a Rect that represents the bounding box.
@param artifacts The list of artifacts to compute the bounding box for. @return A Rect representing the bounding box of the provided artifacts.
Implementation
static Rect getBoundingBox(final List<Artifact> artifacts) {
if (artifacts.isEmpty) {
return Rect.zero;
}
double minX = double.infinity;
double minY = double.infinity;
double maxX = double.negativeInfinity;
double maxY = double.negativeInfinity;
for (final Artifact artifact in artifacts) {
final Rect rect = artifact.matrix.rectangle;
minX = min(minX, rect.left);
minY = min(minY, rect.top);
maxX = max(maxX, rect.right);
maxY = max(maxY, rect.bottom);
}
return Rect.fromLTRB(minX, minY, maxX, maxY);
}