import java.awt.Rectangle;

public class RectangleExamples
{    public static void main(String[] args)
    {    //various examples of creating Rectangle objects

        Rectangle r1 = new Rectangle();
        int i = 10;
        int j = 20;
        Rectangle r2 = new Rectangle(i,i,j,j);
        Rectangle r3 = new Rectangle(i - 10, j * 2);
        //Rectangle r4 = new Rectangle(i,i,j);//error
        Rectangle r5 = new Rectangle(5, 20, i * j, 20 - 5);
        int x = 5, y = 10, width = 20, height = 50;
        Rectangle r6 = new Rectangle(width, x, y, height);
        //Rectangle r7 = new Rectangle( 2.5, 12 / 3);

        //area of combined Rectangles
        r1 = new Rectangle(0, 0, 10, 30);
        r2 = new Rectangle(5, 5, 30, 20);
        r3 = r1.intersection(r2);

        double areaR1 = r1.getWidth() * r1.getHeight();
        double areaR2 = r2.getWidth() * r2.getHeight();
        double areaR3 = r3.getWidth() * r3.getHeight();
        double combinedAreaR1R2 = areaR1 + areaR2 - areaR3;

        //find rectangle that contains both other rectangle
        //easy way
        Rectangle boundsR1R2 = r1.union(r2);
        System.out.println(boundsR1R2);

        //hard way
        int r1BottomRightX = r1.x + r1.width;
        int r1BottomRightY = r1.y + r1.height;
        int r2BottomRightX = r2.x + r2.width;
        int r2BottomRightY = r2.y + r2.height;

        int newTopLeftX = Math.min(r1.x, r2.x);
        int newTopLeftY = Math.min(r1.y, r2.y);
        int newBottomRightX = Math.max(r1BottomRightX, r2BottomRightX);
        int newBottomRightY = Math.max(r1BottomRightY, r2BottomRightY);

        boundsR1R2 = new Rectangle( newTopLeftX, newTopLeftY,
            newBottomRightX - newTopLeftX, newBottomRightY - newTopLeftY);
        System.out.println( boundsR1R2);

        //90 degrees clockwise rotation of R1
        int newY = r1.y + r1.height - r1.width;
        r5 = new Rectangle(r1.x, newY, r1.height, r1.width);

        //180 degree flip down horizontal
        r6 = new Rectangle(r1.x, r1.y - r1.height, r1.width, r1.height);

        //180 degree flip to right around vertical line
        Rectangle r7 = new Rectangle(r1.x + r1.width, r1.y, r1.width, r1.height);
    }
}
