calculateRotatedSize static method

Size calculateRotatedSize(
  1. double rotation,
  2. Size nonRotatedSize
)

Calculates the size of a bounding box which surrounds a box of size nonRotatedSize which is rotated by rotation.

Implementation

static Size calculateRotatedSize(
  double rotation,
  Size nonRotatedSize,
) {
  if (rotation == 0.0) return nonRotatedSize;

  final rotationRad = degrees2Radians * rotation;
  final cosAngle = math.cos(rotationRad).abs();
  final sinAngle = math.sin(rotationRad).abs();
  final width =
      (nonRotatedSize.width * cosAngle) + (nonRotatedSize.height * sinAngle);
  final height =
      (nonRotatedSize.height * cosAngle) + (nonRotatedSize.width * sinAngle);

  return Size(width, height);
}