Skip to content

Commit

Permalink
Use float total_cmp instead of partial_cmp to get a total order.
Browse files Browse the repository at this point in the history
Since Rust version 1.81, sort_by will panic if the provided comparison
function does not implement a total order.
See https://github.com/rust/lang/rust/issues/129561 for more details.
The simplest fix seems to be to use total_cmp instead of partial_cmp.
  • Loading branch information
Rose Hogenson committed Oct 26, 2024
1 parent d660fad commit f3733a8
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions graphics/src/damage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ pub fn list<T>(
/// Groups the given damage regions that are close together inside the given
/// bounds.
pub fn group(mut damage: Vec<Rectangle>, bounds: Rectangle) -> Vec<Rectangle> {
use std::cmp::Ordering;

const AREA_THRESHOLD: f32 = 20_000.0;

damage.sort_by(|a, b| {
a.center()
.distance(Point::ORIGIN)
.partial_cmp(&b.center().distance(Point::ORIGIN))
.unwrap_or(Ordering::Equal)
.total_cmp(&b.center().distance(Point::ORIGIN))
});

let mut output = Vec::new();
Expand Down

0 comments on commit f3733a8

Please sign in to comment.