def merge_intervals(elems, overlap_thres=<NUM_LIT>):
overlap_thres = max(<NUM_LIT:0.0>, overlap_thres)<EOL>ordered = sorted(elems, key=lambda e: e.x0)<EOL>intervals = []<EOL>cur = [-overlap_thres, -overlap_thres]<EOL>for e in ordered:<EOL><INDENT>if e.x0 - cur[<NUM_LIT:1>] > overlap_thres:<EOL><INDENT>if cur[<NUM_LIT:1>] > <NUM_LIT:0.0>:<EOL><INDENT>intervals.append(cur)<EOL><DEDENT>cur = [e.x0, e.x1]<EOL>continue<EOL><DEDENT>cur[<NUM_LIT:1>] = max(cur[<NUM_LIT:1>], e.x1)<EOL><DEDENT>intervals.append(cur)<EOL>return map(tuple, intervals)<EOL>
Project in x axis
Sort by start
Go through segments and keep max x1

Return a list of non-overlapping intervals