code: private Point intersection(int x1, int y1, int x2, int y2, DesktopWindowRect rect) {
      Point
          bottom =
          intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX() + rect.getHeight(),
                       rect.getY());
      if (bottom != null) {
        return bottom;
      }
  
      Point
          right =
          intersection(x1, y1, x2, y2, rect.getX() + rect.getWidth(), rect.getY(),
                       rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight());
      if (right != null) {
        return right;
      }
  
      Point
          top =
          intersection(x1, y1, x2, y2, rect.getX(), rect.getY() + rect.getHeight(),
                       rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight());
      if (top != null) {
        return top;
      }
  
      Point
          left =
          intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX(),
                       rect.getY() + rect.getHeight());
      if (left != null) {
        return left;
      }
  
      return null;
    }
docs: Intersect a line and a DesktopWindowRect