code: function isValidDiagonal(a, b) {
         return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) &&
                locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
     }
docs: check if a diagonal between two polygon nodes is valid (lies in polygon interior)