georust / geo

Geospatial primitives and algorithms for Rust
https://crates.io/crates/geo
Other
1.49k stars 194 forks source link

Address LineStringSegmentize bugs #1078

Closed JosiahParry closed 10 months ago

JosiahParry commented 10 months ago

Thanks to @Robinlovelace for doing tests on real data. Brought to light 2 categories of edge cases where the number of LineStrings in the resultant MultiLineString was not the same quantity as requested by the n parameter.

Bug occurred when:

This has been addressed through the use of the Densify trait.

LineStrings are densified to ensure that a Line segment never has to be partitioned more than once. Additionally, after densification the lines are counted. If the number of lines is exactly n, then the function is exited early.

An additional change was made which incorrectly would return the Line of a LineString if there were n lines. This was wrong because the length may have not been equivalent. I have removed this check and early return. I've removed a test that tested for this equivalence since it was a bad assumption.

I've also removed the unneeded peekable() call.


Aids downstream:

JosiahParry commented 10 months ago

Thanks for your speedy help, @urschrei !!