From 3dc4dfd841e8d73de27b6fe11c14b258bbaac165 Mon Sep 17 00:00:00 2001 From: Taku Fukada Date: Tue, 22 Oct 2024 01:52:42 +0900 Subject: [PATCH] stable sort --- Cargo.toml | 2 +- src/lib.rs | 2 +- tests/fixture.rs | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1db7def..de0acb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "earcut" -version = "0.4.1" +version = "0.4.2" edition = "2021" description = "A Rust port of the Earcut polygon triangulation library" authors = ["Taku Fukada ", "MIERUNE Inc. "] diff --git a/src/lib.rs b/src/lib.rs index 82ba5eb..9911da6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -288,7 +288,7 @@ impl Earcut { } self.queue - .sort_unstable_by(|(_a, ax), (_b, bx)| ax.partial_cmp(bx).unwrap_or(Ordering::Equal)); + .sort_by(|(_a, ax), (_b, bx)| ax.partial_cmp(bx).unwrap_or(Ordering::Equal)); // process holes from left to right for &(q, _) in &self.queue { diff --git a/tests/fixture.rs b/tests/fixture.rs index a8cf35b..04f0d70 100644 --- a/tests/fixture.rs +++ b/tests/fixture.rs @@ -27,7 +27,12 @@ fn test_fixture(name: &str, num_triangles: usize, expected_deviation: f64) { earcut.earcut(data.iter().copied(), &hole_indices, &mut triangles); // check - assert!(triangles.len() == num_triangles * 3); + assert!( + triangles.len() == num_triangles * 3, + "{} {}", + triangles.len(), + num_triangles * 3 + ); if !triangles.is_empty() { assert!(deviation(data.iter().copied(), &hole_indices, &triangles) <= expected_deviation); } @@ -44,7 +49,7 @@ fn fixture_dude() { } #[test] -fn fixture_water() { +fn fixture_water1() { test_fixture("water", 2482, 0.0008); } @@ -69,7 +74,7 @@ fn fixture_water4() { } #[test] -fn fixture_water_huge() { +fn fixture_water_huge1() { test_fixture("water-huge", 5177, 0.0011); }