From f83dc257bd50634bed5022e042f4a00d79ae6a67 Mon Sep 17 00:00:00 2001 From: Niall Oswald Date: Mon, 13 Oct 2025 17:45:38 +0100 Subject: [PATCH 1/2] fix: simplify boundary edge checks --- src/algorithms/simplify_charshape.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/algorithms/simplify_charshape.rs b/src/algorithms/simplify_charshape.rs index 6459124..29d7614 100644 --- a/src/algorithms/simplify_charshape.rs +++ b/src/algorithms/simplify_charshape.rs @@ -143,8 +143,7 @@ where continue; } - let [from, to] = largest.edge.vertices().map(|v| v.index()); - if (to == from + 1) || (from == to + 1) || (to + from + 2 == orig_len) { + if largest.edge.is_constraint_edge() { continue; } From 68bd19beffd135e560b7668338c488f94f1b2b38 Mon Sep 17 00:00:00 2001 From: Niall Oswald Date: Mon, 13 Oct 2025 17:50:33 +0100 Subject: [PATCH 2/2] fix: add missing constraint edge --- src/algorithms/simplify_charshape.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/algorithms/simplify_charshape.rs b/src/algorithms/simplify_charshape.rs index 29d7614..43ea68c 100644 --- a/src/algorithms/simplify_charshape.rs +++ b/src/algorithms/simplify_charshape.rs @@ -92,27 +92,27 @@ fn characteristic_shape(orig: &Polygon, eps: T, max_len: usize) -> Polygon where T: GeoFloat + SpadeNum, { - let orig_len = orig.exterior().0.len(); - - if orig_len < 3 { + if orig.exterior().0.len() < 3 { return orig.clone(); } let eps_2 = eps * eps; // Construct Delaunay triangulation + let num_vertices = orig.exterior().0.len() - 1; + let vertices = orig .exterior_coords_iter() - .take(orig_len - 1) // duplicate points are removed + .take(num_vertices) // duplicate points are removed .map(|c| Point2::new(c.x, c.y)) .collect::>(); - let edges = (0..orig_len - 2) + let edges = (0..num_vertices) .map(|i| { if i == 0 { [vertices.len() - 1, i] } else { - [i, i + 1] + [i - 1, i] } }) .collect::>();