Remove duplicate positions from polylines.

For #898.
This could replace `containsDuplicates` by initializing it to `-1`.