class Point {
  double x, y;
  public Point(double x, double y) {
    this.x = x; this.y = y;
  }
}
interface Region {
  boolean contains(Point p);
}
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;
  }
}
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);
  }
}
class UnionRegion implements Region {
  Region reg1, reg2;
  public UnionRegion(Region reg1, Region reg2) {
    this.reg1 = reg1;
    this.reg2 = reg2;
  }
  public boolean contains(Point p) {
    return this.reg1.contains(p) || this.reg2.contains(p);
  }
}
class SubtractRegion implements Region {
  Region reg1, reg2;
  public SubtractRegion(Region reg1, Region reg2) {
    this.reg1 = reg1;
    this.reg2 = reg2;
  }
  public boolean contains(Point p) {
    return this.reg1.contains(p) && !this.reg2.contains(p);
  }
}
class NegateRegion implements Region {
  Region reg;
  public NegateRegion(Region reg) {
    this.reg = reg;
  }
  public boolean contains(Point p) {
    return !this.reg.contains(p);
  }
}

















public class Handout {
  // 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];
    Region circle = new CircRegion(5, 5, 6);
    Region rect = new RectRegion(3, 4, 6, 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, threeCircles);
    printGrid(grid);


    Region r;















  }
}

