/** * Method to get the coordinates of the enclosing rectangle after this transformation is applied * to the current picture * * @return the enclosing rectangle */ public Rectangle2D getTransformEnclosingRect(AffineTransform trans) { int width = getWidth(); int height = getHeight(); double maxX = width - 1; double maxY = height - 1; double minX, minY; Point2D.Double p1 = new Point2D.Double(0, 0); Point2D.Double p2 = new Point2D.Double(maxX, 0); Point2D.Double p3 = new Point2D.Double(maxX, maxY); Point2D.Double p4 = new Point2D.Double(0, maxY); Point2D.Double result = new Point2D.Double(0, 0); Rectangle2D.Double rect = null; // get the new points and min x and y and max x and y trans.deltaTransform(p1, result); minX = result.getX(); maxX = result.getX(); minY = result.getY(); maxY = result.getY(); trans.deltaTransform(p2, result); minX = Math.min(minX, result.getX()); maxX = Math.max(maxX, result.getX()); minY = Math.min(minY, result.getY()); maxY = Math.max(maxY, result.getY()); trans.deltaTransform(p3, result); minX = Math.min(minX, result.getX()); maxX = Math.max(maxX, result.getX()); minY = Math.min(minY, result.getY()); maxY = Math.max(maxY, result.getY()); trans.deltaTransform(p4, result); minX = Math.min(minX, result.getX()); maxX = Math.max(maxX, result.getX()); minY = Math.min(minY, result.getY()); maxY = Math.max(maxY, result.getY()); // create the bounding rectangle to return rect = new Rectangle2D.Double(minX, minY, maxX - minX + 1, maxY - minY + 1); return rect; }