From c61abfa1e758675cc6aa9925e3e6468cf104eaa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Fri, 2 Dec 2022 10:03:05 +0000 Subject: [PATCH] Add preventative debug assert See https://github.com/georust/geo/pull/941#issuecomment-1332305431 --- geo/src/algorithm/simplify.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/geo/src/algorithm/simplify.rs b/geo/src/algorithm/simplify.rs index 265d16fa4..1c49d9349 100644 --- a/geo/src/algorithm/simplify.rs +++ b/geo/src/algorithm/simplify.rs @@ -83,6 +83,7 @@ where } }, ); + debug_assert_ne!(farthest_index, 0); if farthest_distance > *epsilon { // The farthest index was larger than epsilon, so we will recursively simplify subsegments @@ -248,6 +249,18 @@ mod test { use crate::geo_types::coord; use crate::{line_string, polygon}; + #[test] + fn recursion_test() { + let vec = [ + coord! { x: 8.0, y: 100.0 }, + coord! { x: 9.0, y: 100.0 }, + coord! { x: 12.0, y: 100.0 }, + ]; + let compare = vec![coord! {x: 8.0, y: 100.0}, coord! {x: 12.0, y: 100.0}]; + let simplified = rdp(vec.into_iter(), &1.0); + assert_eq!(simplified, compare); + } + #[test] fn rdp_test() { let vec = vec![