Port https://github.com/pelias/polylines/pull/280 here.
Port pelias/polylines#280 here.