calculateBounds method
Calculates the axis-aligned bounds of the object.
bounds is a buffer to hold the results. If not supplied, a temporary
buffer will be created.
approximate when true, uses a faster calculation to create the bounding
box based on the min/max values of all anchor and control points that
make up the shape. Default value is true.
Returns the axis-aligned bounding box for this object, where the rectangles left, top, right, and bottom values will be stored in entries 0, 1, 2, and 3, in that order.
Implementation
List<double> calculateBounds({
List<double>? bounds,
bool approximate = true,
}) {
bounds ??= List.filled(4, 0);
if (bounds.length < 4) {
throw ArgumentError('Required bounds size of 4.');
}
var minX = double.maxFinite;
var minY = double.maxFinite;
var maxX = double.minPositive;
var maxY = double.minPositive;
for (var i = 0; i < cubics.length; i++) {
cubics[i].calculateBounds(bounds, approximate: approximate);
minX = math.min(minX, bounds[0]);
minY = math.min(minY, bounds[1]);
maxX = math.max(maxX, bounds[2]);
maxY = math.max(maxY, bounds[3]);
}
bounds[0] = minX;
bounds[1] = minY;
bounds[2] = maxX;
bounds[3] = maxY;
return bounds;
}