Fix polyline offset behaviour in common cases

This change modifies the algorithms behind the polyline offset, to make it behave better in more common cases.

I also submitted a pull request to the upstream library.