code: function middleInside (data, start, a, b) {
    var node = start,
      inside = false,
      px = (data[a] + data[b]) / 2,
      py = (data[a + 1] + data[b + 1]) / 2
    do {
      var p1 = node.i,
        p2 = node.next.i
  
      if (((data[p1 + 1] > py) !== (data[p2 + 1] > py)) &&
        (px < (data[p2] - data[p1]) * (py - data[p1 + 1]) / (data[p2 + 1] - data[p1 + 1]) + data[p1])) {
        inside = !inside
      }
  
      node = node.next
    } while (node !== start)
  
    return inside
  }
docs: check if the middle point of a polygon diagonal is inside the polygon