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

unstable_sort_by panics when given NaN #9

Closed Roughsketch closed 1 year ago

Roughsketch commented 5 years ago

There is a panic on the following line when one of the values is NaN: https://github.com/mourner/delaunator-rs/blob/82ddbdb33651139414f2fe581f67dc12522dec32/src/lib.rs#L434

You can get around this by implementing a default ordering with something like

dists.sort_unstable_by(|&(_, da), &(_, db)| da.partial_cmp(&db).unwrap_or(std::cmp::Ordering::Less));

Or by checking if a given argument contains a NaN in the first place if NaN breaks further work. I think having one of these and returning None is preferable to a panic inside the method. At the very least this behavior should be documented.

mourner commented 1 year ago

Fixed by #28