Finding if Path2D self-intersects
I need to find if Path2D intersects itself. For now, I do it by simply extracting an array of lines from path, and finding if any of these intersect. But it has O(n^2) complexity, and so it is very slow. Is there a faster way to do it? You can do this faster using the sweep-line algorithm: http://en.wikipedia.org/wiki/Sweep_line_algorithm Pseudocode: Each line has a start point and an end point. Say that `start_x` <= `end_x` for all the lines. Create an empty bucket of lines. Sort all the points by their x coordinates, and then iterate through the sorted list. If the current point is a start