code: private static Direction getNextDirection(final Direction direction, final double p1x, final double p1y, final double p2x, final double p2y)
      {
          Direction next_direction;
  
          switch (direction)
          {
              case NORTH:
                  if (p2y < p1y)
                  {
                      next_direction = NORTH;
                  }
                  else if (p2x > p1x)
                  {
                      next_direction = EAST;
                  }
                  else
                  {
                      next_direction = WEST;
                  }
                  break;
              case SOUTH:
                  if (p2y > p1y)
                  {
                      next_direction = SOUTH;
                  }
                  else if (p2x > p1x)
                  {
                      next_direction = EAST;
                  }
                  else
                  {
                      next_direction = WEST;
                  }
                  break;
              case EAST:
                  if (p2x > p1x)
                  {
                      next_direction = EAST;
                  }
                  else if (p2y < p1y)
                  {
                      next_direction = NORTH;
                  }
                  else
                  {
                      next_direction = SOUTH;
                  }
                  break;
              case WEST:
                  if (p2x < p1x)
                  {
                      next_direction = WEST;
                  }
                  else if (p2y < p1y)
                  {
                      next_direction = NORTH;
                  }
                  else
                  {
                      next_direction = SOUTH;
                  }
                  break;
              default:
                  throw new IllegalStateException("This should not be reached (Defensive Code)");
          }
          return next_direction;
      }
docs: looks at the current and target points and based on the current direction returns the next direction. This drives the orthogonal line drawing.
  
  @param direction
  @param p1x
  @param p1y
  @param p2x
  @param p2y
  @return