From 48569ff99c49105f9f74a39c6de23058cfd41a72 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Thu, 30 Jan 2025 16:55:51 +0100 Subject: [PATCH] prevent linearity in median splitters due to duplicated points --- .../include/CGAL/Point_container.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Spatial_searching/include/CGAL/Point_container.h b/Spatial_searching/include/CGAL/Point_container.h index eb96024348e..c2218eab6b8 100644 --- a/Spatial_searching/include/CGAL/Point_container.h +++ b/Spatial_searching/include/CGAL/Point_container.h @@ -419,6 +419,24 @@ public: typename Traits::Cartesian_const_iterator_d mpit = construct_it((*(*mid))); FT val1 = *(mpit+split_coord); + + // Avoid using the low coord value as it results in an empty split + if (val1 == tbox.min_coord(split_coord)) { + iterator it = std::min_element(mid, end(), [=](const Point_d* a, const Point_d* b) -> bool { + FT a_c = *(construct_it(*a) + split_coord); + FT b_c = *(construct_it(*b) + split_coord); + + if (a_c == val1) + return false; + + if (b_c == val1) + return true; + + return a_c < b_c; + }); + return *(construct_it(**it) + split_coord); + } + mid++; mpit = construct_it((*(*mid))); FT val2 = *(mpit+split_coord);