generic polyline reduction using Langs' algorithm: