code: private static Direction getTailDirection(final Point2DArray points, final NFastDoubleArrayJSO buffer, final Direction lastDirection, Direction tailDirection, final double correction, final OrthogonalPolyLine pline, final double p0x, final double p0y, final double p1x, final double p1y)
      {
          final double offset = pline.getHeadOffset() + correction;
  
          switch (tailDirection)
          {
              case NONE:
              {
                  final double dx = (p1x - p0x);
  
                  final double dy = (p1y - p0y);
  
                  int bestPoints = 0;
  
                  if (dx > offset)
                  {
                      tailDirection = WEST;
  
                      bestPoints = drawTail(points, buffer, lastDirection, WEST, correction, pline, p0x, p0y, p1x, p1y, false);
                  }
                  else
                  {
                      tailDirection = EAST;
  
                      bestPoints = drawTail(points, buffer, lastDirection, EAST, correction, pline, p0x, p0y, p1x, p1y, false);
                  }
                  if (dy > 0)
                  {
                      final int points3 = drawTail(points, buffer, lastDirection, NORTH, correction, pline, p0x, p0y, p1x, p1y, false);
  
                      if (points3 < bestPoints)
                      {
                          tailDirection = NORTH;
  
                          bestPoints = points3;
                      }
                  }
                  else
                  {
                      final int points4 = drawTail(points, buffer, lastDirection, SOUTH, correction, pline, p0x, p0y, p1x, p1y, false);
  
                      if (points4 < bestPoints)
                      {
                          tailDirection = SOUTH;
  
                          bestPoints = points4;
                      }
                  }
                  break;
              }
              default:
                  break;
          }
          return tailDirection;
      }
docs: When tail is NONE it needs to try multiple directions to determine which gives the least number of corners, and then selects that as the final direction.
  
  @param points
  @param buffer
  @param lastDirection
  @param tailDirection
  @param correction
  @param pline
  @param p0x
  @param p0y
  @param p1x
  @param p1y
  @return