Skip to content

Commit

Permalink
Use stable sort (#17)
Browse files Browse the repository at this point in the history
* Update README to reflect earcut(-js) 3.0.0 release

* stable sort
  • Loading branch information
ciscorn authored Oct 21, 2024
1 parent 5782ed0 commit 3898cc0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "MIERUNE Inc. <[email protected]>"]
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -39,6 +39,5 @@ on Macbook Pro (M1 Pro)

## Authors

- MIERUNE Inc.
- Taku Fukada ([@ciscorn](https://github.com/ciscorn)) - original author

- MIERUNE Inc.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<T: Float> Earcut<T> {
}

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 {
Expand Down
11 changes: 8 additions & 3 deletions tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -44,7 +49,7 @@ fn fixture_dude() {
}

#[test]
fn fixture_water() {
fn fixture_water1() {
test_fixture("water", 2482, 0.0008);
}

Expand All @@ -69,7 +74,7 @@ fn fixture_water4() {
}

#[test]
fn fixture_water_huge() {
fn fixture_water_huge1() {
test_fixture("water-huge", 5177, 0.0011);
}

Expand Down

0 comments on commit 3898cc0

Please sign in to comment.