code: public static int crossLine (float x1, float y1, float x2, float y2, float x, float y) {
          // LEFT/RIGHT/UP/EMPTY
          if ((x < x1 && x < x2) || (x > x1 && x > x2) || (y > y1 && y > y2) || (x1 == x2)) {
              return 0;
          }
  
          // DOWN
          if (y < y1 && y < y2) {
          } else {
              // INSIDE
              if ((y2 - y1) * (x - x1) / (x2 - x1) <= y - y1) {
                  // INSIDE-UP
                  return 0;
              }
          }
  
          // START
          if (x == x1) {
              return x1 < x2 ? 0 : -1;
          }
  
          // END
          if (x == x2) {
              return x1 < x2 ? 1 : 0;
          }
  
          // INSIDE-DOWN
          return x1 < x2 ? 1 : -1;
      }
docs: Returns how many times ray from point (x,y) cross line.