mourner / delaunator-rs

Fast 2D Delaunay triangulation in Rust. A port of Delaunator.
https://docs.rs/delaunator
ISC License
207 stars 28 forks source link

sort_unstable_by has no fallback to equal #27

Closed AndriBaal closed 1 year ago

AndriBaal commented 1 year ago

I use delaunator in a project of mine and sometimes on specific conditions the delaunator crashes because of the partial_cmp of 2 floats without a fallback. Specifically, this needs to be changed:

fn sortf(f: &mut [(usize, f64)]) {
    f.sort_unstable_by(|&(_, da), &(_, db)| da.partial_cmp(&db).unwrap());
}

to:

fn sortf(f: &mut [(usize, f64)]) {
    f.sort_unstable_by(|&(_, da), &(_, db)| da.partial_cmp(&db).unwrap_or(core::cmp::Ordering::Equal));
}
mourner commented 1 year ago

@AndriBaal nice catch! Would you mind making a PR with a fix + test?

mourner commented 1 year ago

Looks like this would fix #9 too.

AndriBaal commented 1 year ago

I have created a pull request, let me know if anything is missing. #28

mourner commented 1 year ago

Fixed by #28