Detect self-intersecting polygons in Javascript. An implementation of the Bentley–Ottmann sweep-line algorithm with redblack tree for detecting crossings in a set of line segments.