Reverting ddb9ba266b because this solution breaks adjacent segments which form u-turn. See #2420 for more details. Added more tests though.
ddb9ba266b