mapbox / turf-swift

A Swift language port of Turf.js.
https://mapbox.github.io/turf-swift/
ISC License
236 stars 55 forks source link

Add method to divide LineString into equal chunks #183

Open 1ec5 opened 2 years ago

1ec5 commented 2 years ago

The lineChunk method should be ported to this library:

Divides a LineString into chunks of a specified length. If the line is shorter than the segment length then the original line is returned.

This method would be useful for sampling a geometry before passing the simplified geometry into a map matching algorithm: https://github.com/mapbox/mapbox-directions-swift/issues/661#issuecomment-1063184448.

Suggested LineString method signatures:

func dividedIntoChunks(of length: LocationDistance, reversed: Bool) -> MultiLineString

/cc @danpat @Guardiola31337

1ec5 commented 2 years ago
mutating func divideIntoChunks(of length: LocationDistance, reversed: Bool)

I removed this suggested method signature because it isn’t possible to convert a LineString into a MultiLineString in place. However, if we add these methods to MultiLineString itself, then it would be possible.

MaximAlien commented 2 years ago

Tagging @mapbox/navigation-android for parity.