code: def bbox_safe_rotate(
      bbox: BoxInternalType, matrix: np.ndarray, cols: int, rows: int
  ) -> BoxInternalType:
      x1, y1, x2, y2 = denormalize_bbox(bbox, rows, cols)[:4]
      points = np.array(
          [
              [x1, y1, 1],
              [x2, y1, 1],
              [x2, y2, 1],
              [x1, y2, 1],
          ]
      )
      points = points @ matrix.T
      x1 = points[:, 0].min()
      x2 = points[:, 0].max()
      y1 = points[:, 1].min()
      y2 = points[:, 1].max()
  
      def fix_point(
          pt1: float, pt2: float, max_val: float
      ) -> Tuple[float, float]:
          # In my opinion, these errors should be very low, around 1-2 pixels.
          if pt1 < 0:
              return 0, pt2 + pt1
          if pt2 > max_val:
              return pt1 - (pt2 - max_val), max_val
          return pt1, pt2
  
      x1, x2 = fix_point(x1, x2, cols)
      y1, y2 = fix_point(y1, y2, rows)
  
      return normalize_bbox((x1, y1, x2, y2), rows, cols)
  
imports: import math
  from typing import List, Optional, Sequence, Tuple, Union
  import cv2
  import numpy
  import skimage.transform
  from scipy.ndimage import gaussian_filter
  from albumentations.augmentations.utils import _maybe_process_in_chunks, angle_2pi_range, clipped, preserve_channel_dim, preserve_shape
  from ...None import random_utils
  from ...core.bbox_utils import denormalize_bbox, normalize_bbox
  from ...core.transforms_interface import BoxInternalType, FillValueType, ImageColorType, KeypointInternalType
label_desc: Use image node_id 26 for calling a global function with example usage: bbox_safe_rotate(bbox, matrix, cols, rows) and returns: normalize_bbox, pt1,  pt2, int,  unknown, unknown,  max_val