getBoundingBox static method
Calculates the bounding rectangle that encloses a list of artifacts.
This static method takes a list of Artifact objects and computes the minimum and maximum coordinates to define a rectangular bounding box that contains all the artifacts.
If the input list is empty, this method returns Rect.zero.
Returns: 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);
}