From 5c1c3d26658aff27a7dafc6719d3c8147769ccfc Mon Sep 17 00:00:00 2001 From: Taku Fukada Date: Mon, 21 Oct 2024 23:59:51 +0900 Subject: [PATCH 1/2] Update README to reflect earcut(-js) 3.0.0 release --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb0f880..12a96bc 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ A Rust port of the [mapbox/earcut](https://github.com/mapbox/earcut) polygon triangulation library, implemented from scratch with some reference to [donbright/earcutr](https://github.com/donbright/earcutr). -- Based on the latest earcut 2.2.4 release. -- Designed to avoid unnecessary memory allocations. You can reuse the internal buffer and the output index vector for multiple triangulations. +- Based on the latest earcut 3.0.0 release. +- Designed to avoid unnecessary memory allocations. The internal buffer and output index vector can be reused across multiple triangulations. - (Experimental) An additional module, `utils3d`, can rotate 3D coplanar polygons into the 2D plane before triangulation. - License: ISC @@ -39,6 +39,5 @@ on Macbook Pro (M1 Pro) ## Authors -- MIERUNE Inc. - Taku Fukada ([@ciscorn](https://github.com/ciscorn)) - original author - +- MIERUNE Inc. From 3dc4dfd841e8d73de27b6fe11c14b258bbaac165 Mon Sep 17 00:00:00 2001 From: Taku Fukada Date: Tue, 22 Oct 2024 01:52:42 +0900 Subject: [PATCH 2/2] 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); }