From 597970b368235fce8c3c7b3bc04a3f9515ae83f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jamin?= Date: Tue, 16 Nov 2021 12:06:32 +0100 Subject: [PATCH 1/4] Bug fix: `remove_outliers` was removing ALL points when no outliers were found Bug in current code: when no outliers are found, `f2r` is `sorted_points.end()`. So, `if (sit == f2r)` is never true, and `out` keeps its initial value, which is `points.begin()`. --- Point_set_processing_3/include/CGAL/remove_outliers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Point_set_processing_3/include/CGAL/remove_outliers.h b/Point_set_processing_3/include/CGAL/remove_outliers.h index a7c584e5466..e06509bb895 100644 --- a/Point_set_processing_3/include/CGAL/remove_outliers.h +++ b/Point_set_processing_3/include/CGAL/remove_outliers.h @@ -266,7 +266,7 @@ remove_outliers( // Replaces [points.begin(), points.end()) range by the sorted content. iterator pit = points.begin(); - iterator out = points.begin(); + iterator out = points.end(); for (auto sit = sorted_points.begin(); sit != sorted_points.end(); ++ sit) { From ffe7a6909a16bb927f5fb4b4a87afb51a69ed4a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jamin?= Date: Tue, 16 Nov 2021 15:48:48 +0100 Subject: [PATCH 2/4] Improve `std::partition` predicate --- Point_set_processing_3/include/CGAL/remove_outliers.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Point_set_processing_3/include/CGAL/remove_outliers.h b/Point_set_processing_3/include/CGAL/remove_outliers.h index e06509bb895..5482d2cbb13 100644 --- a/Point_set_processing_3/include/CGAL/remove_outliers.h +++ b/Point_set_processing_3/include/CGAL/remove_outliers.h @@ -247,9 +247,9 @@ remove_outliers( if (threshold_distance != FT(0)) f2r = std::partition (sorted_points.begin(), sorted_points.end(), - [&threshold_distance](const std::pair& p) -> bool - { - return p.first < threshold_distance * threshold_distance; + [sq_threshold_distance = CGAL::square(threshold_distance)](const std::pair& p) -> bool + { + return p.first < sq_threshold_distance; }); if (static_cast(std::distance (sorted_points.begin(), f2r)) < first_index_to_remove) From c5d341b960c669e02ce0d0ed4bc78c1cb63a777d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jamin?= Date: Tue, 16 Nov 2021 16:06:30 +0100 Subject: [PATCH 3/4] If no outliers are found, just return the original range --- .../include/CGAL/remove_outliers.h | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Point_set_processing_3/include/CGAL/remove_outliers.h b/Point_set_processing_3/include/CGAL/remove_outliers.h index 5482d2cbb13..a95894137ae 100644 --- a/Point_set_processing_3/include/CGAL/remove_outliers.h +++ b/Point_set_processing_3/include/CGAL/remove_outliers.h @@ -252,28 +252,32 @@ remove_outliers( return p.first < sq_threshold_distance; }); - if (static_cast(std::distance (sorted_points.begin(), f2r)) < first_index_to_remove) - { - std::nth_element (f2r, - sorted_points.begin() + first_index_to_remove, - sorted_points.end(), - [](const std::pair& v1, const std::pair& v2) - { - return v1.firstsecond; - if (sit == f2r) - out = pit; - ++ pit; + if (static_cast(std::distance (sorted_points.begin(), f2r)) < first_index_to_remove) + { + std::nth_element (f2r, + sorted_points.begin() + first_index_to_remove, + sorted_points.end(), + [](const std::pair& v1, const std::pair& v2) + { + return v1.firstsecond; + if (sit == f2r) + out = pit; + ++ pit; + } } callback_wrapper.join(); From 7f7214281841b373c1c0b62507388da6432d1fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jamin?= Date: Tue, 16 Nov 2021 17:15:46 +0100 Subject: [PATCH 4/4] Remove trailing whitespaces --- Point_set_processing_3/include/CGAL/remove_outliers.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Point_set_processing_3/include/CGAL/remove_outliers.h b/Point_set_processing_3/include/CGAL/remove_outliers.h index a95894137ae..aac07b43296 100644 --- a/Point_set_processing_3/include/CGAL/remove_outliers.h +++ b/Point_set_processing_3/include/CGAL/remove_outliers.h @@ -247,9 +247,9 @@ remove_outliers( if (threshold_distance != FT(0)) f2r = std::partition (sorted_points.begin(), sorted_points.end(), - [sq_threshold_distance = CGAL::square(threshold_distance)](const std::pair& p) -> bool - { - return p.first < sq_threshold_distance; + [sq_threshold_distance = CGAL::square(threshold_distance)](const std::pair& p) -> bool + { + return p.first < sq_threshold_distance; }); iterator out = points.end();