rotate method

void rotate(
  1. double angle,
  2. Rect layoutRect,
  3. BoxFit? fit
)

Implementation

void rotate(double angle, Rect layoutRect, BoxFit? fit) {
  if (cropRect == null) {
    return;
  }
  _rotateRadian += angle;
  _rotateRadian %= 2 * pi;
  if (_flipX && _flipY && isPi) {
    _flipX = _flipY = false;
    _rotateRadian = 0.0;
  }

  // _cropRect = rotateRect(_cropRect, _cropRect.center, -angle);
  // screenDestinationRect =
  //     rotateRect(screenDestinationRect, screenCropRect.center, -angle);

  /// take care of boundary
  final Rect newCropRect = getDestinationRect(
    rect: layoutRect,
    inputSize: Size(cropRect!.height, cropRect!.width),
    fit: fit,
  );

  final double scale = newCropRect.width / cropRect!.height;

  Rect newScreenDestinationRect =
      rotateRect(screenDestinationRect!, screenCropRect!.center, angle);

  final Offset topLeft = screenCropRect!.center -
      (screenCropRect!.center - newScreenDestinationRect.topLeft) * scale;
  final Offset bottomRight = screenCropRect!.center +
      -(screenCropRect!.center - newScreenDestinationRect.bottomRight) *
          scale;

  newScreenDestinationRect = Rect.fromPoints(topLeft, bottomRight);

  cropRect = newCropRect;
  _screenDestinationRect = newScreenDestinationRect;
  totalScale *= scale;
  preTotalScale = totalScale;
}