code: private Rectangle2D transformedBounds(Shape shape) {
          Rectangle2D rectangle2D = shape.getBounds2D();
          Point2D minPoint = new Point2D.Double(rectangle2D.getMinX(), rectangle2D.getMinY());
          Point2D maxPoint = new Point2D.Double(rectangle2D.getMaxX(), rectangle2D.getMaxY());
  
          transform.transform(minPoint, minPoint);
          transform.transform(maxPoint, maxPoint);
  
          // may be flipped by transformation
          double minX = Math.min(minPoint.getX(), maxPoint.getX());
          double maxX = Math.max(minPoint.getX(), maxPoint.getX());
          double minY = Math.min(minPoint.getY(), maxPoint.getY());
          double maxY = Math.max(minPoint.getY(), maxPoint.getY());
  
          return new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY);
      }
docs: Access the bounds of a shape that have been transformed.
  
  @param shape any shape
  @return the bounds of the shape transformed