Bently-Ottmann algorithm (complete).
a bit of refactoring