class Point {
  double x, y;
  public Point(double x, double y) {
    this.x = x; this.y = y;
  }
}
class RectRegion implements Region {
  double x, y, width, height;
  public RectRegion(double x, double y, double w, double h) {
    this.x = x; this.y = y; this.width = w; this.height = h;
  }

  public boolean contains(Point p) {
    return (p.x <= this.x + width) && (p.x >= this.x)
        && (p.y <= this.y + height) && (p.y >= this.y);
  }
}
class CircRegion implements Region {
  double x, y, radius;
  public CircRegion(double x, double y, double radius) {
    this.x = x; this.y = y; this.radius = radius;
  }
  public boolean contains(Point p) {
    return (Math.sqrt(Math.pow(p.x - this.x, 2) + Math.pow(p.y - this.y, 2)))
      <= this.radius;
  }
}
interface Region {
  public boolean contains(Point p);
}

// Write an example of an IntersectRegion that represents
// this picture (at some x/y coordinate)

/*
                    X
                    X X X X
                    X X X X X X
                    X X X X X X X
                    X X X X X X X
                    X X X X X X X X
                    X X X X X X X X
                    X X X X X X X X
                    X X X X X X X X X

// A: Region i = new IntersectRegion(
//      new CircRegion(5, 5, 8),
//      new RectRegion(5, 5, 2, 2)
      )
   B: Region i = new IntersectRegion(
        new CircRegion(5, 5, 8),
        new RectRegion(5, 5, 8, 8)
      )
   C: Region i = new IntersectRegion(
        new RectRegion(5, 5, 2, 2),
        new CircRegion(5, 5, 8)
      )
   D: Region i = new IntersectRegion(
        new RectRegion(5, 5, 20, 20),
        new CircRegion(5, 5, 8)
     )
*/
class IntersectRegion implements Region {
  Region reg1, reg2;
  public IntersectRegion(Region reg1, Region reg2) {
    this.reg1 = reg1;
    this.reg2 = reg2;
  }
  public boolean contains(Point p) {
    return this.reg1.contains(p) && this.reg2.contains(p);
  }
}
public class Main {
  // drawRegion : takes a grid (char[][]) and a Region,
  // and sets all the indices contained in the Region to 'X'
  // and all others to ' '
  public static void drawRegion(char[][] grid, Region r) {
    for(int i = 0; i < grid.length; i += 1) {
      for(int j = 0; j < grid.length; j += 1) {
        Point p = new Point((double)i, (double)j); // cast
        if(r.contains(p)) {
          grid[i][j] = 'X';
        }
        else {
          grid[i][j] = ' ';
        }
      }
    }
  }
  public static void printGrid(char[][] grid) {
    for(int i = 0; i < grid.length; i += 1) {
      for(int j = 0; j < grid.length; j += 1) {
        System.out.print(grid[j][grid.length - i - 1] + " ");
      }
      System.out.println();
    } }
  public static void main(String[] args) {
    char[][] grid = new char[25][25];
    CircRegion circle = new CircRegion(5, 5, 6);
    RectRegion rect = new RectRegion(3, 4, 6, 8);
    Region i = new IntersectRegion(
         new RectRegion(5, 5, 20, 20),
         new CircRegion(5, 5, 8)
      );
    Region twoCircles = new IntersectRegion(
      new CircRegion(5, 5, 8),
      new CircRegion(10, 5, 8)
    );
    Region threeCircles = new IntersectRegion(
      new CircRegion(7, 10, 8),
      twoCircles
    );
    drawRegion(grid, twoCircles);
    printGrid(grid);

    // Given the above printGrid implementation, write
    // 4 statements that print:
    // W in the bottom left, X in the top left
    // Y in the bottom right, Z in the top right
    /*
    A:
      grid[0][0] = 'W';
      grid[24][24] = 'X';
      grid[0][24] = 'Y';
      grid[24][0] = 'Z';
    B:
      grid[0][24] = 'W';
      grid[24][0] = 'X';
      grid[24][24] = 'Y';
      grid[0][0] = 'Z';
    C:
      grid[24][24] = 'W';
      grid[24][0] = 'X';
      grid[0][24] = 'Y';
      grid[0][0] = 'Z';
    D:
      grid[0][0] = 'W';
      grid[0][24] = 'X';
      grid[24][0] = 'Y';
      grid[24][24] = 'Z';
    */



  }
}

/*

// Write a method drawRegion that takes an array of character
// arrays and a Region.  It should iterates over the indices
// of the grid, and fill each spot with '#' if it is contained
// in the given region, or ' ' if not.

A:
public static void drawRegion(char[][] grid, RectRegion r) {
  for(int i = 0; i < grid.length; i += 1) {
    for(int j = 0; j < grid.length; j += 1) {
      if(r.contains(new Point(i, j))) {
        grid[i][j] = 'X';
      }
      else {
        grid[i][j] = ' ';
      }
    }
  }
}

B:
public static void drawRegion(char[][] grid, CircRegion r) {
  for(int i = 0; i < grid.length; i += 1) {
    for(int j = 0; j < grid.length; j += 1) {
      if(r.contains(new Point(i, j))) {
        grid[i][j] = 'X';
      }
      else {
        grid[i][j] = ' ';
      }
    }
  }
}

C:
public static void drawRegion(char[][] grid, Region r) {
  for(int i = 0; i < grid.length; i += 1) {
    for(int j = 0; j < grid.length; j += 1) {
      if(r.contains(new Point(i, j))) {
        grid[i][j] = 'X';
      }
      else {
        grid[i][j] = ' ';
      }
    }
  }
}

D:
public static void drawRegion(char[][] grid, Region r) {
  for(int i = 0; i < grid.length; i += 1) {
    for(int j = 0; j < grid.length; j += 1) {
      if(r.contains(new Point(i, j))) {
        grid[i][j] = 'X';
      }
      else {
        grid[i][j] = ' ';
      }
    }
  }
}

*/




// Write an example of an IntersectRegion that represents
// this picture (at some x/y coordinate)

/*
                    X
                    X X X X
                    X X X X X X
                    X X X X X X X
                    X X X X X X X
                    X X X X X X X X
                    X X X X X X X X
                    X X X X X X X X
                    X X X X X X X X X
*/













/*

A:
Region r = new IntersectRegion(
  new CircRegion(10, 10, 8),
  new RectRegion(10, 10, 8, 8)
);

B:
Region r =
  new RectRegion(10, 10, 8, 8, new CircRegion(10, 10, 8));

C:
Region r =
  new CircRegion(10, 10, 8, new RectRegion(10, 10, 8, 8));

D:
Region r = new IntersectRegion(
  new RectRegion(10, 10, 20, 20),
  new CircRegion(10, 10, 8)
);

// Write a class IntersectRegion that has two fields,
// reg1 and reg2.  Its contains method should return
// true for points that are in both regions
/*

*/
