isValidDiagonal function

dynamic isValidDiagonal(
  1. dynamic a,
  2. dynamic b
)

Implementation

isValidDiagonal(a, b) {
  var b1 = a.next.i != b.i;
  var b2 = a.prev.i != b.i;
  var b3 = !intersectsPolygon(a, b);

  var b41 = locallyInside(a, b);
  var b42 = locallyInside(b, a);
  var b43 = middleInside(a, b);

  // does not create opposite-facing sectors
  var b44 = area(a.prev, a, b.prev) != 0;
  var b45 = area(a, b.prev, b) != 0;

  var b46 = equals(a, b);
  var b47 = area(a.prev, a, a.next) > 0;
  var b48 = area(b.prev, b, b.next) > 0;
  // locally visible

  var b4 = (b41 && b42 && b43 && (b44 || b45) || b46 && b47 && b48);

  // dones't intersect other edges
  return b1 && b2 && b3 && b4; // special zero-length case
}