Bently-Ottmann algorithm (almost works).