Skip to content

Commit

Permalink
Don't panic on negative epsilon
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Nov 11, 2020
1 parent d0684fd commit e2465c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions geo/src/algorithm/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ fn rdp<T>(points: &[Point<T>], epsilon: &T) -> Vec<Point<T>>
where
T: Float,
{
// Epsilon must be greater than zero for any meaningful simplification to happen
if *epsilon <= T::zero() {
points.to_vec();
}
compute_rdp(
&points
.into_iter()
Expand Down
6 changes: 5 additions & 1 deletion geo/src/algorithm/simplifyvw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ fn visvalingam<T>(orig: &LineString<T>, epsilon: &T) -> Vec<Coordinate<T>>
where
T: Float,
{
// Epsilon must be greater than zero for any meaningful simplification to happen
if *epsilon <= T::zero() {
return orig.0.to_vec()
}
let subset = visvalingam_indices(orig, epsilon);
// filter orig using the indices
// using get would be more robust here, but the input subset is guaranteed to be valid in this case
Expand Down Expand Up @@ -251,7 +255,7 @@ fn visvalingam_preserve<T>(
where
T: Float + RTreeNum,
{
if orig.0.len() < 3 {
if orig.0.len() < 3 || *epsilon <= T::zero() {
return orig.0.to_vec();
}
let max = orig.0.len();
Expand Down

0 comments on commit e2465c7

Please sign in to comment.