code: function finiteLinesIntersect(x1, y1, x2, y2, x3, y3, x4, y4, infiniteLines) {
    var dx13 = x1 - x3;
    var dx21 = x2 - x1;
    var dx43 = x4 - x3;
    var dy13 = y1 - y3;
    var dy21 = y2 - y1;
    var dy43 = y4 - y3;
    var ua_t = dx43 * dy13 - dy43 * dx13;
    var ub_t = dx21 * dy13 - dy21 * dx13;
    var u_b = dy43 * dx21 - dx43 * dy21;
  
    if (u_b !== 0) {
      var ua = ua_t / u_b;
      var ub = ub_t / u_b;
      var flptThreshold = 0.001;
  
      var _min = 0 - flptThreshold;
  
      var _max = 1 + flptThreshold;
  
      if (_min <= ua && ua <= _max && _min <= ub && ub <= _max) {
        return [x1 + ua * dx21, y1 + ua * dy21];
      } else {
        if (!infiniteLines) {
          return [];
        } else {
          return [x1 + ua * dx21, y1 + ua * dy21];
        }
      }
    } else {
      if (ua_t === 0 || ub_t === 0) {
        // Parallel, coincident lines. Check if overlap
        // Check endpoint of second line
        if (midOfThree(x1, x2, x4) === x4) {
          return [x4, y4];
        } // Check start point of second line
  
  
        if (midOfThree(x1, x2, x3) === x3) {
          return [x3, y3];
        } // Endpoint of first line
  
  
        if (midOfThree(x3, x4, x2) === x2) {
          return [x2, y2];
        }
  
        return [];
      } else {
        // Parallel, non-coincident
        return [];
      }
    }
  }
docs: (x1,y1)=>(x2,y2) intersect with (x3,y3)=>(x4,y4)