class Point {
  double x, y;
  public Point(double x, double y) {
    this.x = x; this.y = y;
  }
}

interface Region {
  public 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;
  }
}


public class Main {

  public static void clearGrid(char[][] grid) {
    for(int i = 0; i < grid.length; i += 1) {
      for(int j = 0; j < grid.length; j += 1) {
        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[i][j]);
      }

      System.out.println();
    }
  }

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

  public static void main(String[] args) {
    char[][] grid = new char[20][20];
    clearGrid(grid);
    drawRegion(grid, new SubtractRegion(new RectRegion(2, 2, 8, 8), new CircRegion(6, 6, 3)), 'X');
    printGrid(grid);

    RectRegion rect = new RectRegion(6, 6, 3, 4);
    CircRegion circ = new CircRegion(5, 5, 2);

    Point p1 = new Point(7, 7);
    Point p1a = new Point(6.999999999999, 6.9999999999);
    Point p2 = new Point(5, 5);
    Point corner = new Point(6, 6);

    System.out.println(rect.contains(p1));
    System.out.println(rect.contains(p2));

    System.out.println(circ.contains(p1));
    System.out.println(circ.contains(p1a));
    System.out.println(circ.contains(p2));

    System.out.println(both(circ, rect, corner));
    System.out.println(both(circ, rect, p1));
    System.out.println(both(rect, circ, p1));
    System.out.println(both(circ, circ, p1));



  }
}














/*
class CircRegion {
  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 CircRegion {
  double x, y, radius;
  public CircRegion(x, y, radius) {
    x = x; y = y; 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 CircRegion {
  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.abs(p.x - this.x) < this.radius &&
            Math.abs(p.y - this.y) < this.radius;
  }
}
*/
