calculateMaxBounds method

Rect calculateMaxBounds()

Implementation

Rect calculateMaxBounds() {
  var maxDistSquared = 0.0;
  for (var i = 0; i < cubics.length; i++) {
    final cubic = cubics[i];
    final anchorDistance = distanceSquared(
      cubic.anchor0X - centerX,
      cubic.anchor0Y - centerY,
    );
    final middlePoint = cubic.pointOnCurve(0.5);
    final middleDistance = distanceSquared(
      middlePoint.x - centerX,
      middlePoint.y - centerY,
    );
    maxDistSquared = math.max(
      maxDistSquared,
      math.max(anchorDistance, middleDistance),
    );
  }
  final distance = math.sqrt(maxDistSquared);
  return Rect.fromLTRB(
    centerX - distance,
    centerY - distance,
    centerX + distance,
    centerY + distance,
  );
}